Elaztek Developer Hub
Blamite Game Engine - blam!  00346.12.11.21.0529.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 = nullptr;
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 
54  }
55 
56  return;
57  }
59  {
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  {
154  {
155  item->HandleKeyEnter();
156  }
157 
158  return;
159  }
161  {
163 
165  {
166  item->HandleKeyEnter();
167  }
168 
170 
171  return;
172  }
173  default:
174  {
175  return;
176  }
177  }
178  }
179 
183  void Draw()
184  {
185  if (show)
186  {
187  if (menu)
188  {
189  if (ImGui::Begin(menu->title.c_str(), &show))
190  {
191  ImGui::TextColored(ImVec4(1, 0, 0, 1), "this debug menu is not supported, please use PgUp and use the primary debug menu");
192  ImGui::TextColored(ImVec4(1, 0, 0, 1), "only use this if you seriously can't stand that one");
193 
194  for (int i = 0; i < menu->items.size(); i++)
195  {
196  if (menu->items.at(i).item_type == MENU_ITEM_TYPE_CATEGORY)
197  {
198  if (ImGui::CollapsingHeader(menu->items.at(i).title.c_str()))
199  {
200  for (int x = 0; x < menu->items.at(i).items.size(); x++)
201  {
202  GenerateItemControl(&menu->items.at(i).items.at(x));
203  }
204  }
205  }
206  else
207  {
208  GenerateItemControl(&menu->items.at(i));
209  }
210  }
211  }
212  }
213  else
214  {
215  if (ImGui::Begin("Main", &show))
216  {
217  ImGui::TextColored(ImVec4(1, 0, 0, 1), "debug menu does not appear to be loaded (menu was nullptr)");
218  }
219  }
220 
221  ImGui::End();
222  }
223  }
224  };
225 }
BlamDebugMenuItem::title
std::string title
The title of the debug menu item as shown in the menu.
Definition: debug_menu.h:53
ImGui::TreeNode
IMGUI_API bool TreeNode(const char *label)
Definition: imgui_widgets.cpp:5071
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:80
BlamDebugMenuItem::inc
double inc
How much to add or remove from the value at a time upon activation.
Definition: debug_menu.h:68
Blam::Globals::Int
@ Int
Represents an int.
Definition: globals.h:49
ImGui::Checkbox
IMGUI_API bool Checkbox(const char *label, bool *v)
Definition: imgui_widgets.cpp:974
Blam::Resources::DebugMenu::GetDebugMenu
BLAM BlamDebugMenu * GetDebugMenu()
Retrieves the debug menu data.
Definition: debug_menu.cpp:411
ImGui::PopStyleColor
IMGUI_API void PopStyleColor(int count=1)
Definition: imgui.cpp:6341
ImVec4
Definition: imgui.h:192
Blam::Globals::Long
@ Long
Represents a long.
Definition: globals.h:46
Blam::Globals
Namespace containing things relating to game engine globals.
Definition: globals.h:23
ImGui::End
IMGUI_API void End()
Definition: imgui.cpp:6016
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:73
ImGui::GetWindowContentRegionWidth
IMGUI_API float GetWindowContentRegionWidth()
Definition: imgui.cpp:6831
Blam::Globals::EngineGlobal::name
std::string name
The name of the global.
Definition: globals.h:67
Blam::Globals::EngineGlobal::short_value
short short_value
The short value of the global.
Definition: globals.h:77
debug_menu.h
ImGui::GetTextLineHeightWithSpacing
IMGUI_API float GetTextLineHeightWithSpacing()
Definition: imgui.cpp:6843
ImVec2
Definition: imgui.h:179
Float
@ Float
Definition: render_model.h:12
ImGui::Begin
IMGUI_API bool Begin(const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
Definition: imgui.cpp:5397
ImGui::CollapsingHeader
IMGUI_API bool CollapsingHeader(const char *label, ImGuiTreeNodeFlags flags=0)
Definition: imgui_widgets.cpp:5422
Blam::Globals::EngineGlobal
Structure containing data for a game engine global.
Definition: globals.h:64
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:78
BlamDebugMenuItem::item_type
BlamDebugMenuItemType item_type
The type of menu item. See BlamDebugMenuItemType for details.
Definition: debug_menu.h:52
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:49
Blam::Globals::Short
@ Short
Represents a short.
Definition: globals.h:45
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:79
BlamDebugMenu::items
std::vector< BlamDebugMenuItem > items
The list of items within the debug menu.
Definition: debug_menu.h:102
ImGui::TreePop
IMGUI_API void TreePop()
Definition: imgui_widgets.cpp:5380
BlamDebugMenuItem::global_id
std::string global_id
The ID of the engine global to modify upon activation.
Definition: debug_menu.h:66
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:70
BlamDebugMenuItem::use_bounds
bool use_bounds
Whether or not arbitrary bounds are specified in debug_menu_init.
Definition: debug_menu.h:67
BlamDebugMenu::title
std::string title
The title of the main page of the debug menu. Defaults to Main.
Definition: debug_menu.h:101
MENU_ITEM_TYPE_EXEC
#define MENU_ITEM_TYPE_EXEC
Macro for Executor. See #Blam::Resources::DebugMenu::Executor for details.
Definition: debug_menu.h:7
ImGuiCol_Text
@ ImGuiCol_Text
Definition: imgui.h:1027
ImGui::SliderFloat
IMGUI_API bool SliderFloat(const char *label, float *v, float v_min, float v_max, const char *format="%.3f", float power=1.0f)
Definition: imgui_widgets.cpp:2619
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:99
Blam::DebugUI::Windows
Legacy namespace to contain data for the legacy ImGUI console.
Definition: ui.h:14
x
config GlyphExtraSpacing x
Definition: README.txt:30
Blam::DebugUI::Windows::DebugMenu::GenerateItemControl
void GenerateItemControl(BlamDebugMenuItem *item)
Creates the appropriate control for the debug menu item.
Definition: debug_menu.hpp:40
ImGui::SliderInt
IMGUI_API bool SliderInt(const char *label, int *v, int v_min, int v_max, const char *format="%d")
Definition: imgui_widgets.cpp:2649
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:66
ImGui::TextColored
IMGUI_API void TextColored(const ImVec4 &col, const char *fmt,...) IM_FMTARGS(2)
Definition: imgui_widgets.cpp:257
ImGui::InputFloat
IMGUI_API bool InputFloat(const char *label, float *v, float step=0.0f, float step_fast=0.0f, const char *format="%.3f", ImGuiInputTextFlags flags=0)
Definition: imgui_widgets.cpp:2975
ImGui::Button
IMGUI_API bool Button(const char *label, const ImVec2 &size=ImVec2(0, 0))
Definition: imgui_widgets.cpp:644
ImGui::InputInt
IMGUI_API bool InputInt(const char *label, int *v, int step=1, int step_fast=100, ImGuiInputTextFlags flags=0)
Definition: imgui_widgets.cpp:3031
BlamDebugMenuItem::min
double min
The minimum value specified in debug_menu_init.
Definition: debug_menu.h:69
Blam::Globals::EngineGlobal::boolean_value
bool boolean_value
The boolean value of the global.
Definition: globals.h:76
ImGui::PushStyleColor
IMGUI_API void PushStyleColor(ImGuiCol idx, ImU32 col)
Definition: imgui.cpp:6321