summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/defaults.cpp1
-rw-r--r--src/gui/windows/shopwindow.cpp51
-rw-r--r--src/gui/windows/shopwindow.h6
-rw-r--r--src/listeners/shoprenamelistener.cpp47
-rw-r--r--src/listeners/shoprenamelistener.h48
7 files changed, 150 insertions, 7 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ff6986678..30aea08db 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1136,6 +1136,8 @@ SET(SRCS
gui/rect.h
events/selectionevent.h
listeners/selectionlistener.h
+ listeners/shoprenamelistener.cpp
+ listeners/shoprenamelistener.h
listeners/statlistener.cpp
listeners/statlistener.h
listeners/tablemodellistener.h
diff --git a/src/Makefile.am b/src/Makefile.am
index a788d3f80..ca8330f93 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -214,6 +214,8 @@ manaplus_SOURCES += events/actionevent.h \
gui/rect.h \
events/selectionevent.h \
listeners/selectionlistener.h \
+ listeners/shoprenamelistener.cpp \
+ listeners/shoprenamelistener.h \
listeners/statlistener.cpp \
listeners/statlistener.h \
listeners/tablemodellistener.h \
diff --git a/src/defaults.cpp b/src/defaults.cpp
index 9abd9bb14..eb33c4245 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -373,6 +373,7 @@ DefaultsData* getConfigDefaults()
AddDEF("textureSize", "1024,1024,1024,1024,1024,1024");
AddDEF("ignorelogpackets", "");
AddDEF("disableLoggingInGame", false);
+ AddDEF("sellShopName", "unnamed");
return configData;
}
diff --git a/src/gui/windows/shopwindow.cpp b/src/gui/windows/shopwindow.cpp
index 1068aca2b..41bf90958 100644
--- a/src/gui/windows/shopwindow.cpp
+++ b/src/gui/windows/shopwindow.cpp
@@ -27,6 +27,7 @@
#include "gui/windows/buydialog.h"
#include "gui/windows/chatwindow.h"
#include "gui/windows/confirmdialog.h"
+#include "gui/windows/editdialog.h"
#include "gui/windows/itemamountwindow.h"
#include "gui/windows/shopselldialog.h"
#include "gui/windows/setupwindow.h"
@@ -43,6 +44,8 @@
#include "gui/widgets/shoplistbox.h"
#include "gui/widgets/tabstrip.h"
+#include "listeners/shoprenamelistener.h"
+
#include "actormanager.h"
#include "configuration.h"
#include "inventory.h"
@@ -100,10 +103,12 @@ ShopWindow::ShopWindow() :
mDeleteButton(new Button(this, _("Delete"), "delete", this)),
mAnnounceButton(nullptr),
mPublishButton(nullptr),
+ mRenameButton(nullptr),
mAnnounceLinks(nullptr),
mTabs(nullptr),
mAcceptPlayer(),
mTradeNick(),
+ mSellShopName(serverConfig.getStringValue("sellShopName")),
mSelectedItem(-1),
mAnnonceTime(0),
mLastRequestTimeList(0),
@@ -122,7 +127,7 @@ ShopWindow::ShopWindow() :
setResizable(true);
setCloseButton(true);
setStickyButtonLock(true);
- setMinWidth(260);
+ setMinWidth(300);
setMinHeight(220);
if (mainGraphics->mWidth > 600)
setDefaultSize(500, 300, ImageRect::CENTER);
@@ -132,7 +137,6 @@ ShopWindow::ShopWindow() :
if (setupWindow)
setupWindow->registerWindowForReset(this);
-
const int size = config.getIntValue("fontSize")
+ getOption("tabHeightAdjust", 16);
mTabs = new TabStrip(this, "shop", size);
@@ -143,7 +147,6 @@ ShopWindow::ShopWindow() :
// TRANSLATORS: shop window tab name
mTabs->addButton(_("Sell"), "sell", false);
-
loadList();
mBuyShopItemList->setPriceCheck(false);
@@ -159,11 +162,14 @@ ShopWindow::ShopWindow() :
placer(0, 0, mTabs, 8).setPadding(3);
- if (isBuySelected)
+ if (mHaveVending)
{
// TRANSLATORS: shop window button
mPublishButton = new Button(this, _("Publish"), "publish", this);
+ // TRANSLATORS: shop window button
+ mRenameButton = new Button(this, _("Rename"), "rename", this);
placer(2, 6, mPublishButton);
+ placer(3, 6, mRenameButton);
}
else
{
@@ -180,14 +186,14 @@ ShopWindow::ShopWindow() :
placer(0, 1, mScrollArea, 8, 5).setPadding(3);
placer(0, 6, mAddButton);
placer(1, 6, mDeleteButton);
- placer(7, 7, mCloseButton);
+ placer(7, 6, mCloseButton);
Layout &layout = getLayout();
layout.setRowHeight(0, LayoutType::SET);
center();
loadWindowState();
-
+ updateShopName();
instances.push_back(this);
}
@@ -304,9 +310,17 @@ void ShopWindow::action(const ActionEvent &event)
break;
}
if (!items.empty())
- vendingHandler->createShop("test shop", true, items);
+ vendingHandler->createShop(mSellShopName, true, items);
}
}
+ else if (eventId == "rename")
+ {
+ EditDialog *const dialog = new EditDialog(
+ _("Please enter new shop name"), mSellShopName, "OK");
+ dialog->postInit();
+ shopRenameListener.setDialog(dialog);
+ dialog->addActionListener(&shopRenameListener);
+ }
if (mSelectedItem < 1)
return;
@@ -403,6 +417,8 @@ void ShopWindow::updateButtonsAndLabels()
mPublishButton->setEnabled(false);
}
}
+ if (mRenameButton)
+ mRenameButton->setEnabled(!mEnableVending);
}
void ShopWindow::setVisible(bool visible)
@@ -989,3 +1005,24 @@ void ShopWindow::vendingEnabled(const bool b)
mSellShopSize = 0;
updateButtonsAndLabels();
}
+
+void ShopWindow::updateShopName()
+{
+ if (mSellShopName.empty())
+ {
+ // TRANSLATORS: shop window name
+ setCaption(_("Personal Shop"));
+ }
+ else
+ {
+ // TRANSLATORS: shop window name
+ setCaption(strprintf(_("Personal Shop - %s"), mSellShopName.c_str()));
+ }
+}
+
+void ShopWindow::setShopName(const std::string &name)
+{
+ mSellShopName = name;
+ serverConfig.setValue("sellShopName", mSellShopName);
+ updateShopName();
+}
diff --git a/src/gui/windows/shopwindow.h b/src/gui/windows/shopwindow.h
index c746bff17..0acc814b1 100644
--- a/src/gui/windows/shopwindow.h
+++ b/src/gui/windows/shopwindow.h
@@ -145,11 +145,15 @@ class ShopWindow final : public Window,
void vendingEnabled(const bool b) override final;
+ void setShopName(const std::string &name);
+
private:
void startTrade();
void updateSelection();
+ void updateShopName();
+
typedef std::list<ShopWindow*> DialogList;
static DialogList instances;
@@ -167,10 +171,12 @@ class ShopWindow final : public Window,
Button *mDeleteButton;
Button *mAnnounceButton;
Button *mPublishButton;
+ Button *mRenameButton;
CheckBox *mAnnounceLinks;
TabStrip *mTabs;
std::string mAcceptPlayer;
std::string mTradeNick;
+ std::string mSellShopName;
int mSelectedItem;
int mAnnonceTime;
int mLastRequestTimeList;
diff --git a/src/listeners/shoprenamelistener.cpp b/src/listeners/shoprenamelistener.cpp
new file mode 100644
index 000000000..35c89dba6
--- /dev/null
+++ b/src/listeners/shoprenamelistener.cpp
@@ -0,0 +1,47 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "listeners/shoprenamelistener.h"
+
+#include "gui/windows/editdialog.h"
+#include "gui/windows/shopwindow.h"
+
+#include "net/charserverhandler.h"
+
+#include "debug.h"
+
+ShopRenameListener shopRenameListener;
+
+ShopRenameListener::ShopRenameListener() :
+ ActionListener(),
+ mDialog(nullptr)
+{
+}
+
+void ShopRenameListener::action(const ActionEvent &event)
+{
+ if (event.getId() != "OK")
+ return;
+ if (mDialog)
+ {
+ shopWindow->setShopName(mDialog->getMsg());
+ mDialog = nullptr;
+ }
+}
diff --git a/src/listeners/shoprenamelistener.h b/src/listeners/shoprenamelistener.h
new file mode 100644
index 000000000..4cafe9d0b
--- /dev/null
+++ b/src/listeners/shoprenamelistener.h
@@ -0,0 +1,48 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef LISTENERS_SHOPRENAMELISTENER_H
+#define LISTENERS_SHOPRENAMELISTENER_H
+
+#include "listeners/actionlistener.h"
+
+#include "localconsts.h"
+
+class EditDialog;
+
+class ShopRenameListener final : public ActionListener
+{
+ public:
+ ShopRenameListener();
+
+ A_DELETE_COPY(ShopRenameListener)
+
+ void action(const ActionEvent &event) override final;
+
+ void setDialog(EditDialog *const dialog)
+ { mDialog = dialog; }
+
+ protected:
+ EditDialog *mDialog;
+};
+
+extern ShopRenameListener shopRenameListener;
+
+#endif // LISTENERS_SHOPRENAMELISTENER_H