Skip to content

Commit

Permalink
add DrawPlayerLocationHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
MikiraSora committed Sep 3, 2024
1 parent 0cc606f commit 3467cc6
Show file tree
Hide file tree
Showing 13 changed files with 700 additions and 546 deletions.
3 changes: 3 additions & 0 deletions OngekiFumenEditor/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@
<setting name="EnablePlayFieldDrawing" serializeAs="String">
<value>False</value>
</setting>
<setting name="EnableShowPlayerLocation" serializeAs="String">
<value>False</value>
</setting>
</OngekiFumenEditor.Properties.EditorGlobalSetting>
<OngekiFumenEditor.Properties.AudioPlayerToolViewerSetting>
<setting name="ResampleSize" serializeAs="String">
Expand Down
2 changes: 1 addition & 1 deletion OngekiFumenEditor/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</ResourceDictionary>
<ResourceDictionary Source="UI\Themes\TextBlock.xaml">
</ResourceDictionary>
<!-- Theme setting -->
<!-- Theme setting -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
xmlns:markup="clr-namespace:OngekiFumenEditor.UI.Markup"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:res="clr-namespace:OngekiFumenEditor.Properties"
xmlns:vm="clr-namespace:OngekiFumenEditor.Kernel.SettingPages.FumenVisualEditor.ViewModels" xmlns:valueconverters="clr-namespace:OngekiFumenEditor.Kernel.SettingPages.FumenVisualEditor.ValueConverters"
xmlns:valueconverters="clr-namespace:OngekiFumenEditor.Kernel.SettingPages.FumenVisualEditor.ValueConverters"
xmlns:vm="clr-namespace:OngekiFumenEditor.Kernel.SettingPages.FumenVisualEditor.ViewModels"
d:Background="White"
d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True,
Type=vm:FumenVisualEditorGlobalSettingViewModel}"
d:DesignWidth="800"
mc:Ignorable="d">
<UserControl.Resources>
<valueconverters:IntToSolidBrush x:Key="IntToSolidBrush"/>
<valueconverters:IntToSolidBrush x:Key="IntToSolidBrush" />
</UserControl.Resources>
<StackPanel>
<GroupBox Margin="5" Header="{markup:Translate [AutoSave]}">
Expand Down Expand Up @@ -99,30 +100,54 @@
</StackPanel>
</GroupBox>
<GroupBox Margin="5" Header="{markup:Translate [Render]}">
<GroupBox Header="{markup:Translate [PreviewMode]}" Margin="5">
<GroupBox Margin="5" Header="{markup:Translate [PreviewMode]}">
<StackPanel Margin="10">
<StackPanel Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" Text="{markup:Translate [BellBulletCountOverLimit_Part1]}" />
<TextBox
Width="50"
Margin="5,0,5,0"
Text="{Binding Setting.ParallelCountLimit}">
Width="50"
Margin="5,0,5,0"
Text="{Binding Setting.ParallelCountLimit}">
</TextBox>
<TextBlock VerticalAlignment="Center" Text="{markup:Translate [BellBulletCountOverLimit_Part2]}" />
</StackPanel>
<StackPanel Margin="0,10,0,5" Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" Text="{markup:Translate [BackgroundColor]}"/>
<Border BorderThickness="1" BorderBrush="{Binding Setting.PlayFieldBackgroundColor,Converter={StaticResource IntToSolidBrush},ConverterParameter=True}" CornerRadius="7" Width="60" Height="18" Cursor="Hand" Background="{Binding Setting.PlayFieldBackgroundColor,Converter={StaticResource IntToSolidBrush}}" Margin="10,0" cal:Message.Attach="[Event MouseDown] = [Action OnSelectBackgroundColor($executionContext)]">
<TextBlock VerticalAlignment="Center" Text="{markup:Translate [BackgroundColor]}" />
<Border
Width="60"
Height="18"
Margin="10,0"
cal:Message.Attach="[Event MouseDown] = [Action OnSelectBackgroundColor($executionContext)]"
Background="{Binding Setting.PlayFieldBackgroundColor, Converter={StaticResource IntToSolidBrush}}"
BorderBrush="{Binding Setting.PlayFieldBackgroundColor, Converter={StaticResource IntToSolidBrush}, ConverterParameter=True}"
BorderThickness="1"
CornerRadius="7"
Cursor="Hand">
</Border>
</StackPanel>
<CheckBox IsChecked="{Binding Setting.EnablePlayFieldDrawing}">
<TextBlock Text="{markup:Translate [EnablePlayFieldDrawing]}"/>
<TextBlock Text="{markup:Translate [EnablePlayFieldDrawing]}" />
</CheckBox>
<StackPanel IsEnabled="{Binding Setting.EnablePlayFieldDrawing}" Margin="0,5,0,5" Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" Text="{markup:Translate [PlayFieldForegroundColor]}"/>
<Border BorderThickness="1" BorderBrush="{Binding Setting.PlayFieldForegroundColor,Converter={StaticResource IntToSolidBrush},ConverterParameter=True}" CornerRadius="7" Width="60" Height="18" Cursor="Hand" Background="{Binding Setting.PlayFieldForegroundColor,Converter={StaticResource IntToSolidBrush}}" Margin="10,0" cal:Message.Attach="[Event MouseDown] = [Action OnSelectForegroundColor($executionContext)]">
<StackPanel
Margin="0,5,0,5"
IsEnabled="{Binding Setting.EnablePlayFieldDrawing}"
Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" Text="{markup:Translate [PlayFieldForegroundColor]}" />
<Border
Width="60"
Height="18"
Margin="10,0"
cal:Message.Attach="[Event MouseDown] = [Action OnSelectForegroundColor($executionContext)]"
Background="{Binding Setting.PlayFieldForegroundColor, Converter={StaticResource IntToSolidBrush}}"
BorderBrush="{Binding Setting.PlayFieldForegroundColor, Converter={StaticResource IntToSolidBrush}, ConverterParameter=True}"
BorderThickness="1"
CornerRadius="7"
Cursor="Hand">
</Border>
</StackPanel>
<CheckBox IsChecked="{Binding Setting.EnableShowPlayerLocation}">
<TextBlock Text="{markup:Translate [EnableShowPlayerLocation]}" />
</CheckBox>
</StackPanel>
</GroupBox>
</GroupBox>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.ComponentModel;
using System.Linq;
using System.Numerics;
using Caliburn.Micro;
using OngekiFumenEditor.Base;
using OngekiFumenEditor.Base.EditorObjects;
using OngekiFumenEditor.Kernel.Graphics;
using OngekiFumenEditor.Kernel.Graphics.Base;
using OngekiFumenEditor.Utils;

