 |
Cytopia
0.3
A city building simulation game
|
Go to the documentation of this file.
16 #include "betterEnums.hxx"
20 #include "../services/AudioMixer.hxx"
27 #include "imgui_impl_sdl.h"
28 #include "imgui_impl_sdlrenderer.h"
32 #ifdef MICROPROFILE_ENABLED
33 #include "microprofile/microprofile.h"
38 BETTER_ENUM(Action,
int, RaiseTerrain, LowerTerrain, QuitGame, Demolish, ChangeTileType, ToggleVisibilityOfGroup, NewGame,
39 SaveGame, LoadGame, SaveSettings, ChangeResolution)
53 auto *uiFonts = ImGui::GetIO().Fonts;
58 hashName.append(std::to_string(size));
62 ImFont *newFont = uiFonts->AddFontFromFileTTF(fontPath.c_str(), (
float)size);
73 const auto names = {
"MainMenuButtons",
"PauseMenuButtons",
"LoadDialogButtons",
"BuildMenuButtons"};
74 for (
const auto &name : names)
78 auto &layout = it->second;
79 layout.font =
loadFont(fontPath, layout.fontSize);
87 uiLayout = json::parse(jsonFileContent,
nullptr,
false);
90 if (uiLayout.is_discarded())
97 for (
const auto &it : uiLayout[
"LayoutGroups"].items())
102 for (
size_t id = 0;
id < uiLayout[
"LayoutGroups"][it.key()].size();
id++)
104 layoutGroupName = uiLayout[
"LayoutGroups"][it.key()][id].value(
"GroupName",
"");
106 if (!layoutGroupName.empty())
109 layout.
layoutType = uiLayout[
"LayoutGroups"][it.key()][id].value(
"LayoutType",
"");
110 layout.
alignment = uiLayout[
"LayoutGroups"][it.key()][id].value(
"Alignment",
"");
115 <<
" because it has no parameter \"LayoutType\" set. Check your UiLayout.json file.";
122 <<
" because it has no parameter \"Alignment\" set. Check your UiLayout.json file.";
127 layout.
padding = uiLayout[
"LayoutGroups"][it.key()][id].value(
"Padding", 0);
128 layout.
paddingToParent = uiLayout[
"LayoutGroups"][it.key()][id].value(
"PaddingToParent", 0);
129 layout.
alignmentOffset = uiLayout[
"LayoutGroups"][it.key()][id].value(
"AlignmentOffset", 0.0F);
136 LOG(
LOG_WARNING) <<
"Cannot add a Layout Group without a name. Check your UiLayout.json file.";
154 if (std::none_of(std::begin(
m_menuStack), std::end(
m_menuStack), [&](
const auto &m) {
return m == menu; }))
186 #ifdef MICROPROFILE_ENABLED
187 MICROPROFILE_SCOPEI(
"UI",
"draw UI", MP_BLUE);
201 ImVec2 pos = ui::GetMousePos();
202 ui::SetCursorScreenPos(pos);
208 ui::SetNextWindowPos(ImVec2(0, 0));
209 ui::SetNextWindowSize(ImVec2(140, 20));
212 ui::Begin(
"##fpswindow", &open,
213 ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoScrollbar |
214 ImGuiWindowFlags_NoScrollWithMouse);
std::string layoutType
<mandatory> how to layout, default = HORIZONTAL
float alignmentOffset
Offset in percent to the screen point. can be negative.
void closeOpenMenus()
Close all open menus but the build menu.
FilePath fontFileName
FilePath of the Font that should be used.
void setFPSCounterText(const std::string &fps)
Helper function to update the FPS Counter.
void setTooltip(const std::string &tooltipText)
void init()
Parses the UiLayout.json files and creates UI Elements.
std::unordered_map< std::string, ImFont * > m_loadedFonts
struct ImFont * fontDefault
pointer to the default font used for in-game text
std::unordered_map< std::string, LayoutData > m_layouts
map holding layput groups, accessible via the layoutgroup ID
void parseLayouts(const json &uiLayout)
void initializeImGuiFonts()
void drawUI()
Renders all UI Widgets.
std::string readFileAsString(const std::string &fileName, bool binaryMode)
Read contents from a file as string.
std::string getBasePath()
Get base path (where Cytopia is being run)
BETTER_ENUM(Action, int, RaiseTerrain, LowerTerrain, QuitGame, Demolish, ChangeTileType, ToggleVisibilityOfGroup, NewGame, SaveGame, LoadGame, SaveSettings, ChangeResolution) void UIManager
uint32_t fontSize
<internal> default font size of all elements in group
bool isMouseHovered() const
std::vector< GameMenu::Ptr > m_menuStack
std::string alignment
<mandatory> where the element should be placed. e.g. CENTER
std::vector< GameMenu::Ptr > m_persistentMenu
void loadSettings(json &uiLayout)
void clearTooltip()
Hides and resets the active tooltip.
int paddingToParent
padding between this group and the parent in pixels
bool m_showDebugMenu
visibility of the debug menu
struct ImFont * loadFont(const std::string &name, uint32_t size)
static Settings & instance(void)
Get an instance of the singleton.
int padding
padding between elements in pixels
void canScale(bool value)
WeakType & get() noexcept