Blamite Game Engine - blam!  00296.01.12.21.0102.blamite
The core library for the Blamite Game Engine.
config_editor.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../../debug_ui.h"
4 #include "components/3rdparty/imgui/misc/imgui_stdlib.h"
5 
7 
9 {
17  {
18  private:
19  bool show_comments = false;
20 
26  void GenerateConfigurationSettingControl(BlamConfigurationSetting* setting)
27  {
28  switch (setting->type)
29  {
31  {
32  ImGui::Checkbox(setting->id.c_str(), setting->AsBool());
33  break;
34  }
36  {
37  ImGui::InputText(setting->id.c_str(), setting->GetRawValue());
38  break;
39  }
41  {
42  ImVec4 color = ImVec4(setting->AsColor()->GetRedAsFloat(), setting->AsColor()->GetGreenAsFloat(), setting->AsColor()->GetBlueAsFloat(), setting->AsColor()->GetAlphaAsFloat());
43 
44  ImGui::ColorEdit4(setting->id.c_str(), (float*)&color);
45 
46  setting->AsColor()->r = color.x * 255;
47  setting->AsColor()->g = color.y * 255;
48  setting->AsColor()->b = color.z * 255;
49  setting->AsColor()->a = color.w * 255;
50 
51  break;
52  }
54  {
55  ImGui::InputInt(setting->id.c_str(), setting->AsInt());
56  break;
57  }
59  {
60  ImGui::InputFloat(setting->id.c_str(), setting->AsFloat());
61  break;
62  }
63  case BlamConfigurationSettingType::Comment:
64  {
65  ImGui::TextDisabled(setting->AsString()->c_str());
66  break;
67  }
68  default:
69  {
70  ImGui::TextColored(ImVec4(1, 0, 0, 1), std::string("unsupported setting type (" + setting->id + ")").c_str());
71  }
72  }
73  }
74 
80  void GenerateConfigurationSectionControl(BlamConfigurationSection* section)
81  {
82  std::vector<BlamConfigurationSetting*> settings_to_show = std::vector<BlamConfigurationSetting*>();
83 
84  std::map<std::string, BlamConfigurationSetting*>::iterator it;
85 
86  for (it = section->settings.begin(); it != section->settings.end(); it++)
87  {
88  if (it->second->type == BlamConfigurationSettingType::Comment)
89  {
90  if (show_comments)
91  {
92  settings_to_show.push_back(it->second);
93  }
94  }
95  else
96  {
97  settings_to_show.push_back(it->second);
98  }
99  }
100 
101  if (settings_to_show.size() > 0)
102  {
103  if (ImGui::CollapsingHeader(section->name.c_str()))
104  {
105  for (int i = 0; i < settings_to_show.size(); i++)
106  {
107  GenerateConfigurationSettingControl(settings_to_show.at(i));
108  }
109  }
110  }
111  }
112 
113  public:
114 
115  void Draw()
116  {
117  if (show)
118  {
119  if (ImGui::Begin("Configuration Editor", &show))
120  {
121  if (ImGui::BeginTabBar("config_editor_tabs", ImGuiTabBarFlags_NoTooltip))
122  {
123  std::map<std::string, BlamConfigurationFile*>* config_files = Blam::Settings::Config::GetConfigurationFiles();
124 
125  std::map<std::string, BlamConfigurationFile*>::iterator it;
126 
127  for (it = config_files->begin(); it != config_files->end(); it++)
128  {
129  BlamConfigurationFile* config_file = it->second;
130 
131  if (ImGui::BeginTabItem(config_file->filename.c_str()))
132  {
133  if (ImGui::Button("reload"))
134  {
135  config_file->Reload();
136  }
137 
138  ImGui::SameLine();
139 
140  if (ImGui::Button("save"))
141  {
142  config_file->Save();
143  }
144 
145  ImGui::SameLine();
146 
147  ImGui::Checkbox("show comments", &show_comments);
148 
149  std::map<std::string, BlamConfigurationSection*>::iterator sit;
150 
151  for (sit = config_file->sections.begin(); sit != config_file->sections.end(); sit++)
152  {
153  GenerateConfigurationSectionControl(sit->second);
154  }
155 
156  ImGui::EndTabItem();
157  }
158  }
159 
160  ImGui::EndTabBar();
161  }
162  }
163  ImGui::End();
164  }
165  }
166  };
167 }
Blam::Globals::Int
@ Int
Represents an int.
Definition: globals.h:47
color
@ color
Definition: render_model.h:12
Blam::Globals::String
@ String
Represents a std::string.
Definition: globals.h:46
Float
@ Float
Definition: render_model.h:17
Blam::DebugUI::Windows::ModernConfigEditor
Class for the modern Config Editor.
Definition: config_editor.hpp:16
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::Settings::Config::GetConfigurationFiles
BLAM std::map< std::string, BlamConfigurationFile * > * GetConfigurationFiles()
Definition: config.cpp:137
Blam::DebugUI::ImGUIDrawingGroup
Class representing an ImGUI drawing group/draw list item.
Definition: debug_ui.h:359
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
config.h
Blam::DebugUI::Windows
Legacy namespace to contain data for the legacy ImGUI console.
Definition: debug_ui.h:434
Blam::DebugUI::Windows::ModernConfigEditor::Draw
void Draw()
Draws the contents of the group.
Definition: config_editor.hpp:115