forked from Mirrors/openclonk
GUI: Remove superfluous checks for IsGUIValid() and GetScreenS()
Some of them should rather check whether the user has closed the window, though.
parent
75c2b21ee8
commit
0d59854c5c
|
@ -1810,8 +1810,6 @@ void C4Player::CountControl(ControlType eType, int32_t iID, int32_t iCntAdd)
|
|||
|
||||
void C4Player::ExecMsgBoardQueries()
|
||||
{
|
||||
// query now possible?
|
||||
if (!C4GUI::IsGUIValid()) return;
|
||||
// already active?
|
||||
if (::MessageInput.IsTypeIn()) return;
|
||||
// find an un-evaluated query
|
||||
|
|
|
@ -185,11 +185,7 @@ bool C4DownloadDlg::DownloadFile(const char *szDLType, C4GUI::Screen *pScreen, c
|
|||
C4DownloadDlg *pDlg = new C4DownloadDlg(szDLType);
|
||||
if (!pDlg->ShowModal(pScreen, szURL, szSaveAsFilename))
|
||||
{
|
||||
// an error occurred. Did the GUI get deleted?
|
||||
if (!C4GUI::IsGUIValid())
|
||||
// then the dlg got deleted as well, and we should get out ASAP
|
||||
return false;
|
||||
// otherwise, show an appropriate error
|
||||
// show an appropriate error
|
||||
const char *szError = pDlg->GetError();
|
||||
if (!szError || !*szError) szError = LoadResStr("IDS_PRC_UNKOWNERROR");
|
||||
StdStrBuf sError;
|
||||
|
|
|
@ -436,7 +436,7 @@ bool C4DefinitionSelDlg::SelectDefinitions(C4GUI::Screen *pOnScreen, StdStrBuf *
|
|||
{
|
||||
pSelection->Copy(pDlg->GetSelection(pSelection->getData(), true));
|
||||
}
|
||||
if (C4GUI::IsGUIValid()) delete pDlg;
|
||||
delete pDlg;
|
||||
return fResult;
|
||||
}
|
||||
|
||||
|
@ -668,6 +668,6 @@ bool C4PortraitSelDlg::SelectPortrait(C4GUI::Screen *pOnScreen, StdStrBuf *pSele
|
|||
*pfSetPicture = pDlg->IsSetPicture();
|
||||
*pfSetBigIcon = pDlg->IsSetBigIcon();
|
||||
}
|
||||
if (C4GUI::IsGUIValid()) delete pDlg;
|
||||
delete pDlg;
|
||||
return fResult;
|
||||
}
|
||||
|
|
|
@ -144,8 +144,7 @@ namespace C4GUI
|
|||
pParent->RemoveElement(this);
|
||||
else if (this != Screen::GetScreenS())
|
||||
// always ensure removal from screen!
|
||||
if (Screen::GetScreenS())
|
||||
Screen::GetScreenS()->RemoveElement(this);
|
||||
Screen::GetScreenS()->RemoveElement(this);
|
||||
}
|
||||
|
||||
void Element::RemoveElement(Element *pChild)
|
||||
|
@ -155,10 +154,9 @@ namespace C4GUI
|
|||
pParent->RemoveElement(pChild);
|
||||
else if (this != Screen::GetScreenS())
|
||||
// always ensure removal from screen!
|
||||
if (Screen::GetScreenS())
|
||||
// but not if this is the context menu, to avoid endless flip-flop!
|
||||
if (!IsMenu())
|
||||
Screen::GetScreenS()->RemoveElement(pChild);
|
||||
// but not if this is the context menu, to avoid endless flip-flop!
|
||||
if (!IsMenu())
|
||||
Screen::GetScreenS()->RemoveElement(pChild);
|
||||
}
|
||||
|
||||
void Element::UpdateSize()
|
||||
|
@ -740,12 +738,9 @@ namespace C4GUI
|
|||
|
||||
bool Screen::Execute()
|
||||
{
|
||||
if (!IsGUIValid()) return false;
|
||||
// process messages
|
||||
if (!Application.FlushMessages())
|
||||
return false;
|
||||
// check status
|
||||
if (!IsGUIValid()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -932,8 +927,6 @@ namespace C4GUI
|
|||
{
|
||||
// Okay; do input
|
||||
pDlg->MouseInput(Mouse, iButton, fX - rcDlgBounds.x - iOffX, fY - rcDlgBounds.y - iOffY, dwKeyParam);
|
||||
// dlgs may destroy GUI
|
||||
if (!IsGUIValid()) return false;
|
||||
// CAUTION: pDlg may be invalid now!
|
||||
// set processed-flag manually
|
||||
fProcessed = true;
|
||||
|
@ -947,8 +940,6 @@ namespace C4GUI
|
|||
}
|
||||
}
|
||||
}
|
||||
// check valid GUI; might be destroyed by mouse input
|
||||
if (!IsGUIValid()) return false;
|
||||
}
|
||||
|
||||
// check if MouseOver has changed
|
||||
|
|
|
@ -2714,21 +2714,20 @@ namespace C4GUI
|
|||
};
|
||||
|
||||
// shortcut for check whether GUI is active
|
||||
inline bool IsGUIValid() { return !!Screen::GetScreenS(); }
|
||||
inline bool IsActive() { return Screen::GetScreenS() && Screen::GetScreenS()->IsActive(); }
|
||||
inline bool IsExclusive() { return Screen::GetScreenS() && Screen::GetScreenS()->IsExclusive(); }
|
||||
inline bool IsActive() { return Screen::GetScreenS()->IsActive(); }
|
||||
inline bool IsExclusive() { return Screen::GetScreenS()->IsExclusive(); }
|
||||
|
||||
// shortcut for GUI screen size
|
||||
inline int32_t GetScreenWdt() { Screen *pScreen = Screen::GetScreenS(); return pScreen ? pScreen->GetBounds().Wdt : Config.Graphics.ResX; }
|
||||
inline int32_t GetScreenHgt() { Screen *pScreen = Screen::GetScreenS(); return pScreen ? pScreen->GetBounds().Hgt : Config.Graphics.ResY; }
|
||||
inline int32_t GetScreenWdt() { return Screen::GetScreenS()->GetBounds().Wdt; }
|
||||
inline int32_t GetScreenHgt() { return Screen::GetScreenS()->GetBounds().Hgt; }
|
||||
|
||||
// sound effect in GUI: Only if enabled
|
||||
void GUISound(const char *szSound);
|
||||
|
||||
// Zoom
|
||||
inline float GetZoom() { Screen *s=Screen::GetScreenS(); return s ? s->GetZoom() : 1.0f; }
|
||||
inline float GetZoom() { return Screen::GetScreenS()->GetZoom(); }
|
||||
inline void MouseMove(int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyParam, class C4Viewport *pVP) // pVP specified for console mode viewports only
|
||||
{ Screen *s=Screen::GetScreenS(); if(s) s->MouseMove(iButton, iX, iY, dwKeyParam, pVP); }
|
||||
{ Screen::GetScreenS()->MouseMove(iButton, iX, iY, dwKeyParam, pVP); }
|
||||
|
||||
extern Screen TheScreen;
|
||||
} // end of namespace
|
||||
|
|
|
@ -853,11 +853,9 @@ namespace C4GUI
|
|||
// dialog idle proc
|
||||
OnIdle();
|
||||
// handle messages - this may block until the next timer
|
||||
if (!Application.ScheduleProcs() || !IsGUIValid())
|
||||
if (!Application.ScheduleProcs())
|
||||
return false; // game GUI and lobby will deleted in Game::Clear()
|
||||
}
|
||||
// Idle proc may have done something nasty
|
||||
if (!IsGUIValid()) return false;
|
||||
}
|
||||
// return whether dlg was OK
|
||||
return fOK;
|
||||
|
@ -869,7 +867,7 @@ namespace C4GUI
|
|||
if (!Application.ScheduleProcs(0))
|
||||
return false;
|
||||
// check status
|
||||
if (!IsGUIValid() || !fShow) return false;
|
||||
if (!fShow) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -878,7 +876,7 @@ namespace C4GUI
|
|||
// execute
|
||||
if (Execute()) return true;
|
||||
// delete self if closed
|
||||
if (IsGUIValid()) delete this;
|
||||
delete this;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -900,7 +898,7 @@ namespace C4GUI
|
|||
bool Dialog::FadeIn(Screen *pOnScreen)
|
||||
{
|
||||
// default screen
|
||||
if (!pOnScreen) if (!(pOnScreen = Screen::GetScreenS())) return false;
|
||||
if (!pOnScreen) pOnScreen = Screen::GetScreenS();
|
||||
// fade in there
|
||||
pOnScreen->ShowDialog(this, true);
|
||||
iFade = 0;
|
||||
|
@ -1251,8 +1249,6 @@ namespace C4GUI
|
|||
ProgressDialog *pDlg = new ProgressDialog(szMessage, szCaption, iMaxProgress, iInitialProgress, icoIcon);
|
||||
// show it
|
||||
if (!pDlg->Show(this, true)) { delete pDlg; return false; }
|
||||
// do not return invalid pointer if GUI got deleted (whil eshowing the progress bar Dlg; maybe some stupid stuff in OnShow)
|
||||
if (!IsGUIValid()) return NULL;
|
||||
// return dlg pointer
|
||||
return pDlg;
|
||||
}
|
||||
|
@ -1271,8 +1267,6 @@ namespace C4GUI
|
|||
if (!pDlg->Show(this, true)) { delete pDlg; return false; }
|
||||
// wait until it is closed
|
||||
bool fResult = pDlg->DoModal();
|
||||
// free dlg if this class is still valid (may have been deleted in game clear)
|
||||
if (!IsGUIValid()) return false;
|
||||
if (fDestruct) delete pDlg;
|
||||
// return result
|
||||
return fResult;
|
||||
|
|
|
@ -252,8 +252,6 @@ namespace C4GUI
|
|||
{
|
||||
// do OnFinishInput callback and process result - returns whether pasting operation should be continued
|
||||
InputResult eResult = OnFinishInput(fPasting, fPastingMore);
|
||||
// safety...
|
||||
if (!IsGUIValid()) return false;
|
||||
switch (eResult)
|
||||
{
|
||||
case IR_None: // do nothing and continue pasting
|
||||
|
|
|
@ -161,7 +161,7 @@ C4GUI::Edit::InputResult C4ChatInputDialog::OnChatInput(C4GUI::Edit *edt, bool f
|
|||
// reroute to message input class
|
||||
::MessageInput.ProcessInput(szInputText);
|
||||
// safety: message board commands may do strange things
|
||||
if (!C4GUI::IsGUIValid() || this!=pInstance) return C4GUI::Edit::IR_Abort;
|
||||
if (this!=pInstance) return C4GUI::Edit::IR_Abort;
|
||||
// select all text to be removed with next keypress
|
||||
// just for pasting mode; usually the dlg will be closed now anyway
|
||||
pEdt->SelectAll();
|
||||
|
@ -289,14 +289,13 @@ bool C4MessageInput::CloseTypeIn()
|
|||
{
|
||||
// close dialog if present and valid
|
||||
C4ChatInputDialog *pDlg = GetTypeIn();
|
||||
if (!pDlg || !C4GUI::IsGUIValid()) return false;
|
||||
if (!pDlg) return false;
|
||||
pDlg->Close(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool C4MessageInput::StartTypeIn(bool fObjInput, C4Object *pObj, bool fUpperCase, bool fTeam, int32_t iPlr, const StdStrBuf &rsInputQuery)
|
||||
{
|
||||
if (!C4GUI::IsGUIValid()) return false;
|
||||
// close any previous
|
||||
if (IsTypeIn()) CloseTypeIn();
|
||||
// start new
|
||||
|
@ -313,8 +312,6 @@ bool C4MessageInput::KeyStartTypeIn(bool fTeam)
|
|||
|
||||
bool C4MessageInput::ToggleTypeIn()
|
||||
{
|
||||
// safety
|
||||
if (!C4GUI::IsGUIValid()) return false;
|
||||
// toggle off?
|
||||
if (IsTypeIn())
|
||||
{
|
||||
|
@ -330,7 +327,7 @@ bool C4MessageInput::ToggleTypeIn()
|
|||
bool C4MessageInput::IsTypeIn()
|
||||
{
|
||||
// check GUI and dialog
|
||||
return C4GUI::IsGUIValid() && C4ChatInputDialog::IsShown();
|
||||
return C4ChatInputDialog::IsShown();
|
||||
}
|
||||
|
||||
bool C4MessageInput::ProcessInput(const char *szText)
|
||||
|
|
|
@ -1241,8 +1241,6 @@ void C4PlayerInfoListBox::SetClientSoundIcon(int32_t iForClientID)
|
|||
|
||||
C4PlayerInfoListBox::ListItem *C4PlayerInfoListBox::GetPlayerListItem(ListItem::ID::IDType eType, int32_t id)
|
||||
{
|
||||
// safety
|
||||
if (!C4GUI::IsGUIValid()) return NULL;
|
||||
ListItem::ID idSearch(eType, id);
|
||||
// search through listbox
|
||||
for (C4GUI::Element *pEItem = GetFirst(); pEItem; pEItem = pEItem->GetNext())
|
||||
|
@ -1283,9 +1281,6 @@ static bool fPlayerListUpdating=false;
|
|||
|
||||
void C4PlayerInfoListBox::Update()
|
||||
{
|
||||
// safety
|
||||
if (!C4GUI::IsGUIValid()) return;
|
||||
|
||||
if (fPlayerListUpdating) return;
|
||||
fPlayerListUpdating = true;
|
||||
|
||||
|
|
|
@ -261,8 +261,7 @@ void C4Scoreboard::InvalidateRows()
|
|||
|
||||
void C4Scoreboard::DoDlgShow(int32_t iChange, bool fUserToggle)
|
||||
{
|
||||
// safety: Only if GUI loaded, and GUI already in exclusive mode
|
||||
if (!C4GUI::IsGUIValid() || ::pGUI->IsExclusive()) return;
|
||||
if (::pGUI->IsExclusive()) return;
|
||||
// update dlg show
|
||||
iDlgShow += iChange;
|
||||
if (!fUserToggle)
|
||||
|
@ -285,8 +284,7 @@ void C4Scoreboard::DoDlgShow(int32_t iChange, bool fUserToggle)
|
|||
|
||||
void C4Scoreboard::HideDlg()
|
||||
{
|
||||
// safety: Only if GUI loaded, and GUI already in exclusive mode
|
||||
if (!C4GUI::IsGUIValid() || ::pGUI->IsExclusive()) return;
|
||||
if (::pGUI->IsExclusive()) return;
|
||||
// hide scoreboard if it was active
|
||||
if (pDlg) pDlg->Close(false);
|
||||
}
|
||||
|
|
|
@ -1149,13 +1149,10 @@ bool C4StartupOptionsDlg::TryNewResolution(int32_t iResX, int32_t iResY)
|
|||
if (!pScreen->ShowModalDlg(pConfirmDlg, true))
|
||||
{
|
||||
// abort: Restore screen, if this was not some program abort
|
||||
if (C4GUI::IsGUIValid())
|
||||
if (Application.SetVideoMode(iOldResX, iOldResY, Config.Graphics.BitDepth, Config.Graphics.Monitor,!Config.Graphics.Windowed))
|
||||
{
|
||||
if (Application.SetVideoMode(iOldResX, iOldResY, Config.Graphics.BitDepth, Config.Graphics.Monitor,!Config.Graphics.Windowed))
|
||||
{
|
||||
if (iNewFontSize != iOldFontSize) Application.SetGameFont(Config.General.RXFontName, iOldFontSize);
|
||||
RecreateDialog(false);
|
||||
}
|
||||
if (iNewFontSize != iOldFontSize) Application.SetGameFont(Config.General.RXFontName, iOldFontSize);
|
||||
RecreateDialog(false);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -274,12 +274,10 @@ bool C4UpdateDlg::CheckForUpdates(C4GUI::Screen *pScreen, bool fAutomatic)
|
|||
// Get current update url from server
|
||||
StdStrBuf UpdateURL;
|
||||
C4GUI::Dialog *pWaitDlg = NULL;
|
||||
if (C4GUI::IsGUIValid())
|
||||
{
|
||||
pWaitDlg = new C4GUI::MessageDialog(LoadResStr("IDS_MSG_LOOKINGFORUPDATES"), LoadResStr("IDS_TYPE_UPDATE"), C4GUI::MessageDialog::btnAbort, C4GUI::Ico_Ex_Update, C4GUI::MessageDialog::dsRegular);
|
||||
pWaitDlg->SetDelOnClose(false);
|
||||
pScreen->ShowDialog(pWaitDlg, false);
|
||||
}
|
||||
pWaitDlg = new C4GUI::MessageDialog(LoadResStr("IDS_MSG_LOOKINGFORUPDATES"), LoadResStr("IDS_TYPE_UPDATE"), C4GUI::MessageDialog::btnAbort, C4GUI::Ico_Ex_Update, C4GUI::MessageDialog::dsRegular);
|
||||
pWaitDlg->SetDelOnClose(false);
|
||||
pScreen->ShowDialog(pWaitDlg, false);
|
||||
|
||||
C4Network2UpdateClient UpdateClient;
|
||||
bool fSuccess = false, fAborted = false;
|
||||
StdStrBuf strVersion; strVersion.Format("%d.%d.%d.%d", C4XVER1, C4XVER2, C4XVER3, C4XVER4);
|
||||
|
@ -294,13 +292,13 @@ bool C4UpdateDlg::CheckForUpdates(C4GUI::Screen *pScreen, bool fAutomatic)
|
|||
// wait, check for program abort
|
||||
if (!Application.ScheduleProcs()) { fAborted = true; break; }
|
||||
// check for dialog close
|
||||
if (pWaitDlg) if (!C4GUI::IsGUIValid() || !pWaitDlg->IsShown()) { fAborted = true; break; }
|
||||
if (pWaitDlg) if (!pWaitDlg->IsShown()) { fAborted = true; break; }
|
||||
}
|
||||
if (!fAborted) fSuccess = UpdateClient.GetUpdateURL(&UpdateURL);
|
||||
Application.InteractiveThread.RemoveProc(&UpdateClient);
|
||||
UpdateClient.SetNotify(NULL);
|
||||
}
|
||||
if (C4GUI::IsGUIValid() && pWaitDlg) delete pWaitDlg;
|
||||
delete pWaitDlg;
|
||||
// User abort
|
||||
if (fAborted)
|
||||
{
|
||||
|
|
|
@ -707,7 +707,7 @@ StdStrBuf C4Network2::QueryClientPassword()
|
|||
pInputDlg->SetDelOnClose(false);
|
||||
if (!::pGUI->ShowModalDlg(pInputDlg, false))
|
||||
{
|
||||
if (C4GUI::IsGUIValid()) delete pInputDlg;
|
||||
delete pInputDlg;
|
||||
return StdStrBuf();
|
||||
}
|
||||
// copy to buffer
|
||||
|
|
|
@ -496,8 +496,6 @@ void C4Network2ClientListDlg::Update()
|
|||
|
||||
bool C4Network2ClientListDlg::Toggle()
|
||||
{
|
||||
// safety
|
||||
if (!C4GUI::IsGUIValid()) return false;
|
||||
// toggle off?
|
||||
if (pInstance) { pInstance->Close(true); return true; }
|
||||
// toggle on!
|
||||
|
@ -940,7 +938,7 @@ C4ChartDialog::C4ChartDialog() : Dialog(DialogWidth, DialogHeight, LoadResStr("I
|
|||
void C4ChartDialog::AddChart(const StdStrBuf &rszName)
|
||||
{
|
||||
// get graph by name
|
||||
if (!Game.pNetworkStatistics || !pChartTabular || !C4GUI::IsGUIValid()) return;
|
||||
if (!Game.pNetworkStatistics || !pChartTabular) return;
|
||||
bool fOwnGraph = false;
|
||||
C4Graph *pGraph = Game.pNetworkStatistics->GetGraphByName(rszName, fOwnGraph);
|
||||
if (!pGraph) return;
|
||||
|
@ -955,7 +953,6 @@ void C4ChartDialog::AddChart(const StdStrBuf &rszName)
|
|||
|
||||
void C4ChartDialog::Toggle()
|
||||
{
|
||||
if (!C4GUI::IsGUIValid()) return;
|
||||
// close if open
|
||||
if (pChartDlg) { pChartDlg->Close(false); return; }
|
||||
// otherwise, open
|
||||
|
|
|
@ -385,10 +385,7 @@ bool C4Network2IRCClient::Join(const char *szChannel)
|
|||
const char* message = LoadResStr("IDS_ERR_CHANNELNOTALLOWED");
|
||||
PushMessage(MSG_Status, "", "", message);
|
||||
SetError("Joining this channel not allowed");
|
||||
if (C4GUI::Screen* screen = C4GUI::Screen::GetScreenS())
|
||||
{
|
||||
Application.InteractiveThread.ThreadPostAsync(boost::bind(&C4GUI::Screen::ShowMessage, screen,message, LoadResStr("IDS_DLG_CHAT"), boost::cref(C4GUI::Ico_Error), static_cast<int32_t* const &>(0)));
|
||||
}
|
||||
Application.InteractiveThread.ThreadPostAsync(boost::bind(&C4GUI::Screen::ShowMessage, ::pGUI, message, LoadResStr("IDS_DLG_CHAT"), boost::cref(C4GUI::Ico_Error), static_cast<int32_t* const &>(0)));
|
||||
return false;
|
||||
}
|
||||
return Send("JOIN", szChannel);
|
||||
|
|
Loading…
Reference in New Issue