Skip to content

Commit

Permalink
Fix quest marker rotation on rotated maps
Browse files Browse the repository at this point in the history
  • Loading branch information
CactusPie committed Dec 9, 2023
1 parent 50421a8 commit 32644cd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
27 changes: 20 additions & 7 deletions src/CactusPie.MapLocation.Minimap/Controls/MapControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void SetBotGameLocations(List<BotLocation> botLocations)

BotMarkers.EnsureCapacity(botLocations.Count);

Visibility visibility = BotMarkersVisible ? Visibility.Visible : Visibility.Collapsed;
Visibility visibility = BotMarkersVisible ? Visibility.Visible : Visibility.Hidden;

// We scale it so it looks the same regardless of map size
var scaleTransform = new ScaleTransform
Expand Down Expand Up @@ -284,7 +284,7 @@ public void SetAirdropData(AirdropData? airdropData)
if (_lastReceivedAirdropData != null)
{
_lastReceivedAirdropData = null;
AirdropMarkerImage.Visibility = Visibility.Collapsed;
AirdropMarkerImage.Visibility = Visibility.Hidden;
return;
}

Expand Down Expand Up @@ -532,7 +532,7 @@ private void CurrentBoundDataOnBoundDataUpdated(object? sender, EventArgs e)

private void SetQuestMarkerVisibility(bool areVisible)
{
Visibility visibility = areVisible ? Visibility.Visible : Visibility.Collapsed;
Visibility visibility = areVisible ? Visibility.Visible : Visibility.Hidden;

foreach (QuestMarker questMarker in QuestMarkers.Values)
{
Expand All @@ -542,7 +542,7 @@ private void SetQuestMarkerVisibility(bool areVisible)

private void SetBotMarkerVisibility(bool areVisible)
{
Visibility visibility = areVisible ? Visibility.Visible : Visibility.Collapsed;
Visibility visibility = areVisible ? Visibility.Visible : Visibility.Hidden;

foreach (Image botMarker in BotMarkers.Values)
{
Expand Down Expand Up @@ -599,15 +599,19 @@ private void SetQuestGameLocations(IReadOnlyList<QuestData>? quests)
RemoveQuest(questIdToRemove);
}

Visibility visibility = QuestMarkersVisible ? Visibility.Visible : Visibility.Collapsed;
Visibility visibility = QuestMarkersVisible ? Visibility.Visible : Visibility.Hidden;

// We scale it so it looks the same regardless of map size
var transformGroup = new TransformGroup();
var scaleTransform = new ScaleTransform
{
ScaleX = selectedMap.MarkerScale,
ScaleY = selectedMap.MarkerScale,
};

transformGroup.Children.Add(new RotateTransform { Angle = -selectedMap.MapRotation });
transformGroup.Children.Add(scaleTransform);

foreach (QuestData quest in quests)
{
TransformedPositionResult mapPositions = selectedMap.TransformPositions(
Expand All @@ -626,7 +630,16 @@ private void SetQuestGameLocations(IReadOnlyList<QuestData>? quests)
{
questMarker = new QuestMarker(quest);
questMarker.Visibility = visibility;
questMarker.RenderTransform = scaleTransform;

questMarker.Loaded += (_, _) =>
{
// We want to rotate along the middle of the checkmark button. 2d is here because we want to halve
// the button height or width
double xTransform = questMarker.QuestButton.ActualWidth / (2d * questMarker.ActualWidth);
double yTransform = questMarker.QuestButton.ActualHeight/ (2d * questMarker.ActualHeight);
questMarker.RenderTransformOrigin = new Point(xTransform, yTransform);
questMarker.RenderTransform = transformGroup;
};

WeakEventManager<QuestMarker, QuestMarkerDescriptionVisibilityChangedEventArgs>
.AddHandler(questMarker, nameof(questMarker.DescriptionVisibilityChanged), OnQuestMarkerOnDescriptionVisibilityChanged);
Expand All @@ -645,7 +658,7 @@ private void SetAirdropLocation(IMap selectedMap)
{
if (_lastReceivedAirdropData == null)
{
AirdropMarkerImage.Visibility = Visibility.Collapsed;
AirdropMarkerImage.Visibility = Visibility.Hidden;
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/CactusPie.MapLocation.Minimap/Controls/QuestMarker.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<Button Grid.Row="0" Name="QuestButton" Style="{StaticResource QuestButtonStyle}" Focusable="False" Width="24"
<Button Grid.Row="0" Name="QuestButton" Style="{StaticResource QuestButtonStyle}" Focusable="False" Width="24" Height="24"
HorizontalAlignment="Left" Click="QuestButton_OnClick">
<Image Source="pack://application:,,,/Resources/quest_marker.png"></Image>
</Button>

<Button Grid.Row="1" Name="DescriptionButton" Style="{StaticResource QuestButtonStyle}" Margin="0 2 0 0"
Focusable="False" Visibility="Collapsed" Opacity="0.95" Click="DescriptionButton_OnClick">
Focusable="False" Visibility="Hidden" Opacity="0.95" Click="DescriptionButton_OnClick">
<Border BorderBrush="Black" BorderThickness="1" CornerRadius="5" Width="250"
Padding="2" Background="White">
<StackPanel Orientation="Vertical" Background="White">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private void DescriptionButton_OnClick(object sender, RoutedEventArgs e)
private void ToggleDescriptionVisibility()
{
DescriptionButton.Visibility =
DescriptionButton.Visibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
DescriptionButton.Visibility == Visibility.Visible ? Visibility.Hidden : Visibility.Visible;
IsDescriptionVisible = DescriptionButton.Visibility == Visibility.Visible;
OnDescriptionVisibilityChanged(new QuestMarkerDescriptionVisibilityChangedEventArgs(IsDescriptionVisible));
}
Expand Down
2 changes: 1 addition & 1 deletion src/CactusPie.MapLocation/MapLocationPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace CactusPie.MapLocation
{
[BepInPlugin("com.cactuspie.maplocation", "CactusPie.MapLocation", "2.0.0")]
[BepInPlugin("com.cactuspie.maplocation", "CactusPie.MapLocation", "2.0.1")]
public sealed class MapLocationPlugin : BaseUnityPlugin
{
internal static ManualLogSource MapLocationLogger { get; private set; }
Expand Down

0 comments on commit 32644cd

Please sign in to comment.