Blamite Game Engine - blam!  00296.01.12.21.0102.blamite
The core library for the Blamite Game Engine.
dynamic_menubar.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../debug_ui.h"
4 
11 #include "version_data.h"
12 
13 namespace Blam::DebugUI::Widgets
14 {
21  {
22  private:
23  int commit_hash_label = 0;
24 
30  void create_menu_item(BlamMenubarItem item)
31  {
32  if (item.type == BlamMenubarItemType::Menu)
33  {
34  if (ImGui::BeginMenu(item.name.c_str()))
35  {
36  for (int i = 0; i < item.items.size(); i++)
37  {
38  create_menu_item(item.items.at(i));
39  }
40 
41  ImGui::EndMenu();
42  }
43  }
44  else if (item.type == BlamMenubarItemType::MenuItem)
45  {
46  if (ImGui::MenuItem(item.name.c_str(), item.shortcut.c_str(), false, item.enabled))
47  {
49  {
51  }
53  {
55 
56  if (global)
57  {
58  switch (global->type)
59  {
61  {
63  break;
64  }
65  default:
66  {
67  Blam::Logger::LogEvent("only boolean globals can be modified using the menu bar at this time");
68  break;
69  }
70  }
71  }
72  }
73  }
74 
76  {
78  }
79  }
80  else if (item.type == BlamMenubarItemType::Label)
81  {
82  if (item.override_color)
83  {
84  ImVec4 im_color = ImVec4(item.color.GetRedAsFloat(), item.color.GetGreenAsFloat(), item.color.GetBlueAsFloat(), item.color.GetAlphaAsFloat());
85  ImGui::TextColored(im_color, item.variable.c_str());
86  }
87  else
88  {
89  ImGui::Text(item.variable.c_str());
90  }
91  }
92  else if (item.type == BlamMenubarItemType::Separator)
93  {
94  ImGui::Separator();
95  }
96  }
97 
98  public:
103  {
104  show = true;
105  }
106 
111  {
112 
113  }
114 
118  void Draw()
119  {
120  if (show)
121  {
122  if (ImGui::BeginMainMenuBar())
123  {
125 
126  for (int i = 0; i < menu.items.size(); i++)
127  {
128  create_menu_item(menu.items.at(i));
129  }
130 
131  ImGui::SameLine(ImGui::GetWindowWidth() - (commit_hash_label + 15));
132  ImGui::TextDisabled(CURRENT_COMMIT);
133  if (ImGui::IsItemHovered())
134  {
135  ImGui::BeginTooltip();
136  ImGui::PushTextWrapPos(450.0f);
137  ImGui::TextUnformatted(ENGINE_TEXT("imgui_menu_commit_tooltip_title").c_str());
138 
139  ImGui::Separator();
140 
141  ImGui::TextUnformatted(ENGINE_TEXT("imgui_menu_commit_tooltip_text").c_str());
142 
143 
144  ImGui::PopTextWrapPos();
145  ImGui::EndTooltip();
146  }
147 
148  ImVec2 commit_label_size = ImGui::GetItemRectSize();
149 
150  commit_hash_label = commit_label_size.x;
151 
152  ImGui::EndMainMenuBar();
153  }
154  }
155  }
156  };
157 }
BlamMenubarItem
Structure representing a menu bar item.
Definition: menubar.h:44
Blam::Settings::Menubar::GetMenuBar
BLAM BlamMenubar GetMenuBar()
Definition: menubar.cpp:282
BlamMenubarItem::override_color
bool override_color
Whether or not the label has a custom color set.
Definition: menubar.h:56
BlamMenubarItem::variable
std::string variable
The item variable. Will either be the command to run upon clicking, or the label text.
Definition: menubar.h:50
Blam::Logger::LogEvent
BLAM void LogEvent(std::string message)
Logs a message to the log and/or console.
Definition: aliases.cpp:101
Blam::Globals::GetGlobal
BLAM EngineGlobal * GetGlobal(std::string name)
Retrieves a global with the specified ID.
Definition: globals.cpp:193
BlamMenubarItem::color
BlamColor color
The color of the label.
Definition: menubar.h:55
BlamMenubar
Structure representing the menu bar.
Definition: menubar.h:79
logger.h
menubar.h
version_data.h
BlamMenubarItemType::Separator
@ Separator
A separator item.
console.h
BlamMenubarItemType::Menu
@ Menu
A submenu within the menu.
engine_text.h
BlamMenubarItem::enabled
bool enabled
Whether or not this menu item is enabled and can be clicked.
Definition: menubar.h:53
Blam::DebugUI::Widgets::DynamicMenuBar
Class for the main ImGUI menu bar.
Definition: dynamic_menubar.hpp:20
Blam::DebugUI::Widgets::DynamicMenuBar::DynamicMenuBar
DynamicMenuBar()
Initializes data for the legacy menu bar and instructs it to draw as a standard menu rather than the ...
Definition: dynamic_menubar.hpp:102
Blam::Globals::EngineGlobal
Structure containing data for a game engine global.
Definition: globals.h:62
globals.h
BlamMenubarItemType::Label
@ Label
A non-clickable text label.
Blam::Resources::Console::RunCommandLine
BLAM HRESULT RunCommandLine(std::string command_line)
Executed the provided string as a console command.
Definition: console.cpp:204
widgets.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
BlamMenubarItemVariableType::Command
@ Command
Indicates the menu item will execute a command upon being clicked.
Blam::DebugUI::ImGUIDrawingGroup
Class representing an ImGUI drawing group/draw list item.
Definition: debug_ui.h:359
BlamMenubarItem::type
BlamMenubarItemType type
The type of this menu item.
Definition: menubar.h:46
BlamMenubarItemVariableType::Unimplemented
@ Unimplemented
Indicates the menu item is a placeholder item intended for future use.
CURRENT_COMMIT
#define CURRENT_COMMIT
Definition: version_data.h:14
BlamMenubarItem::shortcut
std::string shortcut
The menu item shortcut label. Cosmetic only.
Definition: menubar.h:51
BlamMenubarItem::items
std::vector< BlamMenubarItem > items
List of all child items in this submenu.
Definition: menubar.h:58
BlamMenubarItem::var_type
BlamMenubarItemVariableType var_type
The type of variable the menu item uses.
Definition: menubar.h:47
BlamMenubarItemType::MenuItem
@ MenuItem
A standard menu item.
Blam::DebugUI::Widgets::ShowNYITooltip
BLAM void ShowNYITooltip()
Shows a tooltip with the text Not yet implemented upon hovered.
Definition: widgets.cpp:20
Blam::Globals::Boolean
@ Boolean
Represents a boolean. Can be true or false.
Definition: globals.h:41
ENGINE_TEXT
#define ENGINE_TEXT(string_id)
Definition: engine_text.h:7
BlamMenubar::items
std::vector< BlamMenubarItem > items
List of all items in this menu.
Definition: menubar.h:81
BlamMenubarItem::name
std::string name
The item name.
Definition: menubar.h:49
Blam::DebugUI::Widgets
Namespace containing general-purpose widgets used in multiple ImGUI drawing groups/windows.
Definition: devtools_bar.hpp:10
BlamMenubarItemVariableType::Global
@ Global
Indicates the menu item will modify an engine global.
Text
@ Text
Master text object that wraps around both BitmapText and DWText.
Definition: render_stack.h:73
Blam::Globals::EngineGlobal::type
GvarType type
The type of the global.
Definition: globals.h:64
Blam::DebugUI::Widgets::DynamicMenuBar::~DynamicMenuBar
~DynamicMenuBar()
Cleans up the legacy menu bar data.
Definition: dynamic_menubar.hpp:110
Blam::Globals::EngineGlobal::boolean_value
bool boolean_value
The boolean value of the global.
Definition: globals.h:74
Blam::DebugUI::Widgets::DynamicMenuBar::Draw
void Draw()
Draws the menu bar contents and current git commit hash.
Definition: dynamic_menubar.hpp:118
Blam::Globals::UpdateGlobal
BLAM GvarUpdateResult UpdateGlobal(std::string name, std::string new_value)
Updates the value of a String global.
Definition: globals.cpp:571