Elaztek Developer Hub
Blamite Game Engine - blam!  00406.12.10.23.1457.blamite
The core library for the Blamite Game Engine.
config_editor.hpp
Go to the documentation of this file.
1 #pragma once
2 
5 
7 
15 {
16 private:
17  bool show_comments = false;
18 
24  void GenerateConfigurationSettingControl(BlamConfigurationSetting* setting)
25  {
26  switch (setting->type)
27  {
29  {
30  ImGui::Checkbox(setting->id.c_str(), setting->AsBool());
31  break;
32  }
34  {
35  ImGui::InputText(setting->id.c_str(), setting->AsString());
36  break;
37  }
39  {
40  ImVec4 color = ImVec4(setting->AsColor()->GetRedAsFloat(), setting->AsColor()->GetGreenAsFloat(), setting->AsColor()->GetBlueAsFloat(), setting->AsColor()->GetAlphaAsFloat());
41 
42  ImGui::ColorEdit4(setting->id.c_str(), (float*)&color);
43 
44  setting->AsColor()->r = color.x * 255;
45  setting->AsColor()->g = color.y * 255;
46  setting->AsColor()->b = color.z * 255;
47  setting->AsColor()->a = color.w * 255;
48 
49  break;
50  }
52  {
53  ImGui::InputInt(setting->id.c_str(), setting->AsInt());
54  break;
55  }
56  case BlamConfigurationSettingType::Float:
57  {
58  ImGui::InputFloat(setting->id.c_str(), setting->AsFloat());
59  break;
60  }
61  case BlamConfigurationSettingType::Comment:
62  {
63  ImGui::TextDisabled(setting->AsString()->c_str());
64  break;
65  }
66  default:
67  {
68  ImGui::TextColored(ImVec4(1, 0, 0, 1), std::string("unsupported setting type (" + setting->id + ")").c_str());
69  }
70  }
71  }
72 
78  void GenerateConfigurationSectionControl(BlamConfigurationSection* section)
79  {
80  std::vector<BlamConfigurationSetting*> settings_to_show = std::vector<BlamConfigurationSetting*>();
81 
82  std::map<std::string, BlamConfigurationSetting*>::iterator it;
83 
84  for (it = section->settings.begin(); it != section->settings.end(); it++)
85  {
86  if (it->second->type == BlamConfigurationSettingType::Comment)
87  {
88  if (show_comments)
89  {
90  settings_to_show.push_back(it->second);
91  }
92  }
93  else
94  {
95  settings_to_show.push_back(it->second);
96  }
97  }
98 
99  if (settings_to_show.size() > 0)
100  {
101  if (ImGui::CollapsingHeader(section->name.c_str()))
102  {
103  for (int i = 0; i < settings_to_show.size(); i++)
104  {
105  GenerateConfigurationSettingControl(settings_to_show.at(i));
106  }
107  }
108  }
109  }
110 
111 public:
112 
113  void Draw()
114  {
115  if (!show)
116  {
117  return;
118  }
119 
120  if (ImGui::Begin("Configuration Editor##modern_config_editor", &show))
121  {
122  if (ImGui::BeginTabBar("config_editor_tabs", ImGuiTabBarFlags_NoTooltip))
123  {
124  std::map<std::string, BlamConfigurationFile*>* config_files = Blam::Settings::Config::GetConfigurationFiles();
125 
126  std::map<std::string, BlamConfigurationFile*>::iterator it;
127 
128  for (it = config_files->begin(); it != config_files->end(); it++)
129  {
130  BlamConfigurationFile* config_file = it->second;
131 
132  if (ImGui::BeginTabItem(BlamStrings::Utils::IO::GetFileName(config_file->filename).c_str()))
133  {
134  if (ImGui::Button("reload"))
135  {
136  config_file->Reload();
137  }
138 
139  ImGui::SameLine();
140 
141  if (ImGui::Button("save"))
142  {
143  config_file->Save();
144  }
145 
146  ImGui::SameLine();
147 
148  ImGui::Checkbox("show comments", &show_comments);
149 
150  std::map<std::string, BlamConfigurationSection*>::iterator sit;
151 
152  for (sit = config_file->sections.begin(); sit != config_file->sections.end(); sit++)
153  {
154  GenerateConfigurationSectionControl(sit->second);
155  }
156 
158  }
159  }
160 
162  }
163  }
164  ImGui::End();
165  }
166 };
color
BlamColor color
Typedef for a color field, used in tag definitions.
Definition: tags.h:416
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
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
ImGui::End
IMGUI_API void End()
Definition: imgui.cpp:6016
ImGui::EndTabItem
IMGUI_API void EndTabItem()
Definition: imgui_widgets.cpp:6851
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
Int
@ Int
Represents an int.
Definition: globals.h:40
ImGuiTabBarFlags_NoTooltip
@ ImGuiTabBarFlags_NoTooltip
Definition: imgui.h:840
BlamImGuiWindow_ModernConfigEditor
Class for the modern Config Editor.
Definition: config_editor.hpp:14
ImGui::Begin
IMGUI_API bool Begin(const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
Definition: imgui.cpp:5397
ImGui::CollapsingHeader
IMGUI_API bool CollapsingHeader(const char *label, ImGuiTreeNodeFlags flags=0)
Definition: imgui_widgets.cpp:5422
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
Blam::Settings::Config::GetConfigurationFiles
BLAM std::map< std::string, BlamConfigurationFile * > * GetConfigurationFiles()
Retrieves the map of all loaded configuration files.
Definition: config.cpp:116
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
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::ColorEdit4
IMGUI_API bool ColorEdit4(const char *label, float col[4], ImGuiColorEditFlags flags=0)
Definition: imgui_widgets.cpp:4154
imgui.h
BlamImGuiWindow_ModernConfigEditor::Draw
void Draw()
Draws the contents of the group.
Definition: config_editor.hpp:113
config.h
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::Button
IMGUI_API bool Button(const char *label, const ImVec2 &size=ImVec2(0, 0))
Definition: imgui_widgets.cpp:644
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