WorldSim  inDev
2D tile-based sandbox RPG with procedurally generated fantasy world simulator 🌏
Menu_Title.hpp
Go to the documentation of this file.
1 #pragma once
2 #ifndef WORLDSIM_MENU_TITLE_HPP
3 #define WORLDSIM_MENU_TITLE_HPP
4 
5 /* WorldSim: Menu_Title
6  #include "Menu_Title.hpp"
7 
8  The title menu. This is the main menu, appearing when the application is launched,
9  and also when the player calls the main menu from within the game. It displays some
10  fancy opening cutscene, or some nice picture, and the basic options for starting
11  and configuring your game.
12 */
13 
14 class Menu_Title: public GUI_Interface, public LogicTickInterface
15 {
16  public:
17 
18 
19  /* Colours / theme. */
20  ColourRGB <unsigned char> cNormal;
21  ColourRGB <unsigned char> cSelected;
22  ColourRGB <unsigned char> cDropPanel;
23  ColourRGB <unsigned char> cHighlight;
24 
25  /* Button new game. */
26  GUI_Button buttonNewGame;
27  /* Button: Load game. */
28  GUI_Button buttonLoadGame;
29  /* Button: Options. */
30  GUI_Button buttonOptions;
31  /* Button: Quit */
32  GUI_Button buttonQuit;
33 
34 
35  /* Button: For testing random things. */
36  GUI_Button buttonTestSomething;
37 
38  /* GUI manager. Manages all GUI controls for this menu. */
39  GUI_Manager guiManager;
40 
41  /* Background image */
43 
45  {
46  active=false;
47  panelX1=0; panelY1=0; panelX2=0; panelY2=0;
48  font=0;
49  }
50 
51  void setFont(Wildcat::Font* _font)
52  {
53  font = _font;
54  guiManager.setFont(_font);
55  }
56 
57  void eventResize()
58  {
59  /* Update control positions. */
60  buttonNewGame.setPanel(panelCenterX-60, panelY2-20, panelCenterX+60, panelY2-40);
61  buttonLoadGame.setPanel(panelCenterX-60, panelY2-42, panelCenterX+60, panelY2-62);
62  buttonOptions.setPanel(panelCenterX-60, panelY2-64, panelCenterX+60, panelY2-84);
63  buttonQuit.setPanel(panelCenterX-60, panelY2-86, panelCenterX+60, panelY2-106);
64  buttonTestSomething.setPanel(panelCenterX-60, panelY2-108, panelCenterX+60, panelY2-128);
65  }
66 
67  void init()
68  {
69  cNormal.set(200,200,200);
70  cSelected.set(180,180,180);
71  cDropPanel.set(170,170,170);
72  cHighlight.set(170,170,170);
73 
74  buttonNewGame.text="1. New Game";
75  buttonNewGame.setColours(cNormal,cHighlight,0);
76 
77  buttonLoadGame.text="Load Game";
78  buttonLoadGame.setColours(cNormal,cHighlight,0);
79 
80  buttonOptions.text="Options";
81  buttonOptions.setColours(cNormal,cHighlight,0);
82 
83  buttonQuit.text="Quit";
84  buttonQuit.setColours(cNormal,cHighlight,0);
85 
86  buttonTestSomething.text="Test map";
87  buttonTestSomething.setColours(cNormal,cHighlight,0);
88  buttonTestSomething.active=true;
89 
90  /* Update GUI positions. */
91  eventResize();
92 
93  guiManager.addControl(&buttonNewGame);
94  guiManager.addControl(&buttonLoadGame);
95  guiManager.addControl(&buttonOptions);
96  guiManager.addControl(&buttonQuit);
97  guiManager.addControl(&buttonTestSomething);
98 
99  setFont(font);
100 
101  if ( QUICKSTART_GENERATOR )
102  {
103  //activeMenu = MENU_WORLDGENERATOR;
104  }
105 
106 
107  }
108  /* DisplayInterface:: */
109  void render()
110  {
111  /* Background image. Stretch to fit, preserve aspect ratio. */
112  Renderer::placeTexture4(panelX1,panelY1,panelX2,panelY2,backgroundTexture,true);
113  guiManager.render();
114  }
115 
116  /* MouseInterface:: */
117  bool mouseEvent (Mouse* _mouse)
118  {
119  /* If the guiManager did something with the mouse event. */
120  if(guiManager.mouseEvent(_mouse)==true)
121  {
122  if(buttonNewGame.clicked==true)
123  {
124  buttonNewGame.unclick();
126  return true;
127  }
128  if(buttonQuit.clicked==true)
129  {
130  QUIT_FLAG=true;
131  buttonQuit.clicked=false;
132  }
133  if(buttonOptions.clicked==true)
134  {
135  buttonOptions.clicked=false;
137  }
138  if(buttonLoadGame.clicked==true)
139  {
140  buttonLoadGame.clicked=false;
142  }
143  if ( buttonTestSomething.clicked == true )
144  {
145  buttonTestSomething.clicked = false;
146  buttonTestSomething.text="Yep it works";
147  }
148  }
149  return false;
150  }
151 
152  void logicTick()
153  {
154  // if(menuWorldGenerator.active==true)
155  // {
156  // menuWorldGenerator.logicTick();
157  // }
158  }
159 
160  bool keyboardEvent(Keyboard* _keyboard)
161  {
162  if ( guiManager.keyboardEvent(_keyboard) )
163  {
164  return true;
165  }
166 
167  if (_keyboard->isPressed(Keyboard::ONE) )
168  {
169  _keyboard->unpress(Keyboard::ONE);
170  //menuWorldGenerator.active=true;
172  return true;
173  }
174 
175  return false;
176  }
177 
179  {
180  return guiManager.stealKeyboard();
181  }
182 
183 };
184 
185 #endif
bool keyboardEvent(Keyboard *_keyboard)
Definition: Menu_Title.hpp:160
Definition: Driver_Settings_Enums.hpp:23
GUI_Manager guiManager
Definition: Menu_Title.hpp:39
GUI_Button buttonOptions
Definition: Menu_Title.hpp:30
ColourRGB< unsigned char > cSelected
Definition: Menu_Title.hpp:21
Definition: Driver_Settings_Enums.hpp:21
bool QUIT_FLAG
Definition: Driver_Settings.cpp:307
void eventResize()
Definition: Menu_Title.hpp:57
ColourRGB< unsigned char > cNormal
Definition: Menu_Title.hpp:20
void init()
Definition: Menu_Title.hpp:67
bool stealKeyboard()
Definition: Menu_Title.hpp:178
GUI_Button buttonLoadGame
Definition: Menu_Title.hpp:28
void render()
Definition: Menu_Title.hpp:109
bool QUICKSTART_GENERATOR
Definition: Driver_Settings.cpp:117
Definition: Menu_Title.hpp:14
Menu_Title()
Definition: Menu_Title.hpp:44
GUI_Button buttonQuit
Definition: Menu_Title.hpp:32
Definition: Driver_Settings_Enums.hpp:22
enumMenu activeMenu
Definition: Driver_Settings_Enums.hpp:29
void setFont(Wildcat::Font *_font)
Definition: Menu_Title.hpp:51
Texture * backgroundTexture
Definition: Menu_Title.hpp:42
void logicTick()
Definition: Menu_Title.hpp:152
GUI_Button buttonTestSomething
Definition: Menu_Title.hpp:36
ColourRGB< unsigned char > cDropPanel
Definition: Menu_Title.hpp:22
GUI_Button buttonNewGame
Definition: Menu_Title.hpp:26
ColourRGB< unsigned char > cHighlight
Definition: Menu_Title.hpp:23
bool mouseEvent(Mouse *_mouse)
Definition: Menu_Title.hpp:117