1 | #include "wmsetuppage.h"
|
---|
2 | #include "ui_wmsetuppage.h"
|
---|
3 |
|
---|
4 | WmSetupPage::WmSetupPage(QWidget *parent) :
|
---|
5 | QWizardPage(parent),
|
---|
6 | ui(new Ui::WmSetupPage)
|
---|
7 | {
|
---|
8 | ui->setupUi(this);
|
---|
9 |
|
---|
10 | this->setTitle("Type of Window");
|
---|
11 | this->setSubTitle("Choose here what kind of pages do you want to create, to be displayed in the game.");
|
---|
12 |
|
---|
13 | // Initialize combobox (hacky!)
|
---|
14 | for(int i=0; i<static_cast<int>(WINDOW_TYPE::ENUM_END); i++){
|
---|
15 | ui->cbWindowType->addItem(getWindowTypeDescription(static_cast<WINDOW_TYPE>(i)));
|
---|
16 | }
|
---|
17 |
|
---|
18 | //Register fields to be accessible in another pages //Not using mandatory field, it would require empty verification too...
|
---|
19 | registerField("cbWindowType", ui->cbWindowType);
|
---|
20 | registerField("leLevelId", ui->leLevelId);
|
---|
21 | registerField("leFileName", ui->leFileName);
|
---|
22 | registerField("lePageNumber", ui->lePageNumber);
|
---|
23 | registerField("leWeaponClassName", ui->leWeaponClassName);
|
---|
24 | registerField("cbIsLearnedMove", ui->cbIsLearnedMove);
|
---|
25 | }
|
---|
26 |
|
---|
27 | WmSetupPage::~WmSetupPage()
|
---|
28 | {
|
---|
29 | delete ui;
|
---|
30 | }
|
---|
31 |
|
---|
32 | bool WmSetupPage::validatePage(){
|
---|
33 |
|
---|
34 | QStringList stringsToCheck;
|
---|
35 |
|
---|
36 | stringsToCheck << ui->leFileName->text();
|
---|
37 |
|
---|
38 | if((ui->lePageNumber->isEnabled())){
|
---|
39 | stringsToCheck << ui->lePageNumber->text();
|
---|
40 | }
|
---|
41 | if((ui->leLevelId->isEnabled())){
|
---|
42 | stringsToCheck << ui->leLevelId->text();
|
---|
43 | }
|
---|
44 | if((ui->leWeaponClassName->isEnabled())){
|
---|
45 | stringsToCheck << ui->leWeaponClassName->text();
|
---|
46 | }
|
---|
47 |
|
---|
48 | if(Util::checkEmptySpaces(stringsToCheck)){
|
---|
49 | Util::showErrorPopUp("You need to fill all fields first!");
|
---|
50 | return false;
|
---|
51 | }
|
---|
52 |
|
---|
53 | return true;
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 |
|
---|
58 | void WmSetupPage::on_leLevelId_textChanged(const QString &arg1)
|
---|
59 | {
|
---|
60 | if(arg1.trimmed().isEmpty()){
|
---|
61 | return;
|
---|
62 | }
|
---|
63 |
|
---|
64 | if(!Util::isStringInteger(arg1)){
|
---|
65 | Util::showErrorPopUp("The level id inputted is invalid! It must be a number.");
|
---|
66 | return;
|
---|
67 | }
|
---|
68 |
|
---|
69 | switch(static_cast<WINDOW_TYPE>(ui->cbWindowType->currentIndex())){
|
---|
70 | case WINDOW_TYPE::OBJECTIVE:
|
---|
71 | ui->leFileName->setText(QString("OPgelevel_") + arg1.trimmed());
|
---|
72 | break;
|
---|
73 | case WINDOW_TYPE::DIARY:
|
---|
74 | generateDiaryFileName();
|
---|
75 | break;
|
---|
76 | case WINDOW_TYPE::TEXT_CONSOLE:
|
---|
77 | ui->leFileName->setText(QString("TxtClevel_") + arg1.trimmed());
|
---|
78 | break;
|
---|
79 | case WINDOW_TYPE::HELP:
|
---|
80 | case WINDOW_TYPE::WEAPON:
|
---|
81 | case WINDOW_TYPE::ITEM:
|
---|
82 | case WINDOW_TYPE::ENUM_END:
|
---|
83 | break;
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 | void WmSetupPage::on_lePageNumber_textChanged(const QString &arg1)
|
---|
88 | {
|
---|
89 | if(arg1.trimmed().isEmpty()){
|
---|
90 | return;
|
---|
91 | }
|
---|
92 |
|
---|
93 | if(!Util::isStringInteger(arg1)){
|
---|
94 | Util::showErrorPopUp("The page number inputted is invalid! It must be a number.");
|
---|
95 | return;
|
---|
96 | }
|
---|
97 |
|
---|
98 | switch(static_cast<WINDOW_TYPE>(ui->cbWindowType->currentIndex())){
|
---|
99 | case WINDOW_TYPE::DIARY:
|
---|
100 | generateDiaryFileName();
|
---|
101 | break;
|
---|
102 | case WINDOW_TYPE::ITEM:
|
---|
103 | ui->leFileName->setText("IPge");
|
---|
104 | break;
|
---|
105 | case WINDOW_TYPE::OBJECTIVE:
|
---|
106 | case WINDOW_TYPE::TEXT_CONSOLE:
|
---|
107 | case WINDOW_TYPE::HELP:
|
---|
108 | case WINDOW_TYPE::WEAPON:
|
---|
109 | case WINDOW_TYPE::ENUM_END:
|
---|
110 | break;
|
---|
111 | }
|
---|
112 |
|
---|
113 | }
|
---|
114 |
|
---|
115 | void WmSetupPage::on_cbWindowType_currentTextChanged(const QString &arg1)
|
---|
116 | {
|
---|
117 | // when we hide the widgets qt will left some empty space, to remove this space we remove and add also the widgets:
|
---|
118 | // http://stackoverflow.com/questions/17986164/how-to-removing-remaining-spacing-after-hide-a-row-in-qformlayout
|
---|
119 |
|
---|
120 | ui->leLevelId->setEnabled(false);
|
---|
121 | ui->lePageNumber->setEnabled(false);
|
---|
122 | ui->leWeaponClassName->setEnabled(false);
|
---|
123 | ui->cbIsLearnedMove->setEnabled(false);
|
---|
124 |
|
---|
125 | if(arg1 == getWindowTypeDescription(WINDOW_TYPE::DIARY)){
|
---|
126 | ui->leLevelId->setEnabled(true);
|
---|
127 | ui->lePageNumber->setEnabled(true);
|
---|
128 | ui->cbIsLearnedMove->setEnabled(true);
|
---|
129 | }
|
---|
130 | else if(arg1 == getWindowTypeDescription(WINDOW_TYPE::WEAPON)){
|
---|
131 | ui->leWeaponClassName->setEnabled(true);
|
---|
132 | }
|
---|
133 | else if(arg1 == getWindowTypeDescription(WINDOW_TYPE::ITEM)){
|
---|
134 | ui->lePageNumber->setEnabled(true);
|
---|
135 | }
|
---|
136 | else if(arg1 == getWindowTypeDescription(WINDOW_TYPE::HELP)){
|
---|
137 | ui->leFileName->setText("HPgehelp_pg_01");
|
---|
138 | }
|
---|
139 | else{
|
---|
140 | ui->leLevelId->setEnabled(true);
|
---|
141 | }
|
---|
142 | }
|
---|
143 |
|
---|
144 | void WmSetupPage::on_leWeaponClassName_textChanged(const QString &arg1)
|
---|
145 | {
|
---|
146 | ui->leFileName->setText(QString("WPge") + arg1.trimmed().replace("ONWC",""));
|
---|
147 | }
|
---|
148 |
|
---|
149 | QString WmSetupPage::getWindowTypeDescription(const WINDOW_TYPE wt){
|
---|
150 | switch(wt){
|
---|
151 | case WINDOW_TYPE::OBJECTIVE:
|
---|
152 | return "Objective Page(s) [OPge]";
|
---|
153 | case WINDOW_TYPE::TEXT_CONSOLE:
|
---|
154 | return "Text Console Pages(s) [TxtC]";
|
---|
155 | case WINDOW_TYPE::WEAPON:
|
---|
156 | return "Weapon Page(s) [WPge]";
|
---|
157 | case WINDOW_TYPE::ITEM:
|
---|
158 | return "Item Pages(s) [IPge]";
|
---|
159 | case WINDOW_TYPE::DIARY:
|
---|
160 | return "Diary Page [DPge]";
|
---|
161 | case WINDOW_TYPE::HELP:
|
---|
162 | return "Help Page(s) [HPge]";
|
---|
163 | default:
|
---|
164 | return "ERROR WINDOW_TYPE ENUM";
|
---|
165 | }
|
---|
166 |
|
---|
167 | }
|
---|
168 |
|
---|
169 | void WmSetupPage::generateDiaryFileName(){
|
---|
170 | ui->leFileName->setText(QString("DPgelev_") + (ui->leLevelId->text().trimmed().length() == 1 ? "0" : "") + ui->leLevelId->text() + "_" + ui->lePageNumber->text());
|
---|
171 | }
|
---|