Skip to content

Commit

Permalink
Merge pull request #16878 from hrydgard/selective-restore-to-default
Browse files Browse the repository at this point in the history
Restore settings to default - let you choose what to reset
  • Loading branch information
hrydgard committed Jan 31, 2023
2 parents 8e38ac0 + 5154e5e commit 599bfed
Show file tree
Hide file tree
Showing 48 changed files with 286 additions and 162 deletions.
2 changes: 1 addition & 1 deletion Common/UI/UIScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class PopupScreen : public UIDialogScreen {
void update() override;

private:
UI::LinearLayout *box_;
UI::LinearLayout *box_ = nullptr;
UI::Button *defaultButton_ = nullptr;
std::string title_;
std::string button1_;
Expand Down
7 changes: 4 additions & 3 deletions Common/UI/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,8 @@ void TextView::GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz
bounds.w -= bulletOffset;
}
dc.MeasureTextRect(small_ ? dc.theme->uiFontSmall : dc.theme->uiFont, 1.0f, 1.0f, text_.c_str(), (int)text_.length(), bounds, &w, &h, textAlign_);

w += pad_ * 2.0f;
h += pad_ * 2.0f;
if (bullet_) {
w += bulletOffset;
}
Expand Down Expand Up @@ -1044,9 +1045,9 @@ void TextView::Draw(UIContext &dc) {

if (shadow_) {
uint32_t shadowColor = 0x80000000;
dc.DrawTextRect(text_.c_str(), textBounds.Offset(1.0f, 1.0f), shadowColor, textAlign_);
dc.DrawTextRect(text_.c_str(), textBounds.Offset(1.0f + pad_, 1.0f + pad_), shadowColor, textAlign_);
}
dc.DrawTextRect(text_.c_str(), textBounds, textColor, textAlign_);
dc.DrawTextRect(text_.c_str(), textBounds.Offset(pad_, pad_), textColor, textAlign_);
if (small_) {
// If we changed font style, reset it.
dc.SetFontStyle(dc.theme->uiFont);
Expand Down
2 changes: 2 additions & 0 deletions Common/UI/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,7 @@ class TextView : public InertView {
void SetFocusable(bool focusable) { focusable_ = focusable; }
void SetClip(bool clip) { clip_ = clip; }
void SetBullet(bool bullet) { bullet_ = bullet; }
void SetPadding(float pad) { pad_ = pad; }

bool CanBeFocused() const override { return focusable_; }

Expand All @@ -947,6 +948,7 @@ class TextView : public InertView {
bool focusable_;
bool clip_;
bool bullet_ = false;
float pad_ = 0.0f;
};

class TextEdit : public View {
Expand Down
26 changes: 20 additions & 6 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1815,17 +1815,31 @@ const Path Config::FindConfigFile(const std::string &baseFilename) {
return filename;
}

void Config::RestoreDefaults() {
void Config::RestoreDefaults(RestoreSettingsBits whatToRestore) {
if (bGameSpecific) {
deleteGameConfig(gameId_);
createGameConfig(gameId_);
Load();
} else {
if (File::Exists(iniFilename_))
File::Delete(iniFilename_);
ClearRecentIsos();
currentDirectory = defaultCurrentDirectory;
if (whatToRestore & RestoreSettingsBits::SETTINGS) {
if (File::Exists(iniFilename_))
File::Delete(iniFilename_);
}

if (whatToRestore & RestoreSettingsBits::CONTROLS) {
if (File::Exists(controllerIniFilename_))
File::Delete(controllerIniFilename_);
}

if (whatToRestore & RestoreSettingsBits::RECENT) {
ClearRecentIsos();
currentDirectory = defaultCurrentDirectory;
}

if (whatToRestore & (RestoreSettingsBits::SETTINGS | RestoreSettingsBits::CONTROLS)) {
Load();
}
}
Load();
}

bool Config::hasGameConfig(const std::string &pGameId) {
Expand Down
2 changes: 1 addition & 1 deletion Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ struct Config {
void Load(const char *iniFileName = nullptr, const char *controllerIniFilename = nullptr);
bool Save(const char *saveReason);
void Reload();
void RestoreDefaults();
void RestoreDefaults(RestoreSettingsBits whatToRestore);

//per game config managment, should maybe be in it's own class
void changeGameSpecific(const std::string &gameId = "", const std::string &title = "");
Expand Down
7 changes: 7 additions & 0 deletions Core/ConfigValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ enum class GPUBackend {
VULKAN = 3,
};

enum class RestoreSettingsBits : int {
SETTINGS = 1,
CONTROLS = 2,
RECENT = 4,
};
ENUM_CLASS_BITOPS(RestoreSettingsBits);

inline std::string GPUBackendToString(GPUBackend backend) {
switch (backend) {
case GPUBackend::OPENGL:
Expand Down
Loading

0 comments on commit 599bfed

Please sign in to comment.