Elaztek Developer Hub
Blamite Game Engine - blam!  00398.09.22.23.2015.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"
5 
7 
9 {
17  {
18  private:
19  bool show_comments = false;
20 
26  void GenerateConfigurationSettingControl(BlamConfigurationSetting* setting)
27  {
28  switch (setting->type)
29  {
30  case BlamConfigurationSettingType::Boolean:
31  {
32  ImGui::Checkbox(setting->id.c_str(), setting->AsBool());
33  break;
34  }
36  {
37  ImGui::InputText(setting->id.c_str(), setting->AsString());
38  break;
39  }
40  case BlamConfigurationSettingType::Color:
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##modern_config_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(BlamStrings::Utils::IO::GetFileName(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 
157  }
158  }
159 
161  }
162  }
163  ImGui::End();
164  }
165  }
166  };
167 }
Blam::Globals::Int
@ Int
Represents an int.
Definition: globals.h:49
color
BlamColor color
Typedef for a color field, used in tag definitions.
Definition: tags.h:359
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
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
ImGuiTabBarFlags_NoTooltip
@ ImGuiTabBarFlags_NoTooltip
Definition: imgui.h:840
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
ImGui::CollapsingHeader
IMGUI_API bool CollapsingHeader(const char *label, ImGuiTreeNodeFlags flags=0)
Definition: imgui_widgets.cpp:5422
Blam::Globals::Float
@ Float
Represents a float.
Definition: globals.h:50
Blam::DebugUI::Windows::ModernConfigEditor
Class for the modern Config Editor.
Definition: config_editor.hpp:16
ImGui::BeginTabBar
IMGUI_API bool BeginTabBar(const char *str_id, ImGuiTabBarFlags flags=0)
Definition: imgui_widgets.cpp:6366
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:116
Blam::DebugUI::ImGUIDrawingGroup
Class representing an ImGUI drawing group/draw list item.
Definition: debug_ui.h:359
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::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
config.h
Blam::DebugUI::Windows
Legacy namespace to contain data for the legacy ImGUI console.
Definition: ui.h:26
Blam::DebugUI::Windows::ModernConfigEditor::Draw
void Draw()
Draws the contents of the group.
Definition: config_editor.hpp:115
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