Skip to content

Commit abe10f1

Browse files
author
Andrej Redeky
committed
Use tinyfiledialogs for dialogs (should enable us to compile for linux, mac, etc.)
1 parent 76d708a commit abe10f1

File tree

14 files changed

+113
-233
lines changed

14 files changed

+113
-233
lines changed

LICENSE_ThirdParty.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,25 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
920920
See the License for the specific language governing permissions and
921921
limitations under the License.
922922

923+
# tiny file dialogs
924+
Copyright (c) 2014 - 2023 Guillaume Vareille http://ysengrin.com
925+
926+
This software is provided 'as-is', without any express or implied
927+
warranty. In no event will the authors be held liable for any damages
928+
arising from the use of this software.
929+
930+
Permission is granted to anyone to use this software for any purpose,
931+
including commercial applications, and to alter it and redistribute it
932+
freely, subject to the following restrictions:
933+
934+
1. The origin of this software must not be misrepresented; you must not
935+
claim that you wrote the original software. If you use this software
936+
in a product, an acknowledgment in the product documentation would be
937+
appreciated but is not required.
938+
2. Altered source versions must be plainly marked as such, and must not be
939+
misrepresented as being the original software.
940+
3. This notice may not be removed or altered from any source distribution.
941+
923942
# toml++
924943
MIT License
925944

data/localization/English.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ARCHIVE_DIALOG_PROCESSING = "Processing..."
1919
ARCHIVE_DIALOG_PROGRESS_SUMMARY = "Currently processing item {} from {}..."
2020
ARCHIVE_DIALOG_NO_ARCHIVE = "There is currently no opened archive."
2121
ARCHIVE_DIALOG_FILE_MENU = "File"
22-
SDL2_INITIALIZATION_ERROR = "Couldn't initialize SDL2!\n\"{}\""
22+
SDL2_INITIALIZATION_ERROR = "Couldnt initialize SDL2!\n\"{}\""
2323
MESSAGEBOX_TITLE_ERROR = "Error"
2424
MESSAGEBOX_TITLE_WARNING = "Warning"
2525
MESSAGEBOX_TITLE_INFORMATION = "Information"
@@ -30,14 +30,14 @@ MESSAGEBOX_BUTTON_CANCEL = "Cancel"
3030
HITMAN_DIALOG_LOADING_ORIGINAL_RECORDS = "Loading the original records..."
3131
HITMAN_DIALOG_ERROR_UNKNOWN_FORMAT_IN_ARCHIVE = "Found an unknown format inside the archive!"
3232
HITMAN_DIALOG_ERROR_CORRUPTED_ORIGINAL_RECORDS_CACHE = "Original records cache corrupted for current archive! Trying to rebuild..."
33-
HITMAN_DIALOG_WARNING_IMPORT_LOADING_DATA = "Couldn't load the input data, skipping the import!"
34-
HITMAN_DIALOG_WARNING_IMPORT_DECODING_DATA = "Couldn't decode the input data, skipping the import!"
35-
HITMAN_DIALOG_WARNING_IMPORT_CREATING_NATIVE_DATA = "Couldn't create the native data, skipping the import!"
36-
HITMAN_DIALOG_WARNING_IMPORT_ENCODING_NATIVE_DATA = "Couldn't encode the native data, skipping the import!"
37-
HITMAN_DIALOG_WARNING_IMPORT_TRANCODING_DATA = "Couldn't transcode the data due to error \"{}\", skipping the import!"
33+
HITMAN_DIALOG_WARNING_IMPORT_LOADING_DATA = "Couldnt load the input data, skipping the import!"
34+
HITMAN_DIALOG_WARNING_IMPORT_DECODING_DATA = "Couldnt decode the input data, skipping the import!"
35+
HITMAN_DIALOG_WARNING_IMPORT_CREATING_NATIVE_DATA = "Couldnt create the native data, skipping the import!"
36+
HITMAN_DIALOG_WARNING_IMPORT_ENCODING_NATIVE_DATA = "Couldnt encode the native data, skipping the import!"
37+
HITMAN_DIALOG_WARNING_IMPORT_TRANCODING_DATA = "Couldnt transcode the data due to error \"{}\", skipping the import!"
3838
HITMAN_DIALOG_WARNING_MISSING_FILE = "Skipping the file \"{}\" which is not present in the archive!"
39-
HITMAN_1_DIALOG_ERROR_MISSING_BIN = "Couldn't find the necessary *.bin file!"
40-
HITMAN_23_DIALOG_ERROR_MISSING_SCENES = "Couldn't find the necessary Scenes directory!"
39+
HITMAN_1_DIALOG_ERROR_MISSING_BIN = "Couldnt find the necessary *.bin file!"
40+
HITMAN_23_DIALOG_ERROR_MISSING_SCENES = "Couldnt find the necessary Scenes directory!"
4141
SETTINGS_DIALOG_TITLE = "Settings"
4242
SETTINGS_DIALOG_COMMON_GROUP = "Common"
4343
SETTINGS_DIALOG_HITMAN_RESET_RECORDS_CACHE = "Reset original records cache"

