summaryrefslogtreecommitdiff
path: root/src/gui/windows
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/windows')
-rw-r--r--src/gui/windows/chatwindow.cpp63
-rw-r--r--src/gui/windows/editdialog.cpp4
-rw-r--r--src/gui/windows/editdialog.h1
-rw-r--r--src/gui/windows/equipmentwindow.h2
-rw-r--r--src/gui/windows/ministatuswindow.cpp2
-rw-r--r--src/gui/windows/npcdialog.h3
-rw-r--r--src/gui/windows/questswindow.cpp21
-rw-r--r--src/gui/windows/questswindow.h2
-rw-r--r--src/gui/windows/serverdialog.cpp3
-rw-r--r--src/gui/windows/setup.cpp32
-rw-r--r--src/gui/windows/setup.h5
-rw-r--r--src/gui/windows/skilldialog.cpp93
-rw-r--r--src/gui/windows/skilldialog.h2
-rw-r--r--src/gui/windows/updaterwindow.cpp173
-rw-r--r--src/gui/windows/updaterwindow.h10
15 files changed, 287 insertions, 129 deletions
diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp
index 015e58b61..e1afb6e5b 100644
--- a/src/gui/windows/chatwindow.cpp
+++ b/src/gui/windows/chatwindow.cpp
@@ -1240,6 +1240,39 @@ WhisperTab *ChatWindow::getWhisperTab(const std::string &nick) const
return ret;
}
+
+#define changeColor(fun) \
+ { \
+ msg = removeColors(msg); \
+ int skip = 0; \
+ const size_t sz = msg.length(); \
+ for (size_t f = 0; f < sz; f ++) \
+ { \
+ if (skip > 0) \
+ { \
+ newMsg += msg.at(f); \
+ skip --; \
+ continue; \
+ } \
+ const unsigned char ch = static_cast<unsigned char>(msg.at(f)); \
+ if (f + 2 < sz && msg.substr(f, 2) == "%%") \
+ { \
+ newMsg += msg.at(f); \
+ skip = 2; \
+ } \
+ else if (ch > 0xc0 || ch < 0x80) \
+ { \
+ newMsg += "##" + toString(fun) + msg.at(f); \
+ if (mRainbowColor > 9) \
+ mRainbowColor = 0; \
+ } \
+ else \
+ { \
+ newMsg += msg.at(f); \
+ } \
+ } \
+ }
+
std::string ChatWindow::addColors(std::string &msg)
{
// default color or chat command
@@ -1256,31 +1289,13 @@ std::string ChatWindow::addColors(std::string &msg)
switch (mChatColor)
{
case 11:
- msg = removeColors(msg);
- for (unsigned int f = 0; f < msg.length(); f ++)
- {
- newMsg += "##" + toString(mRainbowColor++) + msg.at(f);
- if (mRainbowColor > 9)
- mRainbowColor = 0;
- }
+ changeColor(mRainbowColor++)
return newMsg;
case 12:
- msg = removeColors(msg);
- for (unsigned int f = 0; f < msg.length(); f ++)
- {
- newMsg += "##" + toString(cMap[mRainbowColor++]) + msg.at(f);
- if (mRainbowColor > 9)
- mRainbowColor = 0;
- }
+ changeColor(cMap[mRainbowColor++])
return newMsg;
case 13:
- msg = removeColors(msg);
- for (unsigned int f = 0; f < msg.length(); f ++)
- {
- newMsg += "##" + toString(cMap[9-mRainbowColor++]) + msg.at(f);
- if (mRainbowColor > 9)
- mRainbowColor = 0;
- }
+ changeColor(cMap[9-mRainbowColor++])
return newMsg;
default:
break;
@@ -1290,6 +1305,8 @@ std::string ChatWindow::addColors(std::string &msg)
return std::string("##").append(toString(mChatColor - 1)).append(msg);
}
+#undef changeColor
+
void ChatWindow::autoComplete()
{
const int caretPos = mChatInput->getCaretPosition();
@@ -1577,7 +1594,7 @@ void ChatWindow::localPetSay(const std::string &nick, const std::string &text)
Being *pet = nullptr;
if (being)
{
- pet = being->getPet();
+ pet = being->getFirstPet();
if (pet)
pet->setSpeech(text, GENERAL_CHANNEL);
}
@@ -1601,7 +1618,7 @@ void ChatWindow::localPetEmote(const std::string &nick, const uint8_t emoteId)
nick, ActorSprite::PLAYER);
if (being)
{
- Being *const pet = being->getPet();
+ Being *const pet = being->getFirstPet();
if (pet)
pet->setEmote(emoteId, 0);
}
diff --git a/src/gui/windows/editdialog.cpp b/src/gui/windows/editdialog.cpp
index 502b71ecb..5c002212f 100644
--- a/src/gui/windows/editdialog.cpp
+++ b/src/gui/windows/editdialog.cpp
@@ -35,9 +35,9 @@ EditDialog::EditDialog(const std::string &restrict title,
Window(title, modal, parent, "edit.xml"),
gcn::ActionListener(),
mEventOk(eventOk),
- mTextField(new TextField(this)),
- mDefaultWidth(width)
+ mTextField(new TextField(this))
{
+ mDefaultWidth = width;
mTextField->setText(msg);
}
diff --git a/src/gui/windows/editdialog.h b/src/gui/windows/editdialog.h
index 74242ed52..fa4a02bf7 100644
--- a/src/gui/windows/editdialog.h
+++ b/src/gui/windows/editdialog.h
@@ -66,7 +66,6 @@ class EditDialog final : public Window, public gcn::ActionListener
private:
std::string mEventOk;
TextField *mTextField;
- int mDefaultWidth;
};
#endif // GUI_WINDOWS_EDITDIALOG_H
diff --git a/src/gui/windows/equipmentwindow.h b/src/gui/windows/equipmentwindow.h
index 1877d1309..d291a5f81 100644
--- a/src/gui/windows/equipmentwindow.h
+++ b/src/gui/windows/equipmentwindow.h
@@ -115,7 +115,7 @@ class EquipmentWindow final : public Window, public gcn::ActionListener
void addBox(const int idx, int x, int y, const int imageIndex);
- void loadWindow(const XmlNodePtr windowNode);
+ void loadWindow(const XmlNodePtrConst windowNode);
void loadPlayerBox(const XmlNodePtr playerBoxNode);
diff --git a/src/gui/windows/ministatuswindow.cpp b/src/gui/windows/ministatuswindow.cpp
index cfc8f1e12..b5832c7b7 100644
--- a/src/gui/windows/ministatuswindow.cpp
+++ b/src/gui/windows/ministatuswindow.cpp
@@ -485,7 +485,7 @@ void MiniStatusWindow::loadBars()
if (mStatusBar)
mStatusBar->setVisible(false);
if (mJobBar)
- mJobBar->setVisible(false);
+ mJobBar->setVisible(true);
return;
}
diff --git a/src/gui/windows/npcdialog.h b/src/gui/windows/npcdialog.h
index af68594cd..5e679d7d1 100644
--- a/src/gui/windows/npcdialog.h
+++ b/src/gui/windows/npcdialog.h
@@ -212,6 +212,9 @@ class NpcDialog final : public Window,
void mousePressed(gcn::MouseEvent &event);
+ int isCloseState() const
+ { return mActionState == NPC_ACTION_CLOSE; }
+
static void copyToClipboard(const int npcId, const int x, const int y);
static NpcDialogs mNpcDialogs;
diff --git a/src/gui/windows/questswindow.cpp b/src/gui/windows/questswindow.cpp
index 0cd04dbc1..e5f599f0f 100644
--- a/src/gui/windows/questswindow.cpp
+++ b/src/gui/windows/questswindow.cpp
@@ -41,6 +41,8 @@
#include "utils/translation/podict.h"
+#include "resources/beingcommon.h"
+
#include "debug.h"
enum QuestType
@@ -181,7 +183,9 @@ QuestsWindow::QuestsWindow() :
loadWindowState();
enableVisibleSound(true);
- loadXml();
+ loadXmlFile(paths.getStringValue("questsFile"));
+ loadXmlFile(paths.getStringValue("questsPatchFile"));
+ loadXmlDir("questsPatchDir", loadXmlFile);
}
QuestsWindow::~QuestsWindow()
@@ -218,16 +222,23 @@ QuestsWindow::~QuestsWindow()
}
}
-void QuestsWindow::loadXml()
+void QuestsWindow::loadXmlFile(const std::string &fileName)
{
- XML::Document doc(paths.getStringValue("questsFile"));
- const XmlNodePtr root = doc.rootNode();
+ XML::Document doc(fileName);
+ const XmlNodePtrConst root = doc.rootNode();
if (!root)
return;
for_each_xml_child_node(varNode, root)
{
- if (xmlNameEqual(varNode, "var"))
+ if (xmlNameEqual(varNode, "include"))
+ {
+ const std::string name = XML::getProperty(varNode, "name", "");
+ if (!name.empty())
+ loadXmlFile(name);
+ continue;
+ }
+ else if (xmlNameEqual(varNode, "var"))
{
const int id = XML::getProperty(varNode, "id", 0);
if (id < 0)
diff --git a/src/gui/windows/questswindow.h b/src/gui/windows/questswindow.h
index 5b008e93e..7ecc86c84 100644
--- a/src/gui/windows/questswindow.h
+++ b/src/gui/windows/questswindow.h
@@ -72,7 +72,7 @@ class QuestsWindow final : public Window,
void addEffect(Being *const being);
private:
- void loadXml();
+ void loadXmlFile(const std::string &fileName);
void loadQuest(const int var, const XmlNodePtr node);
diff --git a/src/gui/windows/serverdialog.cpp b/src/gui/windows/serverdialog.cpp
index 971f3c5a5..2a1ec8314 100644
--- a/src/gui/windows/serverdialog.cpp
+++ b/src/gui/windows/serverdialog.cpp
@@ -394,7 +394,10 @@ void ServerDialog::connectToSelectedServer()
if (!LoginDialog::savedPasswordKey.empty())
{
if (mServerInfo->hostname != LoginDialog::savedPasswordKey)
+ {
LoginDialog::savedPassword.clear();
+ client->reloadWallpaper();
+ }
}
config.setValue("usePersistentIP",
diff --git a/src/gui/windows/setup.cpp b/src/gui/windows/setup.cpp
index 995e6beac..d0ecc2d6d 100644
--- a/src/gui/windows/setup.cpp
+++ b/src/gui/windows/setup.cpp
@@ -32,13 +32,14 @@
#include "gui/widgets/tabs/setup_audio.h"
#include "gui/widgets/tabs/setup_chat.h"
#include "gui/widgets/tabs/setup_colors.h"
+#include "gui/widgets/tabs/setup_input.h"
#include "gui/widgets/tabs/setup_joystick.h"
+#include "gui/widgets/tabs/setup_mods.h"
#include "gui/widgets/tabs/setup_other.h"
-#include "gui/widgets/tabs/setup_theme.h"
-#include "gui/widgets/tabs/setup_input.h"
#include "gui/widgets/tabs/setup_perfomance.h"
#include "gui/widgets/tabs/setup_players.h"
#include "gui/widgets/tabs/setup_relations.h"
+#include "gui/widgets/tabs/setup_theme.h"
#include "gui/widgets/tabs/setup_touch.h"
#include "gui/widgets/tabs/setup_video.h"
#include "gui/widgets/tabs/setup_visual.h"
@@ -58,6 +59,7 @@ Setup::Setup() :
Window(_("Setup"), false, nullptr, "setup.xml"),
gcn::ActionListener(),
mTabs(),
+ mModsTab(nullptr),
mWindowsToReset(),
mButtons(),
mResetWindows(nullptr),
@@ -201,6 +203,10 @@ void Setup::setInGame(const bool inGame)
void Setup::externalUpdate()
{
+ unloadModTab();
+ 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)
@@ -208,6 +214,28 @@ void Setup::externalUpdate()
}
}
+void Setup::unloadModTab()
+{
+ if (mModsTab)
+ {
+ mTabs.remove(mModsTab);
+ Tab *const tab = mPanel->getTab(mModsTab->getName());
+ mPanel->removeTab(tab);
+ delete mModsTab;
+ mModsTab = nullptr;
+ }
+}
+
+void Setup::externalUnload()
+{
+ FOR_EACH (std::list<SetupTab*>::const_iterator, it, mTabs)
+ {
+ if (*it)
+ (*it)->externalUnloaded();
+ }
+ unloadModTab();
+}
+
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..4c9ab2fb7 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()
@@ -71,7 +73,10 @@ class Setup final : public Window, public gcn::ActionListener
void widgetResized(const gcn::Event &event) override final;
private:
+ void unloadModTab();
+
std::list<SetupTab*> mTabs;
+ SetupTab *mModsTab;
std::list<Window*> mWindowsToReset;
std::vector<Button*> mButtons;
Button *mResetWindows;
diff --git a/src/gui/windows/skilldialog.cpp b/src/gui/windows/skilldialog.cpp
index fc44fdf65..197c60a90 100644
--- a/src/gui/windows/skilldialog.cpp
+++ b/src/gui/windows/skilldialog.cpp
@@ -51,6 +51,8 @@
#include "utils/dtor.h"
#include "utils/gettext.h"
+#include "resources/beingcommon.h"
+
#include <guichan/font.hpp>
#include "debug.h"
@@ -62,14 +64,14 @@ class SkillListBox final : public ListBox
ListBox(widget, model, "skilllistbox.xml"),
mModel(model),
mPopup(new TextPopup),
- mHighlightColor(getThemeColor(Theme::HIGHLIGHT)),
mTextColor(getThemeColor(Theme::TEXT)),
mTextColor2(getThemeColor(Theme::TEXT_OUTLINE)),
mTextPadding(mSkin ? mSkin->getOption("textPadding", 34) : 34),
mSpacing(mSkin ? mSkin->getOption("spacing", 0) : 0),
- mRowHeight(getFont()->getHeight() * 2 + mSpacing + 2 * mPadding),
mSkillClicked(false)
{
+ mRowHeight = getFont()->getHeight() * 2 + mSpacing + 2 * mPadding;
+ mHighlightColor = getThemeColor(Theme::HIGHLIGHT);
mPopup->postInit();
if (mRowHeight < 34)
@@ -231,12 +233,10 @@ class SkillListBox final : public ListBox
private:
SkillModel *mModel;
TextPopup *mPopup;
- gcn::Color mHighlightColor;
gcn::Color mTextColor;
gcn::Color mTextColor2;
int mTextPadding;
int mSpacing;
- int mRowHeight;
bool mSkillClicked;
};
@@ -429,75 +429,41 @@ void SkillDialog::clearSkills()
void SkillDialog::loadSkills()
{
clearSkills();
+ loadXmlFile(paths.getStringValue("skillsFile"));
+ if (mSkills.empty())
+ loadXmlFile(paths.getStringValue("skillsFile2"));
+ loadXmlFile(paths.getStringValue("skillsPatchFile"));
+ loadXmlDir("skillsPatchDir", loadXmlFile);
- XML::Document doc(paths.getStringValue("skillsFile"));
- XML::Document doc2(paths.getStringValue("skillsFile2"));
- XmlNodePtr root = doc.rootNode();
+ update();
+}
- int setCount = 0;
- std::string setName;
- ScrollArea *scroll;
- SkillListBox *listbox;
- SkillTab *tab;
+void SkillDialog::loadXmlFile(const std::string &fileName)
+{
+ XML::Document doc(fileName);
+ XmlNodePtrConst root = doc.rootNode();
- if (!root || !xmlNameEqual(root, "skills"))
- root = doc2.rootNode();
+ int setCount = 0;
if (!root || !xmlNameEqual(root, "skills"))
{
- logger->log("Error loading skills");
-
-#ifdef MANASERV_SUPPORT
- if (Net::getNetworkType() != ServerInfo::MANASERV)
-#endif
- {
- SkillModel *const model = new SkillModel();
- if (!mDefaultModel)
- mDefaultModel = model;
-
- SkillInfo *const skill = new SkillInfo;
- skill->id = 1;
- // TRANSLATORS: skills dialog default skills tab
- skill->data->name = _("basic");
- skill->data->description.clear();
- // TRANSLATORS: skills dialog default skill name
- skill->data->dispName = _("basic, 1");
- skill->data->shortName = "bas";
- skill->data->setIcon("");
- skill->modifiable = true;
- skill->visible = true;
- skill->model = model;
- skill->update();
-
- model->addSkill(skill);
- mSkills[1] = skill;
-
- model->updateVisibilities();
-
- listbox = new SkillListBox(this, model);
- listbox->postInit();
- listbox->setActionEventId("sel");
- listbox->addActionListener(this);
- scroll = new ScrollArea(listbox, false);
- scroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- scroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS);
-
- tab = new SkillTab(this, "Skills", listbox);
- mDeleteTabs.push_back(tab);
-
- mTabs->addTab(tab, scroll);
-
- update();
- }
+ logger->log("Error loading skills: " + fileName);
return;
}
for_each_xml_child_node(set, root)
{
- if (xmlNameEqual(set, "set"))
+ if (xmlNameEqual(set, "include"))
+ {
+ const std::string name = XML::getProperty(set, "name", "");
+ if (!name.empty())
+ loadXmlFile(name);
+ continue;
+ }
+ else if (xmlNameEqual(set, "set"))
{
setCount++;
- setName = XML::getProperty(set, "name",
+ const std::string setName = XML::getProperty(set, "name",
// TRANSLATORS: skills dialog default skill tab
strprintf(_("Skill Set %d"), setCount));
@@ -575,20 +541,19 @@ void SkillDialog::loadSkills()
model->updateVisibilities();
// possible leak listbox, scroll
- listbox = new SkillListBox(this, model);
+ SkillListBox *const listbox = new SkillListBox(this, model);
listbox->setActionEventId("sel");
listbox->addActionListener(this);
- scroll = new ScrollArea(listbox, false);
+ ScrollArea *const scroll = new ScrollArea(listbox, false);
scroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
scroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS);
- tab = new SkillTab(this, setName, listbox);
+ SkillTab *const tab = new SkillTab(this, setName, listbox);
mDeleteTabs.push_back(tab);
mTabs->addTab(tab, scroll);
}
}
- update();
}
bool SkillDialog::updateSkill(const int id, const int range,
diff --git a/src/gui/windows/skilldialog.h b/src/gui/windows/skilldialog.h
index 600ea4d34..4a6182d38 100644
--- a/src/gui/windows/skilldialog.h
+++ b/src/gui/windows/skilldialog.h
@@ -69,6 +69,8 @@ class SkillDialog final : public Window, public gcn::ActionListener
*/
void update();
+ void loadXmlFile(const std::string &fileName);
+
void clearSkills();
void loadSkills();
diff --git a/src/gui/windows/updaterwindow.cpp b/src/gui/windows/updaterwindow.cpp
index 099142cbe..584f8e90e 100644
--- a/src/gui/windows/updaterwindow.cpp
+++ b/src/gui/windows/updaterwindow.cpp
@@ -39,6 +39,8 @@
#include "resources/resourcemanager.h"
+#include "resources/db/moddb.h"
+
#include "utils/gettext.h"
#include "utils/mkdir.h"
#include "utils/paths.h"
@@ -58,11 +60,12 @@ const std::string updateServer2
/**
* Load the given file into a vector of updateFiles.
*/
-static std::vector<UpdateFile> loadXMLFile(const std::string &fileName)
+static std::vector<UpdateFile> loadXMLFile(const std::string &fileName,
+ const bool loadMods)
{
std::vector<UpdateFile> files;
XML::Document doc(fileName, false);
- const XmlNodePtr rootNode = doc.rootNode();
+ const XmlNodePtrConst rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "updates"))
{
@@ -72,10 +75,8 @@ static std::vector<UpdateFile> loadXMLFile(const std::string &fileName)
for_each_xml_child_node(fileNode, rootNode)
{
- if (!xmlNameEqual(fileNode, "update"))
- continue;
-
- if (XML::getProperty(fileNode, "group", "default") != "default")
+ const bool isMod = xmlNameEqual(fileNode, "mod");
+ if (!xmlNameEqual(fileNode, "update") && !isMod)
continue;
UpdateFile file;
@@ -83,6 +84,10 @@ static std::vector<UpdateFile> loadXMLFile(const std::string &fileName)
file.hash = XML::getProperty(fileNode, "hash", "");
file.type = XML::getProperty(fileNode, "type", "data");
file.desc = XML::getProperty(fileNode, "description", "");
+ file.group = XML::getProperty(fileNode, "group", "");
+ if (!file.group.empty() && (!isMod || !loadMods))
+ continue;
+
const std::string version = XML::getProperty(
fileNode, "version", "");
if (!version.empty())
@@ -128,6 +133,7 @@ static std::vector<UpdateFile> loadTxtFile(const std::string &fileName)
thisFile.name = name;
thisFile.hash = hash;
thisFile.type = "data";
+ thisFile.group = "";
thisFile.required = true;
thisFile.desc.clear();
@@ -558,7 +564,7 @@ void UpdaterWindow::loadUpdates()
if (mUpdateFiles.empty())
{ // updates not downloaded
mUpdateFiles = loadXMLFile(std::string(mUpdatesDir).append(
- "/").append(xmlUpdateFile));
+ "/").append(xmlUpdateFile), false);
if (mUpdateFiles.empty())
{
logger->log("Warning this server does not have a"
@@ -573,18 +579,22 @@ void UpdaterWindow::loadUpdates()
const unsigned sz = static_cast<unsigned>(mUpdateFiles.size());
for (mUpdateIndex = 0; mUpdateIndex < sz; mUpdateIndex++)
{
- UpdaterWindow::addUpdateFile(resman, mUpdatesDir, fixPath,
- mUpdateFiles[mUpdateIndex].name, false);
+ const UpdateFile &file = mUpdateFiles[mUpdateIndex];
+ if (!file.group.empty())
+ continue;
+ UpdaterWindow::addUpdateFile(resman, mUpdatesDir,
+ fixPath, file.name, false);
}
loadManaPlusUpdates(mUpdatesDir, resman);
+ loadMods(mUpdatesDir, resman, mUpdateFiles);
}
void UpdaterWindow::loadLocalUpdates(const std::string &dir)
{
const ResourceManager *const resman = ResourceManager::getInstance();
- std::vector<UpdateFile> updateFiles
- = loadXMLFile(std::string(dir).append("/").append(xmlUpdateFile));
+ std::vector<UpdateFile> updateFiles = loadXMLFile(
+ std::string(dir).append("/").append(xmlUpdateFile), false);
if (updateFiles.empty())
{
@@ -599,17 +609,21 @@ void UpdaterWindow::loadLocalUpdates(const std::string &dir)
for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>(
updateFiles.size()); updateIndex < sz; updateIndex ++)
{
- UpdaterWindow::addUpdateFile(resman, dir, fixPath,
- updateFiles[updateIndex].name, false);
+ const UpdateFile &file = updateFiles[updateIndex];
+ if (!file.group.empty())
+ continue;
+ UpdaterWindow::addUpdateFile(resman, dir,
+ fixPath, file.name, false);
}
loadManaPlusUpdates(dir, resman);
+ loadMods(dir, resman, updateFiles);
}
void UpdaterWindow::unloadUpdates(const std::string &dir)
{
const ResourceManager *const resman = ResourceManager::getInstance();
- std::vector<UpdateFile> updateFiles
- = loadXMLFile(std::string(dir).append("/").append(xmlUpdateFile));
+ std::vector<UpdateFile> updateFiles = loadXMLFile(
+ std::string(dir).append("/").append(xmlUpdateFile), true);
if (updateFiles.empty())
{
@@ -631,19 +645,23 @@ void UpdaterWindow::loadManaPlusUpdates(const std::string &dir,
const ResourceManager *const resman)
{
std::string fixPath = dir + "/fix";
- std::vector<UpdateFile> updateFiles
- = loadXMLFile(std::string(fixPath).append("/").append(xmlUpdateFile));
+ std::vector<UpdateFile> updateFiles = loadXMLFile(
+ std::string(fixPath).append("/").append(xmlUpdateFile), false);
for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>(
updateFiles.size()); updateIndex < sz; updateIndex ++)
{
- std::string name = updateFiles[updateIndex].name;
+ const UpdateFile &file = updateFiles[updateIndex];
+ if (!file.group.empty())
+ continue;
+ const std::string name = file.name;
if (strStartWith(name, "manaplus_"))
{
struct stat statbuf;
- std::string file = std::string(fixPath).append("/").append(name);
- if (!stat(file.c_str(), &statbuf))
- resman->addToSearchPath(file, false);
+ std::string fileName = std::string(fixPath).append(
+ "/").append(name);
+ if (!stat(fileName.c_str(), &statbuf))
+ resman->addToSearchPath(fileName, false);
}
}
}
@@ -652,8 +670,8 @@ void UpdaterWindow::unloadManaPlusUpdates(const std::string &dir,
const ResourceManager *const resman)
{
const std::string fixPath = dir + "/fix";
- const std::vector<UpdateFile> updateFiles
- = loadXMLFile(std::string(fixPath).append("/").append(xmlUpdateFile));
+ const std::vector<UpdateFile> updateFiles = loadXMLFile(
+ std::string(fixPath).append("/").append(xmlUpdateFile), true);
for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>(
updateFiles.size()); updateIndex < sz; updateIndex ++)
@@ -780,7 +798,7 @@ void UpdaterWindow::logic()
if (mCurrentFile == xmlUpdateFile)
{
mUpdateFiles = loadXMLFile(std::string(mUpdatesDir).append(
- "/").append(xmlUpdateFile));
+ "/").append(xmlUpdateFile), true);
if (mUpdateFiles.empty())
{
@@ -869,7 +887,7 @@ void UpdaterWindow::logic()
if (mCurrentFile == xmlUpdateFile)
{
mTempUpdateFiles = loadXMLFile(std::string(
- mUpdatesDir).append("/").append(xmlUpdateFile));
+ mUpdatesDir).append("/").append(xmlUpdateFile), true);
}
mUpdateIndexOffset = mUpdateIndex;
mUpdateIndex = 0;
@@ -956,13 +974,9 @@ void UpdaterWindow::handleLink(const std::string &link,
gcn::MouseEvent *event A_UNUSED)
{
if (strStartWith(link, "http://") || strStartWith(link, "https://"))
- {
openBrowser(link);
- }
else if (link == "news")
- {
loadFile("news");
- }
}
void UpdaterWindow::loadFile(std::string file)
@@ -977,3 +991,104 @@ void UpdaterWindow::loadFile(std::string file)
for (size_t i = 0, sz = lines.size(); i < sz; ++i)
mBrowserBox->addRow(lines[i]);
}
+
+void UpdaterWindow::loadMods(const std::string &dir,
+ const ResourceManager *const resman,
+ const std::vector<UpdateFile> &updateFiles)
+{
+ ModDB::load();
+ std::string modsString = serverConfig.getValue("mods", "");
+ std::set<std::string> modsList;
+ splitToStringSet(modsList, modsString, '|');
+
+ const std::string fixPath = dir + "/fix";
+ for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>(
+ updateFiles.size()); updateIndex < sz; updateIndex ++)
+ {
+ const UpdateFile &file = updateFiles[updateIndex];
+ if (file.group.empty())
+ continue;
+ const std::set<std::string>::const_iterator
+ it = modsList.find(file.group);
+ if (it != modsList.end())
+ {
+ UpdaterWindow::addUpdateFile(resman, dir,
+ fixPath, file.name, false);
+ }
+ }
+
+ std::vector<UpdateFile> updateFiles2 = loadXMLFile(
+ std::string(fixPath).append("/").append(xmlUpdateFile), true);
+
+ for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>(
+ updateFiles2.size()); updateIndex < sz; updateIndex ++)
+ {
+ const UpdateFile &file = updateFiles2[updateIndex];
+ if (file.group.empty())
+ continue;
+ std::string name = file.name;
+ if (strStartWith(name, "manaplus_"))
+ {
+ const std::set<std::string>::const_iterator
+ it = modsList.find(file.group);
+ if (it != modsList.end())
+ {
+ struct stat statbuf;
+ std::string fileName = std::string(fixPath).append(
+ "/").append(name);
+ if (!stat(fileName.c_str(), &statbuf))
+ resman->addToSearchPath(fileName, false);
+ }
+ }
+ }
+
+ loadDirMods(dir + "/local/");
+}
+
+void UpdaterWindow::loadDirMods(const std::string &dir)
+{
+ ModDB::load();
+ const ResourceManager *const resman = ResourceManager::getInstance();
+ const ModInfos &mods = ModDB::getAll();
+
+ std::string modsString = serverConfig.getValue("mods", "");
+ StringVect modsList;
+ splitToStringVector(modsList, modsString, '|');
+ FOR_EACH (StringVectCIter, it, modsList)
+ {
+ const std::string &name = *it;
+ const ModInfoCIterator modIt = mods.find(name);
+ if (modIt == mods.end())
+ continue;
+ const ModInfo *const mod = (*modIt).second;
+ if (mod)
+ {
+ const std::string localDir = mod->getLocalDir();
+ if (!localDir.empty())
+ resman->addToSearchPath(dir + "/" + localDir, false);
+ }
+ }
+}
+
+void UpdaterWindow::unloadMods(const std::string &dir)
+{
+ const ResourceManager *const resman = ResourceManager::getInstance();
+ const ModInfos &mods = ModDB::getAll();
+ std::string modsString = serverConfig.getValue("mods", "");
+ StringVect modsList;
+ splitToStringVector(modsList, modsString, '|');
+ FOR_EACH (StringVectCIter, it, modsList)
+ {
+ const std::string &name = *it;
+ const ModInfoCIterator modIt = mods.find(name);
+ if (modIt == mods.end())
+ continue;
+ const ModInfo *const mod = (*modIt).second;
+ if (mod)
+ {
+ const std::string localDir = mod->getLocalDir();
+ if (!localDir.empty())
+ resman->removeFromSearchPath(dir + "/" + localDir);
+ }
+ }
+}
diff --git a/src/gui/windows/updaterwindow.h b/src/gui/windows/updaterwindow.h
index 433ab82ad..bddd3ef9e 100644
--- a/src/gui/windows/updaterwindow.h
+++ b/src/gui/windows/updaterwindow.h
@@ -51,6 +51,7 @@ struct UpdateFile final
hash(),
type(),
desc(),
+ group(),
required(false)
{
}
@@ -58,6 +59,7 @@ struct UpdateFile final
std::string hash;
std::string type;
std::string desc;
+ std::string group;
bool required;
};
@@ -151,6 +153,14 @@ class UpdaterWindow final : public Window,
static unsigned long getFileHash(const std::string &filePath);
+ static void loadMods(const std::string &dir,
+ const ResourceManager *const resman,
+ const std::vector<UpdateFile> &updateFiles);
+
+ static void loadDirMods(const std::string &dir);
+
+ static void unloadMods(const std::string &dir);
+
private:
void download();