summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-01-09 14:16:53 +0300
committerAndrei Karas <akaras@inbox.ru>2014-01-09 14:16:53 +0300
commit46585d7c62a53bfaf5173aa4e67d64735af1d2ed (patch)
tree3ffa2902ee94455441dcc7fe4ae7b1e027e302e7
parentb3ad7da111d1a21f14de39d84be97104a9666017 (diff)
downloadmanaplus-46585d7c62a53bfaf5173aa4e67d64735af1d2ed.tar.gz
manaplus-46585d7c62a53bfaf5173aa4e67d64735af1d2ed.tar.bz2
manaplus-46585d7c62a53bfaf5173aa4e67d64735af1d2ed.tar.xz
manaplus-46585d7c62a53bfaf5173aa4e67d64735af1d2ed.zip
add ability to notify setup pages about disconnect from server.
Show mods page only if connected to server.
-rw-r--r--src/client.cpp2
-rw-r--r--src/gui/widgets/setupitem.cpp4
-rw-r--r--src/gui/widgets/setupitem.h2
-rw-r--r--src/gui/widgets/tabs/setup_mods.cpp6
-rw-r--r--src/gui/widgets/tabs/setup_mods.h2
-rw-r--r--src/gui/widgets/tabs/setuptab.cpp4
-rw-r--r--src/gui/widgets/tabs/setuptab.h2
-rw-r--r--src/gui/widgets/tabs/setuptabscroll.cpp12
-rw-r--r--src/gui/widgets/tabs/setuptabscroll.h2
-rw-r--r--src/gui/windows/setup.cpp22
-rw-r--r--src/gui/windows/setup.h3
11 files changed, 59 insertions, 2 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 483b70c87..443c156fb 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -1720,6 +1720,8 @@ int Client::gameExec()
mServerName.clear();
serverConfig.write();
serverConfig.unload();
+ if (setupWindow)
+ setupWindow->externalUnload();
mState = STATE_CHOOSE_SERVER;
BLOCK_END("Client::gameExec STATE_SWITCH_SERVER")
diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp
index 2cf35c144..e8bec1db6 100644
--- a/src/gui/widgets/setupitem.cpp
+++ b/src/gui/widgets/setupitem.cpp
@@ -184,6 +184,10 @@ void SetupItem::externalUpdated(const std::string &eventName A_UNUSED)
toWidget();
}
+void SetupItem::externalUnloaded(const std::string &eventName A_UNUSED)
+{
+}
+
void SetupItem::fixFirstItemSize(gcn::Widget *const widget)
{
const int maxSize = mParent->getPreferredFirstItemSize();
diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h
index d56efca8e..40a20a985 100644
--- a/src/gui/widgets/setupitem.h
+++ b/src/gui/widgets/setupitem.h
@@ -89,6 +89,8 @@ class SetupItem : public gcn::ActionListener,
virtual void externalUpdated(const std::string &eventName);
+ virtual void externalUnloaded(const std::string &eventName);
+
bool isMainConfig() const A_WARN_UNUSED
{ return mMainConfig; }
diff --git a/src/gui/widgets/tabs/setup_mods.cpp b/src/gui/widgets/tabs/setup_mods.cpp
index 6857b6700..646bfdb7e 100644
--- a/src/gui/widgets/tabs/setup_mods.cpp
+++ b/src/gui/widgets/tabs/setup_mods.cpp
@@ -45,7 +45,6 @@ Setup_Mods::Setup_Mods(const Widget2 *const widget) :
ContainerPlacer place = h.getPlacer(0, 0);
place(0, 0, mScroll, 10, 10);
-
setDimension(gcn::Rectangle(0, 0, 550, 350));
}
@@ -114,3 +113,8 @@ void Setup_Mods::saveMods()
}
serverConfig.setValue("mods", modsString);
}
+
+void Setup_Mods::externalUnloaded()
+{
+ clear();
+}
diff --git a/src/gui/widgets/tabs/setup_mods.h b/src/gui/widgets/tabs/setup_mods.h
index 5c837811a..6c5c519fd 100644
--- a/src/gui/widgets/tabs/setup_mods.h
+++ b/src/gui/widgets/tabs/setup_mods.h
@@ -38,6 +38,8 @@ class Setup_Mods final : public SetupTabScroll
void externalUpdated() override final;
+ void externalUnloaded() override final;
+
void loadMods();
void saveMods();
diff --git a/src/gui/widgets/tabs/setuptab.cpp b/src/gui/widgets/tabs/setuptab.cpp
index ab015f9a2..c445e2ad7 100644
--- a/src/gui/widgets/tabs/setuptab.cpp
+++ b/src/gui/widgets/tabs/setuptab.cpp
@@ -37,3 +37,7 @@ SetupTab::SetupTab(const Widget2 *const widget) :
void SetupTab::externalUpdated()
{
}
+
+void SetupTab::externalUnloaded()
+{
+}
diff --git a/src/gui/widgets/tabs/setuptab.h b/src/gui/widgets/tabs/setuptab.h
index 9d1362faf..388b0a988 100644
--- a/src/gui/widgets/tabs/setuptab.h
+++ b/src/gui/widgets/tabs/setuptab.h
@@ -57,6 +57,8 @@ class SetupTab : public Container,
virtual void externalUpdated();
+ virtual void externalUnloaded();
+
protected:
explicit SetupTab(const Widget2 *const widget);
diff --git a/src/gui/widgets/tabs/setuptabscroll.cpp b/src/gui/widgets/tabs/setuptabscroll.cpp
index 81c191dd6..659ef5824 100644
--- a/src/gui/widgets/tabs/setuptabscroll.cpp
+++ b/src/gui/widgets/tabs/setuptabscroll.cpp
@@ -134,6 +134,18 @@ void SetupTabScroll::externalUpdated()
}
}
+void SetupTabScroll::externalUnloaded()
+{
+ for (std::map<std::string, SetupItem*>::const_iterator
+ iter = mItems.begin(), iter_end = mItems.end();
+ iter != iter_end; ++ iter)
+ {
+ SetupItem *const widget = (*iter).second;
+ if (widget && !widget->isMainConfig())
+ widget->externalUnloaded((*iter).first);
+ }
+}
+
void SetupTabScroll::widgetResized(const gcn::Event &event A_UNUSED)
{
mScroll->setWidth(getWidth() - 12);
diff --git a/src/gui/widgets/tabs/setuptabscroll.h b/src/gui/widgets/tabs/setuptabscroll.h
index 15b493d88..e3d495690 100644
--- a/src/gui/widgets/tabs/setuptabscroll.h
+++ b/src/gui/widgets/tabs/setuptabscroll.h
@@ -54,6 +54,8 @@ class SetupTabScroll : public SetupTab
virtual void externalUpdated() override;
+ virtual void externalUnloaded() override;
+
virtual void action(const gcn::ActionEvent &event A_UNUSED)
override final
{ }
diff --git a/src/gui/windows/setup.cpp b/src/gui/windows/setup.cpp
index cd6e62882..5ba27f23c 100644
--- a/src/gui/windows/setup.cpp
+++ b/src/gui/windows/setup.cpp
@@ -59,6 +59,7 @@ Setup::Setup() :
Window(_("Setup"), false, nullptr, "setup.xml"),
gcn::ActionListener(),
mTabs(),
+ mModsTab(nullptr),
mWindowsToReset(),
mButtons(),
mResetWindows(nullptr),
@@ -125,7 +126,6 @@ void Setup::postInit()
mTabs.push_back(new Setup_Players(this));
mTabs.push_back(new Setup_Relations(this));
mTabs.push_back(new Setup_Theme(this));
- mTabs.push_back(new Setup_Mods(this));
mTabs.push_back(new Setup_Other(this));
FOR_EACH (std::list<SetupTab*>::const_iterator, i, mTabs)
@@ -203,6 +203,9 @@ void Setup::setInGame(const bool inGame)
void Setup::externalUpdate()
{
+ mModsTab = new Setup_Mods(this);
+ mTabs.push_back(mModsTab);
+ mPanel->addTab(mModsTab->getName(), mModsTab);
FOR_EACH (std::list<SetupTab*>::const_iterator, it, mTabs)
{
if (*it)
@@ -210,6 +213,23 @@ void Setup::externalUpdate()
}
}
+void Setup::externalUnload()
+{
+ FOR_EACH (std::list<SetupTab*>::const_iterator, it, mTabs)
+ {
+ if (*it)
+ (*it)->externalUnloaded();
+ }
+ if (mModsTab)
+ {
+ mTabs.remove(mModsTab);
+ Tab *const tab = mPanel->getTab(mModsTab->getName());
+ mPanel->removeTab(tab);
+ delete mModsTab;
+ mModsTab = nullptr;
+ }
+}
+
void Setup::registerWindowForReset(Window *const window)
{
mWindowsToReset.push_back(window);
diff --git a/src/gui/windows/setup.h b/src/gui/windows/setup.h
index 1b484b726..9039f4e87 100644
--- a/src/gui/windows/setup.h
+++ b/src/gui/windows/setup.h
@@ -57,6 +57,8 @@ class Setup final : public Window, public gcn::ActionListener
void externalUpdate();
+ void externalUnload();
+
void registerWindowForReset(Window *const window);
void clearWindowsForReset()
@@ -72,6 +74,7 @@ class Setup final : public Window, public gcn::ActionListener
private:
std::list<SetupTab*> mTabs;
+ SetupTab *mModsTab;
std::list<Window*> mWindowsToReset;
std::vector<Button*> mButtons;
Button *mResetWindows;