Skip to content

Commit

Permalink
Merge branch 'main' into sprite-download-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
MattEqualsCoder authored Jul 23, 2024
2 parents 6b9956a + 36e3406 commit 167ebf1
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia.Media;
using AvaloniaControls.Models;
using Material.Icons;
Expand Down Expand Up @@ -58,6 +59,10 @@ public class TrackerWindowViewModel : ViewModelBase
public bool VoiceEnabled { get; set; }
public bool DisplayTimer { get; set; }

public int IdealWindowWidth => Panels.Max(x => x.Column) * 34 + 10;
public int IdealWindowHeight => Panels.Max(x => x.Row) * 34 + 10 + 50;
[Reactive] public bool ShowResizeButton { get; set; }

public string SpeechToolTip => VoiceEnabled ? "Confidence of last recognized voice command. Double click to disable voice recognition." : "Voice recognition disabled. Double click to attempt to enable voice recognition.";

public MaterialIconKind SpeechIcon => VoiceEnabled ? MaterialIconKind.Microphone : MaterialIconKind.MicOff;
Expand Down
71 changes: 41 additions & 30 deletions src/TrackerCouncil.Smz3.UI/Views/TrackerWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,51 @@
Title="Tracker — SMZ3 Cas' Randomizer"
Loaded="Control_OnLoaded"
Closing="Window_OnClosing"
Resized="WindowBase_OnResized"
Icon="/Assets/smz3.ico">
<LayoutTransformControl x:Name="MainLayout">
<Grid RowDefinitions="Auto, *, Auto">
<controls:HeaderFooter Grid.Row="0" BorderSize="0 0 0 2">
<Menu FontSize="12">
<MenuItem Header="_File">
<MenuItem Header="_Load saved state..."
x:Name="LoadSavedStateMenuItem"
Click="LoadSavedStateMenuItem_OnClick" />
<MenuItem Header="_Save state..."
x:Name="SaveStateMenuItem"
Click="SaveStateMenuItem_OnClick" />
</MenuItem>
<MenuItem Header="_View">
<MenuItem Header="_Locations"
x:Name="LocationsMenuItem"
Click="LocationsMenuItem_OnClick" />
<MenuItem Header="_Map"
x:Name="MapMenuItem"
Click="MapMenuItem_OnClick" />
<MenuItem Header="_Current Song"
x:Name="CurrentSongMenuItem"
Click="CurrentSongMenuItem_OnClick" />
<MenuItem Header="_Tracker Help"
x:Name="TrackerHelpMenuItem"
Click="TrackerHelpMenuItem_OnClick" />
<MenuItem Header="_Auto Tracker Help"
x:Name="AutoTrackerMenuItem"
Click="AutoTrackerMenuItem_OnClick" />
</MenuItem>
<MenuItem Header="_Layouts"
Name="LayoutMenu">
</MenuItem>
</Menu>
<Grid ColumnDefinitions="*,Auto">
<Menu Grid.Column="0" FontSize="12">
<MenuItem Header="_File">
<MenuItem Header="_Load saved state..."
x:Name="LoadSavedStateMenuItem"
Click="LoadSavedStateMenuItem_OnClick" />
<MenuItem Header="_Save state..."
x:Name="SaveStateMenuItem"
Click="SaveStateMenuItem_OnClick" />
</MenuItem>
<MenuItem Header="_View">
<MenuItem Header="_Locations"
x:Name="LocationsMenuItem"
Click="LocationsMenuItem_OnClick" />
<MenuItem Header="_Map"
x:Name="MapMenuItem"
Click="MapMenuItem_OnClick" />
<MenuItem Header="_Current Song"
x:Name="CurrentSongMenuItem"
Click="CurrentSongMenuItem_OnClick" />
<MenuItem Header="_Tracker Help"
x:Name="TrackerHelpMenuItem"
Click="TrackerHelpMenuItem_OnClick" />
<MenuItem Header="_Auto Tracker Help"
x:Name="AutoTrackerMenuItem"
Click="AutoTrackerMenuItem_OnClick" />
</MenuItem>
<MenuItem Header="_Layouts"
Name="LayoutMenu">
</MenuItem>
</Menu>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<controls:ImageButton Cursor="Hand" Background="Transparent" Click="ResizeWindowButton_OnClick" IsVisible="{Binding ShowResizeButton}">
<StackPanel Orientation="Horizontal" Background="Transparent">
<TextBlock Margin="0 0 5 0">Resize to Fit</TextBlock>
<avalonia:MaterialIcon Kind="Resize" Margin="0 0 5 0"></avalonia:MaterialIcon>
</StackPanel>
</controls:ImageButton>
</StackPanel>
</Grid>
</controls:HeaderFooter>
<DockPanel Grid.Row="1" Background="{Binding Background}">
<Panel Name="MainPanel" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5"></Panel>
Expand Down
33 changes: 33 additions & 0 deletions src/TrackerCouncil.Smz3.UI/Views/TrackerWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
Expand Down Expand Up @@ -110,6 +111,14 @@ private void LayoutMenuItemOnClick(object? sender, RoutedEventArgs e)
ITaskService.Run(() =>
{
_service?.SetLayout(layout);

Dispatcher.UIThread.Invoke(() =>
{
if (Math.Abs(Width - _model.IdealWindowWidth) > 1 || Math.Abs(Height - _model.IdealWindowHeight) > 1)
{
_model.ShowResizeButton = true;
}
});
});
}

Expand Down Expand Up @@ -152,6 +161,11 @@ private void Control_OnLoaded(object? sender, RoutedEventArgs e)
}, DispatcherPriority.Background);
});

if (Math.Abs(Width - _model.IdealWindowWidth) > 1 || Math.Abs(Height - _model.IdealWindowHeight) > 1)
{
_model.ShowResizeButton = true;
}

_parentWindow?.Hide();
}

Expand Down Expand Up @@ -270,5 +284,24 @@ private void SpeechRecognition_OnPointerPressed(object? sender, PointerPressedEv
_service?.ToggleSpeechRecognition();
}
}

private void ResizeWindowButton_OnClick(object? sender, RoutedEventArgs e)
{
Width = _model.IdealWindowWidth;
Height = _model.IdealWindowHeight;
_model.ShowResizeButton = false;
}

private void WindowBase_OnResized(object? sender, WindowResizedEventArgs e)
{
if (Math.Abs(Width - _model.IdealWindowWidth) > 1 || Math.Abs(Height - _model.IdealWindowHeight) > 1)
{
_model.ShowResizeButton = true;
}
else
{
_model.ShowResizeButton = false;
}
}
}

0 comments on commit 167ebf1

Please sign in to comment.