diff --git a/external/turtle b/external/turtle index b9a1a4a4b..0dd0dfa15 160000 --- a/external/turtle +++ b/external/turtle @@ -1 +1 @@ -Subproject commit b9a1a4a4b75817366099ef02261cedc84ec8ccba +Subproject commit 0dd0dfa15fbc2774213523fb3a65bc1acb2857b3 diff --git a/libs/s25main/WindowManager.cpp b/libs/s25main/WindowManager.cpp index 2c46380db..e92a582f7 100644 --- a/libs/s25main/WindowManager.cpp +++ b/libs/s25main/WindowManager.cpp @@ -137,7 +137,7 @@ void WindowManager::RelayKeyboardMessage(KeyboardMsgHandler msg, const KeyEvent& // Find one which isn't yet marked for closing so multiple ESC in between draw calls can close multiple windows const auto itActiveWnd = std::find_if(windows.rbegin(), windows.rend(), [](const auto& wnd) { return !wnd->ShouldBeClosed(); }); - if(itActiveWnd != windows.rend() && (*itActiveWnd)->isUserClosable()) + if(itActiveWnd != windows.rend() && (*itActiveWnd)->getCloseBehavior() != CloseBehavior::Custom) (*itActiveWnd)->Close(); } else if(!CALL_MEMBER_FN(*windows.back(), msg)(ke)) // send to active window { @@ -404,7 +404,7 @@ void WindowManager::Msg_RightDown(const MouseCoords& mc) if(!curDesktop) return; - // Sind Fenster vorhanden && ist das aktive Fenster ok + // Right-click closes (most) windows, so check that if(!windows.empty()) { IngameWindow* foundWindow = FindWindowAtPos(mc.GetPos()); @@ -419,7 +419,7 @@ void WindowManager::Msg_RightDown(const MouseCoords& mc) if(foundWindow) { // Close it if requested - if(foundWindow->isUserClosable()) + if(foundWindow->getCloseBehavior() == CloseBehavior::Regular) foundWindow->Close(); else { diff --git a/libs/s25main/ingameWindows/IngameWindow.cpp b/libs/s25main/ingameWindows/IngameWindow.cpp index ecd36a563..32f204ec5 100644 --- a/libs/s25main/ingameWindows/IngameWindow.cpp +++ b/libs/s25main/ingameWindows/IngameWindow.cpp @@ -28,12 +28,12 @@ const DrawPoint IngameWindow::posAtMouse(std::numeric_limitsgetWidth(); // left border contentOffset.y = LOADER.GetImageN("resource", 42)->getHeight(); // title bar contentOffsetEnd.x = LOADER.GetImageN("resource", 39)->getWidth(); // right border @@ -142,37 +142,43 @@ void IngameWindow::MouseLeftDown(const MouseCoords& mc) if(IsPointInRect(mc.GetPos(), title_rect)) { - // Start mit Bewegung + // start moving isMoving = true; lastMousePos = mc.GetPos(); - } - - // beiden Buttons oben links und rechts prfen - const std::array rec = {GetLeftButtonRect(), GetRightButtonRect()}; - - for(unsigned char i = 0; i < 2; ++i) + } else { - if(IsPointInRect(mc.GetPos(), rec[i])) - button_state[i] = ButtonState::Pressed; + // Check the 2 buttons + const std::array rec = {GetCloseButtonBounds(), GetMinimizeButtonBounds()}; + + for(unsigned i = 0; i < 2; ++i) + { + if(IsPointInRect(mc.GetPos(), rec[i])) + buttonState[i] = ButtonState::Pressed; + } } } void IngameWindow::MouseLeftUp(const MouseCoords& mc) { - // Bewegung stoppen isMoving = false; - // beiden Buttons oben links und rechts prfen - const std::array rec = {GetLeftButtonRect(), GetRightButtonRect()}; + const std::array rec = {GetCloseButtonBounds(), GetMinimizeButtonBounds()}; for(unsigned i = 0; i < 2; ++i) { - button_state[i] = ButtonState::Up; + buttonState[i] = ButtonState::Up; + + if((i == 0 && closeBehavior_ == CloseBehavior::Custom) // no close button + || (i == 1 && isModal_)) // modal windows cannot be minimized + { + continue; + } + if(IsPointInRect(mc.GetPos(), rec[i])) { - if(i == 0 && isUserClosable_) + if(i == 0) Close(); - else if(i == 1 && !IsModal()) + else { SetMinimized(!IsMinimized()); LOADER.GetSoundN("sound", 113)->Play(255, false); @@ -196,21 +202,18 @@ void IngameWindow::MouseMove(const MouseCoords& mc) SetPos(newPosBounded); lastMousePos = mc.GetPos(); - } - - // beiden Buttons oben links und rechts prfen - const std::array rec = {GetLeftButtonRect(), GetRightButtonRect()}; - - for(unsigned char i = 0; i < 2; ++i) + } else { - if(IsPointInRect(mc.GetPos(), rec[i])) + // Check the 2 buttons + const std::array rec = {GetCloseButtonBounds(), GetMinimizeButtonBounds()}; + + for(unsigned i = 0; i < 2; ++i) { - if(mc.ldown) - button_state[i] = ButtonState::Pressed; + if(IsPointInRect(mc.GetPos(), rec[i])) + buttonState[i] = mc.ldown ? ButtonState::Pressed : ButtonState::Hover; else - button_state[i] = ButtonState::Hover; - } else - button_state[i] = ButtonState::Up; + buttonState[i] = ButtonState::Up; + } } } @@ -229,8 +232,8 @@ void IngameWindow::Draw_() // This needs a change in GetDrawPos to add this offset and also change all control-add-calls but would be much // cleaner (no more hard coded offsets and we could restyle the ingame windows easily) // - Rect drawRect = GetDrawRect(); - Rect fullWndRect(drawRect.getOrigin() - borderSize, drawRect.getSize() + borderSize * 2u); + const Rect drawRect = GetDrawRect(); + const Rect fullWndRect(drawRect.getOrigin() - borderSize, drawRect.getSize() + borderSize * 2u); // Top DrawRectangle(Rect(fullWndRect.getOrigin(), fullWndRect.getSize().x, borderSize.y), COLOR_BLACK); // Left @@ -242,48 +245,43 @@ void IngameWindow::Draw_() DrawRectangle(Rect(fullWndRect.left, fullWndRect.bottom - borderSize.y, fullWndRect.getSize().x, borderSize.y), COLOR_BLACK); - // Linkes oberes Teil + // Upper parts glArchivItem_Bitmap* leftUpperImg = LOADER.GetImageN("resource", 36); leftUpperImg->DrawFull(GetPos()); - // Rechtes oberes Teil glArchivItem_Bitmap* rightUpperImg = LOADER.GetImageN("resource", 37); rightUpperImg->DrawFull(GetPos() + DrawPoint(GetSize().x - rightUpperImg->getWidth(), 0)); - // Die beiden Buttons oben - static constexpr std::array, 2> ids = {{{47, 55, 50}, {48, 56, 52}}}; - - // Titelleiste - if(isUserClosable_) - LOADER.GetImageN("resource", ids[0][button_state[0]])->DrawFull(GetPos()); + // The 2 buttons + constexpr std::array, 2> ids = {{{47, 55, 50}, {48, 56, 52}}}; + if(closeBehavior_ != CloseBehavior::Custom) + LOADER.GetImageN("resource", ids[0][buttonState[0]])->DrawFull(GetPos()); if(!IsModal()) - LOADER.GetImageN("resource", ids[1][button_state[1]])->DrawFull(GetPos() + DrawPoint(GetSize().x - 16, 0)); - - // Breite berechnen - unsigned title_width = GetSize().x - leftUpperImg->getWidth() - rightUpperImg->getWidth(); + LOADER.GetImageN("resource", ids[1][buttonState[1]])->DrawFull(GetPos() + DrawPoint(GetSize().x - 16, 0)); - unsigned short title_index; + // The title bar + unsigned titleIndex; if(IsActive()) - title_index = isMoving ? 44 : 43; + titleIndex = isMoving ? 44 : 43; else - title_index = 42; + titleIndex = 42; - glArchivItem_Bitmap& titleImg = *LOADER.GetImageN("resource", title_index); + glArchivItem_Bitmap& titleImg = *LOADER.GetImageN("resource", titleIndex); DrawPoint titleImgPos = GetPos() + DrawPoint(leftUpperImg->getWidth(), 0); - // Wieviel mal nebeneinanderzeichnen? - unsigned short title_count = title_width / titleImg.getWidth(); - for(unsigned short i = 0; i < title_count; ++i) + const unsigned titleWidth = GetSize().x - leftUpperImg->getWidth() - rightUpperImg->getWidth(); + // How often should the image be drawn to get the full width + unsigned tileCount = titleWidth / titleImg.getWidth(); + for(unsigned i = 0; i < tileCount; ++i) { titleImg.DrawFull(titleImgPos); titleImgPos.x += titleImg.getWidth(); } - // Rest zeichnen - unsigned short rest = title_width % titleImg.getWidth(); - - if(rest) - titleImg.DrawPart(Rect(titleImgPos, rest, titleImg.getHeight())); + // The remaining part (if any) + unsigned remainingTileSize = titleWidth % titleImg.getWidth(); + if(remainingTileSize) + titleImg.DrawPart(Rect(titleImgPos, remainingTileSize, titleImg.getHeight())); - // Text auf die Leiste + // Text on the title bar NormalFont->Draw(GetPos() + DrawPoint(GetSize().x, titleImg.getHeight()) / 2, title_, FontStyle::CENTER | FontStyle::VCENTER, COLOR_YELLOW); @@ -293,44 +291,42 @@ void IngameWindow::Draw_() // Side bars if(!isMinimized_) { - unsigned side_height = GetSize().y - leftUpperImg->getHeight() - bottomBorderSideImg->getHeight(); + unsigned sideHeight = GetSize().y - leftUpperImg->getHeight() - bottomBorderSideImg->getHeight(); glArchivItem_Bitmap* leftSideImg = LOADER.GetImageN("resource", 38); glArchivItem_Bitmap* rightSideImg = LOADER.GetImageN("resource", 39); - title_count = side_height / leftSideImg->getHeight(); + tileCount = sideHeight / leftSideImg->getHeight(); DrawPoint leftImgPos = GetPos() + DrawPoint(0, leftUpperImg->getHeight()); DrawPoint rightImgPos = leftImgPos + DrawPoint(GetSize().x - leftSideImg->getWidth(), 0); - for(unsigned short i = 0; i < title_count; ++i) + for(unsigned i = 0; i < tileCount; ++i) { leftSideImg->DrawFull(leftImgPos); rightSideImg->DrawFull(rightImgPos); rightImgPos.y = leftImgPos.y += leftSideImg->getHeight(); } - // Rest zeichnen - rest = side_height % leftSideImg->getHeight(); - - if(rest) + // And the partial part + remainingTileSize = sideHeight % leftSideImg->getHeight(); + if(remainingTileSize) { - leftSideImg->DrawPart(Rect(leftImgPos, leftSideImg->getWidth(), rest)); - rightSideImg->DrawPart(Rect(rightImgPos, rightSideImg->getWidth(), rest)); + leftSideImg->DrawPart(Rect(leftImgPos, leftSideImg->getWidth(), remainingTileSize)); + rightSideImg->DrawPart(Rect(rightImgPos, rightSideImg->getWidth(), remainingTileSize)); } } - // Untere Leiste - unsigned side_width = GetSize().x - bottomBorderSideImg->getWidth() * 2; - title_count = side_width / bottomBarImg->getWidth(); + // Lower bar + const unsigned bottomBarWidth = GetSize().x - bottomBorderSideImg->getWidth() * 2; + tileCount = bottomBarWidth / bottomBarImg->getWidth(); DrawPoint bottomImgPos = GetPos() + DrawPoint(bottomBorderSideImg->getWidth(), GetRightBottomBoundary().y); - for(unsigned short i = 0; i < title_count; ++i) + for(unsigned i = 0; i < tileCount; ++i) { bottomBarImg->DrawFull(bottomImgPos); bottomImgPos.x += bottomBarImg->getWidth(); } - rest = side_width % bottomBarImg->getWidth(); - - if(rest) - bottomBarImg->DrawPart(Rect(bottomImgPos, rest, bottomBarImg->getHeight())); + remainingTileSize = bottomBarWidth % bottomBarImg->getWidth(); + if(remainingTileSize) + bottomBarImg->DrawPart(Rect(bottomImgPos, remainingTileSize, bottomBarImg->getHeight())); // Client area if(!isMinimized_) @@ -341,20 +337,16 @@ void IngameWindow::Draw_() Window::Draw_(); } - // Links und rechts unten die 2 kleinen Knäufe + // The 2 rects on the bottom left and right bottomBorderSideImg->DrawFull(GetPos() + DrawPoint(0, GetSize().y - bottomBorderSideImg->getHeight())); - bottomBorderSideImg->DrawFull( - GetPos() - + DrawPoint(GetSize().x - bottomBorderSideImg->getWidth(), GetSize().y - bottomBorderSideImg->getHeight())); + bottomBorderSideImg->DrawFull(GetPos() + GetSize() - bottomBorderSideImg->GetSize()); } -/// Verschiebt Fenster in die Bildschirmmitte void IngameWindow::MoveToCenter() { SetPos(DrawPoint(VIDEODRIVER.GetRenderSize() - GetSize()) / 2); } -/// Verschiebt Fenster neben die Maus void IngameWindow::MoveNextToMouse() { // Center vertically and move slightly right @@ -362,19 +354,17 @@ void IngameWindow::MoveNextToMouse() SetPos(newPos); } -/// Weiterleitung von Nachrichten erlaubt oder nicht? bool IngameWindow::IsMessageRelayAllowed() const { - // Wenn es minimiert wurde, sollen keine Nachrichten weitergeleitet werden return !isMinimized_; } -Rect IngameWindow::GetLeftButtonRect() const +Rect IngameWindow::GetCloseButtonBounds() const { return Rect(GetPos(), 16, 16); } -Rect IngameWindow::GetRightButtonRect() const +Rect IngameWindow::GetMinimizeButtonBounds() const { return Rect(GetPos().x + GetSize().x - 16, GetPos().y, 16, 16); } diff --git a/libs/s25main/ingameWindows/IngameWindow.h b/libs/s25main/ingameWindows/IngameWindow.h index 83766b07f..4f4ff2950 100644 --- a/libs/s25main/ingameWindows/IngameWindow.h +++ b/libs/s25main/ingameWindows/IngameWindow.h @@ -14,6 +14,16 @@ class MouseCoords; template struct Point; +enum CloseBehavior +{ + /// Closeable via right-click, button, keyboard (ESC, ALT+W) + Regular, + /// Close behavior is managed by window, e.g. explicit button + Custom, + /// Same as Regular, but doesn't (auto-)close on right-click + NoRightClick, +}; + class IngameWindow : public Window { public: @@ -27,8 +37,8 @@ class IngameWindow : public Window static const Extent borderSize; IngameWindow(unsigned id, const DrawPoint& pos, const Extent& size, std::string title, - glArchivItem_Bitmap* background, bool modal = false, bool isUserClosable = true, - Window* parent = nullptr); + glArchivItem_Bitmap* background, bool modal = false, + CloseBehavior closeBehavior = CloseBehavior::Regular, Window* parent = nullptr); /// setzt den Hintergrund. void SetBackground(glArchivItem_Bitmap* background) { this->background = background; } @@ -61,11 +71,9 @@ class IngameWindow : public Window /// ist das Fenster minimiert? bool IsMinimized() const { return isMinimized_; } - /// Can the user close the window (e.g. right-click, ESC) - /// If this is false the close button at the title bar will be hidden - bool isUserClosable() const { return isUserClosable_; } + CloseBehavior getCloseBehavior() const { return closeBehavior_; } - /// Modal windows cannot be minimized and stay on top of non-modal ones + /// Modal windows cannot be minimized, are always active and stay on top of non-modal ones bool IsModal() const { return isModal_; } void MouseLeftDown(const MouseCoords& mc); @@ -93,20 +101,22 @@ class IngameWindow : public Window DrawPoint lastMousePos; bool last_down; bool last_down2; - std::array button_state; + std::array buttonState; /// Offset from left and top to actual content Extent contentOffset; /// Offset from content to right and bottom boundary Extent contentOffsetEnd; - Rect GetLeftButtonRect() const; - Rect GetRightButtonRect() const; + /// Get bounds of close button (left) + Rect GetCloseButtonBounds() const; + /// Get bounds of minimize button (right) + Rect GetMinimizeButtonBounds() const; private: bool isModal_; bool closeme; bool isMinimized_; bool isMoving; - bool isUserClosable_; + CloseBehavior closeBehavior_; }; diff --git a/libs/s25main/ingameWindows/TransmitSettingsIgwAdapter.cpp b/libs/s25main/ingameWindows/TransmitSettingsIgwAdapter.cpp index 8fdd479da..62f49fffa 100644 --- a/libs/s25main/ingameWindows/TransmitSettingsIgwAdapter.cpp +++ b/libs/s25main/ingameWindows/TransmitSettingsIgwAdapter.cpp @@ -13,8 +13,8 @@ constexpr unsigned TransmitSettingsIgwAdapter::firstCtrlID; TransmitSettingsIgwAdapter::TransmitSettingsIgwAdapter(unsigned id, const DrawPoint& pos, const Extent& size, const std::string& title, glArchivItem_Bitmap* background, - bool modal, bool isUserClosable, Window* parent) - : IngameWindow(id, pos, size, title, background, modal, isUserClosable, parent), settings_changed(false) + bool modal) + : IngameWindow(id, pos, size, title, background, modal), settings_changed(false) { // Timer for transmitting changes every 2 seconds using namespace std::chrono_literals; diff --git a/libs/s25main/ingameWindows/TransmitSettingsIgwAdapter.h b/libs/s25main/ingameWindows/TransmitSettingsIgwAdapter.h index 639a47645..81a57604a 100644 --- a/libs/s25main/ingameWindows/TransmitSettingsIgwAdapter.h +++ b/libs/s25main/ingameWindows/TransmitSettingsIgwAdapter.h @@ -16,8 +16,7 @@ class TransmitSettingsIgwAdapter : public IngameWindow public: TransmitSettingsIgwAdapter(unsigned id, const DrawPoint& pos, const Extent& size, const std::string& title, - glArchivItem_Bitmap* background, bool modal = false, bool isUserClosable = true, - Window* parent = nullptr); + glArchivItem_Bitmap* background, bool modal = false); /// Updates the control elements with values from visual settings virtual void UpdateSettings() = 0; diff --git a/libs/s25main/ingameWindows/iwAddons.cpp b/libs/s25main/ingameWindows/iwAddons.cpp index e928cbb9c..d26736c09 100644 --- a/libs/s25main/ingameWindows/iwAddons.cpp +++ b/libs/s25main/ingameWindows/iwAddons.cpp @@ -33,7 +33,7 @@ constexpr unsigned AddonGuiLineHeight = 30; iwAddons::iwAddons(GlobalGameSettings& ggs, Window* parent, AddonChangeAllowed policy, std::vector whitelistedAddons) : IngameWindow(CGI_ADDONS, IngameWindow::posLastOrCenter, Extent(700, 500), _("Addon Settings"), - LOADER.GetImageN("resource", 41), true, false, parent), + LOADER.GetImageN("resource", 41), true, CloseBehavior::Custom, parent), ggs(ggs), policy_(policy), whitelistedAddons_(std::move(whitelistedAddons)) { AddText(ID_txtAddFeatures, DrawPoint(20, 30), _("Additional features:"), COLOR_YELLOW, FontStyle{}, NormalFont); diff --git a/libs/s25main/ingameWindows/iwChat.cpp b/libs/s25main/ingameWindows/iwChat.cpp index e11409c40..096a8f28a 100644 --- a/libs/s25main/ingameWindows/iwChat.cpp +++ b/libs/s25main/ingameWindows/iwChat.cpp @@ -16,7 +16,7 @@ ChatDestination lastChatDestination = ChatDestination::All; iwChat::iwChat(Window* parent) : IngameWindow(CGI_CHAT, IngameWindow::posLastOrCenter, Extent(300, 150), _("Chat Window"), - LOADER.GetImageN("resource", 41), false, true, parent) + LOADER.GetImageN("resource", 41), false, CloseBehavior::Regular, parent) { // Eingabefeld für Chattext AddEdit(0, DrawPoint(20, 30), Extent(260, 22), TextureColor::Grey, NormalFont); diff --git a/libs/s25main/ingameWindows/iwConnecting.cpp b/libs/s25main/ingameWindows/iwConnecting.cpp index 54b1cc890..983602596 100644 --- a/libs/s25main/ingameWindows/iwConnecting.cpp +++ b/libs/s25main/ingameWindows/iwConnecting.cpp @@ -25,7 +25,7 @@ enum iwConnecting::iwConnecting(ServerType serverType, std::unique_ptr lobbyClient) : IngameWindow(CGI_CONNECTING, IngameWindow::posCenter, Extent(300, 120), _("Connecting"), - LOADER.GetImageN("resource", 41), true, false), + LOADER.GetImageN("resource", 41), true, CloseBehavior::Custom), serverType_(serverType), lobbyClient_(std::move(lobbyClient)) { WINDOWMANAGER.SetCursor(Cursor::Moon); diff --git a/libs/s25main/ingameWindows/iwDirectIPCreate.cpp b/libs/s25main/ingameWindows/iwDirectIPCreate.cpp index 5ac85368e..5763a0e0f 100644 --- a/libs/s25main/ingameWindows/iwDirectIPCreate.cpp +++ b/libs/s25main/ingameWindows/iwDirectIPCreate.cpp @@ -17,7 +17,7 @@ iwDirectIPCreate::iwDirectIPCreate(ServerType server_type) : IngameWindow(CGI_DIRECTIPCREATE, IngameWindow::posLastOrCenter, Extent(300, 285), _("Create Game"), - LOADER.GetImageN("resource", 41), true, true), + LOADER.GetImageN("resource", 41), true, CloseBehavior::Custom), server_type(server_type) { ctrlEdit *name, *port; diff --git a/libs/s25main/ingameWindows/iwMissionStatement.cpp b/libs/s25main/ingameWindows/iwMissionStatement.cpp index 5d13f4749..ada7bcf11 100644 --- a/libs/s25main/ingameWindows/iwMissionStatement.cpp +++ b/libs/s25main/ingameWindows/iwMissionStatement.cpp @@ -12,7 +12,7 @@ iwMissionStatement::iwMissionStatement(const std::string& title, const std::string& content, bool pauseGame, HelpImage image) : IngameWindow(CGI_MISSION_STATEMENT, IngameWindow::posLastOrCenter, Extent(640, 480), title, - LOADER.GetImageN("io", 5), true, false), + LOADER.GetImageN("io", 5), true, CloseBehavior::Custom), pauseGame_(pauseGame) { glArchivItem_Bitmap* img = (image == IM_NONE) ? nullptr : LOADER.GetImageN("io", image); diff --git a/libs/s25main/ingameWindows/iwMsgbox.cpp b/libs/s25main/ingameWindows/iwMsgbox.cpp index 20cba3897..927b6fae0 100644 --- a/libs/s25main/ingameWindows/iwMsgbox.cpp +++ b/libs/s25main/ingameWindows/iwMsgbox.cpp @@ -28,17 +28,13 @@ const unsigned short maxTextHeight = 200; iwMsgbox::iwMsgbox(const std::string& title, const std::string& text, Window* msgHandler, MsgboxButton button, MsgboxIcon icon, unsigned msgboxid) - : IngameWindow(CGI_MSGBOX, IngameWindow::posLastOrCenter, Extent(420, 140), title, LOADER.GetImageN("resource", 41), - true, false), - button(button), msgboxid(msgboxid), msgHandler_(msgHandler) -{ - Init(text, "io", rttr::enum_cast(icon)); -} + : iwMsgbox(title, text, msgHandler, button, "io", rttr::enum_cast(icon), msgboxid) +{} iwMsgbox::iwMsgbox(const std::string& title, const std::string& text, Window* msgHandler, MsgboxButton button, const ResourceId& iconFile, unsigned iconIdx, unsigned msgboxid /* = 0 */) : IngameWindow(CGI_MSGBOX, IngameWindow::posLastOrCenter, Extent(420, 140), title, LOADER.GetImageN("resource", 41), - true, false), + true, CloseBehavior::Custom), button(button), msgboxid(msgboxid), msgHandler_(msgHandler) { Init(text, iconFile, iconIdx); diff --git a/libs/s25main/ingameWindows/iwObservate.cpp b/libs/s25main/ingameWindows/iwObservate.cpp index 9ceec8609..62f78d0fa 100644 --- a/libs/s25main/ingameWindows/iwObservate.cpp +++ b/libs/s25main/ingameWindows/iwObservate.cpp @@ -25,7 +25,7 @@ const Extent BigWndSize(340, 310); iwObservate::iwObservate(GameWorldView& gwv, const MapPoint selectedPt) : IngameWindow(CGI_OBSERVATION, IngameWindow::posAtMouse, SmallWndSize, _("Observation window"), nullptr, false, - false), + CloseBehavior::NoRightClick), parentView(gwv), view(new GameWorldView(gwv.GetViewer(), Position(GetDrawPos() * DrawPoint(10, 15)), GetSize() - Extent::all(20))), selectedPt(selectedPt), lastWindowPos(Point::Invalid()), isScrolling(false), zoomLvl(0), diff --git a/libs/s25main/ingameWindows/iwPleaseWait.cpp b/libs/s25main/ingameWindows/iwPleaseWait.cpp index 537c7d940..10c383b3f 100644 --- a/libs/s25main/ingameWindows/iwPleaseWait.cpp +++ b/libs/s25main/ingameWindows/iwPleaseWait.cpp @@ -16,7 +16,7 @@ */ iwPleaseWait::iwPleaseWait() : IngameWindow(CGI_PLEASEWAIT, IngameWindow::posLastOrCenter, Extent(300, 60), _("Please wait..."), - LOADER.GetImageN("resource", 41), true, false) + LOADER.GetImageN("resource", 41), true, CloseBehavior::Custom) { WINDOWMANAGER.SetCursor(Cursor::Moon); AddText(0, GetSize() / 2, _("Please wait..."), COLOR_YELLOW, FontStyle::CENTER | FontStyle::VCENTER, NormalFont); diff --git a/tests/s25Main/UI/testIngameWindow.cpp b/tests/s25Main/UI/testIngameWindow.cpp index 4941a68ab..7f158a66a 100644 --- a/tests/s25Main/UI/testIngameWindow.cpp +++ b/tests/s25Main/UI/testIngameWindow.cpp @@ -124,7 +124,7 @@ BOOST_AUTO_TEST_CASE(ConnectingWindow) boost::signals2::scoped_connection _ = wnd.onError.connect(onError); // Modal and doesn't react on right-click BOOST_TEST(wnd.IsModal()); - BOOST_TEST(!wnd.isUserClosable()); + BOOST_TEST(wnd.getCloseBehavior() == CloseBehavior::Custom); ctrlPercent& progressBar = *wnd.GetCtrls().at(0); BOOST_TEST(!progressBar.IsVisible()); // Initially hidden for(auto st : diff --git a/tests/s25Main/UI/testWindowManager.cpp b/tests/s25Main/UI/testWindowManager.cpp index 569379aaa..8ea9ddb87 100644 --- a/tests/s25Main/UI/testWindowManager.cpp +++ b/tests/s25Main/UI/testWindowManager.cpp @@ -137,8 +137,8 @@ BOOST_FIXTURE_TEST_CASE(DblClick, WMFixture) namespace { MOCK_BASE_CLASS(TestIngameWnd, IngameWindow) { - explicit TestIngameWnd(unsigned id, bool isModal = false, bool isUserClosable = true) - : IngameWindow(id, DrawPoint(0, 0), Extent(100, 100), "", nullptr, isModal, isUserClosable) + explicit TestIngameWnd(unsigned id, bool isModal = false, CloseBehavior closeBehavior = CloseBehavior::Regular) + : IngameWindow(id, DrawPoint(0, 0), Extent(100, 100), "", nullptr, isModal, closeBehavior) { closed.erase(std::remove(closed.begin(), closed.end(), this), closed.end()); } @@ -393,7 +393,7 @@ BOOST_FIXTURE_TEST_CASE(EscClosesWindow, uiHelper::Fixture) REQUIRE_WINDOW_DESTROYED(wnd1); // ESC does not close non-user-closable windows - wnd1 = &WINDOWMANAGER.Show(std::make_unique(CGI_HELP, false, false)); + wnd1 = &WINDOWMANAGER.Show(std::make_unique(CGI_HELP, false, CloseBehavior::Custom)); BOOST_TEST_REQUIRE(WINDOWMANAGER.GetTopMostWindow() == wnd1); WINDOWMANAGER.Msg_KeyDown(evEsc); REQUIRE_WINDOW_ALIVE(wnd1); @@ -401,7 +401,7 @@ BOOST_FIXTURE_TEST_CASE(EscClosesWindow, uiHelper::Fixture) WINDOWMANAGER.Draw(); BOOST_TEST_REQUIRE(WINDOWMANAGER.GetTopMostWindow() == wnd1); - wnd2 = &WINDOWMANAGER.Show(std::make_unique(CGI_HELP, true, false)); + wnd2 = &WINDOWMANAGER.Show(std::make_unique(CGI_HELP, true, CloseBehavior::Custom)); BOOST_TEST_REQUIRE(WINDOWMANAGER.GetTopMostWindow() == wnd2); WINDOWMANAGER.Msg_KeyDown(evEsc); REQUIRE_WINDOW_ALIVE(wnd1); @@ -450,14 +450,14 @@ BOOST_FIXTURE_TEST_CASE(RightclickClosesWindow, uiHelper::Fixture) REQUIRE_WINDOW_DESTROYED(wnd3); // Don't close non-user-closable windows - wnd1 = &WINDOWMANAGER.Show(std::make_unique(CGI_HELP, false, false)); + wnd1 = &WINDOWMANAGER.Show(std::make_unique(CGI_HELP, false, CloseBehavior::Custom)); BOOST_TEST_REQUIRE(WINDOWMANAGER.GetTopMostWindow() == wnd1); WINDOWMANAGER.Msg_RightDown(evRDown); MOCK_EXPECT(wnd1->Draw_).once(); WINDOWMANAGER.Draw(); BOOST_TEST_REQUIRE(WINDOWMANAGER.GetTopMostWindow() == wnd1); - wnd2 = &WINDOWMANAGER.Show(std::make_unique(CGI_HELP, true, false)); + wnd2 = &WINDOWMANAGER.Show(std::make_unique(CGI_HELP, true, CloseBehavior::NoRightClick)); BOOST_TEST_REQUIRE(WINDOWMANAGER.GetTopMostWindow() == wnd2); WINDOWMANAGER.Msg_RightDown(evRDown); MOCK_EXPECT(wnd1->Draw_).once();