Elaztek Developer Hub
Blamite Game Engine - blam!  00398.09.22.23.2015.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 
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  {
32  case Blam::Globals::GvarType::Boolean:
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  }
62  case Blam::Globals::GvarType::Color:
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  {
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 
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 
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  {
177  case Blam::Globals::GvarType::Boolean:
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  }
207  case Blam::Globals::GvarType::Color:
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 
235  }
236  }
237  else
238  {
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 
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
globals
Definition: globals.h:26
Blam::Globals::EngineGlobal::float_value
float float_value
The float value of the global.
Definition: globals.h:80
Blam::Globals::EngineGlobal::info
std::string info
An optional description of the global.
Definition: globals.h:68
Blam::Globals::Int
@ Int
Represents an int.
Definition: globals.h:49
Blam::Globals::EngineGlobal::color_value
BlamColor color_value
The color value of the global.
Definition: globals.h:81
ImGui::Checkbox
IMGUI_API bool Checkbox(const char *label, bool *v)
Definition: imgui_widgets.cpp:974
ImVec4
Definition: imgui.h:192
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
Blam::Globals::Long
@ Long
Represents a long.
Definition: globals.h:46
ImGui::End
IMGUI_API void End()
Definition: imgui.cpp:6016
ImGui::EndTabItem
IMGUI_API void EndTabItem()
Definition: imgui_widgets.cpp:6851
engine_text.h
imgui_stdlib.h
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
ImGui::SameLine
IMGUI_API void SameLine(float offset_from_start_x=0.0f, float spacing=-1.0f)
Definition: imgui.cpp:7147
NULL
Add a fourth parameter to bake specific font ranges NULL
Definition: README.txt:57
Blam::Globals::String
@ String
Represents a std::string.
Definition: globals.h:48
ImGui::Begin
IMGUI_API bool Begin(const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
Definition: imgui.cpp:5397
Blam::Globals::EngineGlobal
Structure containing data for a game engine global.
Definition: globals.h:64
Blam::Globals::Float
@ Float
Represents a float.
Definition: globals.h:50
ImGui::BeginTabBar
IMGUI_API bool BeginTabBar(const char *str_id, ImGuiTabBarFlags flags=0)
Definition: imgui_widgets.cpp:6366
ImGui::Text
IMGUI_API void Text(const char *fmt,...) IM_FMTARGS(1)
Definition: imgui_widgets.cpp:238
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:78
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
Blam::DebugUI::ImGUIDrawingGroup
Class representing an ImGUI drawing group/draw list item.
Definition: debug_ui.h:359
globals.h
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
Blam::Globals::Short
@ Short
Represents a short.
Definition: globals.h:45
Blam::Globals::EngineGlobal::int_value
int int_value
The int value of the global.
Definition: globals.h:79
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
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
ImGui::Separator
IMGUI_API void Separator()
Definition: imgui_widgets.cpp:1284
Blam::Globals::EngineGlobal::value_raw
std::string value_raw
The raw value of the global as a string.
Definition: globals.h:69
Blam::DebugUI::Windows
Legacy namespace to contain data for the legacy ImGUI console.
Definition: ui.h:26
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::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
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
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:76