Blamite Game Engine - blam!  00296.01.12.21.0102.blamite
The core library for the Blamite Game Engine.
menu_item.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include "../../../render_stack.h"
10 
12 {
19  {
20  Rectangle* background;
21  BitmapText* index;
22  BitmapText* label;
23 
24  int bar_width = 0;
25  int bar_height = 0;
26 
27  D2D1_COLOR_F inactive_color = D2D1::ColorF(204.0f / 255.0f, 204.0f / 255.0f, 191.0f / 255.0f);
28  D2D1_COLOR_F active_color = D2D1::ColorF(0, 0, 0);
29  D2D1_COLOR_F active_color_2 = D2D1::ColorF(91 / 255.0f, 91 / 255.0f, 85 / 255.0f);
30 
31  D2D1_COLOR_F category_text_color = D2D1::ColorF(12 / 255.0f, 165 / 255.0f, 12 / 255.0f);
32  D2D1_COLOR_F prop_text_color = D2D1::ColorF(76 / 255.0f, 107 / 255.0f, 84 / 255.0f);
33  D2D1_COLOR_F exec_text_color = D2D1::ColorF(255 / 255.0f, 127 / 255.0f, 0 / 255.0f);
34  D2D1_COLOR_F unknown_text_color = D2D1::ColorF(1, 0, 0);
35 
36  Rectangle* global_bg;
37  BitmapText* global_value_label;
38  int global_view_width_base = 60;
39  int global_view_space_between_base = 5;
40 
41  // Scaled properties
42  int global_view_width = global_view_width_base;
43  int global_view_space_between = global_view_space_between_base;
44 
46 
47  public:
48  bool active = false;
49  int menu_index_num = 0;
50 
51  bool lock = false;
52  bool deleting = false;
53 
55 
57 
62  {
64 
65  // Load some configuration settings
66  {
67  useAlternateDebugMenuUnknownGlobalDisplay = Blam::Config::GetConfig()->GetBoolean("useAlternateDebugMenuUnknownGlobalDisplay");
68  }
69 
70  // background layer
71  {
72  background = new Rectangle();
73 
74  background->fill_color = inactive_color;
75  background->draw_mode = DRAWMODE_FILL;
76  }
77 
78  // number label
79  {
80  index = new BitmapText();
81  index->color = unknown_text_color;
82  index->font_id = Blam::Config::GetConfig()->GetString("ui_default_font");
83  index->use_shadow = true;
84  index->shadow_x = 1;
85  index->shadow_y = 1;
86  index->shadow_color = D2D1::ColorF(0, 0, 0);
87  }
88 
89  // label
90  {
91  label = new BitmapText();
92  label->color = unknown_text_color;
93  label->font_id = Blam::Config::GetConfig()->GetString("ui_default_font");
94  label->use_shadow = true;
95  label->shadow_x = 1;
96  label->shadow_y = 1;
97  label->shadow_color = D2D1::ColorF(0, 0, 0);
98  }
99 
100  // global value bg
101  {
102  global_bg = new Rectangle();
103 
104  global_bg->fill_color = inactive_color;
105  global_bg->draw_mode = DRAWMODE_FILL;
106  }
107 
108  // global value label
109  {
110  global_value_label = new BitmapText();
111  global_value_label->color = prop_text_color;
112  global_value_label->font_id = Blam::Config::GetConfig()->GetString("ui_default_font");
113  global_value_label->use_shadow = true;
114  global_value_label->shadow_x = 1;
115  global_value_label->shadow_y = 1;
116  global_value_label->shadow_color = D2D1::ColorF(0, 0, 0);
117  global_value_label->text = "<global>";
118  }
119 
120 
123 
124  animation.Initialize(active_color, active_color_2, 1.3f, true);
125  animation.Start();
126  }
127 
132  {
133  deleting = true;
134 
135  while (lock)
136  {
137  // wait
138  }
139 
140  delete background;
141  delete index;
142  delete label;
143  delete global_bg;
144  delete global_value_label;
145 
146  //delete this;
147  }
148 
149  void OnTickEvent(TickEvent* event)
150  {
151  if (active)
152  {
153  background->fill_color = animation.GetColor();
154  }
155  else
156  {
157  background->fill_color = inactive_color;
158  }
159  }
160 
165  {
167  {
168  label->color = exec_text_color;
169  index->color = exec_text_color;
170  }
172  {
173  label->color = category_text_color;
174  index->color = category_text_color;
175  }
177  {
179  {
180  label->color = prop_text_color;
181  index->color = prop_text_color;
182  }
183  else
184  {
186  {
187  label->color = unknown_text_color;
188  index->color = unknown_text_color;
189  }
190  else
191  {
192  label->color = prop_text_color;
193  index->color = prop_text_color;
194  }
195  }
196  }
198  {
199  label->color = exec_text_color;
200  index->color = exec_text_color;
201  }
202  else
203  {
204  label->color = unknown_text_color;
205  index->color = unknown_text_color;
206  }
207  }
208 
215  void SetDefaultBarDimensions(int _width, int _height)
216  {
217  bar_width = _width;
218  bar_height = _height;
219  }
220 
228  {
229  float ui_scale_factor = *Blam::Globals::GetGlobalAsFloat("ui_scale_factor");
230 
231  global_view_space_between = global_view_space_between_base * ui_scale_factor;
232  global_view_width = global_view_width_base * ui_scale_factor;
233 
234  background->SetSize(bar_width, bar_height);
235  background->SetTranslation(x, y);
236 
238  {
240  {
242  {
243  global_bg->visible = false;
244  global_value_label->visible = false;
245 
246  index->text = "UNDEFINED: " + menu_item.global_id;
247  label->text = "";
248  }
249  else
250  {
251  label->text = menu_item.title;
252  index->text = std::to_string(menu_index_num);
253  }
254  }
255  else
256  {
257  label->text = menu_item.title;
258  index->text = std::to_string(menu_index_num);
259  }
260  }
261  else
262  {
263  label->text = menu_item.title;
264  index->text = std::to_string(menu_index_num);
265  }
266 
267  index->SetTranslation(x + (8 * ui_scale_factor), y - (2 * ui_scale_factor));
268 
269  label->SetTranslation(x + (26 * ui_scale_factor), y - (2 * ui_scale_factor));
270 
271  global_bg->SetSize(global_view_width, bar_height);
272  global_bg->SetTranslation(x - (global_view_space_between + global_view_width), y);
273 
274  global_value_label->SetTranslation(global_bg->x + (3 * ui_scale_factor), y - (2 * ui_scale_factor));
275 
277  }
278 
283  void Draw()
284  {
285  if (!deleting)
286  {
287  lock = true;
288 
289  background->Draw();
290  index->Draw();
291  label->Draw();
292 
294  {
296 
297  if (global)
298  {
299  if (global->type == Blam::Globals::GvarType::Boolean)
300  {
301  if (global->boolean_value == true)
302  {
303  global_value_label->text = "True";
304  }
305  else
306  {
307  global_value_label->text = "False";
308  }
309  }
310  else if (global->type == Blam::Globals::GvarType::String)
311  {
312  global_value_label->text = "<str>";
313  }
314  else
315  {
316  global_value_label->text = global->value_raw;
317  }
318  }
319 
320  global_bg->Draw();
321  global_value_label->Draw();
322  }
323  }
324 
325  lock = false;
326  }
327 
329  {
330 
331  }
332 
337  {
338  visible = !visible;
339  }
340 
346  void SetActive(bool _active)
347  {
348  active = _active;
349 
350  /*if (active)
351  {
352  background->fill_color = active_color;
353  global_bg->fill_color = active_color;
354  }
355  else
356  {
357  background->fill_color = inactive_color;
358  global_bg->fill_color = inactive_color;
359  }*/
360  }
361 
366  {
368  }
369 
374  {
376  }
377 
382  {
384  }
385  };
386 }
BlamRendering::RenderStack::StackObjectBase::draw_mode
StackItemDrawMode draw_mode
The drawing mode of the object.
Definition: render_stack.h:373
BlamDebugMenuItem::title
std::string title
The title of the debug menu item as shown in the menu.
Definition: debug_menu.h:51
Blam::Events::RegisterListener
BLAM void RegisterListener(BlamEventListener *listener)
Registers a an event listener.
Definition: events.cpp:75
BlamRendering::RenderStack::BitmapText::shadow_color
D2D1_COLOR_F shadow_color
The color to use for the drop shadow.
Definition: render_stack.h:851
BlamRendering::RenderStack::StackObjectBase::visible
bool visible
Whether or not the object is visible.
Definition: render_stack.h:375
Blam::Globals::GetGlobal
BLAM EngineGlobal * GetGlobal(std::string name)
Retrieves a global with the specified ID.
Definition: globals.cpp:193
Blam::Globals::GlobalExists
BLAM bool GlobalExists(std::string id)
Determines whether or not a global exists.
Definition: globals.cpp:27
BlamRendering::RenderStack::DebugMenuItem::HandleKeyRight
void HandleKeyRight()
Called when the Right arrow is pressed.
Definition: menu_item.hpp:373
BlamRendering::RenderStack::BitmapText::font_id
std::string font_id
The ID of the font.
Definition: render_stack.h:844
Blam::Animation::ColorTransitionAnimation
Animation used to handle an alternating fade between two colors.
Definition: ColorTransition.h:22
BlamRendering::RenderStack::DebugMenuItem::UpdateMetadata
void UpdateMetadata()
Refresh any data needed for the item.
Definition: menu_item.hpp:227
BitmapText
@ BitmapText
Bitmap-based text, uses Blamite font system.
Definition: render_stack.h:72
BlamRendering::RenderStack::StackObjectBase::type_label
StackType type_label
The type of the object.
Definition: render_stack.h:372
BlamDebugMenuItem::HandleKeyLeft
void HandleKeyLeft()
Called when the menu item is active and the left arrow key is pressed.
Definition: BlamDebugMenuItem.cpp:41
Blam::Config::GetConfig
BLAM ConfigFile * GetConfig()
Definition: compat.cpp:5
Blam::Globals::GetGlobalAsFloat
BLAM float * GetGlobalAsFloat(std::string name)
Retrieves a global's value as a float.
Definition: globals.cpp:400
Generic
@ Generic
Generic stack type - should probably not be used.
Definition: render_stack.h:57
BlamRendering::RenderStack
Namespace containing things relating to the Render Stack.
Definition: drawing.h:14
BlamRendering::RenderStack::BitmapText::shadow_y
int shadow_y
The Y offset of the drop shadow.
Definition: render_stack.h:850
BlamRendering::RenderStack::DebugMenuItem::useAlternateDebugMenuUnknownGlobalDisplay
bool useAlternateDebugMenuUnknownGlobalDisplay
Definition: menu_item.hpp:56
BlamRendering::RenderStack::DebugMenuItem::~DebugMenuItem
~DebugMenuItem()
Deletes any resources used by the item.
Definition: menu_item.hpp:131
BlamRendering::RenderStack::DebugMenuItem::UpdateItemTextColor
void UpdateItemTextColor()
Updates the text color of the item based on the item type.
Definition: menu_item.hpp:164
BlamRendering::RenderStack::Rectangle
Class containing data for a Rectangle object.
Definition: render_stack.h:418
BlamRendering::RenderStack::DebugMenuItem::HandleKeyLeft
void HandleKeyLeft()
Called when the Left arrow is pressed.
Definition: menu_item.hpp:365
debug_menu.h
Blam::Animation::ColorTransitionAnimation::GetColor
D2D1_COLOR_F GetColor()
Returns the evaluated color data.
Definition: ColorTransition.h:171
BlamRendering::RenderStack::Rectangle::Draw
void Draw()
Draws the stack object.
Definition: Rectangle.cpp:10
BlamRendering::RenderStack::DebugMenuItem::Draw
void Draw()
Draws the item, as well as the field for the global value if the item represents a global editor.
Definition: menu_item.hpp:283
Blam::Globals::String
@ String
Represents a std::string.
Definition: globals.h:46
events.h
BlamRendering::RenderStack::BitmapText::text
std::string text
The text to display.
Definition: render_stack.h:846
BlamRendering::RenderStack::DebugMenuItem::menu_item
BlamDebugMenuItem menu_item
The data to use for this menu item.
Definition: menu_item.hpp:54
Blam::Animation::ColorTransitionAnimation::Initialize
void Initialize(D2D1_COLOR_F _c1, D2D1_COLOR_F _c2, float fade_duration, bool _loop)
Prepares data needed for the animation.
Definition: ColorTransition.h:133
BlamRendering::RenderStack::StackObjectBase::color
D2D1_COLOR_F color
The color of the object.
Definition: render_stack.h:370
tick.h
Blam::Globals::EngineGlobal
Structure containing data for a game engine global.
Definition: globals.h:62
MENU_ITEM_TYPE_CATEGORY
#define MENU_ITEM_TYPE_CATEGORY
Macro for Submenu. See #Blam::Resources::DebugMenu::Submenu for details.
Definition: debug_menu.h:8
TickEvent
Class representing an engine tick event.
Definition: TickEvent.h:10
BlamRendering::RenderStack::StackObjectBase::y
float y
The Y coordinate of the object.
Definition: render_stack.h:378
BlamRendering::RenderStack::DebugMenuItem::ItemTriggered
void ItemTriggered()
Called when the item is activated, usually from the Enter key.
Definition: menu_item.hpp:381
globals.h
BlamDebugMenuItem::HandleKeyRight
void HandleKeyRight()
Called when the menu item is active and the right arrow key is pressed.
Definition: BlamDebugMenuItem.cpp:168
BlamRendering::RenderStack::BitmapText::Draw
void Draw()
Draws the stack object.
Definition: BitmapText.cpp:13
BlamRendering::RenderStack::DebugMenuItem
Stack item representing a single item within the debug menu.
Definition: menu_item.hpp:18
MENU_ITEM_TYPE_MULTIEXEC
#define MENU_ITEM_TYPE_MULTIEXEC
Macro for ExecSequence. See #Blam::Resources::DebugMenu::ExecSequence for details.
Definition: debug_menu.h:10
BlamDebugMenuItem::item_type
BlamDebugMenuItemType item_type
The type of menu item. See BlamDebugMenuItemType for details.
Definition: debug_menu.h:50
ColorTransition.h
BlamRendering::RenderStack::DebugMenuItem::SetDefaultBarDimensions
void SetDefaultBarDimensions(int _width, int _height)
Sets the default size of the item.
Definition: menu_item.hpp:215
BlamRendering::RenderStack::DebugMenuItem::toggleVisibility
void toggleVisibility()
Toggles the item's visibility.
Definition: menu_item.hpp:336
BlamRendering::RenderStack::BitmapText::use_shadow
bool use_shadow
Whether or not to draw the text with a drop shadow.
Definition: render_stack.h:852
BlamDebugMenuItem
Class used to store data and functions relating to an item within the engine's debug menu.
Definition: debug_menu.h:47
Blam::Config::ConfigFile::GetBoolean
bool GetBoolean(std::string option)
Definition: compat.cpp:38
BlamRendering::RenderStack::DebugMenuItem::deleting
bool deleting
Whether or not this item is being deleted. Used to prevent drawing while the item is being deleted.
Definition: menu_item.hpp:52
BlamRendering::RenderStack::StackObjectBase::SetTranslation
void SetTranslation(float new_x, float new_y)
Sets the translation of the object.
Definition: StackObjectBase.cpp:55
BlamDebugMenuItem::global_id
std::string global_id
The ID of the engine global to modify upon activation.
Definition: debug_menu.h:64
BlamRendering::RenderStack::DebugMenuItem::menu_index_num
int menu_index_num
The index of this item in the menu.
Definition: menu_item.hpp:49
BlamRendering::RenderStack::DebugMenuItem::lock
bool lock
Whether or not this item is locked. Used to prevent deletion while the item is being drawn.
Definition: menu_item.hpp:51
BlamRendering::RenderStack::DebugMenuItem::ShowImPropertyEditor
void ShowImPropertyEditor()
Shows a set of ImGUI properties associated with the object.
Definition: menu_item.hpp:328
BlamRendering::RenderStack::DebugMenuItem::DebugMenuItem
DebugMenuItem()
Prepares the item for drawing.
Definition: menu_item.hpp:61
BlamDebugMenuItem::HandleKeyEnter
void HandleKeyEnter()
Called when the menu item is active and the enter key is pressed.
Definition: BlamDebugMenuItem.cpp:11
Blam::Animation::ColorTransitionAnimation::Start
void Start()
Instructs the listener to start animating.
Definition: ColorTransition.h:157
BlamEventListener::Subscribe
void Subscribe(BlamEventType type)
Subscribes to an event type.
Definition: BlamEventListener.cpp:3
MENU_ITEM_TYPE_EXEC
#define MENU_ITEM_TYPE_EXEC
Macro for Executor. See #Blam::Resources::DebugMenu::Executor for details.
Definition: debug_menu.h:7
Blam::Globals::Boolean
@ Boolean
Represents a boolean. Can be true or false.
Definition: globals.h:41
BlamRendering::RenderStack::DebugMenuItem::active
bool active
Whether or not this item is active.
Definition: menu_item.hpp:48
EventType_Tick
@ EventType_Tick
Definition: BlamEvent.h:9
BlamRendering::RenderStack::BitmapText::shadow_x
int shadow_x
The X offset of the drop shadow.
Definition: render_stack.h:849
MENU_ITEM_TYPE_GLOBAL
#define MENU_ITEM_TYPE_GLOBAL
Macro for Global. See #Blam::Resources::DebugMenu::Global for details.
Definition: debug_menu.h:9
DRAWMODE_FILL
#define DRAWMODE_FILL
Definition: render_stack.h:33
Blam::Config::ConfigFile::GetString
std::string GetString(std::string option)
Definition: compat.cpp:58
Blam::Globals::EngineGlobal::value_raw
std::string value_raw
The raw value of the global as a string.
Definition: globals.h:67
config.h
BlamRendering::RenderStack::BitmapText
Class representing text drawn using a Bitmap-based engine font.
Definition: render_stack.h:794
BlamRendering::RenderStack::StackObjectBase
Base class for all render stack objects.
Definition: render_stack.h:194
BlamEventListener
Class representing an Event Listener.
Definition: events.h:27
BlamRendering::RenderStack::DebugMenuItem::OnTickEvent
void OnTickEvent(TickEvent *event)
Called when the listener is subscribed to Key Press events, and a new TickEvent is fired.
Definition: menu_item.hpp:149
BlamRendering::RenderStack::StackObjectBase::SetSize
void SetSize(float new_width, float new_height)
Sets the size of the object.
Definition: StackObjectBase.cpp:110
Blam::Globals::EngineGlobal::type
GvarType type
The type of the global.
Definition: globals.h:64
BlamRendering::RenderStack::Rectangle::fill_color
D2D1_COLOR_F fill_color
The current fill color.
Definition: render_stack.h:453
BlamRendering::RenderStack::DebugMenuItem::SetActive
void SetActive(bool _active)
Sets whether or not this item should be displayed as the active item.
Definition: menu_item.hpp:346
Blam::Globals::EngineGlobal::boolean_value
bool boolean_value
The boolean value of the global.
Definition: globals.h:74
BlamRendering::RenderStack::StackObjectBase::x
float x
The X coordinate of the object.
Definition: render_stack.h:377