Blamite Game Engine - blam!  00296.01.12.21.0102.blamite
The core library for the Blamite Game Engine.
globals_editor.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../../debug_ui.h"
4 
5 #include <Strings/components/utils/string/string.h>
6 
9 #include "components/3rdparty/imgui/misc/imgui_stdlib.h"
10 
11 namespace Blam::DebugUI::Windows
12 {
17  {
18  private:
19  char search_buffer[128];
20  bool use_tabs = false;
21  bool show_empty_tabs = false;
22 
28  void GenerateGlobalControl(Blam::Globals::EngineGlobal* global)
29  {
30  switch (global->type)
31  {
33  {
34  ImGui::Checkbox(global->name.c_str(), &global->boolean_value);
35  break;
36  }
38  {
39  ImGui::InputShort(global->name.c_str(), &global->short_value, 1, 10, NULL);
40  break;
41  }
43  {
44  ImGui::InputLong(global->name.c_str(), &global->long_value, 1, 10, NULL);
45  break;
46  }
48  {
49  ImGui::InputText(global->name.c_str(), &global->value_raw);
50  break;
51  }
53  {
54  ImGui::InputInt(global->name.c_str(), &global->int_value);
55  break;
56  }
58  {
59  ImGui::InputFloat(global->name.c_str(), &global->float_value);
60  break;
61  }
63  {
64  float color_values[4];
65  {
66  color_values[0] = global->color_value.GetRedAsFloat();
67  color_values[1] = global->color_value.GetGreenAsFloat();
68  color_values[2] = global->color_value.GetBlueAsFloat();
69  color_values[3] = global->color_value.GetAlphaAsFloat();
70  }
71 
72  ImGui::ColorEdit4(global->name.c_str(), color_values);
73 
74  global->color_value.r = color_values[0] * 255;
75  global->color_value.g = color_values[1] * 255;
76  global->color_value.b = color_values[2] * 255;
77  global->color_value.a = color_values[3] * 255;
78  break;
79  }
80  default:
81  {
82  ImGui::TextColored(ImVec4(1, 0, 0, 1), std::string("this global is not supported for editing: '" + global->name + "'").c_str());
83  break;
84  }
85  }
86 
87  if (global->info.size() > 0)
88  {
89  ImGui::SameLine();
91  }
92  }
93 
109  void GenerateGlobalGroupedControls(std::string string_id_type, std::vector<Blam::Globals::EngineGlobal*> list)
110  {
111  if (list.size() > 0 || show_empty_tabs)
112  {
113  std::string tab_title_id = "globals_editor_group_" + string_id_type + "_title";
114  std::string tab_desc_id = "globals_editor_group_" + string_id_type + "_desc";
115  std::string empty_message_id = "globals_editor_group_" + string_id_type + "_empty";
116 
117  if (ImGui::BeginTabItem(ENGINE_TEXT(tab_title_id).c_str()))
118  {
119  ImGui::Text(ENGINE_TEXT(tab_desc_id).c_str());
120 
121  ImGui::Separator();
122 
123  if (list.size() == 0)
124  {
125  ImGui::TextDisabled(ENGINE_TEXT(empty_message_id).c_str());
126  }
127 
128  for (int i = 0; i < list.size(); i++)
129  {
130  GenerateGlobalControl(list.at(i));
131  }
132 
133  ImGui::EndTabItem();
134  }
135  }
136  }
137 
138  public:
139  void Draw()
140  {
141  if (show)
142  {
143  if (ImGui::Begin("Engine Globals", &show))
144  {
145  ImGui::InputTextWithHint("", "filter globals by name...", search_buffer, 128);
146 
147  ImGui::Checkbox("group into tabs", &use_tabs);
148 
149  if (use_tabs)
150  {
151  ImGui::SameLine();
152  ImGui::Checkbox("show empty tabs", &show_empty_tabs);
153  }
154 
155  std::map<std::string, Blam::Globals::EngineGlobal>* globals = Blam::Globals::GetGlobalsList();
156  std::map<std::string, Blam::Globals::EngineGlobal>::iterator it;
157 
158  std::string search_filter = std::string(search_buffer);
159 
160  if (search_filter.length() == 0)
161  {
162  if (use_tabs)
163  {
164  std::vector<Blam::Globals::EngineGlobal*> boolean_globals = std::vector<Blam::Globals::EngineGlobal*>();
165  std::vector<Blam::Globals::EngineGlobal*> float_globals = std::vector<Blam::Globals::EngineGlobal*>();
166  std::vector<Blam::Globals::EngineGlobal*> short_globals = std::vector<Blam::Globals::EngineGlobal*>();
167  std::vector<Blam::Globals::EngineGlobal*> int_globals = std::vector<Blam::Globals::EngineGlobal*>();
168  std::vector<Blam::Globals::EngineGlobal*> long_globals = std::vector<Blam::Globals::EngineGlobal*>();
169  std::vector<Blam::Globals::EngineGlobal*> string_globals = std::vector<Blam::Globals::EngineGlobal*>();
170  std::vector<Blam::Globals::EngineGlobal*> color_globals = std::vector<Blam::Globals::EngineGlobal*>();
171  std::vector<Blam::Globals::EngineGlobal*> unsorted_globals = std::vector<Blam::Globals::EngineGlobal*>();
172 
173  for (it = globals->begin(); it != globals->end(); it++)
174  {
175  switch (it->second.type)
176  {
178  {
179  boolean_globals.push_back(&it->second);
180  break;
181  }
183  {
184  short_globals.push_back(&it->second);
185  break;
186  }
188  {
189  long_globals.push_back(&it->second);
190  break;
191  }
193  {
194  string_globals.push_back(&it->second);
195  break;
196  }
198  {
199  int_globals.push_back(&it->second);
200  break;
201  }
203  {
204  float_globals.push_back(&it->second);
205  break;
206  }
208  {
209  color_globals.push_back(&it->second);
210  break;
211  }
212  default:
213  {
214  unsorted_globals.push_back(&it->second);
215  break;
216  }
217  }
218  }
219 
220  if (ImGui::BeginTabBar("globals_editor_tabs"))
221  {
222  if (boolean_globals.size() > 0 || show_empty_tabs)
223  {
224  GenerateGlobalGroupedControls("boolean", boolean_globals);
225  GenerateGlobalGroupedControls("float", float_globals);
226  GenerateGlobalGroupedControls("short", short_globals);
227  GenerateGlobalGroupedControls("int", int_globals);
228  GenerateGlobalGroupedControls("long", long_globals);
229  GenerateGlobalGroupedControls("string", string_globals);
230  GenerateGlobalGroupedControls("color", color_globals);
231  GenerateGlobalGroupedControls("unsorted", unsorted_globals);
232  }
233 
234  ImGui::EndTabBar();
235  }
236  }
237  else
238  {
239  ImGui::Separator();
240 
241  for (it = globals->begin(); it != globals->end(); it++)
242  {
243  GenerateGlobalControl(&it->second);
244  }
245  }
246  }
247  else
248  {
249  std::vector<Blam::Globals::EngineGlobal*> matching_globals = std::vector<Blam::Globals::EngineGlobal*>();
250  int omitted_count = 0;
251 
252  for (it = globals->begin(); it != globals->end(); it++)
253  {
254  if (BlamStrings::Utils::String::Contains(it->second.name, search_filter))
255  {
256  matching_globals.push_back(&it->second);
257  }
258  else
259  {
260  omitted_count++;
261  }
262  }
263 
264  ImGui::Separator();
265 
266  ImGui::TextDisabled(std::string("showing matching globals only, omitting " + std::to_string(omitted_count) + " globals").c_str());
267 
268  for (int i = 0; i < matching_globals.size(); i++)
269  {
270  GenerateGlobalControl(matching_globals.at(i));
271  }
272  }
273  }
274  ImGui::End();
275  }
276  }
277  };
278 }
Blam::DebugUI::Widgets::ShowHelpMarker
BLAM void ShowHelpMarker(const char *desc)
Shows a help indicator.
Definition: widgets.cpp:7
Blam::Globals::EngineGlobal::float_value
float float_value
The float value of the global.
Definition: globals.h:78
Blam::Globals::EngineGlobal::info
std::string info
An optional description of the global.
Definition: globals.h:66
Blam::Globals::Int
@ Int
Represents an int.
Definition: globals.h:47
Blam::Globals::EngineGlobal::color_value
BlamColor color_value
The color value of the global.
Definition: globals.h:79
Blam::Globals::Long
@ Long
Represents a long.
Definition: globals.h:44
engine_text.h
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
globals
std::map< std::string, EngineGlobal > globals
The list of loaded globals.
Definition: globals.cpp:20
Blam::Globals::String
@ String
Represents a std::string.
Definition: globals.h:46
Float
@ Float
Definition: render_model.h:17
Blam::Globals::EngineGlobal
Structure containing data for a game engine global.
Definition: globals.h:62
globals.h
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
Blam::Globals::EngineGlobal::long_value
long long_value
The long value of the global.
Definition: globals.h:76
Blam::DebugUI::ImGUIDrawingGroup
Class representing an ImGUI drawing group/draw list item.
Definition: debug_ui.h:359
Blam::Globals::Short
@ Short
Represents a short.
Definition: globals.h:43
Blam::Globals::EngineGlobal::int_value
int int_value
The int value of the global.
Definition: globals.h:77
Blam::DebugUI::Windows::GlobalsEditor::Draw
void Draw()
Draws the contents of the group.
Definition: globals_editor.hpp:139
Blam::Globals::GetGlobalsList
BLAM std::map< std::string, EngineGlobal > * GetGlobalsList()
Retrieves the list of loaded globals.
Definition: globals.cpp:22
Blam::Globals::Color
@ Color
Represents a BlamColor. See #BlamColor for details.
Definition: globals.h:49
Blam::Globals::Boolean
@ Boolean
Represents a boolean. Can be true or false.
Definition: globals.h:41
ENGINE_TEXT
#define ENGINE_TEXT(string_id)
Definition: engine_text.h:7
Blam::Globals::EngineGlobal::value_raw
std::string value_raw
The raw value of the global as a string.
Definition: globals.h:67
Blam::DebugUI::Windows
Legacy namespace to contain data for the legacy ImGUI console.
Definition: debug_ui.h:434
Text
@ Text
Master text object that wraps around both BitmapText and DWText.
Definition: render_stack.h:73
Blam::Globals::EngineGlobal::type
GvarType type
The type of the global.
Definition: globals.h:64
Blam::DebugUI::Windows::GlobalsEditor
Class for the engine Globals editor.
Definition: globals_editor.hpp:16
Blam::Globals::EngineGlobal::boolean_value
bool boolean_value
The boolean value of the global.
Definition: globals.h:74