WorldSim  inDev
2D tile-based sandbox RPG with procedurally generated fantasy world simulator 🌏
Menu_WorldGenerator.hpp
Go to the documentation of this file.
1 #pragma once
2 #ifndef WORLDSIM_MENU_WORLD_GENERATOR_HPP
3 #define WORLDSIM_MENU_WORLD_GENERATOR_HPP
4 
5 /* WorldSim: Menu_WorldGenerator.hpp
6  #include "Menu_WorldGenerator.hpp"
7 
8  Implementation of GUI interface.
9  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.
10 
11 */
12 
13 #include <Graphics/GUI/GUI.hpp>
14 
15 #include <Device/Display/DisplayInterface.hpp>
16 #include <Device/Mouse/MouseInterface.hpp>
17 #include <Data/Debug/DebugMacro.hpp>
18 
19 #include <Data/DataTools.hpp> /* To check if seed is numeric */
20 
21 #include "Menu_AdventureMode.hpp"
22 
23 class Menu_WorldGenerator: public GUI_Interface
24 {
25  private:
26  GUI_Manager guiManager;
27 
28  /* Colours / theme. */
29  ColourRGB <unsigned char> cNormal;
30  ColourRGB <unsigned char> cSelected;
31  ColourRGB <unsigned char> cDropPanel;
32  ColourRGB <unsigned char> cHighlight;
33 
34  /* Background image */
35  Texture* backgroundTexture;
36  /* Button: Back to main menu. */
37  GUI_Button buttonBack;
38  /* Button: Expand preview window. */
39  GUI_Button buttonExpandPreviewWindow;
40  /* Textbox: Title for menu. */
41  GUI_TextBox textMenuTitle;
42  /* TextEntry: Name of the world. */
43  GUI_TextEntry textEntryWorldName;
44  /* TextEntry: Full seed value. */
45  GUI_TextEntry textEntryFullSeed;
46  /* TextEntry: Full biome value. */
47  GUI_TextEntry textEntryFullBiome;
48  /* Button: Generate the world. */
49  GUI_Button buttonGenerate;
50  /* Button: Keep this world and move to world simulation phase. */
51  GUI_Button buttonSimWorld;
52  /* Button: Export a bunch of data about the generated world. */
53  GUI_Button buttonExportData;
54  /* Button: Load a world. Note this only loads starting data. Which is geographic data and starting positions. */
55  GUI_Button buttonLoadWorld;
56  /* Number entry: World size (tiles). The world is square, so only one input is needed. */
57  GUI_CycleButton worldSize;
58  /* Textbox: Caption for worldsize selector. */
59  GUI_TextBox textWorldSize;
60  /* Number entry: World size (tiles). The world is square, so only one input is needed. */
61  GUI_CycleButton freeSteps;
62  /* Textbox: Caption for worldsize selector. */
63  GUI_TextBox textFreeSteps;
64  /* WrapX */
65  GUI_CycleButton guiWrapX;
66  GUI_TextBox textWrapX;
67  /* WrapY */
68  GUI_CycleButton guiWrapY;
69  GUI_TextBox textWrapY;
70  /* Island Mode */
71  GUI_CycleButton guiIslandMode;
72  GUI_TextBox textIslandMode;
73  /* Ocean percent */
74  GUI_NumberInput nLandPercent;
75  GUI_TextBox textOceanPercent;
76  /* Number entry: Number of civs to spawn into the world. */
77  GUI_NumberInput nCiv;
78  GUI_TextBox guiCaptionNCiv;
79  /* Number entry: Number of human tribes to spawn into the world. */
80  GUI_NumberInput nTribe;
81  GUI_TextBox guiCaptionNTribe;
82  /* Number entry: Number of Dwarven tribes to spawn into the world. */
83  GUI_NumberInput nTribeDwarven;
84  GUI_TextBox guiCaptionNTribeDwarven;
85  /* Number entry: Number of Elven tribes to spawn into the world. */
86  GUI_NumberInput nTribeElven;
87  GUI_TextBox guiCaptionNTribeElven;
88 
89  bool fullScreenPreview;
90 
91  public:
92 
94  {
95  fullScreenPreview=false;
97  worldViewer.active = false;
99  minimap.active=false;
100  buttonGenerate.clicked=false;
101  }
102 
103  void setFont(Wildcat::Font* _font)
104  {
105  font = _font;
106  guiManager.setFont(_font);
107  }
108 
109  void logicTick()
110  {
111  // if(menuWorldSimulator.active==true)
112  // {
113  // menuWorldSimulator.logicTick();
114  // }
115  }
116 
117  void init()
118  {
119  backgroundTexture=&TEX_NEW_GAME_BACKGROUND;
120  active=false;
121  fullScreenPreview=true;
122 
123  /* Initialise theme. */
124  cNormal.set(200,200,200);
125  cSelected.set(180,180,180);
126  cDropPanel.set(170,170,170);
127  cHighlight.set(170,170,170);
128 
129  buttonExpandPreviewWindow.setPanel(0,0,32,32);
130 
131  if(fullScreenPreview==false)
132  {
133 
134  int panelSizeX = panelX2-panelX1;
135  int panelSizeY = panelY2-panelY1;
136 
137  int worldPreviewX1=panelX1+(panelSizeX/2);
138  int worldPreviewY1=panelY1+(panelSizeY/2);
139 
140  //worldViewer.setPanel(worldPreviewX1,worldPreviewY1,panelX2,panelY2);
141  //buttonExpandPreviewWindow.setPanel(worldPreviewX1,worldPreviewY1,worldPreviewX1+16,worldPreviewY1+16);
142 
143  /* Put worldviewer in top right corner of panel. */
144  worldViewer.setPanel(panelX2/2,panelY2/2,panelX2,panelY2);
145  }
146  else
147  {
148  //worldViewer.setPanel(panelX1,panelY1,panelX2,panelY2);
149  //buttonExpandPreviewWindow.setPanel(panelX1,panelY1,panelX1+16,panelY1+16);
150 
151  /* Make worldviewer fill screen. */
152  worldViewer.setPanel(panelX1,panelY1,panelX2,panelY2);
153  }
154 
155  buttonBack.text="Back";
156  buttonBack.setColours(cNormal,cHighlight,0);
157 
158  /* WORLD SIZE */
159  worldSize.currentOption=DEFAULT_WORLD_SIZE_SLOT;
160  //worldSize.addOption("17");
161  worldSize.addOption("33");
162  worldSize.addOption("65");
163  worldSize.addOption("129");
164  worldSize.addOption("257");
165  worldSize.addOption("513");
166  worldSize.addOption("1025");
167  worldSize.addOption("2049");
168  worldSize.addOption("4097");
169  worldSize.addOption("8193");
170  worldSize.texCycleButton=&TEX_GUI_DECREMENT;
171  worldSize.setColours(cNormal,cHighlight,0);
172 
173  freeSteps.currentOption=0;
174  freeSteps.addOption("0");
175  freeSteps.addOption("1");
176  freeSteps.addOption("2");
177  freeSteps.addOption("3");
178  freeSteps.addOption("4");
179  freeSteps.addOption("5");
180  freeSteps.addOption("6");
181  freeSteps.addOption("7");
182  freeSteps.addOption("8");
183  freeSteps.addOption("9");
184  freeSteps.addOption("10");
185  freeSteps.addOption("11");
186  freeSteps.addOption("12");
187  freeSteps.texCycleButton=&TEX_GUI_DECREMENT;
188  freeSteps.setColours(cNormal,cHighlight,0);
189 
190  /* WrapX */
191  guiWrapX.currentOption=0;
192  guiWrapX.addOption("Yes");
193  guiWrapX.addOption("No");
194  guiWrapX.texCycleButton=&TEX_GUI_DECREMENT;
195  guiWrapX.setColours(cNormal,cHighlight,0);
196  guiWrapX.wrap=true;
197 
198  /* WrapY */
199  guiWrapY.currentOption=1;
200  guiWrapY.addOption("Yes");
201  guiWrapY.addOption("No");
202  guiWrapY.texCycleButton=&TEX_GUI_DECREMENT;
203  guiWrapY.setColours(cNormal,cHighlight,0);
204  guiWrapY.wrap=true;
205 
206  /* Island mode */
207  guiIslandMode.currentOption=0;
208  guiIslandMode.addOption("Yes");
209  guiIslandMode.addOption("No");
210  guiIslandMode.texCycleButton=&TEX_GUI_DECREMENT;
211  guiIslandMode.setColours(cNormal, cHighlight,0);
212  guiIslandMode.wrap=true;
213 
214  /* N CIV */
215  nCiv.setNumbers(0,128,DEFAULT_NUMBER_CIVS);
216  nCiv.setColours(cNormal,cHighlight,0);
217  nCiv.texIncrement = &TEX_GUI_INCREMENT;
218  nCiv.texDecrement = &TEX_GUI_DECREMENT;
219  guiCaptionNCiv.text="# civs:";
220  guiCaptionNCiv.setColours(cNormal);
221  guiCaptionNCiv.centeredY=true;
222 
223  /* Ocean percent */
224  nLandPercent.setNumbers(0,100,66);
225  nLandPercent.setColours(cNormal,cHighlight,0);
226  nLandPercent.texIncrement = &TEX_GUI_INCREMENT;
227  nLandPercent.texDecrement = &TEX_GUI_DECREMENT;
228  textOceanPercent.text="Land percent:";
229  textOceanPercent.setColours(cNormal);
230  textOceanPercent.centeredY=true;
231 
232  /* N TRIBE */
233  nTribe.setNumbers(0,100,DEFAULT_NUMBER_TRIBES_HUMAN);
234  nTribe.setColours(cNormal,cHighlight,0);
235  nTribe.texIncrement = &TEX_GUI_INCREMENT;
236  nTribe.texDecrement = &TEX_GUI_DECREMENT;
237  guiCaptionNTribe.text="# tribes:";
238  guiCaptionNTribe.setColours(cNormal);
239  guiCaptionNTribe.centeredY=true;
240 
241  /* N TRIBE DWARVEN */
242  nTribeDwarven.setNumbers(0,100,DEFAULT_NUMBER_TRIBES_DWARVEN);
243  nTribeDwarven.setColours(cNormal,cHighlight,0);
244  nTribeDwarven.texIncrement = &TEX_GUI_INCREMENT;
245  nTribeDwarven.texDecrement = &TEX_GUI_DECREMENT;
246  guiCaptionNTribeDwarven.text="# Dwarven tribes:";
247  guiCaptionNTribeDwarven.setColours(cNormal);
248  guiCaptionNTribeDwarven.centeredY=true;
249 
250  /* N TRIBE ELVEN */
251  nTribeElven.setNumbers(0,100,DEFAULT_NUMBER_TRIBES_ELVEN);
252  nTribeElven.setColours(cNormal,cHighlight,0);
253  nTribeElven.texIncrement = &TEX_GUI_INCREMENT;
254  nTribeElven.texDecrement = &TEX_GUI_DECREMENT;
255  guiCaptionNTribeElven.text="# Elven tribes:";
256  guiCaptionNTribeElven.setColours(cNormal);
257  guiCaptionNTribeElven.centeredY=true;
258 
259  /* GENERATE BUTTON */
260  buttonGenerate.text="1. Generate";
261  buttonGenerate.setColours(cNormal,cHighlight,0);
262 
263  /* WORLD NAME */
264  textEntryWorldName.setColours(cNormal,cHighlight);
265  textEntryWorldName.fieldName="World name:";
266  textEntryWorldName.characterLimit=20;
267  /* Give the world a random name */
268  //textEntryWorldName.input = globalNameGen.generateName();
269  textEntryWorldName.input = "testworld";
270 
271  /* WORLD SEED */
272  textEntryFullSeed.setColours(cNormal,cHighlight);
273  textEntryFullSeed.fieldName="World seed:";
274  textEntryFullSeed.characterLimit=16 ;
275  //textEntryFullSeed.input="1902830183";
276  textEntryFullSeed.input="";
277 
278  /* BIOME SEED */
279  textEntryFullBiome.setColours(cNormal,cHighlight);
280  textEntryFullBiome.fieldName="Biome seed:";
281  textEntryFullBiome.characterLimit=16;
282  textEntryFullBiome.input="";
283 
284  textWorldSize.text="World size:";
285  textWorldSize.setColours(cNormal);
286 
287  textFreeSteps.text="Fragmentation:";
288  textFreeSteps.setColours(cNormal);
289 
290  textWrapX.text="Wrap X:";
291  textWrapX.setColours(cNormal);
292 
293  textWrapY.text="Wrap Y:";
294  textWrapY.setColours(cNormal);
295 
296  textIslandMode.text="Island mode:";
297  textIslandMode.setColours(cNormal);
298 
299  textMenuTitle.text="World Generator";
300  textMenuTitle.setColours(cNormal);
301 
302  textMenuTitle.centeredX=true;
303  textMenuTitle.centeredY=true;
304 
305  buttonSimWorld.text="2. Simulate World";
306  buttonSimWorld.setColours(cNormal,cHighlight,0);
307 
308  buttonExportData.text="Export World Data (N/A)";
309  buttonExportData.setColours(cNormal,cHighlight,0);
310 
311  buttonLoadWorld.text="Load world (N/A)";
312  buttonLoadWorld.setColours(cNormal,cHighlight,0);
313 
314  buttonExpandPreviewWindow.texture = &TEX_GUI_EXPAND;
315 
316  guiManager.add(&textMenuTitle);
317  //Not currently functional
318  //guiManager.add(&buttonBack);
319  guiManager.add(&textEntryWorldName);
320  guiManager.add(&textEntryFullSeed);
321  guiManager.add(&textEntryFullBiome);
322  guiManager.add(&buttonGenerate);
323  guiManager.add(&textWorldSize);
324  guiManager.add(&textFreeSteps);
325  guiManager.add(&textIslandMode);
326  guiManager.add(&textWrapX);
327  guiManager.add(&textWrapY);
328  guiManager.add(&worldSize);
329  guiManager.add(&freeSteps);
330  guiManager.add(&guiIslandMode);
331  guiManager.add(&guiWrapX);
332  guiManager.add(&guiWrapY);
333  guiManager.add(&guiCaptionNCiv);
334  guiManager.add(&textOceanPercent);
335  guiManager.add(&nCiv);
336  guiManager.add(&nLandPercent);
337  guiManager.add(&guiCaptionNTribe);
338  guiManager.add(&guiCaptionNTribeDwarven);
339  guiManager.add(&guiCaptionNTribeElven);
340  guiManager.add(&nTribe);
341  guiManager.add(&nTribeDwarven);
342  guiManager.add(&nTribeElven);
343  guiManager.add(&buttonSimWorld);
344  guiManager.add(&buttonExportData);
345  guiManager.add(&buttonLoadWorld);
346  //guiManager.add(&buttonExpandPreviewWindow);
347 
348  // A TEMPORARY FIX TO STOP ACCIDENTALLY HITTING
349  // HOTKEYS WHILE TYPING.
350  globalGuiManager.add(&textEntryWorldName);
351  globalGuiManager.add(&textEntryFullSeed);
352  globalGuiManager.add(&textEntryFullBiome);
353 
354  guiManager.setFont(font);
355 
356  }
357 
358  void eventResize()
359  {
360  /* Menu title. */
361  textMenuTitle.setPanel(panelX1, panelY2, panelX2/2, panelY2-20);
362 
363  /* Bottom left corner. */
364  buttonBack.setPanel(panelX1,panelY1+20,panelX1+120,panelY1);
365  /* Left column, centered. */
366  const int leftColumnCenterX = panelX1+(panelNX/4);
367  textEntryWorldName.setPanel(panelX1+20, panelY2-30, (panelX2/2)-20, panelY2-40);
368 
369  textEntryFullSeed.setPanel(panelX1+20, panelY2-40, (panelX2/2)-20, panelY2-50);
370 
371  textEntryFullBiome.setPanel(panelX1+20, panelY2-50, (panelX2/2)-20, panelY2-60);
372 
373  int ySpacing = 2;
374  int ySize = 10;
375 
376  int currentY1 = panelY2 - 60;
377  int currentY2 = currentY1-ySize;
378 
379  currentY1 -= (ySize+ySpacing);
380  currentY2 -= (ySize+ySpacing);
381 
382  textWorldSize.setPanel(leftColumnCenterX-180, currentY1, leftColumnCenterX-20, currentY2);
383  worldSize.setPanel(leftColumnCenterX-20, currentY1, leftColumnCenterX+120, currentY2);
384 
385  currentY1 -= (ySize+ySpacing);
386  currentY2 -= (ySize+ySpacing);
387 
388  textFreeSteps.setPanel(leftColumnCenterX-180, currentY1, leftColumnCenterX-20, currentY2);
389  freeSteps.setPanel(leftColumnCenterX-20, currentY1, leftColumnCenterX+120, currentY2);
390 
391  currentY1 -= (ySize+ySpacing);
392  currentY2 -= (ySize+ySpacing);
393 
394  textIslandMode.setPanel(leftColumnCenterX-180, currentY1, leftColumnCenterX-20, currentY2);
395  guiIslandMode.setPanel(leftColumnCenterX-20, currentY1, leftColumnCenterX+120, currentY2);
396 
397  currentY1 -= (ySize+ySpacing);
398  currentY2 -= (ySize+ySpacing);
399 
400  textWrapX.setPanel(leftColumnCenterX-180, currentY1, leftColumnCenterX-20, currentY2);
401  guiWrapX.setPanel(leftColumnCenterX-20, currentY1, leftColumnCenterX+120, currentY2);
402 
403  currentY1 -= (ySize+ySpacing);
404  currentY2 -= (ySize+ySpacing);
405 
406  textWrapY.setPanel(leftColumnCenterX-180, currentY1, leftColumnCenterX-20, currentY2);
407  guiWrapY.setPanel(leftColumnCenterX-20, currentY1, leftColumnCenterX+120, currentY2);
408 
409  currentY1 -= (ySize+ySpacing);
410  currentY2 -= (ySize+ySpacing);
411 
412  textOceanPercent.setPanel(leftColumnCenterX-180, currentY1, leftColumnCenterX-20, currentY2);
413  nLandPercent.setPanel(leftColumnCenterX-20, currentY1, leftColumnCenterX+120, currentY2);
414 
415  currentY1 -= (ySize+ySpacing);
416  currentY2 -= (ySize+ySpacing);
417 
418  nCiv.setPanel(leftColumnCenterX-20, currentY1, leftColumnCenterX+120, currentY2);
419  guiCaptionNCiv.setPanel(leftColumnCenterX-120, currentY1, leftColumnCenterX-20, currentY2);
420 
421  currentY1 -= (ySize+ySpacing);
422  currentY2 -= (ySize+ySpacing);
423 
424  nTribe.setPanel(leftColumnCenterX-20, currentY1, leftColumnCenterX+120, currentY2);
425  guiCaptionNTribe.setPanel(leftColumnCenterX-120, currentY1, leftColumnCenterX-20, currentY2);
426 
427  currentY1 -= (ySize+ySpacing);
428  currentY2 -= (ySize+ySpacing);
429 
430  nTribeDwarven.setPanel(leftColumnCenterX-20, currentY1, leftColumnCenterX+120, currentY2);
431  guiCaptionNTribeDwarven.setPanel(leftColumnCenterX-180, currentY1, leftColumnCenterX-20, currentY2);
432 
433  currentY1 -= (ySize+ySpacing);
434  currentY2 -= (ySize+ySpacing);
435 
436  nTribeElven.setPanel(leftColumnCenterX-20, currentY1, leftColumnCenterX+120, currentY2);
437  guiCaptionNTribeElven.setPanel(leftColumnCenterX-180, currentY1, leftColumnCenterX-20, currentY2);
438 
439  currentY1 -= (ySize+ySpacing);
440  currentY2 -= (ySize+ySpacing);
441 
442  buttonGenerate.setPanel(leftColumnCenterX-120, currentY1, leftColumnCenterX+120, currentY2);
443 
444  currentY1 -= (ySize+ySpacing);
445  currentY2 -= (ySize+ySpacing);
446 
447  buttonSimWorld.setPanel(leftColumnCenterX-120, currentY1, leftColumnCenterX+120, currentY2);
448 
449  currentY1 -= (ySize+ySpacing);
450  currentY2 -= (ySize+ySpacing);
451 
452  buttonExportData.setPanel(leftColumnCenterX-120, currentY1, leftColumnCenterX+120, currentY2);
453 
454  currentY1 -= (ySize+ySpacing);
455  currentY2 -= (ySize+ySpacing);
456 
457  buttonLoadWorld.setPanel(leftColumnCenterX-120, currentY1, leftColumnCenterX+120, currentY2);
458 
459  buttonExpandPreviewWindow.setPanel(0,0,32,32);
460 
461 
462  if(fullScreenPreview==false)
463  {
464  //std::cout<<"Preview mode.\n";
465  int panelSizeX = panelX2-panelX1;
466  int panelSizeY = panelY2-panelY1;
467 
468  int worldPreviewX1=panelX1+(panelSizeX/2);
469  int worldPreviewY1=panelY1+(panelSizeY/2);
470 
471  //worldViewer.setPanel(worldPreviewX1,worldPreviewY1,panelX2,panelY2);
472  //buttonExpandPreviewWindow.setPanel(worldPreviewX1,worldPreviewY1,worldPreviewX1+16,worldPreviewY1+16);
473 
474  /* Put worldviewer in top right corner of panel. */
475  //worldViewer.setPanel(panelX2/2,panelY2/2,panelX2,panelY2);
476  worldViewer.setPanel(panelX2/2,panelY1 ,panelX2,panelY2);
477  }
478  else
479  {
480  //std::cout<<"Fullscreen preview.\n";
481  //worldViewer.setPanel(panelX1,panelY1,panelX2,panelY2);
482  //buttonExpandPreviewWindow.setPanel(panelX1,panelY1,panelX1+16,panelY1+16);
483  /* Make worldviewer fill screen. */
484  worldViewer.setPanel(panelX1,panelY1,panelX2,panelY2);
485  }
486  }
487 
488  void render()
489  {
490 
491  //This is a quickstart option to quickly generate a world.
492  // For some reason generating a world too early can cause a crash on
493  // subsequent generate calls.
494  // Moving the quickstart to the first render call seems to resolve this.
495  if ( QUICKSTART_GENERATOR )
496  {
497  eventGenerate();
498  QUICKSTART_GENERATOR=false;
499  }
500 
501  // if ( textEntryWorldName.selected == true )
502  // { HOTKEYS_ENABLED=false; }
503  // else
504  // { HOTKEYS_ENABLED=true; }
505 
506 
507  /* World preview takes top-right quarter of screen. */
508  if(fullScreenPreview==false)
509  {
510  int panelSizeX = panelX2-panelX1;
511  int panelSizeY = panelY2-panelY1;
512 
513  int worldPreviewX1=panelX1+(panelSizeX/2);
514  //int worldPreviewY1=panelY1+(panelSizeY/2);
515  int worldPreviewY1=panelY1;
516 
517 
518  /* Background image. */
519  //Renderer::placeTexture4(panelX1,panelY1,panelX2,panelY2,backgroundTexture,true);
520  //Renderer::placeTexture4(panelX1,panelY1,panelX2,panelY2,&TEX_WORLD_UNIT_NOMAD_01,true);
521  //Renderer::placeColour4(0,0,0,worldPreviewX1,worldPreviewY1,panelX2,panelY2);
522 
523  //worldViewer.setPanel(worldPreviewX1,worldPreviewY1,panelX2,panelY2);
524  //buttonExpandPreviewWindow.setPanel(worldPreviewX1,worldPreviewY1,worldPreviewX1+16,worldPreviewY1+16);
525 
526 
527 
528  }
529  else
530  {
531  //Renderer::placeColour4(0,0,0,panelX1,panelY1,panelX2,panelY2);
532  //worldViewer.setPanel(panelX1,panelY1,panelX2,panelY2);
533  //buttonExpandPreviewWindow.setPanel(panelX1,panelY1,panelX1+16,panelY1+16);
534 
535  }
536  Renderer::placeTexture4(panelX1,panelY1,panelX2,panelY2,backgroundTexture,true);
537  //Renderer::placeTexture4(panelX1,panelY1,panelX2,panelY2,backgroundTexture,true);
539  /* Render GUI controls. */
540  guiManager.render();
541 
542 
543  }
544 
545  bool keyboardEvent(Keyboard* _keyboard)
546  {
547  if ( guiManager.keyboardEvent(_keyboard) )
548  {
549  return true;
550  }
551 
552  // TAB will switch between adventure mode and god mode.
553  else if(_keyboard->isPressed(Keyboard::TAB))
554  {
555  std::cout<<"Enter World Simulator to enable Adventure mode\n";
556  _keyboard->unpress(Keyboard::TAB);
557  }
558 
559  else if(_keyboard->isPressed(Keyboard::ONE)) /* Flush console. */
560  {
561  eventGenerate();
562  _keyboard->unpress(Keyboard::ONE);
563  return true;
564  }
565 
566  else if(_keyboard->isPressed(Keyboard::TWO)) /* Flush console. */
567  {
568  _keyboard->unpress(Keyboard::TWO);
569  if (world.generated == true)
570  {
573  }
574  else
575  {
576  std::cout<<"You must first generate a world.\n";
577  }
578  }
579  else
580  {
581  worldViewer.keyboardEvent(_keyboard);
582  }
583 
584  return false;
585  }
586 
587  bool mouseEvent (Mouse* _mouse)
588  {
589  worldViewer.mouseEvent(_mouse);
590 
591  /* If the guiManager did something with the mouse event. */
592  if(guiManager.mouseEvent(_mouse)==true)
593  {
594 
595  if(buttonBack.clicked==true)
596  {
597  buttonBack.unclick();
598  active=false;
599  }
600  if(buttonGenerate.clicked==true)
601  {
602  buttonGenerate.unclick();
603  eventGenerate();
604  buttonGenerate.unclick();
605  }
606  if(buttonExpandPreviewWindow.clicked==true)
607  {
608  fullScreenPreview=!fullScreenPreview;
609  /* World preview takes top-right quarter of screen. */
610  if(fullScreenPreview==false)
611  {
612  /* Shrink the preview window. Restore GUI. */
613 
614  int panelSizeX = panelX2-panelX1;
615  int panelSizeY = panelY2-panelY1;
616 
617  int worldPreviewX1=panelX1+(panelSizeX/2);
618  int worldPreviewY1=panelY1+(panelSizeY/2);
619 
620  buttonSimWorld.active=true;
621  buttonExportData.active=true;
622  buttonLoadWorld.active=true;
623  buttonGenerate.active=true;
624  textEntryWorldName.active=true;
625  textEntryFullSeed.active=true;
626  textEntryFullBiome.active=true;
627  textWorldSize.active=true;
628  textFreeSteps.active=true;
629  textIslandMode.active=true;
630  textWrapX.active=true;
631  textWrapY.active=true;
632  //Not currently functional
633  //buttonBack.active=true;
634  buttonBack.active=false;
635  worldSize.active=true;
636  freeSteps.active=true;
637  guiWrapX.active=true;
638  guiWrapY.active=true;
639  guiIslandMode.active=true;
640 
641 
642 
643  worldViewer.setPanel(panelX2/2,panelY2/2,panelX2,panelY2);
644  }
645  else
646  {
647  /* Expand the preview window. Hide GUI. */
648  worldViewer.setPanel(panelX1,panelY1,panelX2,panelY2);
649  }
650  buttonExpandPreviewWindow.unclick();
651  }
652  if(buttonSimWorld.clicked==true)
653  {
654  buttonSimWorld.unclick();
655  if (world.generated == true)
656  {
659  }
660  else
661  {
662  std::cout<<"You must first generate a world.\n";
663  }
664 
665  }
666  if ( buttonExportData.clicked==true)
667  {
668  std::cout<<"Export data\n";
669  world.save();
670  buttonExportData.unclick();
671  }
672 
673  if ( buttonLoadWorld.clicked==true)
674  {
675  buttonLoadWorld.unclick();
676  }
677  }
678  return false;
679  }
680 
682  {
683  return guiManager.stealKeyboard();
684  }
685 
687  {
688  // First check to ensure the world has a name. Important because it's also the name of the savefile.
689 
690  if ( textEntryWorldName.input == "" )
691  {
692  std::cout<<"Error: World needs a name.\n";
693  }
694  else if (DataTools::isAlphaNumeric(textEntryWorldName.input,true) == false)
695  {
696  std::cout<<"Error: World name must be alphanumeric.\n";
697  textEntryWorldName.input="";
698  }
699  else
700  {
701  int worldSizeV = DataTools::toInt(worldSize.getCurrentOption());
702 
703  if (worldSizeV<0 || worldSizeV>100000)
704  {
705  std::cout<<"Warning. Strange worldsize. Attempting to continue.\n";
706  }
707  // If a seed string has been entered, either use the actual number,
708  // or hash it to a number if it contains non-numeric characters.
709  // This allows for a word seed to have a numeric equivalent.
710  int seed = 0;
711  if (textEntryFullSeed.input != "")
712  {
713  if ( DataTools::isNumeric(textEntryFullSeed.input))
714  {
715  seed = DataTools::toInt(textEntryFullSeed.input);
716  }
717  else
718  {
719  std::hash<std::string> hasher;
720  seed=hasher(textEntryFullSeed.input);
721  if ( seed < 0 )
722  {
723  seed *= -1;
724  }
725  }
726  }
727 
728  // GET FRAGMENTATION
729  int fragmentation = DataTools::toInt(freeSteps.getCurrentOption());
730 
731  bool islandMode = true;
732  if ( guiIslandMode.currentOption==1 )
733  {
734  islandMode=false;
735  }
736 
737  bool wrapX = true;
738  if ( guiWrapX.currentOption==1 )
739  {
740  wrapX=false;
741  }
742  bool wrapY = true;
743  if ( guiWrapY.currentOption==1 )
744  {
745  wrapY=false;
746  }
747 
748  double landPercent = (double) nLandPercent.currentValue / 100;
749 
750  world.generateWorld(textEntryWorldName.input,worldSizeV,worldSizeV,seed,fragmentation,islandMode,wrapX,wrapY,landPercent); /* MEMORY LEAK */
751  world.generateTribes(nTribe.currentValue,nTribeDwarven.currentValue,nTribeElven.currentValue);
752  world.nameRegions();
753  }
754  }
755 
756  // Load the specified world into the generator.
757  void eventLoad()
758  {
759  // First check to ensure the world has a name. Important because it's also the name of the savefile.
760  if ( textEntryWorldName.input == "" )
761  {
762  std::cout<<"Error: World needs a name.\n";
763  }
764  else if (DataTools::isAlphaNumeric(textEntryWorldName.input) == false)
765  {
766  std::cout<<"Error: World name must be alphanumeric.\n";
767  textEntryWorldName.input="";
768  }
769  else
770  {
771  world.loadWorld(textEntryWorldName.input);
772  }
773 
774  }
775 
776 };
777 
778 #endif
const int DEFAULT_WORLD_SIZE_SLOT
Definition: Driver_Settings.cpp:141
World * world
Definition: World_Viewer.hpp:170
void generateTribes(int, int, int)
Definition: World.cpp:819
void logicTick()
Definition: Menu_WorldGenerator.hpp:109
void generateWorld(const std::string, const int, const int, int, int, const bool, const bool, const bool, const double)
Definition: World.cpp:1355
void init()
Definition: Menu_WorldGenerator.hpp:117
World world
Definition: Driver.cpp:43
Menu_WorldGenerator()
Definition: Menu_WorldGenerator.hpp:93
void render()
Definition: World_Viewer.hpp:603
virtual void save()
Definition: World.cpp:2436
void eventGenerate()
Definition: Menu_WorldGenerator.hpp:686
WorldViewer worldViewer
Definition: World_Viewer.hpp:1214
WorldViewer_Minimap minimap
Definition: World_Viewer_Minimap.hpp:145
GUI_Manager globalGuiManager
Definition: Driver_GlobalObjects.hpp:95
void startSimulation()
Definition: World.cpp:190
bool QUICKSTART_GENERATOR
Definition: Driver_Settings.cpp:127
const int DEFAULT_NUMBER_TRIBES_HUMAN
Definition: Driver_Settings.cpp:144
bool mouseEvent(Mouse *_mouse)
Definition: Menu_WorldGenerator.hpp:587
Definition: Menu_WorldGenerator.hpp:23
void eventResize()
Definition: Menu_WorldGenerator.hpp:358
Definition: Driver_Settings.cpp:111
void eventLoad()
Definition: Menu_WorldGenerator.hpp:757
const int DEFAULT_NUMBER_TRIBES_ELVEN
Definition: Driver_Settings.cpp:145
void setFont(Wildcat::Font *_font)
Definition: Menu_WorldGenerator.hpp:103
enumMenu activeMenu
Definition: Driver_Settings.cpp:113
void setPanel(const int _x1, const int _y1, const int _x2, const int _y2)
Definition: World_Viewer.hpp:398
void render()
Definition: Menu_WorldGenerator.hpp:488
void nameRegions()
Definition: World.cpp:416
const int DEFAULT_NUMBER_CIVS
Definition: Driver_Settings.cpp:146
bool mouseEvent(Mouse *mouse)
Definition: World_Viewer.hpp:341
bool stealKeyboard()
Definition: Menu_WorldGenerator.hpp:681
bool generated
Definition: World.hpp:61
World * world
Definition: World_Viewer_Minimap.hpp:26
bool active
Definition: World_Viewer.hpp:146
const int DEFAULT_NUMBER_TRIBES_DWARVEN
Definition: Driver_Settings.cpp:143
bool keyboardEvent(Keyboard *_keyboard)
Definition: World_Viewer.hpp:261
bool loadWorld(std::string)
Definition: World.cpp:2306
bool keyboardEvent(Keyboard *_keyboard)
Definition: Menu_WorldGenerator.hpp:545