-
Notifications
You must be signed in to change notification settings - Fork 7
/
setup_types.c
379 lines (369 loc) · 8.66 KB
/
setup_types.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
/*
harris - a strategy game
Copyright (C) 2012-2015 Edward Cree
licensed under GPLv3+ - see top of harris.c for details
setup_types: screen for new game a/c type selection
*/
#include <stdio.h>
#include <unistd.h>
#include "setup_types.h"
#include "ui.h"
#include "globals.h"
#include "bits.h"
#include "control.h"
#include "intel_bombers.h"
atg_element *setup_types_box;
atg_element *ST_full, *ST_exit, *ST_back, *ST_start;
atg_element **ST_btrow, **ST_btint, **ST_btsel;
#define ST_BG_COLOUR (atg_colour){31, 31, 47, ATG_ALPHA_OPAQUE}
int setup_types_create(void)
{
setup_types_box=atg_create_element_box(ATG_BOX_PACK_VERTICAL, ST_BG_COLOUR);
if(!setup_types_box)
{
fprintf(stderr, "atg_create_element_box failed\n");
return(1);
}
atg_element *ST_topbox=atg_create_element_box(ATG_BOX_PACK_HORIZONTAL, ST_BG_COLOUR);
if(!ST_topbox)
{
fprintf(stderr, "atg_create_element_box failed\n");
return(1);
}
if(atg_ebox_pack(setup_types_box, ST_topbox))
{
perror("atg_ebox_pack");
return(1);
}
atg_element *ST_title=atg_create_element_label("Set Up New Game: Aircraft Types Selection", 12, (atg_colour){255, 255, 255, ATG_ALPHA_OPAQUE});
if(!ST_title)
{
fprintf(stderr, "atg_create_element_label failed\n");
return(1);
}
if(atg_ebox_pack(ST_topbox, ST_title))
{
perror("atg_ebox_pack");
return(1);
}
ST_full=atg_create_element_image(fullbtn);
if(!ST_full)
{
fprintf(stderr, "atg_create_element_image failed\n");
return(1);
}
ST_full->clickable=true;
if(atg_ebox_pack(ST_topbox, ST_full))
{
perror("atg_ebox_pack");
return(1);
}
ST_exit=atg_create_element_image(exitbtn);
if(!ST_exit)
{
fprintf(stderr, "atg_create_element_image failed\n");
return(1);
}
ST_exit->clickable=true;
if(atg_ebox_pack(ST_topbox, ST_exit))
{
perror("atg_ebox_pack");
return(1);
}
atg_element *helpbox=atg_create_element_box(ATG_BOX_PACK_VERTICAL, (atg_colour){79, 79, 47, ATG_ALPHA_OPAQUE});
if(!helpbox)
{
fprintf(stderr, "atg_create_element_box failed\n");
return(1);
}
helpbox->w=779;
if(atg_ebox_pack(setup_types_box, helpbox))
{
perror("atg_ebox_pack");
return(1);
}
const char *const helptext[] = {
"For alternate-history playthroughs, you can change the aircraft types available in the",
"game. This may significantly alter the game balance, and is not recommended for new",
"players. Note that removing aircraft types used in the startpoint will leave you with",
"smaller starting forces, as those aircraft will not be replaced with other types."
};
for(unsigned int ti=0;ti<ARRAY_SIZE(helptext);ti++)
{
atg_element *hl=atg_create_element_label(helptext[ti], 15, (atg_colour){239, 239, 63, ATG_ALPHA_OPAQUE});
if(!hl)
{
fprintf(stderr, "atg_create_element_label failed\n");
return(1);
}
if(atg_ebox_pack(helpbox, hl))
{
perror("atg_ebox_pack");
return(1);
}
}
atg_element *bomberbox=atg_create_element_box(ATG_BOX_PACK_VERTICAL, ST_BG_COLOUR);
if(!bomberbox)
{
fprintf(stderr, "atg_create_element_box failed\n");
return(1);
}
if(atg_ebox_pack(setup_types_box, bomberbox))
{
perror("atg_ebox_pack");
return(1);
}
if(!(ST_btrow=malloc(ntypes*sizeof(atg_element *))))
{
perror("malloc");
return(1);
}
if(!(ST_btint=malloc(ntypes*sizeof(atg_element *))))
{
perror("malloc");
return(1);
}
if(!(ST_btsel=malloc(ntypes*sizeof(atg_element *))))
{
perror("malloc");
return(1);
}
for(unsigned int i=0;i<ntypes;i++)
{
atg_colour bg=(atg_colour){63, 71, 63, ATG_ALPHA_OPAQUE};
if(types[i].extra)
bg.r=79;
if(!(ST_btrow[i]=atg_create_element_box(ATG_BOX_PACK_HORIZONTAL, bg)))
{
fprintf(stderr, "atg_create_element_box failed\n");
return(1);
}
if(atg_ebox_pack(bomberbox, ST_btrow[i]))
{
perror("atg_ebox_pack");
return(1);
}
atg_element *btpic=atg_create_element_image(types[i].picture);
if(!btpic)
{
fprintf(stderr, "atg_create_element_image failed\n");
return(1);
}
btpic->w=38;
btpic->h=42;
btpic->cache=true;
if(atg_ebox_pack(ST_btrow[i], btpic))
{
perror("atg_ebox_pack");
return(1);
}
atg_element *namebox=atg_create_element_box(ATG_BOX_PACK_VERTICAL, bg);
if(!namebox)
{
fprintf(stderr, "atg_create_element_box failed\n");
return(1);
}
namebox->h=42;
namebox->w=160;
if(atg_ebox_pack(ST_btrow[i], namebox))
{
perror("atg_ebox_pack");
return(1);
}
atg_element *nibox=atg_create_element_box(ATG_BOX_PACK_HORIZONTAL, bg);
if(!nibox)
{
fprintf(stderr, "atg_create_element_box failed\n");
return(1);
}
if(atg_ebox_pack(namebox, nibox))
{
perror("atg_ebox_pack");
return(1);
}
if(!(ST_btint[i]=atg_create_element_image(rawtypes[i].text?intelbtn:nointelbtn)))
{
fprintf(stderr, "atg_create_element_image failed\n");
return(1);
}
ST_btint[i]->clickable=true;
ST_btint[i]->w=10;
ST_btint[i]->h=12;
if(atg_ebox_pack(nibox, ST_btint[i]))
{
perror("atg_ebox_pack");
return(1);
}
if(!(types[i].manu&&types[i].name))
{
fprintf(stderr, "Missing manu or name in type %u\n", i);
return(1);
}
atg_element *manu=atg_create_element_label(types[i].manu, 10, (atg_colour){175, 199, 255, ATG_ALPHA_OPAQUE});
if(!manu)
{
fprintf(stderr, "atg_create_element_label failed\n");
return(1);
}
manu->w=151;
manu->cache=true;
if(atg_ebox_pack(nibox, manu))
{
perror("atg_ebox_pack");
return(1);
}
atg_element *name=atg_create_element_label(types[i].name, 14, (atg_colour){175, 199, 255, ATG_ALPHA_OPAQUE});
if(!name)
{
fprintf(stderr, "atg_create_element_label failed\n");
return(1);
}
name->w=144;
if(atg_ebox_pack(namebox, name))
{
perror("atg_ebox_pack");
return(1);
}
if(!(ST_btsel[i]=atg_create_element_image(NULL)))
{
fprintf(stderr, "atg_create_element_image failed\n");
return(1);
}
ST_btsel[i]->w=36;
ST_btsel[i]->h=42;
ST_btsel[i]->clickable=true;
if(atg_ebox_pack(ST_btrow[i], ST_btsel[i]))
{
perror("atg_ebox_pack");
return(1);
}
}
atg_element *ST_nav=atg_create_element_box(ATG_BOX_PACK_HORIZONTAL, ST_BG_COLOUR);
if(!ST_nav)
{
fprintf(stderr, "atg_create_element_box failed\n");
return(1);
}
if(atg_ebox_pack(setup_types_box, ST_nav))
{
perror("atg_ebox_pack");
return(1);
}
if(!(ST_back=atg_create_element_button("Go Back", (atg_colour){239, 195, 195, ATG_ALPHA_OPAQUE}, (atg_colour){71, 63, 63, ATG_ALPHA_OPAQUE})))
{
fprintf(stderr, "atg_create_element_button failed\n");
return(1);
}
if(atg_ebox_pack(ST_nav, ST_back))
{
perror("atg_ebox_pack");
return(1);
}
if(!(ST_start=atg_create_element_button("Start Game!", (atg_colour){239, 239, 239, ATG_ALPHA_OPAQUE}, (atg_colour){63, 63, 63, ATG_ALPHA_OPAQUE})))
{
fprintf(stderr, "atg_create_element_button failed\n");
return(1);
}
if(atg_ebox_pack(ST_nav, ST_start))
{
perror("atg_ebox_pack");
return(1);
}
return(0);
}
screen_id setup_types_screen(atg_canvas *canvas, game *state)
{
atg_event e;
while(1)
{
for(unsigned int i=0;i<ntypes;i++)
{
if(!ST_btsel[i]) continue;
atg_image *img=ST_btsel[i]->elemdata;
if(img)
img->data=state->btypes[i]?tick:cross;
}
atg_flip(canvas);
while(atg_poll_event(&e, canvas))
{
switch(e.type)
{
case ATG_EV_RAW:;
SDL_Event s=e.event.raw;
switch(s.type)
{
case SDL_QUIT:
return(SCRN_MAINMENU);
case SDL_VIDEORESIZE:
mainsizex=canvas->surface->w;
mainsizey=canvas->surface->h;
break;
}
break;
case ATG_EV_CLICK:;
atg_ev_click c=e.event.click;
if(c.e==ST_full)
{
fullscreen=!fullscreen;
atg_setopts_canvas(canvas, fullscreen?SDL_FULLSCREEN:SDL_RESIZABLE);
}
else if (c.e==ST_exit)
return(SCRN_MAINMENU);
else if(c.e)
{
unsigned int i;
for(i=0;i<ntypes;i++)
{
if(c.e==ST_btsel[i])
{
state->btypes[i]=!state->btypes[i];
break;
}
if(c.e==ST_btint[i])
{
intel_caller=SCRN_SETPTYPS;
IB_i=i;
IB_showmark=types[i].newmark;
return(SCRN_INTELBMB);
}
}
if(i==ntypes)
fprintf(stderr, "Clicked on unknown clickable!\n");
}
break;
case ATG_EV_TRIGGER:;
atg_ev_trigger trigger=e.event.trigger;
if(trigger.e==ST_start)
{
game_preinit(state);
return(SCRN_CONTROL);
}
else if(trigger.e==ST_back)
{
return(SCRN_SETPDIFF);
}
else if(!trigger.e)
{
// internal error
}
else
fprintf(stderr, "Clicked on unknown button!\n");
break;
default:
break;
}
}
SDL_Delay(50);
}
}
void setup_types_free(void)
{
for(unsigned int i=0;i<ntypes;i++)
{
if(!ST_btsel[i]) continue;
atg_image *img=ST_btsel[i]->elemdata;
if(img)
img->data=NULL;
}
atg_free_element(setup_types_box);
}