1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
/*
===========================================================================
blockattack - Block Attack - Rise of the Blocks
Copyright (C) 2005-2022 Poul Sander
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
(at your option) 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/
Source information and contacts persons can be found at
https://blockattack.net
===========================================================================
*/
#include "DialogBox.hpp"
#include "HelpModInfoState.hpp"
#include "global.hpp"
#include "common.h"
#include "sago/SagoMisc.hpp"
#include "os.hpp"
#include <boost/algorithm/string/predicate.hpp>
#include <sstream>
struct Mod {
std::string name;
std::string filename;
bool enabled = false;
int order = 0;
};
static bool sort_mods_enabled_order (const Mod& i,const Mod& j) {
if (i.enabled && !j.enabled) {
//Enabled mods always goes before disabled ones
return true;
}
if (i.enabled) {
return i.order < j.order;
}
return i.name < j.name;
}
static void initMods(std::vector<Mod>& mod_list) {
for (size_t i=0; i < globalData.modList.size(); ++i) {
for (Mod& m : mod_list) {
if (m.name == globalData.modList[i]) {
m.order = i;
m.enabled = true;
}
}
}
std::sort(mod_list.begin(), mod_list.end(), sort_mods_enabled_order);
std::vector<Mod> mod_list_no_duplicates;
std::string last_mod = "";
for (const Mod& m : mod_list) {
if (m.name != last_mod) {
mod_list_no_duplicates.push_back(m);
}
last_mod = m.name;
}
std::swap(mod_list, mod_list_no_duplicates);
}
static void appendMods(const std::vector<std::string>& mod_files, const std::string& dir, std::vector<Mod>& mods_available) {
for (const std::string& mod : mod_files) {
if (!boost::ends_with(mod, ".data")) {
continue;
}
Mod m;
m.name = mod.substr(0, mod.length()-5);
m.filename = dir + "/" + mod;
mods_available.push_back(m);
}
}
static std::vector<Mod> get_mods() {
std::vector<Mod> mods_available;
std::string baseMods = std::string(PHYSFS_getBaseDir())+ "/mods";
std::vector<std::string> baseModFiles = OsGetDirFileList(baseMods);
appendMods(baseModFiles, baseMods, mods_available);
std::string sharedMods = std::string(SHAREDIR)+ "/mods";
std::vector<std::string> sharedModFiles = OsGetDirFileList(sharedMods);
appendMods(sharedModFiles, sharedMods, mods_available);
std::string userMods = getPathToSaveFiles()+"/mods";
std::vector<std::string> userModFiles = OsGetDirFileList(userMods);
appendMods(userModFiles, userMods, mods_available);
initMods(mods_available);
return mods_available;
}
HelpModInfoState::HelpModInfoState() {
std::vector<Mod> mods_available = get_mods();
std::stringstream infoStream;
infoStream << _("Load order:") << "\n";
for (size_t i=0; i < mods_available.size(); ++i) {
const Mod& mod = mods_available[i];
if (mod.enabled) {
infoStream << mod.order << " : " << mod.name << " ";
}
else {
infoStream << "- : " << mod.name << " " << _("(Disabled)");
}
infoStream << "\n";
}
setHelp30FontThinOutline(&globalData.spriteHolder->GetDataHolder(), titleField, _("Mod info"));
setHelpBoxFont(&globalData.spriteHolder->GetDataHolder(), infoBox, infoStream.str().c_str());
}
HelpModInfoState::~HelpModInfoState() {
}
|