Refactor usages of CMenus::DoButton_MenuTab

Use `IGraphics::CORNER_NONE` instead of `0`.

Use `nullptr` instead of `NULL`.

Remove arguments identical to defaults.

Use loops for tab bars with several tabs.
This commit is contained in:
Robert Müller 2024-01-24 23:07:31 +01:00
parent 7854a277c7
commit 8982da4a32
5 changed files with 50 additions and 53 deletions

View file

@ -618,17 +618,17 @@ void CMenus::RenderMenubar(CUIRect Box)
Box.VSplitLeft(90.0f, &Button, &Box); Box.VSplitLeft(90.0f, &Button, &Box);
static CButtonContainer s_PlayersButton; static CButtonContainer s_PlayersButton;
if(DoButton_MenuTab(&s_PlayersButton, Localize("Players"), m_ActivePage == PAGE_PLAYERS, &Button, 0)) if(DoButton_MenuTab(&s_PlayersButton, Localize("Players"), m_ActivePage == PAGE_PLAYERS, &Button, IGraphics::CORNER_NONE))
NewPage = PAGE_PLAYERS; NewPage = PAGE_PLAYERS;
Box.VSplitLeft(130.0f, &Button, &Box); Box.VSplitLeft(130.0f, &Button, &Box);
static CButtonContainer s_ServerInfoButton; static CButtonContainer s_ServerInfoButton;
if(DoButton_MenuTab(&s_ServerInfoButton, Localize("Server info"), m_ActivePage == PAGE_SERVER_INFO, &Button, 0)) if(DoButton_MenuTab(&s_ServerInfoButton, Localize("Server info"), m_ActivePage == PAGE_SERVER_INFO, &Button, IGraphics::CORNER_NONE))
NewPage = PAGE_SERVER_INFO; NewPage = PAGE_SERVER_INFO;
Box.VSplitLeft(90.0f, &Button, &Box); Box.VSplitLeft(90.0f, &Button, &Box);
static CButtonContainer s_NetworkButton; static CButtonContainer s_NetworkButton;
if(DoButton_MenuTab(&s_NetworkButton, Localize("Browser"), m_ActivePage == PAGE_NETWORK, &Button, 0)) if(DoButton_MenuTab(&s_NetworkButton, Localize("Browser"), m_ActivePage == PAGE_NETWORK, &Button, IGraphics::CORNER_NONE))
NewPage = PAGE_NETWORK; NewPage = PAGE_NETWORK;
{ {
@ -636,7 +636,7 @@ void CMenus::RenderMenubar(CUIRect Box)
if(GameClient()->m_GameInfo.m_Race) if(GameClient()->m_GameInfo.m_Race)
{ {
Box.VSplitLeft(90.0f, &Button, &Box); Box.VSplitLeft(90.0f, &Button, &Box);
if(DoButton_MenuTab(&s_GhostButton, Localize("Ghost"), m_ActivePage == PAGE_GHOST, &Button, 0)) if(DoButton_MenuTab(&s_GhostButton, Localize("Ghost"), m_ActivePage == PAGE_GHOST, &Button, IGraphics::CORNER_NONE))
NewPage = PAGE_GHOST; NewPage = PAGE_GHOST;
} }
} }
@ -672,13 +672,13 @@ void CMenus::RenderMenubar(CUIRect Box)
Box.VSplitRight(10.0f, &Box, nullptr); Box.VSplitRight(10.0f, &Box, nullptr);
Box.VSplitRight(33.0f, &Box, &Button); Box.VSplitRight(33.0f, &Box, &Button);
static CButtonContainer s_SettingsButton; static CButtonContainer s_SettingsButton;
if(DoButton_MenuTab(&s_SettingsButton, FONT_ICON_GEAR, m_ActivePage == PAGE_SETTINGS, &Button, IGraphics::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_SETTINGS], nullptr, nullptr, nullptr, 10.0f)) if(DoButton_MenuTab(&s_SettingsButton, FONT_ICON_GEAR, m_ActivePage == PAGE_SETTINGS, &Button, IGraphics::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_SETTINGS]))
NewPage = PAGE_SETTINGS; NewPage = PAGE_SETTINGS;
Box.VSplitRight(10.0f, &Box, nullptr); Box.VSplitRight(10.0f, &Box, nullptr);
Box.VSplitRight(33.0f, &Box, &Button); Box.VSplitRight(33.0f, &Box, &Button);
static CButtonContainer s_EditorButton; static CButtonContainer s_EditorButton;
if(DoButton_MenuTab(&s_EditorButton, FONT_ICON_PEN_TO_SQUARE, 0, &Button, IGraphics::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_EDITOR], nullptr, nullptr, nullptr, 10.0f)) if(DoButton_MenuTab(&s_EditorButton, FONT_ICON_PEN_TO_SQUARE, 0, &Button, IGraphics::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_EDITOR]))
{ {
g_Config.m_ClEditor = 1; g_Config.m_ClEditor = 1;
} }
@ -688,7 +688,7 @@ void CMenus::RenderMenubar(CUIRect Box)
Box.VSplitRight(10.0f, &Box, nullptr); Box.VSplitRight(10.0f, &Box, nullptr);
Box.VSplitRight(33.0f, &Box, &Button); Box.VSplitRight(33.0f, &Box, &Button);
static CButtonContainer s_DemoButton; static CButtonContainer s_DemoButton;
if(DoButton_MenuTab(&s_DemoButton, FONT_ICON_CLAPPERBOARD, m_ActivePage == PAGE_DEMOS, &Button, IGraphics::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_DEMOBUTTON], nullptr, nullptr, nullptr, 10.0f)) if(DoButton_MenuTab(&s_DemoButton, FONT_ICON_CLAPPERBOARD, m_ActivePage == PAGE_DEMOS, &Button, IGraphics::CORNER_T, &m_aAnimatorsSmallPage[SMALL_TAB_DEMOBUTTON]))
NewPage = PAGE_DEMOS; NewPage = PAGE_DEMOS;
} }

