Skip to content

Commit

Permalink
Use tinyfiledialogs for dialogs (should enable us to compile for linu…
Browse files Browse the repository at this point in the history
…x, mac, etc.)
  • Loading branch information
WSSDude committed Oct 15, 2023
1 parent 76d708a commit abe10f1
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 233 deletions.
19 changes: 19 additions & 0 deletions LICENSE_ThirdParty.md
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,25 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
See the License for the specific language governing permissions and
limitations under the License.

# tiny file dialogs
Copyright (c) 2014 - 2023 Guillaume Vareille http://ysengrin.com

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.

# toml++
MIT License

Expand Down
16 changes: 8 additions & 8 deletions data/localization/English.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ARCHIVE_DIALOG_PROCESSING = "Processing..."
ARCHIVE_DIALOG_PROGRESS_SUMMARY = "Currently processing item {} from {}..."
ARCHIVE_DIALOG_NO_ARCHIVE = "There is currently no opened archive."
ARCHIVE_DIALOG_FILE_MENU = "File"
SDL2_INITIALIZATION_ERROR = "Couldn't initialize SDL2!\n\"{}\""
SDL2_INITIALIZATION_ERROR = "Couldnt initialize SDL2!\n\"{}\""
MESSAGEBOX_TITLE_ERROR = "Error"
MESSAGEBOX_TITLE_WARNING = "Warning"
MESSAGEBOX_TITLE_INFORMATION = "Information"
Expand All @@ -30,14 +30,14 @@ MESSAGEBOX_BUTTON_CANCEL = "Cancel"
HITMAN_DIALOG_LOADING_ORIGINAL_RECORDS = "Loading the original records..."
HITMAN_DIALOG_ERROR_UNKNOWN_FORMAT_IN_ARCHIVE = "Found an unknown format inside the archive!"
HITMAN_DIALOG_ERROR_CORRUPTED_ORIGINAL_RECORDS_CACHE = "Original records cache corrupted for current archive! Trying to rebuild..."
HITMAN_DIALOG_WARNING_IMPORT_LOADING_DATA = "Couldn't load the input data, skipping the import!"
HITMAN_DIALOG_WARNING_IMPORT_DECODING_DATA = "Couldn't decode the input data, skipping the import!"
HITMAN_DIALOG_WARNING_IMPORT_CREATING_NATIVE_DATA = "Couldn't create the native data, skipping the import!"
HITMAN_DIALOG_WARNING_IMPORT_ENCODING_NATIVE_DATA = "Couldn't encode the native data, skipping the import!"
HITMAN_DIALOG_WARNING_IMPORT_TRANCODING_DATA = "Couldn't transcode the data due to error \"{}\", skipping the import!"
HITMAN_DIALOG_WARNING_IMPORT_LOADING_DATA = "Couldnt load the input data, skipping the import!"
HITMAN_DIALOG_WARNING_IMPORT_DECODING_DATA = "Couldnt decode the input data, skipping the import!"
HITMAN_DIALOG_WARNING_IMPORT_CREATING_NATIVE_DATA = "Couldnt create the native data, skipping the import!"
HITMAN_DIALOG_WARNING_IMPORT_ENCODING_NATIVE_DATA = "Couldnt encode the native data, skipping the import!"
HITMAN_DIALOG_WARNING_IMPORT_TRANCODING_DATA = "Couldnt transcode the data due to error \"{}\", skipping the import!"
HITMAN_DIALOG_WARNING_MISSING_FILE = "Skipping the file \"{}\" which is not present in the archive!"
HITMAN_1_DIALOG_ERROR_MISSING_BIN = "Couldn't find the necessary *.bin file!"
HITMAN_23_DIALOG_ERROR_MISSING_SCENES = "Couldn't find the necessary Scenes directory!"
HITMAN_1_DIALOG_ERROR_MISSING_BIN = "Couldnt find the necessary *.bin file!"
HITMAN_23_DIALOG_ERROR_MISSING_SCENES = "Couldnt find the necessary Scenes directory!"
SETTINGS_DIALOG_TITLE = "Settings"
SETTINGS_DIALOG_COMMON_GROUP = "Common"
SETTINGS_DIALOG_HITMAN_RESET_RECORDS_CACHE = "Reset original records cache"
Expand Down
93 changes: 32 additions & 61 deletions src/Core/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace

