-
Notifications
You must be signed in to change notification settings - Fork 0
feat(config): add SKSE Menu Framework menu #47
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
35964e4
feat(menu): add SKSE Menu Framework menu
codepuncher bfe086f
fix(menu): review changes
codepuncher 41a52ab
fix(config): extract ParseAction and ActionName into ConfigParsing.cpp
codepuncher c8df503
fix(menu-ui): use backslash path in LoadLibraryW (r3369989651)
codepuncher bf4040f
fix(config): add missing vector include to Config.h (r3369989658)
codepuncher d0f69ea
refactor(config): remove logWarnings param and ifdef guards from Pars…
codepuncher ce6cd67
fix(config): preserve INI format on save
codepuncher 94f6442
refactor(config): extract LongPressAction and ButtonConfig to RE-free…
codepuncher ff73bfb
fix(plugin): remove unused includes and dead null-check
codepuncher b2be64a
fix(config): add cctype include and document menuFramework source
codepuncher da44bff
fix(menu): remove per-frame allocs and align hold duration minimum
codepuncher 89ae6c0
fix(config): log correct warning for below-minimum hold duration
codepuncher 04c0557
fix(input): skip IsBlockingInput check when no buttons are tracked
codepuncher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| #include "PCH.h" | ||
|
|
||
| #include <cctype> | ||
|
|
||
| #include "Config.h" | ||
| #include "InputHandler.h" | ||
| #include "Utils.h" | ||
|
|
||
| namespace | ||
| { | ||
| constexpr auto kIniPath = R"(Data\SKSE\Plugins\HoldFast.ini)"; | ||
|
|
||
| [[nodiscard]] float ReadHoldDuration(const CSimpleIniA& ini) | ||
| { | ||
| const auto raw = static_cast<float>(ini.GetDoubleValue("General", "fHoldDuration", HoldFast::kDefaultHoldDuration)); | ||
| const auto duration = HoldFast::ClampHoldDuration(raw, HoldFast::kDefaultHoldDuration, HoldFast::kMinHoldDuration, HoldFast::kMaxHoldDuration); | ||
| if (duration == raw) { | ||
| return duration; | ||
| } | ||
| if (!std::isfinite(raw)) { | ||
| logger::warn("fHoldDuration is non-finite — using default {:.1f}", HoldFast::kDefaultHoldDuration); | ||
| return duration; | ||
| } | ||
| if (raw <= 0.0F) { | ||
| logger::warn("fHoldDuration ({:.2f}) must be positive — using default {:.1f}", raw, HoldFast::kDefaultHoldDuration); | ||
| return duration; | ||
| } | ||
| if (raw < HoldFast::kMinHoldDuration) { | ||
| logger::warn("fHoldDuration ({:.2f}) is below minimum {:.1f} — using default {:.1f}", raw, HoldFast::kMinHoldDuration, HoldFast::kDefaultHoldDuration); | ||
| return duration; | ||
| } | ||
| logger::warn("fHoldDuration ({:.2f}) exceeds maximum {:.1f} — capping", raw, HoldFast::kMaxHoldDuration); | ||
|
codepuncher marked this conversation as resolved.
|
||
| return duration; | ||
| } | ||
| } | ||
|
|
||
| HoldFast::Config::Settings HoldFast::Config::LoadSettings() | ||
| { | ||
| Settings settings{}; | ||
|
|
||
| CSimpleIniA ini; | ||
| const auto rc = ini.LoadFile(kIniPath); | ||
| if (rc < SI_OK) { | ||
| logger::warn("HoldFast.ini not found or could not be parsed (rc={}) — using defaults", static_cast<int>(rc)); | ||
| } | ||
|
|
||
| settings.holdDuration = ReadHoldDuration(ini); | ||
|
|
||
| const char* rawStart = ini.GetValue("General", "sButtonStartAction", nullptr); | ||
| const char* rawBack = ini.GetValue("General", "sButtonBackAction", nullptr); | ||
| const bool hasStart = rawStart && !HoldFast::TrimWhitespace(rawStart).empty(); | ||
| const bool hasBack = rawBack && !HoldFast::TrimWhitespace(rawBack).empty(); | ||
|
|
||
| if (!hasStart && !hasBack) { | ||
| logger::info("No button action keys found — applying defaults (Start=Map, Back=System)"); | ||
| return settings; | ||
| } | ||
|
|
||
| settings.startAction = hasStart ? ParseAction(rawStart) : LongPressAction::kNone; | ||
| if (hasStart && settings.startAction == LongPressAction::kNone) { | ||
| std::string lower{ HoldFast::TrimWhitespace(rawStart) }; | ||
| for (auto& c : lower) { | ||
| c = static_cast<char>(std::tolower(static_cast<unsigned char>(c))); | ||
| } | ||
| if (lower != "none") { | ||
| logger::warn("sButtonStartAction='{}' is not a recognised action (valid: Map, System, Quests, Stats, Inventory, Magic, Favorites/Favourites, TweenMenu, Wait, NewSave, QuickSave, Bestiary, CharacterSheet, None) — disabling button", rawStart); | ||
| } | ||
| } | ||
|
codepuncher marked this conversation as resolved.
|
||
| settings.backAction = hasBack ? ParseAction(rawBack) : LongPressAction::kNone; | ||
| if (hasBack && settings.backAction == LongPressAction::kNone) { | ||
| std::string lower{ HoldFast::TrimWhitespace(rawBack) }; | ||
| for (auto& c : lower) { | ||
| c = static_cast<char>(std::tolower(static_cast<unsigned char>(c))); | ||
| } | ||
| if (lower != "none") { | ||
| logger::warn("sButtonBackAction='{}' is not a recognised action (valid: Map, System, Quests, Stats, Inventory, Magic, Favorites/Favourites, TweenMenu, Wait, NewSave, QuickSave, Bestiary, CharacterSheet, None) — disabling button", rawBack); | ||
| } | ||
| } | ||
|
codepuncher marked this conversation as resolved.
|
||
| return settings; | ||
| } | ||
|
|
||
| bool HoldFast::Config::SaveSettings(const Settings& settings) | ||
| { | ||
| CSimpleIniA ini; | ||
| ini.SetSpaces(false); | ||
| ini.LoadFile(kIniPath); | ||
|
|
||
| const auto startActionName = std::string{ ActionName(settings.startAction) }; | ||
| const auto backActionName = std::string{ ActionName(settings.backAction) }; | ||
|
|
||
| const auto holdDurationStr = fmt::format("{:g}", settings.holdDuration); | ||
| ini.SetValue("General", "fHoldDuration", holdDurationStr.c_str()); | ||
| ini.SetValue("General", "sButtonStartAction", startActionName.c_str()); | ||
| ini.SetValue("General", "sButtonBackAction", backActionName.c_str()); | ||
|
|
||
| const auto rc = ini.SaveFile(kIniPath); | ||
| if (rc < SI_OK) { | ||
| logger::error("Failed to write HoldFast.ini (rc={})", static_cast<int>(rc)); | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| std::vector<ButtonConfig> HoldFast::Config::BuildButtons(const Settings& settings) | ||
| { | ||
| using Key = RE::BSWin32GamepadDevice::Key; | ||
|
|
||
| std::vector<ButtonConfig> buttons; | ||
| if (settings.startAction != LongPressAction::kNone) { | ||
| buttons.push_back({ .keyCode = static_cast<std::uint32_t>(Key::kStart), .name = "Start", .action = settings.startAction }); | ||
| } | ||
| if (settings.backAction != LongPressAction::kNone) { | ||
| buttons.push_back({ .keyCode = static_cast<std::uint32_t>(Key::kBack), .name = "Back", .action = settings.backAction }); | ||
| } | ||
| return buttons; | ||
| } | ||
|
|
||
| void HoldFast::Config::ApplySettings(InputHandler& handler, const Settings& settings) | ||
| { | ||
| handler.SetHoldDuration(settings.holdDuration); | ||
| handler.SetButtons(BuildButtons(settings)); | ||
| handler.UpdateShortPressBinding(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| #pragma once | ||
|
|
||
| #include <array> | ||
| #include <string_view> | ||
| #include <vector> | ||
|
|
||
| #include "LongPressAction.h" | ||
|
|
||
| class InputHandler; | ||
|
|
||
|
codepuncher marked this conversation as resolved.
|
||
| namespace HoldFast::Config | ||
|
codepuncher marked this conversation as resolved.
|
||
| { | ||
| struct Settings | ||
| { | ||
| float holdDuration{ HoldFast::kDefaultHoldDuration }; | ||
| LongPressAction startAction{ LongPressAction::kMap }; | ||
| LongPressAction backAction{ LongPressAction::kSystem }; | ||
| }; | ||
|
|
||
| struct ActionOption | ||
| { | ||
| const char* name; | ||
| LongPressAction action; | ||
| }; | ||
|
|
||
| inline constexpr std::array<ActionOption, 14> kActionOptions{ { | ||
| { "Map", LongPressAction::kMap }, | ||
| { "System", LongPressAction::kSystem }, | ||
| { "Quests", LongPressAction::kQuests }, | ||
| { "Stats", LongPressAction::kStats }, | ||
| { "Inventory", LongPressAction::kInventory }, | ||
| { "Magic", LongPressAction::kMagic }, | ||
| { "Favorites", LongPressAction::kFavorites }, | ||
| { "TweenMenu", LongPressAction::kTweenMenu }, | ||
| { "Wait", LongPressAction::kWait }, | ||
| { "NewSave", LongPressAction::kNewSave }, | ||
| { "QuickSave", LongPressAction::kQuickSave }, | ||
| { "Bestiary", LongPressAction::kBestiary }, | ||
| { "CharacterSheet", LongPressAction::kCharacterSheet }, | ||
| { "None", LongPressAction::kNone }, | ||
| } }; | ||
|
|
||
| [[nodiscard]] Settings LoadSettings(); | ||
| [[nodiscard]] bool SaveSettings(const Settings& settings); | ||
|
|
||
| [[nodiscard]] std::vector<ButtonConfig> BuildButtons(const Settings& settings); | ||
| void ApplySettings(InputHandler& handler, const Settings& settings); | ||
|
|
||
| [[nodiscard]] LongPressAction ParseAction(std::string_view raw); | ||
| [[nodiscard]] const char* ActionName(LongPressAction action); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #include <cctype> | ||
| #include <unordered_map> | ||
|
|
||
| #include "Config.h" | ||
| #include "Utils.h" | ||
|
|
||
| LongPressAction HoldFast::Config::ParseAction(std::string_view raw) | ||
| { | ||
| static const std::unordered_map<std::string, LongPressAction> kActionMap{ | ||
| { "map", LongPressAction::kMap }, | ||
| { "system", LongPressAction::kSystem }, | ||
| { "quests", LongPressAction::kQuests }, | ||
| { "stats", LongPressAction::kStats }, | ||
| { "inventory", LongPressAction::kInventory }, | ||
| { "magic", LongPressAction::kMagic }, | ||
| { "favorites", LongPressAction::kFavorites }, | ||
| { "favourites", LongPressAction::kFavorites }, | ||
| { "tweenmenu", LongPressAction::kTweenMenu }, | ||
| { "wait", LongPressAction::kWait }, | ||
| { "newsave", LongPressAction::kNewSave }, | ||
| { "quicksave", LongPressAction::kQuickSave }, | ||
| { "bestiary", LongPressAction::kBestiary }, | ||
| { "charactersheet", LongPressAction::kCharacterSheet }, | ||
| { "none", LongPressAction::kNone }, | ||
| }; | ||
|
|
||
| const auto trimmed = HoldFast::TrimWhitespace(raw); | ||
| std::string lower{ trimmed }; | ||
| for (auto& c : lower) { | ||
| c = static_cast<char>(std::tolower(static_cast<unsigned char>(c))); | ||
| } | ||
|
|
||
| const auto it = kActionMap.find(lower); | ||
| return it != kActionMap.end() ? it->second : LongPressAction::kNone; | ||
| } | ||
|
|
||
| const char* HoldFast::Config::ActionName(LongPressAction action) | ||
| { | ||
| for (const auto& option : kActionOptions) { | ||
| if (option.action == action) { | ||
| return option.name; | ||
| } | ||
| } | ||
| return "None"; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.