View file

@ -61,7 +61,7 @@ class CMenus : public CComponent
int DoButton_FontIcon(CButtonContainer *pButtonContainer, const char *pText, int Checked, const CUIRect *pRect, int Corners = IGraphics::CORNER_ALL, bool Enabled = true); int DoButton_FontIcon(CButtonContainer *pButtonContainer, const char *pText, int Checked, const CUIRect *pRect, int Corners = IGraphics::CORNER_ALL, bool Enabled = true);
int DoButton_Toggle(const void *pID, int Checked, const CUIRect *pRect, bool Active); int DoButton_Toggle(const void *pID, int Checked, const CUIRect *pRect, bool Active);
int DoButton_Menu(CButtonContainer *pButtonContainer, const char *pText, int Checked, const CUIRect *pRect, const char *pImageName = nullptr, int Corners = IGraphics::CORNER_ALL, float Rounding = 5.0f, float FontFactor = 0.0f, ColorRGBA Color = ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f)); int DoButton_Menu(CButtonContainer *pButtonContainer, const char *pText, int Checked, const CUIRect *pRect, const char *pImageName = nullptr, int Corners = IGraphics::CORNER_ALL, float Rounding = 5.0f, float FontFactor = 0.0f, ColorRGBA Color = ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f));
int DoButton_MenuTab(CButtonContainer *pButtonContainer, const char *pText, int Checked, const CUIRect *pRect, int Corners, SUIAnimator *pAnimator = nullptr, const ColorRGBA *pDefaultColor = nullptr, const ColorRGBA *pActiveColor = nullptr, const ColorRGBA *pHoverColor = nullptr, float EdgeRounding = 10); int DoButton_MenuTab(CButtonContainer *pButtonContainer, const char *pText, int Checked, const CUIRect *pRect, int Corners, SUIAnimator *pAnimator = nullptr, const ColorRGBA *pDefaultColor = nullptr, const ColorRGBA *pActiveColor = nullptr, const ColorRGBA *pHoverColor = nullptr, float EdgeRounding = 10.0f);
int DoButton_CheckBox_Common(const void *pID, const char *pText, const char *pBoxText, const CUIRect *pRect); int DoButton_CheckBox_Common(const void *pID, const char *pText, const char *pBoxText, const CUIRect *pRect);
int DoButton_CheckBox(const void *pID, const char *pText, int Checked, const CUIRect *pRect); int DoButton_CheckBox(const void *pID, const char *pText, int Checked, const CUIRect *pRect);