std::shared_ptr<HitmanDialog> s_SelectedDialog;
OrderedSet<std::shared_ptr<HitmanDialog>> s_Dialogs;
String8CI s_OpenFilters;
std::vector<std::pair<StringView8CI, StringView8>> s_OpenFilters;

}

Expand Down Expand Up @@ -93,11 +93,9 @@ void InitializeOpenFilters()
if (!s_OpenFilters.empty())
return;

auto hitmanFilters = Hitman1Dialog::GetOpenFilter();
ranges::copy(Hitman23Dialog::GetOpenFilter(), std::back_inserter(hitmanFilters));
ranges::copy(Hitman4Dialog::GetOpenFilter(), std::back_inserter(hitmanFilters));

s_OpenFilters = MakeFileDialogFilter(hitmanFilters);
s_OpenFilters = Hitman1Dialog::GetOpenFilter();
ranges::copy(Hitman23Dialog::GetOpenFilter(), std::back_inserter(s_OpenFilters));
ranges::copy(Hitman4Dialog::GetOpenFilter(), std::back_inserter(s_OpenFilters));
}

namespace App {
Expand Down Expand Up @@ -314,7 +312,7 @@ ExitStatus App::Application::run() {
{
InitializeOpenFilters();

auto [archivePath, archiveType] = OpenFileDialog(s_OpenFilters);
const auto archivePath = OpenFileDialog(s_OpenFilters);

auto alreadyOpened = false;
for (const auto& dialog : s_Dialogs)
Expand All @@ -327,68 +325,41 @@ ExitStatus App::Application::run() {
}

// TODO - some error messages/warnings wouldn't hurt...
if (!alreadyOpened && !archivePath.empty() && archiveType != 0)
if (!alreadyOpened && !archivePath.empty())
{
switch (archiveType)
{
case 1:
{

const auto* originalSelectedDialog = s_SelectedDialog.get();

for (const auto& filter : Hitman1Dialog::GetOpenFilter() | ranges::views::values)
{
if (archivePath.path().extension() != StringViewWCI(filter.path().extension()))
continue;

s_SelectedDialog = *s_Dialogs.insert(std::make_shared<Hitman1Dialog>()).first;
s_SelectedDialog->Load(archivePath);
break;
}

if (s_SelectedDialog.get() != originalSelectedDialog)
break;
const auto* originalSelectedDialog = s_SelectedDialog.get();

for (const auto& filter : Hitman23Dialog::GetOpenFilter() | ranges::views::values)
{
if (archivePath.path().extension() != StringViewWCI(filter.path().extension()))
continue;

s_SelectedDialog = *s_Dialogs.insert(std::make_shared<Hitman23Dialog>()).first;
s_SelectedDialog->Load(archivePath);
break;
}

if (s_SelectedDialog.get() != originalSelectedDialog)
break;

for (const auto& filter : Hitman4Dialog::GetOpenFilter() | ranges::views::values)
{
if (archivePath.path().extension() != StringViewWCI(filter.path().extension()))
continue;
for (const auto& filter : Hitman1Dialog::GetOpenFilter() | ranges::views::keys)
{
if (archivePath.path().extension() != StringViewWCI(filter.path().extension()))
continue;

s_SelectedDialog = *s_Dialogs.insert(std::make_shared<Hitman4Dialog>()).first;
s_SelectedDialog->Load(archivePath);
break;
}
s_SelectedDialog = *s_Dialogs.insert(std::make_shared<Hitman1Dialog>()).first;
s_SelectedDialog->Load(archivePath);
break;
}

break;
}
case 2:
{
s_SelectedDialog = *s_Dialogs.insert(std::make_unique<Hitman1Dialog>()).first;
s_SelectedDialog->Load(archivePath);
break;
}
case 3:
if (s_SelectedDialog.get() == originalSelectedDialog)
{
for (const auto& filter : Hitman23Dialog::GetOpenFilter() | ranges::views::keys)
{
s_SelectedDialog = *s_Dialogs.insert(std::make_unique<Hitman23Dialog>()).first;
if (archivePath.path().extension() != StringViewWCI(filter.path().extension()))
continue;

s_SelectedDialog = *s_Dialogs.insert(std::make_shared<Hitman23Dialog>()).first;
s_SelectedDialog->Load(archivePath);
break;
}
case 4:
}

if (s_SelectedDialog.get() == originalSelectedDialog)
{
for (const auto& filter : Hitman4Dialog::GetOpenFilter() | ranges::views::keys)
{
s_SelectedDialog = *s_Dialogs.insert(std::make_unique<Hitman4Dialog>()).first;
if (archivePath.path().extension() != StringViewWCI(filter.path().extension()))
continue;

s_SelectedDialog = *s_Dialogs.insert(std::make_shared<Hitman4Dialog>()).first;
s_SelectedDialog->Load(archivePath);
break;
}
Expand Down Expand Up @@ -435,7 +406,7 @@ ExitStatus App::Application::run() {
{
assert(s_SelectedDialog);

const auto [archivePath, archiveType] = SaveFileDialog(MakeFileDialogFilter(s_SelectedDialog->GetSaveFilter()));
const auto archivePath = SaveFileDialog(s_SelectedDialog->GetSaveFilter());

s_SelectedDialog->Save(archivePath, true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/G1AT/ArchiveDialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ArchiveDialog
virtual bool IsExportAllowed() const = 0;
virtual bool IsImportAllowed() const = 0;

virtual const std::vector<std::pair<String8, String8CI>>& GetSaveFilter() const = 0;
virtual const std::vector<std::pair<StringView8CI, StringView8>>& GetSaveFilter() const = 0;

bool IsAllowed() const;
bool IsInProgress() const;
Expand Down
12 changes: 6 additions & 6 deletions src/G1AT/Hitman1Dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,24 +186,24 @@ int32_t Hitman1Dialog::DrawDialog()
return DrawHitmanDialog();
}

const std::vector<std::pair<String8, String8CI>>& Hitman1Dialog::GetOpenFilter()
const std::vector<std::pair<StringView8CI, StringView8>>& Hitman1Dialog::GetOpenFilter()
{
static std::vector<std::pair<String8, String8CI>> filters;
static std::vector<std::pair<StringView8CI, StringView8>> filters;
if (!filters.empty())
return filters;

filters.emplace_back("FILE_DIALOG_FILTER_HITMAN1_SPEECH", "*.idx");
filters.emplace_back("*.idx", "FILE_DIALOG_FILTER_HITMAN1_SPEECH");

return filters;
}

const std::vector<std::pair<String8, String8CI>>& Hitman1Dialog::GetSaveFilter() const
const std::vector<std::pair<StringView8CI, StringView8>>& Hitman1Dialog::GetSaveFilter() const
{
static std::vector<std::pair<String8, String8CI>> filters;
static std::vector<std::pair<StringView8CI, StringView8>> filters;
if (!filters.empty())
return filters;

filters.emplace_back("FILE_DIALOG_FILTER_HITMAN1_SPEECH", "*.idx");
filters.emplace_back("*.idx", "FILE_DIALOG_FILTER_HITMAN1_SPEECH");

return filters;
}
4 changes: 2 additions & 2 deletions src/G1AT/Hitman1Dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class Hitman1Dialog final : public HitmanDialog

int32_t DrawDialog() override;

static const std::vector<std::pair<String8, String8CI>>& GetOpenFilter();
static const std::vector<std::pair<StringView8CI, StringView8>>& GetOpenFilter();

const std::vector<std::pair<String8, String8CI>>& GetSaveFilter() const override;
const std::vector<std::pair<StringView8CI, StringView8>>& GetSaveFilter() const override;

std::vector<StringView8CI> indexToKey;

Expand Down
12 changes: 6 additions & 6 deletions src/G1AT/Hitman23Dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,24 +417,24 @@ int32_t Hitman23Dialog::DrawDialog()
return DrawHitmanDialog();
}

const std::vector<std::pair<String8, String8CI>>& Hitman23Dialog::GetOpenFilter()
const std::vector<std::pair<StringView8CI, StringView8>>& Hitman23Dialog::GetOpenFilter()
{
static std::vector<std::pair<String8, String8CI>> filters;
static std::vector<std::pair<StringView8CI, StringView8>> filters;
if (!filters.empty())
return filters;

filters.emplace_back("FILE_DIALOG_FILTER_HITMAN23_STREAMS", "streams.wav");
filters.emplace_back("streams.wav", "FILE_DIALOG_FILTER_HITMAN23_STREAMS");

return filters;
}

const std::vector<std::pair<String8, String8CI>>& Hitman23Dialog::GetSaveFilter() const
const std::vector<std::pair<StringView8CI, StringView8>>& Hitman23Dialog::GetSaveFilter() const
{
static std::vector<std::pair<String8, String8CI>> filters;
static std::vector<std::pair<StringView8CI, StringView8>> filters;
if (!filters.empty())
return filters;

filters.emplace_back("FILE_DIALOG_FILTER_HITMAN23_STREAMS", "streams.wav");
filters.emplace_back("streams.wav", "FILE_DIALOG_FILTER_HITMAN23_STREAMS");

return filters;
}
4 changes: 2 additions & 2 deletions src/G1AT/Hitman23Dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ class Hitman23Dialog final : public HitmanDialog

int32_t DrawDialog() override;

static const std::vector<std::pair<String8, String8CI>>& GetOpenFilter();
static const std::vector<std::pair<StringView8CI, StringView8>>& GetOpenFilter();

const std::vector<std::pair<String8, String8CI>>& GetSaveFilter() const override;
const std::vector<std::pair<StringView8CI, StringView8>>& GetSaveFilter() const override;

std::vector<Hitman23WHDFile> whdFiles;
std::vector<Hitman23WAVFile> wavFiles;
Expand Down
12 changes: 6 additions & 6 deletions src/G1AT/Hitman4Dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,24 +947,24 @@ bool Hitman4Dialog::IsImportAllowed() const
return G1AT_DEBUG_BUILD == 1;
}

const std::vector<std::pair<String8, String8CI>>& Hitman4Dialog::GetOpenFilter()
const std::vector<std::pair<StringView8CI, StringView8>>& Hitman4Dialog::GetOpenFilter()
{
static std::vector<std::pair<String8, String8CI>> filters;
static std::vector<std::pair<StringView8CI, StringView8>> filters;
if (!filters.empty())
return filters;

filters.emplace_back("FILE_DIALOG_FILTER_HITMAN4_STREAMS", "pc_*.str");
filters.emplace_back("pc_*.str", "FILE_DIALOG_FILTER_HITMAN4_STREAMS");

return filters;
}

const std::vector<std::pair<String8, String8CI>>& Hitman4Dialog::GetSaveFilter() const
const std::vector<std::pair<StringView8CI, StringView8>>& Hitman4Dialog::GetSaveFilter() const
{
static std::vector<std::pair<String8, String8CI>> filters;
static std::vector<std::pair<StringView8CI, StringView8>> filters;
if (!filters.empty())
return filters;

filters.emplace_back("FILE_DIALOG_FILTER_HITMAN4_STREAMS", "pc_*.str");
filters.emplace_back("pc_*.str", "FILE_DIALOG_FILTER_HITMAN4_STREAMS");

return filters;
}
4 changes: 2 additions & 2 deletions src/G1AT/Hitman4Dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ class Hitman4Dialog final : public HitmanDialog
bool IsExportAllowed() const override;
bool IsImportAllowed() const override;

static const std::vector<std::pair<String8, String8CI>>& GetOpenFilter();
static const std::vector<std::pair<StringView8CI, StringView8>>& GetOpenFilter();

const std::vector<std::pair<String8, String8CI>>& GetSaveFilter() const override;
const std::vector<std::pair<StringView8CI, StringView8>>& GetSaveFilter() const override;

std::vector<Hitman4WHDFile> whdFiles;
std::vector<Hitman4WAVFile> wavFiles;
Expand Down
Loading

0 comments on commit abe10f1

Please sign in to comment.