Compare commits

...

6 commits

10 changed files with 169 additions and 34 deletions

View file

@ -127,8 +127,8 @@ class Application: public Platform::Sdl2Application, public efsw::FileWatchListe
void drawMaterialRow(Containers::StringView name, std::int32_t tier, GameData::MaterialID id);
void drawUnavailableMaterialRow(Containers::StringView name, std::int32_t tier);
void drawMassManager();
auto drawDeleteMassPopup(int mass_index) -> ImGuiID;
auto drawDeleteStagedMassPopup(Containers::StringView filename) -> ImGuiID;
void drawDeleteMassPopup(int mass_index);
void drawDeleteStagedMassPopup(Containers::StringView filename);
void drawMassViewer();
void drawFrameInfo();

View file

@ -16,6 +16,7 @@
#include <algorithm>
#include <Corrade/Containers/ScopeGuard.h>
#include <Corrade/Utility/Format.h>
#include <Corrade/Utility/Path.h>
@ -399,7 +400,6 @@ Application::drawMassManager() {
}
static int mass_to_delete = 0;
static ImGuiID mass_deletion_popup_ID = drawDeleteMassPopup(mass_to_delete);
if(ImGui::BeginTable("##HangarsTable", 4,
ImGuiTableFlags_BordersOuter|ImGuiTableFlags_RowBg|ImGuiTableFlags_ScrollY,
@ -509,9 +509,10 @@ Application::drawMassManager() {
ImGui::SameLine(0.0f, 2.0f);
if(drawUnsafeWidget(ImGui::SmallButton, ICON_FA_TRASH_ALT)) {
mass_to_delete = i;
ImGui::OpenPopup(mass_deletion_popup_ID);
ImGui::OpenPopup("Confirmation##DeleteMassConfirmation");
}
drawTooltip("Delete");
drawDeleteMassPopup(mass_to_delete);
ImGui::PopID();
}
}
@ -521,8 +522,6 @@ Application::drawMassManager() {
drawDeleteMassPopup(mass_to_delete);
// TODO: fix this shit, like with the profile manager.
static ImGuiID staged_mass_deletion_popup_ID = drawDeleteStagedMassPopup("");
static Containers::StringView staged_mass_to_delete;
if(ImGui::BeginTable("##StagingArea", 2,
@ -562,9 +561,10 @@ Application::drawMassManager() {
ImGui::PushID(pair.first.data());
if(ImGui::SmallButton(ICON_FA_TRASH_ALT)) {
staged_mass_to_delete = pair.first;
ImGui::OpenPopup(staged_mass_deletion_popup_ID);
ImGui::OpenPopup("Confirmation##DeleteStagedMassConfirmation");
}
drawTooltip("Delete");
drawDeleteStagedMassPopup(staged_mass_to_delete);
ImGui::PopID();
}
@ -592,24 +592,24 @@ Application::drawMassManager() {
drawDeleteStagedMassPopup(staged_mass_to_delete);
}
ImGuiID
void
Application::drawDeleteMassPopup(int mass_index) {
if(!ImGui::BeginPopupModal("Confirmation##DeleteMassConfirmation", nullptr,
ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove))
{
return ImGui::GetID("Confirmation##DeleteMassConfirmation");
return;
}
Containers::ScopeGuard guard{ImGui::EndPopup};
if(_massManager->hangar(mass_index).state() == GameObjects::Mass::State::Empty) {
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
return 0;
return;
}
if(_gameState != GameState::NotRunning) {
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
return 0;
return;
}
ImGui::PushTextWrapPos(float(windowSize().x()) * 0.40f);
@ -643,18 +643,14 @@ Application::drawDeleteMassPopup(int mass_index) {
ImGui::EndTable();
}
ImGui::EndPopup();
return 0;
}
ImGuiID
void
Application::drawDeleteStagedMassPopup(Containers::StringView filename) {
if(!ImGui::BeginPopupModal("Confirmation##DeleteStagedMassConfirmation", nullptr,
ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove))
{
return ImGui::GetID("Confirmation##DeleteStagedMassConfirmation");
return;
}
ImGui::PushTextWrapPos(float(windowSize().x()) * 0.40f);
@ -684,8 +680,6 @@ Application::drawDeleteStagedMassPopup(Containers::StringView filename) {
}
ImGui::EndPopup();
return 0;
}
}

View file

@ -199,6 +199,8 @@ add_executable(MassBuilderSaveTool
Managers/MassManager.cpp
Managers/ProfileManager.h
Managers/ProfileManager.cpp
Managers/Vfs/VirtualFileSystem.h
Managers/Vfs/VfsDirectory.h
Maps/ArmourSlots.hpp
Maps/BulletLauncherAttachmentStyles.hpp
Maps/BulletLauncherSockets.hpp

View file

@ -20,6 +20,7 @@
#include <chrono>
#include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Containers/Pair.h>
#include <Corrade/Containers/ScopeGuard.h>
#include <Corrade/Utility/Path.h>
#include <Corrade/Utility/String.h>
@ -225,10 +226,12 @@ void
BackupManager::scanSubdir(Containers::StringView subdir) {
static std::uint8_t depth = 0;
auto full_subdir = Utility::Path::join(conf().directories().backups, subdir);
using Flag = Utility::Path::ListFlag;
auto files = Utility::Path::list(conf().directories().backups, Flag::SkipDirectories|Flag::SkipSpecial);
auto files = Utility::Path::list(full_subdir, Flag::SkipDirectories|Flag::SkipSpecial);
if(!files) {
LOG_ERROR_FORMAT("Couldn't list contents of {}.", conf().directories().backups);
LOG_ERROR_FORMAT("Couldn't list contents of {}.", full_subdir);
}
auto predicate = [](Containers::StringView file)->bool{
@ -243,7 +246,9 @@ BackupManager::scanSubdir(Containers::StringView subdir) {
Backup backup;
backup.filename = Utility::Path::join(subdir, file);
zip = zip_open(Utility::Path::join(conf().directories().backups, file).data(), ZIP_RDONLY, &error_code);
auto full_path = Utility::Path::join(full_subdir, file);
zip = zip_open(full_path.cbegin(), ZIP_RDONLY, &error_code);
if(zip == nullptr) {
continue;
}
@ -301,16 +306,15 @@ BackupManager::scanSubdir(Containers::StringView subdir) {
arrayAppend(_backups, Utility::move(backup));
}
auto subdirs = Utility::Path::list(conf().directories().backups,
Flag::SkipFiles|Flag::SkipSpecial|Flag::SkipDotAndDotDot);
if(!subdirs) {
LOG_ERROR_FORMAT("Couldn't list contents of {}.", conf().directories().backups);
}
if(depth == 5) {
return;
}
auto subdirs = Utility::Path::list(full_subdir, Flag::SkipFiles|Flag::SkipSpecial|Flag::SkipDotAndDotDot);
if(!subdirs) {
LOG_ERROR_FORMAT("Couldn't list contents of {}.", full_subdir);
}
depth++;
for(auto& dir : *subdirs) {

View file

@ -32,7 +32,7 @@ namespace mbst { namespace Managers {
class BackupManager {
public:
BackupManager();
explicit BackupManager();
auto lastError() -> Containers::StringView;

View file

@ -0,0 +1,88 @@
#pragma once
// MassBuilderSaveTool
// Copyright (C) 2021-2024 Guillaume Jacquemin
//
// 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 3 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 <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringView.h>
using namespace Corrade;
namespace mbst { namespace Managers { namespace Vfs {
CORRADE_HAS_TYPE(HasFilename, decltype(T::filename));
template<typename FileType>
class VfsDirectory {
public:
static_assert(HasFilename<FileType>::value && (std::is_same<decltype(FileType::filename), Containers::String>::value || std::is_same<decltype(FileType::filename), Containers::StringView>::value),
"FileType has no string-like member named filename.");
using DirType = VfsDirectory<FileType>;
explicit VfsDirectory(Containers::StringView name): _name{name} {
// ctor
}
VfsDirectory(const VfsDirectory<FileType>& other) = delete;
VfsDirectory& operator=(const VfsDirectory<FileType>& other) = delete;
VfsDirectory(VfsDirectory<FileType>&& other) = default;
VfsDirectory& operator=(VfsDirectory<FileType>&& other) = default;
auto name() const -> Containers::StringView {
return _name;
}
auto subdirs() const -> Containers::ArrayView<const DirType> {
return _subdirs;
}
auto files() const -> Containers::ArrayView<const FileType*> {
return _files;
}
protected:
void buildNestedPath(VfsDirectory<FileType>& root, Containers::ArrayView<const Containers::MutableStringView> components,
FileType& file)
{
if(components.size() > 1) {
bool found = false;
for(auto& subdir : root._subdirs) {
if(subdir._name == components[0]) {
found = true;
buildNestedPath(subdir, components.exceptPrefix(1), file);
break;
}
}
if(!found) {
arrayAppend(root._subdirs, InPlaceInit, components[0]);
buildNestedPath(root._subdirs.back(), components.exceptPrefix(1), file);
}
}
else if(components.size() == 1) {
arrayAppend(root._files, &file);
}
}
Containers::String _name;
Containers::Array<DirType> _subdirs;
Containers::Array<FileType*> _files;
};
}}}

View file

@ -0,0 +1,47 @@
#pragma once
// MassBuilderSaveTool
// Copyright (C) 2021-2024 Guillaume Jacquemin
//
// 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 3 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 <https://www.gnu.org/licenses/>.
#include "VfsDirectory.h"
namespace mbst { namespace Managers { namespace Vfs {
template<typename FileType>
class VirtualFileSystem: public VfsDirectory<FileType> {
public:
explicit VirtualFileSystem():
VfsDirectory<FileType>("")
{
// ctor
}
explicit VirtualFileSystem(Containers::ArrayView<FileType> files):
VfsDirectory<FileType>("")
{
build(files);
}
void build(Containers::ArrayView<FileType> files) {
for(auto& file : files) {
auto components = file.filename.split('/');
CORRADE_INTERNAL_ASSERT(components.size() == 0);
VfsDirectory<FileType>::buildNestedPath(*this, components, file);
}
}
};
}}}

2
third-party/corrade vendored

@ -1 +1 @@
Subproject commit 295bbba1f49887da060465f88b8501965f6acd7d
Subproject commit f966f918bd7dec95002921227b6bd68ccbdda113

2
third-party/imgui vendored

@ -1 +1 @@
Subproject commit 4f9ba19e520bea478f5cb654d37ef45e6404bd52
Subproject commit a8e96ae21a4ec10e5f02b19dd865dfffe8a98e67

2
third-party/magnum vendored

@ -1 +1 @@
Subproject commit 8538610fa27e1db37070eaabe34f1e4e41648bab
Subproject commit a40020f3fff91dc9c59148f52adb0d48203799eb