Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ConVars for ModSelector sliders #332

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
21 changes: 21 additions & 0 deletions src/App/Osu/Osu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ ConVar osu_notification_color_b("osu_notification_color_b", 255);

ConVar osu_ui_scale("osu_ui_scale", 1.0f);
ConVar osu_ui_scale_to_dpi("osu_ui_scale_to_dpi", true);
ConVar osu_ui_modselect_slider_delta("osu_ui_modselect_slider_delta", 0.1f);
ConVar osu_ui_modselect_slider_snap_alt("osu_ui_modselect_slider_snap_alt", 10.0f);
ConVar osu_ui_modselect_slider_snap("osu_ui_modselect_slider_snap", 100.0f);
ConVar osu_letterboxing("osu_letterboxing", true);
ConVar osu_letterboxing_offset_x("osu_letterboxing_offset_x", 0.0f);
ConVar osu_letterboxing_offset_y("osu_letterboxing_offset_y", 0.0f);
Expand Down Expand Up @@ -296,6 +299,9 @@ Osu::Osu(Osu2 *osu2, int instanceID)
osu_resolution.setCallback( fastdelegate::MakeDelegate(this, &Osu::onInternalResolutionChanged) );
osu_ui_scale.setCallback( fastdelegate::MakeDelegate(this, &Osu::onUIScaleChange) );
osu_ui_scale_to_dpi.setCallback( fastdelegate::MakeDelegate(this, &Osu::onUIScaleToDPIChange) );
osu_ui_modselect_slider_delta.setCallback( fastdelegate::MakeDelegate(this, &Osu::onUISliderDeltaChange) );
osu_ui_modselect_slider_snap.setCallback( fastdelegate::MakeDelegate(this, &Osu::onUISliderSnapChange) );
osu_ui_modselect_slider_snap_alt.setCallback( fastdelegate::MakeDelegate(this, &Osu::onUISliderSnapAltChange) );
osu_letterboxing.setCallback( fastdelegate::MakeDelegate(this, &Osu::onLetterboxingChange) );
osu_letterboxing_offset_x.setCallback( fastdelegate::MakeDelegate(this, &Osu::onLetterboxingOffsetChange) );
osu_letterboxing_offset_y.setCallback( fastdelegate::MakeDelegate(this, &Osu::onLetterboxingOffsetChange) );
Expand Down Expand Up @@ -2332,6 +2338,21 @@ void Osu::onUIScaleToDPIChange(UString oldValue, UString newValue)
}
}

void Osu::onUISliderDeltaChange(UString oldValue, UString newValue)
{
m_modSelector->updateKeyDelta(newValue.toFloat());
}

void Osu::onUISliderSnapChange(UString oldValue, UString newValue)
{
m_modSelector->updateSliderSnap(newValue.toFloat(), true);
}

void Osu::onUISliderSnapAltChange(UString oldValue, UString newValue)
{
m_modSelector->updateSliderSnap(newValue.toFloat(), true);
}

void Osu::onLetterboxingChange(UString oldValue, UString newValue)
{
if (osu_resolution_enabled.getBool())
Expand Down
3 changes: 3 additions & 0 deletions src/App/Osu/Osu.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ class Osu : public App, public MouseListener

void onUIScaleChange(UString oldValue, UString newValue);
void onUIScaleToDPIChange(UString oldValue, UString newValue);
void onUISliderDeltaChange(UString oldValue, UString newValue);
void onUISliderSnapChange(UString oldValue, UString newValue);
void onUISliderSnapAltChange(UString oldValue, UString newValue);
void onLetterboxingChange(UString oldValue, UString newValue);

void onConfineCursorWindowedChange(UString oldValue, UString newValue);
Expand Down
30 changes: 27 additions & 3 deletions src/App/Osu/OsuModSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include "OsuUICheckbox.h"
#include "OsuUIModSelectorModButton.h"


#define NAMEOF(name) #name

class OsuModSelectorOverrideSliderDescButton : public CBaseUIButton
{
Expand Down Expand Up @@ -151,6 +151,8 @@ class OsuModSelectorOverrideSliderLockButton : public CBaseUICheckbox

OsuModSelector::OsuModSelector(Osu *osu) : OsuScreen(osu)
{
//m_sliderSnapAmount = 100.0f;
//m_sliderSnapAmountAlt = 10.0f;
m_fAnimation = 0.0f;
m_fExperimentalAnimation = 0.0f;
m_bScheduledHide = false;
Expand Down Expand Up @@ -991,6 +993,28 @@ void OsuModSelector::updateModConVar()
updateOverrideSliderLabels();
}

void OsuModSelector::updateKeyDelta(float delta)
{
if (m_modButtons.size() < 1 || m_overrideSliders.size() < 1) return;

for (int i = 0; i < m_overrideSliders.size(); i++)
{
m_overrideSliders[i].slider->setKeyDelta(delta);
}
}

void OsuModSelector::updateSliderSnap(float amount, bool forAlt)
{
debugLog("OsuModSelector::updateSliderSnap(float, bool)");

if (forAlt)
m_sliderSnapAmountAlt = amount;
else
m_sliderSnapAmount = amount;

debugLog("Updated " + (forAlt ? NAMEOF(m_sliderSnapAmount) : NAMEOF(m_sliderSnapAmountAlt)) + " to " + std::to_string(amount));
}

OsuUIModSelectorModButton *OsuModSelector::setModButtonOnGrid(int x, int y, int state, bool initialState, UString modName, UString tooltipText, std::function<OsuSkinImage*()> getImageFunc)
{
OsuUIModSelectorModButton *modButton = getModButtonOnGrid(x, y);
Expand Down Expand Up @@ -1157,9 +1181,9 @@ void OsuModSelector::onOverrideSliderChange(CBaseUISlider *slider)

// alt key allows rounding to only 1 decimal digit
if (!engine->getKeyboard()->isAltDown())
sliderValue = std::round(sliderValue * 10.0f) / 10.0f;
sliderValue = std::round(sliderValue * m_sliderSnapAmountAlt) / m_sliderSnapAmountAlt;
else
sliderValue = std::round(sliderValue * 100.0f) / 100.0f;
sliderValue = std::round(sliderValue * m_sliderSnapAmount) / m_sliderSnapAmount;

if (sliderValue < 0.0f)
{
Expand Down
5 changes: 5 additions & 0 deletions src/App/Osu/OsuModSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class OsuModSelector : public OsuScreen

void updateModConVar();

void updateKeyDelta(float delta);
void updateSliderSnap(float amount, bool forAlt);

private:
struct OVERRIDE_SLIDER
{
Expand Down Expand Up @@ -109,6 +112,8 @@ class OsuModSelector : public OsuScreen

void close();

float m_sliderSnapAmount;
float m_sliderSnapAmountAlt;
float m_fAnimation;
float m_fExperimentalAnimation;
bool m_bScheduledHide;
Expand Down