From 5dd673aa6abe2a070de45388a885d03fcc037d70 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 21 May 2014 23:53:20 +0300 Subject: allow open updater window from inside game. --- src/actionmanager.cpp | 10 ++++++++++ src/actionmanager.h | 1 + src/client.h | 9 +++++++++ src/game.cpp | 11 +++++++++++ src/game.h | 2 ++ src/gui/windowmenu.cpp | 4 ++++ src/gui/windows/updaterwindow.cpp | 30 +++++++++++++++++++++++++----- src/gui/windows/updaterwindow.h | 5 ++++- src/input/inputaction.h | 1 + src/input/keyboarddata.h | 7 +++++++ 10 files changed, 74 insertions(+), 6 deletions(-) diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp index 0c2814d75..c751c9530 100644 --- a/src/actionmanager.cpp +++ b/src/actionmanager.cpp @@ -60,6 +60,7 @@ #include "gui/windows/setupwindow.h" #include "gui/windows/shopwindow.h" #include "gui/windows/shortcutwindow.h" +#include "gui/windows/updaterwindow.h" #include "gui/widgets/tabs/chattab.h" @@ -863,6 +864,15 @@ impHandler0(questsWindowShow) return true; } +impHandler0(updaterWindowShow) +{ + if (updaterWindow) + updaterWindow->deleteSelf(); + else + Game::createUpdaterWindow(); + return true; +} + impHandler0(changeMapMode) { if (viewport) diff --git a/src/actionmanager.h b/src/actionmanager.h index 7a0ad6e17..8e11697fc 100644 --- a/src/actionmanager.h +++ b/src/actionmanager.h @@ -123,6 +123,7 @@ namespace ActionManager decHandler(whoIsOnlineWindowShow); decHandler(didYouKnowWindowShow); decHandler(questsWindowShow); + decHandler(updaterWindowShow); } // namespace ActionManager #undef decHandler diff --git a/src/client.h b/src/client.h index 15a851eb1..3d414d466 100644 --- a/src/client.h +++ b/src/client.h @@ -228,6 +228,15 @@ public: std::string getLogFileName() const A_WARN_UNUSED { return mLogFileName; } + std::string getUpdateHost() const A_WARN_UNUSED + { return mUpdateHost; } + + std::string getOldUpdates() const A_WARN_UNUSED + { return mOldUpdates; } + + const Options &getOptions() const A_WARN_UNUSED + { return mOptions; } + const std::vector &getMirrors() const A_WARN_UNUSED { return mCurrentServer.updateMirrors; } diff --git a/src/game.cpp b/src/game.cpp index d4a75803e..c124fcfcf 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -77,6 +77,7 @@ #include "gui/windows/statuswindow.h" #include "gui/windows/tradewindow.h" #include "gui/windows/questswindow.h" +#include "gui/windows/updaterwindow.h" #include "gui/windows/whoisonline.h" #include "gui/widgets/tabs/battletab.h" @@ -154,6 +155,7 @@ BotCheckerWindow *botCheckerWindow = nullptr; SocialWindow *socialWindow = nullptr; QuestsWindow *questsWindow = nullptr; WindowMenu *windowMenu = nullptr; +UpdaterWindow *updaterWindow = nullptr; ActorManager *actorManager = nullptr; CommandHandler *commandHandler = nullptr; @@ -1201,3 +1203,12 @@ void Game::videoResized(const int width, const int height) if (windowMenu) windowMenu->setPosition(width - windowMenu->getWidth(), 0); } + +void Game::createUpdaterWindow() +{ + updaterWindow = new UpdaterWindow(client->getUpdateHost(), + client->getOldUpdates(), + false, + 0); + updaterWindow->postInit(); +} diff --git a/src/game.h b/src/game.h index 8f488c6ed..8b25cd146 100644 --- a/src/game.h +++ b/src/game.h @@ -120,6 +120,8 @@ class Game final static bool saveScreenshot(SDL_Surface *const screenshot); + static void createUpdaterWindow(); + void updateHistory(const SDL_Event &event); void checkKeys(); diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp index b30306c3f..a4908d2a6 100644 --- a/src/gui/windowmenu.cpp +++ b/src/gui/windowmenu.cpp @@ -139,6 +139,10 @@ WindowMenu::WindowMenu(const Widget2 *const widget) : addButton(N_("OU"), // TRANSLATORS: full button name _("Outfits"), x, h, InputAction::WINDOW_OUTFIT, false); + // TRANSLATORS: short button name for updates window. + addButton(N_("UP"), + // TRANSLATORS: full button name + _("Updates"), x, h, InputAction::WINDOW_UPDATER, false); // TRANSLATORS: short button name for debug window. addButton(N_("DBG"), // TRANSLATORS: full button name diff --git a/src/gui/windows/updaterwindow.cpp b/src/gui/windows/updaterwindow.cpp index ff194ada4..9835279cc 100644 --- a/src/gui/windows/updaterwindow.cpp +++ b/src/gui/windows/updaterwindow.cpp @@ -276,8 +276,15 @@ void UpdaterWindow::enable() mPlayButton->setEnabled(true); mPlayButton->requestFocus(); - if (mUpdateType & UpdateType::Close) - client->setState(STATE_LOAD_DATA); + if (client->getState() != STATE_GAME) + { + if (mUpdateType & UpdateType::Close) + client->setState(STATE_LOAD_DATA); + } + else + { + deleteSelf(); + } } void UpdaterWindow::action(const ActionEvent &event) @@ -296,7 +303,10 @@ void UpdaterWindow::action(const ActionEvent &event) } else if (eventId == "play") { - client->setState(STATE_LOAD_DATA); + if (client->getState() != STATE_GAME) + client->setState(STATE_LOAD_DATA); + else + deleteSelf(); } } @@ -306,7 +316,10 @@ void UpdaterWindow::keyPressed(KeyEvent &event) if (actionId == static_cast(InputAction::GUI_CANCEL)) { action(ActionEvent(nullptr, mCancelButton->getActionEventId())); - client->setState(STATE_LOGIN); + if (client->getState() != STATE_GAME) + client->setState(STATE_LOGIN); + else + deleteSelf(); } else if (actionId == static_cast(InputAction::GUI_SELECT) || actionId == static_cast(InputAction::GUI_SELECT2)) @@ -503,7 +516,8 @@ int UpdaterWindow::updateProgress(void *ptr, DownloadStatus::Type status, uw->setProgress(progress); - if (client->getState() != STATE_UPDATE + if ((client->getState() != STATE_UPDATE + && client->getState() != STATE_GAME) || uw->mDownloadStatus == UPDATE_ERROR) { // If the action was canceled return an error code to stop the mThread @@ -1134,3 +1148,9 @@ void UpdaterWindow::unloadMods(const std::string &dir) } } } + +void UpdaterWindow::deleteSelf() +{ + scheduleDelete(); + updaterWindow = nullptr; +} diff --git a/src/gui/windows/updaterwindow.h b/src/gui/windows/updaterwindow.h index eaca25e9f..fec31fce0 100644 --- a/src/gui/windows/updaterwindow.h +++ b/src/gui/windows/updaterwindow.h @@ -117,6 +117,8 @@ class UpdaterWindow final : public Window, void loadFile(std::string file); + void deleteSelf(); + static void loadLocalUpdates(const std::string &dir); static void unloadUpdates(const std::string &dir); @@ -156,7 +158,6 @@ private: */ void loadUpdates(); - /** * A download callback for progress updates. */ @@ -259,4 +260,6 @@ private: bool mValidateXml; }; +extern UpdaterWindow *updaterWindow; + #endif // GUI_WINDOWS_UPDATERWINDOW_H diff --git a/src/input/inputaction.h b/src/input/inputaction.h index 5c3611233..963e43750 100644 --- a/src/input/inputaction.h +++ b/src/input/inputaction.h @@ -339,6 +339,7 @@ namespace InputAction GUI_F11, GUI_F12, WINDOW_ABOUT, + WINDOW_UPDATER, TOTAL }; } // namespace InputAction diff --git a/src/input/keyboarddata.h b/src/input/keyboarddata.h index 636aa9268..76e5a15ab 100644 --- a/src/input/keyboarddata.h +++ b/src/input/keyboarddata.h @@ -2202,6 +2202,13 @@ static const KeyData keyData[InputAction::TOTAL] = { &ActionManager::aboutWindowShow, InputAction::NO_VALUE, 50, InputCondition::SHORTCUT0}, + {"keyWindowUpdater", + InputType::UNKNOWN, InputAction::NO_VALUE, + InputType::UNKNOWN, InputAction::NO_VALUE, + Input::GRP_DEFAULT | Input::GRP_GUI, + &ActionManager::updaterWindowShow, + InputAction::NO_VALUE, 50, + InputCondition::GAME} }; #endif // INPUT_KEYBOARDDATA_H -- cgit v1.2.3-70-g09d2