namespace OngekiFumenEditor.Modules.FumenVisualEditor.Graphics.Drawing.Editors;

public class DrawPlayerLocationHelper
{
private readonly (Vector2 size, Vector2 position, float rotation)[] arr = { default };
private readonly Texture texture;
private readonly ITextureDrawing textureDrawing;
private bool enableShowPlayerLocation;

public DrawPlayerLocationHelper()
{
textureDrawing = IoC.Get<ITextureDrawing>();
arr[0].size = new Vector2(48, 48);
arr[0].rotation = 0f;

texture = ResourceUtils.OpenReadTextureFromResource(@"Modules\FumenVisualEditor\Views\OngekiObjects\playerLoc.png");

UpdateProps();
Properties.EditorGlobalSetting.Default.PropertyChanged += Default_PropertyChanged;
}

private void UpdateProps()
{
enableShowPlayerLocation = Properties.EditorGlobalSetting.Default.EnableShowPlayerLocation;
}

private void Default_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(Properties.EditorGlobalSetting.EnableShowPlayerLocation):
UpdateProps();
break;
default:
break;
}
}

public void Draw(IFumenEditorDrawingContext target)
{
if (target.Editor.IsDesignMode)
return;
if (!enableShowPlayerLocation)
return;

var tGrid = TGridCalculator.ConvertAudioTimeToTGrid(target.CurrentPlayTime, target.Editor);
var apfLane = target.Editor.Fumen.Lanes.GetVisibleStartObjects(tGrid, tGrid).OfType<AutoplayFaderLaneStart>()
.LastOrDefault();
var xGrid = apfLane?.CalulateXGrid(tGrid) ?? XGrid.Zero;

var x = XGridCalculator.ConvertXGridToX(xGrid, target.Editor);
var y = target.ConvertToY(tGrid);

arr[0].position = new Vector2((float)x, (float)y);

textureDrawing.Draw(target, texture, arr);
}
}
Loading

0 comments on commit 3467cc6

Please sign in to comment.