Elaztek Developer Hub
Blamite Game Engine - blam!  00406.12.10.23.1457.blamite
The core library for the Blamite Game Engine.
globals_editor.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <Strings/components/utils/string/string.h>
6 
10 
15 {
16 private:
17  char search_buffer[128];
18  bool use_tabs = false;
19  bool show_empty_tabs = false;
20 
26  void GenerateGlobalControl(BlamEngineGlobal* global)
27  {
28  switch (global->type)
29  {
31  {
32  ImGui::Checkbox(global->name.c_str(), &global->boolean_value);
33  break;
34  }
36  {
37  ImGui::InputShort(global->name.c_str(), &global->short_value, 1, 10, NULL);
38  break;
39  }
41  {
42  ImGui::InputLong(global->name.c_str(), &global->long_value, 1, 10, NULL);
43  break;
44  }
46  {
47  ImGui::InputText(global->name.c_str(), &global->value_raw);
48  break;
49  }
51  {
52  ImGui::InputInt(global->name.c_str(), &global->int_value);
53  break;
54  }
56  {
57  ImGui::InputFloat(global->name.c_str(), &global->float_value);
58  break;
59  }
61  {
62  float color_values[4];
63  {
64  color_values[0] = global->color_value.GetRedAsFloat();
65  color_values[1] = global->color_value.GetGreenAsFloat();
66  color_values[2] = global->color_value.GetBlueAsFloat();
67  color_values[3] = global->color_value.GetAlphaAsFloat();
68  }
69 
70  ImGui::ColorEdit4(global->name.c_str(), color_values);
71 
72  global->color_value.r = color_values[0] * 255;
73  global->color_value.g = color_values[1] * 255;
74  global->color_value.b = color_values[2] * 255;
75  global->color_value.a = color_values[3] * 255;
76  break;
77  }
78  default:
79  {
80  ImGui::TextColored(ImVec4(1, 0, 0, 1), std::string("this global is not supported for editing: '" + global->name + "'").c_str());
81  break;
82  }
83  }
84 
85  if (global->info.size() > 0)
86  {
89  }
90  }
91 
107  void GenerateGlobalGroupedControls(std::string string_id_type, std::vector<BlamEngineGlobal*> list)
108  {
109  if (list.size() > 0 || show_empty_tabs)
110  {
111  std::string tab_title_id = "globals_editor_group_" + string_id_type + "_title";
112  std::string tab_desc_id = "globals_editor_group_" + string_id_type + "_desc";
113  std::string empty_message_id = "globals_editor_group_" + string_id_type + "_empty";
114 
115  if (ImGui::BeginTabItem(ENGINE_TEXT(tab_title_id).c_str()))
116  {
117  ImGui::Text(ENGINE_TEXT(tab_desc_id).c_str());
118 
120 
121  if (list.size() == 0)
122  {
123  ImGui::TextDisabled(ENGINE_TEXT(empty_message_id).c_str());
124  }
125 
126  for (int i = 0; i < list.size(); i++)
127  {
128  GenerateGlobalControl(list.at(i));
129  }
130 
132  }
133  }
134  }
135 
136 public:
137  void Draw()
138  {
139  if (show)
140  {
141  if (ImGui::Begin("Engine Globals", &show))
142  {
143  ImGui::InputTextWithHint("", "filter globals by name...", search_buffer, 128);
144 
145  ImGui::Checkbox("group into tabs", &use_tabs);
146 
147  if (use_tabs)
148  {
149  ImGui::SameLine();
150  ImGui::Checkbox("show empty tabs", &show_empty_tabs);
151  }
152 
153  std::map<std::string, BlamEngineGlobal>* globals = Blam::Globals::GetGlobalsList();
154  std::map<std::string, BlamEngineGlobal>::iterator it;
155 
156  std::string search_filter = std::string(search_buffer);
157 
158  if (search_filter.length() == 0)
159  {
160  if (use_tabs)
161  {
162  std::vector<BlamEngineGlobal*> boolean_globals = std::vector<BlamEngineGlobal*>();
163  std::vector<BlamEngineGlobal*> float_globals = std::vector<BlamEngineGlobal*>();
164  std::vector<BlamEngineGlobal*> short_globals = std::vector<BlamEngineGlobal*>();
165  std::vector<BlamEngineGlobal*> int_globals = std::vector<BlamEngineGlobal*>();
166  std::vector<BlamEngineGlobal*> long_globals = std::vector<BlamEngineGlobal*>();
167  std::vector<BlamEngineGlobal*> string_globals = std::vector<BlamEngineGlobal*>();
168  std::vector<BlamEngineGlobal*> color_globals = std::vector<BlamEngineGlobal*>();
169  std::vector<BlamEngineGlobal*> unsorted_globals = std::vector<BlamEngineGlobal*>();
170 
171  for (it = globals->begin(); it != globals->end(); it++)
172  {
173  switch (it->second.type)
174  {
176  {
177  boolean_globals.push_back(&it->second);
178  break;
179  }
181  {
182  short_globals.push_back(&it->second);
183  break;
184  }
186  {
187  long_globals.push_back(&it->second);
188  break;
189  }
191  {
192  string_globals.push_back(&it->second);
193  break;
194  }
195  case BlamGlobalType::Int:
196  {
197  int_globals.push_back(&it->second);
198  break;
199  }
201  {
202  float_globals.push_back(&it->second);
203  break;
204  }
206  {
207  color_globals.push_back(&it->second);
208  break;
209  }
210  default:
211  {
212  unsorted_globals.push_back(&it->second);
213  break;
214  }
215  }
216  }
217 
218  if (ImGui::BeginTabBar("globals_editor_tabs"))
219  {
220  if (boolean_globals.size() > 0 || show_empty_tabs)
221  {
222  GenerateGlobalGroupedControls("boolean", boolean_globals);
223  GenerateGlobalGroupedControls("real", float_globals);
224  GenerateGlobalGroupedControls("short", short_globals);
225  GenerateGlobalGroupedControls("int", int_globals);
226  GenerateGlobalGroupedControls("long", long_globals);
227  GenerateGlobalGroupedControls("string", string_globals);
228  GenerateGlobalGroupedControls("color", color_globals);
229  GenerateGlobalGroupedControls("unsorted", unsorted_globals);
230  }
231 
233  }
234  }
235  else
236  {
238 
239  for (it = globals->begin(); it != globals->end(); it++)
240  {
241  GenerateGlobalControl(&it->second);
242  }
243  }
244  }
245  else
246  {
247  std::vector<BlamEngineGlobal*> matching_globals = std::vector<BlamEngineGlobal*>();
248  int omitted_count = 0;
249 
250  for (it = globals->begin(); it != globals->end(); it++)
251  {
252  if (BlamStrings::Utils::String::Contains(it->second.name, search_filter))
253  {
254  matching_globals.push_back(&it->second);
255  }
256  else
257  {
258  omitted_count++;
259  }
260  }
261 
263 
264  ImGui::TextDisabled(std::string("showing matching globals only, omitting " + std::to_string(omitted_count) + " globals").c_str());
265 
266  for (int i = 0; i < matching_globals.size(); i++)
267  {
268  GenerateGlobalControl(matching_globals.at(i));
269  }
270  }
271  }
272  ImGui::End();
273  }
274  }
275 };
BlamImGuiWindow_GlobalsEditor
Class for the engine Globals editor.
Definition: globals_editor.hpp:14
Short
@ Short
!< Represents a float.
Definition: globals.h:36
globals
Definition: globals.h:25
ImGui::Checkbox
IMGUI_API bool Checkbox(const char *label, bool *v)
Definition: imgui_widgets.cpp:974
BlamImGuiWindow::show
bool show
Controls whether or not the group should be shown. May not be used in all groups.
Definition: imgui.h:34
ImVec4
Definition: imgui.h:192
Real
@ Real
Definition: globals.h:35
ImGui::InputText
IMGUI_API bool InputText(const char *label, char *buf, size_t buf_size, ImGuiInputTextFlags flags=0, ImGuiInputTextCallback callback=NULL, void *user_data=NULL)
Definition: imgui_widgets.cpp:3068
BlamEngineGlobal::name
std::string name
The name of the global.
Definition: globals.h:57
ImGui::End
IMGUI_API void End()
Definition: imgui.cpp:6016
ImGui::EndTabItem
IMGUI_API void EndTabItem()
Definition: imgui_widgets.cpp:6851
engine_text.h
BlamEngineGlobal::boolean_value
bool boolean_value
The boolean value of the global.
Definition: globals.h:66
imgui_stdlib.h
ImGui::SameLine
IMGUI_API void SameLine(float offset_from_start_x=0.0f, float spacing=-1.0f)
Definition: imgui.cpp:7147
BlamImGuiWindow
Class representing an ImGUI window.
Definition: imgui.h:31
NULL
Add a fourth parameter to bake specific font ranges NULL
Definition: README.txt:57
Int
@ Int
Represents an int.
Definition: globals.h:40
BlamEngineGlobal::info
std::string info
An optional description of the global.
Definition: globals.h:58
Blam::UI::ImGUI::Widgets::ShowHelpMarker
BLAM void ShowHelpMarker(const char *desc)
Shows a help indicator.
Definition: widgets.cpp:7
BlamEngineGlobal::type
BlamGlobalType type
The type of the global.
Definition: globals.h:56
ImGui::Begin
IMGUI_API bool Begin(const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
Definition: imgui.cpp:5397
ImGui::BeginTabBar
IMGUI_API bool BeginTabBar(const char *str_id, ImGuiTabBarFlags flags=0)
Definition: imgui_widgets.cpp:6366
String
@ String
Represents a std::string.
Definition: globals.h:39
ImGui::Text
IMGUI_API void Text(const char *fmt,...) IM_FMTARGS(1)
Definition: imgui_widgets.cpp:238
BlamEngineGlobal
Structure containing data for a game engine global.
Definition: globals.h:54
ImGui::InputTextWithHint
IMGUI_API bool InputTextWithHint(const char *label, const char *hint, char *buf, size_t buf_size, ImGuiInputTextFlags flags=0, ImGuiInputTextCallback callback=NULL, void *user_data=NULL)
Definition: imgui_widgets.cpp:3079
globals.h
BlamEngineGlobal::short_value
short short_value
The short value of the global.
Definition: globals.h:67
it
ARPHIC PUBLIC LICENSE Ltd Yung Chi Taiwan All rights reserved except as specified below Everyone is permitted to copy and distribute verbatim copies of this license but changing it is forbidden Preamble The licenses for most software are designed to take away your freedom to share and change it By the ARPHIC PUBLIC LICENSE specifically permits and encourages you to use this provided that you give the recipients all the rights that we gave you and make sure they can get the modifications of this software Legal Terms Font means the TrueType fonts AR PL Mingti2L AR PL KaitiM AR PL KaitiM and the derivatives of those fonts created through any modification including modifying reordering converting changing font or adding deleting some characters in from glyph table PL means Public License Copyright Holder means whoever is named in the copyright or copyrights for the Font You means the or person redistributing or modifying the Font Freely Available means that you have the freedom to copy or modify the Font as well as redistribute copies of the Font under the same conditions you not price If you you can charge for this service Copying &Distribution You may copy and distribute verbatim copies of this Font in any without provided that you retain this license including modifying reordering converting changing font or adding deleting some characters in from glyph and copy and distribute such modifications under the terms of Section provided that the following conditions are such as by offering access to copy the modifications from a designated or distributing the modifications on a medium customarily used for software interchange c If the modified fonts normally reads commands interactively when you must cause it
Definition: ARPHICPL.TXT:36
ImGui::InputLong
IMGUI_API bool InputLong(const char *label, long *v, long step, long step_fast, ImGuiInputTextFlags flags)
Definition: imgui_extensions.cpp:52
BlamEngineGlobal::color_value
BlamColor color_value
The color value of the global.
Definition: globals.h:71
Long
@ Long
Represents a long.
Definition: globals.h:37
Color
@ Color
Represents a BlamColor. See #BlamColor for details.
Definition: globals.h:41
Boolean
@ Boolean
Represents a boolean. Can be true or false.
Definition: globals.h:34
ImGui::EndTabBar
IMGUI_API void EndTabBar()
Definition: imgui_widgets.cpp:6432
ImGui::InputShort
IMGUI_API bool InputShort(const char *label, short *v, short step, short step_fast, ImGuiInputTextFlags flags)
Definition: imgui_extensions.cpp:46
ImGui::ColorEdit4
IMGUI_API bool ColorEdit4(const char *label, float col[4], ImGuiColorEditFlags flags=0)
Definition: imgui_widgets.cpp:4154
ENGINE_TEXT
#define ENGINE_TEXT(string_id)
Definition: engine_text.h:7
BlamEngineGlobal::int_value
int int_value
The int value of the global.
Definition: globals.h:69
imgui.h
ImGui::Separator
IMGUI_API void Separator()
Definition: imgui_widgets.cpp:1284
BlamEngineGlobal::float_value
float float_value
The float value of the global.
Definition: globals.h:70
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::BeginTabItem
IMGUI_API bool BeginTabItem(const char *label, bool *p_open=NULL, ImGuiTabItemFlags flags=0)
Definition: imgui_widgets.cpp:6829
ImGui::TextDisabled
IMGUI_API void TextDisabled(const char *fmt,...) IM_FMTARGS(1)
Definition: imgui_widgets.cpp:272
BlamEngineGlobal::value_raw
std::string value_raw
The raw value of the global as a string.
Definition: globals.h:59
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
BlamImGuiWindow_GlobalsEditor::Draw
void Draw()
Draws the contents of the group.
Definition: globals_editor.hpp:137
Blam::Globals::GetGlobalsList
BLAM std::map< std::string, BlamEngineGlobal > * GetGlobalsList()
Retrieves the list of loaded globals.
Definition: globals.cpp:22
BlamEngineGlobal::long_value
long long_value
The long value of the global.
Definition: globals.h:68