Skip to content

Commit a25c1fa

Browse files
Allow excluding windows from being closed via Esc
Add a "pin" function to ingame windows, toggleable by clicking the shade (aka. minimize) button while holding shift. Pinned windows will be excluded from being closed by the window manager when hitting the escape key.
1 parent 60499d9 commit a25c1fa

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

libs/s25main/WindowManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ void WindowManager::RelayKeyboardMessage(KeyboardMsgHandler msg, const KeyEvent&
135135
if(ke.kt == KeyType::Escape || (ke.c == 'w' && ke.alt))
136136
{
137137
// Find one which isn't yet marked for closing so multiple ESC in between draw calls can close multiple windows
138-
const auto itActiveWnd =
139-
std::find_if(windows.rbegin(), windows.rend(), [](const auto& wnd) { return !wnd->ShouldBeClosed(); });
138+
const auto itActiveWnd = std::find_if(
139+
windows.rbegin(), windows.rend(), [](const auto& wnd) { return !wnd->ShouldBeClosed() && !wnd->IsPinned(); });
140140
if(itActiveWnd != windows.rend() && (*itActiveWnd)->getCloseBehavior() != CloseBehavior::Custom)
141141
(*itActiveWnd)->Close();
142142
} else if(!CALL_MEMBER_FN(*windows.back(), msg)(ke)) // send to active window

libs/s25main/ingameWindows/IngameWindow.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "ogl/glArchivItem_Bitmap.h"
1616
#include "ogl/glFont.h"
1717
#include "gameData/const_gui_ids.h"
18+
#include "s25util/colors.h"
1819
#include "s25util/error.h"
1920
#include <algorithm>
2021
#include <utility>
@@ -180,8 +181,15 @@ void IngameWindow::MouseLeftUp(const MouseCoords& mc)
180181
Close();
181182
else
182183
{
183-
SetMinimized(!IsMinimized());
184-
LOADER.GetSoundN("sound", 113)->Play(255, false);
184+
if(VIDEODRIVER.GetModKeyState().shift)
185+
{
186+
SetPinned(!IsPinned());
187+
LOADER.GetSoundN("sound", 111)->Play(255, false);
188+
} else
189+
{
190+
SetMinimized(!IsMinimized());
191+
LOADER.GetSoundN("sound", 113)->Play(255, false);
192+
}
185193
}
186194
}
187195
}
@@ -256,7 +264,13 @@ void IngameWindow::Draw_()
256264
if(closeBehavior_ != CloseBehavior::Custom)
257265
LOADER.GetImageN("resource", ids[0][buttonState[0]])->DrawFull(GetPos());
258266
if(!IsModal())
267+
{
259268
LOADER.GetImageN("resource", ids[1][buttonState[1]])->DrawFull(GetPos() + DrawPoint(GetSize().x - 16, 0));
269+
if(IsPinned())
270+
LOADER.GetImageN("resource", ids[1][ButtonState::Hover])
271+
->DrawPart(Rect(GetPos() + DrawPoint(GetSize().x - 13, 3), Extent(10, 10)), DrawPoint(3, 3),
272+
SetAlpha(COLOR_RED, 0xFF / 2));
273+
}
260274

261275
// The title bar
262276
unsigned titleIndex;

libs/s25main/ingameWindows/IngameWindow.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class IngameWindow : public Window
7171
/// ist das Fenster minimiert?
7272
bool IsMinimized() const { return isMinimized_; }
7373

74+
void SetPinned(bool pinned = true) { isPinned_ = pinned; }
75+
bool IsPinned() const { return isPinned_; }
76+
7477
CloseBehavior getCloseBehavior() const { return closeBehavior_; }
7578

7679
/// Modal windows cannot be minimized, are always active and stay on top of non-modal ones
@@ -117,6 +120,7 @@ class IngameWindow : public Window
117120
bool isModal_;
118121
bool closeme;
119122
bool isMinimized_;
123+
bool isPinned_ = false;
120124
bool isMoving;
121125
CloseBehavior closeBehavior_;
122126
};

0 commit comments

Comments
 (0)