View file

@ -636,16 +636,16 @@ void CMenus::RenderServerControl(CUIRect MainView)
// tab bar // tab bar
TabBar.VSplitLeft(TabBar.w / 3, &Button, &TabBar); TabBar.VSplitLeft(TabBar.w / 3, &Button, &TabBar);
static CButtonContainer s_Button0; static CButtonContainer s_Button0;
if(DoButton_MenuTab(&s_Button0, Localize("Change settings"), s_ControlPage == 0, &Button, 0)) if(DoButton_MenuTab(&s_Button0, Localize("Change settings"), s_ControlPage == 0, &Button, IGraphics::CORNER_NONE))
s_ControlPage = 0; s_ControlPage = 0;
TabBar.VSplitMid(&Button, &TabBar); TabBar.VSplitMid(&Button, &TabBar);
static CButtonContainer s_Button1; static CButtonContainer s_Button1;
if(DoButton_MenuTab(&s_Button1, Localize("Kick player"), s_ControlPage == 1, &Button, 0)) if(DoButton_MenuTab(&s_Button1, Localize("Kick player"), s_ControlPage == 1, &Button, IGraphics::CORNER_NONE))
s_ControlPage = 1; s_ControlPage = 1;
static CButtonContainer s_Button2; static CButtonContainer s_Button2;
if(DoButton_MenuTab(&s_Button2, Localize("Move player to spectators"), s_ControlPage == 2, &TabBar, 0)) if(DoButton_MenuTab(&s_Button2, Localize("Move player to spectators"), s_ControlPage == 2, &TabBar, IGraphics::CORNER_NONE))
s_ControlPage = 2; s_ControlPage = 2;
// render page // render page

View file

