Blamite Game Engine - blam!  00296.01.12.21.0102.blamite
The core library for the Blamite Game Engine.
debug_menu.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../debug_ui.h"
4 
7 
9 {
21  {
22  private:
23  BlamDebugMenu menu;
24  public:
29  {
31  }
32 
41  {
42  switch (item->item_type)
43  {
45  {
46  if (ImGui::TreeNode(item->title.c_str()))
47  {
48  for (int i = 0; i < item->items.size(); i++)
49  {
50  GenerateItemControl(&item->items.at(i));
51  }
52 
53  ImGui::TreePop();
54  }
55 
56  return;
57  }
59  {
60  if (ImGui::Button(item->title.c_str(), ImVec2(ImGui::GetWindowContentRegionWidth(), ImGui::GetTextLineHeightWithSpacing())))
61  {
62  item->HandleKeyEnter();
63  }
64 
65  return;
66  }
68  {
69  using namespace Blam::Globals;
70 
71  EngineGlobal* global = GetGlobal(item->global_id);
72 
73  if (global)
74  {
75  switch (global->type)
76  {
77  case GvarType::Boolean:
78  {
79  ImGui::Checkbox(item->title.c_str(), &global->boolean_value);
80  return;
81  }
82  case GvarType::Int:
83  {
84  if (item->use_bounds)
85  {
86  ImGui::SliderInt(item->title.c_str(), &global->int_value, item->min, item->max);
87  }
88  else
89  {
90  ImGui::InputInt(item->title.c_str(), &global->int_value, 1, item->inc);
91  }
92 
93  return;
94  }
95  case GvarType::Long:
96  {
97  if (item->use_bounds)
98  {
99  ImGui::SliderInt(item->title.c_str(), (int*)&global->long_value, item->min, item->max);
100  }
101  else
102  {
103  ImGui::InputInt(item->title.c_str(), (int*)&global->long_value, 1, item->inc);
104  }
105 
106  return;
107  }
108  case GvarType::Short:
109  {
110  if (item->use_bounds)
111  {
112  ImGui::SliderInt(item->title.c_str(), (int*)&global->short_value, item->min, item->max);
113  }
114  else
115  {
116  ImGui::InputInt(item->title.c_str(), (int*)&global->short_value, 1, item->inc);
117  }
118 
119  return;
120  }
121  case GvarType::Float:
122  {
123  if (item->use_bounds)
124  {
125  ImGui::SliderFloat(item->title.c_str(), &global->float_value, item->min, item->max);
126  }
127  else
128  {
129  ImGui::InputFloat(item->title.c_str(), &global->float_value, 1, item->inc);
130  }
131 
132  return;
133  }
134  default:
135  {
136  std::string text = "UNSUPPORTED: " + item->title + " (" + global->name + ")";
137  ImGui::TextColored(ImVec4(1, 0, 0, 1), text.c_str());
138 
139  return;
140  }
141  }
142  }
143  else
144  {
145  std::string text = "UNDEFINED: " + item->title + " (" + item->global_id + ")";
146  ImGui::TextColored(ImVec4(1, 0, 0, 1), text.c_str());
147  }
148 
149  return;
150  }
152  {
153  if (ImGui::Button(item->title.c_str(), ImVec2(ImGui::GetWindowContentRegionWidth(), ImGui::GetTextLineHeightWithSpacing())))
154  {
155  item->HandleKeyEnter();
156  }
157 
158  return;
159  }
161  {
162  ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1, 0, 0, 1));
163 
164  if (ImGui::Button(item->title.c_str(), ImVec2(ImGui::GetWindowContentRegionWidth(), ImGui::GetTextLineHeightWithSpacing())))
165  {
166  item->HandleKeyEnter();
167  }
168 
169  ImGui::PopStyleColor();
170 
171  return;
172  }
173  default:
174  {
175  return;
176  }
177  }
178  }
179 
183  void Draw()
184  {
185  if (show)
186  {
187  if (ImGui::Begin(menu.title.c_str(), &show))
188  {
189  ImGui::TextColored(ImVec4(1, 0, 0, 1), "this debug menu is not supported, please use PgUp and use the primary debug menu");
190  ImGui::TextColored(ImVec4(1, 0, 0, 1), "only use this if you seriously can't stand that one");
191 
192  for (int i = 0; i < menu.items.size(); i++)
193  {
194  if (menu.items.at(i).item_type == MENU_ITEM_TYPE_CATEGORY)
195  {
196  if (ImGui::CollapsingHeader(menu.items.at(i).title.c_str()))
197  {
198  for (int x = 0; x < menu.items.at(i).items.size();x++)
199  {
200  GenerateItemControl(&menu.items.at(i).items.at(x));
201  }
202  }
203  }
204  else
205  {
206  GenerateItemControl(&menu.items.at(i));
207  }
208  }
209  }
210  ImGui::End();
211  }
212  }
213  };
214 }
BlamDebugMenuItem::title
std::string title
The title of the debug menu item as shown in the menu.
Definition: debug_menu.h:51
Blam::Globals::GetGlobal
BLAM EngineGlobal * GetGlobal(std::string name)
Retrieves a global with the specified ID.
Definition: globals.cpp:193
Blam::Globals::EngineGlobal::float_value
float float_value
The float value of the global.
Definition: globals.h:78
BlamDebugMenuItem::inc
double inc
How much to add or remove from the value at a time upon activation.
Definition: debug_menu.h:66
Blam::Globals::Int
@ Int
Represents an int.
Definition: globals.h:47
Blam::Globals::Long
@ Long
Represents a long.
Definition: globals.h:44
Blam::Globals
Namespace containing things relating to game engine globals.
Definition: globals.h:21
Blam::DebugUI::Windows::DebugMenu
Class for the ImGUI-based debug menu implementation.
Definition: debug_menu.hpp:20
console.h
BlamDebugMenuItem::items
std::vector< BlamDebugMenuItem > items
The contents of the submenu to show upon activation.
Definition: debug_menu.h:71
Blam::Globals::EngineGlobal::name
std::string name
The name of the global.
Definition: globals.h:65
Blam::Globals::EngineGlobal::short_value
short short_value
The short value of the global.
Definition: globals.h:75
debug_menu.h
Float
@ Float
Definition: render_model.h:17
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
Blam::DebugUI::Windows::DebugMenu::DebugMenu
DebugMenu()
Retrieves the debug menu data.
Definition: debug_menu.hpp:28
Blam::DebugUI::ImGUIDrawingGroup::show
bool show
Controls whether or not the group should be shown. May not be used in all groups.
Definition: debug_ui.h:362
MENU_ITEM_TYPE_MULTIEXEC
#define MENU_ITEM_TYPE_MULTIEXEC
Macro for ExecSequence. See #Blam::Resources::DebugMenu::ExecSequence for details.
Definition: debug_menu.h:10
Blam::Globals::EngineGlobal::long_value
long long_value
The long value of the global.
Definition: globals.h:76
BlamDebugMenuItem::item_type
BlamDebugMenuItemType item_type
The type of menu item. See BlamDebugMenuItemType for details.
Definition: debug_menu.h:50
Blam::DebugUI::ImGUIDrawingGroup
Class representing an ImGUI drawing group/draw list item.
Definition: debug_ui.h:359
BlamDebugMenuItem
Class used to store data and functions relating to an item within the engine's debug menu.
Definition: debug_menu.h:47
Blam::Globals::Short
@ Short
Represents a short.
Definition: globals.h:43
Blam::DebugUI::Windows::DebugMenu::Draw
void Draw()
Draws the debug menu window.
Definition: debug_menu.hpp:183
Blam::Globals::EngineGlobal::int_value
int int_value
The int value of the global.
Definition: globals.h:77
BlamDebugMenu::items
std::vector< BlamDebugMenuItem > items
The list of items within the debug menu.
Definition: debug_menu.h:100
BlamDebugMenuItem::global_id
std::string global_id
The ID of the engine global to modify upon activation.
Definition: debug_menu.h:64
BlamDebugMenuItem::HandleKeyEnter
void HandleKeyEnter()
Called when the menu item is active and the enter key is pressed.
Definition: BlamDebugMenuItem.cpp:11
BlamDebugMenuItem::max
double max
The maximum value specified in debug_menu_init.
Definition: debug_menu.h:68
BlamDebugMenuItem::use_bounds
bool use_bounds
Whether or not arbitrary bounds are specified in debug_menu_init.
Definition: debug_menu.h:65
BlamDebugMenu::title
std::string title
The title of the main page of the debug menu. Defaults to Main.
Definition: debug_menu.h:99
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
MENU_ITEM_TYPE_GLOBAL
#define MENU_ITEM_TYPE_GLOBAL
Macro for Global. See #Blam::Resources::DebugMenu::Global for details.
Definition: debug_menu.h:9
BlamDebugMenu
Structure containing data for the root of the debug menu.
Definition: debug_menu.h:97
Blam::DebugUI::Windows
Legacy namespace to contain data for the legacy ImGUI console.
Definition: debug_ui.h:434
Blam::DebugUI::Windows::DebugMenu::GenerateItemControl
void GenerateItemControl(BlamDebugMenuItem *item)
Creates the appropriate control for the debug menu item.
Definition: debug_menu.hpp:40
MENU_ITEM_TYPE_UNKNOWN
#define MENU_ITEM_TYPE_UNKNOWN
Macro for Unknown. See #Blam::Resources::DebugMenu::Unknown for details.
Definition: debug_menu.h:6
Blam::Globals::EngineGlobal::type
GvarType type
The type of the global.
Definition: globals.h:64
BlamDebugMenuItem::min
double min
The minimum value specified in debug_menu_init.
Definition: debug_menu.h:67
Blam::Resources::DebugMenu::GetDebugMenu
BLAM BlamDebugMenu GetDebugMenu()
Retrieves the debug menu data.
Definition: debug_menu.cpp:25
Blam::Globals::EngineGlobal::boolean_value
bool boolean_value
The boolean value of the global.
Definition: globals.h:74