Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions assets/Settings.bsml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<vertical preferred-width="130" child-control-height="false" vertical-fit="PreferredSize" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/RedBrumbler/Quest-BSML-Docs/gh-pages/schema.xsd">
<vertical preferred-width="130" anchor-pos-y="20" child-control-height="false" vertical-fit="PreferredSize" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/RedBrumbler/Quest-BSML-Docs/gh-pages/schema.xsd">
<horizontal spacing="2" child-align="MiddleLeft" child-control-height="true" bg="panel-top" pad="4" pad-bottom="1" pad-top="1" horizontal-fit="PreferredSize">
<text text="ImageCoverExpander" font-size="4" color="#FFFFFF" align="Left" bold="true" preferred-height="4" />
<text id="versionText" text="" font-size="3" color="#BBBBBB" align="Right" preferred-height="4" />
Expand All @@ -8,7 +8,11 @@
<bool-setting text="Enabled" value="enabledValue" bind-value="true" apply-on-change="true" on-change="UpdateSettings"/>
</horizontal>

<horizontal spacing="2" child-align="MiddleLeft" child-control-height="false" bg="panel-bottom" pad="2" pad-bottom="1" pad-top="1" horizontal-fit="PreferredSize">
<text text="" font-size="3" align="Center"/>
<horizontal spacing="2" child-align="MiddleLeft" child-control-height="false" bg="panel-middle" pad="2" pad-bottom="1" pad-top="1" horizontal-fit="PreferredSize">
<slider-setting text="Brightness" min="0" max="1" increment="0.1" value="brightnessValue" bind-value="true" apply-on-change="true" on-change="UpdateSettings" />
</horizontal>

<horizontal spacing="2" child-align="MiddleLeft" child-control-height="false" bg="panel-middle" pad="2" pad-bottom="1" pad-top="1" horizontal-fit="PreferredSize">
<slider-setting text="Opacity" min="0" max="1" increment="0.1" value="opacityValue" bind-value="true" apply-on-change="true" on-change="UpdateSettings" />
</horizontal>
</vertical>
2 changes: 2 additions & 0 deletions include/UI/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ DECLARE_CLASS_CODEGEN(ImageCoverExpander::UI, Settings, HMUI::ViewController){
DECLARE_INSTANCE_FIELD(TMPro::TextMeshProUGUI*, versionText);

DECLARE_BSML_PROPERTY(bool, enabledValue);
DECLARE_BSML_PROPERTY(float, brightnessValue);
DECLARE_BSML_PROPERTY(float, opacityValue);
};
2 changes: 2 additions & 0 deletions include/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

DECLARE_CONFIG(ModConfig) {
CONFIG_VALUE(Active, bool, "Enable the Mod", true);
CONFIG_VALUE(Brightness, float, "Brightness of the cover", 0.5);
CONFIG_VALUE(Opacity, float, "Opacity of the cover", 0.8);
};
7 changes: 6 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ MAKE_LATE_HOOK_MATCH(

// Get the ImageView component of the image cover and set its properties
auto* imageView = imageCoverTransform->GetComponent<ImageView*>();
imageView->set_color(Color(0.5, 0.5, 0.5, 1));
imageView->set_color(Color(
getModConfig().Brightness.GetValue(),
getModConfig().Brightness.GetValue(),
getModConfig().Brightness.GetValue(),
getModConfig().Opacity.GetValue()
));
imageView->set_preserveAspect(false);
imageView->_skew = 0.0f;

Expand Down
34 changes: 33 additions & 1 deletion src/ui/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ using namespace ImageCoverExpander;
// Global variables to track settings updates and original enabled value
bool updatedSettings = false;
bool originalEnabledValue = false;
float originalBrightnessValue = 0.0;
float originalOpacityValue = 0.0;

// Method called when the view is activated
void ImageCoverExpander::UI::Settings::DidActivate(bool firstActivation, bool addedToHeirarchy, bool screenSystemDisabling) {
Expand All @@ -31,6 +33,8 @@ void ImageCoverExpander::UI::Settings::DidActivate(bool firstActivation, bool ad
// Initialize settings state
updatedSettings = false;
originalEnabledValue = get_enabledValue();
originalBrightnessValue = get_brightnessValue();
originalOpacityValue = get_opacityValue();
versionText->text = GIT_VERSION;

// Uncomment the following lines for hot reload functionality
Expand All @@ -44,9 +48,13 @@ void ImageCoverExpander::UI::Settings::DidActivate(bool firstActivation, bool ad
void ImageCoverExpander::UI::Settings::DidDeactivate(bool removedFromHierarchy, bool screenSystemDisabling) {
if (updatedSettings) {
auto mfc = GetMainFlowCoordinator();
if(!mfc) return;

// Restart the game if the enabled value has changed
if (mfc && originalEnabledValue != get_enabledValue()) {
if (originalEnabledValue != get_enabledValue() ||
originalBrightnessValue != get_brightnessValue() ||
originalOpacityValue != get_opacityValue()
) {
mfc->_menuTransitionsHelper->RestartGame(nullptr);
}
}
Expand All @@ -63,3 +71,27 @@ void ImageCoverExpander::UI::Settings::set_enabledValue(bool value) {

updatedSettings = true;
}

// Get the current brightness value from the mod configuration
float ImageCoverExpander::UI::Settings::get_brightnessValue() {
return getModConfig().Brightness.GetValue();
}

// Set the brightness value in the mod configuration and mark settings as updated
void ImageCoverExpander::UI::Settings::set_brightnessValue(float value) {
getModConfig().Brightness.SetValue(value);

updatedSettings = true;
}

// Get the current opacity value from the mod configuration
float ImageCoverExpander::UI::Settings::get_opacityValue() {
return getModConfig().Opacity.GetValue();
}

// Set the opacity value in the mod configuration and mark settings as updated
void ImageCoverExpander::UI::Settings::set_opacityValue(float value) {
getModConfig().Opacity.SetValue(value);

updatedSettings = true;
}