-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add place editor on Avalonia branch (#449)
Showing
5 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/SerialLoops/ViewModels/Editors/PlaceEditorViewModel.cs
This file contains 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,48 @@ | ||
using System.IO; | ||
using Avalonia.Platform; | ||
using HaruhiChokuretsuLib.Util; | ||
using ReactiveUI; | ||
using ReactiveUI.Fody.Helpers; | ||
using SerialLoops.Lib.Items; | ||
using SkiaSharp; | ||
|
||
namespace SerialLoops.ViewModels.Editors; | ||
|
||
public class PlaceEditorViewModel : EditorViewModel | ||
{ | ||
private PlaceItem _place; | ||
private SKTypeface _msGothicHaruhi; | ||
|
||
[Reactive] | ||
public SKBitmap Preview { get; set; } | ||
|
||
public string PlaceName | ||
{ | ||
get => _place.PlaceName; | ||
set | ||
{ | ||
_place.PlaceName = value; | ||
this.RaisePropertyChanged(); | ||
Preview = _place.GetNewPlaceGraphic(_msGothicHaruhi); | ||
_place.PlaceGraphic.SetImage(Preview); | ||
_place.UnsavedChanges = true; | ||
} | ||
} | ||
|
||
public PlaceEditorViewModel(PlaceItem place, MainWindowViewModel window, ILogger log) : base(place, window, log) | ||
{ | ||
_place = place; | ||
if (string.IsNullOrEmpty(_place.PlaceName)) | ||
{ | ||
_place.PlaceName = _place.DisplayName[4..]; | ||
} | ||
Preview = _place.GetPreview(window.OpenProject); | ||
|
||
using Stream typefaceStream = AssetLoader.Open(new("avares://SerialLoops/Assets/Graphics/MS-Gothic-Haruhi.ttf")); | ||
_msGothicHaruhi = SKTypeface.FromStream(typefaceStream); | ||
if (!PlaceItem.CustomFontMapper.HasFont()) | ||
{ | ||
PlaceItem.CustomFontMapper.AddFont(_msGothicHaruhi); | ||
} | ||
} | ||
} |
This file contains 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 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 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,20 @@ | ||
<UserControl xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:vm="using:SerialLoops.ViewModels.Editors" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:assets="using:SerialLoops.Assets" | ||
xmlns:utility="using:SerialLoops.Utility" | ||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" | ||
x:DataType="vm:PlaceEditorViewModel" | ||
x:Class="SerialLoops.Views.Editors.PlaceEditorView"> | ||
<Grid RowDefinitions="Auto,Auto"> | ||
<Image Grid.Row="0" Stretch="None" | ||
Source="{Binding Preview, Converter={x:Static utility:SLConverters.SKBitmapToAvaloniaConverter}}"/> | ||
<StackPanel Grid.Row="1" Orientation="Horizontal" Spacing="3"> | ||
<TextBlock Text="{x:Static assets:Strings.Place_Name}"/> | ||
<TextBox Text="{Binding PlaceName}"/> | ||
</StackPanel> | ||
</Grid> | ||
</UserControl> | ||
|
This file contains 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,12 @@ | ||
using Avalonia.Controls; | ||
|
||
namespace SerialLoops.Views.Editors; | ||
|
||
public partial class PlaceEditorView : UserControl | ||
{ | ||
public PlaceEditorView() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
|