src/Core/Application.cpp

Lines changed: 32 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace
2424

2525
std::shared_ptr<HitmanDialog> s_SelectedDialog;
2626
OrderedSet<std::shared_ptr<HitmanDialog>> s_Dialogs;
27-
String8CI s_OpenFilters;
27+
std::vector<std::pair<StringView8CI, StringView8>> s_OpenFilters;
2828

2929
}
3030

@@ -93,11 +93,9 @@ void InitializeOpenFilters()
9393
if (!s_OpenFilters.empty())
9494
return;
9595

96-
auto hitmanFilters = Hitman1Dialog::GetOpenFilter();
97-
ranges::copy(Hitman23Dialog::GetOpenFilter(), std::back_inserter(hitmanFilters));
98-
ranges::copy(Hitman4Dialog::GetOpenFilter(), std::back_inserter(hitmanFilters));
99-
100-
s_OpenFilters = MakeFileDialogFilter(hitmanFilters);
96+
s_OpenFilters = Hitman1Dialog::GetOpenFilter();
97+
ranges::copy(Hitman23Dialog::GetOpenFilter(), std::back_inserter(s_OpenFilters));
98+
ranges::copy(Hitman4Dialog::GetOpenFilter(), std::back_inserter(s_OpenFilters));
10199
}
102100

