Skip to content

Commit

Permalink
rework GuiShortcut. for main menu
Browse files Browse the repository at this point in the history
  • Loading branch information
cryham committed Apr 28, 2024
1 parent 3e397fa commit da60493
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 46 deletions.
8 changes: 8 additions & 0 deletions src/game/BaseApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ bool BaseApp::isTweak()
return mWndTweak && mWndTweak->getVisible();
}

void BaseApp::updPanGames(int yToSet)
{
if (yToSet >= 0)
pSet->yGames = yToSet;
for (int i=0; i < ciGamesBtns; ++i)
mMainGamesPanels[i]->setVisible(pSet->yGames == i);
}


//-------------------------------------------------------------------------------------
// 🎛️ input events 🖱️ mouse
Expand Down
1 change: 1 addition & 0 deletions src/game/BaseApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class BaseApp : public AppGui, public GameState
Wnd mWMainMenu =0, mWMainSetup =0, mWMainGames =0;
Img mMainPanels[ciMainBtns] ={0,}, mMainSetupPanels[ciSetupBtns] ={0,}, mMainGamesPanels[ciGamesBtns] ={0,};
Btn mMainBtns [ciMainBtns] ={0,}, mMainSetupBtns [ciSetupBtns] ={0,}, mMainGamesBtns [ciGamesBtns] ={0,};
void updPanGames(int yToSet=-1);

/// wnds ----
Wnd mWndGame =0, mWndReplays =0,
Expand Down
2 changes: 1 addition & 1 deletion src/game/CGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CGui : public BGui

// Gui util
void toggleGui(bool toggle=true);
void GuiShortcut(EMenu menu, int tab, int subtab=-1);
void GuiShortcut(EMenu menu, int tab, int subtab=-1, int game=-1);
void UpdWndTitle();
void tabGame(Tab, size_t);

