Skip to content

Commit a3a11df

Browse files
Look up PersistentWindowSettings only once
1 parent 8712b76 commit a3a11df

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

libs/s25main/ingameWindows/IngameWindow.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ IngameWindow::IngameWindow(unsigned id, const DrawPoint& pos, const Extent& size
4343
contentOffsetEnd.x = LOADER.GetImageN("resource", 39)->getWidth(); // right border
4444
contentOffsetEnd.y = LOADER.GetImageN("resource", 40)->getHeight(); // bottom bar
4545

46+
const auto it = SETTINGS.windows.persistentSettings.find(GetGUIID());
47+
windowSettings_ = (it == SETTINGS.windows.persistentSettings.cend() ? nullptr : &it->second);
48+
4649
// For compatibility we treat the given height as the window height, not the content height
4750
// First we have to make sure the size is not to small
4851
Window::Resize(elMax(contentOffset + contentOffsetEnd, GetSize()));
@@ -54,9 +57,8 @@ IngameWindow::IngameWindow(unsigned id, const DrawPoint& pos, const Extent& size
5457
// Load last position or center the window
5558
if(pos == posLastOrCenter)
5659
{
57-
const auto windowSettings = SETTINGS.windows.persistentSettings.find(GetGUIID());
58-
if(windowSettings != SETTINGS.windows.persistentSettings.cend() && windowSettings->second.lastPos.isValid())
59-
SetPos(windowSettings->second.lastPos);
60+
if(windowSettings_ && windowSettings_->lastPos.isValid())
61+
SetPos(windowSettings_->lastPos);
6062
else
6163
MoveToCenter();
6264
} else if(pos == posCenter)
@@ -111,11 +113,8 @@ void IngameWindow::SetPos(DrawPoint newPos)
111113
newPos.y = screenSize.y - GetSize().y;
112114

113115
// if possible save the position to settings
114-
const auto windowSettings = SETTINGS.windows.persistentSettings.find(GetGUIID());
115-
if(windowSettings != SETTINGS.windows.persistentSettings.cend())
116-
{
117-
windowSettings->second.lastPos = newPos;
118-
}
116+
if(windowSettings_)
117+
windowSettings_->lastPos = newPos;
119118

120119
Window::SetPos(newPos);
121120
}
@@ -361,11 +360,8 @@ bool IngameWindow::IsMessageRelayAllowed() const
361360

362361
void IngameWindow::SaveOpenStatus(bool isOpen) const
363362
{
364-
auto windowSettings = SETTINGS.windows.persistentSettings.find(GetGUIID());
365-
if(windowSettings != SETTINGS.windows.persistentSettings.cend())
366-
{
367-
windowSettings->second.isOpen = isOpen;
368-
}
363+
if(windowSettings_)
364+
windowSettings_->isOpen = isOpen;
369365
}
370366

371367
Rect IngameWindow::GetButtonBounds(IwButton btn) const

libs/s25main/ingameWindows/IngameWindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
class glArchivItem_Bitmap;
1414
class MouseCoords;
15+
struct PersistentWindowSettings;
1516
template<typename T>
1617
struct Point;
1718

@@ -126,4 +127,5 @@ class IngameWindow : public Window
126127
bool isMoving;
127128
CloseBehavior closeBehavior_;
128129
helpers::EnumArray<ButtonState, IwButton> buttonStates_;
130+
PersistentWindowSettings* windowSettings_;
129131
};

0 commit comments

Comments
 (0)