From f46f6a4d178556636459943f895aa493322e733b Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Wed, 21 Aug 2019 03:38:25 +1000 Subject: [PATCH] launcher: start work on plugin config --- .../source/plugins/Launcher/ConfigOption.h | 170 +++++++++++++++--- .../source/plugins/Launcher/PluginConfig.h | 158 ++++++++++++++++ source-code/source/plugins/Launcher/ui.h | 11 +- 3 files changed, 314 insertions(+), 25 deletions(-) create mode 100644 source-code/source/plugins/Launcher/PluginConfig.h diff --git a/source-code/source/plugins/Launcher/ConfigOption.h b/source-code/source/plugins/Launcher/ConfigOption.h index d1d0304..601b8c7 100644 --- a/source-code/source/plugins/Launcher/ConfigOption.h +++ b/source-code/source/plugins/Launcher/ConfigOption.h @@ -178,7 +178,7 @@ public: }; -static ref class ChangeHandler +ref class ChangeHandler { public: bool* changebool; @@ -220,6 +220,26 @@ public: }; +class OptionMetaGroupStart : public ConfigOptionBase +{ +public: + int _height; + + OptionMetaGroupStart(LPCWSTR friendlyName, int height) + { + _friendlyName = friendlyName; + _height = height; + } +}; +class OptionMetaGroupEnd : public ConfigOptionBase +{ +public: + OptionMetaGroupEnd() + { + } +}; + + class BooleanOption : public ConfigOptionBase { public: @@ -252,9 +272,14 @@ public: cb->BackColor = System::Drawing::Color::FromArgb(0, 0, 0, 0); Form^ RootForm = panel->FindForm(); - Drawing::SizeF CurrentScaleSize = RootForm->CurrentAutoScaleDimensions; - float ScaleWidth = CurrentScaleSize.Width / BaseScaleSize; - float ScaleHeight = CurrentScaleSize.Height / BaseScaleSize; + float ScaleWidth = 1.0f; + float ScaleHeight = 1.0f; + if (RootForm) + { + Drawing::SizeF CurrentScaleSize = RootForm->CurrentAutoScaleDimensions; + ScaleWidth = CurrentScaleSize.Width / BaseScaleSize; + ScaleHeight = CurrentScaleSize.Height / BaseScaleSize; + } cb->Scale(ScaleWidth, ScaleHeight); tooltip->SetToolTip(cb, gcnew String(_description)); @@ -325,9 +350,14 @@ public: numberbox->AutoSize = true; Form^ RootForm = panel->FindForm(); - Drawing::SizeF CurrentScaleSize = RootForm->CurrentAutoScaleDimensions; - float ScaleWidth = CurrentScaleSize.Width / BaseScaleSize; - float ScaleHeight = CurrentScaleSize.Height / BaseScaleSize; + float ScaleWidth = 1.0f; + float ScaleHeight = 1.0f; + if (RootForm) + { + Drawing::SizeF CurrentScaleSize = RootForm->CurrentAutoScaleDimensions; + ScaleWidth = CurrentScaleSize.Width / BaseScaleSize; + ScaleHeight = CurrentScaleSize.Height / BaseScaleSize; + } label->Scale(ScaleWidth, ScaleHeight); numberbox->Scale(ScaleWidth, ScaleHeight); @@ -404,9 +434,14 @@ public: textbox->AutoSize = true; Form^ RootForm = panel->FindForm(); - Drawing::SizeF CurrentScaleSize = RootForm->CurrentAutoScaleDimensions; - float ScaleWidth = CurrentScaleSize.Width / BaseScaleSize; - float ScaleHeight = CurrentScaleSize.Height / BaseScaleSize; + float ScaleWidth = 1.0f; + float ScaleHeight = 1.0f; + if (RootForm) + { + Drawing::SizeF CurrentScaleSize = RootForm->CurrentAutoScaleDimensions; + ScaleWidth = CurrentScaleSize.Width / BaseScaleSize; + ScaleHeight = CurrentScaleSize.Height / BaseScaleSize; + } label->Scale(ScaleWidth, ScaleHeight); textbox->Scale(ScaleWidth, ScaleHeight); @@ -498,9 +533,14 @@ public: combobox->DropDownStyle = ComboBoxStyle::DropDownList; Form^ RootForm = panel->FindForm(); - Drawing::SizeF CurrentScaleSize = RootForm->CurrentAutoScaleDimensions; - float ScaleWidth = CurrentScaleSize.Width / BaseScaleSize; - float ScaleHeight = CurrentScaleSize.Height / BaseScaleSize; + float ScaleWidth = 1.0f; + float ScaleHeight = 1.0f; + if (RootForm) + { + Drawing::SizeF CurrentScaleSize = RootForm->CurrentAutoScaleDimensions; + ScaleWidth = CurrentScaleSize.Width / BaseScaleSize; + ScaleHeight = CurrentScaleSize.Height / BaseScaleSize; + } label->Scale(ScaleWidth, ScaleHeight); combobox->Scale(ScaleWidth, ScaleHeight); @@ -585,9 +625,14 @@ public: combobox->DropDownStyle = ComboBoxStyle::DropDown; Form^ RootForm = panel->FindForm(); - Drawing::SizeF CurrentScaleSize = RootForm->CurrentAutoScaleDimensions; - float ScaleWidth = CurrentScaleSize.Width / BaseScaleSize; - float ScaleHeight = CurrentScaleSize.Height / BaseScaleSize; + float ScaleWidth = 1.0f; + float ScaleHeight = 1.0f; + if (RootForm) + { + Drawing::SizeF CurrentScaleSize = RootForm->CurrentAutoScaleDimensions; + ScaleWidth = CurrentScaleSize.Width / BaseScaleSize; + ScaleHeight = CurrentScaleSize.Height / BaseScaleSize; + } label->Scale(ScaleWidth, ScaleHeight); combobox->Scale(ScaleWidth, ScaleHeight); @@ -685,9 +730,14 @@ public: combobox->DropDownStyle = ComboBoxStyle::DropDown; Form^ RootForm = panel->FindForm(); - Drawing::SizeF CurrentScaleSize = RootForm->CurrentAutoScaleDimensions; - float ScaleWidth = CurrentScaleSize.Width / BaseScaleSize; - float ScaleHeight = CurrentScaleSize.Height / BaseScaleSize; + float ScaleWidth = 1.0f; + float ScaleHeight = 1.0f; + if (RootForm) + { + Drawing::SizeF CurrentScaleSize = RootForm->CurrentAutoScaleDimensions; + ScaleWidth = CurrentScaleSize.Width / BaseScaleSize; + ScaleHeight = CurrentScaleSize.Height / BaseScaleSize; + } label->Scale(ScaleWidth, ScaleHeight); combobox->Scale(ScaleWidth, ScaleHeight); @@ -780,9 +830,14 @@ public: combobox->DropDownStyle = ComboBoxStyle::DropDown; Form^ RootForm = panel->FindForm(); - Drawing::SizeF CurrentScaleSize = RootForm->CurrentAutoScaleDimensions; - float ScaleWidth = CurrentScaleSize.Width / BaseScaleSize; - float ScaleHeight = CurrentScaleSize.Height / BaseScaleSize; + float ScaleWidth = 1.0f; + float ScaleHeight = 1.0f; + if (RootForm) + { + Drawing::SizeF CurrentScaleSize = RootForm->CurrentAutoScaleDimensions; + ScaleWidth = CurrentScaleSize.Width / BaseScaleSize; + ScaleHeight = CurrentScaleSize.Height / BaseScaleSize; + } label->Scale(ScaleWidth, ScaleHeight); combobox->Scale(ScaleWidth, ScaleHeight); @@ -823,4 +878,73 @@ public: WritePrivateProfileStringW(_iniSectionName, _iniVarName2, tempWStr.c_str(), _iniFilePath); } -}; \ No newline at end of file +}; + + +Panel^ MakePanel(int width, int height, std::vector cfg, ToolTip^ tooltip) +{ + Panel^ outpanel = gcnew Panel(); + outpanel->Width = width; + outpanel->Height = height; + outpanel->AutoScroll = true; + + Form^ RootForm = outpanel->FindForm(); + float ScaleWidth = 1.0f; + float ScaleHeight = 1.0f; + if (RootForm) + { + Drawing::SizeF CurrentScaleSize = RootForm->CurrentAutoScaleDimensions; + ScaleWidth = CurrentScaleSize.Width / BaseScaleSize; + ScaleHeight = CurrentScaleSize.Height / BaseScaleSize; + } + + int curX = 12; + int curY = 3; + + for (int i = 0; i < cfg.size(); i++) + { + if (typeid(cfg[i]).hash_code() == typeid(OptionMetaGroupEnd).hash_code()) + continue; + + if (typeid(cfg[i]).hash_code() == typeid(OptionMetaGroupStart).hash_code()) + { + OptionMetaGroupStart* groupData = (OptionMetaGroupStart*)(cfg[i]); + GroupBox^ groupbox = gcnew GroupBox(); + groupbox->Width = width - (ScaleWidth * 8); + groupbox->Height = ScaleHeight * groupData->_height; + groupbox->Left = ScaleWidth * 4; + groupbox->Top = ScaleHeight * curY; + groupbox->Text = gcnew String(groupData->_friendlyName); + + // find the end of this group by simple iteration keeping track of indent level + int level = 1; + int endidx; + for (endidx = i + 1; endidx < cfg.size(); endidx++) + { + if (typeid(&cfg[endidx]).hash_code() == typeid(OptionMetaGroupStart).hash_code()) + level++; + if (typeid(&cfg[endidx]).hash_code() == typeid(OptionMetaGroupEnd).hash_code()) + level--; + + if (level == 0) + break; + } + + Panel^ groupPanel = MakePanel(groupbox->Width - (ScaleWidth * 8), groupbox->Height - (ScaleHeight * 10), std::vector(&(cfg[i + 1]), &(cfg[endidx])), tooltip); + groupPanel->Left = ScaleWidth * 12; + groupPanel->Top = ScaleHeight * (curY + 8); + + groupbox->Controls->Add(groupPanel); + outpanel->Controls->Add(groupbox); + + i = endidx; + curY += groupData->_height; + } + else + { + curY += cfg[i]->AddToPanel(outpanel, curX, curY, tooltip); + } + } + + return outpanel; +} \ No newline at end of file diff --git a/source-code/source/plugins/Launcher/PluginConfig.h b/source-code/source/plugins/Launcher/PluginConfig.h new file mode 100644 index 0000000..76badf0 --- /dev/null +++ b/source-code/source/plugins/Launcher/PluginConfig.h @@ -0,0 +1,158 @@ +#pragma once +#include "ConfigOption.h" +#include "framework.h" + +namespace PluginConfig +{ + enum ConfigType { + CONFIG_BOOLEAN, + CONFIG_NUMERIC, + CONFIG_STRING, + CONFIG_DROPDOWN_INDEX, + CONFIG_DROPDOWN_TEXT, + CONFIG_DROPDOWN_NUMBER, + CONFIG_RESOLUTION, + CONFIG_GROUP_START, + CONFIG_GROUP_END + }; + + struct PluginConfigBooleanData { + LPCWSTR iniVarName; + LPCWSTR iniSectionName; + LPCWSTR iniFilePath; + LPCWSTR friendlyName; + LPCWSTR description; + bool defaultVal; + bool saveAsString; + }; + + struct PluginConfigNumericData { + LPCWSTR iniVarName; + LPCWSTR iniSectionName; + LPCWSTR iniFilePath; + LPCWSTR friendlyName; + LPCWSTR description; + int defaultVal; + int minVal; + int maxVal; + }; + + struct PluginConfigStringData { + LPCWSTR iniVarName; + LPCWSTR iniSectionName; + LPCWSTR iniFilePath; + LPCWSTR friendlyName; + LPCWSTR description; + LPCWSTR defaultVal; + bool useUtf8; + }; + + struct PluginConfigDropdownIndexData { + LPCWSTR iniVarName; + LPCWSTR iniSectionName; + LPCWSTR iniFilePath; + LPCWSTR friendlyName; + LPCWSTR description; + int defaultVal; + std::vector valueStrings; + }; + + struct PluginConfigDropdownTextData { + LPCWSTR iniVarName; + LPCWSTR iniSectionName; + LPCWSTR iniFilePath; + LPCWSTR friendlyName; + LPCWSTR description; + LPCWSTR defaultVal; + std::vector valueStrings; + bool useUtf8; + }; + + struct PluginConfigDropdownNumberData { + LPCWSTR iniVarName; + LPCWSTR iniSectionName; + LPCWSTR iniFilePath; + LPCWSTR friendlyName; + LPCWSTR description; + int defaultVal; + std::vector valueInts; + }; + + struct PluginConfigResolutionData { + LPCWSTR iniVarName; + LPCWSTR iniVarName2; + LPCWSTR iniSectionName; + LPCWSTR iniFilePath; + LPCWSTR friendlyName; + LPCWSTR description; + resolution defaultVal; + std::vector valueResolutions; + }; + + struct PluginConfigGroupData + { + LPCWSTR name; + int height; + }; + + struct PluginConfigOption + { + ConfigType cfgType; + void* data; + }; + + ConfigOptionBase* GetConfigOption(PluginConfigOption cfg) + { + PluginConfigBooleanData* boolData = (PluginConfigBooleanData*)(cfg.data); + PluginConfigNumericData* numericData = (PluginConfigNumericData*)(cfg.data); + PluginConfigStringData* stringData = (PluginConfigStringData*)(cfg.data); + PluginConfigDropdownIndexData* ddIdxData = (PluginConfigDropdownIndexData*)(cfg.data); + PluginConfigDropdownTextData* ddTextData = (PluginConfigDropdownTextData*)(cfg.data); + PluginConfigDropdownNumberData* ddNumberData = (PluginConfigDropdownNumberData*)(cfg.data); + PluginConfigResolutionData* resData = (PluginConfigResolutionData*)(cfg.data); + PluginConfigGroupData* groupData = (PluginConfigGroupData*)(cfg.data); + + switch (cfg.cfgType) + { + case CONFIG_BOOLEAN: + return new BooleanOption(boolData->iniVarName, boolData->iniSectionName, boolData->iniFilePath, boolData->friendlyName, boolData->description, boolData->defaultVal, boolData->saveAsString); + case CONFIG_NUMERIC: + return new NumericOption(numericData->iniVarName, numericData->iniSectionName, numericData->iniFilePath, numericData->friendlyName, numericData->description, numericData->defaultVal, numericData->minVal, numericData->maxVal); + case CONFIG_STRING: + return new StringOption(stringData->iniVarName, stringData->iniSectionName, stringData->iniFilePath, stringData->friendlyName, stringData->description, stringData->defaultVal, stringData->useUtf8); + case CONFIG_DROPDOWN_INDEX: + return new DropdownOption(ddIdxData->iniVarName, ddIdxData->iniSectionName, ddIdxData->iniFilePath, ddIdxData->friendlyName, ddIdxData->description, ddIdxData->defaultVal, ddIdxData->valueStrings); + case CONFIG_DROPDOWN_TEXT: + return new EditableDropdownOption(ddTextData->iniVarName, ddTextData->iniSectionName, ddTextData->iniFilePath, ddTextData->friendlyName, ddTextData->description, ddTextData->defaultVal, ddTextData->valueStrings, ddTextData->useUtf8); + case CONFIG_DROPDOWN_NUMBER: + return new EditableDropdownNumberOption(ddNumberData->iniVarName, ddNumberData->iniSectionName, ddNumberData->iniFilePath, ddNumberData->friendlyName, ddNumberData->description, ddNumberData->defaultVal, ddNumberData->valueInts); + case CONFIG_RESOLUTION: + return new ResolutionOption(resData->iniVarName, resData->iniVarName2, resData->iniSectionName, resData->iniFilePath, resData->friendlyName, resData->description, resData->defaultVal, resData->valueResolutions); + case CONFIG_GROUP_START: + return new OptionMetaGroupStart(groupData->name, groupData->height); + case CONFIG_GROUP_END: + return new OptionMetaGroupEnd(); + default: + return new ConfigOptionBase(); + } + } + + std::vector GetConfigOptionVec(std::vector in) + { + std::vector outvec; + for (PluginConfigOption &opt : in) + { + outvec.push_back(GetConfigOption(opt)); + } + return outvec; + } + + std::vector testcfg = + { + PluginConfigOption{ CONFIG_GROUP_START, new PluginConfigGroupData{L"Screen Resolution", 400 } }, + PluginConfigOption{ CONFIG_DROPDOWN_INDEX, new PluginConfigDropdownIndexData{ L"display", RESOLUTION_SECTION, CONFIG_FILE, L"Display:", L"Sets the window/screen mode.", 0, std::vector({ L"Windowed", L"Borderless", L"Fullscreen" }) } }, + PluginConfigOption{ CONFIG_RESOLUTION, new PluginConfigResolutionData{ L"width", L"height", RESOLUTION_SECTION, CONFIG_FILE, L"Resolution:", L"Sets the display resolution.", resolution(1280, 720), getScreenResolutionsVec(screenModes) } } + }; + + std::vector testcfgconfigopts = GetConfigOptionVec(testcfg); +}; \ No newline at end of file diff --git a/source-code/source/plugins/Launcher/ui.h b/source-code/source/plugins/Launcher/ui.h index 42b2d81..955dee7 100644 --- a/source-code/source/plugins/Launcher/ui.h +++ b/source-code/source/plugins/Launcher/ui.h @@ -6,6 +6,7 @@ #include #include #include "SkinnedMessageBox.h" +#include "PluginConfig.h" namespace Launcher { @@ -90,6 +91,7 @@ namespace Launcher { this->panel_Patches->PerformLayout(); + this->panel_Playerdata->SuspendLayout(); // populate playerdata options from array in framework @@ -112,13 +114,18 @@ namespace Launcher { for (ConfigOptionBase* component : componentsArray) { component->hasChanged = ConfigHasChanged; - componentsY += component->AddToPanel(panel_Components, 12, componentsY, toolTip1); + //componentsY += component->AddToPanel(panel_Components, 12, componentsY, toolTip1); } this->panel_Components->ResumeLayout(false); this->panel_Components->PerformLayout(); + using namespace PluginConfig; + //tabPage_Components->Controls->Add(MakePanel(256, 800, testcfg, toolTip1)); + tabPage_Components->Controls->Add(MakePanel(256, 100, std::vector(&componentsArray[0], &componentsArray[12]), toolTip1)); + + // trick Optimus into switching to the NVIDIA GPU if (cuInit != NULL) cuInit(0); @@ -402,7 +409,7 @@ namespace Launcher { // this->tabPage_Components->BackColor = System::Drawing::Color::FromArgb(static_cast(static_cast(64)), static_cast(static_cast(64)), static_cast(static_cast(64))); - this->tabPage_Components->Controls->Add(this->panel_Components); + //this->tabPage_Components->Controls->Add(this->panel_Components); this->tabPage_Components->Location = System::Drawing::Point(4, 32); this->tabPage_Components->Margin = System::Windows::Forms::Padding(4); this->tabPage_Components->Name = L"tabPage_Components";