@ -2468,30 +2468,28 @@ void CMenus::RenderSettingsAppearance(CUIRect MainView)
char aBuf[128]; char aBuf[128];
static int s_CurTab = 0; static int s_CurTab = 0;
CUIRect TabBar, Page1Tab, Page2Tab, Page3Tab, Page4Tab, Page5Tab, Page6Tab, LeftView, RightView, Section, Button, Label; CUIRect TabBar, LeftView, RightView, Section, Button, Label;
MainView.HSplitTop(20, &TabBar, &MainView);
float TabsW = TabBar.w;
TabBar.VSplitLeft(TabsW / NUMBER_OF_APPEARANCE_TABS, &Page1Tab, &Page2Tab);
Page2Tab.VSplitLeft(TabsW / NUMBER_OF_APPEARANCE_TABS, &Page2Tab, &Page3Tab);
Page3Tab.VSplitLeft(TabsW / NUMBER_OF_APPEARANCE_TABS, &Page3Tab, &Page4Tab);
Page4Tab.VSplitLeft(TabsW / NUMBER_OF_APPEARANCE_TABS, &Page4Tab, &Page5Tab);
Page5Tab.VSplitLeft(TabsW / NUMBER_OF_APPEARANCE_TABS, &Page5Tab, &Page6Tab);
MainView.HSplitTop(20.0f, &TabBar, &MainView);
const float TabWidth = TabBar.w / NUMBER_OF_APPEARANCE_TABS;
static CButtonContainer s_aPageTabs[NUMBER_OF_APPEARANCE_TABS] = {}; static CButtonContainer s_aPageTabs[NUMBER_OF_APPEARANCE_TABS] = {};
const char *apTabNames[NUMBER_OF_APPEARANCE_TABS] = {
Localize("HUD"),
Localize("Chat"),
Localize("Name Plate"),
Localize("Hook Collisions"),
Localize("Info Messages"),
Localize("Laser")};
if(DoButton_MenuTab(&s_aPageTabs[APPEARANCE_TAB_HUD], Localize("HUD"), s_CurTab == APPEARANCE_TAB_HUD, &Page1Tab, IGraphics::CORNER_L, NULL, NULL, NULL, NULL, 4)) for(int Tab = APPEARANCE_TAB_HUD; Tab < NUMBER_OF_APPEARANCE_TABS; ++Tab)
s_CurTab = APPEARANCE_TAB_HUD; {
if(DoButton_MenuTab(&s_aPageTabs[APPEARANCE_TAB_CHAT], Localize("Chat"), s_CurTab == APPEARANCE_TAB_CHAT, &Page2Tab, 0, NULL, NULL, NULL, NULL, 4)) TabBar.VSplitLeft(TabWidth, &Button, &TabBar);
s_CurTab = APPEARANCE_TAB_CHAT; const int Corners = Tab == APPEARANCE_TAB_HUD ? IGraphics::CORNER_L : Tab == NUMBER_OF_APPEARANCE_TABS - 1 ? IGraphics::CORNER_R : IGraphics::CORNER_NONE;
if(DoButton_MenuTab(&s_aPageTabs[APPEARANCE_TAB_NAME_PLATE], Localize("Name Plate"), s_CurTab == APPEARANCE_TAB_NAME_PLATE, &Page3Tab, 0, NULL, NULL, NULL, NULL, 4)) if(DoButton_MenuTab(&s_aPageTabs[Tab], apTabNames[Tab], s_CurTab == Tab, &Button, Corners, nullptr, nullptr, nullptr, nullptr, 4.0f))
s_CurTab = APPEARANCE_TAB_NAME_PLATE; {
if(DoButton_MenuTab(&s_aPageTabs[APPEARANCE_TAB_HOOK_COLLISION], Localize("Hook Collisions"), s_CurTab == APPEARANCE_TAB_HOOK_COLLISION, &Page4Tab, 0, NULL, NULL, NULL, NULL, 4)) s_CurTab = Tab;
s_CurTab = APPEARANCE_TAB_HOOK_COLLISION; }
if(DoButton_MenuTab(&s_aPageTabs[APPEARANCE_TAB_INFO_MESSAGES], Localize("Info Messages"), s_CurTab == APPEARANCE_TAB_INFO_MESSAGES, &Page5Tab, 0, NULL, NULL, NULL, NULL, 4)) }
s_CurTab = APPEARANCE_TAB_INFO_MESSAGES;
if(DoButton_MenuTab(&s_aPageTabs[APPEARANCE_TAB_LASER], Localize("Laser"), s_CurTab == APPEARANCE_TAB_LASER, &Page6Tab, IGraphics::CORNER_R, NULL, NULL, NULL, NULL, 4))
s_CurTab = APPEARANCE_TAB_LASER;
MainView.HSplitTop(10.0f, nullptr, &MainView); MainView.HSplitTop(10.0f, nullptr, &MainView);

View file

