Skip to content

Commit

Permalink
Add setting to alter map pan speed
Browse files Browse the repository at this point in the history
  • Loading branch information
timoschwarzer committed May 22, 2024
1 parent 5cc0773 commit 7618835
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions projects/Core/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ namespace core::settings {
return get_settings().get_float("Values", "CameraShakeIntensity", 1.f);
}

float map_pan_speed() {
return get_settings().get_float("Values", "MapPanSpeed", 1.f);
}

bool shriek_is_shrek() {
return get_settings().get_boolean("Flags", "ShriekIsShrek", false);
}
Expand Down
1 change: 1 addition & 0 deletions projects/Core/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace core::settings {
CORE_DLLEXPORT bool world_map_enabled();
CORE_DLLEXPORT float map_icon_transparency();
CORE_DLLEXPORT float camera_shake_intensity();
CORE_DLLEXPORT float map_pan_speed();
CORE_DLLEXPORT bool shriek_is_shrek();
CORE_DLLEXPORT bool enable_minimap();
CORE_DLLEXPORT std::string ori_model_texture();
Expand Down
18 changes: 18 additions & 0 deletions projects/Randomizer/game/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
#include <Modloader/app/methods/GameMapUI.h>
#include <Modloader/app/methods/Moon/uberSerializationWisp/PlayerUberStateAreaMapInformation.h>
#include <Modloader/app/methods/RuntimeWorldMapIcon.h>
#include <Modloader/app/methods/UnityEngine/AnimationCurve.h>
#include <Modloader/app/structs/Boolean__Boxed.h>
#include <Modloader/app/types/GameMapUI.h>
#include <Modloader/app/types/GameWorld.h>
#include <Modloader/app/types/PlayerUberStateGroup.h>
#include <Modloader/app/types/GameSettings.h>
#include <Modloader/il2cpp_helpers.h>
#include <Modloader/interception_macros.h>
#include <Randomizer/game/map/filter.h>
Expand All @@ -30,6 +32,7 @@ namespace randomizer::game::map {
std::unordered_map<Filters, icon_vector> icons;
std::unordered_map<std::shared_ptr<Icon>, icon_visibility_callback> visibility_callbacks;
Filters last_filter = Filters::COUNT;
auto is_handling_map_scrolling_on_controller = false;

app::WorldMapIconType__Enum get_base_icon(const app::RuntimeWorldMapIcon* icon) {
for (const auto base_icon: il2cpp::ListIterator(icon->fields.Area->fields.Area->fields.Icons)) {
Expand Down Expand Up @@ -212,6 +215,21 @@ namespace randomizer::game::map {
}
}

IL2CPP_INTERCEPT(UnityEngine::AnimationCurve, float, Evaluate, (app::AnimationCurve* this_ptr, float time)) {
if (is_handling_map_scrolling_on_controller) {
// When scrolling the map on controller, time is the magnitude of
// the input axis
return next::UnityEngine::AnimationCurve::Evaluate(this_ptr, time) * core::settings::map_pan_speed();
}

return next::UnityEngine::AnimationCurve::Evaluate(this_ptr, time);
}

IL2CPP_INTERCEPT(AreaMapNavigation, void, HandleMapScrolling, (app::AreaMapNavigation* this_ptr)) {
ScopedSetter _(is_handling_map_scrolling_on_controller, types::GameSettings::get_class()->static_fields->Instance->fields.m_currentControlSchemes == app::ControlScheme__Enum::Controller);
next::AreaMapNavigation::HandleMapScrolling(this_ptr);
}

auto on_area_map_destroyed = core::api::game::event_bus().register_handler(GameEvent::DestroyAreaMap, EventTiming::Before, [](auto, auto) {
for (auto const& icon_set: icons | std::views::values) {
for (auto const& icon: icon_set) {
Expand Down

0 comments on commit 7618835

Please sign in to comment.