From 3949f52f1dd081d1e8ed3de7a9c08cf3b20ec084 Mon Sep 17 00:00:00 2001 From: Tayou Date: Tue, 18 Apr 2023 20:02:15 +0200 Subject: [PATCH] Implement custom widgets for edit delegate, always show edit delegate Signed-off-by: Tayou --- launcher/CMakeLists.txt | 22 ++ .../gameoptions/GameOptionDelegate.cpp | 202 ++++--------- .../gameoptions/GameOptionDelegate.h | 2 + .../minecraft/gameoptions/GameOptions.cpp | 145 ++-------- launcher/minecraft/gameoptions/GameOptions.h | 6 +- .../gameoptions/GameOptionsSchema.cpp | 269 +++++++++--------- .../minecraft/gameoptions/GameOptionsSchema.h | 62 ++-- .../ui/pages/instance/GameOptionsPage.cpp | 12 +- launcher/ui/widgets/GameOptionWidget.h | 42 +++ .../ui/widgets/GameOptionWidgetCheckBox.cpp | 46 +++ .../ui/widgets/GameOptionWidgetCheckBox.h | 39 +++ .../ui/widgets/GameOptionWidgetCheckBox.ui | 53 ++++ .../ui/widgets/GameOptionWidgetComboBox.cpp | 43 +++ .../ui/widgets/GameOptionWidgetComboBox.h | 39 +++ .../ui/widgets/GameOptionWidgetComboBox.ui | 49 ++++ .../ui/widgets/GameOptionWidgetKeyBind.cpp | 61 ++++ launcher/ui/widgets/GameOptionWidgetKeyBind.h | 39 +++ .../ui/widgets/GameOptionWidgetKeyBind.ui | 56 ++++ .../ui/widgets/GameOptionWidgetSlider.cpp | 91 ++++++ launcher/ui/widgets/GameOptionWidgetSlider.h | 38 +++ launcher/ui/widgets/GameOptionWidgetSlider.ui | 112 ++++++++ .../widgets/GameOptionWidgetSpinnerFloat.cpp | 45 +++ .../ui/widgets/GameOptionWidgetSpinnerFloat.h | 41 +++ .../widgets/GameOptionWidgetSpinnerFloat.ui | 49 ++++ .../ui/widgets/GameOptionWidgetSpinnerInt.cpp | 45 +++ .../ui/widgets/GameOptionWidgetSpinnerInt.h | 41 +++ .../ui/widgets/GameOptionWidgetSpinnerInt.ui | 49 ++++ launcher/ui/widgets/GameOptionWidgetText.cpp | 45 +++ launcher/ui/widgets/GameOptionWidgetText.h | 40 +++ launcher/ui/widgets/GameOptionWidgetText.ui | 49 ++++ 30 files changed, 1380 insertions(+), 452 deletions(-) create mode 100644 launcher/ui/widgets/GameOptionWidget.h create mode 100644 launcher/ui/widgets/GameOptionWidgetCheckBox.cpp create mode 100644 launcher/ui/widgets/GameOptionWidgetCheckBox.h create mode 100644 launcher/ui/widgets/GameOptionWidgetCheckBox.ui create mode 100644 launcher/ui/widgets/GameOptionWidgetComboBox.cpp create mode 100644 launcher/ui/widgets/GameOptionWidgetComboBox.h create mode 100644 launcher/ui/widgets/GameOptionWidgetComboBox.ui create mode 100644 launcher/ui/widgets/GameOptionWidgetKeyBind.cpp create mode 100644 launcher/ui/widgets/GameOptionWidgetKeyBind.h create mode 100644 launcher/ui/widgets/GameOptionWidgetKeyBind.ui create mode 100644 launcher/ui/widgets/GameOptionWidgetSlider.cpp create mode 100644 launcher/ui/widgets/GameOptionWidgetSlider.h create mode 100644 launcher/ui/widgets/GameOptionWidgetSlider.ui create mode 100644 launcher/ui/widgets/GameOptionWidgetSpinnerFloat.cpp create mode 100644 launcher/ui/widgets/GameOptionWidgetSpinnerFloat.h create mode 100644 launcher/ui/widgets/GameOptionWidgetSpinnerFloat.ui create mode 100644 launcher/ui/widgets/GameOptionWidgetSpinnerInt.cpp create mode 100644 launcher/ui/widgets/GameOptionWidgetSpinnerInt.h create mode 100644 launcher/ui/widgets/GameOptionWidgetSpinnerInt.ui create mode 100644 launcher/ui/widgets/GameOptionWidgetText.cpp create mode 100644 launcher/ui/widgets/GameOptionWidgetText.h create mode 100644 launcher/ui/widgets/GameOptionWidgetText.ui diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 1998addf0..85ca816ff 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -1015,6 +1015,21 @@ SET(LAUNCHER_SOURCES ui/widgets/WideBar.cpp ui/widgets/ThemeCustomizationWidget.h ui/widgets/ThemeCustomizationWidget.cpp + ui/widgets/GameOptionWidget.h + ui/widgets/GameOptionWidgetSlider.h + ui/widgets/GameOptionWidgetSlider.cpp + ui/widgets/GameOptionWidgetComboBox.h + ui/widgets/GameOptionWidgetComboBox.cpp + ui/widgets/GameOptionWidgetCheckBox.h + ui/widgets/GameOptionWidgetCheckBox.cpp + ui/widgets/GameOptionWidgetSpinnerFloat.h + ui/widgets/GameOptionWidgetSpinnerFloat.cpp + ui/widgets/GameOptionWidgetSpinnerInt.h + ui/widgets/GameOptionWidgetSpinnerInt.cpp + ui/widgets/GameOptionWidgetText.h + ui/widgets/GameOptionWidgetText.cpp + ui/widgets/GameOptionWidgetKeyBind.h + ui/widgets/GameOptionWidgetKeyBind.cpp # GUI - instance group view ui/instanceview/InstanceProxyModel.cpp @@ -1068,6 +1083,13 @@ qt_wrap_ui(LAUNCHER_UI ui/widgets/ModFilterWidget.ui ui/widgets/SubTaskProgressBar.ui ui/widgets/ThemeCustomizationWidget.ui + ui/widgets/GameOptionWidgetSlider.ui + ui/widgets/GameOptionWidgetComboBox.ui + ui/widgets/GameOptionWidgetCheckBox.ui + ui/widgets/GameOptionWidgetSpinnerFloat.ui + ui/widgets/GameOptionWidgetSpinnerInt.ui + ui/widgets/GameOptionWidgetText.ui + ui/widgets/GameOptionWidgetKeyBind.ui ui/dialogs/CopyInstanceDialog.ui ui/dialogs/ProfileSetupDialog.ui ui/dialogs/ProgressDialog.ui diff --git a/launcher/minecraft/gameoptions/GameOptionDelegate.cpp b/launcher/minecraft/gameoptions/GameOptionDelegate.cpp index 033aed321..d65285e4c 100644 --- a/launcher/minecraft/gameoptions/GameOptionDelegate.cpp +++ b/launcher/minecraft/gameoptions/GameOptionDelegate.cpp @@ -16,184 +16,82 @@ * along with this program. If not, see . */ #include "GameOptionDelegate.h" +#include "ui/widgets/GameOptionWidget.h" +#include "ui/widgets/GameOptionWidgetCheckBox.h" +#include "ui/widgets/GameOptionWidgetComboBox.h" +#include "ui/widgets/GameOptionWidgetKeyBind.h" +#include "ui/widgets/GameOptionWidgetSlider.h" +#include "ui/widgets/GameOptionWidgetSpinnerFloat.h" +#include "ui/widgets/GameOptionWidgetSpinnerInt.h" +#include "ui/widgets/GameOptionWidgetText.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include -QWidget* GameOptionDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const { - std::shared_ptr knownOption = contents->at(index.row()).knownOption; - - switch (contents->at(index.row()).type) { - case OptionType::String: { - if (knownOption != nullptr && !knownOption->validValues.isEmpty()) { - QComboBox* comboBox = new QComboBox(parent); - for (auto value : knownOption->validValues) { - comboBox->addItem(value); - } - comboBox->setGeometry(option.rect); - return comboBox; - } else { - QLineEdit* textField = new QLineEdit(parent); - textField->setGeometry(option.rect); - return textField; - } - } - case OptionType::Int: { - if (knownOption != nullptr && (knownOption->getIntRange().max != 0 || knownOption->getIntRange().min != 0)) { - QSlider* slider = new QSlider(parent); - slider->setMinimum(knownOption->getIntRange().min); - slider->setMaximum(knownOption->getIntRange().max); - slider->setOrientation(Qt::Horizontal); - slider->setGeometry(option.rect); - return slider; - } else { - QSpinBox* intInput = new QSpinBox(parent); - intInput->setGeometry(option.rect); - return intInput; - } - } - case OptionType::Bool: { - QCheckBox* checkBox = new QCheckBox(parent); - checkBox->setGeometry(option.rect); - return checkBox; - } - case OptionType::Float: { - if (knownOption != nullptr && (knownOption->getFloatRange().max != 0 || knownOption->getFloatRange().min != 0)) { - QSlider* slider = new QSlider(parent); - slider->setMinimum(knownOption->getFloatRange().min*100); - slider->setMaximum(knownOption->getFloatRange().max*100); - slider->setOrientation(Qt::Horizontal); - slider->setGeometry(option.rect); - return slider; - } else { - QDoubleSpinBox* floatInput = new QDoubleSpinBox(parent); - floatInput->setGeometry(option.rect); - return floatInput; - } - } - case OptionType::KeyBind: { - QKeySequenceEdit* keySequenceEdit = new QKeySequenceEdit(parent); - keySequenceEdit->setGeometry(option.rect); - return keySequenceEdit; - } - default: - break; - } -}; -void GameOptionDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const +QWidget* GameOptionDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const { std::shared_ptr knownOption = contents->at(index.row()).knownOption; switch (contents->at(index.row()).type) { case OptionType::String: { - QComboBox* comboBox; - if ((comboBox = dynamic_cast(editor)) != nullptr) { - comboBox->setCurrentIndex(comboBox->findText(contents->at(index.row()).value)); + if (knownOption != nullptr && !knownOption->validValues.isEmpty()) { + return new GameOptionWidgetComboBox(parent, knownOption); } else { - ((QLineEdit*)editor)->setText(contents->at(index.row()).value); + return new GameOptionWidgetText(parent, knownOption); } - return; } case OptionType::Int: { - QSlider* slider; - if ((slider = dynamic_cast(editor)) != nullptr) { - slider->setValue(contents->at(index.row()).intValue); + if (knownOption != nullptr && (knownOption->getIntRange().max != 0 || knownOption->getIntRange().min != 0)) { + return new GameOptionWidgetSlider(parent, knownOption); } else { - ((QSpinBox*)editor)->setValue(contents->at(index.row()).intValue); + return new GameOptionWidgetSpinnerInt(parent, knownOption); } - return; } case OptionType::Bool: { - ((QCheckBox*)editor)->setText(contents->at(index.row()).value); - ((QCheckBox*)editor)->setChecked(contents->at(index.row()).boolValue); - return; + return new GameOptionWidgetCheckBox(parent, knownOption); } case OptionType::Float: { - QSlider* slider; - if ((slider = dynamic_cast(editor)) != nullptr) { - slider->setValue(contents->at(index.row()).floatValue*100); + if (knownOption != nullptr && (knownOption->getFloatRange().max != 0 || knownOption->getFloatRange().min != 0)) { + return new GameOptionWidgetSlider(parent, knownOption); } else { - ((QDoubleSpinBox*)editor)->setValue(contents->at(index.row()).floatValue); + return new GameOptionWidgetSpinnerFloat(parent, knownOption); } - return; } case OptionType::KeyBind: { - // TODO: fall back to QLineEdit if keybind can't be represented, like some mods do (by using another key input API) - // TODO: mouse binding? If not possible, fall back as well maybe? - Qt::Key key; - for (auto& keyBinding : *keybindingOptions) { - // this could become a std::find_if eventually, if someone wants to bother making it that. - if (keyBinding->minecraftKeyCode == contents->at(index.row()).value) { - key = keyBinding->qtKeyCode.keyboardKey; - } - } - ((QKeySequenceEdit*)editor)->setKeySequence(QKeySequence(key)); - return; + return new GameOptionWidgetKeyBind(parent, knownOption); } default: - return; + return nullptr; + } +} + +void GameOptionDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const +{ + GameOptionWidget* widget = dynamic_cast(editor); + + GameOptionItem optionItem = contents->at(index.row()); + + if (widget != nullptr) { + widget->setEditorData(optionItem); + } else { + qDebug() << "[GameOptions] Setting widget data failed because widget was still null"; } }; -void GameOptionDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const { - editor->setGeometry(option.rect); + +void GameOptionDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + GameOptionWidget* widget = dynamic_cast(editor); + widget->setSize(option.rect); }; -void GameOptionDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const { - std::shared_ptr knownOption = contents->at(index.row()).knownOption; - switch (contents->at(index.row()).type) { - case OptionType::String: { - QComboBox* comboBox; - if ((comboBox = dynamic_cast(editor)) != nullptr) { - contents->at(index.row()).value = comboBox->currentText(); - } else { - contents->at(index.row()).value = ((QLineEdit*)editor)->text(); - } - return; - } - case OptionType::Int: { - QSlider* slider; - if ((slider = dynamic_cast(editor)) != nullptr) { - contents->at(index.row()).intValue = slider->value(); - } else { - contents->at(index.row()).intValue = ((QSpinBox*)editor)->value(); - } - return; - } - case OptionType::Bool: { - ((QCheckBox*)editor)->setText(contents->at(index.row()).value); - contents->at(index.row()).boolValue = ((QCheckBox*)editor)->isChecked(); - return; - } - case OptionType::Float: { - QSlider* slider; - if ((slider = dynamic_cast(editor)) != nullptr) { - contents->at(index.row()).floatValue = slider->value()/100.0f; - } else { - contents->at(index.row()).floatValue = ((QDoubleSpinBox*)editor)->value(); - } - return; - } - case OptionType::KeyBind: { - QKeySequenceEdit* keySequenceEdit = (QKeySequenceEdit*)editor; +void GameOptionDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const +{ + GameOptionWidget* widget = dynamic_cast(editor); - QString minecraftKeyCode; - for (auto& keyBinding : *keybindingOptions) { - // this could become a std::find_if eventually, if someone wants to bother making it that. - if (keyBinding->qtKeyCode.keyboardKey == keySequenceEdit->keySequence()[0].key() || - keyBinding->qtKeyCode.mouseButton == keySequenceEdit->keySequence()[0].key()) { - minecraftKeyCode = keyBinding->minecraftKeyCode; - } - } - contents->at(index.row()).value = minecraftKeyCode; - return; - } - default: - return; + GameOptionItem optionItem = contents->at(index.row()); + + if (widget != nullptr) { + widget->saveEditorData(optionItem); + } else { + qDebug() << "[GameOptions] Saving widget data to Model failed because widget was null"; } -}; +} \ No newline at end of file diff --git a/launcher/minecraft/gameoptions/GameOptionDelegate.h b/launcher/minecraft/gameoptions/GameOptionDelegate.h index 61e59fe34..5993ba603 100644 --- a/launcher/minecraft/gameoptions/GameOptionDelegate.h +++ b/launcher/minecraft/gameoptions/GameOptionDelegate.h @@ -38,6 +38,8 @@ class GameOptionDelegate : public QStyledItemDelegate { const QModelIndex& index) const override; void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const override; + enum GameOptionWidgetType { slider, text, keybind, number, comboBox }; + private: std::vector* contents; QList>* keybindingOptions; diff --git a/launcher/minecraft/gameoptions/GameOptions.cpp b/launcher/minecraft/gameoptions/GameOptions.cpp index d11fbbd27..c98a964f6 100644 --- a/launcher/minecraft/gameoptions/GameOptions.cpp +++ b/launcher/minecraft/gameoptions/GameOptions.cpp @@ -98,12 +98,12 @@ bool load(const QString& path, item.type = OptionType::Float; // qDebug() << "The value" << value << "is a float"; } else if (item.value == "true" || item.value == "false") { - item.boolValue = item.value == "true" ? true : false; + item.boolValue = item.value == "true"; item.type = OptionType::Bool; qDebug() << "The value" << item.value << "is a bool"; } else if (item.value.endsWith("]") && item.value.startsWith("[")) { qDebug() << "The value" << item.value << "is an array"; - for (QString part : item.value.mid(1, item.value.size() - 2).split(",")) { + for (const QString& part : item.value.mid(1, item.value.size() - 2).split(",")) { GameOptionChildItem child{ part, static_cast(contents.size()) }; qDebug() << "Array has entry" << part; item.children.append(child); @@ -154,17 +154,15 @@ QVariant GameOptions::headerData(int section, Qt::Orientation orientation, int r if (role != Qt::DisplayRole) { return QAbstractItemModel::headerData(section, orientation, role); } - switch (section) { - case 0: - return tr("Key"); - case 1: - return tr("Description"); - case 2: - return tr("Value"); - case 3: - return tr("Default Value"); + switch ((Column)section) { default: return QVariant(); + case Column::Key: + return tr("Key"); + case Column::Description: + return tr("Description"); + case Column::Value: + return tr("Value"); } } bool GameOptions::setData(const QModelIndex& index, const QVariant& value, int role) @@ -175,16 +173,22 @@ bool GameOptions::setData(const QModelIndex& index, const QVariant& value, int r switch (contents[row].type) { case OptionType::String: { contents[row].value = value.toString(); + return true; } case OptionType::Int: { contents[row].intValue = value.toInt(); + return true; } case OptionType::Bool: { contents[row].boolValue = value.toBool(); + return true; } case OptionType::Float: { contents[row].floatValue = value.toFloat(); + return true; } + case OptionType::KeyBind: + break; } } @@ -193,34 +197,7 @@ bool GameOptions::setData(const QModelIndex& index, const QVariant& value, int r Qt::ItemFlags GameOptions::flags(const QModelIndex& index) const { - Qt::ItemFlags flags = QAbstractItemModel::flags(index); - - if (!index.isValid()) - return flags; - - Column column = (Column)index.column(); - - if (column == Column::Key) { - return flags; - } - - if (index.parent().isValid()) { - return flags; - } - - if (contents[index.row()].children.count() > 0) { - return flags; - } - - flags = flags | Qt::ItemFlag::ItemIsEditable; - /*if (column == Column::Value || column == Column::DefaultValue) { - flags = flags | Qt::ItemFlag::ItemIsUserCheckable; - }*/ - if (column == Column::DefaultValue) { - flags = flags & ~Qt::ItemFlag::ItemIsEnabled; - } - - return flags; + return QAbstractItemModel::flags(index); } QVariant GameOptions::data(const QModelIndex& index, int role) const @@ -263,90 +240,6 @@ QVariant GameOptions::data(const QModelIndex& index, int role) const return QVariant(); } } - case Column::Value: { - switch (contents[row].type) { - case OptionType::String: { - return contents[row].value; - } - case OptionType::Int: { - return contents[row].intValue; - } - case OptionType::Bool: { - return contents[row].boolValue; - } - case OptionType::Float: { - return contents[row].floatValue; - } - case OptionType::KeyBind: { - for (auto& keyBinding : *keybindingOptions) { - // this could become a std::find_if eventually, if someone wants to bother making it that. - if (keyBinding->minecraftKeyCode == contents[row].value) { - return keyBinding->displayName; // + " (" + contents[row].value + ")"; - } - } - - return contents[row].value; - } - default: { - return QVariant(); - } - } - } - case Column::DefaultValue: { - if (contents[row].knownOption != nullptr) { - switch (contents[row].type) { - case OptionType::String: { - return contents[row].knownOption->getDefaultString(); - } - case OptionType::Int: { - return contents[row].knownOption->getDefaultInt(); - } - case OptionType::Bool: { - return contents[row].knownOption->getDefaultBool(); - } - case OptionType::Float: { - return contents[row].knownOption->getDefaultFloat(); - } - case OptionType::KeyBind: { - for (auto& keyBinding : *keybindingOptions) { - // this could become a std::find_if eventually, if someone wants to bother making it that. - if (keyBinding->minecraftKeyCode == contents[row].knownOption->getDefaultString()) { - return keyBinding->displayName; // + " (" + contents[row].knownOption->getDefaultString() + ")"; - } - } - - return contents[row].knownOption->getDefaultString(); - } - default: { - return QVariant(); - } - } - } else { - return QVariant(); - } - } - default: { - return QVariant(); - } - } - } - case Qt::CheckStateRole: { - switch (column) { - case Column::Value: { - if (contents[row].type == OptionType::Bool) { - return boolToState(contents[row].boolValue); - } else { - return QVariant(); - } - } - case Column::DefaultValue: { - if (contents[row].knownOption != nullptr && contents[row].type == OptionType::Bool) { - // checkboxes are tristate, this 1(true) needs to be 2 for fully checked - return contents[row].knownOption->getDefaultBool() * 2; - } else { - return QVariant(); - } - } default: { return QVariant(); } @@ -371,7 +264,7 @@ QModelIndex GameOptions::index(int row, int column, const QModelIndex& parent) c GameOptionItem* item = static_cast(parent.internalPointer()); return createIndex(row, column, &item->children[row]); } else { - return createIndex(row, column, &contents[row]); + return createIndex(row, column, reinterpret_cast(&contents[row])); } } @@ -388,7 +281,7 @@ QModelIndex GameOptions::parent(const QModelIndex& index) const return QModelIndex(); } else { GameOptionChildItem* child = static_cast(index.internalPointer()); - return createIndex(child->parentRow, 0, &contents[child->parentRow]); + return createIndex(child->parentRow, 0, reinterpret_cast(&contents[child->parentRow])); } } @@ -417,7 +310,7 @@ int GameOptions::columnCount(const QModelIndex& parent) const if (parent.parent().isValid()) return 0; - return 4; + return 3; } bool GameOptions::isLoaded() const diff --git a/launcher/minecraft/gameoptions/GameOptions.h b/launcher/minecraft/gameoptions/GameOptions.h index a4c8e56dc..4de2a7c88 100644 --- a/launcher/minecraft/gameoptions/GameOptions.h +++ b/launcher/minecraft/gameoptions/GameOptions.h @@ -60,7 +60,7 @@ struct GameOptionItem { class GameOptions : public QAbstractItemModel { Q_OBJECT public: - enum class Column { Key, Description, Value, DefaultValue }; + enum class Column { Key, Description, Value }; explicit GameOptions(const QString& path); virtual ~GameOptions() = default; @@ -86,6 +86,6 @@ class GameOptions : public QAbstractItemModel { QString path; int version = 0; - QMap>* knownOptions; - QList>* keybindingOptions; + QMap>* knownOptions{}; + QList>* keybindingOptions{}; }; diff --git a/launcher/minecraft/gameoptions/GameOptionsSchema.cpp b/launcher/minecraft/gameoptions/GameOptionsSchema.cpp index 22daaa28e..60bf53663 100644 --- a/launcher/minecraft/gameoptions/GameOptionsSchema.cpp +++ b/launcher/minecraft/gameoptions/GameOptionsSchema.cpp @@ -17,6 +17,7 @@ */ #include "GameOptionsSchema.h" #include +#include QMap> GameOptionsSchema::knownOptions; QList> GameOptionsSchema::keyboardButtons; @@ -46,154 +47,154 @@ void GameOptionsSchema::populateInternalOptionList() // clang-format off // data version - knownOptions["version"] = std::shared_ptr(new GameOption(0, "Data version of the client version this file was last saved in; used for upgrading default settings. (numeric)", true)); + knownOptions["version"] = std::make_shared(0, "Data version of the client version this file was last saved in; used for upgrading default settings. (numeric)", true); // general options - knownOptions["autoJump"] = std::shared_ptr(new GameOption(false, "Whether auto-jump is enabled")); - knownOptions["autoSuggestions"] = std::shared_ptr(new GameOption(true, "True if brigadier's command suggestion UI should always be shown, instead of just when pressing tab")); - knownOptions["chatColors"] = std::shared_ptr(new GameOption(true, "Whether colored chat is allowed")); - knownOptions["chatLinks"] = std::shared_ptr(new GameOption(true, "Whether links show as links or just text in the chat")); - knownOptions["chatLinksPrompt"] = std::shared_ptr(new GameOption(true, "Whether clicking on links in chat needs confirmation before opening them")); - knownOptions["enableVsync"] = std::shared_ptr(new GameOption(true, "Whether v-sync (vertical synchronization) is enabled")); - knownOptions["entityShadows"] = std::shared_ptr(new GameOption(true, "Whether to display entity shadows")); - knownOptions["forceUnicodeFont"] = std::shared_ptr(new GameOption(false, "Whether Unicode font should be used")); - knownOptions["discrete_mouse_scroll"] = std::shared_ptr(new GameOption(false, "Ignores scrolling set by operating system")); - knownOptions["invertYMouse"] = std::shared_ptr(new GameOption(false, "Whether mouse is inverted or not")); - knownOptions["realmsNotifications"] = std::shared_ptr(new GameOption(true, "Whether Realms invites are alerted on the main menu")); - knownOptions["reducedDebugInfo"] = std::shared_ptr(new GameOption(false, "Whether to show reduced information on the Debug screen")); - knownOptions["showSubtitles"] = std::shared_ptr(new GameOption(false, "If subtitles are shown")); - knownOptions["directionalAudio"] = std::shared_ptr(new GameOption(false, "If Directional Audio is enabled")); - knownOptions["touchscreen"] = std::shared_ptr(new GameOption(false, "Whether touchscreen controls are used")); - knownOptions["fullscreen"] = std::shared_ptr(new GameOption(false, "Whether the game attempts to go fullscreen at startup")); - knownOptions["bobView"] = std::shared_ptr(new GameOption(true, "Whether or not the camera bobs up and down as the player walks")); - knownOptions["toggleCrouch"] = std::shared_ptr(new GameOption(false, "Whether the sneak key must be pressed or held to activate sneaking")); - knownOptions["toggleSprint"] = std::shared_ptr(new GameOption(false, "Whether the sprint key must be pressed or held to activate sprinting")); - knownOptions["darkMojangStudiosBackground"] = std::shared_ptr(new GameOption(false, "Whether the Mojang Studios loading screen will appear monochrome")); - knownOptions["hideLightningFlashes"] = std::shared_ptr(new GameOption(false, "Hide lightning flashes (visual effect)")); + knownOptions["autoJump"] = std::make_shared(false, "Whether auto-jump is enabled"); + knownOptions["autoSuggestions"] = std::make_shared(true, "True if brigadier's command suggestion UI should always be shown, instead of just when pressing tab"); + knownOptions["chatColors"] = std::make_shared(true, "Whether colored chat is allowed"); + knownOptions["chatLinks"] = std::make_shared(true, "Whether links show as links or just text in the chat"); + knownOptions["chatLinksPrompt"] = std::make_shared(true, "Whether clicking on links in chat needs confirmation before opening them"); + knownOptions["enableVsync"] = std::make_shared(true, "Whether v-sync (vertical synchronization) is enabled"); + knownOptions["entityShadows"] = std::make_shared(true, "Whether to display entity shadows"); + knownOptions["forceUnicodeFont"] = std::make_shared(false, "Whether Unicode font should be used"); + knownOptions["discrete_mouse_scroll"] = std::make_shared(false, "Ignores scrolling set by operating system"); + knownOptions["invertYMouse"] = std::make_shared(false, "Whether mouse is inverted or not"); + knownOptions["realmsNotifications"] = std::make_shared(true, "Whether Realms invites are alerted on the main menu"); + knownOptions["reducedDebugInfo"] = std::make_shared(false, "Whether to show reduced information on the Debug screen"); + knownOptions["showSubtitles"] = std::make_shared(false, "If subtitles are shown"); + knownOptions["directionalAudio"] = std::make_shared(false, "If Directional Audio is enabled"); + knownOptions["touchscreen"] = std::make_shared(false, "Whether touchscreen controls are used"); + knownOptions["fullscreen"] = std::make_shared(false, "Whether the game attempts to go fullscreen at startup"); + knownOptions["bobView"] = std::make_shared(true, "Whether or not the camera bobs up and down as the player walks"); + knownOptions["toggleCrouch"] = std::make_shared(false, "Whether the sneak key must be pressed or held to activate sneaking"); + knownOptions["toggleSprint"] = std::make_shared(false, "Whether the sprint key must be pressed or held to activate sprinting"); + knownOptions["darkMojangStudiosBackground"] = std::make_shared(false, "Whether the Mojang Studios loading screen will appear monochrome"); + knownOptions["hideLightningFlashes"] = std::make_shared(false, "Hide lightning flashes (visual effect)"); - knownOptions["mouseSensitivity"] = std::shared_ptr(new GameOption(0.5, "How much a mouse movement changes the position of the camera", Range{ 0.0, 1.0 })); + knownOptions["mouseSensitivity"] = std::make_shared(0.5, "How much a mouse movement changes the position of the camera", Range{ 0.0, 1.0 }); // FOV: The in-game value is counted in degrees, however, the options.txt isn't. The value is converted into degrees with the following formula: degrees = 40 * value + 70 - knownOptions["fov"] = std::shared_ptr(new GameOption(0.0, "How large the field of view is", Range{ -1.0, 1.0 })); - knownOptions["screenEffectScale"] = std::shared_ptr(new GameOption(1.0, "Distortion Effects (how intense the effects of Nausea and nether portals are)", Range{ 0.0, 1.0 })); - knownOptions["fovEffectScale"] = std::shared_ptr(new GameOption(1.0, "FOV Effects (how much the field of view changes when sprinting, having Speed or Slowness etc.)", Range{ 0.0, 1.0 })); - knownOptions["darknessEffectScale"] = std::shared_ptr(new GameOption(1.0, "Darkness Pulsing (how much the Darkness effect pulses)", Range{ 0.0, 1.0 })); - knownOptions["gamma"] = std::shared_ptr(new GameOption(0.5, "Brightness", Range{ 0.0, 1.0 })); - knownOptions["renderDistance"] = std::shared_ptr(new GameOption(12, "The render distance in the chunk radius from the player - Note: The Maximum and default in vanilla is 32 and 12, 16 and 8 on 32bit machines", Range{ 2, 64 })); - knownOptions["simulationDistance"] = std::shared_ptr(new GameOption(12, "The simulation distance in the chunk radius from the player - Note: The Maximum and default in vanilla is 32 and 12, 16 and 8 on 32bit machines", Range{ 5, 32 })); - knownOptions["entityDistanceScaling"] = std::shared_ptr(new GameOption(1.0, "The maximum distance from the player that entities render", Range{ 0.5, 5.0 })); - knownOptions["guiScale"] = std::shared_ptr(new GameOption(0, "Size of interfaces - Note: 0 (Auto) or 1+ for size. Upper limit based on window resolution")); - knownOptions["particles"] = std::shared_ptr(new GameOption(0, "Amount of particles (such as rain, potion effects, etc.)", Range{ 0, 2 })); - knownOptions["maxFps"] = std::shared_ptr(new GameOption(120, "The maximum framerate", Range{ 10, 260 })); - knownOptions["difficulty‌"] = std::shared_ptr(new GameOption(2, "Has no effect after 1.7.2", Range{ 0, 3 })); - knownOptions["graphicsMode"] = std::shared_ptr(new GameOption(1, "Whether Fast (less detailed), Fancy (more detailed), or Fabulous! (most detailed) graphics are turned on", Range{ 0, 2 })); - knownOptions["ao"] = std::shared_ptr(new GameOption(true, "Smooth lighting (Ambient Occlusion)")); - knownOptions["prioritizeChunkUpdates"] = std::shared_ptr(new GameOption(0, "Chunk section update strategy", Range{ 0, 2 })); - knownOptions["biomeBlendRadius"] = std::shared_ptr(new GameOption(2, "Radius for which biome blending should happen", Range{ 0, 7 })); - knownOptions["renderClouds"] = std::shared_ptr(new GameOption("true", "Whether to display clouds", QStringList{ "true", "false", "fast" })); + knownOptions["fov"] = std::make_shared(0.0, "How large the field of view is", Range{ -1.0, 1.0 }); + knownOptions["screenEffectScale"] = std::make_shared(1.0, "Distortion Effects (how intense the effects of Nausea and nether portals are)", Range{ 0.0, 1.0 }); + knownOptions["fovEffectScale"] = std::make_shared(1.0, "FOV Effects (how much the field of view changes when sprinting, having Speed or Slowness etc.)", Range{ 0.0, 1.0 }); + knownOptions["darknessEffectScale"] = std::make_shared(1.0, "Darkness Pulsing (how much the Darkness effect pulses)", Range{ 0.0, 1.0 }); + knownOptions["gamma"] = std::make_shared(0.5, "Brightness", Range{ 0.0, 1.0 }); + knownOptions["renderDistance"] = std::make_shared(12, "The render distance in the chunk radius from the player - Note: The Maximum and default in vanilla is 32 and 12, 16 and 8 on 32bit machines", Range{ 2, 64 }); + knownOptions["simulationDistance"] = std::make_shared(12, "The simulation distance in the chunk radius from the player - Note: The Maximum and default in vanilla is 32 and 12, 16 and 8 on 32bit machines", Range{ 5, 32 }); + knownOptions["entityDistanceScaling"] = std::make_shared(1.0, "The maximum distance from the player that entities render", Range{ 0.5, 5.0 }); + knownOptions["guiScale"] = std::make_shared(0, "Size of interfaces - Note: 0 (Auto) or 1+ for size. Upper limit based on window resolution"); + knownOptions["particles"] = std::make_shared(0, "Amount of particles (such as rain, potion effects, etc.)", Range{ 0, 2 }); + knownOptions["maxFps"] = std::make_shared(120, "The maximum framerate", Range{ 10, 260 }); + knownOptions["difficulty‌"] = std::make_shared(2, "Has no effect after 1.7.2", Range{ 0, 3 }); + knownOptions["graphicsMode"] = std::make_shared(1, "Whether Fast (less detailed), Fancy (more detailed), or Fabulous! (most detailed) graphics are turned on", Range{ 0, 2 }); + knownOptions["ao"] = std::make_shared(true, "Smooth lighting (Ambient Occlusion)"); + knownOptions["prioritizeChunkUpdates"] = std::make_shared(0, "Chunk section update strategy", Range{ 0, 2 }); + knownOptions["biomeBlendRadius"] = std::make_shared(2, "Radius for which biome blending should happen", Range{ 0, 7 }); + knownOptions["renderClouds"] = std::make_shared("true", "Whether to display clouds", QStringList{ "true", "false", "fast" }); - knownOptions["resourcePacks"] = std::shared_ptr(new GameOption("[]", "A list of active resource packs", QStringList(), false)); - knownOptions["incompatibleResourcePacks"] = std::shared_ptr(new GameOption("[]", "A list of active resource packs that are marked as incompatible with the current Minecraft version.", QStringList(), false)); + knownOptions["resourcePacks"] = std::make_shared("[]", "A list of active resource packs", QStringList(), false); + knownOptions["incompatibleResourcePacks"] = std::make_shared("[]", "A list of active resource packs that are marked as incompatible with the current Minecraft version.", QStringList(), false); - knownOptions["lastServer"] = std::shared_ptr(new GameOption("", "Address of last server used with Direct Connection")); - knownOptions["lang"] = std::shared_ptr(new GameOption("en_us", "Language to be used")); - knownOptions["soundDevice"] = std::shared_ptr(new GameOption("", "Sound device to be used")); - knownOptions["chatVisibility"] = std::shared_ptr(new GameOption(0, "What is seen in chat", Range{ 0, 2 })); - knownOptions["chatOpacity"] = std::shared_ptr(new GameOption(1.0, "Opacity of the chat", Range{ 0, 1 })); - knownOptions["chatLineSpacing"] = std::shared_ptr(new GameOption(0.0, "Spacing between text in chat", Range{ 0, 1 })); - knownOptions["textBackgroundOpacity"] = std::shared_ptr(new GameOption(0.5, "Opacity of text background", Range{ 0, 1 })); - knownOptions["backgroundForChatOnly"] = std::shared_ptr(new GameOption(true, "Toggles if the background is only in chat or if it's everywhere")); - knownOptions["hideServerAddress"] = std::shared_ptr(new GameOption(false, "Has no effect in modern versions")); - knownOptions["advancedItemTooltips"] = std::shared_ptr(new GameOption(false, "Whether hovering over items in the inventory shows its ID and durability; toggled by pressing F3 + H")); - knownOptions["pauseOnLostFocus"] = std::shared_ptr(new GameOption(true, "Whether switching out of Minecraft without pressing Esc or opening an in-game interface automatically pauses the game; toggled by pressing F3 + P")); - knownOptions["overrideWidth"] = std::shared_ptr(new GameOption(0, "Width to open Minecraft with in pixels (0 means default to the Minecraft settings); no in-game control")); - knownOptions["overrideHeight"] = std::shared_ptr(new GameOption(0, "Height to open Minecraft with in pixels (0 means default to the Minecraft settings); no in-game control")); - knownOptions["heldItemTooltips"] = std::shared_ptr(new GameOption(true, "Whether switching between items shows the name of the item; no in-game control")); - knownOptions["chatHeightFocused"] = std::shared_ptr(new GameOption(1.0, "How tall the chat span is", Range{ 0, 1 })); - knownOptions["chatDelay"] = std::shared_ptr(new GameOption(0.0, "How much delay there is between text", Range{ 0, 6 })); - knownOptions["chatHeightUnfocused"] = std::shared_ptr(new GameOption(0.4375, "How tall the maximum chat span is, when the chat button is not pressed", Range{ 0, 1 })); - knownOptions["chatScale"] = std::shared_ptr(new GameOption(1.0, "The scale/size of the text in the chat", Range{ 0, 1 })); - knownOptions["chatWidth"] = std::shared_ptr(new GameOption(1.0, "The span width of the chat", Range{ 0, 1 })); - knownOptions["mipmapLevels"] = std::shared_ptr(new GameOption(4, "Amount by which distant textures are smoothed", Range{0, 4})); - knownOptions["useNativeTransport"] = std::shared_ptr(new GameOption(true, "Whether to use a Netty EpollSocketChannel for connections to servers instead of a NioSocketChannel (only applies if EPOLL is available on the user's system)")); - knownOptions["mainHand"] = std::shared_ptr(new GameOption("right", "Whether the main hand appears as left or right", QStringList{ "left", "right" })); - knownOptions["attackIndicator"] = std::shared_ptr(new GameOption(1, "When hitting, how the attack indicator is shown on screen", Range{ 0, 2 })); - knownOptions["narrator"] = std::shared_ptr(new GameOption(0, "Setting of the Narrator", Range{ 0, 3 })); - knownOptions["tutorialStep"] = std::shared_ptr(new GameOption("movement", "Next stage of tutorial hints to display", - QStringList{ "movement", "find_tree", "punch_tree", "open_inventory", "craft_planks", "none" })); - knownOptions["mouseWheelSensitivity"] = std::shared_ptr(new GameOption(1.0f, "Allows making the mouse wheel more sensitive (see MC-123773)", Range{ 1.0f, 10.0f })); - knownOptions["rawMouseInput"] = std::shared_ptr(new GameOption(true, "Ignores acceleration set by the operating system")); - knownOptions["glDebugVerbosity"] = std::shared_ptr(new GameOption(1, "LWJGL log info level (only on some machines)", Range{ 0, 4 })); - knownOptions["skipMultiplayerWarning"] = std::shared_ptr(new GameOption(true, "Whether to skip the legal disclaimer when entering the multiplayer screen")); - knownOptions["skipRealms32bitWarning"] = std::shared_ptr(new GameOption(true, "Whether to skip the 32-bit environment warning when entering the Realms screen")); - knownOptions["hideMatchedNames"] = std::shared_ptr(new GameOption(true, "Some servers send chat messages in non-standard formats. With this option on, the game will attempt to apply chat hiding anyway by matching the text in messages.")); - knownOptions["joinedFirstServer"] = std::shared_ptr(new GameOption(true, "Whether the player has joined a server before. If false, the Social Interactions tutorial hint will appear when joining a server.")); - knownOptions["hideBundleTutorial"] = std::shared_ptr(new GameOption(true, "Whether the player has seen the bundle tutorial hint when trying to use a bundle.")); - knownOptions["syncChunkWrites"] = std::shared_ptr(new GameOption(true, "Whether to open region files in synchronous mode")); - knownOptions["showAutosaveIndicator"] = std::shared_ptr(new GameOption(true, "Whether to show autosave indicator on the right-bottom of the screen")); - knownOptions["allowServerListing"] = std::shared_ptr(new GameOption(true, "Whether to allow player's ID to be shown in the player list shown on the multiplayer screen")); + knownOptions["lastServer"] = std::make_shared("", "Address of last server used with Direct Connection"); + knownOptions["lang"] = std::make_shared("en_us", "Language to be used"); + knownOptions["soundDevice"] = std::make_shared("", "Sound device to be used"); + knownOptions["chatVisibility"] = std::make_shared(0, "What is seen in chat", Range{ 0, 2 }); + knownOptions["chatOpacity"] = std::make_shared(1.0, "Opacity of the chat", Range{ 0, 1 }); + knownOptions["chatLineSpacing"] = std::make_shared(0.0, "Spacing between text in chat", Range{ 0, 1 }); + knownOptions["textBackgroundOpacity"] = std::make_shared(0.5, "Opacity of text background", Range{ 0, 1 }); + knownOptions["backgroundForChatOnly"] = std::make_shared(true, "Toggles if the background is only in chat or if it's everywhere"); + knownOptions["hideServerAddress"] = std::make_shared(false, "Has no effect in modern versions"); + knownOptions["advancedItemTooltips"] = std::make_shared(false, "Whether hovering over items in the inventory shows its ID and durability; toggled by pressing F3 + H"); + knownOptions["pauseOnLostFocus"] = std::make_shared(true, "Whether switching out of Minecraft without pressing Esc or opening an in-game interface automatically pauses the game; toggled by pressing F3 + P"); + knownOptions["overrideWidth"] = std::make_shared(0, "Width to open Minecraft with in pixels (0 means default to the Minecraft settings); no in-game control"); + knownOptions["overrideHeight"] = std::make_shared(0, "Height to open Minecraft with in pixels (0 means default to the Minecraft settings); no in-game control"); + knownOptions["heldItemTooltips"] = std::make_shared(true, "Whether switching between items shows the name of the item; no in-game control"); + knownOptions["chatHeightFocused"] = std::make_shared(1.0, "How tall the chat span is", Range{ 0, 1 }); + knownOptions["chatDelay"] = std::make_shared(0.0, "How much delay there is between text", Range{ 0, 6 }); + knownOptions["chatHeightUnfocused"] = std::make_shared(0.4375, "How tall the maximum chat span is, when the chat button is not pressed", Range{ 0, 1 }); + knownOptions["chatScale"] = std::make_shared(1.0, "The scale/size of the text in the chat", Range{ 0, 1 }); + knownOptions["chatWidth"] = std::make_shared(1.0, "The span width of the chat", Range{ 0, 1 }); + knownOptions["mipmapLevels"] = std::make_shared(4, "Amount by which distant textures are smoothed", Range{0, 4}); + knownOptions["useNativeTransport"] = std::make_shared(true, "Whether to use a Netty EpollSocketChannel for connections to servers instead of a NioSocketChannel (only applies if EPOLL is available on the user's system)"); + knownOptions["mainHand"] = std::make_shared("right", "Whether the main hand appears as left or right", QStringList{ "left", "right" }); + knownOptions["attackIndicator"] = std::make_shared(1, "When hitting, how the attack indicator is shown on screen", Range{ 0, 2 }); + knownOptions["narrator"] = std::make_shared(0, "Setting of the Narrator", Range{ 0, 3 }); + knownOptions["tutorialStep"] = std::make_shared("movement", "Next stage of tutorial hints to display", + QStringList{ "movement", "find_tree", "punch_tree", "open_inventory", "craft_planks", "none" }); + knownOptions["mouseWheelSensitivity"] = std::make_shared(1.0f, "Allows making the mouse wheel more sensitive (see MC-123773)", Range{ 1.0f, 10.0f }); + knownOptions["rawMouseInput"] = std::make_shared(true, "Ignores acceleration set by the operating system"); + knownOptions["glDebugVerbosity"] = std::make_shared(1, "LWJGL log info level (only on some machines)", Range{ 0, 4 }); + knownOptions["skipMultiplayerWarning"] = std::make_shared(true, "Whether to skip the legal disclaimer when entering the multiplayer screen"); + knownOptions["skipRealms32bitWarning"] = std::make_shared(true, "Whether to skip the 32-bit environment warning when entering the Realms screen"); + knownOptions["hideMatchedNames"] = std::make_shared(true, "Some servers send chat messages in non-standard formats. With this option on, the game will attempt to apply chat hiding anyway by matching the text in messages."); + knownOptions["joinedFirstServer"] = std::make_shared(true, "Whether the player has joined a server before. If false, the Social Interactions tutorial hint will appear when joining a server."); + knownOptions["hideBundleTutorial"] = std::make_shared(true, "Whether the player has seen the bundle tutorial hint when trying to use a bundle."); + knownOptions["syncChunkWrites"] = std::make_shared(true, "Whether to open region files in synchronous mode"); + knownOptions["showAutosaveIndicator"] = std::make_shared(true, "Whether to show autosave indicator on the right-bottom of the screen"); + knownOptions["allowServerListing"] = std::make_shared(true, "Whether to allow player's ID to be shown in the player list shown on the multiplayer screen"); // Keys Binds - knownOptions["key_key.attack"] = std::shared_ptr(new GameOption("key.mouse.left", "Attack control", OptionType::KeyBind)); - knownOptions["key_key.use"] = std::shared_ptr(new GameOption("key.mouse.right", "Use Item control", OptionType::KeyBind)); - knownOptions["key_key.forward"] = std::shared_ptr(new GameOption("key.keyboard.w", "Forward control ", OptionType::KeyBind)); - knownOptions["key_key.left"] = std::shared_ptr(new GameOption("key.keyboard.a", "Left control", OptionType::KeyBind)); - knownOptions["key_key.back"] = std::shared_ptr(new GameOption("key.keyboard.s", "Back control", OptionType::KeyBind)); - knownOptions["key_key.right"] = std::shared_ptr(new GameOption("key.keyboard.d", "Right control", OptionType::KeyBind)); - knownOptions["key_key.jump"] = std::shared_ptr(new GameOption("key.keyboard.space", "Jump control", OptionType::KeyBind)); - knownOptions["key_key.sneak"] = std::shared_ptr(new GameOption("key.keyboard.left.shift", "Sneak control", OptionType::KeyBind)); - knownOptions["key_key.sprint"] = std::shared_ptr(new GameOption("key.keyboard.left.control", "Sprint control ", OptionType::KeyBind)); - knownOptions["key_key.drop"] = std::shared_ptr(new GameOption("key.keyboard.q", "Drop control ", OptionType::KeyBind)); - knownOptions["key_key.inventory"] = std::shared_ptr(new GameOption("key.keyboard.e", "Inventory control", OptionType::KeyBind)); - knownOptions["key_key.chat"] = std::shared_ptr(new GameOption("key.keyboard.t", "Chat control", OptionType::KeyBind)); - knownOptions["key_key.playerlist"] = std::shared_ptr(new GameOption("key.keyboard.tab", "List Players control", OptionType::KeyBind)); - knownOptions["key_key.pickItem"] = std::shared_ptr(new GameOption("key.mouse.middle", "Pick Block control", OptionType::KeyBind)); - knownOptions["key_key.command"] = std::shared_ptr(new GameOption("key.keyboard.slash", "Command control", OptionType::KeyBind)); - knownOptions["key_key.socialInteractions"] = std::shared_ptr(new GameOption("key.keyboard.p", "Social Interaction control", OptionType::KeyBind)); - knownOptions["key_key.screenshot"] = std::shared_ptr(new GameOption("key.keyboard.f2", "Screenshot control", OptionType::KeyBind)); - knownOptions["key_key.togglePerspective"] = std::shared_ptr(new GameOption("key.keyboard.f5", "Perspective control", OptionType::KeyBind)); - knownOptions["key_key.smoothCamera"] = std::shared_ptr(new GameOption("key.keyboard.unknown", "Mouse Smoothing control", OptionType::KeyBind)); - knownOptions["key_key.fullscreen"] = std::shared_ptr(new GameOption("key.keyboard.f11", "Fullscreen control", OptionType::KeyBind)); - knownOptions["key_key.spectatorOutlines"] = std::shared_ptr(new GameOption("key.keyboard.unknown", "Visibility of player outlines in Spectator Mode control", OptionType::KeyBind)); - knownOptions["key_key.swapOffhand"] = std::shared_ptr(new GameOption("key.keyboard.f", "Swapping of items between both hands control", OptionType::KeyBind)); - knownOptions["key_key.saveToolbarActivator"] = std::shared_ptr(new GameOption("key.keyboard.c", "Save current toolbar to a slot (in Creative Mode)", OptionType::KeyBind)); - knownOptions["key_key.loadToolbarActivator"] = std::shared_ptr(new GameOption("key.keyboard.x", "Load toolbar from a slot (in Creative Mode)", OptionType::KeyBind)); - knownOptions["key_key.advancements"] = std::shared_ptr(new GameOption("key.keyboard.l", "Open the Advancements screen", OptionType::KeyBind)); - knownOptions["key_key.hotbar.1"] = std::shared_ptr(new GameOption("key.keyboard.1", "Hotbar Slot 1 control", OptionType::KeyBind)); - knownOptions["key_key.hotbar.2"] = std::shared_ptr(new GameOption("key.keyboard.2", "Hotbar Slot 2 control", OptionType::KeyBind)); - knownOptions["key_key.hotbar.3"] = std::shared_ptr(new GameOption("key.keyboard.3", "Hotbar Slot 3 control", OptionType::KeyBind)); - knownOptions["key_key.hotbar.4"] = std::shared_ptr(new GameOption("key.keyboard.4", "Hotbar Slot 4 control", OptionType::KeyBind)); - knownOptions["key_key.hotbar.5"] = std::shared_ptr(new GameOption("key.keyboard.5", "Hotbar Slot 5 control", OptionType::KeyBind)); - knownOptions["key_key.hotbar.6"] = std::shared_ptr(new GameOption("key.keyboard.6", "Hotbar Slot 6 control", OptionType::KeyBind)); - knownOptions["key_key.hotbar.7"] = std::shared_ptr(new GameOption("key.keyboard.7", "Hotbar Slot 7 control", OptionType::KeyBind)); - knownOptions["key_key.hotbar.8"] = std::shared_ptr(new GameOption("key.keyboard.8", "Hotbar Slot 8 control", OptionType::KeyBind)); - knownOptions["key_key.hotbar.9"] = std::shared_ptr(new GameOption("key.keyboard.9", "Hotbar Slot 9 control", OptionType::KeyBind)); + knownOptions["key_key.attack"] = std::make_shared("key.mouse.left", "Attack control"); + knownOptions["key_key.use"] = std::make_shared("key.mouse.right", "Use Item control"); + knownOptions["key_key.forward"] = std::make_shared("key.keyboard.w", "Forward control "); + knownOptions["key_key.left"] = std::make_shared("key.keyboard.a", "Left control"); + knownOptions["key_key.back"] = std::make_shared("key.keyboard.s", "Back control"); + knownOptions["key_key.right"] = std::make_shared("key.keyboard.d", "Right control"); + knownOptions["key_key.jump"] = std::make_shared("key.keyboard.space", "Jump control"); + knownOptions["key_key.sneak"] = std::make_shared("key.keyboard.left.shift", "Sneak control"); + knownOptions["key_key.sprint"] = std::make_shared("key.keyboard.left.control", "Sprint control "); + knownOptions["key_key.drop"] = std::make_shared("key.keyboard.q", "Drop control "); + knownOptions["key_key.inventory"] = std::make_shared("key.keyboard.e", "Inventory control"); + knownOptions["key_key.chat"] = std::make_shared("key.keyboard.t", "Chat control"); + knownOptions["key_key.playerlist"] = std::make_shared("key.keyboard.tab", "List Players control"); + knownOptions["key_key.pickItem"] = std::make_shared("key.mouse.middle", "Pick Block control"); + knownOptions["key_key.command"] = std::make_shared("key.keyboard.slash", "Command control"); + knownOptions["key_key.socialInteractions"] = std::make_shared("key.keyboard.p", "Social Interaction control"); + knownOptions["key_key.screenshot"] = std::make_shared("key.keyboard.f2", "Screenshot control"); + knownOptions["key_key.togglePerspective"] = std::make_shared("key.keyboard.f5", "Perspective control"); + knownOptions["key_key.smoothCamera"] = std::make_shared("key.keyboard.unknown", "Mouse Smoothing control"); + knownOptions["key_key.fullscreen"] = std::make_shared("key.keyboard.f11", "Fullscreen control"); + knownOptions["key_key.spectatorOutlines"] = std::make_shared("key.keyboard.unknown", "Visibility of player outlines in Spectator Mode control"); + knownOptions["key_key.swapOffhand"] = std::make_shared("key.keyboard.f", "Swapping of items between both hands control"); + knownOptions["key_key.saveToolbarActivator"] = std::make_shared("key.keyboard.c", "Save current toolbar to a slot (in Creative Mode)"); + knownOptions["key_key.loadToolbarActivator"] = std::make_shared("key.keyboard.x", "Load toolbar from a slot (in Creative Mode)"); + knownOptions["key_key.advancements"] = std::make_shared("key.keyboard.l", "Open the Advancements screen"); + knownOptions["key_key.hotbar.1"] = std::make_shared("key.keyboard.1", "Hotbar Slot 1 control"); + knownOptions["key_key.hotbar.2"] = std::make_shared("key.keyboard.2", "Hotbar Slot 2 control"); + knownOptions["key_key.hotbar.3"] = std::make_shared("key.keyboard.3", "Hotbar Slot 3 control"); + knownOptions["key_key.hotbar.4"] = std::make_shared("key.keyboard.4", "Hotbar Slot 4 control"); + knownOptions["key_key.hotbar.5"] = std::make_shared("key.keyboard.5", "Hotbar Slot 5 control"); + knownOptions["key_key.hotbar.6"] = std::make_shared("key.keyboard.6", "Hotbar Slot 6 control"); + knownOptions["key_key.hotbar.7"] = std::make_shared("key.keyboard.7", "Hotbar Slot 7 control"); + knownOptions["key_key.hotbar.8"] = std::make_shared("key.keyboard.8", "Hotbar Slot 8 control"); + knownOptions["key_key.hotbar.9"] = std::make_shared("key.keyboard.9", "Hotbar Slot 9 control"); // Sound - knownOptions["soundCategory_master"] = std::shared_ptr(new GameOption(1.0f, "The volume of all sounds", Range{ 0, 1 })); - knownOptions["soundCategory_music"] = std::shared_ptr(new GameOption(1.0f, "The volume of gameplay music", Range{ 0, 1 })); - knownOptions["soundCategory_record"] = std::shared_ptr(new GameOption(1.0f, "The volume of music/sounds from Jukeboxes and Note Blocks", Range{ 0, 1 })); - knownOptions["soundCategory_weather"] = std::shared_ptr(new GameOption(1.0f, "The volume of rain and thunder", Range{ 0, 1 })); - knownOptions["soundCategory_block"] = std::shared_ptr(new GameOption(1.0f, "The volume of blocks", Range{ 0, 1 })); - knownOptions["soundCategory_hostile"] = std::shared_ptr(new GameOption(1.0f, "The volume of hostile and neutral mobs", Range{ 0, 1 })); - knownOptions["soundCategory_neutral"] = std::shared_ptr(new GameOption(1.0f, "The volume of passive mobs", Range{ 0, 1 })); - knownOptions["soundCategory_player"] = std::shared_ptr(new GameOption(1.0f, "The volume of players", Range{ 0, 1 })); - knownOptions["soundCategory_ambient"] = std::shared_ptr(new GameOption(1.0f, "The volume of cave sounds and fireworks", Range{ 0, 1 })); - knownOptions["soundCategory_voice"] = std::shared_ptr(new GameOption(1.0f, "The volume of voices", Range{ 0, 1 })); + knownOptions["soundCategory_master"] = std::make_shared(1.0f, "The volume of all sounds", Range{ 0, 1 }); + knownOptions["soundCategory_music"] = std::make_shared(1.0f, "The volume of gameplay music", Range{ 0, 1 }); + knownOptions["soundCategory_record"] = std::make_shared(1.0f, "The volume of music/sounds from Jukeboxes and Note Blocks", Range{ 0, 1 }); + knownOptions["soundCategory_weather"] = std::make_shared(1.0f, "The volume of rain and thunder", Range{ 0, 1 }); + knownOptions["soundCategory_block"] = std::make_shared(1.0f, "The volume of blocks", Range{ 0, 1 }); + knownOptions["soundCategory_hostile"] = std::make_shared(1.0f, "The volume of hostile and neutral mobs", Range{ 0, 1 }); + knownOptions["soundCategory_neutral"] = std::make_shared(1.0f, "The volume of passive mobs", Range{ 0, 1 }); + knownOptions["soundCategory_player"] = std::make_shared(1.0f, "The volume of players", Range{ 0, 1 }); + knownOptions["soundCategory_ambient"] = std::make_shared(1.0f, "The volume of cave sounds and fireworks", Range{ 0, 1 }); + knownOptions["soundCategory_voice"] = std::make_shared(1.0f, "The volume of voices", Range{ 0, 1 }); // Model Parts - knownOptions["modelPart_cape"] = std::shared_ptr(new GameOption(true, "Whether the cape is shown")); - knownOptions["modelPart_jacket"] = std::shared_ptr(new GameOption(true, "Whether the \"Jacket\" skin layer is shown")); - knownOptions["modelPart_left_sleeve"] = std::shared_ptr(new GameOption(true, "Whether the \"Left Sleeve\" skin layer is shown")); - knownOptions["modelPart_right_sleeve"] = std::shared_ptr(new GameOption(true, "Whether the \"Right Sleeve\" skin layer is shown")); - knownOptions["modelPart_left_pants_leg"] = std::shared_ptr(new GameOption(true, "Whether the \"Left Pants Leg\" skin layer is shown")); - knownOptions["modelPart_right_pants_leg"] = std::shared_ptr(new GameOption(true, "Whether the \"Right Pants Leg\" skin layer is shown")); - knownOptions["modelPart_hat"] = std::shared_ptr(new GameOption(true, "Whether the \"Hat\" skin layer is shown")); + knownOptions["modelPart_cape"] = std::make_shared(true, "Whether the cape is shown"); + knownOptions["modelPart_jacket"] = std::make_shared(true, "Whether the \"Jacket\" skin layer is shown"); + knownOptions["modelPart_left_sleeve"] = std::make_shared(true, "Whether the \"Left Sleeve\" skin layer is shown"); + knownOptions["modelPart_right_sleeve"] = std::make_shared(true, "Whether the \"Right Sleeve\" skin layer is shown"); + knownOptions["modelPart_left_pants_leg"] = std::make_shared(true, "Whether the \"Left Pants Leg\" skin layer is shown"); + knownOptions["modelPart_right_pants_leg"] = std::make_shared(true, "Whether the \"Right Pants Leg\" skin layer is shown"); + knownOptions["modelPart_hat"] = std::make_shared(true, "Whether the \"Hat\" skin layer is shown"); // Misc - knownOptions["fullscreenResolution"] = std::shared_ptr(new GameOption("", "Changes the resolution of the game when in fullscreen mode. The only values allowed are the values supported by the user's monitor, shown when changing the screen resolution in the operating system settings. Setting this option to a value not supported by the monitor resets the option to \"Current\". When set to \"Current\", this option is absent from options.txt. ")); + knownOptions["fullscreenResolution"] = std::make_shared("", "Changes the resolution of the game when in fullscreen mode. The only values allowed are the values supported by the user's monitor, shown when changing the screen resolution in the operating system settings. Setting this option to a value not supported by the monitor resets the option to \"Current\". When set to \"Current\", this option is absent from options.txt. "); // Not vanilla - from mods or modloaders - knownOptions["quilt_available_resourcepacks"] = std::shared_ptr(new GameOption{"[]", "Quilt Internal Available Resource Packs", QStringList(), false}); + knownOptions["quilt_available_resourcepacks"] = std::make_shared("[]", "Quilt Internal Available Resource Packs", QStringList(), false); } @@ -238,7 +239,7 @@ void GameOptionsSchema::populateInternalKeyBindList() { addMouseBind( "key.mouse.26", 0, QObject::tr("Mouse Button 26"), Qt::MouseButton::ExtraButton22 ); addMouseBind( "key.mouse.27", 0, QObject::tr("Mouse Button 27"), Qt::MouseButton::ExtraButton23 ); addMouseBind( "key.mouse.28", 0, QObject::tr("Mouse Button 28"), Qt::MouseButton::ExtraButton24 ); - // not sure if it makes sense to go this far, but its how far Qt can count. + // not sure if it makes sense to go this far, but it's how far Qt can count. // Number Row addKeyboardBind("key.keyboard.0", 11, QObject::tr("0"), Qt::Key::Key_0 ); @@ -376,3 +377,5 @@ void GameOptionsSchema::populateInternalKeyBindList() { // clang-format on }; +QString GameOption::getDefaultString() +{ return defaultString; } diff --git a/launcher/minecraft/gameoptions/GameOptionsSchema.h b/launcher/minecraft/gameoptions/GameOptionsSchema.h index a83a95c4e..ab8e9aee7 100644 --- a/launcher/minecraft/gameoptions/GameOptionsSchema.h +++ b/launcher/minecraft/gameoptions/GameOptionsSchema.h @@ -21,11 +21,12 @@ #include #include #include +#include enum class OptionType { String, Int, Float, Bool, KeyBind }; template struct Range { - typename T min, max; + T min, max; }; union UniversalRange { @@ -46,10 +47,9 @@ class GameOption { /// @brief Bool variant /// @param defaultValue Default Value /// @param description The Description for this Option - /// @param readOnly wether or not this option should be editable - GameOption(bool defaultValue, QString description = "", bool readOnly = false) - : description(description) - , type(OptionType::Bool), readOnly(readOnly) { + /// @param readOnly whether or not this option should be editable + explicit GameOption(bool defaultValue, QString description = "", bool readOnly = false) + : description(std::move(description)), type(OptionType::Bool), readOnly(readOnly) { GameOption::defaultValue.boolValue = defaultValue; }; @@ -57,31 +57,31 @@ class GameOption { /// @param defaultValue Default Value /// @param description The Description for this Option /// @param validValues List of possible options for this field, if empty any input will be possible - /// @param readOnly wether or not this option should be editable - GameOption(QString defaultValue = "", QString description = "", QList validValues = QList(), bool readOnly = false) - : description(description), type(OptionType::String), readOnly(readOnly), defaultString(defaultValue), validValues(validValues){}; + /// @param readOnly whether or not this option should be editable + explicit GameOption(QString defaultValue = "", QString description = "", QList validValues = QList(), bool readOnly = false) + : description(std::move(description)), type(OptionType::String), readOnly(readOnly), defaultString(std::move(defaultValue)), validValues(std::move(validValues)){}; /// @brief KeyBind variant /// @param defaultValue Default Value /// @param description The Description for this Option - GameOption(QString defaultValue = "", QString description = "", OptionType type = OptionType::KeyBind) - : description(description), type(OptionType::KeyBind), defaultString(defaultValue){}; + explicit GameOption(QString defaultValue = "", QString description = "") + : description(std::move(description)), type(OptionType::KeyBind), defaultString(std::move(defaultValue)){}; /// @brief Float variant /// @param defaultValue Default Value /// @param description The Description for this Option /// @param range if left empty (0,0) no limits are assumed - /// @param readOnly wether or not this option should be editable - GameOption(float defaultValue = 0.0f, QString description = "", Range range = Range{ 0.0f, 0.0f }, bool readOnly = false) - : description(description), type(OptionType::Float), readOnly(readOnly), range{ range }, defaultValue{ defaultValue } {}; + /// @param readOnly whether or not this option should be editable + explicit GameOption(float defaultValue = 0.0f, QString description = "", Range range = Range{ 0.0f, 0.0f }, bool readOnly = false) + : description(std::move(description)), type(OptionType::Float), readOnly(readOnly), range{ range }, defaultValue{ defaultValue } {}; /// @brief Int variant /// @param defaultValue Default Value /// @param description Description for this Option /// @param range if left empty (0,0) no limits are assumed - /// @param readOnly wether or not this option should be editable - GameOption(int defaultValue = 0, QString description = "", Range range = Range{ 0, 0 }, bool readOnly = false) - : description(description), type(OptionType::Int), readOnly(readOnly) + /// @param readOnly whether or not this option should be editable + explicit GameOption(int defaultValue = 0, QString description = "", Range range = Range{ 0, 0 }, bool readOnly = false) + : description(std::move(description)), type(OptionType::Int), readOnly(readOnly) { GameOption::range.intRange = range; GameOption::defaultValue.intValue = defaultValue; @@ -94,13 +94,13 @@ class GameOption { //int introducedVersion; //int removedVersion; - int getDefaultInt() { return defaultValue.intValue; }; - bool getDefaultBool() { return defaultValue.boolValue; }; - float getDefaultFloat() { return defaultValue.floatValue; }; - QString getDefaultString() { return defaultString; }; + int getDefaultInt() const { return defaultValue.intValue; }; + bool getDefaultBool() const { return defaultValue.boolValue; }; + float getDefaultFloat() const { return defaultValue.floatValue; }; + QString getDefaultString();; - Range getIntRange() { return range.intRange; }; - Range getFloatRange() { return range.floatRange; }; + Range getIntRange() const { return range.intRange; }; + Range getFloatRange() const { return range.floatRange; }; private: OptionValue defaultValue = { 0.0f }; @@ -109,12 +109,6 @@ class GameOption { }; -union a { - QList enumValues; - struct BoolMarker { - } boolean; -}; - union mouseOrKeyboardButton { Qt::Key keyboardKey; Qt::MouseButton mouseButton; @@ -123,13 +117,13 @@ union mouseOrKeyboardButton { class KeyBindData { public: KeyBindData(QString minecraftKeyCode, int glfwCode, QString displayName, Qt::MouseButton mouseButton) : - minecraftKeyCode(minecraftKeyCode), glfwCode(glfwCode), displayName(displayName) + minecraftKeyCode(std::move(minecraftKeyCode)), glfwCode(glfwCode), displayName(std::move(displayName)) { qtKeyCode.mouseButton = mouseButton; } KeyBindData(QString minecraftKeyCode, int glfwCode, QString displayName, Qt::Key keyboardKey) - : minecraftKeyCode(minecraftKeyCode), glfwCode(glfwCode), displayName(displayName) + : minecraftKeyCode(std::move(minecraftKeyCode)), glfwCode(glfwCode), displayName(std::move(displayName)) { qtKeyCode.keyboardKey = keyboardKey; } @@ -154,13 +148,13 @@ class GameOptionsSchema { static void populateInternalOptionList(); static void populateInternalKeyBindList(); - static void addKeyboardBind(QString minecraftKeyCode, int glfwCode, QString displayName, Qt::Key keyboardKey) + static void addKeyboardBind(const QString& minecraftKeyCode, int glfwCode, const QString& displayName, Qt::Key keyboardKey) { - keyboardButtons.append(std::shared_ptr(new KeyBindData(minecraftKeyCode, glfwCode, displayName, keyboardKey))); + keyboardButtons.append(std::make_shared(minecraftKeyCode, glfwCode, displayName, keyboardKey)); }; - static void addMouseBind(QString minecraftKeyCode, int glfwCode, QString displayName, Qt::MouseButton mouseButton) + static void addMouseBind(const QString& minecraftKeyCode, int glfwCode, const QString& displayName, Qt::MouseButton mouseButton) { - keyboardButtons.append(std::shared_ptr(new KeyBindData(minecraftKeyCode, glfwCode, displayName, mouseButton))); + keyboardButtons.append(std::make_shared(minecraftKeyCode, glfwCode, displayName, mouseButton)); }; }; diff --git a/launcher/ui/pages/instance/GameOptionsPage.cpp b/launcher/ui/pages/instance/GameOptionsPage.cpp index d46e1b252..9b9d13c69 100644 --- a/launcher/ui/pages/instance/GameOptionsPage.cpp +++ b/launcher/ui/pages/instance/GameOptionsPage.cpp @@ -37,8 +37,9 @@ #include "GameOptionsPage.h" #include "minecraft/MinecraftInstance.h" -#include "minecraft/gameoptions/GameOptions.h" #include "minecraft/gameoptions/GameOptionDelegate.h" +#include "minecraft/gameoptions/GameOptions.h" +#include "ui_GameOptionsPage.h" GameOptionsPage::GameOptionsPage(MinecraftInstance* inst, QWidget* parent) : QWidget(parent), ui(new Ui::GameOptionsPage) { @@ -48,13 +49,16 @@ GameOptionsPage::GameOptionsPage(MinecraftInstance* inst, QWidget* parent) : QWi ui->optionsView->setModel(m_model.get()); ui->optionsView->setItemDelegateForColumn(2, new GameOptionDelegate(ui->optionsView, m_model->getContents())); ui->optionsView->setEditTriggers(QAbstractItemView::AllEditTriggers); + for (int i = 0; i < m_model->getContents()->size(); ++i) { + ui->optionsView->openPersistentEditor(m_model->index(i, 2)); + } auto head = ui->optionsView->header(); - head->setDefaultSectionSize(250); + head->setDefaultSectionSize(350); if (head->count()) { for (int i = 1; i < head->count(); i++) { - head->setSectionResizeMode(i, QHeaderView::Stretch); + head->setSectionResizeMode(i, QHeaderView::Interactive); } - head->setSectionResizeMode(head->count() -1, QHeaderView::Stretch); + head->setSectionResizeMode(head->count() - 1, QHeaderView::Stretch); } connect(ui->optionsView, &QTreeView::doubleClicked, this, &GameOptionsPage::OptionDoubleClicked); } diff --git a/launcher/ui/widgets/GameOptionWidget.h b/launcher/ui/widgets/GameOptionWidget.h new file mode 100644 index 000000000..d544e311b --- /dev/null +++ b/launcher/ui/widgets/GameOptionWidget.h @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2023 Tayou + * + * 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, version 3. + * + * 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 . + */ +#pragma once + +#include +#include +#include +#include + +#include "minecraft/gameoptions/GameOptions.h" + +class GameOptionWidget : public QWidget { + public: + GameOptionWidget(QWidget* parent) : QWidget(parent){}; + virtual void setEditorData(GameOptionItem optionItem) = 0; + virtual void saveEditorData(GameOptionItem optionItem) = 0; + + void setSize(QRect size) { + setGeometry(size); + sizeHintData = QSize(size.height(), size.width()); + } + + QSize sizeHint() const override { return sizeHintData; } + + protected: + QSize sizeHintData; +}; \ No newline at end of file diff --git a/launcher/ui/widgets/GameOptionWidgetCheckBox.cpp b/launcher/ui/widgets/GameOptionWidgetCheckBox.cpp new file mode 100644 index 000000000..7a26e4ede --- /dev/null +++ b/launcher/ui/widgets/GameOptionWidgetCheckBox.cpp @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2023 Tayou + * + * 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, version 3. + * + * 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 . + */ + +#include "GameOptionWidgetCheckBox.h" +#include "ui_GameOptionWidgetCheckBox.h" + +GameOptionWidgetCheckBox::GameOptionWidgetCheckBox(QWidget* parent, std::shared_ptr knownOption) : GameOptionWidget(parent), ui(new Ui::GameOptionWidgetCheckBox) +{ + ui->setupUi(this); + + if (knownOption == nullptr) { + ui->horizontalLayout->removeWidget(ui->resetButton); + delete ui->resetButton; + } else { + ui->resetButton->setMaximumWidth(ui->resetButton->height()); + ui->resetButton->setToolTip(QString(tr("Default Value: %1")).arg(knownOption->getDefaultBool() ? "true" : "false")); + } +} + +GameOptionWidgetCheckBox::~GameOptionWidgetCheckBox() +{ + delete ui; +} + +void GameOptionWidgetCheckBox::setEditorData(GameOptionItem optionItem) { + ui->checkBox->setText(optionItem.boolValue ? "true" : "false"); + ui->checkBox->setChecked(optionItem.boolValue); +} +void GameOptionWidgetCheckBox::saveEditorData(GameOptionItem optionItem) { + optionItem.boolValue = ui->checkBox->isChecked(); +} diff --git a/launcher/ui/widgets/GameOptionWidgetCheckBox.h b/launcher/ui/widgets/GameOptionWidgetCheckBox.h new file mode 100644 index 000000000..d20999c8c --- /dev/null +++ b/launcher/ui/widgets/GameOptionWidgetCheckBox.h @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2023 Tayou + * + * 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, version 3. + * + * 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 . + */ +#pragma once + +#include +#include + +#include "GameOptionWidget.h" + +namespace Ui { +class GameOptionWidgetCheckBox; +} + +class GameOptionWidgetCheckBox : public GameOptionWidget { + + public: + explicit GameOptionWidgetCheckBox(QWidget* parent, std::shared_ptr knownOption); + ~GameOptionWidgetCheckBox() override; + void setEditorData(GameOptionItem optionItem) override; + void saveEditorData(GameOptionItem optionItem) override; + + private: + Ui::GameOptionWidgetCheckBox* ui; +}; diff --git a/launcher/ui/widgets/GameOptionWidgetCheckBox.ui b/launcher/ui/widgets/GameOptionWidgetCheckBox.ui new file mode 100644 index 000000000..e408038e3 --- /dev/null +++ b/launcher/ui/widgets/GameOptionWidgetCheckBox.ui @@ -0,0 +1,53 @@ + + + GameOptionWidgetCheckBox + + + + 0 + 0 + 400 + 42 + + + + GameOptionWidgetComboBox + + + + + + CheckBox + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 24 + 16777215 + + + + + + + + + + + + diff --git a/launcher/ui/widgets/GameOptionWidgetComboBox.cpp b/launcher/ui/widgets/GameOptionWidgetComboBox.cpp new file mode 100644 index 000000000..be992330a --- /dev/null +++ b/launcher/ui/widgets/GameOptionWidgetComboBox.cpp @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2023 Tayou + * + * 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, version 3. + * + * 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 . + */ + +#include "GameOptionWidgetComboBox.h" +#include "ui_GameOptionWidgetComboBox.h" + +GameOptionWidgetComboBox::GameOptionWidgetComboBox(QWidget* parent, std::shared_ptr knownOption) : GameOptionWidget(parent), ui(new Ui::GameOptionWidgetComboBox) +{ + ui->setupUi(this); + + ui->resetButton->setMaximumWidth(ui->resetButton->height()); + ui->resetButton->setToolTip(QString(tr("Default Value: %1")).arg(knownOption->getDefaultString())); + + for (const auto& value : knownOption->validValues) { + ui->comboBox->addItem(value); + } +} + +GameOptionWidgetComboBox::~GameOptionWidgetComboBox() +{ + delete ui; +} +void GameOptionWidgetComboBox::setEditorData(GameOptionItem optionItem) { + ui->comboBox->setCurrentIndex(ui->comboBox->findText(optionItem.value)); +} +void GameOptionWidgetComboBox::saveEditorData(GameOptionItem optionItem) { + optionItem.value = ui->comboBox->currentText(); +} diff --git a/launcher/ui/widgets/GameOptionWidgetComboBox.h b/launcher/ui/widgets/GameOptionWidgetComboBox.h new file mode 100644 index 000000000..7331d2e49 --- /dev/null +++ b/launcher/ui/widgets/GameOptionWidgetComboBox.h @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2023 Tayou + * + * 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, version 3. + * + * 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 . + */ +#pragma once + +#include +#include + +#include "GameOptionWidget.h" + +namespace Ui { +class GameOptionWidgetComboBox; +} + +class GameOptionWidgetComboBox : public GameOptionWidget { + + public: + explicit GameOptionWidgetComboBox(QWidget* parent, std::shared_ptr knownOption); + ~GameOptionWidgetComboBox() override; + void setEditorData(GameOptionItem optionItem) override; + void saveEditorData(GameOptionItem optionItem) override; + + private: + Ui::GameOptionWidgetComboBox* ui; +}; diff --git a/launcher/ui/widgets/GameOptionWidgetComboBox.ui b/launcher/ui/widgets/GameOptionWidgetComboBox.ui new file mode 100644 index 000000000..1c7c95bc5 --- /dev/null +++ b/launcher/ui/widgets/GameOptionWidgetComboBox.ui @@ -0,0 +1,49 @@ + + + GameOptionWidgetComboBox + + + + 0 + 0 + 400 + 45 + + + + GameOptionWidgetComboBox + + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 24 + 16777215 + + + + + + + + + + + + diff --git a/launcher/ui/widgets/GameOptionWidgetKeyBind.cpp b/launcher/ui/widgets/GameOptionWidgetKeyBind.cpp new file mode 100644 index 000000000..2879b8b39 --- /dev/null +++ b/launcher/ui/widgets/GameOptionWidgetKeyBind.cpp @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2023 Tayou + * + * 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, version 3. + * + * 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 . + */ + +#include "GameOptionWidgetKeyBind.h" +#include "ui_GameOptionWidgetKeyBind.h" + +GameOptionWidgetKeyBind::GameOptionWidgetKeyBind(QWidget* parent, std::shared_ptr knownOption) : GameOptionWidget(parent), ui(new Ui::GameOptionWidgetKeyBind) +{ + ui->setupUi(this); + + if (knownOption == nullptr) { + ui->horizontalLayout->removeWidget(ui->resetButton); + delete ui->resetButton; + } else { + ui->resetButton->setMaximumWidth(ui->resetButton->height()); + ui->resetButton->setToolTip(QString(tr("Default Value: %1")).arg(knownOption->getDefaultString())); + } +} + +GameOptionWidgetKeyBind::~GameOptionWidgetKeyBind() +{ + delete ui; +} + +void GameOptionWidgetKeyBind::setEditorData(GameOptionItem optionItem) { + /*for (auto& keyBinding : *keybindingOptions) { + // this could become a std::find_if eventually, if someone wants to bother making it that. + if (keyBinding->minecraftKeyCode == contents[row].knownOption->getDefaultString()) { + return keyBinding->displayName; // + " (" + contents[row].knownOption->getDefaultString() + ")"; + } + } + + return contents[row].knownOption->getDefaultString();*/ + ui->keySequenceEdit->setKeySequence(optionItem.value); +} +void GameOptionWidgetKeyBind::saveEditorData(GameOptionItem optionItem) { + QString minecraftKeyCode; + /*for (auto& keyBinding : *keybindingOptions) { + // this could become a std::find_if eventually, if someone wants to bother making it that. + if (keyBinding->qtKeyCode.keyboardKey == ui->keySequenceEdit->keySequence()[0].key() || + keyBinding->qtKeyCode.mouseButton == ui->keySequenceEdit->keySequence()[0].key()) { + minecraftKeyCode = keyBinding->minecraftKeyCode; + } + }*/ + optionItem.value = minecraftKeyCode; +} diff --git a/launcher/ui/widgets/GameOptionWidgetKeyBind.h b/launcher/ui/widgets/GameOptionWidgetKeyBind.h new file mode 100644 index 000000000..1f932251c --- /dev/null +++ b/launcher/ui/widgets/GameOptionWidgetKeyBind.h @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2023 Tayou + * + * 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, version 3. + * + * 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 . + */ +#pragma once + +#include +#include + +#include "GameOptionWidget.h" + +namespace Ui { +class GameOptionWidgetKeyBind; +} + +class GameOptionWidgetKeyBind : public GameOptionWidget { + + public: + explicit GameOptionWidgetKeyBind(QWidget* parent, std::shared_ptr knownOption); + ~GameOptionWidgetKeyBind() override; + void setEditorData(GameOptionItem optionItem) override; + void saveEditorData(GameOptionItem optionItem) override; + + private: + Ui::GameOptionWidgetKeyBind* ui; +}; diff --git a/launcher/ui/widgets/GameOptionWidgetKeyBind.ui b/launcher/ui/widgets/GameOptionWidgetKeyBind.ui new file mode 100644 index 000000000..46ab61628 --- /dev/null +++ b/launcher/ui/widgets/GameOptionWidgetKeyBind.ui @@ -0,0 +1,56 @@ + + + GameOptionWidgetKeyBind + + + + 0 + 0 + 400 + 63 + + + + GameOptionWidgetComboBox + + + + + + + + + Bind Mouse Button + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 24 + 16777215 + + + + + + + + + + + + diff --git a/launcher/ui/widgets/GameOptionWidgetSlider.cpp b/launcher/ui/widgets/GameOptionWidgetSlider.cpp new file mode 100644 index 000000000..47d323ff5 --- /dev/null +++ b/launcher/ui/widgets/GameOptionWidgetSlider.cpp @@ -0,0 +1,91 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2023 Tayou + * + * 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, version 3. + * + * 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 . + */ + +#include "GameOptionWidgetSlider.h" +#include "Application.h" +#include "minecraft/gameoptions/GameOptions.h" +#include "ui_GameOptionWidgetSlider.h" + +#include +#include +#include + +GameOptionWidgetSlider::GameOptionWidgetSlider(QWidget* parent, std::shared_ptr knownOption) + : GameOptionWidget(parent), ui(new Ui::GameOptionWidgetSlider) +{ + ui->setupUi(this); + + ui->resetButton->setMaximumWidth(ui->resetButton->height()); + + if (knownOption->type == OptionType::Float) { + ui->resetButton->setToolTip(QString(tr("Default Value: %1")).arg(knownOption->getDefaultFloat())); + + ui->slider->setMinimum(knownOption->getFloatRange().min * 100); + ui->slider->setMaximum(knownOption->getFloatRange().max * 100); + + // QLocale((QString)APPLICATION->settings()->get("Language")) + ui->maxLabel->setText(QString("%1").arg(knownOption->getFloatRange().max)); + ui->minLabel->setText(QString("%1").arg(knownOption->getFloatRange().min)); + + connect(ui->slider, QOverload::of(&QSlider::valueChanged), this, [&](int value) { ui->spinBox->setValue(value); }); + connect(ui->spinBox, QOverload::of(&QSpinBox::valueChanged), this, [&](int value) { ui->slider->setValue(value); }); + } else { // Int slider + ui->resetButton->setToolTip(QString(tr("Default Value: %1")).arg(knownOption->getDefaultInt())); + + ui->slider->setMinimum(knownOption->getIntRange().min); + ui->slider->setMaximum(knownOption->getIntRange().max); + + ui->maxLabel->setText(QString("%1").arg(knownOption->getIntRange().max)); + ui->minLabel->setText(QString("%1").arg(knownOption->getIntRange().min)); + + connect(ui->slider, QOverload::of(&QSlider::valueChanged), this, [&](int value) { ui->spinBox->setValue(value / 100.0f); }); + connect(ui->spinBox, QOverload::of(&QSpinBox::valueChanged), this, [&](int value) { ui->slider->setValue(value * 100.0f); }); + } +} + +void GameOptionWidgetSlider::setEditorData(GameOptionItem optionItem) { + switch (optionItem.type) { + case OptionType::Int: { + ui->slider->setValue(optionItem.intValue); + break; + } + case OptionType::Float: { + ui->slider->setValue(optionItem.floatValue * 100); + break; + } + default: + break; + } +} +GameOptionWidgetSlider::~GameOptionWidgetSlider() { + destroy(ui); +} +void GameOptionWidgetSlider::saveEditorData(GameOptionItem optionItem) { + switch (optionItem.type) { + case OptionType::Int: { + optionItem.intValue = ui->slider->value(); + break; + } + case OptionType::Float: { + optionItem.floatValue = ui->slider->value() / 100.0f; + break; + } + default: + break; + } +} diff --git a/launcher/ui/widgets/GameOptionWidgetSlider.h b/launcher/ui/widgets/GameOptionWidgetSlider.h new file mode 100644 index 000000000..ce9a6fcb1 --- /dev/null +++ b/launcher/ui/widgets/GameOptionWidgetSlider.h @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2023 Tayou + * + * 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, version 3. + * + * 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 . + */ +#pragma once + +#include +#include + +#include "GameOptionWidget.h" + +namespace Ui { +class GameOptionWidgetSlider; +} + +class GameOptionWidgetSlider : public GameOptionWidget { + public: + GameOptionWidgetSlider(QWidget* parent, std::shared_ptr knownOption); + ~GameOptionWidgetSlider() override; + void setEditorData(GameOptionItem optionItem); + void saveEditorData(GameOptionItem optionItem) override; + + private: + Ui::GameOptionWidgetSlider* ui; +}; \ No newline at end of file diff --git a/launcher/ui/widgets/GameOptionWidgetSlider.ui b/launcher/ui/widgets/GameOptionWidgetSlider.ui new file mode 100644 index 000000000..52f04d54d --- /dev/null +++ b/launcher/ui/widgets/GameOptionWidgetSlider.ui @@ -0,0 +1,112 @@ + + + GameOptionWidgetSlider + + + + 0 + 0 + 400 + 60 + + + + + 0 + 60 + + + + Form + + + + QLayout::SetMinimumSize + + + 0 + + + 3 + + + 0 + + + 3 + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + + + + + + + [min] + + + + + + + + 0 + 0 + + + + + + + + [max] + + + + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 24 + 16777215 + + + + + + + + + + + + diff --git a/launcher/ui/widgets/GameOptionWidgetSpinnerFloat.cpp b/launcher/ui/widgets/GameOptionWidgetSpinnerFloat.cpp new file mode 100644 index 000000000..49fe43fc6 --- /dev/null +++ b/launcher/ui/widgets/GameOptionWidgetSpinnerFloat.cpp @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2023 Tayou + * + * 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, version 3. + * + * 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 . + */ + +#include "GameOptionWidgetSpinnerFloat.h" +#include "ui_GameOptionWidgetSpinnerFloat.h" + +GameOptionWidgetSpinnerFloat::GameOptionWidgetSpinnerFloat(QWidget* parent, std::shared_ptr knownOption) : GameOptionWidget(parent), ui(new Ui::GameOptionWidgetSpinnerFloat) +{ + ui->setupUi(this); + + if (knownOption == nullptr) { + ui->horizontalLayout->removeWidget(ui->resetButton); + delete ui->resetButton; + } else { + ui->resetButton->setMaximumWidth(ui->resetButton->height()); + ui->resetButton->setToolTip(QString(tr("Default Value: %1")).arg(knownOption->getDefaultFloat())); + } +} + +GameOptionWidgetSpinnerFloat::~GameOptionWidgetSpinnerFloat() +{ + delete ui; +} + +void GameOptionWidgetSpinnerFloat::setEditorData(GameOptionItem optionItem) { + ui->doubleSpinBox->setValue(optionItem.floatValue); +} +void GameOptionWidgetSpinnerFloat::saveEditorData(GameOptionItem optionItem) { + optionItem.floatValue = ui->doubleSpinBox->value(); +} diff --git a/launcher/ui/widgets/GameOptionWidgetSpinnerFloat.h b/launcher/ui/widgets/GameOptionWidgetSpinnerFloat.h new file mode 100644 index 000000000..845ce6739 --- /dev/null +++ b/launcher/ui/widgets/GameOptionWidgetSpinnerFloat.h @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2023 Tayou + * + * 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, version 3. + * + * 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 . + */ +#pragma once + +#include +#include + +#include "GameOptionWidget.h" + +namespace Ui { +class GameOptionWidgetSpinnerFloat; +} + +class GameOptionWidgetSpinnerFloat : public GameOptionWidget { + + public: + explicit GameOptionWidgetSpinnerFloat(QWidget* parent, std::shared_ptr knownOption); + ~GameOptionWidgetSpinnerFloat() override; + void setEditorData(GameOptionItem optionItem) override; + + private: + Ui::GameOptionWidgetSpinnerFloat* ui; + + public: + void saveEditorData(GameOptionItem optionItem) override; +}; diff --git a/launcher/ui/widgets/GameOptionWidgetSpinnerFloat.ui b/launcher/ui/widgets/GameOptionWidgetSpinnerFloat.ui new file mode 100644 index 000000000..d3235cf2f --- /dev/null +++ b/launcher/ui/widgets/GameOptionWidgetSpinnerFloat.ui @@ -0,0 +1,49 @@ + + + GameOptionWidgetSpinnerFloat + + + + 0 + 0 + 400 + 300 + + + + GameOptionWidgetComboBox + + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 24 + 16777215 + + + + + + + + + + + + diff --git a/launcher/ui/widgets/GameOptionWidgetSpinnerInt.cpp b/launcher/ui/widgets/GameOptionWidgetSpinnerInt.cpp new file mode 100644 index 000000000..e62613f95 --- /dev/null +++ b/launcher/ui/widgets/GameOptionWidgetSpinnerInt.cpp @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2023 Tayou + * + * 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, version 3. + * + * 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 . + */ + +#include "GameOptionWidgetSpinnerInt.h" +#include "ui_GameOptionWidgetSpinnerInt.h" + +GameOptionWidgetSpinnerInt::GameOptionWidgetSpinnerInt(QWidget* parent, std::shared_ptr knownOption) : GameOptionWidget(parent), ui(new Ui::GameOptionWidgetSpinnerInt) +{ + ui->setupUi(this); + + if (knownOption == nullptr) { + ui->horizontalLayout->removeWidget(ui->resetButton); + delete ui->resetButton; + } else { + ui->resetButton->setMaximumWidth(ui->resetButton->height()); + ui->resetButton->setToolTip(QString(tr("Default Value: %1")).arg(knownOption->getDefaultInt())); + } +} + +GameOptionWidgetSpinnerInt::~GameOptionWidgetSpinnerInt() +{ + delete ui; +} + +void GameOptionWidgetSpinnerInt::setEditorData(GameOptionItem optionItem) { + ui->spinBox->setValue(optionItem.intValue); +} +void GameOptionWidgetSpinnerInt::saveEditorData(GameOptionItem optionItem) { + optionItem.intValue = ui->spinBox->value(); +} diff --git a/launcher/ui/widgets/GameOptionWidgetSpinnerInt.h b/launcher/ui/widgets/GameOptionWidgetSpinnerInt.h new file mode 100644 index 000000000..707bb69dc --- /dev/null +++ b/launcher/ui/widgets/GameOptionWidgetSpinnerInt.h @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2023 Tayou + * + * 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, version 3. + * + * 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 . + */ +#pragma once + +#include +#include + +#include "GameOptionWidget.h" + +namespace Ui { +class GameOptionWidgetSpinnerInt; +} + +class GameOptionWidgetSpinnerInt : public GameOptionWidget { + + public: + explicit GameOptionWidgetSpinnerInt(QWidget* parent, std::shared_ptr knownOption); + ~GameOptionWidgetSpinnerInt() override; + void setEditorData(GameOptionItem optionItem) override; + + private: + Ui::GameOptionWidgetSpinnerInt* ui; + + public: + void saveEditorData(GameOptionItem optionItem) override; +}; diff --git a/launcher/ui/widgets/GameOptionWidgetSpinnerInt.ui b/launcher/ui/widgets/GameOptionWidgetSpinnerInt.ui new file mode 100644 index 000000000..65ceb8980 --- /dev/null +++ b/launcher/ui/widgets/GameOptionWidgetSpinnerInt.ui @@ -0,0 +1,49 @@ + + + GameOptionWidgetSpinnerInt + + + + 0 + 0 + 400 + 300 + + + + GameOptionWidgetComboBox + + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 24 + 16777215 + + + + + + + + + + + + diff --git a/launcher/ui/widgets/GameOptionWidgetText.cpp b/launcher/ui/widgets/GameOptionWidgetText.cpp new file mode 100644 index 000000000..4602d9fad --- /dev/null +++ b/launcher/ui/widgets/GameOptionWidgetText.cpp @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2023 Tayou + * + * 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, version 3. + * + * 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 . + */ + +#include "GameOptionWidgetText.h" +#include "ui_GameOptionWidgetText.h" + +GameOptionWidgetText::GameOptionWidgetText(QWidget* parent, const std::shared_ptr& knownOption) : GameOptionWidget(parent), ui(new Ui::GameOptionWidgetText) +{ + ui->setupUi(this); + + if (knownOption == nullptr) { + ui->horizontalLayout->removeWidget(ui->resetButton); + delete ui->resetButton; + } else { + ui->resetButton->setMaximumWidth(ui->resetButton->height()); + ui->resetButton->setToolTip(QString(tr("Default Value: %1")).arg(knownOption->getDefaultString())); + } +} + +GameOptionWidgetText::~GameOptionWidgetText() +{ + delete ui; +} + +void GameOptionWidgetText::setEditorData(GameOptionItem optionItem) { + ui->lineEdit->setText(optionItem.value); +} +void GameOptionWidgetText::saveEditorData(GameOptionItem optionItem) { + optionItem.value = ui->lineEdit->text(); +} diff --git a/launcher/ui/widgets/GameOptionWidgetText.h b/launcher/ui/widgets/GameOptionWidgetText.h new file mode 100644 index 000000000..0235c5d47 --- /dev/null +++ b/launcher/ui/widgets/GameOptionWidgetText.h @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2023 Tayou + * + * 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, version 3. + * + * 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 . + */ +#pragma once + +#include +#include + +#include "GameOptionWidget.h" + +namespace Ui { +class GameOptionWidgetText; +} + +class GameOptionWidgetText : public GameOptionWidget { + public: + void saveEditorData(GameOptionItem optionItem) override; + + public: + explicit GameOptionWidgetText(QWidget* parent, const std::shared_ptr& knownOption); + ~GameOptionWidgetText() override; + void setEditorData(GameOptionItem optionItem) override; + + private: + Ui::GameOptionWidgetText* ui; +}; diff --git a/launcher/ui/widgets/GameOptionWidgetText.ui b/launcher/ui/widgets/GameOptionWidgetText.ui new file mode 100644 index 000000000..b887d7414 --- /dev/null +++ b/launcher/ui/widgets/GameOptionWidgetText.ui @@ -0,0 +1,49 @@ + + + GameOptionWidgetText + + + + 0 + 0 + 400 + 55 + + + + GameOptionWidgetComboBox + + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 24 + 16777215 + + + + + + + + + + + +