This repository has been archived by the owner on Mar 8, 2024. It is now read-only.
forked from markol/machines
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ctxskirm.cpp
729 lines (600 loc) · 23.5 KB
/
ctxskirm.cpp
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
/*
* C T X S K I R M . C P P
* (c) Charybdis Limited, 1998. All Rights Reserved
*/
// Definitions of non-inline non-template methods and global functions
#include "machgui/ctxskirm.hpp"
#include "machgui/menubutn.hpp"
#include "machgui/menutext.hpp"
#include "machgui/startup.hpp"
#include "machgui/scrltext.hpp"
#include "machgui/scrolbar.hpp"
#include "machgui/gui.hpp"
#include "machgui/sslistbx.hpp"
#include "machgui/sslistit.hpp"
#include "machgui/dbsystem.hpp"
#include "machgui/dbplanet.hpp"
#include "machgui/dbscenar.hpp"
#include "machgui/dbscenar.hpp"
#include "machgui/dbtexdat.hpp"
#include "machgui/database.hpp"
#include "machgui/strtdata.hpp"
#include "machgui/text.hpp"
#include "machgui/dropdwnc.hpp"
#include "machgui/msgbox.hpp"
#include "machgui/numpdrop.hpp"
#include "gui/scrolbut.hpp"
#include "gui/font.hpp"
#include "gui/painter.hpp"
#include "machgui/internal/strings.hpp"
#include "system/registry.hpp"
#include <stdarg.h>
#include "machgui/menus_helper.hpp"
//////////////////////////////////////////////////////////////////////////////////////////////
class MachGuiTerrainTypeListBoxItem : public MachGuiSingleSelectionListBoxItem
// Canonical form revoked
{
public:
MachGuiTerrainTypeListBoxItem( MachGuiStartupScreens* pStartupScreens,
MachGuiSingleSelectionListBox* pListBox,
size_t width,
MachGuiDbPlanet& planet,
MachGuiCtxSkirmish* pSkirmishCtx )
: MachGuiSingleSelectionListBoxItem( pStartupScreens, pListBox, width, displayString( planet ) ),
planet_( planet ),
pSkirmishCtx_( pSkirmishCtx )
{}
~MachGuiTerrainTypeListBoxItem()
{}
static bool allScenariosCompleted( MachGuiDbPlanet& planet )
{
// Work out if all the scenarios on this planet have been played and won
// Iterate through scenarios
uint numScenarios = planet.nScenarios();
bool allComplete = true;
for ( uint loop = 0; loop < numScenarios and allComplete; ++loop )
{
MachGuiDbScenario& scenario = planet.scenario( loop );
allComplete = scenario.hasBeenWon();
}
return allComplete;
}
protected:
virtual void select()
{
MachGuiSingleSelectionListBoxItem::select();
pSkirmishCtx_->updateScenarioList( planet_ );
}
static string displayString( MachGuiDbPlanet& planet )
{
string retValue;
if ( allScenariosCompleted( planet ) )
{
retValue = MachGui::wonSymbolText();
}
retValue += planet.menuString();
return retValue;
}
private:
MachGuiTerrainTypeListBoxItem( const MachGuiTerrainTypeListBoxItem& );
MachGuiTerrainTypeListBoxItem& operator =( const MachGuiTerrainTypeListBoxItem& );
// Data members...
MachGuiDbPlanet& planet_;
MachGuiCtxSkirmish* pSkirmishCtx_;
};
//////////////////////////////////////////////////////////////////////////////////////////////
class MachGuiMapSizeListBoxItem : public MachGuiSingleSelectionListBoxItem
// Canonical form revoked
{
public:
MachGuiMapSizeListBoxItem( MachGuiStartupScreens* pStartupScreens,
MachGuiSingleSelectionListBox* pListBox,
size_t width,
MachGuiDbSystem& system,
MachGuiCtxSkirmish* pSkirmishCtx )
: MachGuiSingleSelectionListBoxItem( pStartupScreens, pListBox, width, displayString( system ) ),
system_( system ),
pSkirmishCtx_( pSkirmishCtx )
{}
~MachGuiMapSizeListBoxItem()
{}
protected:
virtual void select()
{
MachGuiSingleSelectionListBoxItem::select();
pSkirmishCtx_->updateTerrainTypeList( system_ );
}
static string displayString( MachGuiDbSystem& system )
{
string retValue;
if ( allPlanetsCompleted( system ) )
{
retValue = MachGui::wonSymbolText();
}
retValue += system.menuString();
return retValue;
}
// Work out if all the planets in this system have been played and won
static bool allPlanetsCompleted( MachGuiDbSystem& system )
{
uint numPlanets = system.nPlanets();
bool allComplete = true;
for ( uint loop = 0; loop < numPlanets and allComplete; ++loop )
{
MachGuiDbPlanet& planet = system.planet( loop );
allComplete = MachGuiTerrainTypeListBoxItem::allScenariosCompleted( planet );
}
return allComplete;
}
private:
MachGuiMapSizeListBoxItem( const MachGuiMapSizeListBoxItem& );
MachGuiMapSizeListBoxItem& operator =( const MachGuiMapSizeListBoxItem& );
// Data members...
MachGuiDbSystem& system_;
MachGuiCtxSkirmish* pSkirmishCtx_;
};
//////////////////////////////////////////////////////////////////////////////////////////////
class MachGuiSkirmScenarioListBoxItem : public MachGuiSingleSelectionListBoxItem
// Canonical form revoked
{
public:
MachGuiSkirmScenarioListBoxItem(MachGuiStartupScreens* pStartupScreens,
MachGuiSingleSelectionListBox* pListBox,
size_t width,
MachGuiDbScenario& scenario,
MachGuiCtxSkirmish* pSkirmishCtx )
: MachGuiSingleSelectionListBoxItem( pStartupScreens, pListBox, width, displayString( scenario ) ),
scenario_( scenario ),
pSkirmishCtx_( pSkirmishCtx )
{}
~MachGuiSkirmScenarioListBoxItem()
{}
protected:
virtual void select()
{
MachGuiSingleSelectionListBoxItem::select();
pSkirmishCtx_->updateSelectedScenario( scenario_ );
}
static string displayString( MachGuiDbScenario& scenario )
{
string retValue;
if ( scenario.hasBeenWon() )
{
retValue = MachGui::wonSymbolText();
}
retValue += scenario.menuString();
return retValue;
}
private:
MachGuiSkirmScenarioListBoxItem( const MachGuiSkirmScenarioListBoxItem& );
MachGuiSkirmScenarioListBoxItem& operator =( const MachGuiSkirmScenarioListBoxItem& );
// Data members...
MachGuiDbScenario& scenario_;
MachGuiCtxSkirmish* pSkirmishCtx_;
};
//////////////////////////////////////////////////////////////////////////////////////////////
#define LB_MINX 61
#define LB_MAXX 266
#define MAPSIZE_LB_MINY 15
#define MAPSIZE_LB_MAXY 84
#define TERRAINTYPE_LB_MINY 127
#define TERRAINTYPE_LB_MAXY 280
#define SCENARIO_LB_MINY 305
#define SCENARIO_LB_MAXY 457
#define SETTINGS_LB_MINY 19
#define SETTINGS_LB_MAXY 205
#define SETTINGS_LB_MINX 369
#define SETTINGS_LB_MAXX 601
MachGuiCtxSkirmish::MachGuiCtxSkirmish( MachGuiStartupScreens* pStartupScreens )
: MachGuiStartupScreenContext( pStartupScreens ),
animations_( pStartupScreens, SysPathName("gui/menu/sn_anims.anm") ),
pNumPlayersSelector_( NULL ),
pNumPlayersText_( NULL ),
autoLoadGame_( false )
{
// Display backdrop, play correct music, switch cursor on.
changeBackdrop( "gui/menu/sn.bmp" );
const auto& topLeft = getBackdropTopLeft();
pStartupScreens->cursorOn( true );
pStartupScreens->desiredCdTrack( MachGuiStartupScreens::MENU_MUSIC );
// Regular menu buttons...
MachGuiMenuButton* pOkBtn = _NEW(MachGuiMenuButton(pStartupScreens, pStartupScreens, Gui::Box(302, 420, 444, 451),
IDS_MENUBTN_OK, MachGuiStartupScreens::BE_DUMMY_OK));
MachGuiMenuButton* pCancelBtn = _NEW(MachGuiMenuButton(pStartupScreens, pStartupScreens, Gui::Box(472, 420, 607, 451),
IDS_MENUBTN_CANCEL, MachGuiStartupScreens::EXIT));
pCancelBtn->escapeControl( true );
pOkBtn->defaultControl( true );
// Scenario description
pScenarioDesc_ = _NEW( MachGuiScrollableText( pStartupScreens, Gui::Box( 353, 288, 576, 385 ) ) );
MachGuiVerticalScrollBar::createWholeBar( pStartupScreens, Gui::Coord( 576, 288 ), 96, pScenarioDesc_ );
// Display mapsize list box heading
GuiResourceString mapsizeHeading( IDS_MENULB_MAPSIZE );
GuiBmpFont font( GuiBmpFont::getFont("gui/menu/largefnt.bmp") );
MachGuiMenuText* pMapSizeText =
_NEW( MachGuiMenuText( pStartupScreens,
Gui::Box( LB_MINX, MAPSIZE_LB_MINY,
LB_MINX + font.textWidth( mapsizeHeading.asString() ),
MAPSIZE_LB_MINY + font.charHeight() + 2 ), IDS_MENULB_MAPSIZE, "gui/menu/largefnt.bmp" ) );
// Display planet list box heading
GuiResourceString terrainHeading( IDS_MENULB_TERRAINTYPE );
MachGuiMenuText* pTerrainText =
_NEW( MachGuiMenuText( pStartupScreens,
Gui::Box( LB_MINX, TERRAINTYPE_LB_MINY,
LB_MINX + font.textWidth( terrainHeading.asString() ),
TERRAINTYPE_LB_MINY + font.charHeight() + 2 ), IDS_MENULB_TERRAINTYPE, "gui/menu/largefnt.bmp" ) );
// Display scenario list box heading
GuiResourceString scenarioHeading( IDS_MENULB_SCENARIO );
MachGuiMenuText* pScenarioText =
_NEW( MachGuiMenuText( pStartupScreens,
Gui::Box( LB_MINX, SCENARIO_LB_MINY,
LB_MINX + font.textWidth( scenarioHeading.asString() ),
SCENARIO_LB_MINY + font.charHeight() + 2 ), IDS_MENULB_SCENARIO, "gui/menu/largefnt.bmp" ) );
// Display settings list box heading
GuiResourceString settingsHeading( IDS_MENULB_SETTINGS );
MachGuiMenuText* pSettingsText =
_NEW( MachGuiMenuText( pStartupScreens,
Gui::Box( SETTINGS_LB_MINX, SETTINGS_LB_MINY,
SETTINGS_LB_MINX + font.textWidth( settingsHeading.asString() ),
SETTINGS_LB_MINY + font.charHeight() + 2 ), IDS_MENULB_SETTINGS, "gui/menu/largefnt.bmp" ) );
// Create system list box
pMapSizeList_ = _NEW(MachGuiSingleSelectionListBox(pStartupScreens, pStartupScreens,
Gui::Box(LB_MINX,
pMapSizeText->absoluteBoundary().maxCorner().y() -
topLeft.first, LB_MAXX,
MAPSIZE_LB_MAXY),
1000, MachGuiSingleSelectionListBoxItem::reqHeight(), 1));
// Create planet list box
pTerrainTypeList_ = _NEW(MachGuiSingleSelectionListBox(pStartupScreens, pStartupScreens,
Gui::Box(LB_MINX,
pTerrainText->absoluteBoundary().maxCorner().y() -
topLeft.first, LB_MAXX,
TERRAINTYPE_LB_MAXY),
1000, MachGuiSingleSelectionListBoxItem::reqHeight(), 1));
// Create scenario list box
pScenarioList_ = _NEW(MachGuiSingleSelectionListBox(pStartupScreens, pStartupScreens,
Gui::Box(LB_MINX,
pScenarioText->absoluteBoundary().maxCorner().y() -
topLeft.first, LB_MAXX,
SCENARIO_LB_MAXY),
1000, MachGuiSingleSelectionListBoxItem::reqHeight(), 1));
// Create settings list box
pSettingsList_ = _NEW( GuiSimpleScrollableList( pStartupScreens,
Gui::Box( SETTINGS_LB_MINX, pSettingsText->absoluteBoundary().maxCorner().y() - topLeft.first, SETTINGS_LB_MAXX, SETTINGS_LB_MAXY),
(SETTINGS_LB_MAXX-SETTINGS_LB_MINX)/2,
MachGuiDropDownListBoxCreator::reqHeight() + 1, 1 ) );
initSettings();
updateMapSizeList();
TEST_INVARIANT;
}
MachGuiCtxSkirmish::~MachGuiCtxSkirmish()
{
TEST_INVARIANT;
}
void MachGuiCtxSkirmish::CLASS_INVARIANT
{
INVARIANT( this != NULL );
}
ostream& operator <<( ostream& o, const MachGuiCtxSkirmish& t )
{
o << "MachGuiCtxSkirmish " << (void*)&t << " start" << std::endl;
o << "MachGuiCtxSkirmish " << (void*)&t << " end" << std::endl;
return o;
}
//virtual
void MachGuiCtxSkirmish::update()
{
if ( autoLoadGame_ )
{
pStartupScreens_->buttonAction( MachGuiStartupScreens::BE_OK );
}
else
{
animations_.update();
}
}
void MachGuiCtxSkirmish::updateMapSizeList()
{
bool firstItem = true;
// There will be no CUSTOM skirmishSystem if there is no customscen.dat file
const MachGuiDatabase::TerrainSize maxMapSize = MachGuiDatabase::doCustomScenariosExist() ? MachGuiDatabase::CUSTOM : MachGuiDatabase::LARGE;
for ( MachGuiDatabase::TerrainSize loop = MachGuiDatabase::SMALL; loop <= maxMapSize; loop = _STATIC_CAST(MachGuiDatabase::TerrainSize, _STATIC_CAST(uint, loop)+1 ))
{
MachGuiDbSystem& system = MachGuiDatabase::instance().skirmishSystem( loop );
if( not system.nPlanets() ) // skip user custom scenarios if empty
continue;
MachGuiMapSizeListBoxItem* pItem = _NEW( MachGuiMapSizeListBoxItem( pStartupScreens_, pMapSizeList_, LB_MAXX - LB_MINX, system, this ) );
// Select first item in list
if ( firstItem )
{
firstItem = false;
pItem->selectThisItem();
}
}
pMapSizeList_->childrenUpdated();
}
void MachGuiCtxSkirmish::updateTerrainTypeList( MachGuiDbSystem& system )
{
// Delete all items from list
pTerrainTypeList_->deleteAllItems();
// Redraw backdrop to list
auto* shared = pStartupScreens_->getSharedBitmaps();
auto backdrop = shared->getNamedBitmap("backdrop");
shared->blitNamedBitmapFromArea(
backdrop,
pTerrainTypeList_->absoluteBoundary(),
pTerrainTypeList_->absoluteBoundary().minCorner(),
[shared, backdrop](const Gui::Box& box) {
using namespace machgui::helper::menus;
return centered_bitmap_transform(
box,
shared->getWidthOfNamedBitmap(backdrop),
shared->getHeightOfNamedBitmap(backdrop)
);
});
// Insert new items into list
uint numPlanets = system.nPlanets();
bool firstItem = true;
for ( uint loop = 0; loop < numPlanets; ++loop )
{
MachGuiDbPlanet& planet = system.planet( loop );
MachGuiTerrainTypeListBoxItem* pItem = _NEW( MachGuiTerrainTypeListBoxItem( pStartupScreens_, pTerrainTypeList_, LB_MAXX - LB_MINX, planet, this ) );
// Select first item in list
if ( firstItem )
{
firstItem = false;
pItem->selectThisItem();
}
}
pTerrainTypeList_->childrenUpdated();
}
void MachGuiCtxSkirmish::updateScenarioList( MachGuiDbPlanet& planet )
{
// Delete all items from list
pScenarioList_->deleteAllItems();
// Redraw backdrop to list
auto* shared = pStartupScreens_->getSharedBitmaps();
auto backdrop = shared->getNamedBitmap("backdrop");
shared->blitNamedBitmapFromArea(
backdrop,
pScenarioList_->absoluteBoundary(),
pScenarioList_->absoluteBoundary().minCorner(),
[shared, backdrop](const Gui::Box& box) {
using namespace machgui::helper::menus;
return centered_bitmap_transform(
box,
shared->getWidthOfNamedBitmap(backdrop),
shared->getHeightOfNamedBitmap(backdrop)
);
});
// Insert new items into list
uint numScenarios = planet.nScenarios();
bool firstItem = true;
for ( uint loop = 0; loop < numScenarios; ++loop )
{
MachGuiDbScenario& scenario = planet.scenario( loop );
MachGuiSkirmScenarioListBoxItem* pItem = _NEW( MachGuiSkirmScenarioListBoxItem( pStartupScreens_, pScenarioList_, LB_MAXX - LB_MINX, scenario, this ) );
// Select first item in list
if ( firstItem )
{
firstItem = false;
pItem->selectThisItem();
}
}
pScenarioList_->childrenUpdated();
}
void MachGuiCtxSkirmish::updateSelectedScenario( MachGuiDbScenario& scenario )
{
pStartupScreens_->startupData()->scenario( &scenario );
pScenarioDesc_->setText( scenario.textData().campaignText() );
updateMaxPlayersList( scenario );
}
void MachGuiCtxSkirmish::initSettings()
{
// Delete all items from list
pSettingsList_->deleteAllChildren();
// Redraw backdrop to list
auto* shared = pStartupScreens_->getSharedBitmaps();
auto backdrop = shared->getNamedBitmap("backdrop");
shared->blitNamedBitmapFromArea(
backdrop,
pSettingsList_->absoluteBoundary(),
pSettingsList_->absoluteBoundary().minCorner(),
[shared, backdrop](const Gui::Box& box) {
using namespace machgui::helper::menus;
return centered_bitmap_transform(
box,
shared->getWidthOfNamedBitmap(backdrop),
shared->getHeightOfNamedBitmap(backdrop)
);
});
// Add "fog of war" setting...
addSetting( false, pFogOfWarSelector_, IDS_MENU_FOGOFWAR, 2, IDS_MENU_ON, IDS_MENU_OFF );
pFogOfWarSelector_->text( pStartupScreens_->startupData()->fogOfWarStr() );
// Add "resource" setting...
addSetting( false, pResourcesSelector_, IDS_MENU_RESOURCES, 3, IDS_MENU_HIGH, IDS_MENU_MEDIUM, IDS_MENU_LOW );
pResourcesSelector_->text( pStartupScreens_->startupData()->resourcesStr() );
// Add "starting resource" setting...
addSetting( false, pStartingResourcesSelector_, IDS_MENU_STARTINGRESOURCES, 6, IDS_MENU_DEFAULT, IDS_MENU_RESOURCESLEVEL1, IDS_MENU_RESOURCESLEVEL2, IDS_MENU_RESOURCESLEVEL3, IDS_MENU_RESOURCESLEVEL4 ,IDS_MENU_RESOURCESLEVEL5 );
pStartingResourcesSelector_->text( pStartupScreens_->startupData()->startingResourcesStr() );
// Add "starting pos" setting...
addSetting( false, pStartingPosSelector_, IDS_MENU_STARTPOS, 2, IDS_MENU_STARTFIXED, IDS_MENU_STARTRANDOM );
pStartingPosSelector_->text( pStartupScreens_->startupData()->startingPositionStr() );
// Add "victory conditions" setting...
addSetting( false, pVictorySelector_, IDS_MENU_VICTORYCONDITION, 12, IDS_MENU_DEFAULT, IDS_MENU_VICTORYTANNIHILATION, IDS_MENU_VICTORYDESTROYPOD,
IDS_MENU_VICTORYTIMED5, IDS_MENU_VICTORYTIMED10, IDS_MENU_VICTORYTIMED15, IDS_MENU_VICTORYTIMED30, IDS_MENU_VICTORYTIMED45,
IDS_MENU_VICTORYTIMED60, IDS_MENU_VICTORYTIMED90, IDS_MENU_VICTORYTIMED120, IDS_MENU_VICTORYTIMED180 );
pVictorySelector_->text( pStartupScreens_->startupData()->victoryConditionStr() );
// Add "tech level" setting...
addSetting( false, pTechLevelSelector_, IDS_MENU_STARTINGTECHLEVEL, 4, IDS_MENU_DEFAULT, IDS_MENU_TECHLEVELLOW, IDS_MENU_TECHLEVELMED, IDS_MENU_TECHLEVELHIGH );
pTechLevelSelector_->text( pStartupScreens_->startupData()->techLevelStr() );
// Add "player colour" setting...
addSetting( false, pColourSelector_, IDS_MENU_PLAYERCOLOUR, 4, IDS_MENU_PLAYERCOLOURRED, IDS_MENU_PLAYERCOLOURGREEN, IDS_MENU_PLAYERCOLOURBLUE, IDS_MENU_PLAYERCOLOURYELLOW );
pColourSelector_->text( pStartupScreens_->startupData()->playerRaceStr() );
pSettingsList_->childrenUpdated();
}
//virtual
bool MachGuiCtxSkirmish::okayToSwitchContext()
{
// Update settings...
pStartupScreens_->startupData()->resources( pResourcesSelector_->text() );
pStartupScreens_->startupData()->fogOfWar( pFogOfWarSelector_->text() );
pStartupScreens_->startupData()->resources( pResourcesSelector_->text() );
pStartupScreens_->startupData()->startingResources( pStartingResourcesSelector_->text() );
pStartupScreens_->startupData()->startingPosition( pStartingPosSelector_->text() );
pStartupScreens_->startupData()->victoryCondition( pVictorySelector_->text() );
pStartupScreens_->startupData()->numPlayers( pNumPlayersSelector_->text() );
pStartupScreens_->startupData()->techLevel( pTechLevelSelector_->text() );
pStartupScreens_->startupData()->playerRace( pColourSelector_->text() );
return true;
}
MachGuiText* MachGuiCtxSkirmish::addSetting( bool numPlayersDropDown, MachGuiDropDownListBoxCreator*& pCreator, uint labelStrId, int numStrs, ... )
{
const int width = (SETTINGS_LB_MAXX-SETTINGS_LB_MINX)/2;
va_list marker;
va_start( marker, numStrs ); // Initialize variable arguments.
GuiResourceString labelStr( labelStrId );
GuiStrings strings;
strings.reserve( numStrs + 1 );
MachGuiText* pText = _NEW(MachGuiText(pSettingsList_, width, labelStr.asString()));
pText->textOffset( 1, 1 );
while( numStrs )
{
--numStrs;
int listBoxStrId = va_arg( marker, int);
GuiResourceString listBoxStr( listBoxStrId );
strings.push_back( listBoxStr.asString() );
}
if ( numPlayersDropDown )
{
pCreator = _NEW( MachGuiNumPlayersDropDownListBoxCreator( pSettingsList_, pStartupScreens_, width, strings, true ) );
}
else
{
pCreator = _NEW( MachGuiDropDownListBoxCreator( pSettingsList_, pStartupScreens_, width, strings, true ) );
}
va_end( marker ); // Reset variable arguments.
return pText;
}
void MachGuiCtxSkirmish::updateMaxPlayersList( MachGuiDbScenario& scenario )
{
// Update "num players" setting so that, for example, you can't select a four player game when
// the scenario doesn't support four players
bool hasKeyboardFocus = false;
if ( pNumPlayersSelector_ )
{
ASSERT( pNumPlayersText_, "this should be created at the same time as the pNumPlayersSelector_" );
if ( pNumPlayersSelector_->hasFocusSet() )
{
hasKeyboardFocus = true;
}
_DELETE( pNumPlayersSelector_ );
_DELETE( pNumPlayersText_ );
}
GuiResourceString str4( IDS_MENU_NUMPLAYERS4 );
GuiResourceString str3( IDS_MENU_NUMPLAYERS3 );
GuiResourceString str2( IDS_MENU_NUMPLAYERS2 );
switch ( scenario.maxPlayers() )
{
case 4:
{
pNumPlayersText_ = addSetting( true, pNumPlayersSelector_, IDS_MENU_NUMPLAYERS, 3, IDS_MENU_NUMPLAYERS2, IDS_MENU_NUMPLAYERS3, IDS_MENU_NUMPLAYERS4 );
if ( chosenNumPlayers() == 2 )
{
pNumPlayersSelector_->text( str2.asString() );
}
else if ( chosenNumPlayers() == 3 )
{
pNumPlayersSelector_->text( str3.asString() );
}
else
{
pNumPlayersSelector_->text( str4.asString() );
}
}
break;
case 3:
{
pNumPlayersText_ = addSetting( true, pNumPlayersSelector_, IDS_MENU_NUMPLAYERS, 2, IDS_MENU_NUMPLAYERS2, IDS_MENU_NUMPLAYERS3 );
if ( chosenNumPlayers() == 2 )
{
pNumPlayersSelector_->text( str2.asString() );
}
else
{
pNumPlayersSelector_->text( str3.asString() );
}
}
break;
case 2:
{
pNumPlayersText_ = addSetting( true, pNumPlayersSelector_, IDS_MENU_NUMPLAYERS, 1, IDS_MENU_NUMPLAYERS2 );
pNumPlayersSelector_->text( str2.asString() );
}
break;
DEFAULT_ASSERT_BAD_CASE( scenario.maxPlayers() );
}
if ( hasKeyboardFocus )
{
pNumPlayersSelector_->hasFocus( true );
}
pSettingsList_->childrenUpdated();
}
///////////////////////////////////////////////////////////////////////////////////////////
class MachGuiStartSkirmishMessageBoxResponder : public MachGuiMessageBoxResponder
{
public:
MachGuiStartSkirmishMessageBoxResponder( MachGuiCtxSkirmish* pSkirmishCtx )
: pSkirmishCtx_( pSkirmishCtx )
{}
virtual bool okPressed()
{
//if ( MachGui::machinesCDIsAvailable( 2 ) )
{
pSkirmishCtx_->autoLoadGame();
return true;
}
//return false;
}
private:
MachGuiCtxSkirmish* pSkirmishCtx_;
};
///////////////////////////////////////////////////////////////////////////////////////////
// virtual
void MachGuiCtxSkirmish::buttonEvent( MachGuiStartupScreens::ButtonEvent buttonEvent )
{
if ( buttonEvent == MachGuiStartupScreens::BE_DUMMY_OK )
{
#ifndef DEMO
//if ( MachGui::machinesCDIsAvailable( 2 )
#ifndef PRODUCTION
// or getenv("cb_dontcheckcd") )
#else
// )
#endif
{
pStartupScreens_->buttonAction( MachGuiStartupScreens::BE_OK );
}
//else
//{
// pStartupScreens_->displayMsgBox( IDS_MENUMSG_INSERTCD, _NEW( MachGuiStartSkirmishMessageBoxResponder(this) ) );
//}
#else // DEMO defined.
pStartupScreens_->buttonAction( MachGuiStartupScreens::BE_OK );
#endif
}
}
void MachGuiCtxSkirmish::autoLoadGame()
{
autoLoadGame_ = true;
}
//static
int& MachGuiCtxSkirmish::chosenNumPlayers()
{
static int chosenNumPlayersVal = SysRegistry::instance().queryIntegerValue( "Game Settings\\Num Players", "Value", SysRegistry::CURRENT_USER );
if ( chosenNumPlayersVal == 0 )
{
chosenNumPlayersVal = 4;
}
return chosenNumPlayersVal;
}
/* End CTXSKIRM.CPP *************************************************/