From 62444d3b58a3b7310a7013c8b0d350c205b9ec5b Mon Sep 17 00:00:00 2001 From: Mingming Cui Date: Tue, 29 Nov 2022 13:10:47 +0800 Subject: [PATCH 1/5] fix MenuItems and add new theme --- scripts/modules/CETMM.lua | 2 - scripts/modules/gui/init.lua | 7 +- scripts/modules/gui/style.lua | 9 ++ scripts/modules/gui/theme.lua | 179 ++++++++++++++++++++++++++++++++- scripts/modules/gui/window.lua | 12 ++- 5 files changed, 198 insertions(+), 11 deletions(-) diff --git a/scripts/modules/CETMM.lua b/scripts/modules/CETMM.lua index 6a69c12..98a2cd5 100644 --- a/scripts/modules/CETMM.lua +++ b/scripts/modules/CETMM.lua @@ -121,9 +121,7 @@ end function CETMM.Render() registerForEvent("onDraw", function() m_gui.Initialize() - m_gui.GetStyle().PushTheme() m_gui.Render() - m_gui.GetStyle().PopTheme() end) end diff --git a/scripts/modules/gui/init.lua b/scripts/modules/gui/init.lua index 5c19da7..ddd8ca0 100644 --- a/scripts/modules/gui/init.lua +++ b/scripts/modules/gui/init.lua @@ -25,7 +25,10 @@ function gui.Initialize() if not m_initialized then m_showUninstall = CETMM.IsUninstalled() m_dpi.Initialize() - if not m_showUninstall then + if m_showUninstall then + m_style.GetTheme().LoadDefault() + else + m_style.Initialize() m_window.Initialize() end m_initialized = true @@ -33,11 +36,13 @@ function gui.Initialize() end function gui.Render() + m_style.PushTheme() if m_showUninstall then m_windows.uninstall.Render() else m_window.Render() end + m_style.PopTheme() end return gui \ No newline at end of file diff --git a/scripts/modules/gui/style.lua b/scripts/modules/gui/style.lua index 1404c46..94ce60a 100644 --- a/scripts/modules/gui/style.lua +++ b/scripts/modules/gui/style.lua @@ -2,6 +2,14 @@ local style = {} local theme = require ("modules/gui/theme") +function style.Initialize() + theme.Load() +end + +function style.GetTheme() + return theme +end + ---@param aStyle number ---@param aColor number[] function style.PushColor(aStyle, aColor) @@ -9,6 +17,7 @@ function style.PushColor(aStyle, aColor) end function style.PushTheme() + theme:Push() style.PushColor(ImGuiCol.TitleBg, theme.TitleBg) style.PushColor(ImGuiCol.TitleBgCollapsed, theme.TitleBgCollapsed) style.PushColor(ImGuiCol.TitleBgActive, theme.TitleBgActive) diff --git a/scripts/modules/gui/theme.lua b/scripts/modules/gui/theme.lua index 5a714ff..7d920b1 100644 --- a/scripts/modules/gui/theme.lua +++ b/scripts/modules/gui/theme.lua @@ -85,7 +85,6 @@ local theme_default = { CustomToggleOnDisableText = { 0.06, 0.18, 0.2 , 1 }, CustomToggleOff = { 0.57, 0.18, 0.16, 1 }, CustomToggleOffHovered = { 0.45, 0.13, 0.14, 1 }, - CustomToggleOffText = { 1 , 0.44, 0.4 , 1 }, CustomToggleOffDisable = { 0.1 , 0.04, 0.07, 1 }, CustomToggleOffDisableHovered = { 0.16, 0.06, 0.07, 1 }, CustomToggleOffDisableText = { 0.22, 0.07, 0.07, 1 }, @@ -161,7 +160,6 @@ local theme_ua_special = { CustomToggleOnDisableText = { 0.06, 0.18, 0.2 , 1 }, CustomToggleOff = { 0.57, 0.18, 0.16, 1 }, CustomToggleOffHovered = { 0.45, 0.13, 0.14, 1 }, - CustomToggleOffText = { 0.96, 0.81, 0.00, 1 }, CustomToggleOffDisable = { 0.1 , 0.04, 0.07, 1 }, CustomToggleOffDisableHovered = { 0.16, 0.06, 0.07, 1 }, CustomToggleOffDisableText = { 0.22, 0.07, 0.07, 1 }, @@ -169,9 +167,178 @@ local theme_ua_special = { Hidden = { 0 , 0 , 0 , 0 }, } +---@class theme_white +local theme_white = { + DEF_Text = { 1 , 1 , 1 , 1 }, + DEF_TextDisabled = { 1 , 1 , 1 , 1 }, + DEF_WindowBg = { 1 , 1 , 1 , 1 }, + DEF_ChildBg = { 1 , 1 , 1 , 1 }, + DEF_PopupBg = { 1 , 1 , 1 , 1 }, + DEF_Border = { 1 , 1 , 1 , 1 }, + DEF_BorderShadow = { 1 , 1 , 1 , 1 }, + DEF_FrameBg = { 1 , 1 , 1 , 1 }, + DEF_FrameBgHovered = { 1 , 1 , 1 , 1 }, + DEF_FrameBgActive = { 1 , 1 , 1 , 1 }, + DEF_FrameBgDisabled = { 1 , 1 , 1 , 1 }, + DEF_FrameBgHoveredDisabled = { 1 , 1 , 1 , 1 }, + DEF_FrameBgActiveDisabled = { 1 , 1 , 1 , 1 }, + DEF_TitleBg = { 1 , 1 , 1 , 1 }, + DEF_TitleBgActive = { 1 , 1 , 1 , 1 }, + DEF_TitleBgCollapsed = { 1 , 1 , 1 , 1 }, + DEF_MenuBarBg = { 1 , 1 , 1 , 1 }, + DEF_ScrollbarBg = { 1 , 1 , 1 , 1 }, + DEF_ScrollbarGrab = { 1 , 1 , 1 , 1 }, + DEF_ScrollbarGrabHovered = { 1 , 1 , 1 , 1 }, + DEF_ScrollbarGrabActive = { 1 , 1 , 1 , 1 }, + DEF_CheckMark = { 1 , 1 , 1 , 1 }, + DEF_CheckMarkTrueDisabled = { 1 , 1 , 1 , 1 }, + DEF_CheckMarkFalseDisabled = { 1 , 1 , 1 , 1 }, + DEF_SliderGrab = { 1 , 1 , 1 , 1 }, + DEF_SliderGrabActive = { 1 , 1 , 1 , 1 }, + DEF_Button = { 1 , 1 , 1 , 1 }, + DEF_ButtonHovered = { 1 , 1 , 1 , 1 }, + DEF_ButtonActive = { 1 , 1 , 1 , 1 }, + DEF_Header = { 1 , 1 , 1 , 1 }, + DEF_HeaderHovered = { 1 , 1 , 1 , 1 }, + DEF_HeaderActive = { 1 , 1 , 1 , 1 }, + DEF_Separator = { 1 , 1 , 1 , 1 }, + DEF_SeparatorHovered = { 1 , 1 , 1 , 1 }, + DEF_SeparatorActive = { 1 , 1 , 1 , 1 }, + DEF_ResizeGrip = { 1 , 1 , 1 , 1 }, + DEF_ResizeGripHovered = { 1 , 1 , 1 , 1 }, + DEF_ResizeGripActive = { 1 , 1 , 1 , 1 }, + DEF_Tab = { 1 , 1 , 1 , 1 }, + DEF_TabHovered = { 1 , 1 , 1 , 1 }, + DEF_TabActive = { 1 , 1 , 1 , 1 }, + DEF_TabUnfocused = { 1 , 1 , 1 , 1 }, + DEF_TabUnfocusedActive = { 1 , 1 , 1 , 1 }, + DEF_DockingPreview = { 1 , 1 , 1 , 1 }, + DEF_DockingEmptyBg = { 1 , 1 , 1 , 1 }, + DEF_PlotLines = { 1 , 1 , 1 , 1 }, + DEF_PlotLinesHovered = { 1 , 1 , 1 , 1 }, + DEF_PlotHistogram = { 1 , 1 , 1 , 1 }, + DEF_PlotHistogramHovered = { 1 , 1 , 1 , 1 }, + DEF_TextSelectedBg = { 1 , 1 , 1 , 1 }, + DEF_DragDropTarget = { 1 , 1 , 1 , 1 }, + DEF_NavHighlight = { 1 , 1 , 1 , 1 }, + DEF_NavWindowingHighlight = { 1 , 1 , 1 , 1 }, + DEF_NavWindowingDimBg = { 1 , 1 , 1 , 1 }, + DEF_ModalWindowDimBg = { 1 , 1 , 1 , 1 }, + DEF_ModalWindowDarkening = { 1 , 1 , 1 , 1 }, + DEF_COUNT = { 1 , 1 , 1 , 1 }, + DEF_CustomToggleOn = { 1 , 1 , 1 , 1 }, + DEF_CustomToggleOnHovered = { 1 , 1 , 1 , 1 }, + DEF_CustomToggleOnActive = { 1 , 1 , 1 , 1 }, + DEF_CustomToggleOnText = { 1 , 1 , 1 , 1 }, + DEF_CustomToggleOnDisable = { 1 , 1 , 1 , 1 }, + DEF_CustomToggleOnDisableHovered = { 1 , 1 , 1 , 1 }, + DEF_CustomToggleOnDisableText = { 1 , 1 , 1 , 1 }, + DEF_CustomToggleOff = { 1 , 1 , 1 , 1 }, + DEF_CustomToggleOffHovered = { 1 , 1 , 1 , 1 }, + DEF_CustomToggleOffDisable = { 1 , 1 , 1 , 1 }, + DEF_CustomToggleOffDisableHovered = { 1 , 1 , 1 , 1 }, + DEF_CustomToggleOffDisableText = { 1 , 1 , 1 , 1 }, + DEF_AltText = { 1 , 1 , 1 , 1 }, + DEF_Hidden = { 1 , 1 , 1 , 1 }, + HVR_Text = { 0.20, 0.20, 0.20, 1 }, + HVR_TextDisabled = { 0.48, 0.39, 0.40, 1 }, + HVR_WindowBg = { 1 , 1 , 1 , 0.9 }, + HVR_ChildBg = { 1 , 1 , 1 , 0.9 }, + HVR_PopupBg = { 1 , 1 , 1 , 0.9 }, + HVR_Border = { 0.5 , 0.5 , 0.5 , 1 }, + HVR_BorderShadow = { 0 , 0 , 0 , 0 }, + HVR_FrameBg = { 1 , 1 , 1 , 1 }, + HVR_FrameBgHovered = { 0.80, 0.80, 0.80, 1 }, + HVR_FrameBgActive = { 1 , 1 , 1 , 1 }, + HVR_FrameBgDisabled = { 0.48, 0.39, 0.40, 1 }, + HVR_FrameBgHoveredDisabled = { 0.48, 0.39, 0.40, 1 }, + HVR_FrameBgActiveDisabled = { 0.48, 0.39, 0.40, 1 }, + HVR_TitleBg = { 1 , 1 , 1 , 0.9 }, + HVR_TitleBgActive = { 1 , 1 , 1 , 0.9 }, + HVR_TitleBgCollapsed = { 1 , 1 , 1 , 0.9 }, + HVR_MenuBarBg = { 1 , 1 , 1 , 0.9 }, + HVR_ScrollbarBg = { 0.06, 0.04, 0.06, 0 }, + HVR_ScrollbarGrab = { 1 , 1 , 1 , 1 }, + HVR_ScrollbarGrabHovered = { 0.80, 0.80, 0.80, 1 }, + HVR_ScrollbarGrabActive = { 1 , 1 , 1 , 1 }, + HVR_CheckMark = { 0.20, 0.20, 0.20, 1 }, + HVR_CheckMarkTrueDisabled = { 0.20, 0.20, 0.20, 1 }, + HVR_CheckMarkFalseDisabled = { 0.20, 0.20, 0.20, 1 }, + HVR_SliderGrab = { 0 , 0 , 0 , 0 }, + HVR_SliderGrabActive = { 0 , 0 , 0 , 0 }, + HVR_Button = { 1 , 1 , 1 , 1 }, + HVR_ButtonHovered = { 0.80, 0.80, 0.80, 1 }, + HVR_ButtonActive = { 1 , 1 , 1 , 1 }, + HVR_Header = { 0.80, 0.80, 0.80, 0.6 }, + HVR_HeaderHovered = { 0.80, 0.80, 0.80, 0.9 }, + HVR_HeaderActive = { 0.80, 0.80, 0.80, 0.9 }, + HVR_Separator = { 0.5 , 0.5 , 0.5 , 1 }, + HVR_SeparatorHovered = { 0.5 , 0.5 , 0.5 , 1 }, + HVR_SeparatorActive = { 0.5 , 0.5 , 0.5 , 1 }, + HVR_ResizeGrip = { 0.80, 0.80, 0.80, 1 }, + HVR_ResizeGripHovered = { 0.70, 0.70, 0.70, 1 }, + HVR_ResizeGripActive = { 0.70, 0.70, 0.70, 1 }, + HVR_Tab = { 0 , 0 , 0 , 0 }, + HVR_TabHovered = { 0 , 0 , 0 , 0 }, + HVR_TabActive = { 0 , 0 , 0 , 0 }, + HVR_TabUnfocused = { 0 , 0 , 0 , 0 }, + HVR_TabUnfocusedActive = { 0 , 0 , 0 , 0 }, + HVR_DockingPreview = { 0 , 0 , 0 , 0 }, + HVR_DockingEmptyBg = { 0 , 0 , 0 , 0 }, + HVR_PlotLines = { 0 , 0 , 0 , 0 }, + HVR_PlotLinesHovered = { 0 , 0 , 0 , 0 }, + HVR_PlotHistogram = { 0 , 0 , 0 , 0 }, + HVR_PlotHistogramHovered = { 0 , 0 , 0 , 0 }, + HVR_TextSelectedBg = { 0 , 0 , 0 , 0 }, + HVR_DragDropTarget = { 0 , 0 , 0 , 0 }, + HVR_NavHighlight = { 0 , 0 , 0 , 0 }, + HVR_NavWindowingHighlight = { 0 , 0 , 0 , 0 }, + HVR_NavWindowingDimBg = { 0 , 0 , 0 , 0 }, + HVR_ModalWindowDimBg = { 0 , 0 , 0 , 0 }, + HVR_ModalWindowDarkening = { 0 , 0 , 0 , 0 }, + HVR_COUNT = { 0 , 0 , 0 , 0 }, + HVR_CustomToggleOn = { 0.80, 0.80, 0.80, 1 }, + HVR_CustomToggleOnHovered = { 0.70, 0.70, 0.70, 1 }, + HVR_CustomToggleOnActive = { 0.80, 0.80, 0.80, 1 }, + HVR_CustomToggleOnText = { 0.20, 0.20, 0.20, 1 }, + HVR_CustomToggleOnDisable = { 0.04, 0.11, 0.12, 1 }, + HVR_CustomToggleOnDisableHovered = { 0.05, 0.16, 0.16, 1 }, + HVR_CustomToggleOnDisableText = { 0.06, 0.18, 0.2 , 1 }, + HVR_CustomToggleOff = { 0.57, 0.18, 0.16, 1 }, + HVR_CustomToggleOffHovered = { 0.45, 0.13, 0.14, 1 }, + HVR_CustomToggleOffDisable = { 0.1 , 0.04, 0.07, 1 }, + HVR_CustomToggleOffDisableHovered = { 0.16, 0.06, 0.07, 1 }, + HVR_CustomToggleOffDisableText = { 0.22, 0.07, 0.07, 1 }, + HVR_AltText = { 0.80, 0.80, 0.80, 1 }, + HVR_Hidden = { 0 , 0 , 0 , 0 }, + HVR = false, + HVRBefore = nil, +} + +function theme_white.Push(self) + if options.m_theme ~= "white" then + return + end + if (self.HVRBefore == nil) or (self.HVR ~= self.HVRBefore and not self.HVR) then + for key, value in pairs(self) do + if string.find(key, "^DEF_") then + self[string.gsub(key, "^DEF_", "")] = value + end + end + self.HVRBefore = false + elseif (self.HVR ~= self.HVRBefore and self.HVR) then + for key, value in pairs(self) do + if string.find(key, "^HVR_") then + self[string.gsub(key, "^HVR_", "")] = value + end + end + self.HVRBefore = true + end +end ---@class theme:theme_default local theme = {} +function theme.Push(self) end local function load_impl(aTheme) for key, value in pairs(aTheme) do @@ -183,13 +350,15 @@ end function theme.Load() if options.m_theme == "ua_special" then load_impl(theme_ua_special) + elseif options.m_theme == "white" then + load_impl(theme_white) else load_impl(theme_default) end end -theme.Load() - -print("theme loadded...") +function theme.LoadDefault() + load_impl(theme_default) +end return theme diff --git a/scripts/modules/gui/window.lua b/scripts/modules/gui/window.lua index 6ccb7ca..ace89d8 100644 --- a/scripts/modules/gui/window.lua +++ b/scripts/modules/gui/window.lua @@ -139,14 +139,18 @@ local function settings_popup() -- Theme if ImGui.BeginMenu("Theme") then - if ImGui.MenuItem("Default", "", options.m_theme == "default") then + if select(2, ImGui.MenuItem("Default", "", options.m_theme == "default")) then options.m_theme = "default" theme.Load() end - if ImGui.MenuItem("UA Special", "", options.m_theme == "ua_special") then + if select(2, ImGui.MenuItem("UA Special", "", options.m_theme == "ua_special")) then options.m_theme = "ua_special" theme.Load() end + if select(2, ImGui.MenuItem("White", "", options.m_theme == "white")) then + options.m_theme = "white" + theme.Load() + end ImGui.EndMenu() end @@ -164,7 +168,7 @@ local function settings_popup() end for _, entry in ipairs(languages) do - if ImGui.MenuItem(entry.name, "", options.m_lang == entry.id) then + if select(2, ImGui.MenuItem(entry.name, "", options.m_lang == entry.id)) then options.m_lang = entry.id CETMM.GetLocale().SetLocale() end @@ -215,6 +219,8 @@ end function window.Render() window.m_draw = ImGui.Begin(i18n("window_title"), window.m_draw) if window.m_draw then + -- Hover check for white theme + theme.HVR = ImGui.IsWindowHovered(bit32.bor(ImGuiHoveredFlags.AnyWindow, ImGuiHoveredFlags.AllowWhenBlockedByActiveItem, ImGuiHoveredFlags.AllowWhenBlockedByPopup, ImGuiHoveredFlags.AllowWhenDisabled)) -- Set window size and position ImGui.SetWindowPos(dpi.GetDisplayResolution().x / 2 - 210 * dpi.GetScale(), dpi.GetDisplayResolution().y / 2 - 320 * dpi.GetScale(), From dae31d6bbb6a874a4b8e82de0e49ee2b8459b502 Mon Sep 17 00:00:00 2001 From: Mingming Cui Date: Wed, 30 Nov 2022 04:37:07 +0800 Subject: [PATCH 2/5] theme system rework --- scripts/modules/gui/init.lua | 14 +- scripts/modules/gui/style.lua | 56 ---- scripts/modules/gui/theme.lua | 364 ---------------------- scripts/modules/gui/themeSys.lua | 78 +++++ scripts/modules/gui/themes/baseTheme.lua | 61 ++++ scripts/modules/gui/themes/default.lua | 80 +++++ scripts/modules/gui/themes/ua_special.lua | 87 ++++++ scripts/modules/gui/themes/white.lua | 173 ++++++++++ scripts/modules/gui/widgets/btnToggle.lua | 20 +- scripts/modules/gui/window.lua | 27 +- 10 files changed, 507 insertions(+), 453 deletions(-) delete mode 100644 scripts/modules/gui/style.lua delete mode 100644 scripts/modules/gui/theme.lua create mode 100644 scripts/modules/gui/themeSys.lua create mode 100644 scripts/modules/gui/themes/baseTheme.lua create mode 100644 scripts/modules/gui/themes/default.lua create mode 100644 scripts/modules/gui/themes/ua_special.lua create mode 100644 scripts/modules/gui/themes/white.lua diff --git a/scripts/modules/gui/init.lua b/scripts/modules/gui/init.lua index ddd8ca0..7ada4c7 100644 --- a/scripts/modules/gui/init.lua +++ b/scripts/modules/gui/init.lua @@ -2,7 +2,7 @@ local CETMM = require ("modules/CETMM") ---@class gui local gui = {} local m_dpi = require ("modules/gui/dpi") -local m_style = require ("modules/gui/style") +local m_themeSys = require ("modules/gui/themeSys") local m_widgets = require ("modules/gui/widgets") local m_window = require ("modules/gui/window") local m_windows = require ("modules/gui/windows") @@ -13,8 +13,8 @@ function gui.GetDPI() return m_dpi end -function gui.GetStyle() - return m_style +function gui.GetThemeSys() + return m_themeSys end function gui.GetWindow() @@ -26,9 +26,9 @@ function gui.Initialize() m_showUninstall = CETMM.IsUninstalled() m_dpi.Initialize() if m_showUninstall then - m_style.GetTheme().LoadDefault() + m_themeSys.Load("default", true) else - m_style.Initialize() + m_themeSys.Initialize() m_window.Initialize() end m_initialized = true @@ -36,13 +36,13 @@ function gui.Initialize() end function gui.Render() - m_style.PushTheme() + m_themeSys.PushTheme() if m_showUninstall then m_windows.uninstall.Render() else m_window.Render() end - m_style.PopTheme() + m_themeSys.PopTheme() end return gui \ No newline at end of file diff --git a/scripts/modules/gui/style.lua b/scripts/modules/gui/style.lua deleted file mode 100644 index 94ce60a..0000000 --- a/scripts/modules/gui/style.lua +++ /dev/null @@ -1,56 +0,0 @@ ----@class style -local style = {} -local theme = require ("modules/gui/theme") - -function style.Initialize() - theme.Load() -end - -function style.GetTheme() - return theme -end - ----@param aStyle number ----@param aColor number[] -function style.PushColor(aStyle, aColor) - ImGui.PushStyleColor(aStyle, aColor[1], aColor[2], aColor[3], aColor[4]) -end - -function style.PushTheme() - theme:Push() - style.PushColor(ImGuiCol.TitleBg, theme.TitleBg) - style.PushColor(ImGuiCol.TitleBgCollapsed, theme.TitleBgCollapsed) - style.PushColor(ImGuiCol.TitleBgActive, theme.TitleBgActive) - style.PushColor(ImGuiCol.Border, theme.Border) - style.PushColor(ImGuiCol.WindowBg, theme.WindowBg) - style.PushColor(ImGuiCol.ScrollbarBg, theme.ScrollbarBg) - style.PushColor(ImGuiCol.ScrollbarGrab, theme.ScrollbarGrab) - style.PushColor(ImGuiCol.ScrollbarGrabHovered, theme.ScrollbarGrabHovered) - style.PushColor(ImGuiCol.ScrollbarGrabActive, theme.ScrollbarGrabActive) - style.PushColor(ImGuiCol.ResizeGrip, theme.ResizeGrip) - style.PushColor(ImGuiCol.ResizeGripHovered, theme.ResizeGripHovered) - style.PushColor(ImGuiCol.ResizeGripActive, theme.ResizeGripActive) - style.PushColor(ImGuiCol.Text, theme.Text) - style.PushColor(ImGuiCol.Header, theme.Header) - style.PushColor(ImGuiCol.HeaderHovered, theme.HeaderHovered) - style.PushColor(ImGuiCol.HeaderActive, theme.HeaderActive) - style.PushColor(ImGuiCol.CheckMark, theme.CheckMark) - style.PushColor(ImGuiCol.FrameBg, theme.FrameBg) - style.PushColor(ImGuiCol.FrameBgHovered, theme.FrameBgHovered) - style.PushColor(ImGuiCol.FrameBgActive, theme.FrameBgActive) - style.PushColor(ImGuiCol.Button, theme.Button) - style.PushColor(ImGuiCol.ButtonHovered, theme.ButtonHovered) - style.PushColor(ImGuiCol.ButtonActive, theme.ButtonActive) - style.PushColor(ImGuiCol.Separator, theme.Separator) - style.PushColor(ImGuiCol.PopupBg, theme.PopupBg) - - ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, 8, 8) - ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 0) -end - -function style.PopTheme() - ImGui.PopStyleColor(25) - ImGui.PopStyleVar(2) -end - -return style \ No newline at end of file diff --git a/scripts/modules/gui/theme.lua b/scripts/modules/gui/theme.lua deleted file mode 100644 index 7d920b1..0000000 --- a/scripts/modules/gui/theme.lua +++ /dev/null @@ -1,364 +0,0 @@ --- CyberEngineTWeaks Mod Manager is a mod manager for Cyber Engine Tweaks based mods - --- Copyright (C) 2021 Mingming Cui --- --- This program is free software: you can redistribute it and/or modify --- it under the terms of the GNU General Public License as published by --- the Free Software Foundation, either version 3 of the License, or --- (at your option) any later version. --- --- This program is distributed in the hope that it will be useful, --- but WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --- GNU General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program. If not, see . -local CETMM = require("modules/CETMM") -local options = CETMM.GetOptions() - ----@class theme_default -local theme_default = { - Text = { 1 , 0.44, 0.4 , 1 }, - TextDisabled = { 0.48, 0.39, 0.40, 1 }, - WindowBg = { 0.06, 0.04, 0.06, 0.9 }, - ChildBg = { 0.06, 0.04, 0.06, 0.9 }, - PopupBg = { 0.06, 0.04, 0.06, 0.9 }, - Border = { 0.3 , 0.07, 0.08, 1 }, - BorderShadow = { 0 , 0 , 0 , 0 }, - FrameBg = { 0.57, 0.17, 0.16, 1 }, - FrameBgHovered = { 0.32, 0.09, 0.11, 1 }, - FrameBgActive = { 0.1 , 0.05, 0.05, 1 }, - FrameBgDisabled = { 0.48, 0.39, 0.40, 1 }, - FrameBgHoveredDisabled = { 0.48, 0.39, 0.40, 1 }, - FrameBgActiveDisabled = { 0.48, 0.39, 0.40, 1 }, - TitleBg = { 0.06, 0.04, 0.06, 0.9 }, - TitleBgActive = { 0.06, 0.04, 0.06, 0.9 }, - TitleBgCollapsed = { 0.06, 0.04, 0.06, 0.9 }, - MenuBarBg = { 0 , 0 , 0 , 0 }, - ScrollbarBg = { 0.06, 0.04, 0.06, 0 }, - ScrollbarGrab = { 0.57, 0.17, 0.16, 1 }, - ScrollbarGrabHovered = { 0.57, 0.17, 0.16, 1 }, - ScrollbarGrabActive = { 0.57, 0.17, 0.16, 1 }, - CheckMark = { 1 , 0.44, 0.4 , 1 }, - CheckMarkTrueDisabled = { 0.34, 0.22, 0.24, 1 }, - CheckMarkFalseDisabled = { 0.48, 0.39, 0.40, 1 }, - SliderGrab = { 0 , 0 , 0 , 0 }, - SliderGrabActive = { 0 , 0 , 0 , 0 }, - Button = { 0.57, 0.17, 0.16, 1 }, - ButtonHovered = { 0.45, 0.13, 0.14, 1 }, - ButtonActive = { 0.57, 0.17, 0.16, 1 }, - Header = { 0.22, 0.64, 0.69, 0.2 }, - HeaderHovered = { 0.22, 0.64, 0.69, 0.3 }, - HeaderActive = { 0.22, 0.64, 0.69, 0.5 }, - Separator = { 0.3 , 0.07, 0.08, 1 }, - SeparatorHovered = { 0.29, 0.77, 0.79, 1 }, - SeparatorActive = { 0.29, 0.77, 0.79, 1 }, - ResizeGrip = { 0.06, 0.04, 0.06, 1 }, - ResizeGripHovered = { 1 , 0.44, 0.4 , 1 }, - ResizeGripActive = { 1 , 0.44, 0.4 , 1 }, - Tab = { 0 , 0 , 0 , 0 }, - TabHovered = { 0 , 0 , 0 , 0 }, - TabActive = { 0 , 0 , 0 , 0 }, - TabUnfocused = { 0 , 0 , 0 , 0 }, - TabUnfocusedActive = { 0 , 0 , 0 , 0 }, - DockingPreview = { 0 , 0 , 0 , 0 }, - DockingEmptyBg = { 0 , 0 , 0 , 0 }, - PlotLines = { 0 , 0 , 0 , 0 }, - PlotLinesHovered = { 0 , 0 , 0 , 0 }, - PlotHistogram = { 0 , 0 , 0 , 0 }, - PlotHistogramHovered = { 0 , 0 , 0 , 0 }, - TextSelectedBg = { 0 , 0 , 0 , 0 }, - DragDropTarget = { 0 , 0 , 0 , 0 }, - NavHighlight = { 0 , 0 , 0 , 0 }, - NavWindowingHighlight = { 0 , 0 , 0 , 0 }, - NavWindowingDimBg = { 0 , 0 , 0 , 0 }, - ModalWindowDimBg = { 0 , 0 , 0 , 0 }, - ModalWindowDarkening = { 0 , 0 , 0 , 0 }, - COUNT = { 0 , 0 , 0 , 0 }, - CustomToggleOn = { 0.29, 0.77, 0.79, 1 }, - CustomToggleOnHovered = { 0.20, 0.56, 0.59, 1 }, - CustomToggleOnActive = { 0.29, 0.77, 0.79, 1 }, - CustomToggleOnText = { 0 , 0 , 0 , 1 }, - CustomToggleOnDisable = { 0.04, 0.11, 0.12, 1 }, - CustomToggleOnDisableHovered = { 0.05, 0.16, 0.16, 1 }, - CustomToggleOnDisableText = { 0.06, 0.18, 0.2 , 1 }, - CustomToggleOff = { 0.57, 0.18, 0.16, 1 }, - CustomToggleOffHovered = { 0.45, 0.13, 0.14, 1 }, - CustomToggleOffDisable = { 0.1 , 0.04, 0.07, 1 }, - CustomToggleOffDisableHovered = { 0.16, 0.06, 0.07, 1 }, - CustomToggleOffDisableText = { 0.22, 0.07, 0.07, 1 }, - AltText = { 0.29, 0.77, 0.79, 1 }, - Hidden = { 0 , 0 , 0 , 0 }, -} - ----@class theme_ua_special -local theme_ua_special = { - Text = { 0.96, 0.81, 0.00, 1 }, - TextDisabled = { 0.48, 0.39, 0.40, 1 }, - WindowBg = { 0.05, 0.11, 0.18, 0.9 }, - ChildBg = { 0.05, 0.11, 0.18, 0.9 }, - PopupBg = { 0.05, 0.11, 0.18, 0.9 }, - Border = { 0.60, 0.51, 0.00, 1 }, - BorderShadow = { 0 , 0 , 0 , 0 }, - FrameBg = { 0.00, 0.35, 0.71, 1 }, - FrameBgHovered = { 0.00, 0.44, 0.90, 1 }, - FrameBgActive = { 0.00, 0.35, 0.71, 1 }, - FrameBgDisabled = { 0.48, 0.39, 0.40, 1 }, - FrameBgHoveredDisabled = { 0.48, 0.39, 0.40, 1 }, - FrameBgActiveDisabled = { 0.48, 0.39, 0.40, 1 }, - TitleBg = { 0.05, 0.11, 0.18, 0.9 }, - TitleBgActive = { 0.05, 0.11, 0.18, 0.9 }, - TitleBgCollapsed = { 0.05, 0.11, 0.18, 0.9 }, - MenuBarBg = { 0.05, 0.11, 0.18, 0.9 }, - ScrollbarBg = { 0.06, 0.04, 0.06, 0 }, - ScrollbarGrab = { 0.00, 0.35, 0.71, 1 }, - ScrollbarGrabHovered = { 0.00, 0.44, 0.90, 1 }, - ScrollbarGrabActive = { 0.00, 0.35, 0.71, 1 }, - CheckMark = { 0.96, 0.81, 0.00, 1 }, - CheckMarkTrueDisabled = { 0.34, 0.22, 0.24, 1 }, - CheckMarkFalseDisabled = { 0.48, 0.39, 0.40, 1 }, - SliderGrab = { 0 , 0 , 0 , 0 }, - SliderGrabActive = { 0 , 0 , 0 , 0 }, - Button = { 0.00, 0.35, 0.71, 1 }, - ButtonHovered = { 0.00, 0.44, 0.90, 1 }, - ButtonActive = { 0.00, 0.35, 0.71, 1 }, - Header = { 0.00, 0.21, 0.43, 0.6 }, - HeaderHovered = { 0.00, 0.21, 0.43, 0.9 }, - HeaderActive = { 0.00, 0.21, 0.43, 0.9 }, - Separator = { 0.60, 0.51, 0.00, 0.5 }, - SeparatorHovered = { 0.29, 0.77, 0.79, 1 }, - SeparatorActive = { 0.29, 0.77, 0.79, 1 }, - ResizeGrip = { 0.05, 0.11, 0.18, 1 }, - ResizeGripHovered = { 0.96, 0.81, 0.00, 1 }, - ResizeGripActive = { 0.96, 0.81, 0.00, 1 }, - Tab = { 0 , 0 , 0 , 0 }, - TabHovered = { 0 , 0 , 0 , 0 }, - TabActive = { 0 , 0 , 0 , 0 }, - TabUnfocused = { 0 , 0 , 0 , 0 }, - TabUnfocusedActive = { 0 , 0 , 0 , 0 }, - DockingPreview = { 0 , 0 , 0 , 0 }, - DockingEmptyBg = { 0 , 0 , 0 , 0 }, - PlotLines = { 0 , 0 , 0 , 0 }, - PlotLinesHovered = { 0 , 0 , 0 , 0 }, - PlotHistogram = { 0 , 0 , 0 , 0 }, - PlotHistogramHovered = { 0 , 0 , 0 , 0 }, - TextSelectedBg = { 0 , 0 , 0 , 0 }, - DragDropTarget = { 0 , 0 , 0 , 0 }, - NavHighlight = { 0 , 0 , 0 , 0 }, - NavWindowingHighlight = { 0 , 0 , 0 , 0 }, - NavWindowingDimBg = { 0 , 0 , 0 , 0 }, - ModalWindowDimBg = { 0 , 0 , 0 , 0 }, - ModalWindowDarkening = { 0 , 0 , 0 , 0 }, - COUNT = { 0 , 0 , 0 , 0 }, - CustomToggleOn = { 0.96, 0.81, 0.00, 1 }, - CustomToggleOnHovered = { 0.81, 0.67, 0.00, 1 }, - CustomToggleOnActive = { 0.96, 0.81, 0.00, 1 }, - CustomToggleOnText = { 0.00, 0.44, 0.90, 1 }, - CustomToggleOnDisable = { 0.04, 0.11, 0.12, 1 }, - CustomToggleOnDisableHovered = { 0.05, 0.16, 0.16, 1 }, - CustomToggleOnDisableText = { 0.06, 0.18, 0.2 , 1 }, - CustomToggleOff = { 0.57, 0.18, 0.16, 1 }, - CustomToggleOffHovered = { 0.45, 0.13, 0.14, 1 }, - CustomToggleOffDisable = { 0.1 , 0.04, 0.07, 1 }, - CustomToggleOffDisableHovered = { 0.16, 0.06, 0.07, 1 }, - CustomToggleOffDisableText = { 0.22, 0.07, 0.07, 1 }, - AltText = { 0.00, 0.44, 0.90, 1 }, - Hidden = { 0 , 0 , 0 , 0 }, -} - ----@class theme_white -local theme_white = { - DEF_Text = { 1 , 1 , 1 , 1 }, - DEF_TextDisabled = { 1 , 1 , 1 , 1 }, - DEF_WindowBg = { 1 , 1 , 1 , 1 }, - DEF_ChildBg = { 1 , 1 , 1 , 1 }, - DEF_PopupBg = { 1 , 1 , 1 , 1 }, - DEF_Border = { 1 , 1 , 1 , 1 }, - DEF_BorderShadow = { 1 , 1 , 1 , 1 }, - DEF_FrameBg = { 1 , 1 , 1 , 1 }, - DEF_FrameBgHovered = { 1 , 1 , 1 , 1 }, - DEF_FrameBgActive = { 1 , 1 , 1 , 1 }, - DEF_FrameBgDisabled = { 1 , 1 , 1 , 1 }, - DEF_FrameBgHoveredDisabled = { 1 , 1 , 1 , 1 }, - DEF_FrameBgActiveDisabled = { 1 , 1 , 1 , 1 }, - DEF_TitleBg = { 1 , 1 , 1 , 1 }, - DEF_TitleBgActive = { 1 , 1 , 1 , 1 }, - DEF_TitleBgCollapsed = { 1 , 1 , 1 , 1 }, - DEF_MenuBarBg = { 1 , 1 , 1 , 1 }, - DEF_ScrollbarBg = { 1 , 1 , 1 , 1 }, - DEF_ScrollbarGrab = { 1 , 1 , 1 , 1 }, - DEF_ScrollbarGrabHovered = { 1 , 1 , 1 , 1 }, - DEF_ScrollbarGrabActive = { 1 , 1 , 1 , 1 }, - DEF_CheckMark = { 1 , 1 , 1 , 1 }, - DEF_CheckMarkTrueDisabled = { 1 , 1 , 1 , 1 }, - DEF_CheckMarkFalseDisabled = { 1 , 1 , 1 , 1 }, - DEF_SliderGrab = { 1 , 1 , 1 , 1 }, - DEF_SliderGrabActive = { 1 , 1 , 1 , 1 }, - DEF_Button = { 1 , 1 , 1 , 1 }, - DEF_ButtonHovered = { 1 , 1 , 1 , 1 }, - DEF_ButtonActive = { 1 , 1 , 1 , 1 }, - DEF_Header = { 1 , 1 , 1 , 1 }, - DEF_HeaderHovered = { 1 , 1 , 1 , 1 }, - DEF_HeaderActive = { 1 , 1 , 1 , 1 }, - DEF_Separator = { 1 , 1 , 1 , 1 }, - DEF_SeparatorHovered = { 1 , 1 , 1 , 1 }, - DEF_SeparatorActive = { 1 , 1 , 1 , 1 }, - DEF_ResizeGrip = { 1 , 1 , 1 , 1 }, - DEF_ResizeGripHovered = { 1 , 1 , 1 , 1 }, - DEF_ResizeGripActive = { 1 , 1 , 1 , 1 }, - DEF_Tab = { 1 , 1 , 1 , 1 }, - DEF_TabHovered = { 1 , 1 , 1 , 1 }, - DEF_TabActive = { 1 , 1 , 1 , 1 }, - DEF_TabUnfocused = { 1 , 1 , 1 , 1 }, - DEF_TabUnfocusedActive = { 1 , 1 , 1 , 1 }, - DEF_DockingPreview = { 1 , 1 , 1 , 1 }, - DEF_DockingEmptyBg = { 1 , 1 , 1 , 1 }, - DEF_PlotLines = { 1 , 1 , 1 , 1 }, - DEF_PlotLinesHovered = { 1 , 1 , 1 , 1 }, - DEF_PlotHistogram = { 1 , 1 , 1 , 1 }, - DEF_PlotHistogramHovered = { 1 , 1 , 1 , 1 }, - DEF_TextSelectedBg = { 1 , 1 , 1 , 1 }, - DEF_DragDropTarget = { 1 , 1 , 1 , 1 }, - DEF_NavHighlight = { 1 , 1 , 1 , 1 }, - DEF_NavWindowingHighlight = { 1 , 1 , 1 , 1 }, - DEF_NavWindowingDimBg = { 1 , 1 , 1 , 1 }, - DEF_ModalWindowDimBg = { 1 , 1 , 1 , 1 }, - DEF_ModalWindowDarkening = { 1 , 1 , 1 , 1 }, - DEF_COUNT = { 1 , 1 , 1 , 1 }, - DEF_CustomToggleOn = { 1 , 1 , 1 , 1 }, - DEF_CustomToggleOnHovered = { 1 , 1 , 1 , 1 }, - DEF_CustomToggleOnActive = { 1 , 1 , 1 , 1 }, - DEF_CustomToggleOnText = { 1 , 1 , 1 , 1 }, - DEF_CustomToggleOnDisable = { 1 , 1 , 1 , 1 }, - DEF_CustomToggleOnDisableHovered = { 1 , 1 , 1 , 1 }, - DEF_CustomToggleOnDisableText = { 1 , 1 , 1 , 1 }, - DEF_CustomToggleOff = { 1 , 1 , 1 , 1 }, - DEF_CustomToggleOffHovered = { 1 , 1 , 1 , 1 }, - DEF_CustomToggleOffDisable = { 1 , 1 , 1 , 1 }, - DEF_CustomToggleOffDisableHovered = { 1 , 1 , 1 , 1 }, - DEF_CustomToggleOffDisableText = { 1 , 1 , 1 , 1 }, - DEF_AltText = { 1 , 1 , 1 , 1 }, - DEF_Hidden = { 1 , 1 , 1 , 1 }, - HVR_Text = { 0.20, 0.20, 0.20, 1 }, - HVR_TextDisabled = { 0.48, 0.39, 0.40, 1 }, - HVR_WindowBg = { 1 , 1 , 1 , 0.9 }, - HVR_ChildBg = { 1 , 1 , 1 , 0.9 }, - HVR_PopupBg = { 1 , 1 , 1 , 0.9 }, - HVR_Border = { 0.5 , 0.5 , 0.5 , 1 }, - HVR_BorderShadow = { 0 , 0 , 0 , 0 }, - HVR_FrameBg = { 1 , 1 , 1 , 1 }, - HVR_FrameBgHovered = { 0.80, 0.80, 0.80, 1 }, - HVR_FrameBgActive = { 1 , 1 , 1 , 1 }, - HVR_FrameBgDisabled = { 0.48, 0.39, 0.40, 1 }, - HVR_FrameBgHoveredDisabled = { 0.48, 0.39, 0.40, 1 }, - HVR_FrameBgActiveDisabled = { 0.48, 0.39, 0.40, 1 }, - HVR_TitleBg = { 1 , 1 , 1 , 0.9 }, - HVR_TitleBgActive = { 1 , 1 , 1 , 0.9 }, - HVR_TitleBgCollapsed = { 1 , 1 , 1 , 0.9 }, - HVR_MenuBarBg = { 1 , 1 , 1 , 0.9 }, - HVR_ScrollbarBg = { 0.06, 0.04, 0.06, 0 }, - HVR_ScrollbarGrab = { 1 , 1 , 1 , 1 }, - HVR_ScrollbarGrabHovered = { 0.80, 0.80, 0.80, 1 }, - HVR_ScrollbarGrabActive = { 1 , 1 , 1 , 1 }, - HVR_CheckMark = { 0.20, 0.20, 0.20, 1 }, - HVR_CheckMarkTrueDisabled = { 0.20, 0.20, 0.20, 1 }, - HVR_CheckMarkFalseDisabled = { 0.20, 0.20, 0.20, 1 }, - HVR_SliderGrab = { 0 , 0 , 0 , 0 }, - HVR_SliderGrabActive = { 0 , 0 , 0 , 0 }, - HVR_Button = { 1 , 1 , 1 , 1 }, - HVR_ButtonHovered = { 0.80, 0.80, 0.80, 1 }, - HVR_ButtonActive = { 1 , 1 , 1 , 1 }, - HVR_Header = { 0.80, 0.80, 0.80, 0.6 }, - HVR_HeaderHovered = { 0.80, 0.80, 0.80, 0.9 }, - HVR_HeaderActive = { 0.80, 0.80, 0.80, 0.9 }, - HVR_Separator = { 0.5 , 0.5 , 0.5 , 1 }, - HVR_SeparatorHovered = { 0.5 , 0.5 , 0.5 , 1 }, - HVR_SeparatorActive = { 0.5 , 0.5 , 0.5 , 1 }, - HVR_ResizeGrip = { 0.80, 0.80, 0.80, 1 }, - HVR_ResizeGripHovered = { 0.70, 0.70, 0.70, 1 }, - HVR_ResizeGripActive = { 0.70, 0.70, 0.70, 1 }, - HVR_Tab = { 0 , 0 , 0 , 0 }, - HVR_TabHovered = { 0 , 0 , 0 , 0 }, - HVR_TabActive = { 0 , 0 , 0 , 0 }, - HVR_TabUnfocused = { 0 , 0 , 0 , 0 }, - HVR_TabUnfocusedActive = { 0 , 0 , 0 , 0 }, - HVR_DockingPreview = { 0 , 0 , 0 , 0 }, - HVR_DockingEmptyBg = { 0 , 0 , 0 , 0 }, - HVR_PlotLines = { 0 , 0 , 0 , 0 }, - HVR_PlotLinesHovered = { 0 , 0 , 0 , 0 }, - HVR_PlotHistogram = { 0 , 0 , 0 , 0 }, - HVR_PlotHistogramHovered = { 0 , 0 , 0 , 0 }, - HVR_TextSelectedBg = { 0 , 0 , 0 , 0 }, - HVR_DragDropTarget = { 0 , 0 , 0 , 0 }, - HVR_NavHighlight = { 0 , 0 , 0 , 0 }, - HVR_NavWindowingHighlight = { 0 , 0 , 0 , 0 }, - HVR_NavWindowingDimBg = { 0 , 0 , 0 , 0 }, - HVR_ModalWindowDimBg = { 0 , 0 , 0 , 0 }, - HVR_ModalWindowDarkening = { 0 , 0 , 0 , 0 }, - HVR_COUNT = { 0 , 0 , 0 , 0 }, - HVR_CustomToggleOn = { 0.80, 0.80, 0.80, 1 }, - HVR_CustomToggleOnHovered = { 0.70, 0.70, 0.70, 1 }, - HVR_CustomToggleOnActive = { 0.80, 0.80, 0.80, 1 }, - HVR_CustomToggleOnText = { 0.20, 0.20, 0.20, 1 }, - HVR_CustomToggleOnDisable = { 0.04, 0.11, 0.12, 1 }, - HVR_CustomToggleOnDisableHovered = { 0.05, 0.16, 0.16, 1 }, - HVR_CustomToggleOnDisableText = { 0.06, 0.18, 0.2 , 1 }, - HVR_CustomToggleOff = { 0.57, 0.18, 0.16, 1 }, - HVR_CustomToggleOffHovered = { 0.45, 0.13, 0.14, 1 }, - HVR_CustomToggleOffDisable = { 0.1 , 0.04, 0.07, 1 }, - HVR_CustomToggleOffDisableHovered = { 0.16, 0.06, 0.07, 1 }, - HVR_CustomToggleOffDisableText = { 0.22, 0.07, 0.07, 1 }, - HVR_AltText = { 0.80, 0.80, 0.80, 1 }, - HVR_Hidden = { 0 , 0 , 0 , 0 }, - HVR = false, - HVRBefore = nil, -} - -function theme_white.Push(self) - if options.m_theme ~= "white" then - return - end - if (self.HVRBefore == nil) or (self.HVR ~= self.HVRBefore and not self.HVR) then - for key, value in pairs(self) do - if string.find(key, "^DEF_") then - self[string.gsub(key, "^DEF_", "")] = value - end - end - self.HVRBefore = false - elseif (self.HVR ~= self.HVRBefore and self.HVR) then - for key, value in pairs(self) do - if string.find(key, "^HVR_") then - self[string.gsub(key, "^HVR_", "")] = value - end - end - self.HVRBefore = true - end -end - ----@class theme:theme_default -local theme = {} -function theme.Push(self) end - -local function load_impl(aTheme) - for key, value in pairs(aTheme) do - theme[key] = value - end -end - - -function theme.Load() - if options.m_theme == "ua_special" then - load_impl(theme_ua_special) - elseif options.m_theme == "white" then - load_impl(theme_white) - else - load_impl(theme_default) - end -end - -function theme.LoadDefault() - load_impl(theme_default) -end - -return theme diff --git a/scripts/modules/gui/themeSys.lua b/scripts/modules/gui/themeSys.lua new file mode 100644 index 0000000..78eec65 --- /dev/null +++ b/scripts/modules/gui/themeSys.lua @@ -0,0 +1,78 @@ +local CETMM = require("modules/CETMM") +---@class themeSys +local themeSys = {} +local themes = { + default = require("modules/gui/themes/default"), + ua_special = require("modules/gui/themes/ua_special"), + white = require("modules/gui/themes/white"), +} +local currentTheme = {} ---@type baseTheme + +function themeSys.Initialize() + local theme = CETMM.GetOptions().m_theme + themeSys.Load(theme) +end + +---Load theme +---@param aTheme string +---@param aNoSave? bool +function themeSys.Load(aTheme, aNoSave) + if themes[aTheme] then + currentTheme = themes[aTheme] + else + currentTheme = themes.default + spdlog.error(string.format("Failed to load theme %s, loaded default theme instead.", aTheme)) + end + if aNoSave then + CETMM.GetOptions().m_theme = currentTheme:GetName() + CETMM.GetOptions().Save() + end +end + +function themeSys.GetCurrentTheme() + return currentTheme +end + +---@param aStyle ImGuiCol +---@param aColor number[] +function themeSys.PushColor(aStyle, aColor) + ImGui.PushStyleColor(aStyle, unpack(aColor)) +end + +function themeSys.PushTheme() + themeSys.PushColor(ImGuiCol.TitleBg, currentTheme:GetStyleColor("TitleBg" )) + themeSys.PushColor(ImGuiCol.TitleBgCollapsed, currentTheme:GetStyleColor("TitleBgCollapsed" )) + themeSys.PushColor(ImGuiCol.TitleBgActive, currentTheme:GetStyleColor("TitleBgActive" )) + themeSys.PushColor(ImGuiCol.Border, currentTheme:GetStyleColor("Border" )) + themeSys.PushColor(ImGuiCol.WindowBg, currentTheme:GetStyleColor("WindowBg" )) + themeSys.PushColor(ImGuiCol.ScrollbarBg, currentTheme:GetStyleColor("ScrollbarBg" )) + themeSys.PushColor(ImGuiCol.ScrollbarGrab, currentTheme:GetStyleColor("ScrollbarGrab" )) + themeSys.PushColor(ImGuiCol.ScrollbarGrabHovered, currentTheme:GetStyleColor("ScrollbarGrabHovered" )) + themeSys.PushColor(ImGuiCol.ScrollbarGrabActive, currentTheme:GetStyleColor("ScrollbarGrabActive" )) + themeSys.PushColor(ImGuiCol.ResizeGrip, currentTheme:GetStyleColor("ResizeGrip" )) + themeSys.PushColor(ImGuiCol.ResizeGripHovered, currentTheme:GetStyleColor("ResizeGripHovered" )) + themeSys.PushColor(ImGuiCol.ResizeGripActive, currentTheme:GetStyleColor("ResizeGripActive" )) + themeSys.PushColor(ImGuiCol.Text, currentTheme:GetStyleColor("Text" )) + themeSys.PushColor(ImGuiCol.Header, currentTheme:GetStyleColor("Header" )) + themeSys.PushColor(ImGuiCol.HeaderHovered, currentTheme:GetStyleColor("HeaderHovered" )) + themeSys.PushColor(ImGuiCol.HeaderActive, currentTheme:GetStyleColor("HeaderActive" )) + themeSys.PushColor(ImGuiCol.CheckMark, currentTheme:GetStyleColor("CheckMark" )) + themeSys.PushColor(ImGuiCol.FrameBg, currentTheme:GetStyleColor("FrameBg" )) + themeSys.PushColor(ImGuiCol.FrameBgHovered, currentTheme:GetStyleColor("FrameBgHovered" )) + themeSys.PushColor(ImGuiCol.FrameBgActive, currentTheme:GetStyleColor("FrameBgActive" )) + themeSys.PushColor(ImGuiCol.Button, currentTheme:GetStyleColor("Button" )) + themeSys.PushColor(ImGuiCol.ButtonHovered, currentTheme:GetStyleColor("ButtonHovered" )) + themeSys.PushColor(ImGuiCol.ButtonActive, currentTheme:GetStyleColor("ButtonActive" )) + themeSys.PushColor(ImGuiCol.Separator, currentTheme:GetStyleColor("Separator" )) + themeSys.PushColor(ImGuiCol.PopupBg, currentTheme:GetStyleColor("PopupBg" )) + + ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, 8, 8) + ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 0) +end + +function themeSys.PopTheme() + ImGui.PopStyleColor(25) + ImGui.PopStyleVar(2) +end + +return themeSys \ No newline at end of file diff --git a/scripts/modules/gui/themes/baseTheme.lua b/scripts/modules/gui/themes/baseTheme.lua new file mode 100644 index 0000000..380dc7e --- /dev/null +++ b/scripts/modules/gui/themes/baseTheme.lua @@ -0,0 +1,61 @@ +---@class baseTheme +---@operator call(string):baseTheme +local baseTheme = { + name = "default", + colors = {}, +} +baseTheme.__index = baseTheme + +-- baseTheme constructor + +setmetatable(baseTheme, { + __call = function (cls, ...) + return cls.New(...) + end, +}) + + +---@param aName string +---@return baseTheme +function baseTheme.New(aName) -- path: aPath + local self = setmetatable({}, baseTheme) + self.name = aName or self.name + return self +end + +-- methods +function baseTheme.GetName(self) + return self.name +end + +---Safe call method +---@param self baseTheme +---@param aMethod string +---@param ... any +---@return any +function baseTheme.Call(self, aMethod, ...) + if self[aMethod] then + return self[aMethod](self, ...) + end +end + +---Only call method in specific theme +---@param self baseTheme +---@param aThemeName string +---@param aMethod string +---@param ... any +---@return any +function baseTheme.CallIf(self, aThemeName, aMethod, ...) + if self.name == aThemeName and self[aMethod] then + return self[aMethod](self, ...) + end +end + +---@param self baseTheme +---@param aGuiColor string +---@return float[] +function baseTheme.GetStyleColor(self, aGuiColor) + return self.colors[aGuiColor] +end + +return baseTheme \ No newline at end of file diff --git a/scripts/modules/gui/themes/default.lua b/scripts/modules/gui/themes/default.lua new file mode 100644 index 0000000..42716d3 --- /dev/null +++ b/scripts/modules/gui/themes/default.lua @@ -0,0 +1,80 @@ +local baseTheme = require("modules/gui/themes/baseTheme") + +---@class themeDefault : baseTheme +local themeDefault = baseTheme("default") + +themeDefault.colors = { + Text = { 1 , 0.44, 0.4 , 1 }, + TextDisabled = { 0.48, 0.39, 0.40, 1 }, + WindowBg = { 0.06, 0.04, 0.06, 0.9 }, + ChildBg = { 0.06, 0.04, 0.06, 0.9 }, + PopupBg = { 0.06, 0.04, 0.06, 0.9 }, + Border = { 0.3 , 0.07, 0.08, 1 }, + BorderShadow = { 0 , 0 , 0 , 0 }, + FrameBg = { 0.57, 0.17, 0.16, 1 }, + FrameBgHovered = { 0.32, 0.09, 0.11, 1 }, + FrameBgActive = { 0.1 , 0.05, 0.05, 1 }, + FrameBgDisabled = { 0.48, 0.39, 0.40, 1 }, + FrameBgHoveredDisabled = { 0.48, 0.39, 0.40, 1 }, + FrameBgActiveDisabled = { 0.48, 0.39, 0.40, 1 }, + TitleBg = { 0.06, 0.04, 0.06, 0.9 }, + TitleBgActive = { 0.06, 0.04, 0.06, 0.9 }, + TitleBgCollapsed = { 0.06, 0.04, 0.06, 0.9 }, + MenuBarBg = { 0 , 0 , 0 , 0 }, + ScrollbarBg = { 0.06, 0.04, 0.06, 0 }, + ScrollbarGrab = { 0.57, 0.17, 0.16, 1 }, + ScrollbarGrabHovered = { 0.57, 0.17, 0.16, 1 }, + ScrollbarGrabActive = { 0.57, 0.17, 0.16, 1 }, + CheckMark = { 1 , 0.44, 0.4 , 1 }, + CheckMarkTrueDisabled = { 0.34, 0.22, 0.24, 1 }, + CheckMarkFalseDisabled = { 0.48, 0.39, 0.40, 1 }, + SliderGrab = { 0 , 0 , 0 , 0 }, + SliderGrabActive = { 0 , 0 , 0 , 0 }, + Button = { 0.57, 0.17, 0.16, 1 }, + ButtonHovered = { 0.45, 0.13, 0.14, 1 }, + ButtonActive = { 0.57, 0.17, 0.16, 1 }, + Header = { 0.22, 0.64, 0.69, 0.2 }, + HeaderHovered = { 0.22, 0.64, 0.69, 0.3 }, + HeaderActive = { 0.22, 0.64, 0.69, 0.5 }, + Separator = { 0.3 , 0.07, 0.08, 1 }, + SeparatorHovered = { 0.29, 0.77, 0.79, 1 }, + SeparatorActive = { 0.29, 0.77, 0.79, 1 }, + ResizeGrip = { 0.06, 0.04, 0.06, 1 }, + ResizeGripHovered = { 1 , 0.44, 0.4 , 1 }, + ResizeGripActive = { 1 , 0.44, 0.4 , 1 }, + Tab = { 0 , 0 , 0 , 0 }, + TabHovered = { 0 , 0 , 0 , 0 }, + TabActive = { 0 , 0 , 0 , 0 }, + TabUnfocused = { 0 , 0 , 0 , 0 }, + TabUnfocusedActive = { 0 , 0 , 0 , 0 }, + DockingPreview = { 0 , 0 , 0 , 0 }, + DockingEmptyBg = { 0 , 0 , 0 , 0 }, + PlotLines = { 0 , 0 , 0 , 0 }, + PlotLinesHovered = { 0 , 0 , 0 , 0 }, + PlotHistogram = { 0 , 0 , 0 , 0 }, + PlotHistogramHovered = { 0 , 0 , 0 , 0 }, + TextSelectedBg = { 0 , 0 , 0 , 0 }, + DragDropTarget = { 0 , 0 , 0 , 0 }, + NavHighlight = { 0 , 0 , 0 , 0 }, + NavWindowingHighlight = { 0 , 0 , 0 , 0 }, + NavWindowingDimBg = { 0 , 0 , 0 , 0 }, + ModalWindowDimBg = { 0 , 0 , 0 , 0 }, + ModalWindowDarkening = { 0 , 0 , 0 , 0 }, + COUNT = { 0 , 0 , 0 , 0 }, + CustomToggleOn = { 0.29, 0.77, 0.79, 1 }, + CustomToggleOnHovered = { 0.20, 0.56, 0.59, 1 }, + CustomToggleOnActive = { 0.29, 0.77, 0.79, 1 }, + CustomToggleOnText = { 0 , 0 , 0 , 1 }, + CustomToggleOnDisable = { 0.04, 0.11, 0.12, 1 }, + CustomToggleOnDisableHovered = { 0.05, 0.16, 0.16, 1 }, + CustomToggleOnDisableText = { 0.06, 0.18, 0.2 , 1 }, + CustomToggleOff = { 0.57, 0.18, 0.16, 1 }, + CustomToggleOffHovered = { 0.45, 0.13, 0.14, 1 }, + CustomToggleOffDisable = { 0.1 , 0.04, 0.07, 1 }, + CustomToggleOffDisableHovered = { 0.16, 0.06, 0.07, 1 }, + CustomToggleOffDisableText = { 0.22, 0.07, 0.07, 1 }, + AltText = { 0.29, 0.77, 0.79, 1 }, + Hidden = { 0 , 0 , 0 , 0 }, +} + +return themeDefault \ No newline at end of file diff --git a/scripts/modules/gui/themes/ua_special.lua b/scripts/modules/gui/themes/ua_special.lua new file mode 100644 index 0000000..351d9be --- /dev/null +++ b/scripts/modules/gui/themes/ua_special.lua @@ -0,0 +1,87 @@ +local baseTheme = require("modules/gui/themes/baseTheme") + +---@class themeUA : baseTheme +local themeUA = baseTheme("ua_special") + +themeUA.colors = { + Text = { 0.96, 0.81, 0.00, 1 }, + TextDisabled = { 0.48, 0.39, 0.40, 1 }, + WindowBg = { 0.05, 0.11, 0.18, 0.9 }, + ChildBg = { 0.05, 0.11, 0.18, 0.9 }, + PopupBg = { 0.05, 0.11, 0.18, 0.9 }, + Border = { 0.60, 0.51, 0.00, 1 }, + BorderShadow = { 0 , 0 , 0 , 0 }, + FrameBg = { 0.00, 0.35, 0.71, 1 }, + FrameBgHovered = { 0.00, 0.44, 0.90, 1 }, + FrameBgActive = { 0.00, 0.35, 0.71, 1 }, + FrameBgDisabled = { 0.48, 0.39, 0.40, 1 }, + FrameBgHoveredDisabled = { 0.48, 0.39, 0.40, 1 }, + FrameBgActiveDisabled = { 0.48, 0.39, 0.40, 1 }, + TitleBg = { 0.05, 0.11, 0.18, 0.9 }, + TitleBgActive = { 0.05, 0.11, 0.18, 0.9 }, + TitleBgCollapsed = { 0.05, 0.11, 0.18, 0.9 }, + MenuBarBg = { 0.05, 0.11, 0.18, 0.9 }, + ScrollbarBg = { 0.06, 0.04, 0.06, 0 }, + ScrollbarGrab = { 0.00, 0.35, 0.71, 1 }, + ScrollbarGrabHovered = { 0.00, 0.44, 0.90, 1 }, + ScrollbarGrabActive = { 0.00, 0.35, 0.71, 1 }, + CheckMark = { 0.96, 0.81, 0.00, 1 }, + CheckMarkTrueDisabled = { 0.34, 0.22, 0.24, 1 }, + CheckMarkFalseDisabled = { 0.48, 0.39, 0.40, 1 }, + SliderGrab = { 0 , 0 , 0 , 0 }, + SliderGrabActive = { 0 , 0 , 0 , 0 }, + Button = { 0.00, 0.35, 0.71, 1 }, + ButtonHovered = { 0.00, 0.44, 0.90, 1 }, + ButtonActive = { 0.00, 0.35, 0.71, 1 }, + Header = { 0.00, 0.21, 0.43, 0.6 }, + HeaderHovered = { 0.00, 0.21, 0.43, 0.9 }, + HeaderActive = { 0.00, 0.21, 0.43, 0.9 }, + Separator = { 0.60, 0.51, 0.00, 0.5 }, + SeparatorHovered = { 0.29, 0.77, 0.79, 1 }, + SeparatorActive = { 0.29, 0.77, 0.79, 1 }, + ResizeGrip = { 0.05, 0.11, 0.18, 1 }, + ResizeGripHovered = { 0.96, 0.81, 0.00, 1 }, + ResizeGripActive = { 0.96, 0.81, 0.00, 1 }, + Tab = { 0 , 0 , 0 , 0 }, + TabHovered = { 0 , 0 , 0 , 0 }, + TabActive = { 0 , 0 , 0 , 0 }, + TabUnfocused = { 0 , 0 , 0 , 0 }, + TabUnfocusedActive = { 0 , 0 , 0 , 0 }, + DockingPreview = { 0 , 0 , 0 , 0 }, + DockingEmptyBg = { 0 , 0 , 0 , 0 }, + PlotLines = { 0 , 0 , 0 , 0 }, + PlotLinesHovered = { 0 , 0 , 0 , 0 }, + PlotHistogram = { 0 , 0 , 0 , 0 }, + PlotHistogramHovered = { 0 , 0 , 0 , 0 }, + TextSelectedBg = { 0 , 0 , 0 , 0 }, + DragDropTarget = { 0 , 0 , 0 , 0 }, + NavHighlight = { 0 , 0 , 0 , 0 }, + NavWindowingHighlight = { 0 , 0 , 0 , 0 }, + NavWindowingDimBg = { 0 , 0 , 0 , 0 }, + ModalWindowDimBg = { 0 , 0 , 0 , 0 }, + ModalWindowDarkening = { 0 , 0 , 0 , 0 }, + COUNT = { 0 , 0 , 0 , 0 }, + CustomToggleOn = { 0.96, 0.81, 0.00, 1 }, + CustomToggleOnHovered = { 0.81, 0.67, 0.00, 1 }, + CustomToggleOnActive = { 0.96, 0.81, 0.00, 1 }, + CustomToggleOnText = { 0.00, 0.44, 0.90, 1 }, + CustomToggleOnDisable = { 0.04, 0.11, 0.12, 1 }, + CustomToggleOnDisableHovered = { 0.05, 0.16, 0.16, 1 }, + CustomToggleOnDisableText = { 0.06, 0.18, 0.2 , 1 }, + CustomToggleOff = { 0.57, 0.18, 0.16, 1 }, + CustomToggleOffHovered = { 0.45, 0.13, 0.14, 1 }, + CustomToggleOffDisable = { 0.1 , 0.04, 0.07, 1 }, + CustomToggleOffDisableHovered = { 0.16, 0.06, 0.07, 1 }, + CustomToggleOffDisableText = { 0.22, 0.07, 0.07, 1 }, + AltText = { 0.00, 0.44, 0.90, 1 }, + Hidden = { 0 , 0 , 0 , 0 }, +} + +function themeUA.RenderFooter(self) + ImGui.TableSetColumnIndex(1) + ImGui.PushStyleColor(ImGuiCol.Text, unpack(self.colors.Border)) + ImGui.Text("We stand with Ukraine!") + ImGui.PopStyleColor(1) +end + +return themeUA \ No newline at end of file diff --git a/scripts/modules/gui/themes/white.lua b/scripts/modules/gui/themes/white.lua new file mode 100644 index 0000000..27337e4 --- /dev/null +++ b/scripts/modules/gui/themes/white.lua @@ -0,0 +1,173 @@ +local baseTheme = require("modules/gui/themes/baseTheme") + +---@class themeWhite : baseTheme +local themeWhite = baseTheme("white") + +themeWhite.states = { + HVR = false, + HVRBefore = nil, +} + +themeWhite.def_colors = { + Text = { 1 , 1 , 1 , 1 }, + TextDisabled = { 1 , 1 , 1 , 1 }, + WindowBg = { 1 , 1 , 1 , 1 }, + ChildBg = { 1 , 1 , 1 , 1 }, + PopupBg = { 1 , 1 , 1 , 1 }, + Border = { 1 , 1 , 1 , 1 }, + BorderShadow = { 1 , 1 , 1 , 1 }, + FrameBg = { 1 , 1 , 1 , 1 }, + FrameBgHovered = { 1 , 1 , 1 , 1 }, + FrameBgActive = { 1 , 1 , 1 , 1 }, + FrameBgDisabled = { 1 , 1 , 1 , 1 }, + FrameBgHoveredDisabled = { 1 , 1 , 1 , 1 }, + FrameBgActiveDisabled = { 1 , 1 , 1 , 1 }, + TitleBg = { 1 , 1 , 1 , 1 }, + TitleBgActive = { 1 , 1 , 1 , 1 }, + TitleBgCollapsed = { 1 , 1 , 1 , 1 }, + MenuBarBg = { 1 , 1 , 1 , 1 }, + ScrollbarBg = { 1 , 1 , 1 , 1 }, + ScrollbarGrab = { 1 , 1 , 1 , 1 }, + ScrollbarGrabHovered = { 1 , 1 , 1 , 1 }, + ScrollbarGrabActive = { 1 , 1 , 1 , 1 }, + CheckMark = { 1 , 1 , 1 , 1 }, + CheckMarkTrueDisabled = { 1 , 1 , 1 , 1 }, + CheckMarkFalseDisabled = { 1 , 1 , 1 , 1 }, + SliderGrab = { 1 , 1 , 1 , 1 }, + SliderGrabActive = { 1 , 1 , 1 , 1 }, + Button = { 1 , 1 , 1 , 1 }, + ButtonHovered = { 1 , 1 , 1 , 1 }, + ButtonActive = { 1 , 1 , 1 , 1 }, + Header = { 1 , 1 , 1 , 1 }, + HeaderHovered = { 1 , 1 , 1 , 1 }, + HeaderActive = { 1 , 1 , 1 , 1 }, + Separator = { 1 , 1 , 1 , 1 }, + SeparatorHovered = { 1 , 1 , 1 , 1 }, + SeparatorActive = { 1 , 1 , 1 , 1 }, + ResizeGrip = { 1 , 1 , 1 , 1 }, + ResizeGripHovered = { 1 , 1 , 1 , 1 }, + ResizeGripActive = { 1 , 1 , 1 , 1 }, + Tab = { 1 , 1 , 1 , 1 }, + TabHovered = { 1 , 1 , 1 , 1 }, + TabActive = { 1 , 1 , 1 , 1 }, + TabUnfocused = { 1 , 1 , 1 , 1 }, + TabUnfocusedActive = { 1 , 1 , 1 , 1 }, + DockingPreview = { 1 , 1 , 1 , 1 }, + DockingEmptyBg = { 1 , 1 , 1 , 1 }, + PlotLines = { 1 , 1 , 1 , 1 }, + PlotLinesHovered = { 1 , 1 , 1 , 1 }, + PlotHistogram = { 1 , 1 , 1 , 1 }, + PlotHistogramHovered = { 1 , 1 , 1 , 1 }, + TextSelectedBg = { 1 , 1 , 1 , 1 }, + DragDropTarget = { 1 , 1 , 1 , 1 }, + NavHighlight = { 1 , 1 , 1 , 1 }, + NavWindowingHighlight = { 1 , 1 , 1 , 1 }, + NavWindowingDimBg = { 1 , 1 , 1 , 1 }, + ModalWindowDimBg = { 1 , 1 , 1 , 1 }, + ModalWindowDarkening = { 1 , 1 , 1 , 1 }, + COUNT = { 1 , 1 , 1 , 1 }, + CustomToggleOn = { 1 , 1 , 1 , 1 }, + CustomToggleOnHovered = { 1 , 1 , 1 , 1 }, + CustomToggleOnActive = { 1 , 1 , 1 , 1 }, + CustomToggleOnText = { 1 , 1 , 1 , 1 }, + CustomToggleOnDisable = { 1 , 1 , 1 , 1 }, + CustomToggleOnDisableHovered = { 1 , 1 , 1 , 1 }, + CustomToggleOnDisableText = { 1 , 1 , 1 , 1 }, + CustomToggleOff = { 1 , 1 , 1 , 1 }, + CustomToggleOffHovered = { 1 , 1 , 1 , 1 }, + CustomToggleOffDisable = { 1 , 1 , 1 , 1 }, + CustomToggleOffDisableHovered = { 1 , 1 , 1 , 1 }, + CustomToggleOffDisableText = { 1 , 1 , 1 , 1 }, + AltText = { 1 , 1 , 1 , 1 }, + Hidden = { 1 , 1 , 1 , 1 }, +} + +themeWhite.hvr_colors = { + Text = { 0.20, 0.20, 0.20, 1 }, + TextDisabled = { 0.48, 0.39, 0.40, 1 }, + WindowBg = { 1 , 1 , 1 , 0.9 }, + ChildBg = { 1 , 1 , 1 , 0.9 }, + PopupBg = { 1 , 1 , 1 , 0.9 }, + Border = { 0.5 , 0.5 , 0.5 , 1 }, + BorderShadow = { 0 , 0 , 0 , 0 }, + FrameBg = { 1 , 1 , 1 , 1 }, + FrameBgHovered = { 0.80, 0.80, 0.80, 1 }, + FrameBgActive = { 1 , 1 , 1 , 1 }, + FrameBgDisabled = { 0.48, 0.39, 0.40, 1 }, + FrameBgHoveredDisabled = { 0.48, 0.39, 0.40, 1 }, + FrameBgActiveDisabled = { 0.48, 0.39, 0.40, 1 }, + TitleBg = { 1 , 1 , 1 , 0.9 }, + TitleBgActive = { 1 , 1 , 1 , 0.9 }, + TitleBgCollapsed = { 1 , 1 , 1 , 0.9 }, + MenuBarBg = { 1 , 1 , 1 , 0.9 }, + ScrollbarBg = { 0.06, 0.04, 0.06, 0 }, + ScrollbarGrab = { 1 , 1 , 1 , 1 }, + ScrollbarGrabHovered = { 0.80, 0.80, 0.80, 1 }, + ScrollbarGrabActive = { 1 , 1 , 1 , 1 }, + CheckMark = { 0.20, 0.20, 0.20, 1 }, + CheckMarkTrueDisabled = { 0.20, 0.20, 0.20, 1 }, + CheckMarkFalseDisabled = { 0.20, 0.20, 0.20, 1 }, + SliderGrab = { 0 , 0 , 0 , 0 }, + SliderGrabActive = { 0 , 0 , 0 , 0 }, + Button = { 1 , 1 , 1 , 1 }, + ButtonHovered = { 0.80, 0.80, 0.80, 1 }, + ButtonActive = { 1 , 1 , 1 , 1 }, + Header = { 0.80, 0.80, 0.80, 0.6 }, + HeaderHovered = { 0.80, 0.80, 0.80, 0.9 }, + HeaderActive = { 0.80, 0.80, 0.80, 0.9 }, + Separator = { 0.5 , 0.5 , 0.5 , 1 }, + SeparatorHovered = { 0.5 , 0.5 , 0.5 , 1 }, + SeparatorActive = { 0.5 , 0.5 , 0.5 , 1 }, + ResizeGrip = { 0.80, 0.80, 0.80, 1 }, + ResizeGripHovered = { 0.70, 0.70, 0.70, 1 }, + ResizeGripActive = { 0.70, 0.70, 0.70, 1 }, + Tab = { 0 , 0 , 0 , 0 }, + TabHovered = { 0 , 0 , 0 , 0 }, + TabActive = { 0 , 0 , 0 , 0 }, + TabUnfocused = { 0 , 0 , 0 , 0 }, + TabUnfocusedActive = { 0 , 0 , 0 , 0 }, + DockingPreview = { 0 , 0 , 0 , 0 }, + DockingEmptyBg = { 0 , 0 , 0 , 0 }, + PlotLines = { 0 , 0 , 0 , 0 }, + PlotLinesHovered = { 0 , 0 , 0 , 0 }, + PlotHistogram = { 0 , 0 , 0 , 0 }, + PlotHistogramHovered = { 0 , 0 , 0 , 0 }, + TextSelectedBg = { 0 , 0 , 0 , 0 }, + DragDropTarget = { 0 , 0 , 0 , 0 }, + NavHighlight = { 0 , 0 , 0 , 0 }, + NavWindowingHighlight = { 0 , 0 , 0 , 0 }, + NavWindowingDimBg = { 0 , 0 , 0 , 0 }, + ModalWindowDimBg = { 0 , 0 , 0 , 0 }, + ModalWindowDarkening = { 0 , 0 , 0 , 0 }, + COUNT = { 0 , 0 , 0 , 0 }, + CustomToggleOn = { 0.80, 0.80, 0.80, 1 }, + CustomToggleOnHovered = { 0.70, 0.70, 0.70, 1 }, + CustomToggleOnActive = { 0.80, 0.80, 0.80, 1 }, + CustomToggleOnText = { 0.20, 0.20, 0.20, 1 }, + CustomToggleOnDisable = { 0.04, 0.11, 0.12, 1 }, + CustomToggleOnDisableHovered = { 0.05, 0.16, 0.16, 1 }, + CustomToggleOnDisableText = { 0.06, 0.18, 0.2 , 1 }, + CustomToggleOff = { 0.57, 0.18, 0.16, 1 }, + CustomToggleOffHovered = { 0.45, 0.13, 0.14, 1 }, + CustomToggleOffDisable = { 0.1 , 0.04, 0.07, 1 }, + CustomToggleOffDisableHovered = { 0.16, 0.06, 0.07, 1 }, + CustomToggleOffDisableText = { 0.22, 0.07, 0.07, 1 }, + AltText = { 0.80, 0.80, 0.80, 1 }, + Hidden = { 0 , 0 , 0 , 0 }, +} + +---@param self themeWhite +---@param aGuiColor string +---@return float[] +function themeWhite.GetStyleColor(self, aGuiColor) + if self.states.HVR then + return self.hvr_colors[aGuiColor] + end + return self.def_colors[aGuiColor] +end + +function themeWhite.GetHoverState(self) + self.states.HVR = ImGui.IsWindowHovered(bit32.bor(ImGuiHoveredFlags.AnyWindow, ImGuiHoveredFlags.AllowWhenBlockedByActiveItem, ImGuiHoveredFlags.AllowWhenBlockedByPopup, ImGuiHoveredFlags.AllowWhenDisabled)) +end + +return themeWhite \ No newline at end of file diff --git a/scripts/modules/gui/widgets/btnToggle.lua b/scripts/modules/gui/widgets/btnToggle.lua index 96d081e..53d8ddc 100644 --- a/scripts/modules/gui/widgets/btnToggle.lua +++ b/scripts/modules/gui/widgets/btnToggle.lua @@ -1,6 +1,6 @@ local dpi = require ("modules/gui/dpi") -local style = require ("modules/gui/style") -local theme = require ("modules/gui/theme") +local themeSys = require ("modules/gui/themeSys") +local theme = themeSys.GetCurrentTheme() -- config local padding_x = 5 @@ -25,15 +25,15 @@ local function btnToggle(aLabel, aValue, aSizeX, aSizeY, aAutoscale) local imgui_style = ImGui.GetStyle() ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, imgui_style.FramePadding.x + dpi.Scale(padding_x), imgui_style.FramePadding.y + dpi.Scale(padding_y)) if aValue then - style.PushColor(ImGuiCol.Button, theme.CustomToggleOn) - style.PushColor(ImGuiCol.ButtonHovered, theme.CustomToggleOnHovered) - style.PushColor(ImGuiCol.ButtonActive, theme.CustomToggleOnActive) - style.PushColor(ImGuiCol.Text, theme.CustomToggleOnText) + themeSys.PushColor(ImGuiCol.Button, theme:GetStyleColor("CustomToggleOn")) + themeSys.PushColor(ImGuiCol.ButtonHovered, theme:GetStyleColor("CustomToggleOnHovered")) + themeSys.PushColor(ImGuiCol.ButtonActive, theme:GetStyleColor("CustomToggleOnActive")) + themeSys.PushColor(ImGuiCol.Text, theme:GetStyleColor("CustomToggleOnText")) else - style.PushColor(ImGuiCol.Button, theme.Button) - style.PushColor(ImGuiCol.ButtonHovered, theme.ButtonHovered) - style.PushColor(ImGuiCol.ButtonActive, theme.ButtonActive) - style.PushColor(ImGuiCol.Text, theme.Text) + themeSys.PushColor(ImGuiCol.Button, theme:GetStyleColor("Button")) + themeSys.PushColor(ImGuiCol.ButtonHovered, theme:GetStyleColor("ButtonHovered")) + themeSys.PushColor(ImGuiCol.ButtonActive, theme:GetStyleColor("ButtonActive")) + themeSys.PushColor(ImGuiCol.Text, theme:GetStyleColor("Text")) end if ImGui.Button(aLabel, aSizeX, aSizeY) then aValue = not aValue diff --git a/scripts/modules/gui/window.lua b/scripts/modules/gui/window.lua index ace89d8..15d6654 100644 --- a/scripts/modules/gui/window.lua +++ b/scripts/modules/gui/window.lua @@ -3,8 +3,8 @@ local dpi = require("modules/gui/dpi") local i18n = require("modules/i18n") local languages = require("lang/lang") local widgets = require("modules/gui/widgets") -local style = require("modules/gui/style") -local theme = require("modules/gui/theme") +local themeSys = require("modules/gui/themeSys") +local theme = themeSys.GetCurrentTheme() local options = CETMM.GetOptions() local mods = CETMM.GetBackEnd().GetMods() local dofiles = CETMM.GetDofiles() @@ -140,16 +140,13 @@ local function settings_popup() -- Theme if ImGui.BeginMenu("Theme") then if select(2, ImGui.MenuItem("Default", "", options.m_theme == "default")) then - options.m_theme = "default" - theme.Load() + themeSys.Load("default") end if select(2, ImGui.MenuItem("UA Special", "", options.m_theme == "ua_special")) then - options.m_theme = "ua_special" - theme.Load() + themeSys.Load("ua_special") end if select(2, ImGui.MenuItem("White", "", options.m_theme == "white")) then - options.m_theme = "white" - theme.Load() + themeSys.Load("white") end ImGui.EndMenu() end @@ -217,10 +214,13 @@ function window.Initialize() end function window.Render() + if ImGui.Button("Click") then + print(#theme) + end window.m_draw = ImGui.Begin(i18n("window_title"), window.m_draw) if window.m_draw then -- Hover check for white theme - theme.HVR = ImGui.IsWindowHovered(bit32.bor(ImGuiHoveredFlags.AnyWindow, ImGuiHoveredFlags.AllowWhenBlockedByActiveItem, ImGuiHoveredFlags.AllowWhenBlockedByPopup, ImGuiHoveredFlags.AllowWhenDisabled)) + theme:CallIf("white", "GetHoverState") -- Set window size and position ImGui.SetWindowPos(dpi.GetDisplayResolution().x / 2 - 210 * dpi.GetScale(), dpi.GetDisplayResolution().y / 2 - 320 * dpi.GetScale(), @@ -290,7 +290,7 @@ function window.Render() ImGui.Spacing() ImGui.TextWrapped(i18n("text_help_manager_5")) else - style.PushColor(ImGuiCol.Text, theme.AltText) + themeSys.PushColor(ImGuiCol.Text, theme:GetStyleColor("AltText")) ImGui.TextWrapped(i18n("text_help_dofiles_1")) ImGui.Spacing() ImGui.TextWrapped(i18n("text_help_dofiles_2")) @@ -385,12 +385,7 @@ function window.Render() CETMM.GetBackEnd().OpenDofilesFolder() end - if options.m_theme == "ua_special" then - ImGui.TableSetColumnIndex(1) - style.PushColor(ImGuiCol.Text, theme.Border) - ImGui.Text("We stand with Ukraine!") - ImGui.PopStyleColor(1) - end + theme:CallIf("ua_special", "RenderFooter") ImGui.EndTable() end From e948036d9d04a73ed27406924df67725fbf40d7b Mon Sep 17 00:00:00 2001 From: Mingming Cui Date: Wed, 30 Nov 2022 05:15:41 +0800 Subject: [PATCH 3/5] fix theme require --- scripts/modules/gui/themeSys.lua | 75 ++++++++++++----------- scripts/modules/gui/themes/white.lua | 13 ++-- scripts/modules/gui/widgets/btnToggle.lua | 17 +++-- scripts/modules/gui/window.lua | 11 ++-- 4 files changed, 58 insertions(+), 58 deletions(-) diff --git a/scripts/modules/gui/themeSys.lua b/scripts/modules/gui/themeSys.lua index 78eec65..4bcba33 100644 --- a/scripts/modules/gui/themeSys.lua +++ b/scripts/modules/gui/themeSys.lua @@ -1,12 +1,13 @@ local CETMM = require("modules/CETMM") ---@class themeSys -local themeSys = {} -local themes = { - default = require("modules/gui/themes/default"), - ua_special = require("modules/gui/themes/ua_special"), - white = require("modules/gui/themes/white"), +local themeSys = { + themes = { + default = require("modules/gui/themes/default"), + ua_special = require("modules/gui/themes/ua_special"), + white = require("modules/gui/themes/white"), + }, + currentTheme = {} ---@type baseTheme } -local currentTheme = {} ---@type baseTheme function themeSys.Initialize() local theme = CETMM.GetOptions().m_theme @@ -17,20 +18,20 @@ end ---@param aTheme string ---@param aNoSave? bool function themeSys.Load(aTheme, aNoSave) - if themes[aTheme] then - currentTheme = themes[aTheme] + if themeSys.themes[aTheme] then + themeSys.currentTheme = themeSys.themes[aTheme] else - currentTheme = themes.default + themeSys.currentTheme = themeSys.themes.default spdlog.error(string.format("Failed to load theme %s, loaded default theme instead.", aTheme)) end - if aNoSave then - CETMM.GetOptions().m_theme = currentTheme:GetName() + if not aNoSave then + CETMM.GetOptions().m_theme = themeSys.currentTheme:GetName() CETMM.GetOptions().Save() end end function themeSys.GetCurrentTheme() - return currentTheme + return themeSys.currentTheme end ---@param aStyle ImGuiCol @@ -40,31 +41,31 @@ function themeSys.PushColor(aStyle, aColor) end function themeSys.PushTheme() - themeSys.PushColor(ImGuiCol.TitleBg, currentTheme:GetStyleColor("TitleBg" )) - themeSys.PushColor(ImGuiCol.TitleBgCollapsed, currentTheme:GetStyleColor("TitleBgCollapsed" )) - themeSys.PushColor(ImGuiCol.TitleBgActive, currentTheme:GetStyleColor("TitleBgActive" )) - themeSys.PushColor(ImGuiCol.Border, currentTheme:GetStyleColor("Border" )) - themeSys.PushColor(ImGuiCol.WindowBg, currentTheme:GetStyleColor("WindowBg" )) - themeSys.PushColor(ImGuiCol.ScrollbarBg, currentTheme:GetStyleColor("ScrollbarBg" )) - themeSys.PushColor(ImGuiCol.ScrollbarGrab, currentTheme:GetStyleColor("ScrollbarGrab" )) - themeSys.PushColor(ImGuiCol.ScrollbarGrabHovered, currentTheme:GetStyleColor("ScrollbarGrabHovered" )) - themeSys.PushColor(ImGuiCol.ScrollbarGrabActive, currentTheme:GetStyleColor("ScrollbarGrabActive" )) - themeSys.PushColor(ImGuiCol.ResizeGrip, currentTheme:GetStyleColor("ResizeGrip" )) - themeSys.PushColor(ImGuiCol.ResizeGripHovered, currentTheme:GetStyleColor("ResizeGripHovered" )) - themeSys.PushColor(ImGuiCol.ResizeGripActive, currentTheme:GetStyleColor("ResizeGripActive" )) - themeSys.PushColor(ImGuiCol.Text, currentTheme:GetStyleColor("Text" )) - themeSys.PushColor(ImGuiCol.Header, currentTheme:GetStyleColor("Header" )) - themeSys.PushColor(ImGuiCol.HeaderHovered, currentTheme:GetStyleColor("HeaderHovered" )) - themeSys.PushColor(ImGuiCol.HeaderActive, currentTheme:GetStyleColor("HeaderActive" )) - themeSys.PushColor(ImGuiCol.CheckMark, currentTheme:GetStyleColor("CheckMark" )) - themeSys.PushColor(ImGuiCol.FrameBg, currentTheme:GetStyleColor("FrameBg" )) - themeSys.PushColor(ImGuiCol.FrameBgHovered, currentTheme:GetStyleColor("FrameBgHovered" )) - themeSys.PushColor(ImGuiCol.FrameBgActive, currentTheme:GetStyleColor("FrameBgActive" )) - themeSys.PushColor(ImGuiCol.Button, currentTheme:GetStyleColor("Button" )) - themeSys.PushColor(ImGuiCol.ButtonHovered, currentTheme:GetStyleColor("ButtonHovered" )) - themeSys.PushColor(ImGuiCol.ButtonActive, currentTheme:GetStyleColor("ButtonActive" )) - themeSys.PushColor(ImGuiCol.Separator, currentTheme:GetStyleColor("Separator" )) - themeSys.PushColor(ImGuiCol.PopupBg, currentTheme:GetStyleColor("PopupBg" )) + themeSys.PushColor(ImGuiCol.TitleBg, themeSys.currentTheme:GetStyleColor("TitleBg" )) + themeSys.PushColor(ImGuiCol.TitleBgCollapsed, themeSys.currentTheme:GetStyleColor("TitleBgCollapsed" )) + themeSys.PushColor(ImGuiCol.TitleBgActive, themeSys.currentTheme:GetStyleColor("TitleBgActive" )) + themeSys.PushColor(ImGuiCol.Border, themeSys.currentTheme:GetStyleColor("Border" )) + themeSys.PushColor(ImGuiCol.WindowBg, themeSys.currentTheme:GetStyleColor("WindowBg" )) + themeSys.PushColor(ImGuiCol.ScrollbarBg, themeSys.currentTheme:GetStyleColor("ScrollbarBg" )) + themeSys.PushColor(ImGuiCol.ScrollbarGrab, themeSys.currentTheme:GetStyleColor("ScrollbarGrab" )) + themeSys.PushColor(ImGuiCol.ScrollbarGrabHovered, themeSys.currentTheme:GetStyleColor("ScrollbarGrabHovered" )) + themeSys.PushColor(ImGuiCol.ScrollbarGrabActive, themeSys.currentTheme:GetStyleColor("ScrollbarGrabActive" )) + themeSys.PushColor(ImGuiCol.ResizeGrip, themeSys.currentTheme:GetStyleColor("ResizeGrip" )) + themeSys.PushColor(ImGuiCol.ResizeGripHovered, themeSys.currentTheme:GetStyleColor("ResizeGripHovered" )) + themeSys.PushColor(ImGuiCol.ResizeGripActive, themeSys.currentTheme:GetStyleColor("ResizeGripActive" )) + themeSys.PushColor(ImGuiCol.Text, themeSys.currentTheme:GetStyleColor("Text" )) + themeSys.PushColor(ImGuiCol.Header, themeSys.currentTheme:GetStyleColor("Header" )) + themeSys.PushColor(ImGuiCol.HeaderHovered, themeSys.currentTheme:GetStyleColor("HeaderHovered" )) + themeSys.PushColor(ImGuiCol.HeaderActive, themeSys.currentTheme:GetStyleColor("HeaderActive" )) + themeSys.PushColor(ImGuiCol.CheckMark, themeSys.currentTheme:GetStyleColor("CheckMark" )) + themeSys.PushColor(ImGuiCol.FrameBg, themeSys.currentTheme:GetStyleColor("FrameBg" )) + themeSys.PushColor(ImGuiCol.FrameBgHovered, themeSys.currentTheme:GetStyleColor("FrameBgHovered" )) + themeSys.PushColor(ImGuiCol.FrameBgActive, themeSys.currentTheme:GetStyleColor("FrameBgActive" )) + themeSys.PushColor(ImGuiCol.Button, themeSys.currentTheme:GetStyleColor("Button" )) + themeSys.PushColor(ImGuiCol.ButtonHovered, themeSys.currentTheme:GetStyleColor("ButtonHovered" )) + themeSys.PushColor(ImGuiCol.ButtonActive, themeSys.currentTheme:GetStyleColor("ButtonActive" )) + themeSys.PushColor(ImGuiCol.Separator, themeSys.currentTheme:GetStyleColor("Separator" )) + themeSys.PushColor(ImGuiCol.PopupBg, themeSys.currentTheme:GetStyleColor("PopupBg" )) ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, 8, 8) ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 0) diff --git a/scripts/modules/gui/themes/white.lua b/scripts/modules/gui/themes/white.lua index 27337e4..6bc137d 100644 --- a/scripts/modules/gui/themes/white.lua +++ b/scripts/modules/gui/themes/white.lua @@ -160,14 +160,17 @@ themeWhite.hvr_colors = { ---@param aGuiColor string ---@return float[] function themeWhite.GetStyleColor(self, aGuiColor) - if self.states.HVR then - return self.hvr_colors[aGuiColor] - end + for window, hovering in pairs(self.states) do + if hovering then + return self.hvr_colors[aGuiColor] + end + end return self.def_colors[aGuiColor] end -function themeWhite.GetHoverState(self) - self.states.HVR = ImGui.IsWindowHovered(bit32.bor(ImGuiHoveredFlags.AnyWindow, ImGuiHoveredFlags.AllowWhenBlockedByActiveItem, ImGuiHoveredFlags.AllowWhenBlockedByPopup, ImGuiHoveredFlags.AllowWhenDisabled)) +---@param aWindow string +function themeWhite.GetHoverState(self, aWindow) + self.states[aWindow] = ImGui.IsWindowHovered(bit32.bor(ImGuiHoveredFlags.RootAndChildWindows, ImGuiHoveredFlags.AllowWhenBlockedByActiveItem, ImGuiHoveredFlags.AllowWhenBlockedByPopup, ImGuiHoveredFlags.AllowWhenDisabled)) end return themeWhite \ No newline at end of file diff --git a/scripts/modules/gui/widgets/btnToggle.lua b/scripts/modules/gui/widgets/btnToggle.lua index 53d8ddc..1d2c1d4 100644 --- a/scripts/modules/gui/widgets/btnToggle.lua +++ b/scripts/modules/gui/widgets/btnToggle.lua @@ -1,6 +1,5 @@ local dpi = require ("modules/gui/dpi") local themeSys = require ("modules/gui/themeSys") -local theme = themeSys.GetCurrentTheme() -- config local padding_x = 5 @@ -25,15 +24,15 @@ local function btnToggle(aLabel, aValue, aSizeX, aSizeY, aAutoscale) local imgui_style = ImGui.GetStyle() ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, imgui_style.FramePadding.x + dpi.Scale(padding_x), imgui_style.FramePadding.y + dpi.Scale(padding_y)) if aValue then - themeSys.PushColor(ImGuiCol.Button, theme:GetStyleColor("CustomToggleOn")) - themeSys.PushColor(ImGuiCol.ButtonHovered, theme:GetStyleColor("CustomToggleOnHovered")) - themeSys.PushColor(ImGuiCol.ButtonActive, theme:GetStyleColor("CustomToggleOnActive")) - themeSys.PushColor(ImGuiCol.Text, theme:GetStyleColor("CustomToggleOnText")) + themeSys.PushColor(ImGuiCol.Button, themeSys.GetCurrentTheme():GetStyleColor("CustomToggleOn")) + themeSys.PushColor(ImGuiCol.ButtonHovered, themeSys.GetCurrentTheme():GetStyleColor("CustomToggleOnHovered")) + themeSys.PushColor(ImGuiCol.ButtonActive, themeSys.GetCurrentTheme():GetStyleColor("CustomToggleOnActive")) + themeSys.PushColor(ImGuiCol.Text, themeSys.GetCurrentTheme():GetStyleColor("CustomToggleOnText")) else - themeSys.PushColor(ImGuiCol.Button, theme:GetStyleColor("Button")) - themeSys.PushColor(ImGuiCol.ButtonHovered, theme:GetStyleColor("ButtonHovered")) - themeSys.PushColor(ImGuiCol.ButtonActive, theme:GetStyleColor("ButtonActive")) - themeSys.PushColor(ImGuiCol.Text, theme:GetStyleColor("Text")) + themeSys.PushColor(ImGuiCol.Button, themeSys.GetCurrentTheme():GetStyleColor("Button")) + themeSys.PushColor(ImGuiCol.ButtonHovered, themeSys.GetCurrentTheme():GetStyleColor("ButtonHovered")) + themeSys.PushColor(ImGuiCol.ButtonActive, themeSys.GetCurrentTheme():GetStyleColor("ButtonActive")) + themeSys.PushColor(ImGuiCol.Text, themeSys.GetCurrentTheme():GetStyleColor("Text")) end if ImGui.Button(aLabel, aSizeX, aSizeY) then aValue = not aValue diff --git a/scripts/modules/gui/window.lua b/scripts/modules/gui/window.lua index 15d6654..83240f2 100644 --- a/scripts/modules/gui/window.lua +++ b/scripts/modules/gui/window.lua @@ -4,7 +4,6 @@ local i18n = require("modules/i18n") local languages = require("lang/lang") local widgets = require("modules/gui/widgets") local themeSys = require("modules/gui/themeSys") -local theme = themeSys.GetCurrentTheme() local options = CETMM.GetOptions() local mods = CETMM.GetBackEnd().GetMods() local dofiles = CETMM.GetDofiles() @@ -38,6 +37,7 @@ local layout = { local function renderAboutWindow() window.m_draw_about = ImGui.Begin(window.m_about_title, window.m_draw_about, bit32.bor(ImGuiWindowFlags.NoSavedSettings, ImGuiWindowFlags.NoResize)) if window.m_draw_about then + themeSys.GetCurrentTheme():CallIf("white", "GetHoverState", "about") ImGui.SetWindowPos(dpi.GetDisplayResolution().x / 2 - dpi.Scale(300), dpi.Scale(dpi.GetDisplayResolution().y * 0.1), ImGuiCond.FirstUseEver) @@ -214,13 +214,10 @@ function window.Initialize() end function window.Render() - if ImGui.Button("Click") then - print(#theme) - end window.m_draw = ImGui.Begin(i18n("window_title"), window.m_draw) if window.m_draw then -- Hover check for white theme - theme:CallIf("white", "GetHoverState") + themeSys.GetCurrentTheme():CallIf("white", "GetHoverState", "main") -- Set window size and position ImGui.SetWindowPos(dpi.GetDisplayResolution().x / 2 - 210 * dpi.GetScale(), dpi.GetDisplayResolution().y / 2 - 320 * dpi.GetScale(), @@ -290,7 +287,7 @@ function window.Render() ImGui.Spacing() ImGui.TextWrapped(i18n("text_help_manager_5")) else - themeSys.PushColor(ImGuiCol.Text, theme:GetStyleColor("AltText")) + themeSys.PushColor(ImGuiCol.Text, themeSys.GetCurrentTheme():GetStyleColor("AltText")) ImGui.TextWrapped(i18n("text_help_dofiles_1")) ImGui.Spacing() ImGui.TextWrapped(i18n("text_help_dofiles_2")) @@ -385,7 +382,7 @@ function window.Render() CETMM.GetBackEnd().OpenDofilesFolder() end - theme:CallIf("ua_special", "RenderFooter") + themeSys.GetCurrentTheme():CallIf("ua_special", "RenderFooter") ImGui.EndTable() end From f03342b1636d9d355f51eb10507c5dfb1b87b71a Mon Sep 17 00:00:00 2001 From: Mingming Cui Date: Wed, 30 Nov 2022 06:10:49 +0800 Subject: [PATCH 4/5] set default theme --- scripts/modules/options.lua | 2 +- src/Installer/Update.cpp | 23 +++++++++++++++++++++++ src/Installer/Update.h | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/scripts/modules/options.lua b/scripts/modules/options.lua index 00d664d..d70296a 100644 --- a/scripts/modules/options.lua +++ b/scripts/modules/options.lua @@ -5,7 +5,7 @@ local options = { m_lang = "en_us", m_autoappear = true, - m_theme = "default" + m_theme = "white" --default } -- private functions diff --git a/src/Installer/Update.cpp b/src/Installer/Update.cpp index 2fe0bb5..24da5f5 100644 --- a/src/Installer/Update.cpp +++ b/src/Installer/Update.cpp @@ -74,7 +74,10 @@ void Update::extractModule() bin2cppLua::FileManager& mgr_lua = bin2cppLua::FileManager::getInstance(); bool saved_lua = mgr_lua.saveFiles(scriptDir.string().c_str()); if (saved_loose && saved_lua) + { spdlog::info("Extracted script files to \"{}\"", scriptDir.string()); + setConfig(); // white update + } else spdlog::error("Failed to extract script files to \"{}\"", scriptDir.string()); } @@ -104,4 +107,24 @@ void Update::removeOldModule() spdlog::info("Removed: {}", dir_entry.path().string()); } } +} + +void Update::setConfig() // white update +{ + spdlog::info("Updating theme config.."); + + std::filesystem::path configPath = Installer::GetPaths().CETMMRoot() / "config.json"; + + std::fstream file; + file.open(configPath, std::fstream::in | std::fstream::out); + if (!file.is_open()) return; + + nlohmann::json cetmm_config = nlohmann::json::parse(file); + std::filesystem::resize_file(configPath, 0); + file.seekg(0); + + cetmm_config["theme"] = "white"; + + file << cetmm_config.dump() << std::endl; + file.close(); } \ No newline at end of file diff --git a/src/Installer/Update.h b/src/Installer/Update.h index 4258885..8ec2ef2 100644 --- a/src/Installer/Update.h +++ b/src/Installer/Update.h @@ -16,4 +16,5 @@ class Update std::string getModuleVersion(); void extractModule(); void removeOldModule(); + void setConfig(); //white update }; \ No newline at end of file From 7a192fff30a01d5315a80ace78766265e1c3b4ec Mon Sep 17 00:00:00 2001 From: Mingming Cui Date: Wed, 30 Nov 2022 06:22:48 +0800 Subject: [PATCH 5/5] cleanup --- scripts/modules/gui/themes/white.lua | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/scripts/modules/gui/themes/white.lua b/scripts/modules/gui/themes/white.lua index 6bc137d..39a5de0 100644 --- a/scripts/modules/gui/themes/white.lua +++ b/scripts/modules/gui/themes/white.lua @@ -3,10 +3,7 @@ local baseTheme = require("modules/gui/themes/baseTheme") ---@class themeWhite : baseTheme local themeWhite = baseTheme("white") -themeWhite.states = { - HVR = false, - HVRBefore = nil, -} +themeWhite.states = {} themeWhite.def_colors = { Text = { 1 , 1 , 1 , 1 }, @@ -83,7 +80,7 @@ themeWhite.def_colors = { } themeWhite.hvr_colors = { - Text = { 0.20, 0.20, 0.20, 1 }, + Text = { 0.20, 0.20, 0.20, 1 }, TextDisabled = { 0.48, 0.39, 0.40, 1 }, WindowBg = { 1 , 1 , 1 , 0.9 }, ChildBg = { 1 , 1 , 1 , 0.9 },