@ -352,30 +352,29 @@ int InitSearchList(std::vector<const TName *> &vpSearchList, std::vector<TName>
void CMenus::RenderSettingsCustom(CUIRect MainView) void CMenus::RenderSettingsCustom(CUIRect MainView)
{ {
CUIRect TabBar, CustomList, QuickSearch, QuickSearchClearButton, DirectoryButton, Page1Tab, Page2Tab, Page3Tab, Page4Tab, Page5Tab, Page6Tab, ReloadButton; CUIRect TabBar, CustomList, QuickSearch, QuickSearchClearButton, DirectoryButton, ReloadButton;
MainView.HSplitTop(20, &TabBar, &MainView);
float TabsW = TabBar.w;
TabBar.VSplitLeft(TabsW / NUMBER_OF_ASSETS_TABS, &Page1Tab, &Page2Tab);
Page2Tab.VSplitLeft(TabsW / NUMBER_OF_ASSETS_TABS, &Page2Tab, &Page3Tab);
Page3Tab.VSplitLeft(TabsW / NUMBER_OF_ASSETS_TABS, &Page3Tab, &Page4Tab);
Page4Tab.VSplitLeft(TabsW / NUMBER_OF_ASSETS_TABS, &Page4Tab, &Page5Tab);
Page5Tab.VSplitLeft(TabsW / NUMBER_OF_ASSETS_TABS, &Page5Tab, &Page6Tab);
MainView.HSplitTop(20.0f, &TabBar, &MainView);
const float TabWidth = TabBar.w / NUMBER_OF_ASSETS_TABS;
static CButtonContainer s_aPageTabs[NUMBER_OF_ASSETS_TABS] = {}; static CButtonContainer s_aPageTabs[NUMBER_OF_ASSETS_TABS] = {};
const char *apTabNames[NUMBER_OF_ASSETS_TABS] = {
Localize("Entities"),
Localize("Game"),
Localize("Emoticons"),
Localize("Particles"),
Localize("HUD"),
Localize("Extras")};
if(DoButton_MenuTab((CButtonContainer *)&s_aPageTabs[ASSETS_TAB_ENTITIES], Localize("Entities"), s_CurCustomTab == ASSETS_TAB_ENTITIES, &Page1Tab, IGraphics::CORNER_L, NULL, NULL, NULL, NULL, 4)) for(int Tab = ASSETS_TAB_ENTITIES; Tab < NUMBER_OF_ASSETS_TABS; ++Tab)
s_CurCustomTab = ASSETS_TAB_ENTITIES; {
if(DoButton_MenuTab((CButtonContainer *)&s_aPageTabs[ASSETS_TAB_GAME], Localize("Game"), s_CurCustomTab == ASSETS_TAB_GAME, &Page2Tab, 0, NULL, NULL, NULL, NULL, 4)) CUIRect Button;
s_CurCustomTab = ASSETS_TAB_GAME; TabBar.VSplitLeft(TabWidth, &Button, &TabBar);
if(DoButton_MenuTab((CButtonContainer *)&s_aPageTabs[ASSETS_TAB_EMOTICONS], Localize("Emoticons"), s_CurCustomTab == ASSETS_TAB_EMOTICONS, &Page3Tab, 0, NULL, NULL, NULL, NULL, 4)) const int Corners = Tab == ASSETS_TAB_ENTITIES ? IGraphics::CORNER_L : Tab == NUMBER_OF_ASSETS_TABS - 1 ? IGraphics::CORNER_R : IGraphics::CORNER_NONE;
s_CurCustomTab = ASSETS_TAB_EMOTICONS; if(DoButton_MenuTab(&s_aPageTabs[Tab], apTabNames[Tab], s_CurCustomTab == Tab, &Button, Corners, nullptr, nullptr, nullptr, nullptr, 4.0f))
if(DoButton_MenuTab((CButtonContainer *)&s_aPageTabs[ASSETS_TAB_PARTICLES], Localize("Particles"), s_CurCustomTab == ASSETS_TAB_PARTICLES, &Page4Tab, 0, NULL, NULL, NULL, NULL, 4)) {
s_CurCustomTab = ASSETS_TAB_PARTICLES; s_CurCustomTab = Tab;
if(DoButton_MenuTab((CButtonContainer *)&s_aPageTabs[ASSETS_TAB_HUD], Localize("HUD"), s_CurCustomTab == ASSETS_TAB_HUD, &Page5Tab, 0, NULL, NULL, NULL, NULL, 4)) }
s_CurCustomTab = ASSETS_TAB_HUD; }
if(DoButton_MenuTab((CButtonContainer *)&s_aPageTabs[ASSETS_TAB_EXTRAS], Localize("Extras"), s_CurCustomTab == ASSETS_TAB_EXTRAS, &Page6Tab, IGraphics::CORNER_R, NULL, NULL, NULL, NULL, 4))
s_CurCustomTab = ASSETS_TAB_EXTRAS;
auto LoadStartTime = time_get_nanoseconds(); auto LoadStartTime = time_get_nanoseconds();
SMenuAssetScanUser User; SMenuAssetScanUser User;