core.remove_packs
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
# Menu
|
# Menu
|
||||||
menu.missing-content=Missing Content!
|
menu.missing-content=Missing Content!
|
||||||
world.convert-request=Content indices have changed! Convert world files?
|
world.convert-request=Content indices have changed! Convert world files?
|
||||||
pack.remove-confirm=Do you want to erase all pack content from the world forever?
|
pack.remove-confirm=Do you want to erase all pack(s) content from the world forever?
|
||||||
error.pack-not-found=Could not to find pack
|
error.pack-not-found=Could not to find pack
|
||||||
error.dependency-not-found=Dependency pack is not found
|
error.dependency-not-found=Dependency pack is not found
|
||||||
world.delete-confirm=Do you want to delete world forever?
|
world.delete-confirm=Do you want to delete world forever?
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ Converting world...=Выполняется конвертация мира...
|
|||||||
|
|
||||||
error.pack-not-found=Не удалось найти пакет
|
error.pack-not-found=Не удалось найти пакет
|
||||||
error.dependency-not-found=Используемая зависимость не найдена
|
error.dependency-not-found=Используемая зависимость не найдена
|
||||||
pack.remove-confirm=Удалить весь поставляемый паком контент из мира (безвозвратно)?
|
pack.remove-confirm=Удалить весь поставляемый паком/паками контент из мира (безвозвратно)?
|
||||||
|
|
||||||
# Меню
|
# Меню
|
||||||
menu.New World=Новый Мир
|
menu.New World=Новый Мир
|
||||||
|
|||||||
@@ -47,6 +47,12 @@ namespace menus {
|
|||||||
/// @param engine engine instance
|
/// @param engine engine instance
|
||||||
void delete_world(std::string name, Engine* engine);
|
void delete_world(std::string name, Engine* engine);
|
||||||
|
|
||||||
|
void remove_packs(
|
||||||
|
Engine* engine,
|
||||||
|
LevelController* controller,
|
||||||
|
std::vector<std::string> packs
|
||||||
|
);
|
||||||
|
|
||||||
/// @brief Create development version label at the top-right screen corner
|
/// @brief Create development version label at the top-right screen corner
|
||||||
void create_version_label(Engine* engine);
|
void create_version_label(Engine* engine);
|
||||||
void create_menus(Engine* engine);
|
void create_menus(Engine* engine);
|
||||||
|
|||||||
@@ -60,21 +60,23 @@ std::shared_ptr<Container> create_pack_panel(
|
|||||||
if (!pack.creator.empty()) {
|
if (!pack.creator.empty()) {
|
||||||
packpanel->add(guiutil::create(
|
packpanel->add(guiutil::create(
|
||||||
"<label color='#CCFFE5B2' size='300,20' align='right' pos='215,60'>"+
|
"<label color='#CCFFE5B2' size='300,20' align='right' pos='215,60'>"+
|
||||||
pack.creator+
|
pack.creator+
|
||||||
"</label>"
|
"</label>"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto descriptionlabel = std::make_shared<Label>(pack.description);
|
packpanel->add(guiutil::create(
|
||||||
descriptionlabel->setColor(glm::vec4(1, 1, 1, 0.7f));
|
"<label pos='80,28' color='#FFFFFFB2'>" +
|
||||||
packpanel->add(descriptionlabel, glm::vec2(80, 28));
|
pack.description +
|
||||||
|
"</label>"
|
||||||
|
));
|
||||||
|
|
||||||
packpanel->add(std::make_shared<Image>(icon, glm::vec2(64)), glm::vec2(8));
|
packpanel->add(std::make_shared<Image>(icon, glm::vec2(64)), glm::vec2(8));
|
||||||
|
|
||||||
if (remover && pack.id != "base") {
|
if (remover && pack.id != "base") {
|
||||||
auto rembtn = guiutil::create(
|
auto rembtn = guiutil::create(
|
||||||
"<button color='#00000000' hover-color='#FFFFFF2B'>"
|
"<button color='#00000000' hover-color='#FFFFFF2B'>"
|
||||||
" <image src='gui/cross' size='32,32'/>"
|
"<image src='gui/cross' size='32,32'/>"
|
||||||
"</button>"
|
"</button>"
|
||||||
);
|
);
|
||||||
rembtn->listenAction([=](GUI* gui) {
|
rembtn->listenAction([=](GUI* gui) {
|
||||||
@@ -134,6 +136,46 @@ static bool try_add_dependency(Engine* engine, World* world, const ContentPack&
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void menus::remove_packs(
|
||||||
|
Engine* engine,
|
||||||
|
LevelController* controller,
|
||||||
|
std::vector<std::string> packsToRemove
|
||||||
|
) {
|
||||||
|
auto content = engine->getContent();
|
||||||
|
auto world = controller->getLevel()->getWorld();
|
||||||
|
bool hasIndices = false;
|
||||||
|
|
||||||
|
std::stringstream ss;
|
||||||
|
for (const auto& id : packsToRemove) {
|
||||||
|
if (content->getPackRuntime(id)->getStats().hasSavingContent()) {
|
||||||
|
if (hasIndices) {
|
||||||
|
ss << ", ";
|
||||||
|
}
|
||||||
|
hasIndices = true;
|
||||||
|
ss << id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runnable removeFunc = [=]() {
|
||||||
|
controller->saveWorld();
|
||||||
|
for (const auto& id : packsToRemove) {
|
||||||
|
world->wfile->removePack(world, id);
|
||||||
|
}
|
||||||
|
reopen_world(engine, world);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (hasIndices) {
|
||||||
|
guiutil::confirm(
|
||||||
|
engine->getGUI(),
|
||||||
|
langs::get(L"remove-confirm", L"pack")+
|
||||||
|
L" ("+util::str2wstr_utf8(ss.str())+L")",
|
||||||
|
[=]() {removeFunc();}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
removeFunc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void create_content_panel(Engine* engine, LevelController* controller) {
|
void create_content_panel(Engine* engine, LevelController* controller) {
|
||||||
auto level = controller->getLevel();
|
auto level = controller->getLevel();
|
||||||
auto menu = engine->getGUI()->getMenu();
|
auto menu = engine->getGUI()->getMenu();
|
||||||
@@ -149,24 +191,11 @@ void create_content_panel(Engine* engine, LevelController* controller) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto panel = menus::create_packs_panel(
|
auto panel = menus::create_packs_panel(
|
||||||
engine->getContentPacks(), engine, false, nullptr,
|
engine->getContentPacks(), engine, false, nullptr,
|
||||||
[=](const ContentPack& pack) {
|
[=](const ContentPack& pack) {
|
||||||
auto world = level->getWorld();
|
std::vector<std::string> packsToRemove {pack.id};
|
||||||
auto runtime = engine->getContent()->getPackRuntime(pack.id);
|
menus::remove_packs(engine, controller, packsToRemove);
|
||||||
if (runtime->getStats().hasSavingContent()) {
|
|
||||||
guiutil::confirm(engine->getGUI(), langs::get(L"remove-confirm", L"pack")+
|
|
||||||
L" ("+util::str2wstr_utf8(pack.id)+L")", [=]() {
|
|
||||||
controller->saveWorld();
|
|
||||||
world->wfile->removePack(world, pack.id);
|
|
||||||
reopen_world(engine, world);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
controller->saveWorld();
|
|
||||||
world->wfile->removePack(world, pack.id);
|
|
||||||
reopen_world(engine, world);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
mainPanel->add(panel);
|
mainPanel->add(panel);
|
||||||
|
|||||||
@@ -57,6 +57,21 @@ static int l_delete_world(lua_State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_remove_packs(lua_State* L) {
|
||||||
|
if (!lua_istable(L, 1)) {
|
||||||
|
luaL_error(L, "strings array expected as an argument");
|
||||||
|
}
|
||||||
|
std::vector<std::string> packs;
|
||||||
|
int len = lua_objlen(L, 1);
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
lua_rawgeti(L, -1, i+1);
|
||||||
|
packs.push_back(lua_tostring(L, -1));
|
||||||
|
lua_pop(L, 1);
|
||||||
|
}
|
||||||
|
menus::remove_packs(scripting::engine, scripting::controller, packs);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int l_get_bindings(lua_State* L) {
|
static int l_get_bindings(lua_State* L) {
|
||||||
auto& bindings = Events::bindings;
|
auto& bindings = Events::bindings;
|
||||||
lua_createtable(L, bindings.size(), 0);
|
lua_createtable(L, bindings.size(), 0);
|
||||||
@@ -101,6 +116,7 @@ const luaL_Reg corelib [] = {
|
|||||||
{"open_world", lua_wrap_errors<l_open_world>},
|
{"open_world", lua_wrap_errors<l_open_world>},
|
||||||
{"close_world", lua_wrap_errors<l_close_world>},
|
{"close_world", lua_wrap_errors<l_close_world>},
|
||||||
{"delete_world", lua_wrap_errors<l_delete_world>},
|
{"delete_world", lua_wrap_errors<l_delete_world>},
|
||||||
|
{"remove_packs", lua_wrap_errors<l_remove_packs>},
|
||||||
{"get_bindings", lua_wrap_errors<l_get_bindings>},
|
{"get_bindings", lua_wrap_errors<l_get_bindings>},
|
||||||
{"get_setting", lua_wrap_errors<l_get_setting>},
|
{"get_setting", lua_wrap_errors<l_get_setting>},
|
||||||
{"set_setting", lua_wrap_errors<l_set_setting>},
|
{"set_setting", lua_wrap_errors<l_set_setting>},
|
||||||
|
|||||||
Reference in New Issue
Block a user