Skip to content

Commit

Permalink
UI: Rework interface visibility flag
Browse files Browse the repository at this point in the history
  • Loading branch information
IonAgorria committed May 14, 2024
1 parent 36e69e1 commit 84ab621
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 45 deletions.
28 changes: 17 additions & 11 deletions Source/UserInterface/GameShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ windowClientSize_(1024, 768)
GameActive = false;
GameContinue = true;
showKeysHelp_ = false;
interfaceShowFlag_ = true;

autoSwitchAITimer = 0;

Expand Down Expand Up @@ -893,7 +892,7 @@ void GameShell::Show()
if(showWireFrame_)
terRenderDevice->SetRenderState(RS_WIREFRAME,0);

if(interfaceShowFlag_)
if(_shellIconManager.interfaceShowFlag())
universe()->ShowInfo();

showWays();
Expand Down Expand Up @@ -1471,13 +1470,20 @@ bool GameShell::DebugKeyPressed(sKey& Key)
case VK_SPACE:
showWireFrame_ = !showWireFrame_;
break;
case VK_F8:
_shellIconManager.Toggle(GameActive);
interfaceShowFlag_ ^= 1;
break;
case VK_F8 | KBD_SHIFT:
if (!_shellIconManager.isCutSceneMode()) {
_shellIconManager.Toggle(GameActive);
_shellIconManager.toggleInterfaceShowFlag();
}
break;
case VK_F8:
if (!_shellIconManager.isCutSceneMode()) {
_shellIconManager.toggleInterfaceShowFlag();
}
break;
case VK_F7:
interfaceShowFlag_ ^= 1;
_shellIconManager.setCutSceneMode(!interfaceShowFlag_);
_shellIconManager.toggleInterfaceShowFlag();
_shellIconManager.setCutSceneMode(!_shellIconManager.interfaceShowFlag());
break;
case 'D':
universe()->select.explodeUnit();
Expand Down Expand Up @@ -1610,7 +1616,7 @@ void GameShell::KeyPressed(sKey& Key)
return;
}

