1 #include "subpagespells.h"
2 #include "pagespells.h"
3 #include "dfspells.h"
4 #include <wx/wx.h>
5 #include "common.h"
6 #include "../common/constants.h"
7 
subPageSpells()8 subPageSpells::subPageSpells()
9 {
10 	schoolStrArray = new wxArrayString;
11 	spellNumber = 1;
12 }
13 
~subPageSpells()14 subPageSpells::~subPageSpells()
15 {
16 	delete schoolStrArray;
17 }
18 
Init(wxNotebook * notebook,DF * dataFile,PageSpells * parent)19 void subPageSpells::Init(wxNotebook *notebook, DF* dataFile, PageSpells *parent)
20 {
21 	dfSpells = (DFSpells*)dataFile;		// Make a copy of the datafile
22 	this->dataFile = dataFile;
23 	spellItr = dfSpells->GetCurrent()->spells.begin();
24 	currentSpell = *spellItr;
25 	currentSchool = *(dfSpells->data.begin());
26 
27 	page = new wxNotebookPage(notebook, ID_Spells_subPage);
28 	this->parent = parent;
29 
30 	School *school = dfSpells->GetCurrent();
31 	Spell *spell = *(school->spells.begin());
32 
33 /**
34 	Schools
35 **/
36 	new wxStaticText(page, -1, L"Schools", wxPoint(10,10));
37 	for ( std::vector<School*>::iterator itr = dfSpells->data.begin(); itr != dfSpells->data.end(); itr++ )
38 		schoolStrArray->Add( std2wx( (*itr)->name ) );
39 	schoolList = new wxListBox(page, ID_subSpellsSchoolList, wxPoint(10,30), wxSize(200,90), *schoolStrArray);
40 
41 	schoolNameText = new wxStaticText(page, -1, std2wx(school->name), wxPoint(220,40));
42 		schoolNameText->SetFont( wxFont(10,wxFONTFAMILY_DEFAULT,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD) );
43 
44 
45 	// name
46 	new wxStaticText(page, -1, _("Name"), wxPoint(220,60));
47 	nameEdit = new wxTextCtrl(page, -1, std2wx(spell->name), wxPoint(220,80), wxSize(200,25));
48 
49 	// symbol
50 	new wxStaticText(page, -1, _("Symbol"), wxPoint(430,60));
51 	symbolEdit = new wxTextCtrl(page, -1, std2wx(spell->symbol), wxPoint(430,80), wxSize(150,25));
52 
53 	// level
54 	new wxStaticText(page, -1, _("Level"), wxPoint(590,60));
55 	levelEdit = new wxTextCtrl(page, -1, std2wx(spell->level), wxPoint(590,80), wxSize(50,25));
56 
57 	// mana
58 	new wxStaticText(page, -1, _("Mana"), wxPoint(650,60));
59 	manaEdit = new wxTextCtrl(page, -1, std2wx(spell->mana), wxPoint(650,80), wxSize(50,25));
60 
61 	// exp
62 	new wxStaticText(page, -1, _("Exp"), wxPoint(10,130));
63 	expEdit = new wxTextCtrl(page, -1, std2wx(spell->exp), wxPoint(10,150), wxSize(50,-1));
64 
65 	// failure rate
66 	new wxStaticText(page, -1, _("Failure Rate"), wxPoint(70,130));
67 	failureRateEdit = new wxTextCtrl(page, -1, std2wx(spell->failureRate), wxPoint(70,150), wxSize(50,25));
68 
69 	// action
70 	new wxStaticText(page, -1, _("Action"), wxPoint(160,130));
71 	actionEdit = new wxTextCtrl(page, -1, std2wx(spell->action), wxPoint(160,150), wxSize(100,25));
72 
73 	// distance
74 	new wxStaticText(page, -1, _("Distance"), wxPoint(270,130));
75 	distanceEdit = new wxTextCtrl(page, -1, std2wx(spell->distance), wxPoint(270,150), wxSize(50,25));
76 
77 	// area
78 	new wxStaticText(page, -1, _("Area"), wxPoint(330,130));
79 	wxString choices[2] = { L"single", L"group" };
80 	areaCombo = new wxComboBox(page, -1, std2wx(spell->area), wxPoint(330,150),wxSize(80,25),
81 			2,choices, wxCB_READONLY);
82 
83 	// CLIP
84 	new wxStaticText(page, -1, _("Targets"), wxPoint(420,130));
85 	wxString clipStr[] = { L"Creature", L"Location", L"Item", L"Party" };
86 	clipCheckList = new wxCheckListBox(page, -1, wxPoint(420,150), wxSize(85,90), 4,clipStr);
87 	clipCheckList->Check(0, spell->target.find("C") != std::string::npos );
88 	clipCheckList->Check(1, spell->target.find("L") != std::string::npos );
89 	clipCheckList->Check(2, spell->target.find("I") != std::string::npos );
90 	clipCheckList->Check(3, spell->target.find("P") != std::string::npos );
91 
92 	// speed
93 	new wxStaticText(page, -1, _("Speed"), wxPoint(515,130));
94 	speedEdit = new wxTextCtrl(page, -1, std2wx(spell->speed), wxPoint(515,150), wxSize(50,25));
95 
96 	// effect
97 	new wxStaticText(page, -1, _("Effect"), wxPoint(575,130));
98 	effectEdit = new wxTextCtrl(page, -1, std2wx(spell->effect), wxPoint(575,150), wxSize(150,25));
99 
100 /**
101 	Icon
102 **/
103 	new wxStaticText(page, -1, _("Icon (x,y)"), wxPoint(25,180));
104 	// icon_x
105 	int x = atoi( spell->icon_x.c_str() );
106 	iconXEdit = new wxTextCtrl(page, -1, std2wx(spell->icon_x), wxPoint(10,200), wxSize(30,25));
107 	iconXScroll = new wxScrollBar(page, ID_subSpellsIconXScroll, wxPoint(40,200), wxSize(-1,25), wxSB_VERTICAL);
108 		iconXScroll->SetScrollbar(x,1,20,1);
109 	// icon_y
110 	int y = atoi( spell->icon_y.c_str() );
111 	iconYEdit = new wxTextCtrl(page, -1, std2wx(spell->icon_y), wxPoint(55,200), wxSize(30,25));
112 	iconYScroll = new wxScrollBar(page, ID_subSpellsIconYScroll, wxPoint(85,200), wxSize(-1,25), wxSB_VERTICAL);
113 		iconYScroll->SetScrollbar(y,1,17,1);
114 	// Make sure the icon is painted when tabs are changed
115 	page->Connect( wxEVT_PAINT, (wxObjectEventFunction)&subPageSpells::OnPaint, NULL, (wxEvtHandler*)this);
116 
117 
118 	// disposition
119 	new wxStaticText(page, -1, _("Disposition"), wxPoint(160,180));
120 	wxString dispositionChoices[2] = { L"Friendly", L"Hostile" };
121 	wxString disposition = L"Friendly";
122 	if ( spell->disposition == "H" )	disposition = L"Hostile";
123 	dispositionCombo = new wxComboBox(page, -1, disposition, wxPoint(160,200),wxSize(80,25),
124 			2,dispositionChoices, wxCB_READONLY);
125 
126 	// prerequisite
127 	new wxStaticText(page, -1, _("Prerequisite"), wxPoint(250,180));
128 	wxString prereqChoices[] = { L"-none-", L"HP", L"AC",
129 			L"blessed", L"empowered", L"enraged", L"ac_protected", L"magic_protected", L"invisible",	// good
130 			L"drunk", L"poisoned", L"cursed", L"possessed", L"blinded", L"charmed", L"dead",			// bad
131 			L"overloaded", L"leveled" };																// neutral
132 	wxString prereq = std2wx(spell->prerequisite);
133 	if ( prereq == L"" )	prereq = L"-none-";
134 	prereqCombo = new wxComboBox(page, -1, std2wx(spell->prerequisite), wxPoint(250,200),wxSize(130,25),
135 			17,prereqChoices, wxCB_READONLY);
136 
137 	// sound
138 	new wxStaticText(page, -1, _("Sound"), wxPoint(160,230));
139 	soundEdit = new wxTextCtrl(page, -1, std2wx(spell->sound), wxPoint(160,250), wxSize(200,25));
140 
141 	// notes
142 	new wxStaticText(page, -1, _("Notes"), wxPoint(515,180));
143 	notesEdit = new wxTextCtrl(page, -1, std2wx(spell->notes), wxPoint(515,200), wxSize(230,90), wxTE_MULTILINE);
144 
145 
146 	notebook->AddPage(page, _("Spells"));
147 }
148 
UpdatePage()149 void subPageSpells::UpdatePage()
150 {
151 /**
152 	Schools
153 **/
154 	new wxStaticText(page, -1, L"Schools", wxPoint(10,10));
155 	schoolStrArray->Clear();
156 	for ( std::vector<School*>::iterator itr = dfSpells->data.begin(); itr != dfSpells->data.end(); itr++ )
157 		schoolStrArray->Add( std2wx( (*itr)->name ) );
158 	schoolList->Set(*schoolStrArray);
159 }
160 
Prev(unsigned int n)161 void subPageSpells::Prev(unsigned int n)
162 {
163 	SetCurrent();
164 
165 	std::vector<Spell*> *pSpells = &currentSchool->spells;
166 
167 	if ( n > spellNumber )
168 	{
169 		spellItr = pSpells->begin();
170 		currentSpell = *spellItr;
171 		spellNumber = 1;
172 		return;
173 	}
174 
175 	for ( ; n > 0; n-- )
176 	{
177 		spellNumber--;
178 		if ( spellItr == pSpells->begin() )
179 		{
180 			spellItr = pSpells->end();
181 			spellNumber = currentSchool->spells.size();
182 		}
183 		spellItr--;
184 		currentSpell = *spellItr;
185 	}
186 
187 	GetCurrent();
188 }
Next(unsigned int n)189 void subPageSpells::Next(unsigned int n)
190 {
191 	SetCurrent();
192 
193 	std::vector<Spell*> *pSpells = &currentSchool->spells;
194 
195 	if ( n > (pSpells->size()-spellNumber) && n!=1 )
196 	{
197 		spellItr = pSpells->end();
198 		spellItr--;
199 		currentSpell = *spellItr;
200 		spellNumber = pSpells->size();
201 		return;
202 	}
203 
204 	for ( ; n > 0; n-- )
205 	{
206 		spellItr++;
207 		spellNumber++;
208 		if ( spellItr == pSpells->end() )
209 		{
210 			spellItr = pSpells->begin();
211 			spellNumber = 1;
212 		}
213 		currentSpell = *spellItr;
214 	}
215 
216 	GetCurrent();
217 }
New()218 void subPageSpells::New()
219 {
220 	SetCurrent();
221 
222 //	School *school = dfSpells->GetCurrent();			!! DON'T DO THIS !!
223 	School *school = currentSchool;
224 	Spell *spell = new Spell;
225 
226 	school->spells.push_back( spell );
227 
228 	spellItr = school->spells.end();	spellItr--;
229 	currentSpell = *spellItr;
230 	spellNumber = school->spells.size();
231 
232 	GetCurrent();
233 }
Del()234 void subPageSpells::Del()
235 {
236 	School *school = currentSchool;
237 
238 	if ( school->spells.size() == 1 )
239 	{
240 		currentSpell->Clear();
241 		GetCurrent();
242 		return;
243 	}
244 	spellItr = school->spells.erase(spellItr);
245 	delete currentSpell;
246 	currentSpell = *spellItr;
247 
248 	GetCurrent();
249 }
250 
UpdatePageNumber()251 void subPageSpells::UpdatePageNumber()
252 {
253 	char buffer[64];
254 	sprintf(buffer, "Page %i/%i", spellNumber, currentSchool->spells.size());
255 	g_pageNumText->SetLabel(std2wx(buffer));
256 }
257 
GetCurrent()258 void subPageSpells::GetCurrent()
259 {
260 	Spell *spell = currentSpell;
261 
262 	nameEdit->SetValue(std2wx(spell->name));
263 	symbolEdit->SetValue(std2wx(spell->symbol));
264 	levelEdit->SetValue(std2wx(spell->level));
265 	manaEdit->SetValue(std2wx(spell->mana));
266 	expEdit->SetValue(std2wx(spell->exp));
267 	failureRateEdit->SetValue(std2wx(spell->failureRate));
268 	actionEdit->SetValue(std2wx(spell->action));
269 	distanceEdit->SetValue(std2wx(spell->distance));
270 	areaCombo->SetValue(std2wx(spell->area));
271 
272 	// CLIP
273 	clipCheckList->Check(0, spell->target.find("C") != std::string::npos );
274 	clipCheckList->Check(1, spell->target.find("L") != std::string::npos );
275 	clipCheckList->Check(2, spell->target.find("I") != std::string::npos );
276 	clipCheckList->Check(3, spell->target.find("P") != std::string::npos );
277 
278 
279 	speedEdit->SetValue(std2wx(spell->speed));
280 	effectEdit->SetValue(std2wx(spell->effect));
281 
282 	// icon
283 	int x = atoi( spell->icon_x.c_str() );
284 	iconXEdit->SetValue( std2wx(spell->icon_x) );
285 		iconXScroll->SetScrollbar(x,1,20,1);
286 	int y = atoi( spell->icon_y.c_str() );
287 	iconYEdit->SetValue( std2wx(spell->icon_y) );
288 		iconYScroll->SetScrollbar(y,1,17,1);
289 	UpdateIcon();
290 
291 	// disposition
292 	wxString disposition = L"Friendly";
293 	if ( spell->disposition == "H" )	disposition = L"Hostile";
294 	dispositionCombo->SetValue(disposition);
295 
296 	wxString prereq = std2wx(spell->prerequisite);
297 	if ( prereq == L"" )	prereq = L"-none-";
298 	prereqCombo->SetValue(prereq);
299 
300 	soundEdit->SetValue(std2wx(spell->sound));
301 	notesEdit->SetValue(std2wx(spell->notes));
302 }
303 void subPageSpells::SetCurrent()
304 {
305 	Spell *spell = currentSpell;
306 
307 	spell->name = wx2std( nameEdit->GetValue() );
308 	spell->symbol = wx2std( symbolEdit->GetValue() );
309 	spell->level = wx2std( levelEdit->GetValue() );
310 	spell->mana = wx2std( manaEdit->GetValue() );
311 	spell->exp = wx2std( expEdit->GetValue() );
312 	spell->failureRate = wx2std( failureRateEdit->GetValue() );
313 	spell->action = wx2std( actionEdit->GetValue() );
314 	spell->distance = wx2std( distanceEdit->GetValue() );
315 	spell->area = wx2std( areaCombo->GetValue() );
316 
317 	// CLIP
318 	spell->target = "";
319 	if ( clipCheckList->IsChecked(0) ) spell->target += "C";
320 	if ( clipCheckList->IsChecked(1) ) spell->target += "L";
321 	if ( clipCheckList->IsChecked(2) ) spell->target += "I";
322 	if ( clipCheckList->IsChecked(3) ) spell->target += "P";
323 
324 	spell->speed = wx2std( speedEdit->GetValue() );
325 	spell->effect = wx2std( effectEdit->GetValue() );
326 
327 	// icon
328 	spell->icon_x = wx2std( iconXEdit->GetValue() );
329 	spell->icon_y = wx2std( iconYEdit->GetValue() );
330 	if ( spell->icon_x == "0" )		spell->icon_x = "1";
331 	if ( spell->icon_y == "0" )		spell->icon_y = "1";
332 
333 	// disposition
334 	spell->disposition = "F";
335 	if ( dispositionCombo->GetValue() == L"Hostile" )	spell->disposition = "H";
336 
337 	spell->prerequisite = wx2std( prereqCombo->GetValue() );
338 	if ( spell->prerequisite == "-none-" )
339 		spell->prerequisite = "";
340 
341 	spell->sound = wx2std( soundEdit->GetValue() );
342 	spell->notes = wx2std( notesEdit->GetValue() );
ClearCurrent()343 }
344 void subPageSpells::ClearCurrent()
345 {
346 	Spell *spell = currentSpell;
347 
348 	spell->Clear();
349 }
GetSelectedSchool()350 
351 School* subPageSpells::GetSelectedSchool()
352 {
353 	wxArrayInt selected;
354 	if ( schoolList->GetSelections(selected) == 0 )
355 		return 0;
356 
357 	wxArrayString *pSchoolStrArray = schoolStrArray;
358 	wxString *schoolName = &(*pSchoolStrArray)[ (selected[0]) ];
359 
360 	for ( unsigned int i = 0; i < dfSpells->data.size(); i++ )
361 		if ( dfSpells->data[i]->name == wx2std(*schoolName) )
362 			currentSchool = dfSpells->data[i];
363 
364 	spellItr = currentSchool->spells.begin();
365 	currentSpell = *spellItr;
366 	spellNumber = 1;
367 
368 	schoolNameText->SetLabel( *schoolName );
369 
370 	return currentSchool;
371 }
OnSchoolChange()372 
373 void subPageSpells::OnSchoolChange()
374 {
375 	subPageSpells *pPage = ((PageSpells*)currentPage)->pageSpells;
376 
377 	pPage->SetCurrent();
378 	pPage->GetSelectedSchool();
379 	pPage->GetCurrent();
380 
381 	pPage->UpdatePageNumber();
382 }
OnIconXChange()383 
384 void subPageSpells::OnIconXChange()
385 {
386 	subPageSpells *pPage = ((PageSpells*)currentPage)->pageSpells;
387 	int newPos = pPage->iconXScroll->GetThumbPosition();
388 
389 	char buffer[16]; sprintf(buffer, "%i", newPos);
390 	pPage->iconXEdit->SetValue( std2wx( buffer ) );
391 
392 	pPage->UpdateIcon();
393 }
394 void subPageSpells::OnIconYChange()
395 {
396 	subPageSpells *pPage = ((PageSpells*)currentPage)->pageSpells;
397 	int newPos = pPage->iconYScroll->GetThumbPosition();
398 
399 	char buffer[16]; sprintf(buffer, "%i", newPos);
400 	pPage->iconYEdit->SetValue( std2wx( buffer ) );
401 
402 	pPage->UpdateIcon();
403 
UpdateIcon()404 }
405 void subPageSpells::UpdateIcon()
406 {
407 	wxImage image(std2wx(GetDataPath("%s/textures/spells.bmp")));
408 	wxBitmap bitmap(image);
409 
410 	int icon_x = iconXScroll->GetThumbPosition();
411 	int icon_y = iconYScroll->GetThumbPosition();
412 	if ( icon_x == 0 ) icon_x = 1;
413 	if ( icon_y == 0 ) icon_y = 1;
414 	wxBitmap icon = bitmap.GetSubBitmap( wxRect(32*(icon_x-1),32*(icon_y-1),32,32) );
415 
416 	wxClientDC dc(page);
417 	dc.DrawBitmap(icon, 35,230, false);
418 }
OnPaint()419 
420 void subPageSpells::OnPaint()
421 {
422 	UpdateIcon();
423 }
424