1/*
2 * LegacyClonk
3 *
4 * Copyright (c) 2023, The LegacyClonk Team and contributors
5 *
6 * Distributed under the terms of the ISC license; see accompanying file
7 * "COPYING" for details.
8 *
9 * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10 * See accompanying file "TRADEMARK" for details.
11 *
12 * To redistribute this file separately, substitute the full license texts
13 * for the above references.
14 */
15
16#pragma once
17
18#include "C4Gui.h"
19#include "C4GuiDialogs.h"
20
21#include <unordered_map>
22
23class C4StartupOptionsAdvancedConfigDialog : public C4GUI::Dialog
24{
25public:
26 C4StartupOptionsAdvancedConfigDialog(std::int32_t width, std::int32_t height);
27 const char *GetID() override;
28 void UpdateSize() override;
29 template <std::integral T>
30 void AddSetting(std::string_view name, T &setting) const;
31 void AddSetting(std::string_view name, bool &setting) const;
32 void AddSetting(std::string_view name, char &setting) const;
33 void AddSetting(std::string_view name, std::string &text, std::size_t maxLength = std::string::npos) const;
34 void AddStringSetting(std::string_view name, char *text, std::size_t maxLength) const;
35 template <std::integral T>
36 void GetSetting(std::string_view name, T &setting) const;
37 void GetSetting(std::string_view name, bool &setting) const;
38 void GetSetting(std::string_view name, char &setting) const;
39 void GetSetting(std::string_view name, std::string &text) const;
40 void AddText(std::string_view name, std::string_view text) const;
41 void ChangeSection(const char *name);
42
43 static bool ShowModal(C4GUI::Screen *screen);
44
45protected:
46 bool OnEnter() override;
47 void UserClose(bool ok) override;
48
49private:
50 void AddSettingInternal(std::string_view name, C4GUI::Element *control) const;
51 template <typename T>
52 T *GetSettingInternal(std::string_view name) const;
53 void OnSave(C4GUI::Control *control);
54 void OnAbort(C4GUI::Control *control);
55 bool IsBlocked(std::string_view name) const;
56
57 C4GUI::Tabular *tabs;
58 C4GUI::Button *cancelButton;
59 C4GUI::Button *saveButton;
60
61 class Setting : public Window
62 {
63 public:
64 Setting(std::string_view label, C4GUI::Element *control);
65 void UpdateSize() override;
66 void UpdateSize(bool adjustHeight);
67 C4GUI::Element *GetControl() const;
68
69 static inline constexpr int32_t Margin{2};
70 int32_t GetMarginTop() override { return Margin; }
71 int32_t GetMarginBottom() override { return Margin; }
72 int32_t GetMarginLeft() override { return Margin; }
73 int32_t GetMarginRight() override { return Margin; }
74
75 private:
76 C4GUI::Label label;
77 C4GUI::Element *control;
78 };
79
80 struct string_hash : std::hash<std::string_view>
81 {
82 using is_transparent = void;
83 };
84
85 struct Section;
86
87 Section *currentSection{nullptr};
88
89 std::unordered_map<std::string, Section, string_hash, std::equal_to<>> sections;
90};
91