Expand Down
16 changes: 8 additions & 8 deletions src/game/CGui_Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,16 @@ void CGui::btnMainMenu(WP wp)
if (wp == app->mMainGamesBtns[i])
{ switch (i)
{
case Games_Single: SetNumPlayers(1); GuiShortcut(MN_Single, TAB_Track); break;
case Games_SplitScreen: SetNumPlayers(-2); GuiShortcut(MN_Single, TAB_Split); break; // 👥
case Games_Multiplayer: SetNumPlayers(1); GuiShortcut(MN_Single, TAB_Multi); break; // 📡
case Games_Single: GuiShortcut(MN_Single, TAB_Track, -1, i); return;
case Games_SplitScreen: GuiShortcut(MN_Single, TAB_Split, -1, i); return; // 👥
case Games_Multiplayer: GuiShortcut(MN_Single, TAB_Multi, -1, i); return; // 📡

case Games_Tutorial: pSet->iMenu = MN_Tutorial; break;
case Games_Champ: pSet->iMenu = MN_Champ; break;
case Games_Challenge: pSet->iMenu = MN_Chall; break;
case Games_Tutorial: GuiShortcut(MN_Tutorial, TAB_Champs, -1, i); return;
case Games_Champ: GuiShortcut(MN_Champ, TAB_Champs, -1, i); return;
case Games_Challenge: GuiShortcut(MN_Chall, TAB_Champs, -1, i); return;

case Games_Collection: pSet->iMenu = MN_Collect; break;
case Games_Career: pSet->iMenu = MN_Career; break; // todo
case Games_Collection: GuiShortcut(MN_Collect, TAB_Champs, -1, i); break;
case Games_Career: GuiShortcut(MN_Career, TAB_Champs, -1, i); break;
case Games_Back: pSet->iMenu = MN1_Setup; break;
}
app->gui->toggleGui(false);
Expand Down
2 changes: 1 addition & 1 deletion src/game/Game_Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void App::update( float dt )
pg = alt ? 64 : ctrl ? 32 : 8;

if (isFocGui && !isTweak() && !bLoading &&
pSet->iMenu >= MN_Single && pSet->iMenu <= MN_Chall)
pSet->iMenu >= MN_Single && pSet->iMenu <= MN_Career)
{
if (keyDown) fDn += dt; else if (keyPgDown) fPgDn += dt; else
if (keyUp) fUp += dt; else if (keyPgUp) fPgUp += dt; else
Expand Down
1 change: 1 addition & 0 deletions src/game/Gui_Init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ void CGui::InitGui()
Btn("OpenEdTut", btnEdTut); Btn("OpenTransl", btnTransl); // mplr?


UpdWndTitle();
bGI = true; // gui inited, gui events can now save vals

LogO(Ogre::String(":::* Time Init Gui: ") + fToStr(ti.getMilliseconds(),0,3) + " ms");
Expand Down
49 changes: 28 additions & 21 deletions src/game/Gui_KeyPress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void App::keyPressed(const SDL_KeyboardEvent &arg)
gui->toggleGui(false); return;

case key(BACKSPACE): pSet->iMenu = MN1_Main;
gui->toggleGui(false); break;
gui->toggleGui(false); return;

case key(KP_ENTER):
case key(RETURN):
Expand Down Expand Up @@ -189,22 +189,22 @@ void App::keyPressed(const SDL_KeyboardEvent &arg)
gui->toggleGui(false); return;

case key(BACKSPACE): pSet->iMenu = MN1_Setup;
gui->toggleGui(false); break;
gui->toggleGui(false); return;

case key(KP_ENTER):
case key(RETURN):
switch (pSet->yGames)
{
case Games_Single: gui->SetNumPlayers(1); gui->GuiShortcut(MN_Single, TAB_Track); break;
case Games_SplitScreen: gui->SetNumPlayers(-2); gui->GuiShortcut(MN_Single, TAB_Split); break; // 👥
case Games_Multiplayer: gui->SetNumPlayers(1); gui->GuiShortcut(MN_Single, TAB_Multi); break; // 📡
case Games_Single: gui->GuiShortcut(MN_Single, TAB_Track); return;
case Games_SplitScreen: gui->GuiShortcut(MN_Single, TAB_Split); return; // 👥
case Games_Multiplayer: gui->GuiShortcut(MN_Single, TAB_Multi); return; // 📡

case Games_Tutorial: pSet->iMenu = MN_Tutorial; break;
case Games_Champ: pSet->iMenu = MN_Champ; break;
case Games_Challenge: pSet->iMenu = MN_Chall; break;
case Games_Tutorial: gui->GuiShortcut(MN_Tutorial, TAB_Champs); return;
case Games_Champ: gui->GuiShortcut(MN_Champ, TAB_Champs); return;
case Games_Challenge: gui->GuiShortcut(MN_Chall, TAB_Champs); return;

case Games_Collection: pSet->iMenu = MN_Collect; break;
case Games_Career: pSet->iMenu = MN_Career; break; // todo
case Games_Collection: gui->GuiShortcut(MN_Collect, TAB_Champs); break;
case Games_Career: gui->GuiShortcut(MN_Career, TAB_Champs); break;
case Games_Back: pSet->iMenu = MN1_Setup; break;
}
gui->toggleGui(false); return;
Expand Down Expand Up @@ -241,19 +241,21 @@ void App::keyPressed(const SDL_KeyboardEvent &arg)
//************************************************************************************************************
// shortcut keys for gui access (alt-Q,C,S,G,V,.. )
if (alt && !shift)
{ EMenu no = ctrl ? MN_Single : MN_NoCng; // ctrl sets game mode
auto gm = ctrl ? Games_Single : -1;
switch (skey) // alt- Shortcuts 🎛️
{
case key(Q): gui->GuiShortcut(MN_Single, TAB_Track); return; // Q Track 🏞️
case key(C): gui->GuiShortcut(MN_Single, TAB_Car); return; // C Car 🚗
case key(Q): gui->GuiShortcut(no, TAB_Track, -1, gm); return; // Q Track 🏞️
case key(C): gui->GuiShortcut(no, TAB_Car, -1, gm); return; // C Car 🚗
case key(W): gui->GuiShortcut(no, TAB_Setup, -1, gm); return; // W Setup 🔩

case key(W): gui->GuiShortcut(MN_Single, TAB_Setup); return; // W Setup 🔩
case key(G): gui->GuiShortcut(MN_Single, TAB_Split); return; // G SplitScreen 👥
case key(G): gui->GuiShortcut(MN_Single, TAB_Split, -1, Games_SplitScreen); return; // G SplitScreen 👥
case key(U): gui->GuiShortcut(MN_Single, TAB_Multi, -1, Games_Multiplayer); return; // U Multiplayer 📡

case key(J): gui->GuiShortcut(MN_Tutorial, TAB_Champs); return; // J Tutorials
case key(H): gui->GuiShortcut(MN_Champ, TAB_Champs); return; // H Champs 🏆
case key(L): gui->GuiShortcut(MN_Chall, TAB_Champs); return; // L Challs 🥇
case key(J): gui->GuiShortcut(MN_Tutorial, TAB_Champs, -1, Games_Tutorial); return; // J Tutorials
case key(H): gui->GuiShortcut(MN_Champ, TAB_Champs, -1, Games_Champ); return; // H Champs 🏆
case key(L): gui->GuiShortcut(MN_Chall, TAB_Champs, -1, Games_Challenge); return; // L Challs 🥇

case key(U): gui->GuiShortcut(MN_Single, TAB_Multi); return; // U Multiplayer 📡
case key(R): gui->GuiShortcut(MN_Replays, 1); return; // R Replays 📽️

case key(S): gui->GuiShortcut(MN_Options, TABo_Screen); return; // S Screen 🖥️
Expand All @@ -269,7 +271,7 @@ void App::keyPressed(const SDL_KeyboardEvent &arg)
case key(F): gui->GuiShortcut(MN_Materials, 1); return; // F Material editor 🔮
case key(K): gui->GuiShortcut(MN_Options, TABo_Tweak); return; // K -Tweak 🔧
default: break;
}
} }
//............................................................................................................
//>-- dev shortcuts, alt-shift - start Test Tracks 🏞️
if (pSet->dev_keys && alt && shift && !mClient)
Expand Down Expand Up @@ -469,6 +471,7 @@ void App::keyPressed(const SDL_KeyboardEvent &arg)
{
case MN_Replays: gui->btnRplLoad(0); break;
case MN_Single:
case MN_Tutorial: case MN_Champ: case MN_Chall: case MN_Collect:
if (mWndGame->getVisible())
switch (mTabsGame->getIndexSelected())
{
Expand All @@ -477,10 +480,14 @@ void App::keyPressed(const SDL_KeyboardEvent &arg)
case TAB_Split: gui->btnNewGame(0); break;
case TAB_Multi: gui->chatSendMsg(); break;
case TAB_Champs:
if (gui->isChallGui())
gui->btnChallStart(0);
if (gui->isCollectGui()) gui->btnCollectStart(0);
else if (gui->isChallGui()) gui->btnChallStart(0);
else gui->btnChampStart(0); break;
} break;
/*if (mWndGame->getVisible() && gui->isCollectGui() &&
mTabsGame->getIndexSelected() == TAB_Champs)
gui->btnCollectStart(0);
break;*/
}
else
if (mClient && !isFocGui) // show/hide players net wnd
Expand Down
43 changes: 29 additions & 14 deletions src/game/Gui_Util.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "pch.h"
#include "Def_Str.h"
#include "paths.h"
#include "BaseApp.h"
#include "CGame.h"
#include "CGui.h"
#include "CData.h"
Expand Down Expand Up @@ -148,8 +149,7 @@ void CGui::toggleGui(bool toggle)
app->mMainPanels[i]->setVisible(pSet->yMain == i);
for (int i=0; i < ciSetupBtns; ++i)
app->mMainSetupPanels[i]->setVisible(pSet->ySetup == i);
for (int i=0; i < ciGamesBtns; ++i)
app->mMainGamesPanels[i]->setVisible(pSet->yGames == i);
app->updPanGames();

