3
3
//
4
4
5
5
#include " charactercreator.h"
6
-
7
6
#include < ranges>
8
7
9
- #define CONTROLS 3
8
+ #define CONTROLS 6
9
+ #define LEFT 2
10
+ #define COLUMN_2 16
11
+ #define COLUMN_3 48
12
+
13
+ using namespace ui ;
10
14
11
15
CharacterCreator::CharacterCreator (const std::shared_ptr<Game> &game, const MessageHandler& message_handler) : NCursesView(game, message_handler) {
12
16
new_game = game->StartNewGame ();
@@ -16,7 +20,7 @@ CharacterCreator::CharacterCreator(const std::shared_ptr<Game> &game, const Mess
16
20
17
21
void CharacterCreator::ShowPopup (const std::string &label, const std::vector<std::string> &items, const int current_index) const {
18
22
const int desired_rows = static_cast <int >(items.size ());
19
- const int rows = std::min (screen_height - 4 , desired_rows);
23
+ const int rows = std::min (24 - 4 , desired_rows);
20
24
int skip = 0 ;
21
25
WINDOW *w = subwin (win, rows + 2 , 30 , 1 , 4 );
22
26
wclear (w);
@@ -53,7 +57,9 @@ void CharacterCreator::ShowPopup(const std::string &label, const std::vector<std
53
57
void CharacterCreator::Resize (const int new_screen_width, const int new_screen_height) {
54
58
NCursesView::Resize (new_screen_width, new_screen_height);
55
59
delwin (win);
56
- win = newwin (0 , 0 , 0 , 0 );
60
+ constexpr int required_width = 80 ;
61
+ constexpr int required_height = 24 ;
62
+ win = newwin (required_height, required_width, 0 , 0 );
57
63
keypad (win, true );
58
64
nodelay (win, true );
59
65
wtimeout (win, 100 );
@@ -62,35 +68,79 @@ void CharacterCreator::Resize(const int new_screen_width, const int new_screen_h
62
68
void CharacterCreator::Render () {
63
69
wclear (win);
64
70
box (win, 0 , 0 );
65
- LeftAlign (win, " Progress Quest 2" , 2 , 0 );
66
- LeftAlign (win, " Name:" , 2 , 2 );
71
+ LeftAlign (win, " Progress Quest 2" , LEFT , 0 );
72
+ LeftAlign (win, " Name:" , LEFT , 2 );
67
73
if (selected_control == 0 ) {
68
74
wattron (win, A_UNDERLINE);
69
75
}
70
76
const auto name = new_game->GetName ();
71
- LeftAlign (win, name, 9 , 2 );
77
+ LeftAlign (win, name, COLUMN_2 , 2 );
72
78
wattroff (win, A_UNDERLINE);
73
79
if (selected_control == 0 ) {
74
80
wattron (win, A_REVERSE);
75
- mvwaddch (win, 2 , 9 + name.size (), ' ' );
81
+ mvwaddch (win, 2 , COLUMN_2 + name.size (), ' ' );
76
82
wattroff (win, A_REVERSE);
77
83
}
78
84
if (selected_control == 1 ) {
79
85
wattron (win, A_STANDOUT);
80
86
}
81
- LeftAlign (win, " ? " , 40 , 2 );
87
+ RightAlign (win, " Random " , COLUMN_3 , 2 );
82
88
wattroff (win, A_STANDOUT);
83
- LeftAlign (win, " Race:" , 2 , 3 );
89
+ LeftAlign (win, " Race:" , LEFT , 3 );
84
90
if (selected_control == 2 ) {
85
91
wattron (win, A_STANDOUT);
86
92
}
87
- LeftAlign (win, new_game->GetRace (), 9 , 3 );
93
+ LeftAlign (win, new_game->GetRace (), COLUMN_2 , 3 );
88
94
wattroff (win, A_STANDOUT);
89
- LeftAlign (win, " Class:" , 2 , 4 );
95
+ LeftAlign (win, " Class:" , LEFT , 4 );
90
96
if (selected_control == 3 ) {
91
97
wattron (win, A_STANDOUT);
92
98
}
93
- LeftAlign (win, new_game->GetClass (), 9 , 4 );
99
+ LeftAlign (win, new_game->GetClass (), COLUMN_2, 4 );
100
+ wattroff (win, A_STANDOUT);
101
+ LeftAlign (win, " Stats:" , LEFT, 6 );
102
+ LeftAlign (win, " STR:" , LEFT, 7 );
103
+ LeftAlign (win, std::to_string (new_game->GetSTR ()), COLUMN_2, 7 );
104
+ LeftAlign (win, " CON:" , LEFT, 8 );
105
+ LeftAlign (win, std::to_string (new_game->GetCON ()), COLUMN_2, 8 );
106
+ LeftAlign (win, " DEX:" , LEFT, 9 );
107
+ LeftAlign (win, std::to_string (new_game->GetDEX ()), COLUMN_2, 9 );
108
+ LeftAlign (win, " INT:" , LEFT, 10 );
109
+ LeftAlign (win, std::to_string (new_game->GetINT ()), COLUMN_2, 10 );
110
+ LeftAlign (win, " WIS:" , LEFT, 11 );
111
+ LeftAlign (win, std::to_string (new_game->GetWIS ()), COLUMN_2, 11 );
112
+ LeftAlign (win, " CHA:" , LEFT, 12 );
113
+ LeftAlign (win, std::to_string (new_game->GetCHA ()), COLUMN_2, 12 );
114
+ LeftAlign (win, std::string (COLUMN_2 + 6 , ' -' ), LEFT, 13 );
115
+ LeftAlign (win, " TOTAL:" , LEFT, 14 );
116
+ LeftAlign (win, std::to_string (new_game->GetTotal ()), COLUMN_2, 14 );
117
+ const auto colour = new_game->GetTotalColor ();
118
+ if (colour == ColorRed) {
119
+ LeftAlign (win, " ++" , COLUMN_2 + 3 , 14 );
120
+ }
121
+ else if (colour == ColorYellow) {
122
+ LeftAlign (win, " +" , COLUMN_2 + 3 , 14 );
123
+ }
124
+ else if (colour == ColorSilver) {
125
+ RightAlign (win, " -" , COLUMN_2 - 1 , 14 );
126
+ }
127
+ else if (colour == ColorGray) {
128
+ RightAlign (win, " --" , COLUMN_2 - 1 , 14 );
129
+ }
130
+ if (selected_control == 4 ) {
131
+ wattron (win, A_STANDOUT);
132
+ }
133
+ LeftAlign (win, " Roll" , LEFT, 16 );
134
+ wattroff (win, A_STANDOUT);
135
+ if (selected_control == 5 ) {
136
+ wattron (win, A_STANDOUT);
137
+ }
138
+ LeftAlign (win, " Unroll" , COLUMN_2, 16 );
139
+ wattroff (win, A_STANDOUT);
140
+ if (selected_control == 6 ) {
141
+ wattron (win, A_STANDOUT);
142
+ }
143
+ LeftAlign (win, " Sold!" , LEFT, 22 );
94
144
wattroff (win, A_STANDOUT);
95
145
if (show_race_popup) {
96
146
ShowPopup (" Race:" , races, race_index);
@@ -141,7 +191,7 @@ void CharacterCreator::Render() {
141
191
}
142
192
else {
143
193
selected_control = std::min (selected_control + 1 , CONTROLS);
144
- if (selected_control == 1 ) { // 2nd column controls go down to next row
194
+ if (selected_control == 1 || selected_control == 5 ) { // 2nd column controls go down to next row
145
195
selected_control++;
146
196
}
147
197
}
@@ -155,47 +205,55 @@ void CharacterCreator::Render() {
155
205
}
156
206
else {
157
207
selected_control = std::max (selected_control - 1 , 0 );
158
- if (selected_control == 1 ) { // skip 2nd column controls
208
+ if (selected_control == 1 || selected_control == 5 ) { // skip 2nd column controls
159
209
selected_control--;
160
210
}
161
211
}
162
212
}
163
213
else if (ch == KEY_LEFT) {
164
- if (!show_race_popup && !show_class_popup && selected_control == 1 ) {
214
+ if (!show_race_popup && !show_class_popup && ( selected_control == 1 || selected_control == 5 ) ) {
165
215
selected_control--;
166
216
}
167
217
}
168
218
else if (ch == KEY_RIGHT) {
169
- if (!show_race_popup && !show_class_popup && selected_control == 0 ) {
219
+ if (!show_race_popup && !show_class_popup && ( selected_control == 0 || selected_control == 4 ) ) {
170
220
selected_control++;
171
221
}
172
222
}
173
223
else if (ch == ' \n ' || ch == ' ' ) {
174
- if (selected_control == 1 ) {
224
+ if (show_race_popup) {
225
+ const auto race = races[race_index];
226
+ new_game->SetRace (race);
227
+ show_race_popup = false ;
228
+ }
229
+ else if (show_class_popup) {
230
+ const auto cls = classes[class_index];
231
+ new_game->SetClass (cls);
232
+ show_class_popup = false ;
233
+ }
234
+ else if (selected_control == 1 ) {
175
235
new_game->GenerateName ();
176
236
}
177
237
else if (selected_control == 2 ) {
178
- if (show_race_popup) {
179
- const auto race = races[race_index];
180
- new_game->SetRace (race);
181
- show_race_popup = false ;
182
- }
183
- else {
184
- show_race_popup = true ;
185
- race_index = static_cast <int >(std::ranges::find (races, new_game->GetRace ()) - races.begin ());
186
- }
238
+ show_race_popup = true ;
239
+ race_index = static_cast <int >(std::ranges::find (races, new_game->GetRace ()) - races.begin ());
187
240
}
188
241
else if (selected_control == 3 ) {
189
- if (show_class_popup) {
190
- const auto cls = classes[class_index];
191
- new_game->SetClass (cls);
192
- show_class_popup = false ;
193
- }
194
- else {
195
- show_class_popup = true ;
196
- class_index = static_cast <int >(std::ranges::find (classes, new_game->GetClass ()) - classes.begin ());
242
+ show_class_popup = true ;
243
+ class_index = static_cast <int >(std::ranges::find (classes, new_game->GetClass ()) - classes.begin ());
244
+ }
245
+ else if (selected_control == 4 ) {
246
+ new_game->ReRoll ();
247
+ }
248
+ else if (selected_control == 5 ) {
249
+ if (new_game->CanUnroll ()) {
250
+ new_game->UnRoll ();
197
251
}
198
252
}
253
+ else if (selected_control == 6 ) {
254
+ new_game->ConfirmCharacter ();
255
+ message_handler (" start" );
256
+ }
199
257
}
200
258
else if (ch == KEY_BACKSPACE) {
201
259
if (selected_control == 0 ) {
0 commit comments