Skip to content

Commit

Permalink
Make the /chart and F4 dialogs closable via Escape
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmitti committed Sep 17, 2019
1 parent 140903f commit d6b1353
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/C4Network2Dialogs.cpp
Expand Up @@ -428,6 +428,20 @@ void C4Network2ClientListBox::Update()

// C4Network2ClientListDlg

namespace
{
C4KeyBinding* registerStrongerEscape(C4GUI::Dialog* dialog)
{
C4CustomKey::CodeList keys;
keys.push_back(C4KeyCodeEx(K_ESCAPE));
if (Config.Controls.GamepadGuiControl)
{
keys.push_back(C4KeyCodeEx(KEY_Gamepad(0, KEY_JOY_AnyHighButton)));
}
return new C4KeyBinding(keys, "GUIDialogAbort", KEYSCOPE_Fullscreen, new C4GUI::DlgKeyCB<C4GUI::Dialog>(*dialog, &C4GUI::Dialog::KeyEscape), C4CustomKey::PRIO_Dlg);
}
}

// singleton
C4Network2ClientListDlg *C4Network2ClientListDlg::pInstance = nullptr;

Expand All @@ -450,6 +464,8 @@ C4Network2ClientListDlg::C4Network2ClientListDlg()
AddElement(pListBox = new C4Network2ClientListBox(caAll.GetAll(), false));
// create status label
AddElement(pStatusLabel = new C4GUI::Label("", rcStatus));

keyEscape.reset(registerStrongerEscape(this));
// add timer
pSec1Timer = new C4Sec1TimerCallback<C4Network2ClientListDlg>(this);
// initial update
Expand Down Expand Up @@ -894,6 +910,8 @@ C4ChartDialog::C4ChartDialog() : Dialog(DialogWidth, DialogHeight, LoadResStr("I
AddChart(StdStrBuf("Pings"));
AddChart(StdStrBuf("Control"));
AddChart(StdStrBuf("APM"));

keyEscape.reset(registerStrongerEscape(this));
}

void C4ChartDialog::AddChart(const StdStrBuf &rszName)
Expand Down
4 changes: 4 additions & 0 deletions src/C4Network2Dialogs.h
Expand Up @@ -24,6 +24,8 @@
#include "C4Scenario.h"
#include "C4Network2Res.h"

#include <memory>

// dialog showing info about a connected client
class C4Network2ClientDlg : public C4GUI::InfoDialog
{
Expand Down Expand Up @@ -167,6 +169,7 @@ class C4Network2ClientListBox : public C4GUI::ListBox
class C4Network2ClientListDlg : public C4GUI::Dialog
{
private:
std::unique_ptr<C4KeyBinding> keyEscape;
C4Sec1TimerCallback<C4Network2ClientListDlg> *pSec1Timer; // engine timer hook for updates
class C4GameOptionsList *pGameOptions;
C4GUI::Label *pStatusLabel;
Expand Down Expand Up @@ -253,6 +256,7 @@ class C4ChartDialog : public C4GUI::Dialog
{
private:
C4GUI::Tabular *pChartTabular;
std::unique_ptr<C4KeyBinding> keyEscape;

// singleton-stuff
static C4ChartDialog *pChartDlg;
Expand Down

0 comments on commit d6b1353

Please sign in to comment.