diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-08-22 14:14:34 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-08-22 14:14:34 +0300 |
commit | da05d9dd98315378bdded216184294f376643191 (patch) | |
tree | ffc4b984c73c3bb68d26a1df6481634254075744 /src/gui | |
parent | ec856b2026c7ceecab5f74942bb36661d7c6ae67 (diff) | |
download | mv-da05d9dd98315378bdded216184294f376643191.tar.gz mv-da05d9dd98315378bdded216184294f376643191.tar.bz2 mv-da05d9dd98315378bdded216184294f376643191.tar.xz mv-da05d9dd98315378bdded216184294f376643191.zip |
Use resource manager as global variable.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/gui.cpp | 3 | ||||
-rw-r--r-- | src/gui/models/langlistmodel.h | 3 | ||||
-rw-r--r-- | src/gui/popups/itempopup.cpp | 7 | ||||
-rw-r--r-- | src/gui/theme.cpp | 17 | ||||
-rw-r--r-- | src/gui/widgets/browserbox.cpp | 6 | ||||
-rw-r--r-- | src/gui/widgets/desktop.cpp | 7 | ||||
-rw-r--r-- | src/gui/widgets/emotepage.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/icon.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/skilldata.cpp | 3 | ||||
-rw-r--r-- | src/gui/windows/mailviewwindow.cpp | 3 | ||||
-rw-r--r-- | src/gui/windows/minimap.cpp | 3 | ||||
-rw-r--r-- | src/gui/windows/npcdialog.cpp | 4 | ||||
-rw-r--r-- | src/gui/windows/updaterwindow.cpp | 81 | ||||
-rw-r--r-- | src/gui/windows/updaterwindow.h | 13 |
14 files changed, 60 insertions, 94 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index e2d6ca054..330f2c54b 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -295,8 +295,7 @@ Gui::~Gui() void Gui::logic() { BLOCK_START("Gui::logic") - ResourceManager *const resman = ResourceManager::getInstance(); - resman->clearScheduled(); + resourceManager->clearScheduled(); if (!mTop) { diff --git a/src/gui/models/langlistmodel.h b/src/gui/models/langlistmodel.h index 62bc15e3e..f442982ff 100644 --- a/src/gui/models/langlistmodel.h +++ b/src/gui/models/langlistmodel.h @@ -84,10 +84,9 @@ class LangListModel final : public ExtendedListModel public: LangListModel() { - ResourceManager *const resman = ResourceManager::getInstance(); for (int f = 0; f < langs_count; f ++) { - mIcons[f] = resman->getImage("graphics/flags/" + mIcons[f] = resourceManager->getImage("graphics/flags/" + LANG_NAME[f].icon); } } diff --git a/src/gui/popups/itempopup.cpp b/src/gui/popups/itempopup.cpp index a97b2480b..a9afe136a 100644 --- a/src/gui/popups/itempopup.cpp +++ b/src/gui/popups/itempopup.cpp @@ -175,10 +175,9 @@ void ItemPopup::setItem(const ItemInfo &item, if (showImage) { - ResourceManager *const resman = ResourceManager::getInstance(); - Image *const image = resman->getImage(combineDye2( - paths.getStringValue("itemIcons").append( - item.getDisplay().image), item.getDyeIconColorsString(color))); + Image *const image = resourceManager->getImage(combineDye2( + paths.getStringValue("itemIcons").append(item.getDisplay().image), + item.getDyeIconColorsString(color))); mIcon->setImage(image); if (image) diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 000994368..90c351476 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -347,8 +347,7 @@ struct SkinHelper final height(), rect(), node(), - image(), - resman() + image() { } @@ -362,7 +361,6 @@ struct SkinHelper final ImageRect *rect; XmlNodePtr *node; Image *image; - ResourceManager *resman; bool loadList(const SkinParameter *const params, const size_t size) A_NONNULL(2) @@ -372,7 +370,7 @@ struct SkinHelper final const SkinParameter ¶m = params[f]; if (partType == param.name) { - rect->grid[param.index] = resman->getSubImage( + rect->grid[param.index] = resourceManager->getSubImage( image, xPos, yPos, width, height); return true; } @@ -430,7 +428,6 @@ Skin *Theme::readSkin(const std::string &filename, const bool full) if (widgetType == "Window") { SkinHelper helper; - helper.resman = ResourceManager::getInstance(); const int globalXPos = XML::getProperty(widgetNode, "xpos", 0); const int globalYPos = XML::getProperty(widgetNode, "ypos", 0); for_each_xml_child_node(partNode, widgetNode) @@ -635,15 +632,13 @@ std::string Theme::resolveThemePath(const std::string &path) Image *Theme::getImageFromTheme(const std::string &path) { - ResourceManager *const resman = ResourceManager::getInstance(); - return resman->getImage(resolveThemePath(path)); + return resourceManager->getImage(resolveThemePath(path)); } ImageSet *Theme::getImageSetFromTheme(const std::string &path, const int w, const int h) { - ResourceManager *const resman = ResourceManager::getInstance(); - return resman->getImageSet(resolveThemePath(path), w, h); + return resourceManager->getImageSet(resolveThemePath(path), w, h); } static int readColorType(const std::string &type) @@ -1143,8 +1138,8 @@ ImageSet *Theme::getImageSetFromThemeXml(const std::string &name, const SDL_Rect &rect2 = image->mBounds; if (rect2.w && rect2.h) { - ResourceManager *const resman = ResourceManager::getInstance(); - ImageSet *const imageSet = resman->getSubImageSet(image, w, h); + ImageSet *const imageSet = resourceManager->getSubImageSet( + image, w, h); theme->unload(skin); return imageSet; } diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index d5eb6b89a..ea6ca7be4 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -121,7 +121,7 @@ BrowserBox::BrowserBox(const Widget2 *const widget, mSkin = theme->load(skin, "browserbox.xml"); if (mInstances == 0) { - mEmotes = ResourceManager::getInstance()->getImageSet( + mEmotes = resourceManager->getImageSet( "graphics/sprites/chatemotes.png", 17, 18); } mInstances ++; @@ -570,8 +570,6 @@ int BrowserBox::calcHeight() Color selColor[2] = {mForegroundColor, mForegroundColor2}; const Color textColor[2] = {mForegroundColor, mForegroundColor2}; - ResourceManager *const resman = ResourceManager::getInstance(); - mLineParts.clear(); FOR_EACH (TextRowCIter, i, mTextRows) @@ -601,7 +599,7 @@ int BrowserBox::calcHeight() const size_t sz = str.size(); if (sz > 2 && str.substr(sz - 1) == "~") str = str.substr(0, sz - 1); - Image *const img = resman->getImage(str); + Image *const img = resourceManager->getImage(str); if (img) { img->incRef(); diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp index 18cb7b138..9fdc11a61 100644 --- a/src/gui/widgets/desktop.cpp +++ b/src/gui/widgets/desktop.cpp @@ -172,10 +172,9 @@ void Desktop::setBestFittingWallpaper() if (nWallPaper) { - ResourceManager *const resman = ResourceManager::getInstance(); if (mWallpaper) { - resman->decRefDelete(mWallpaper); + resourceManager->decRefDelete(mWallpaper); mWallpaper = nullptr; } @@ -188,12 +187,12 @@ void Desktop::setBestFittingWallpaper() || nWallPaper->getHeight() != height)) { // We rescale to obtain a fullscreen wallpaper... - Image *const newRsclWlPpr = resman->getRescaled( + Image *const newRsclWlPpr = resourceManager->getRescaled( nWallPaper, width, height); if (newRsclWlPpr) { - resman->decRefDelete(nWallPaper); + resourceManager->decRefDelete(nWallPaper); // We replace the resource in the resource manager mWallpaper = newRsclWlPpr; } diff --git a/src/gui/widgets/emotepage.cpp b/src/gui/widgets/emotepage.cpp index f40a855ec..7a9eee261 100644 --- a/src/gui/widgets/emotepage.cpp +++ b/src/gui/widgets/emotepage.cpp @@ -39,7 +39,7 @@ EmotePage::EmotePage(const Widget2 *const widget) : Widget(widget), MouseListener(), WidgetListener(), - mEmotes(ResourceManager::getInstance()->getImageSet( + mEmotes(resourceManager->getImageSet( "graphics/sprites/chatemotes.png", emoteWidth, emoteHeight)), mVertexes(new ImageCollection), mSelectedIndex(-1) diff --git a/src/gui/widgets/icon.cpp b/src/gui/widgets/icon.cpp index 4be9ae127..5876b1201 100644 --- a/src/gui/widgets/icon.cpp +++ b/src/gui/widgets/icon.cpp @@ -32,7 +32,7 @@ Icon::Icon(const Widget2 *const widget, const std::string &file) : Widget(widget), - mImage(ResourceManager::getInstance()->getImage(file)) + mImage(resourceManager->getImage(file)) { if (mImage) { diff --git a/src/gui/widgets/skilldata.cpp b/src/gui/widgets/skilldata.cpp index 6137d768b..826d1d719 100644 --- a/src/gui/widgets/skilldata.cpp +++ b/src/gui/widgets/skilldata.cpp @@ -59,9 +59,8 @@ SkillData::~SkillData() void SkillData::setIcon(const std::string &iconPath) { - ResourceManager *const res = ResourceManager::getInstance(); if (!iconPath.empty()) - icon = res->getImage(iconPath); + icon = resourceManager->getImage(iconPath); if (!icon) { diff --git a/src/gui/windows/mailviewwindow.cpp b/src/gui/windows/mailviewwindow.cpp index 1ba871cd6..5e2159f5f 100644 --- a/src/gui/windows/mailviewwindow.cpp +++ b/src/gui/windows/mailviewwindow.cpp @@ -107,10 +107,9 @@ MailViewWindow::MailViewWindow(const MailMessage *const message) : placer(0, n++, mMessageLabel); if (message->itemId) { - ResourceManager *const resman = ResourceManager::getInstance(); const ItemInfo &item = ItemDB::get(message->itemId); // +++ need use message->cards and ItemColorManager for colors - Image *const image = resman->getImage(combineDye2( + Image *const image = resourceManager->getImage(combineDye2( paths.getStringValue("itemIcons").append( item.getDisplay().image), item.getDyeIconColorsString(ItemColor_one))); diff --git a/src/gui/windows/minimap.cpp b/src/gui/windows/minimap.cpp index 502ebf91a..06531c69b 100644 --- a/src/gui/windows/minimap.cpp +++ b/src/gui/windows/minimap.cpp @@ -168,7 +168,6 @@ void Minimap::setMap(const Map *const map) { std::string tempname = paths.getStringValue("minimaps").append( map->getFilename()).append(".png"); - ResourceManager *const resman = ResourceManager::getInstance(); std::string minimapName = map->getProperty("minimap"); @@ -183,7 +182,7 @@ void Minimap::setMap(const Map *const map) minimapName = tempname; } - mMapImage = resman->getImage(minimapName); + mMapImage = resourceManager->getImage(minimapName); mCustomMapImage = false; } } diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp index 992fd7e9c..bda9b3039 100644 --- a/src/gui/windows/npcdialog.cpp +++ b/src/gui/windows/npcdialog.cpp @@ -597,8 +597,6 @@ void NpcDialog::addChoice(const std::string &choice) void NpcDialog::parseListItems(const std::string &itemString) { std::istringstream iss(itemString); - ResourceManager *const resman = ResourceManager::getInstance(); - std::string tmp; const std::string path = paths.getStringValue("guiIcons"); while (getline(iss, tmp, ':')) @@ -614,7 +612,7 @@ void NpcDialog::parseListItems(const std::string &itemString) else { mItems.push_back(tmp.substr(pos + 1)); - Image *const img = resman->getImage(std::string( + Image *const img = resourceManager->getImage(std::string( path).append(tmp.substr(0, pos)).append(".png")); mImages.push_back(img); } diff --git a/src/gui/windows/updaterwindow.cpp b/src/gui/windows/updaterwindow.cpp index 9330539ab..79dfe29aa 100644 --- a/src/gui/windows/updaterwindow.cpp +++ b/src/gui/windows/updaterwindow.cpp @@ -639,7 +639,6 @@ void UpdaterWindow::download() void UpdaterWindow::loadUpdates() { - const ResourceManager *const resman = ResourceManager::getInstance(); if (mUpdateFiles.empty()) { // updates not downloaded mUpdateFiles = loadXMLFile(std::string(mUpdatesDir).append( @@ -661,17 +660,17 @@ void UpdaterWindow::loadUpdates() const UpdateFile &file = mUpdateFiles[mUpdateIndex]; if (!file.group.empty()) continue; - UpdaterWindow::addUpdateFile(resman, mUpdatesDir, - fixPath, file.name, false); + UpdaterWindow::addUpdateFile(mUpdatesDir, + fixPath, + file.name, + false); } - loadManaPlusUpdates(mUpdatesDir, resman); - loadMods(mUpdatesDir, resman, mUpdateFiles); + loadManaPlusUpdates(mUpdatesDir); + loadMods(mUpdatesDir, 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), false); @@ -691,16 +690,17 @@ void UpdaterWindow::loadLocalUpdates(const std::string &dir) const UpdateFile &file = updateFiles[updateIndex]; if (!file.group.empty()) continue; - UpdaterWindow::addUpdateFile(resman, dir, - fixPath, file.name, false); + UpdaterWindow::addUpdateFile(dir, + fixPath, + file.name, + false); } - loadManaPlusUpdates(dir, resman); - loadMods(dir, resman, updateFiles); + loadManaPlusUpdates(dir); + loadMods(dir, 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), true); @@ -714,17 +714,15 @@ void UpdaterWindow::unloadUpdates(const std::string &dir) for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>( updateFiles.size()); updateIndex < sz; updateIndex ++) { - UpdaterWindow::removeUpdateFile(resman, dir, fixPath, + UpdaterWindow::removeUpdateFile(dir, + fixPath, updateFiles[updateIndex].name); } - unloadManaPlusUpdates(dir, resman); + unloadManaPlusUpdates(dir); } -void UpdaterWindow::loadManaPlusUpdates(const std::string &dir, - const ResourceManager *const resman) +void UpdaterWindow::loadManaPlusUpdates(const std::string &dir) { - if (!resman) - return; std::string fixPath = dir + "/fix"; std::vector<UpdateFile> updateFiles = loadXMLFile( std::string(fixPath).append("/").append(xmlUpdateFile), false); @@ -742,16 +740,13 @@ void UpdaterWindow::loadManaPlusUpdates(const std::string &dir, std::string fileName = std::string(fixPath).append( "/").append(name); if (!stat(fileName.c_str(), &statbuf)) - resman->addToSearchPath(fileName, false); + resourceManager->addToSearchPath(fileName, false); } } } -void UpdaterWindow::unloadManaPlusUpdates(const std::string &dir, - const ResourceManager *const resman) +void UpdaterWindow::unloadManaPlusUpdates(const std::string &dir) { - if (!resman) - return; const std::string fixPath = dir + "/fix"; const std::vector<UpdateFile> updateFiles = loadXMLFile( std::string(fixPath).append("/").append(xmlUpdateFile), true); @@ -766,44 +761,39 @@ void UpdaterWindow::unloadManaPlusUpdates(const std::string &dir, const std::string file = std::string( fixPath).append("/").append(name); if (!stat(file.c_str(), &statbuf)) - resman->removeFromSearchPath(file); + resourceManager->removeFromSearchPath(file); } } } -void UpdaterWindow::addUpdateFile(const ResourceManager *const resman, - const std::string &restrict path, +void UpdaterWindow::addUpdateFile(const std::string &restrict path, const std::string &restrict fixPath, const std::string &restrict file, const bool append) { - if (!resman) - return; const std::string tmpPath = std::string(path).append("/").append(file); if (!append) - resman->addToSearchPath(tmpPath, append); + resourceManager->addToSearchPath(tmpPath, append); const std::string fixFile = std::string(fixPath).append("/").append(file); struct stat statbuf; if (!stat(fixFile.c_str(), &statbuf)) - resman->addToSearchPath(fixFile, append); + resourceManager->addToSearchPath(fixFile, append); if (append) - resman->addToSearchPath(tmpPath, append); + resourceManager->addToSearchPath(tmpPath, append); } -void UpdaterWindow::removeUpdateFile(const ResourceManager *const resman, - const std::string &restrict path, +void UpdaterWindow::removeUpdateFile(const std::string &restrict path, const std::string &restrict fixPath, const std::string &restrict file) { - if (!resman) - return; - resman->removeFromSearchPath(std::string(path).append("/").append(file)); + resourceManager->removeFromSearchPath( + std::string(path).append("/").append(file)); const std::string fixFile = std::string(fixPath).append("/").append(file); struct stat statbuf; if (!stat(fixFile.c_str(), &statbuf)) - resman->removeFromSearchPath(fixFile); + resourceManager->removeFromSearchPath(fixFile); } void UpdaterWindow::logic() @@ -1086,11 +1076,8 @@ void UpdaterWindow::loadFile(std::string file) } void UpdaterWindow::loadMods(const std::string &dir, - const ResourceManager *const resman, const std::vector<UpdateFile> &updateFiles) { - if (!resman) - return; ModDB::load(); std::string modsString = serverConfig.getValue("mods", ""); std::set<std::string> modsList; @@ -1107,8 +1094,10 @@ void UpdaterWindow::loadMods(const std::string &dir, it = modsList.find(file.group); if (it != modsList.end()) { - UpdaterWindow::addUpdateFile(resman, dir, - fixPath, file.name, false); + UpdaterWindow::addUpdateFile(dir, + fixPath, + file.name, + false); } } @@ -1132,7 +1121,7 @@ void UpdaterWindow::loadMods(const std::string &dir, std::string fileName = std::string(fixPath).append( "/").append(name); if (!stat(fileName.c_str(), &statbuf)) - resman->addToSearchPath(fileName, false); + resourceManager->addToSearchPath(fileName, false); } } } @@ -1143,7 +1132,6 @@ void UpdaterWindow::loadMods(const std::string &dir, 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", ""); @@ -1160,14 +1148,13 @@ void UpdaterWindow::loadDirMods(const std::string &dir) { const std::string &localDir = mod->getLocalDir(); if (!localDir.empty()) - resman->addToSearchPath(dir + "/" + localDir, false); + resourceManager->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; @@ -1183,7 +1170,7 @@ void UpdaterWindow::unloadMods(const std::string &dir) { const std::string &localDir = mod->getLocalDir(); if (!localDir.empty()) - resman->removeFromSearchPath(dir + "/" + localDir); + resourceManager->removeFromSearchPath(dir + "/" + localDir); } } } diff --git a/src/gui/windows/updaterwindow.h b/src/gui/windows/updaterwindow.h index 7c70817b0..be8b67938 100644 --- a/src/gui/windows/updaterwindow.h +++ b/src/gui/windows/updaterwindow.h @@ -122,27 +122,22 @@ class UpdaterWindow final : public Window, static void unloadUpdates(const std::string &dir); - static void addUpdateFile(const ResourceManager *const resman, - const std::string &restrict path, + static void addUpdateFile(const std::string &restrict path, const std::string &restrict fixPath, const std::string &restrict file, const bool append); - static void removeUpdateFile(const ResourceManager *const resman, - const std::string &restrict path, + static void removeUpdateFile(const std::string &restrict path, const std::string &restrict fixPath, const std::string &filerestrict); - static void loadManaPlusUpdates(const std::string &dir, - const ResourceManager *const resman); + static void loadManaPlusUpdates(const std::string &dir); - static void unloadManaPlusUpdates(const std::string &dir, - const ResourceManager *const resman); + static void unloadManaPlusUpdates(const std::string &dir); 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); |