103101
namespace App {
@@ -314,7 +312,7 @@ ExitStatus App::Application::run() {
314312
{
315313
InitializeOpenFilters();
316314

317-
auto [archivePath, archiveType] = OpenFileDialog(s_OpenFilters);
315+
const auto archivePath = OpenFileDialog(s_OpenFilters);
318316

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

329327
// TODO - some error messages/warnings wouldn't hurt...
330-
if (!alreadyOpened && !archivePath.empty() && archiveType != 0)
328+
if (!alreadyOpened && !archivePath.empty())
331329
{
332-
switch (archiveType)
333-
{
334-
case 1:
335-
{
336-
337-
const auto* originalSelectedDialog = s_SelectedDialog.get();
338-
339-
for (const auto& filter : Hitman1Dialog::GetOpenFilter() | ranges::views::values)
340-
{
341-
if (archivePath.path().extension() != StringViewWCI(filter.path().extension()))
342-
continue;
343-
344-
s_SelectedDialog = *s_Dialogs.insert(std::make_shared<Hitman1Dialog>()).first;
345-
s_SelectedDialog->Load(archivePath);
346-
break;
347-
}
348-
349-
if (s_SelectedDialog.get() != originalSelectedDialog)
350-
break;
330+
const auto* originalSelectedDialog = s_SelectedDialog.get();
351331

352-
for (const auto& filter : Hitman23Dialog::GetOpenFilter() | ranges::views::values)
353-
{
354-
if (archivePath.path().extension() != StringViewWCI(filter.path().extension()))
355-
continue;
356-
357-
s_SelectedDialog = *s_Dialogs.insert(std::make_shared<Hitman23Dialog>()).first;
358-
s_SelectedDialog->Load(archivePath);
359-
break;
360-
}
361-
362-
if (s_SelectedDialog.get() != originalSelectedDialog)
363-
break;
364-
365-
for (const auto& filter : Hitman4Dialog::GetOpenFilter() | ranges::views::values)
366-
{
367-
if (archivePath.path().extension() != StringViewWCI(filter.path().extension()))
368-
continue;
332+
for (const auto& filter : Hitman1Dialog::GetOpenFilter() | ranges::views::keys)
333+
{
334+
if (archivePath.path().extension() != StringViewWCI(filter.path().extension()))
335+
continue;
369336

370-
s_SelectedDialog = *s_Dialogs.insert(std::make_shared<Hitman4Dialog>()).first;
371-
s_SelectedDialog->Load(archivePath);
372-
break;
373-
}
337+
s_SelectedDialog = *s_Dialogs.insert(std::make_shared<Hitman1Dialog>()).first;
338+
s_SelectedDialog->Load(archivePath);
339+
break;
340+
}
374341

375-
break;
376-
}
377-
case 2:
378-
{
379-
s_SelectedDialog = *s_Dialogs.insert(std::make_unique<Hitman1Dialog>()).first;
380-
s_SelectedDialog->Load(archivePath);
381-
break;
382-
}
383-
case 3:
342+
if (s_SelectedDialog.get() == originalSelectedDialog)
343+
{
344+
for (const auto& filter : Hitman23Dialog::GetOpenFilter() | ranges::views::keys)
384345
{
385-
s_SelectedDialog = *s_Dialogs.insert(std::make_unique<Hitman23Dialog>()).first;
346+
if (archivePath.path().extension() != StringViewWCI(filter.path().extension()))
347+
continue;
348+
349+
s_SelectedDialog = *s_Dialogs.insert(std::make_shared<Hitman23Dialog>()).first;
386350
s_SelectedDialog->Load(archivePath);
387351
break;
388352
}
389-
case 4:
353+
}
354+
355+
if (s_SelectedDialog.get() == originalSelectedDialog)
356+
{
357+
for (const auto& filter : Hitman4Dialog::GetOpenFilter() | ranges::views::keys)
390358
{
391-
s_SelectedDialog = *s_Dialogs.insert(std::make_unique<Hitman4Dialog>()).first;
359+
if (archivePath.path().extension() != StringViewWCI(filter.path().extension()))
360+
continue;
361+
362+
s_SelectedDialog = *s_Dialogs.insert(std::make_shared<Hitman4Dialog>()).first;
392363
s_SelectedDialog->Load(archivePath);
393364
break;
394365
}
@@ -435,7 +406,7 @@ ExitStatus App::Application::run() {
435406
{
436407
assert(s_SelectedDialog);
437408

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

440411
s_SelectedDialog->Save(archivePath, true);
441412
}

src/G1AT/ArchiveDialog.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class ArchiveDialog
7171
virtual bool IsExportAllowed() const = 0;
7272
virtual bool IsImportAllowed() const = 0;
7373

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

7676
bool IsAllowed() const;
7777
bool IsInProgress() const;

src/G1AT/Hitman1Dialog.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,24 +186,24 @@ int32_t Hitman1Dialog::DrawDialog()
186186
return DrawHitmanDialog();
187187
}
188188

189-
const std::vector<std::pair<String8, String8CI>>& Hitman1Dialog::GetOpenFilter()
189+
const std::vector<std::pair<StringView8CI, StringView8>>& Hitman1Dialog::GetOpenFilter()
190190
{
191-
static std::vector<std::pair<String8, String8CI>> filters;
191+
static std::vector<std::pair<StringView8CI, StringView8>> filters;
192192
if (!filters.empty())
193193
return filters;
194194

195-
filters.emplace_back("FILE_DIALOG_FILTER_HITMAN1_SPEECH", "*.idx");
195+
filters.emplace_back("*.idx", "FILE_DIALOG_FILTER_HITMAN1_SPEECH");
196196

197197
return filters;
198198
}
199199

200-
const std::vector<std::pair<String8, String8CI>>& Hitman1Dialog::GetSaveFilter() const
200+
const std::vector<std::pair<StringView8CI, StringView8>>& Hitman1Dialog::GetSaveFilter() const
201201
{
202-
static std::vector<std::pair<String8, String8CI>> filters;
202+
static std::vector<std::pair<StringView8CI, StringView8>> filters;
203203
if (!filters.empty())
204204
return filters;
205205

206-
filters.emplace_back("FILE_DIALOG_FILTER_HITMAN1_SPEECH", "*.idx");
206+
filters.emplace_back("*.idx", "FILE_DIALOG_FILTER_HITMAN1_SPEECH");
207207

208208
return filters;
209209
}

src/G1AT/Hitman1Dialog.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class Hitman1Dialog final : public HitmanDialog
2121

2222
int32_t DrawDialog() override;
2323

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

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

2828
std::vector<StringView8CI> indexToKey;
2929

src/G1AT/Hitman23Dialog.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,24 +417,24 @@ int32_t Hitman23Dialog::DrawDialog()
417417
return DrawHitmanDialog();
418418
}
419419

420-
const std::vector<std::pair<String8, String8CI>>& Hitman23Dialog::GetOpenFilter()
420+
const std::vector<std::pair<StringView8CI, StringView8>>& Hitman23Dialog::GetOpenFilter()
421421
{
422-
static std::vector<std::pair<String8, String8CI>> filters;
422+
static std::vector<std::pair<StringView8CI, StringView8>> filters;
423423
if (!filters.empty())
424424
return filters;
425425

426-
filters.emplace_back("FILE_DIALOG_FILTER_HITMAN23_STREAMS", "streams.wav");
426+
filters.emplace_back("streams.wav", "FILE_DIALOG_FILTER_HITMAN23_STREAMS");
427427

428428
return filters;
429429
}
430430

431-
const std::vector<std::pair<String8, String8CI>>& Hitman23Dialog::GetSaveFilter() const
431+
const std::vector<std::pair<StringView8CI, StringView8>>& Hitman23Dialog::GetSaveFilter() const
432432
{
433-
static std::vector<std::pair<String8, String8CI>> filters;
433+
static std::vector<std::pair<StringView8CI, StringView8>> filters;
434434
if (!filters.empty())
435435
return filters;
436436

437-
filters.emplace_back("FILE_DIALOG_FILTER_HITMAN23_STREAMS", "streams.wav");
437+
filters.emplace_back("streams.wav", "FILE_DIALOG_FILTER_HITMAN23_STREAMS");
438438

439439
return filters;
440440
}

src/G1AT/Hitman23Dialog.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ class Hitman23Dialog final : public HitmanDialog
116116

117117
int32_t DrawDialog() override;
118118

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

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

123123
std::vector<Hitman23WHDFile> whdFiles;
124124
std::vector<Hitman23WAVFile> wavFiles;

src/G1AT/Hitman4Dialog.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -947,24 +947,24 @@ bool Hitman4Dialog::IsImportAllowed() const
947947
return G1AT_DEBUG_BUILD == 1;
948948
}
949949

950-
const std::vector<std::pair<String8, String8CI>>& Hitman4Dialog::GetOpenFilter()
950+
const std::vector<std::pair<StringView8CI, StringView8>>& Hitman4Dialog::GetOpenFilter()
951951
{
952-
static std::vector<std::pair<String8, String8CI>> filters;
952+
static std::vector<std::pair<StringView8CI, StringView8>> filters;
953953
if (!filters.empty())
954954
return filters;
955955

956-
filters.emplace_back("FILE_DIALOG_FILTER_HITMAN4_STREAMS", "pc_*.str");
956+
filters.emplace_back("pc_*.str", "FILE_DIALOG_FILTER_HITMAN4_STREAMS");
957957

958958
return filters;
959959
}
960960

961-
const std::vector<std::pair<String8, String8CI>>& Hitman4Dialog::GetSaveFilter() const
961+
const std::vector<std::pair<StringView8CI, StringView8>>& Hitman4Dialog::GetSaveFilter() const
962962
{
963-
static std::vector<std::pair<String8, String8CI>> filters;
963+
static std::vector<std::pair<StringView8CI, StringView8>> filters;
964964
if (!filters.empty())
965965
return filters;
966966

967-
filters.emplace_back("FILE_DIALOG_FILTER_HITMAN4_STREAMS", "pc_*.str");
967+
filters.emplace_back("pc_*.str", "FILE_DIALOG_FILTER_HITMAN4_STREAMS");
968968

969969
return filters;
970970
}

src/G1AT/Hitman4Dialog.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ class Hitman4Dialog final : public HitmanDialog
263263
bool IsExportAllowed() const override;
264264
bool IsImportAllowed() const override;
265265

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

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

270270
std::vector<Hitman4WHDFile> whdFiles;
271271
std::vector<Hitman4WAVFile> wavFiles;

0 commit comments

Comments
 (0)