if (gameShell->currentSingleProfile.getLastGameType() == UserSingleProfile::MULTIPLAYER) {
if (_shellIconManager.IsInterface() && gameShell->currentSingleProfile.getLastGameType() == UserSingleProfile::MULTIPLAYER) {
CChatInGameEditWindow* chatEdit = (CChatInGameEditWindow*) _shellIconManager.GetWnd(SQSH_INGAME_CHAT_EDIT_ID);
CChatInfoWindow* chatInfo = (CChatInfoWindow*) _shellIconManager.GetWnd(SQSH_CHAT_INFO_ID);
if (Key.fullkey == VK_INSERT) {
Expand Down Expand Up @@ -1706,7 +1712,7 @@ void GameShell::ControlPressed(int key)
int ctrl = g_controls_converter.control(key);
if (ctrl == CTRL_ESCAPE) {
//temp
if(_shellIconManager.IsInterface() && interfaceShowFlag_)
if(_shellIconManager.IsInterface() && _shellIconManager.interfaceShowFlag())
{
//if(MainMenuEnable)
EnterInMissionMenu();
Expand Down Expand Up @@ -2062,7 +2068,7 @@ void GameShell::MouseRightUnpressed(const Vect2f& pos)

void GameShell::MouseWheel(int delta)
{
if(!_bMenuMode && GameActive && !isScriptReelEnabled() && !(cameraMouseShift && mouseLeftPressed_)) {
if(!_bMenuMode && GameActive && _shellIconManager.IsInterface() && !isScriptReelEnabled() && !(cameraMouseShift && mouseLeftPressed_)) {
CChatInfoWindow* chatInfo = (CChatInfoWindow*) _shellIconManager.GetWnd(SQSH_CHAT_INFO_ID);
if (!chatInfo || !chatInfo->isVisible() || !chatInfo->HitTest(mousePosition().x+0.5f, mousePosition().y+0.5f)) {
terCamera->mouseWheel(delta);
Expand Down
2 changes: 0 additions & 2 deletions Source/UserInterface/GameShell.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ class GameShell

void rememberPlayerCamera(terPlayer* player, const char* triggerName);

bool interfaceShowFlag() const { return interfaceShowFlag_; }
bool showKeysHelp() const { return showKeysHelp_; }

cFont* debugFont() const { return debugFont_; }
Expand Down Expand Up @@ -313,7 +312,6 @@ class GameShell
Vect2f mousePressControl_;

bool alwaysRun_;
bool interfaceShowFlag_;
bool showKeysHelp_;
bool showWireFrame_;
int activePlayerID_;
Expand Down
2 changes: 1 addition & 1 deletion Source/UserInterface/Menu/MultiplayerCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ void GameShell::addStringToChatWindow(bool clanOnly, const std::string& newStrin
////////// Latency info ////////////

int updateLatencyInfoWindowQuant( float, float ) {
if (!_shellIconManager.getDesktop()) {
if (!_shellIconManager.IsInterface()) {
return 0;
}
CNetLatencyInfoWindow* wnd = safe_cast<CNetLatencyInfoWindow*>(_shellIconManager.GetWnd(SQSH_NET_LATENCY_INFO_ID));
Expand Down
52 changes: 28 additions & 24 deletions Source/UserInterface/PerimeterShellDisp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,7 @@ CShellIconManager::CShellIconManager()
initialMenu = SQSH_MM_START_SCR;

m_editMode = false;
interfaceShowFlag_ = true;

speechSound = 0;
resultMusicStarted = false;
Expand Down Expand Up @@ -946,10 +947,10 @@ CShellIconManager::~CShellIconManager()

void CShellIconManager::addChatString(const LocalizedText* newChatString) {
CChatInfoWindow* wnd;
if (cutSceneModeOn) {
wnd = (CChatInfoWindow*)controls[SQSH_CHAT_INFO_ID];
if (interfaceShowFlag()) {
wnd = (CChatInfoWindow*)GetWnd(SQSH_CHAT_INFO_ID);
} else {
wnd = (CChatInfoWindow*)GetWnd(SQSH_CHAT_INFO_ID);
wnd = (CChatInfoWindow*)controls[SQSH_CHAT_INFO_ID];
}
xassert(wnd);
if (wnd) {
Expand All @@ -961,10 +962,10 @@ void CShellIconManager::addChatString(const LocalizedText* newChatString) {

void CShellIconManager::showHintChat(const LocalizedText* text, int showTime) {
CChatInfoWindow* wnd;
if (cutSceneModeOn) {
wnd = (CChatInfoWindow*)controls[SQSH_CHAT_INFO_ID];
if (interfaceShowFlag()) {
wnd = (CChatInfoWindow*)GetWnd(SQSH_CHAT_INFO_ID);
} else {
wnd = (CChatInfoWindow*)GetWnd(SQSH_CHAT_INFO_ID);
wnd = (CChatInfoWindow*)controls[SQSH_CHAT_INFO_ID];
}
if (wnd) {
wnd->AddString(text);
Expand All @@ -978,10 +979,10 @@ void CShellIconManager::showHint(const char* text, int showTime, ActionTask::Typ
}

CHintWindow* wnd;
if (cutSceneModeOn) {
wnd = (CHintWindow*)controls[SQSH_HINT_ID];
if (interfaceShowFlag()) {
wnd = (CHintWindow*)GetWnd(SQSH_HINT_ID);
} else {
wnd = (CHintWindow*)GetWnd(SQSH_HINT_ID);
wnd = (CHintWindow*)controls[SQSH_HINT_ID];
}
xassert(wnd);
if (wnd) {
Expand Down Expand Up @@ -1080,10 +1081,10 @@ void CShellIconManager::fillTaskWnd() {
}

CTextWindow* wnd;
if (cutSceneModeOn) {
wnd = (CTextWindow*)controls[SQSH_MM_MISSION_TASK_TXT];
if (interfaceShowFlag()) {
wnd = (CTextWindow*)GetWnd(SQSH_MM_MISSION_TASK_TXT);
} else {
wnd = (CTextWindow*)GetWnd(SQSH_MM_MISSION_TASK_TXT);
wnd = (CTextWindow*)controls[SQSH_MM_MISSION_TASK_TXT];
}
xassert(wnd);
if (wnd) {
Expand Down Expand Up @@ -1479,10 +1480,11 @@ CShellWindow* CShellIconManager::GetWnd(int id)
// return 0;


if(getDesktop() && m_pDesktop->ID == id)
return m_pDesktop;
else
return controls[id];
if (getDesktop() && m_pDesktop->ID == id) {
return m_pDesktop;
} else {
return controls[id];
}

// return FindWnd(m_pDesktop, id);
}
Expand Down Expand Up @@ -2408,9 +2410,9 @@ void CShellIconManager::draw()
return;
}

if(!mt_interface_quant)
return;

if (!mt_interface_quant || !interfaceShowFlag()) {
return;
}

if(getDesktop())
{
Expand Down Expand Up @@ -2937,7 +2939,7 @@ void CShellIconManager::UpdateIcons()
if(_bDebugDisplayAllIcons)
return;

if(!getDesktop() || _bMenuMode)
if (!getDesktop() || _bMenuMode || !interfaceShowFlag())
return;

// if(!universe()->activePlayer())
Expand Down Expand Up @@ -3857,10 +3859,12 @@ void CShellIconManager::ClearSquadIconTable()
}

bool CtrlAction::actionPerformed() {
CShellWindow* wnd = _shellIconManager.GetWnd(controlID);
if (wnd) {
return wnd->actionPerformed( action.code, action.param );
}
if (_shellIconManager.IsInterface()) {
CShellWindow* wnd = _shellIconManager.GetWnd(controlID);
if (wnd) {
return wnd->actionPerformed(action.code, action.param);
}
}
return false;
}

Expand Down
6 changes: 5 additions & 1 deletion Source/UserInterface/PerimeterShellUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,8 @@ class CShellIconManager

CutSceneCommand cutSceneCommand;

bool interfaceShowFlag_;

public:
std::string hold;
std::string units;
Expand Down Expand Up @@ -1772,6 +1774,8 @@ class CShellIconManager
CShellWindow* GetModalWnd();
int IsFocusControl();
bool isInEditMode() const;
void toggleInterfaceShowFlag() { interfaceShowFlag_ = !interfaceShowFlag_; }
bool interfaceShowFlag() const { return interfaceShowFlag_; }

int OnLButtonDown(float x, float y);
int OnLButtonUp(float x, float y);
Expand Down Expand Up @@ -1801,7 +1805,7 @@ class CShellIconManager
m_dyn_queue.clear();
}
inline int IsEffect() { return m_fEffectTime>=0; }
inline int IsInterface(){ return getDesktop() != 0;}
inline int IsInterface(){ return getDesktop() != nullptr;}

void ShowControls(int bShow, const ShellControlID ids[], int numIds);

Expand Down
11 changes: 5 additions & 6 deletions Source/UserInterface/ShellLogDisp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void CShellLogicDispatcher::quant(bool game_active)

if(game_active)
{
if ((isAltPressed() || alwaysShowLifeBars) && !_bMenuMode && !gameShell->isScriptReelEnabled() && !gameShell->isCutSceneMode()) {
if ((isAltPressed() || alwaysShowLifeBars) && !_bMenuMode && !gameShell->isScriptReelEnabled() && _shellIconManager.interfaceShowFlag()) {
for (int i = 0; i < universe()->Players.size(); i++) {
universe()->Players[i]->mark();
}
Expand Down Expand Up @@ -295,10 +295,8 @@ void CShellLogicDispatcher::draw()
}
#endif // PERIMETER_DEBUG

if(_shellIconManager.IsInterface())
{
if(!_bMenuMode)
m_hScene->Draw(m_hCamera);
if (_shellIconManager.IsInterface() && !_bMenuMode && _shellIconManager.interfaceShowFlag()) {
m_hScene->Draw(m_hCamera);
}
}

Expand Down Expand Up @@ -568,7 +566,8 @@ int CShellLogicDispatcher::OnLButtonDblClk(float x, float y)
if (_pUnitHover()) {
terPlayer* pPlayer = universe()->activePlayer();
terFrame* fr = dynamic_cast<terFrame*>(_pUnitHover());
if (fr && pPlayer && _pUnitHover->playerID() == pPlayer->playerID() && _shellIconManager.GetWnd(SQSH_SELPANEL_FRAME_INSTALL_ID)->isEnabled()) {
if (fr && pPlayer && _pUnitHover->playerID() == pPlayer->playerID()
&& _shellIconManager.IsInterface() && _shellIconManager.GetWnd(SQSH_SELPANEL_FRAME_INSTALL_ID)->isEnabled()) {
if (!fr->attached() && fr->basementReady()) {
universe()->makeCommand(COMMAND_ID_FRAME_ATTACH,0);
}
Expand Down

0 comments on commit 84ab621

Please sign in to comment.