From 08ebbb4a60fa746576eaf07ee5b94cf45e451886 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 20 Dec 2015 12:58:24 -0800 Subject: [PATCH] Customize labels for zero in config sliders. --- UI/GameSettingsScreen.cpp | 25 +++++++++++++++---------- ext/native/ui/ui_screen.cpp | 16 ++++++++++++++-- ext/native/ui/ui_screen.h | 18 ++++++++++++++++++ 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index fb3d5793df..4ef33c7b29 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -152,7 +152,9 @@ void GameSettingsScreen::CreateViews() { frameSkipAuto_->OnClick.Handle(this, &GameSettingsScreen::OnAutoFrameskip); graphicsSettings->Add(new CheckBox(&cap60FPS_, gr->T("Force max 60 FPS (helps GoW)"))); - graphicsSettings->Add(new PopupSliderChoice(&iAlternateSpeedPercent_, 0, 600, gr->T("Alternative Speed", "Alternative Speed (in %, 0 = unlimited)"), 5, screenManager(), "%, 0=unlimited")); + PopupSliderChoice *altSpeed = graphicsSettings->Add(new PopupSliderChoice(&iAlternateSpeedPercent_, 0, 600, gr->T("Alternative Speed", "Alternative speed"), 5, screenManager(), gr->T("%, 0=unlimited"))); + altSpeed->SetFormat("%i%%"); + altSpeed->SetZeroLabel(gr->T("Unlimited")); graphicsSettings->Add(new ItemHeader(gr->T("Features"))); I18NCategory *ps = GetI18NCategory("PostShaders"); @@ -289,11 +291,11 @@ void GameSettingsScreen::CreateViews() { graphicsSettings->Add(new ItemHeader(gr->T("Cardboard Settings", "Cardboard Settings"))); CheckBox *cardboardMode = graphicsSettings->Add(new CheckBox(&g_Config.bEnableCardboard, gr->T("Enable Cardboard", "Enable Cardboard"))); cardboardMode->SetDisabledPtr(&g_Config.bSoftwareRendering); - PopupSliderChoice * cardboardScreenSize = graphicsSettings->Add(new PopupSliderChoice(&g_Config.iCardboardScreenSize, 30, 100, gr->T("Cardboard Screen Size", "Screen Size (in % of the viewport)"), 1, screenManager(), "% of viewport")); + PopupSliderChoice * cardboardScreenSize = graphicsSettings->Add(new PopupSliderChoice(&g_Config.iCardboardScreenSize, 30, 100, gr->T("Cardboard Screen Size", "Screen Size (in % of the viewport)"), 1, screenManager(), gr->T("% of viewport"))); cardboardScreenSize->SetDisabledPtr(&g_Config.bSoftwareRendering); - PopupSliderChoice *cardboardXShift = graphicsSettings->Add(new PopupSliderChoice(&g_Config.iCardboardXShift, -100, 100, gr->T("Cardboard Screen X Shift", "X Shift (in % of the void)"), 1, screenManager(), "% of the void")); + PopupSliderChoice *cardboardXShift = graphicsSettings->Add(new PopupSliderChoice(&g_Config.iCardboardXShift, -100, 100, gr->T("Cardboard Screen X Shift", "X Shift (in % of the void)"), 1, screenManager(), gr->T("% of the void"))); cardboardXShift->SetDisabledPtr(&g_Config.bSoftwareRendering); - PopupSliderChoice *cardboardYShift = graphicsSettings->Add(new PopupSliderChoice(&g_Config.iCardboardYShift, -100, 100, gr->T("Cardboard Screen Y Shift", "Y Shift (in % of the void)"), 1, screenManager(), "% of the void")); + PopupSliderChoice *cardboardYShift = graphicsSettings->Add(new PopupSliderChoice(&g_Config.iCardboardYShift, -100, 100, gr->T("Cardboard Screen Y Shift", "Y Shift (in % of the void)"), 1, screenManager(), gr->T("% of the void"))); cardboardYShift->SetDisabledPtr(&g_Config.bSoftwareRendering); #endif @@ -427,10 +429,13 @@ void GameSettingsScreen::CreateViews() { CheckBox *disableDiags = controlsSettings->Add(new CheckBox(&g_Config.bDisableDpadDiagonals, co->T("Disable D-Pad diagonals (4-way touch)"))); disableDiags->SetEnabledPtr(&g_Config.bShowTouchControls); - View *opacity = controlsSettings->Add(new PopupSliderChoice(&g_Config.iTouchButtonOpacity, 0, 100, co->T("Button Opacity"), screenManager(), "%")); + PopupSliderChoice *opacity = controlsSettings->Add(new PopupSliderChoice(&g_Config.iTouchButtonOpacity, 0, 100, co->T("Button Opacity"), screenManager(), "%")); opacity->SetEnabledPtr(&g_Config.bShowTouchControls); - PopupSliderChoice *autoHide = controlsSettings->Add(new PopupSliderChoice(&g_Config.iTouchButtonHideSeconds, 0, 300, co->T("Auto-hide buttons after (0 = off)"), screenManager(), "seconds")); + opacity->SetFormat("%i%%"); + PopupSliderChoice *autoHide = controlsSettings->Add(new PopupSliderChoice(&g_Config.iTouchButtonHideSeconds, 0, 300, co->T("Auto-hide buttons after seconds"), screenManager(), co->T("seconds, 0 = off"))); autoHide->SetEnabledPtr(&g_Config.bShowTouchControls); + autoHide->SetFormat("%is"); + autoHide->SetZeroLabel(co->T("Off")); static const char *touchControlStyles[] = {"Classic", "Thin borders"}; View *style = controlsSettings->Add(new PopupMultiChoice(&g_Config.iTouchButtonStyle, co->T("Button style"), touchControlStyles, 0, ARRAY_SIZE(touchControlStyles), co->GetName(), screenManager())); style->SetEnabledPtr(&g_Config.bShowTouchControls); @@ -516,10 +521,10 @@ void GameSettingsScreen::CreateViews() { View *ioTimingMethod = systemSettings->Add(new PopupMultiChoice(&g_Config.iIOTimingMethod, sy->T("IO timing method"), ioTimingMethods, 0, ARRAY_SIZE(ioTimingMethods), sy->GetName(), screenManager())); ioTimingMethod->SetEnabledPtr(&g_Config.bSeparateIOThread); systemSettings->Add(new CheckBox(&g_Config.bForceLagSync, sy->T("Force real clock sync (slower, less lag)"))); - systemSettings->Add(new PopupSliderChoice(&g_Config.iLockedCPUSpeed, 0, 1000, sy->T("Change CPU Clock", "Change CPU Clock (0 = default) (unstable)"), screenManager(), "MHz, 0=default")); -#ifndef MOBILE_DEVICE - systemSettings->Add(new PopupSliderChoice(&g_Config.iRewindFlipFrequency, 0, 1800, sy->T("Rewind Snapshot Frequency", "Rewind Snapshot Frequency (0 = off, mem hog)"), screenManager(), "frames, 0=off")); -#endif + PopupSliderChoice *lockedMhz = systemSettings->Add(new PopupSliderChoice(&g_Config.iLockedCPUSpeed, 0, 1000, sy->T("Change CPU Clock", "Change CPU Clock (unstable)"), screenManager(), sy->T("MHz, 0=default"))); + lockedMhz->SetZeroLabel(sy->T("Auto")); + PopupSliderChoice *rewindFreq = systemSettings->Add(new PopupSliderChoice(&g_Config.iRewindFlipFrequency, 0, 1800, sy->T("Rewind Snapshot Frequency", "Rewind Snapshot Frequency (mem hog)"), screenManager(), sy->T("frames, 0=off"))); + rewindFreq->SetZeroLabel(sy->T("Off")); systemSettings->Add(new ItemHeader(sy->T("General"))); diff --git a/ext/native/ui/ui_screen.cpp b/ext/native/ui/ui_screen.cpp index a29a735edc..167ee24203 100644 --- a/ext/native/ui/ui_screen.cpp +++ b/ext/native/ui/ui_screen.cpp @@ -343,21 +343,25 @@ void PopupMultiChoice::Draw(UIContext &dc) { PopupSliderChoice::PopupSliderChoice(int *value, int minValue, int maxValue, const std::string &text, ScreenManager *screenManager, const std::string &units, LayoutParams *layoutParams) : Choice(text, "", false, layoutParams), value_(value), minValue_(minValue), maxValue_(maxValue), step_(1), screenManager_(screenManager), units_(units) { + fmt_ = "%i"; OnClick.Handle(this, &PopupSliderChoice::HandleClick); } PopupSliderChoice::PopupSliderChoice(int *value, int minValue, int maxValue, const std::string &text, int step, ScreenManager *screenManager, const std::string &units, LayoutParams *layoutParams) : Choice(text, "", false, layoutParams), value_(value), minValue_(minValue), maxValue_(maxValue), step_(step), screenManager_(screenManager), units_(units) { + fmt_ = "%i"; OnClick.Handle(this, &PopupSliderChoice::HandleClick); } PopupSliderChoiceFloat::PopupSliderChoiceFloat(float *value, float minValue, float maxValue, const std::string &text, ScreenManager *screenManager, const std::string &units, LayoutParams *layoutParams) : Choice(text, "", false, layoutParams), value_(value), minValue_(minValue), maxValue_(maxValue), step_(1.0f), screenManager_(screenManager), units_(units) { + fmt_ = "%2.2f"; OnClick.Handle(this, &PopupSliderChoiceFloat::HandleClick); } PopupSliderChoiceFloat::PopupSliderChoiceFloat(float *value, float minValue, float maxValue, const std::string &text, float step, ScreenManager *screenManager, const std::string &units, LayoutParams *layoutParams) : Choice(text, "", false, layoutParams), value_(value), minValue_(minValue), maxValue_(maxValue), step_(step), screenManager_(screenManager), units_(units) { + fmt_ = "%2.2f"; OnClick.Handle(this, &PopupSliderChoiceFloat::HandleClick); } @@ -387,7 +391,11 @@ void PopupSliderChoice::Draw(UIContext &dc) { } Choice::Draw(dc); char temp[32]; - sprintf(temp, "%i", *value_); + if (zeroLabel_.size() && *value_ == 0) { + strcpy(temp, zeroLabel_.c_str()); + } else { + sprintf(temp, fmt_, *value_); + } dc.SetFontStyle(dc.theme->uiFont); dc.DrawText(temp, bounds_.x2() - 12, bounds_.centerY(), style.fgColor, ALIGN_RIGHT | ALIGN_VCENTER); } @@ -418,7 +426,11 @@ void PopupSliderChoiceFloat::Draw(UIContext &dc) { } Choice::Draw(dc); char temp[32]; - sprintf(temp, "%2.2f", *value_); + if (zeroLabel_.size() && *value_ == 0.0f) { + strcpy(temp, zeroLabel_.c_str()); + } else { + sprintf(temp, fmt_, *value_); + } dc.SetFontStyle(dc.theme->uiFont); dc.DrawText(temp, bounds_.x2() - 12, bounds_.centerY(), style.fgColor, ALIGN_RIGHT | ALIGN_VCENTER); } diff --git a/ext/native/ui/ui_screen.h b/ext/native/ui/ui_screen.h index 5c6a2ef9e9..5765f0a242 100644 --- a/ext/native/ui/ui_screen.h +++ b/ext/native/ui/ui_screen.h @@ -241,6 +241,13 @@ public: virtual void Draw(UIContext &dc) override; + void SetFormat(const char *fmt) { + fmt_ = fmt; + } + void SetZeroLabel(const std::string &str) { + zeroLabel_ = str; + } + Event OnChange; private: @@ -251,6 +258,8 @@ private: int minValue_; int maxValue_; int step_; + const char *fmt_; + std::string zeroLabel_; std::string units_; ScreenManager *screenManager_; bool restoreFocus_; @@ -263,6 +272,13 @@ public: virtual void Draw(UIContext &dc) override; + void SetFormat(const char *fmt) { + fmt_ = fmt; + } + void SetZeroLabel(const std::string &str) { + zeroLabel_ = str; + } + Event OnChange; private: @@ -272,6 +288,8 @@ private: float minValue_; float maxValue_; float step_; + const char *fmt_; + std::string zeroLabel_; std::string units_; ScreenManager *screenManager_; bool restoreFocus_;