1 #include "subpageskills.h"
2 #include "pagerpg.h"
3 #include "dfrpg.h"
4 #include <wx/wx.h>
5 #include <wx/spinctrl.h>
6 #include "listadddel.h"
7 #include "common.h"
8 #include "../common/constants.h"
9 
subPageSkills()10 subPageSkills::subPageSkills()
11 {
12 	//ctor
13 	currentSkillName = new wxString;
14 }
15 
~subPageSkills()16 subPageSkills::~subPageSkills()
17 {
18 	//dtor
19 	delete currentSkillName;
20 }
21 
Init(wxNotebook * notebook,DF * dataFile,PageRpg * parent)22 void subPageSkills::Init(wxNotebook *notebook, DF *dataFile, PageRpg *parent)
23 {
24 	dfRpg = (DFRpg*)dataFile;
25 	this->dataFile = dataFile;
26 	page = new wxNotebookPage(notebook, ID_Skills_subPage);
27 	this->parent = parent;
28 
29 	Group *group = dfRpg->GetCurrent();
30 
31 	// name
32 	new wxStaticText(page, -1, _("Name"), wxPoint(10,10));
33 	nameEdit = new wxTextCtrl(page, -1, std2wx(group->name), wxPoint(10,30), wxSize(200,25));
34 
35 	// group description
36 	new wxStaticText(page, -1, _("Description"), wxPoint(10,60));
37 	descEdit = new wxTextCtrl(page, -1, std2wx(group->description), wxPoint(10,80), wxSize(260,80), wxTE_MULTILINE);
38 
39 /** Skills **/
40 	new wxStaticBox(page, -1, L"Skills", wxPoint(290,10),wxSize(540,280));
41 
42 	// skills
43 	skillList = new ListAddDel;
44 	skillList->Init(page, L"", group->skills, 300,20, 260);
45 	skillList->GetList()->Connect( wxEVT_COMMAND_LISTBOX_SELECTED, (wxObjectEventFunction)&subPageSkills::OnSkillChange, NULL, (wxEvtHandler*)this);
46 	currentSkill = (Skill*)group->skills[0];
47 	// skill name
48 	skillNameText = new wxStaticText(page, -1, std2wx(currentSkill->name), wxPoint(300,20));
49 		skillNameText->SetFont( wxFont(10,wxFONTFAMILY_DEFAULT,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD) );
50 
51 	// symbol
52 	new wxStaticText(page, -1, _("Symbol"), wxPoint(300,185));
53 	symbolEdit = new wxTextCtrl(page, -1, std2wx( currentSkill->symbol ), wxPoint(300,205), wxSize(100,25));
54 
55 	// skill description
56 	new wxStaticText(page, -1, _("Description"), wxPoint(410,185));
57 	skillDescEdit = new wxTextCtrl(page, -1, std2wx(currentSkill->description), wxPoint(410,205), wxSize(350,60), wxTE_MULTILINE);
58 
59 	// multiplier
60 	multiplierText = new wxStaticText(page, -1, _("Multiplier"), wxPoint(715,150));
61 	multiplierSpin = new wxSpinCtrl(page, -1, L"", wxPoint(770,145),wxSize(45,-1), wxSP_ARROW_KEYS, 0,5, atoi(currentSkill->multiplier.c_str()));
62 	// multiplied stats
63 	statList = new ListAddDel;
64 	statList->Init(page, L"Multiplied Stats", currentSkill->statNames, 580,20);
65 
66 	bool hasStats = ( group->name != "BASIC_GROUP" );
67 	statList->Show( hasStats );
68 	multiplierSpin->Show( hasStats );
69 	multiplierText->Show( hasStats );
70 
71 	notebook->AddPage(page, _("Skills"));
72 }
73 
UpdatePage()74 void subPageSkills::UpdatePage()
75 {
76 }
77 
GetCurrent()78 void subPageSkills::GetCurrent()
79 {
80 	Group *group = dfRpg->GetCurrent();
81 
82 	nameEdit->SetValue( std2wx(group->name) );
83 	descEdit->SetValue( std2wx(group->description) );
84 	skillList->Get( group->skills );
85 
86 	bool hasStats = ( group->name != "BASIC_GROUP" );
87 	statList->Show( hasStats );
88 	multiplierSpin->Show( hasStats );
89 	multiplierText->Show( hasStats );
90 
91 	GetSkill();
92 }
SetCurrent()93 void subPageSkills::SetCurrent()
94 {
95 	Group *group = dfRpg->GetCurrent();
96 
97 	group->name = wx2std( nameEdit->GetValue() );
98 	group->description = wx2std( descEdit->GetValue() );
99 
100 	SetSkill();
101 }
102 
GetSkill()103 void subPageSkills::GetSkill()
104 {
105 //	Group *group = dfRpg->GetCurrent();
106 	skillList->SetListSelection(0);		// So there is a selection after clicking next
107 
108 	Skill *skill = GetSelectedSkill();
109 	if ( skill )
110 	{
111 		skillNameText->SetLabel( *currentSkillName );
112 		symbolEdit->SetValue( std2wx( skill->symbol ) );
113 		skillDescEdit->SetValue( std2wx( skill->description ) );
114 		multiplierSpin->SetValue( std2wx(skill->multiplier) );
115 
116 		statList->Get( skill->statNames );
117 	}
118 }
SetSkill()119 void subPageSkills::SetSkill()
120 {
121 	Skill *skill = currentSkill;
122 	if ( skill )
123 	{
124 		skill->symbol = wx2std( symbolEdit->GetValue() );
125 		skill->description = wx2std( skillDescEdit->GetValue() );
126 
127 		char buffer[16];
128 		sprintf(buffer, "%i", multiplierSpin->GetValue() );
129 		skill->multiplier = buffer;
130 	}
131 }
132 
ClearCurrent()133 void subPageSkills::ClearCurrent()
134 {
135 }
136 
GetSelectedSkill()137 Skill* subPageSkills::GetSelectedSkill()
138 {
139 //	Group *group = dfRpg->GetCurrent();
140 
141 	wxListBox *pList = skillList->GetList();
142 	*currentSkillName = pList->GetString( pList->GetSelection() );
143 	Skill *skill = (Skill*)skillList->GetPointer( wx2std(*currentSkillName) );
144 	if ( skill )
145 		currentSkill = skill;
146 
147 	return currentSkill;
148 }
149 
OnSkillChange()150 void subPageSkills::OnSkillChange()
151 {
152 //	Group *group = dfRpg->GetCurrent();
153 
154 	SetSkill();
155 
156 	GetSelectedSkill();
157 
158 	skillNameText->SetLabel( *currentSkillName );
159 
160 	symbolEdit->SetValue( std2wx( currentSkill->symbol ) );
161 	skillDescEdit->SetValue( std2wx( currentSkill->description ) );
162 	multiplierSpin->SetValue( std2wx(currentSkill->multiplier) );
163 
164 	statList->Get( currentSkill->statNames );
165 }
166