1 #include "pagemissions.h"
2 #include "dfmissions.h"
3 #include <wx/wx.h>
4 #include <wx/spinctrl.h>
5 #include "common.h"
6 #include "listadddel.h"
7
PageMissions()8 PageMissions::PageMissions()
9 {
10 }
11
~PageMissions()12 PageMissions::~PageMissions()
13 {
14 delete itemList;
15 delete creatureList;
16 }
17
Init(wxNotebook * notebook,DF * dataFile)18 void PageMissions::Init(wxNotebook *notebook, DF *dataFile)
19 {
20 dfMissions = (DFMissions*)dataFile;
21 this->dataFile = dataFile;
22 page = new wxNotebookPage(notebook, ID_MissionsPage);
23
24 Mission *mission = dfMissions->GetCurrent();
25
26 // name
27 /*wxStaticText *nameText =*/ new wxStaticText(page, -1, _("Name"), wxPoint(10,10));
28 nameEdit = new wxTextCtrl(page, ID_MissionNameEdit, std2wx(mission->name), wxPoint(10,30), wxSize(200,25));
29
30 // type
31 /*wxStaticText *typeText =*/ new wxStaticText(page, -1, _("Type"), wxPoint(220,10));
32 char buffer[2]; buffer[0] = mission->type; buffer[1] = 0;
33 wxString choices[2] = { L"D", L"C" };
34 typeCombo = new wxComboBox(page, ID_MissionTypeCombo, std2wx(buffer), wxPoint(220,30),wxSize(50,25),
35 2,choices, wxCB_READONLY);
36
37 // storyline
38 /*wxStaticText *storylineText =*/ new wxStaticText(page, -1, _("Storyline"), wxPoint(280,10));
39 wxString choicesYesNo[2] = { L"Yes", L"No" };
40 wxString startChoice=L"No"; if ( mission->storyline ) startChoice=L"Yes";
41 storylineCombo = new wxComboBox(page, ID_MissionStorylineCombo, startChoice, wxPoint(280,30),wxSize(60,25),
42 2,choicesYesNo, wxCB_READONLY);
43 storylineCombo->Connect( wxEVT_COMMAND_COMBOBOX_SELECTED, (wxObjectEventFunction)&PageMissions::OnStorylineChange, NULL, (wxEvtHandler*)this);
44
45 // level
46 levelText = new wxStaticText(page, -1, _("Min-level"), wxPoint(10,60));
47 int n = atoi( mission->level.c_str() );
48 levelSpin = new wxSpinCtrl(page, -1, L"", wxPoint(15,80),wxSize(45,-1), wxSP_ARROW_KEYS, 1,100,n);
49 // stories
50 storiesText = new wxStaticText(page, -1, _("Floors"), wxPoint(70,60));
51 n = atoi( mission->stories.c_str() );
52 storiesSpin = new wxSpinCtrl(page, -1, L"", wxPoint(70,80),wxSize(45,-1), wxSP_ARROW_KEYS, 1,100,n);
53 // map
54 mapText = new wxStaticText(page, -1, _("Map Name"), wxPoint(120,60));
55 mapEdit = new wxTextCtrl(page, -1, std2wx(mission->mapname), wxPoint(120,80), wxSize(100,-1));
56
57 // description
58 /*wxStaticText *descText =*/ new wxStaticText(page, -1, _("Description"), wxPoint(450,10));
59 descEdit = new wxTextCtrl(page, ID_MissionDescEdit, std2wx(mission->description), wxPoint(450,30), wxSize(350,150), wxTE_MULTILINE);
60
61 // items
62 itemList = new ListAddDel;
63 itemList->Init(page, L"Items", mission->items, 400,185);
64 // creatures
65 creatureList = new ListAddDel;
66 creatureList->Init(page, L"Creatures", mission->creatures, 650,185, 180);
67
68 // success
69 /*wxStaticText *succText =*/ new wxStaticText(page, -1, _("Success"), wxPoint(10,160));
70 succEdit = new wxTextCtrl(page, ID_MissionSuccEdit, std2wx(mission->success), wxPoint(10,180), wxSize(300,60), wxTE_MULTILINE);
71
72 // failure
73 /*wxStaticText *failText =*/ new wxStaticText(page, -1, _("Faliure"), wxPoint(10,250));
74 failEdit = new wxTextCtrl(page, ID_MissionFailEdit, std2wx(mission->failure), wxPoint(10,270), wxSize(300,60), wxTE_MULTILINE);
75
76 // special
77 specialText = new wxStaticText(page, -1, _("Special"), wxPoint(230,60));
78 specialEdit = new wxTextCtrl(page, -1, std2wx(mission->special), wxPoint(230,80), wxSize(200,-1));
79
80 ShowStoryControls( mission->storyline );
81
82 notebook->AddPage(page, _("Missions"));
83 }
84
UpdatePage()85 void PageMissions::UpdatePage()
86 {
87 // bool lock = ( storylineCombo->GetValue() == L"No" );
88 // itemList->Lock(lock);
89 // creatureList->Lock(lock);
90 }
91
92 /*void PageMissions::LoadAll()
93 {}*/
94
95 /*void PageMissions::SaveAll()
96 {}*/
97
GetCurrent()98 void PageMissions::GetCurrent()
99 {
100 Mission *mission = dfMissions->GetCurrent();
101
102 nameEdit->SetValue(std2wx(mission->name));
103
104 char buffer[2]; buffer[0] = mission->type; buffer[1] = 0;
105 typeCombo->SetValue(std2wx( buffer ));
106
107 if ( mission->storyline )
108 storylineCombo->SetValue(L"Yes");
109 else
110 storylineCombo->SetValue(L"No");
111
112 wxString startChoice=L"No"; if ( mission->storyline ) startChoice=L"Yes";
113 storylineCombo->SetValue(startChoice);
114
115 int n = atoi( mission->level.c_str() );
116 levelSpin->SetValue(n);
117 n = atoi( mission->stories.c_str() );
118 storiesSpin->SetValue(n);
119 mapEdit->SetValue(std2wx(mission->mapname));
120
121 ShowStoryControls( mission->storyline );
122
123
124 descEdit->SetValue(std2wx(mission->description));
125
126 // items
127 itemList->Get( mission->items );
128 // creatures
129 creatureList->Get( mission->creatures );
130
131 itemList->Show( mission->storyline );
132 creatureList->Show( mission->storyline );
133
134
135 succEdit->SetValue(std2wx(mission->success));
136 failEdit->SetValue(std2wx(mission->failure));
137
138 specialEdit->SetValue(std2wx(mission->special));
139 }
140
SetCurrent()141 void PageMissions::SetCurrent()
142 {
143 Mission *mission = dfMissions->GetCurrent();
144
145 mission->name = wx2std( nameEdit->GetValue() );
146
147 char buffer[2]; buffer[0] = mission->type; buffer[1] = 0;
148 mission->type = *( wx2std( typeCombo->GetValue() ).c_str() );
149
150 mission->storyline = ( storylineCombo->GetValue() == L"Yes" );
151
152 mission->description = wx2std( descEdit->GetValue() );
153
154 // items
155 itemList->Set( mission->items );
156 // creatures
157 creatureList->Set( mission->creatures );
158
159 mission->success = wx2std( succEdit->GetValue() );
160
161 mission->failure = wx2std( failEdit->GetValue() );
162 }
163
ClearCurrent()164 void PageMissions::ClearCurrent()
165 {
166 Mission *mission = dfMissions->GetCurrent();
167 mission->type = 'D';
168 mission->name = mission->description = mission->success = mission->failure = "";
169 mission->items.clear();
170 mission->creatures.clear();
171 }
172
ShowStoryControls(bool show)173 void PageMissions::ShowStoryControls(bool show)
174 {
175 // Show/hide labels
176 levelText->Show( show );
177 storiesText->Show( show );
178 mapText->Show( show );
179 specialText->Show( show );
180 // Show/hide edits
181 levelSpin->Show( show );
182 storiesSpin->Show( show );
183 mapEdit->Show( show );
184 specialEdit->Show( show );
185
186 itemList->Show( show );
187 creatureList->Show( show );
188 }
189
OnStorylineChange()190 void PageMissions::OnStorylineChange()
191 {
192 bool show = (storylineCombo->GetValue() == L"Yes");
193 this->ShowStoryControls( show );
194 UpdatePage();
195 }
196