-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMenu_WorldGenerator.hpp
More file actions
783 lines (645 loc) · 23.7 KB
/
Menu_WorldGenerator.hpp
File metadata and controls
783 lines (645 loc) · 23.7 KB
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
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
#pragma once
#ifndef WORLDSIM_MENU_WORLD_GENERATOR_HPP
#define WORLDSIM_MENU_WORLD_GENERATOR_HPP
/* WorldSim: Menu_WorldGenerator.hpp
#include "Menu_WorldGenerator.hpp"
Implementation of GUI interface.
This menu is displayed upon starting the game app. It allows the player to start a new game, load a saved game, access the options menu, and quit the application.
*/
#include <Graphics/GUI/GUI.hpp>
#include <Device/Display/DisplayInterface.hpp>
#include <Device/Mouse/MouseInterface.hpp>
#include <Data/Debug/DebugMacro.hpp>
#include <Data/DataTools.hpp> /* To check if seed is numeric */
#include "Menu_AdventureMode.hpp"
class Menu_WorldGenerator: public GUI_Interface
{
private:
GUI_Manager guiManager;
/* Colours / theme. */
ColourRGB <unsigned char> cNormal;
ColourRGB <unsigned char> cSelected;
ColourRGB <unsigned char> cDropPanel;
ColourRGB <unsigned char> cHighlight;
/* Background image */
Texture* backgroundTexture;
/* Button: Back to main menu. */
GUI_Button buttonBack;
/* Button: Expand preview window. */
GUI_Button buttonExpandPreviewWindow;
/* Textbox: Title for menu. */
GUI_TextBox textMenuTitle;
/* TextEntry: Name of the world. */
GUI_TextEntry textEntryWorldName;
/* TextEntry: Full seed value. */
GUI_TextEntry textEntryFullSeed;
/* TextEntry: Full biome value. */
GUI_TextEntry textEntryFullBiome;
/* Button: Generate the world. */
GUI_Button buttonGenerate;
/* Button: Keep this world and move to world simulation phase. */
GUI_Button buttonSimWorld;
/* Button: Export a bunch of data about the generated world. */
GUI_Button buttonExportData;
/* Button: Load a world. Note this only loads starting data. Which is geographic data and starting positions. */
GUI_Button buttonLoadWorld;
/* Number entry: World size (tiles). The world is square, so only one input is needed. */
GUI_CycleButton worldSize;
/* Textbox: Caption for worldsize selector. */
GUI_TextBox textWorldSize;
/* Number entry: World size (tiles). The world is square, so only one input is needed. */
GUI_CycleButton freeSteps;
/* Textbox: Caption for worldsize selector. */
GUI_TextBox textFreeSteps;
/* WrapX */
GUI_CycleButton guiWrapX;
GUI_TextBox textWrapX;
/* WrapY */
GUI_CycleButton guiWrapY;
GUI_TextBox textWrapY;
/* Island Mode */
GUI_CycleButton guiIslandMode;
GUI_TextBox textIslandMode;
/* Ocean percent */
GUI_NumberInput nLandPercent;
GUI_TextBox textOceanPercent;
/* Number entry: Number of civs to spawn into the world. */
GUI_NumberInput nCiv;
GUI_TextBox guiCaptionNCiv;
/* Number entry: Number of human tribes to spawn into the world. */
GUI_NumberInput nTribe;
GUI_TextBox guiCaptionNTribe;
/* Number entry: Number of Dwarven tribes to spawn into the world. */
GUI_NumberInput nTribeDwarven;
GUI_TextBox guiCaptionNTribeDwarven;
/* Number entry: Number of Elven tribes to spawn into the world. */
GUI_NumberInput nTribeElven;
GUI_TextBox guiCaptionNTribeElven;
bool fullScreenPreview;
public:
Menu_WorldGenerator()
{
fullScreenPreview=false;
worldViewer.world = &world;
worldViewer.active = false;
minimap.world=&world;
minimap.active=false;
buttonGenerate.clicked=false;
}
void setFont(Wildcat::Font* _font)
{
font = _font;
guiManager.setFont(_font);
}
void logicTick()
{
// if(menuWorldSimulator.active==true)
// {
// menuWorldSimulator.logicTick();
// }
}
void init()
{
backgroundTexture=&TEX_NEW_GAME_BACKGROUND;
active=false;
fullScreenPreview=true;
/* Initialise theme. */
cNormal.set(200,200,200);
cSelected.set(180,180,180);
cDropPanel.set(170,170,170);
cHighlight.set(170,170,170);
buttonExpandPreviewWindow.setPanel(0,0,32,32);
if(fullScreenPreview==false)
{
int panelSizeX = panelX2-panelX1;
int panelSizeY = panelY2-panelY1;
int worldPreviewX1=panelX1+(panelSizeX/2);
int worldPreviewY1=panelY1+(panelSizeY/2);
//worldViewer.setPanel(worldPreviewX1,worldPreviewY1,panelX2,panelY2);
//buttonExpandPreviewWindow.setPanel(worldPreviewX1,worldPreviewY1,worldPreviewX1+16,worldPreviewY1+16);
/* Put worldviewer in top right corner of panel. */
worldViewer.setPanel(panelX2/2,panelY2/2,panelX2,panelY2);
}
else
{
//worldViewer.setPanel(panelX1,panelY1,panelX2,panelY2);
//buttonExpandPreviewWindow.setPanel(panelX1,panelY1,panelX1+16,panelY1+16);
/* Make worldviewer fill screen. */
worldViewer.setPanel(panelX1,panelY1,panelX2,panelY2);
}
buttonBack.text="Back";
buttonBack.setColours(cNormal,cHighlight,0);
/* WORLD SIZE */
worldSize.currentOption=DEFAULT_WORLD_SIZE_SLOT;
//worldSize.addOption("17");
worldSize.addOption("33");
worldSize.addOption("65");
worldSize.addOption("129");
worldSize.addOption("257");
worldSize.addOption("513");
worldSize.addOption("1025");
worldSize.addOption("2049");
worldSize.addOption("4097");
worldSize.addOption("8193");
worldSize.texCycleButton=&TEX_GUI_DECREMENT;
worldSize.setColours(cNormal,cHighlight,0);
freeSteps.currentOption=0;
freeSteps.addOption("0");
freeSteps.addOption("1");
freeSteps.addOption("2");
freeSteps.addOption("3");
freeSteps.addOption("4");
freeSteps.addOption("5");
freeSteps.addOption("6");
freeSteps.addOption("7");
freeSteps.addOption("8");
freeSteps.addOption("9");
freeSteps.addOption("10");
freeSteps.addOption("11");
freeSteps.addOption("12");
freeSteps.texCycleButton=&TEX_GUI_DECREMENT;
freeSteps.setColours(cNormal,cHighlight,0);
/* WrapX */
guiWrapX.currentOption=0;
guiWrapX.addOption("Yes");
guiWrapX.addOption("No");
guiWrapX.texCycleButton=&TEX_GUI_DECREMENT;
guiWrapX.setColours(cNormal,cHighlight,0);
guiWrapX.wrap=true;
/* WrapY */
guiWrapY.currentOption=1;
guiWrapY.addOption("Yes");
guiWrapY.addOption("No");
guiWrapY.texCycleButton=&TEX_GUI_DECREMENT;
guiWrapY.setColours(cNormal,cHighlight,0);
guiWrapY.wrap=true;
/* Island mode */
guiIslandMode.currentOption=0;
guiIslandMode.addOption("Yes");
guiIslandMode.addOption("No");
guiIslandMode.texCycleButton=&TEX_GUI_DECREMENT;
guiIslandMode.setColours(cNormal, cHighlight,0);
guiIslandMode.wrap=true;
/* N CIV */
nCiv.setNumbers(0,128,DEFAULT_NUMBER_CIVS);
nCiv.setColours(cNormal,cHighlight,0);
nCiv.texIncrement = &TEX_GUI_INCREMENT;
nCiv.texDecrement = &TEX_GUI_DECREMENT;
guiCaptionNCiv.text="# civs:";
guiCaptionNCiv.setColours(cNormal);
guiCaptionNCiv.centeredY=true;
/* Ocean percent */
nLandPercent.setNumbers(0,100,66);
nLandPercent.setColours(cNormal,cHighlight,0);
nLandPercent.texIncrement = &TEX_GUI_INCREMENT;
nLandPercent.texDecrement = &TEX_GUI_DECREMENT;
textOceanPercent.text="Land percent:";
textOceanPercent.setColours(cNormal);
textOceanPercent.centeredY=true;
/* N TRIBE */
nTribe.setNumbers(0,100,DEFAULT_NUMBER_TRIBES_HUMAN);
nTribe.setColours(cNormal,cHighlight,0);
nTribe.texIncrement = &TEX_GUI_INCREMENT;
nTribe.texDecrement = &TEX_GUI_DECREMENT;
guiCaptionNTribe.text="# human tribes:";
guiCaptionNTribe.setColours(cNormal);
guiCaptionNTribe.centeredY=true;
/* N TRIBE DWARVEN */
nTribeDwarven.setNumbers(0,100,DEFAULT_NUMBER_TRIBES_DWARVEN);
nTribeDwarven.setColours(cNormal,cHighlight,0);
nTribeDwarven.texIncrement = &TEX_GUI_INCREMENT;
nTribeDwarven.texDecrement = &TEX_GUI_DECREMENT;
guiCaptionNTribeDwarven.text="# Dwarven forts:";
guiCaptionNTribeDwarven.setColours(cNormal);
guiCaptionNTribeDwarven.centeredY=true;
/* N TRIBE ELVEN */
nTribeElven.setNumbers(0,100,DEFAULT_NUMBER_TRIBES_ELVEN);
nTribeElven.setColours(cNormal,cHighlight,0);
nTribeElven.texIncrement = &TEX_GUI_INCREMENT;
nTribeElven.texDecrement = &TEX_GUI_DECREMENT;
guiCaptionNTribeElven.text="# Elven tribes:";
guiCaptionNTribeElven.setColours(cNormal);
guiCaptionNTribeElven.centeredY=true;
/* GENERATE BUTTON */
buttonGenerate.text="1. Generate";
buttonGenerate.setColours(cNormal,cHighlight,0);
/* WORLD NAME */
textEntryWorldName.setColours(cNormal,cHighlight);
textEntryWorldName.fieldName="World name:";
textEntryWorldName.characterLimit=20;
/* Give the world a random name */
//textEntryWorldName.input = globalNameGen.generateName();
textEntryWorldName.input = "testworld";
/* WORLD SEED */
textEntryFullSeed.setColours(cNormal,cHighlight);
textEntryFullSeed.fieldName="World seed:";
textEntryFullSeed.characterLimit=16 ;
//textEntryFullSeed.input="1902830183";
textEntryFullSeed.input="";
/* BIOME SEED */
textEntryFullBiome.setColours(cNormal,cHighlight);
textEntryFullBiome.fieldName="Biome seed:";
textEntryFullBiome.characterLimit=16;
textEntryFullBiome.input="";
textWorldSize.text="World size:";
textWorldSize.setColours(cNormal);
textWorldSize.centeredY=true;
textFreeSteps.text="Fragmentation:";
textFreeSteps.setColours(cNormal);
textFreeSteps.centeredY=true;
textWrapX.text="Wrap X:";
textWrapX.setColours(cNormal);
textWrapX.centeredY=true;
textWrapY.text="Wrap Y:";
textWrapY.setColours(cNormal);
textWrapY.centeredY=true;
textIslandMode.text="Island mode:";
textIslandMode.setColours(cNormal);
textIslandMode.centeredY=true;
textMenuTitle.text="World Generator";
textMenuTitle.setColours(cNormal);
textMenuTitle.centeredX=true;
textMenuTitle.centeredY=true;
buttonSimWorld.text="2. Simulate World";
buttonSimWorld.setColours(cNormal,cHighlight,0);
buttonExportData.text="Export World Data (N/A)";
buttonExportData.setColours(cNormal,cHighlight,0);
buttonLoadWorld.text="Load world (N/A)";
buttonLoadWorld.setColours(cNormal,cHighlight,0);
buttonExpandPreviewWindow.texture = &TEX_GUI_EXPAND;
guiManager.add(&textMenuTitle);
//Not currently functional
//guiManager.add(&buttonBack);
guiManager.add(&textEntryWorldName);
guiManager.add(&textEntryFullSeed);
guiManager.add(&textEntryFullBiome);
guiManager.add(&buttonGenerate);
guiManager.add(&textWorldSize);
guiManager.add(&textFreeSteps);
guiManager.add(&textIslandMode);
guiManager.add(&textWrapX);
guiManager.add(&textWrapY);
guiManager.add(&worldSize);
guiManager.add(&freeSteps);
guiManager.add(&guiIslandMode);
guiManager.add(&guiWrapX);
guiManager.add(&guiWrapY);
//guiManager.add(&guiCaptionNCiv);
guiManager.add(&textOceanPercent);
//guiManager.add(&nCiv);
guiManager.add(&nLandPercent);
guiManager.add(&guiCaptionNTribe);
guiManager.add(&guiCaptionNTribeDwarven);
guiManager.add(&guiCaptionNTribeElven);
guiManager.add(&nTribe);
guiManager.add(&nTribeDwarven);
guiManager.add(&nTribeElven);
guiManager.add(&buttonSimWorld);
//guiManager.add(&buttonExportData);
//guiManager.add(&buttonLoadWorld);
//guiManager.add(&buttonExpandPreviewWindow);
// A TEMPORARY FIX TO STOP ACCIDENTALLY HITTING
// HOTKEYS WHILE TYPING.
globalGuiManager.add(&textEntryWorldName);
globalGuiManager.add(&textEntryFullSeed);
globalGuiManager.add(&textEntryFullBiome);
guiManager.setFont(font);
}
void eventResize()
{
/* Menu title. */
textMenuTitle.setPanel(panelX1, panelY2, panelX2/2, panelY2-20);
/* Bottom left corner. */
buttonBack.setPanel(panelX1,panelY1+20,panelX1+120,panelY1);
/* Left column, centered. */
const int leftColumnCenterX = panelX1+(panelNX/4);
textEntryWorldName.setPanel(panelX1+20, panelY2-30, (panelX2/2)-20, panelY2-40);
textEntryFullSeed.setPanel(panelX1+20, panelY2-40, (panelX2/2)-20, panelY2-50);
textEntryFullBiome.setPanel(panelX1+20, panelY2-50, (panelX2/2)-20, panelY2-60);
int ySpacing = 2;
int ySize = 10;
int currentY1 = panelY2 - 60;
int currentY2 = currentY1-ySize;
currentY1 -= (ySize+ySpacing);
currentY2 -= (ySize+ySpacing);
textWorldSize.setPanel(leftColumnCenterX-180, currentY1, leftColumnCenterX-20, currentY2);
worldSize.setPanel(leftColumnCenterX-20, currentY1, leftColumnCenterX+120, currentY2);
currentY1 -= (ySize+ySpacing);
currentY2 -= (ySize+ySpacing);
textFreeSteps.setPanel(leftColumnCenterX-180, currentY1, leftColumnCenterX-20, currentY2);
freeSteps.setPanel(leftColumnCenterX-20, currentY1, leftColumnCenterX+120, currentY2);
currentY1 -= (ySize+ySpacing);
currentY2 -= (ySize+ySpacing);
textIslandMode.setPanel(leftColumnCenterX-180, currentY1, leftColumnCenterX-20, currentY2);
guiIslandMode.setPanel(leftColumnCenterX-20, currentY1, leftColumnCenterX+120, currentY2);
currentY1 -= (ySize+ySpacing);
currentY2 -= (ySize+ySpacing);
textWrapX.setPanel(leftColumnCenterX-180, currentY1, leftColumnCenterX-20, currentY2);
guiWrapX.setPanel(leftColumnCenterX-20, currentY1, leftColumnCenterX+120, currentY2);
currentY1 -= (ySize+ySpacing);
currentY2 -= (ySize+ySpacing);
textWrapY.setPanel(leftColumnCenterX-180, currentY1, leftColumnCenterX-20, currentY2);
guiWrapY.setPanel(leftColumnCenterX-20, currentY1, leftColumnCenterX+120, currentY2);
currentY1 -= (ySize+ySpacing);
currentY2 -= (ySize+ySpacing);
textOceanPercent.setPanel(leftColumnCenterX-180, currentY1, leftColumnCenterX-20, currentY2);
nLandPercent.setPanel(leftColumnCenterX-20, currentY1, leftColumnCenterX+120, currentY2);
currentY1 -= (ySize+ySpacing);
currentY2 -= (ySize+ySpacing);
nCiv.setPanel(leftColumnCenterX-20, currentY1, leftColumnCenterX+120, currentY2);
guiCaptionNCiv.setPanel(leftColumnCenterX-120, currentY1, leftColumnCenterX-20, currentY2);
currentY1 -= (ySize+ySpacing);
currentY2 -= (ySize+ySpacing);
nTribeDwarven.setPanel(leftColumnCenterX-20, currentY1, leftColumnCenterX+120, currentY2);
guiCaptionNTribeDwarven.setPanel(leftColumnCenterX-180, currentY1, leftColumnCenterX-20, currentY2);
currentY1 -= (ySize+ySpacing);
currentY2 -= (ySize+ySpacing);
nTribeElven.setPanel(leftColumnCenterX-20, currentY1, leftColumnCenterX+120, currentY2);
guiCaptionNTribeElven.setPanel(leftColumnCenterX-180, currentY1, leftColumnCenterX-20, currentY2);
currentY1 -= (ySize+ySpacing);
currentY2 -= (ySize+ySpacing);
nTribe.setPanel(leftColumnCenterX-20, currentY1, leftColumnCenterX+120, currentY2);
guiCaptionNTribe.setPanel(leftColumnCenterX-180, currentY1, leftColumnCenterX-20, currentY2);
currentY1 -= (ySize+ySpacing);
currentY2 -= (ySize+ySpacing);
buttonGenerate.setPanel(leftColumnCenterX-170, currentY1, leftColumnCenterX+110, currentY2);
currentY1 -= (ySize+ySpacing);
currentY2 -= (ySize+ySpacing);
buttonSimWorld.setPanel(leftColumnCenterX-170, currentY1, leftColumnCenterX+110, currentY2);
currentY1 -= (ySize+ySpacing);
currentY2 -= (ySize+ySpacing);
buttonExportData.setPanel(leftColumnCenterX-170, currentY1, leftColumnCenterX+110, currentY2);
currentY1 -= (ySize+ySpacing);
currentY2 -= (ySize+ySpacing);
buttonLoadWorld.setPanel(leftColumnCenterX-170, currentY1, leftColumnCenterX+110, currentY2);
buttonExpandPreviewWindow.setPanel(0,0,32,32);
if(fullScreenPreview==false)
{
//std::cout<<"Preview mode.\n";
int panelSizeX = panelX2-panelX1;
int panelSizeY = panelY2-panelY1;
int worldPreviewX1=panelX1+(panelSizeX/2);
int worldPreviewY1=panelY1+(panelSizeY/2);
//worldViewer.setPanel(worldPreviewX1,worldPreviewY1,panelX2,panelY2);
//buttonExpandPreviewWindow.setPanel(worldPreviewX1,worldPreviewY1,worldPreviewX1+16,worldPreviewY1+16);
/* Put worldviewer in top right corner of panel. */
//worldViewer.setPanel(panelX2/2,panelY2/2,panelX2,panelY2);
worldViewer.setPanel(panelX2/2,panelY1 ,panelX2,panelY2);
}
else
{
//std::cout<<"Fullscreen preview.\n";
//worldViewer.setPanel(panelX1,panelY1,panelX2,panelY2);
//buttonExpandPreviewWindow.setPanel(panelX1,panelY1,panelX1+16,panelY1+16);
/* Make worldviewer fill screen. */
worldViewer.setPanel(panelX1,panelY1,panelX2,panelY2);
}
}
void render()
{
//This is a quickstart option to quickly generate a world.
// For some reason generating a world too early can cause a crash on
// subsequent generate calls.
// Moving the quickstart to the first render call seems to resolve this.
if ( QUICKSTART_GENERATOR )
{
eventGenerate();
QUICKSTART_GENERATOR=false;
}
// if ( textEntryWorldName.selected == true )
// { HOTKEYS_ENABLED=false; }
// else
// { HOTKEYS_ENABLED=true; }
/* World preview takes top-right quarter of screen. */
if(fullScreenPreview==false)
{
int panelSizeX = panelX2-panelX1;
int panelSizeY = panelY2-panelY1;
int worldPreviewX1=panelX1+(panelSizeX/2);
//int worldPreviewY1=panelY1+(panelSizeY/2);
int worldPreviewY1=panelY1;
/* Background image. */
//Renderer::placeTexture4(panelX1,panelY1,panelX2,panelY2,backgroundTexture,true);
//Renderer::placeTexture4(panelX1,panelY1,panelX2,panelY2,&TEX_WORLD_UNIT_NOMAD_01,true);
//Renderer::placeColour4(0,0,0,worldPreviewX1,worldPreviewY1,panelX2,panelY2);
//worldViewer.setPanel(worldPreviewX1,worldPreviewY1,panelX2,panelY2);
//buttonExpandPreviewWindow.setPanel(worldPreviewX1,worldPreviewY1,worldPreviewX1+16,worldPreviewY1+16);
}
else
{
//Renderer::placeColour4(0,0,0,panelX1,panelY1,panelX2,panelY2);
//worldViewer.setPanel(panelX1,panelY1,panelX2,panelY2);
//buttonExpandPreviewWindow.setPanel(panelX1,panelY1,panelX1+16,panelY1+16);
}
Renderer::placeTexture4(panelX1,panelY1,panelX2,panelY2,backgroundTexture,true);
//Renderer::placeTexture4(panelX1,panelY1,panelX2,panelY2,backgroundTexture,true);
worldViewer.render();
/* Render GUI controls. */
guiManager.render();
}
bool keyboardEvent(Keyboard* _keyboard)
{
if ( guiManager.keyboardEvent(_keyboard) )
{
return true;
}
// TAB will switch between adventure mode and god mode.
else if(_keyboard->isPressed(Keyboard::TAB))
{
std::cout<<"Enter World Simulator to enable Adventure mode\n";
_keyboard->unpress(Keyboard::TAB);
}
else if(_keyboard->isPressed(Keyboard::ONE)) /* Flush console. */
{
eventGenerate();
_keyboard->unpress(Keyboard::ONE);
return true;
}
else if(_keyboard->isPressed(Keyboard::TWO)) /* Flush console. */
{
_keyboard->unpress(Keyboard::TWO);
if (world.generated == true)
{
activeMenu = MENU_WORLDSIMULATOR;
world.startSimulation();
}
else
{
std::cout<<"You must first generate a world.\n";
}
}
else
{
worldViewer.keyboardEvent(_keyboard);
}
return false;
}
bool mouseEvent (Mouse* _mouse)
{
worldViewer.mouseEvent(_mouse);
/* If the guiManager did something with the mouse event. */
if(guiManager.mouseEvent(_mouse)==true)
{
if(buttonBack.clicked==true)
{
buttonBack.unclick();
active=false;
}
if(buttonGenerate.clicked==true)
{
buttonGenerate.unclick();
eventGenerate();
buttonGenerate.unclick();
}
if(buttonExpandPreviewWindow.clicked==true)
{
fullScreenPreview=!fullScreenPreview;
/* World preview takes top-right quarter of screen. */
if(fullScreenPreview==false)
{
/* Shrink the preview window. Restore GUI. */
int panelSizeX = panelX2-panelX1;
int panelSizeY = panelY2-panelY1;
int worldPreviewX1=panelX1+(panelSizeX/2);
int worldPreviewY1=panelY1+(panelSizeY/2);
buttonSimWorld.active=true;
buttonExportData.active=true;
buttonLoadWorld.active=true;
buttonGenerate.active=true;
textEntryWorldName.active=true;
textEntryFullSeed.active=true;
textEntryFullBiome.active=true;
textWorldSize.active=true;
textFreeSteps.active=true;
textIslandMode.active=true;
textWrapX.active=true;
textWrapY.active=true;
//Not currently functional
//buttonBack.active=true;
buttonBack.active=false;
worldSize.active=true;
freeSteps.active=true;
guiWrapX.active=true;
guiWrapY.active=true;
guiIslandMode.active=true;
worldViewer.setPanel(panelX2/2,panelY2/2,panelX2,panelY2);
}
else
{
/* Expand the preview window. Hide GUI. */
worldViewer.setPanel(panelX1,panelY1,panelX2,panelY2);
}
buttonExpandPreviewWindow.unclick();
}
if(buttonSimWorld.clicked==true)
{
buttonSimWorld.unclick();
if (world.generated == true)
{
activeMenu = MENU_WORLDSIMULATOR;
world.startSimulation();
}
else
{
std::cout<<"You must first generate a world.\n";
}
}
if ( buttonExportData.clicked==true)
{
std::cout<<"Export data\n";
world.save();
buttonExportData.unclick();
}
if ( buttonLoadWorld.clicked==true)
{
buttonLoadWorld.unclick();
}
}
return false;
}
bool stealKeyboard()
{
return guiManager.stealKeyboard();
}
void eventGenerate()
{
// First check to ensure the world has a name. Important because it's also the name of the savefile.
if ( textEntryWorldName.input == "" )
{
std::cout<<"Error: World needs a name.\n";
}
else if (DataTools::isAlphaNumeric(textEntryWorldName.input,true) == false)
{
std::cout<<"Error: World name must be alphanumeric.\n";
textEntryWorldName.input="";
}
else
{
int worldSizeV = DataTools::toInt(worldSize.getCurrentOption());
if (worldSizeV<0 || worldSizeV>100000)
{
std::cout<<"Warning. Strange worldsize. Attempting to continue.\n";
}
// If a seed string has been entered, either use the actual number,
// or hash it to a number if it contains non-numeric characters.
// This allows for a word seed to have a numeric equivalent.
int seed = 0;
if (textEntryFullSeed.input != "")
{
if ( DataTools::isNumeric(textEntryFullSeed.input))
{
seed = DataTools::toInt(textEntryFullSeed.input);
}
else
{
std::hash<std::string> hasher;
seed=hasher(textEntryFullSeed.input);
if ( seed < 0 )
{
seed *= -1;
}
}
}
// GET FRAGMENTATION
int fragmentation = DataTools::toInt(freeSteps.getCurrentOption());
bool islandMode = true;
if ( guiIslandMode.currentOption==1 )
{
islandMode=false;
}
bool wrapX = true;
if ( guiWrapX.currentOption==1 )
{
wrapX=false;
}
bool wrapY = true;
if ( guiWrapY.currentOption==1 )
{
wrapY=false;
}
double landPercent = (double) nLandPercent.currentValue / 100;
world.generateWorld(textEntryWorldName.input,worldSizeV,worldSizeV,seed,fragmentation,islandMode,wrapX,wrapY,landPercent); /* MEMORY LEAK */
world.nameRegions();
world.generateTribes(nTribe.currentValue,nTribeDwarven.currentValue,nTribeElven.currentValue);
}
}
// Load the specified world into the generator.
void eventLoad()
{
// First check to ensure the world has a name. Important because it's also the name of the savefile.
if ( textEntryWorldName.input == "" )
{
std::cout<<"Error: World needs a name.\n";
}
else if (DataTools::isAlphaNumeric(textEntryWorldName.input) == false)
{
std::cout<<"Error: World name must be alphanumeric.\n";
textEntryWorldName.input="";
}
else
{
world.loadWorld(textEntryWorldName.input);
}
}
};
#endif