Blamite Game Engine - blam!  00285.12.18.20.1411.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 
6 
8 {
13  {
14  private:
15  char search_buffer[128];
16  bool use_tabs = false;
17 
18  void GenerateGlobalControl(Blam::Globals::EngineGlobal* global)
19  {
20  switch (global->type)
21  {
22  case Blam::Globals::GvarType::Boolean:
23  {
24  ImGui::Checkbox(global->name.c_str(), &global->boolean_value);
25  break;
26  }
28  {
29  ImGui::InputShort(global->name.c_str(), &global->short_value, 1, 10, NULL);
30  break;
31  }
33  {
34  ImGui::InputLong(global->name.c_str(), &global->long_value, 1, 10, NULL);
35  break;
36  }
37  case Blam::Globals::GvarType::String:
38  {
39  if (global->value_raw.size() < 1024)
40  {
41  char string_value[1024];
42  memcpy(string_value, global->value_raw.c_str(), global->value_raw.size());
43  string_value[global->value_raw.size()] = NULL;
44 
45  ImGui::InputText(global->name.c_str(), string_value, 1024);
46 
47  global->value_raw = string_value;
48  }
49  else
50  {
51  ImGui::TextColored(ImVec4(1, 0, 0, 1), std::string("this global is too long to be modified (must be less than 1024 bytes): '" + global->name + "'").c_str());
52  }
53 
54  break;
55  }
56  case Blam::Globals::GvarType::Int:
57  {
58  ImGui::InputInt(global->name.c_str(), &global->int_value);
59  break;
60  }
62  {
63  ImGui::InputFloat(global->name.c_str(), &global->float_value);
64  break;
65  }
66  case Blam::Globals::GvarType::Color:
67  {
68  float color_values[4];
69  {
70  color_values[0] = global->color_value.GetRedAsFloat();
71  color_values[1] = global->color_value.GetGreenAsFloat();
72  color_values[2] = global->color_value.GetBlueAsFloat();
73  color_values[3] = global->color_value.GetAlphaAsFloat();
74  }
75 
76  ImGui::ColorEdit4(global->name.c_str(), color_values);
77 
78  global->color_value.r = color_values[0] * 255;
79  global->color_value.g = color_values[1] * 255;
80  global->color_value.b = color_values[2] * 255;
81  global->color_value.a = color_values[3] * 255;
82  break;
83  }
84  default:
85  {
86  ImGui::TextColored(ImVec4(1, 0, 0, 1), std::string("this global is not supported for editing: '" + global->name + "'").c_str());
87  break;
88  }
89  }
90 
91  if (global->info.size() > 0)
92  {
93  ImGui::SameLine();
95  }
96  }
97 
98  public:
99  void Draw()
100  {
101  if (show)
102  {
103  if (ImGui::Begin("Engine Globals", &show))
104  {
105  ImGui::InputTextWithHint("", "filter globals by name...", search_buffer, 128);
106  ImGui::SameLine();
107  ImGui::Checkbox("group into tabs", &use_tabs);
108 
109  std::map<std::string, Blam::Globals::EngineGlobal>* globals = Blam::Globals::GetGlobalsList();
110  std::map<std::string, Blam::Globals::EngineGlobal>::iterator it;
111 
112  for (it = globals->begin(); it != globals->end(); it++)
113  {
114  GenerateGlobalControl(&it->second);
115  }
116  }
117  ImGui::End();
118  }
119  }
120  };
121 }
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:272
Blam::Globals::EngineGlobal::info
std::string info
An optional description of the global.
Definition: globals.h:260
Blam::Globals::EngineGlobal::color_value
BlamColor color_value
The color value of the global.
Definition: globals.h:273
Blam::Globals::Long
@ Long
Represents a long.
Definition: globals.h:238
BlamColor::a
unsigned char a
The Alpha value of the color.
Definition: globals.h:26
Blam::Globals::EngineGlobal::name
std::string name
The name of the global.
Definition: globals.h:259
Blam::Globals::EngineGlobal::short_value
short short_value
The short value of the global.
Definition: globals.h:269
globals
std::map< std::string, EngineGlobal > globals
The list of loaded globals.
Definition: globals.cpp:20
Float
@ Float
Definition: render_model.h:17
Blam::Globals::EngineGlobal
Structure containing data for a game engine global.
Definition: globals.h:256
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:270
Blam::DebugUI::ImGUIDrawingGroup
Class representing an ImGUI drawing group/draw list item.
Definition: debug_ui.h:359
BlamColor::g
unsigned char g
The Green value of the color.
Definition: globals.h:24
BlamColor::b
unsigned char b
The Blue value of the color.
Definition: globals.h:25
Blam::Globals::Short
@ Short
Represents a short.
Definition: globals.h:237
BlamColor::GetBlueAsFloat
float GetBlueAsFloat()
Gets the color's red value as a float, between 0 and 1.
Definition: globals.h:87
Blam::Globals::EngineGlobal::int_value
int int_value
The int value of the global.
Definition: globals.h:271
Blam::DebugUI::Windows::GlobalsEditor::Draw
void Draw()
Draws the contents of the group.
Definition: globals_editor.hpp:99
Blam::Globals::GetGlobalsList
BLAM std::map< std::string, EngineGlobal > * GetGlobalsList()
Retrieves the list of loaded globals.
Definition: globals.cpp:22
BlamColor::GetRedAsFloat
float GetRedAsFloat()
Gets the color's red value as a float, between 0 and 1.
Definition: globals.h:67
BlamColor::GetGreenAsFloat
float GetGreenAsFloat()
Gets the color's red value as a float, between 0 and 1.
Definition: globals.h:77
Blam::Globals::EngineGlobal::value_raw
std::string value_raw
The raw value of the global as a string.
Definition: globals.h:261
Blam::DebugUI::Windows
Legacy namespace to contain data for the legacy ImGUI console.
Definition: debug_ui.h:434
BlamColor::GetAlphaAsFloat
float GetAlphaAsFloat()
Gets the color's red value as a float, between 0 and 1.
Definition: globals.h:97
Blam::Globals::EngineGlobal::type
GvarType type
The type of the global.
Definition: globals.h:258
BlamColor::r
unsigned char r
The Red value of the color.
Definition: globals.h:23
Blam::DebugUI::Windows::GlobalsEditor
Class for the engine Globals editor.
Definition: globals_editor.hpp:12
Blam::Globals::EngineGlobal::boolean_value
bool boolean_value
The boolean value of the global.
Definition: globals.h:268