// 1st center mouse
static bool first = true;
Expand All @@ -160,15 +160,17 @@ void CGui::toggleGui(bool toggle)
// LogO(String(":::* Time Gui upd: ") + fToStr(ti.getMilliseconds(),0,3) + " ms");
}

void CGui::tabGame(Tab, size_t)
void CGui::tabGame(Tab, size_t) // main game wnd tab change
{
UpdWndTitle();
//UpdWndTitle();
}

// 🪟 game window title and color
void CGui::UpdWndTitle()
{
const int mnu = pSet->iMenu;
if (mnu < MN_Single && mnu > MN_Career)
return; // not set
bool game = mnu == MN_Single, champ = mnu == MN_Champ,
tutor = mnu == MN_Tutorial, chall = mnu == MN_Chall,
collect = mnu == MN_Collect, career = mnu == MN_Career,
Expand Down Expand Up @@ -202,31 +204,43 @@ void CGui::UpdWndTitle()
}


// 🎛️ Gui Shortcut ⌨️ alt-letters
// 🎛️ Gui Shortcut ⌨️ alt-letters, main menu btns too
//.......................................................................................
void CGui::GuiShortcut(EMenu menu, int tab, int subtab)
void CGui::GuiShortcut(EMenu menu, int tab, int subtab, int game)
{
if (subtab == -1 && (!app->isFocGui || pSet->iMenu != menu))
subtab = -2; // cancel subtab cycling
if (subtab == -1 && (!app->isFocGui || (menu != MN_NoCng && pSet->iMenu != menu)))
subtab = -2; // cancel subtab cycling ?^

app->isFocGui = true;
pSet->iMenu = menu;

if (menu != MN_NoCng) // chg menu
{
pSet->iMenu = menu;

if (tab == TAB_Track || tab == TAB_Champs){
SetNumPlayers(1); app->updPanGames(game); }
if (tab == TAB_Split){
SetNumPlayers(-2); app->updPanGames(game); } // 👥
if (tab == TAB_Multi){
SetNumPlayers(1); app->updPanGames(game); } // 📡
}

TabPtr tabs = 0;
std::vector<TabControl*>* subt = 0;

switch (menu)
switch (pSet->iMenu)
{ case MN_Replays: tabs = app->mTabsRpl; break;
case MN_Help: tabs = app->mTabsHelp; break;
case MN_Options: tabs = app->mTabsOpts; subt = &vSubTabsOpts; break;
case MN_Materials: tabs = app->mTabsMat; subt = &vSubTabsMat; break;
default: tabs = app->mTabsGame; subt = &vSubTabsGame; break;
}
toggleGui(false);

if (tab < 0) return;
if (tab < 0)
{ toggleGui(false); return; }

size_t t = tabs->getIndexSelected();
tabs->setIndexSelected(tab);
toggleGui(false);

if (!subt) return;
TabControl* tc = (*subt)[tab]; if (!tc) return;
Expand All @@ -244,7 +258,8 @@ void CGui::GuiShortcut(EMenu menu, int tab, int subtab)

if (!tc->eventTabChangeSelect.empty())
tc->eventTabChangeSelect(tc, tc->getIndexSelected());
UpdWndTitle();
// UpdWndTitle();
toggleGui(false);
}

// close netw end
Expand Down
3 changes: 2 additions & 1 deletion src/game/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ enum EMenu
MN_Single, MN_Tutorial, MN_Champ, MN_Chall, // game, same window
MN_Collect, MN_Career,
MN_HowTo, MN_Replays, // other windows
MN_Help, MN_Options, MN_Materials // common
MN_Help, MN_Options, MN_Materials, // common
MN_NoCng // fake for GuiShortcut
};


Expand Down

0 comments on commit da60493

Please sign in to comment.