Skip to content
This repository has been archived by the owner on Mar 14, 2023. It is now read-only.

Commit

Permalink
All buttons and textboxes are now disabled when the program starts up
Browse files Browse the repository at this point in the history
Also created the ElementManager.cs class, which is pretty self-explanatory
  • Loading branch information
Plextora committed Jan 19, 2023
1 parent ebbe899 commit dd7f1f9
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 38 deletions.
40 changes: 28 additions & 12 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@
Width="140"
Background="Transparent"
Foreground="PeachPuff"
BorderBrush="PeachPuff" />
BorderBrush="PeachPuff"
IsEnabled="False"/>
<Button
x:Name="OpenReplayButton"
Content="Open Replay"
Expand All @@ -321,7 +322,9 @@
Height="38"
Margin="310,67,186,0"
VerticalAlignment="Top"
Click="SaveReplayButton_Click" />
Click="SaveReplayButton_Click"
IsEnabled="False"
Opacity="0.6"/>
<TextBox
x:Name="ComboTextbox"
x:FieldModifier="public"
Expand All @@ -335,7 +338,8 @@
Width="140"
Background="Transparent"
Foreground="PeachPuff"
BorderBrush="PeachPuff" />
BorderBrush="PeachPuff"
IsEnabled="False"/>
<Label
Content="Combo"
Foreground="PeachPuff"
Expand All @@ -353,7 +357,9 @@
HorizontalAlignment="Left"
Margin="210,13,0,0"
VerticalAlignment="Top"
IsChecked="False" />
IsChecked="False"
IsEnabled="False"
Opacity="0.6"/>
<Label
Content="Number of 300s"
Foreground="PeachPuff"
Expand All @@ -373,7 +379,8 @@
Width="140"
Background="Transparent"
Foreground="PeachPuff"
BorderBrush="PeachPuff" />
BorderBrush="PeachPuff"
IsEnabled="False"/>
<Label
Content="Number of 100s"
Foreground="PeachPuff"
Expand All @@ -393,7 +400,8 @@
Width="140"
Background="Transparent"
Foreground="PeachPuff"
BorderBrush="PeachPuff" />
BorderBrush="PeachPuff"
IsEnabled="False"/>
<Label
Content="Number of 50s"
Foreground="PeachPuff"
Expand All @@ -413,7 +421,8 @@
Width="140"
Background="Transparent"
Foreground="PeachPuff"
BorderBrush="PeachPuff" />
BorderBrush="PeachPuff"
IsEnabled="False"/>
<Label
Content="Number of misses"
Foreground="PeachPuff"
Expand All @@ -433,7 +442,8 @@
Width="140"
Background="Transparent"
Foreground="PeachPuff"
BorderBrush="PeachPuff" />
BorderBrush="PeachPuff"
IsEnabled="False"/>
<Label
Content="Number of Geki's"
Foreground="PeachPuff"
Expand All @@ -453,7 +463,9 @@
Width="140"
Background="Transparent"
Foreground="PeachPuff"
BorderBrush="PeachPuff" Grid.RowSpan="2" />
BorderBrush="PeachPuff"
Grid.RowSpan="2"
IsEnabled="False"/>
<Label
Content="Number of Katu's"
Foreground="PeachPuff"
Expand All @@ -473,7 +485,9 @@
Width="140"
Background="Transparent"
Foreground="PeachPuff"
BorderBrush="PeachPuff" Grid.RowSpan="2" />
BorderBrush="PeachPuff"
Grid.RowSpan="2"
IsEnabled="False"/>
<Label
Content="Made by Plextora"
Foreground="PeachPuff"
Expand All @@ -482,7 +496,8 @@
Margin="0,115,10,0"
VerticalAlignment="Top"
FontSize="15"
Grid.Row="1" />
Grid.Row="1"
IsEnabled="False"/>
<TextBox
x:Name="ReplayTimestampTextBox"
x:FieldModifier="public"
Expand All @@ -496,7 +511,8 @@
Width="172"
Background="Transparent"
Foreground="PeachPuff"
BorderBrush="PeachPuff" />
BorderBrush="PeachPuff"
IsEnabled="False"/>
<Label
Content="Replay timestamp"
Foreground="PeachPuff"
Expand Down
19 changes: 4 additions & 15 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Globalization;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
Expand All @@ -15,7 +14,7 @@ namespace RyuEdit
/// </summary>
public partial class MainWindow
{
private Replay? _osuReplay;
private static Replay? _osuReplay;

public MainWindow()
{
Expand Down Expand Up @@ -51,22 +50,12 @@ private async void OpenReplayButton_Click(object sender, RoutedEventArgs e)
SetStatusLabel.Completed("Finished decoding replay! Now loading replay info...");
await Task.Delay(2000);
SetStatusLabel.Pending("Loading replay info...");
LoadReplayInfo();
OnReplayLoaded();
}

private async void LoadReplayInfo()
private static async void OnReplayLoaded()
{
ReplayUsernameTextbox.Text = _osuReplay?.PlayerName;
ComboTextbox.Text = (_osuReplay?.Combo).ToString();
ReplayTimestampTextBox.Text =
_osuReplay?.ReplayTimestamp.ToLocalTime().ToString(CultureInfo.CurrentCulture);
IsPerfectComboCheckbox.IsChecked = _osuReplay is { PerfectCombo: true };
_300CountTextBox.Text = _osuReplay?.Count300.ToString();
_100CountTextBox.Text = _osuReplay?.Count100.ToString();
_50CountTextBox.Text = _osuReplay?.Count50.ToString();
MissCountTextBox.Text = _osuReplay?.CountMiss.ToString();
GekiCountTextBox.Text = _osuReplay?.CountGeki.ToString();
KatuCountTextBox.Text = _osuReplay?.CountKatu.ToString();
ElementManager.LoadReplayInfo(_osuReplay);

SetStatusLabel.Completed("Loaded replay info!");
await Task.Delay(2000);
Expand Down
12 changes: 1 addition & 11 deletions Util/CheckFields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ public static class CheckFields

private static readonly TextBox? ComboTextbox = Form?.ComboTextbox;
private static readonly TextBox? ReplayTimestampTextBox = Form?.ReplayTimestampTextBox;
private static readonly IDictionary<TextBox?, string> JudgementTextBoxes = new Dictionary<TextBox, string>
{
{ Form?._300CountTextBox!, "number of 300s" },
{ Form?._100CountTextBox!, "number of 100s" },
{ Form?._50CountTextBox!, "number of 50s" },
{ Form?.MissCountTextBox!, "number of misses" },
{ Form?.GekiCountTextBox!, "number of Geki's" },
{ Form?.KatuCountTextBox!, "number of Katu's" }
// definitely not best practice but whatever, bad practice is my jam!
}!;

/*
* "Why do you have so many 'CheckX' functions that you don't use?"
Expand Down Expand Up @@ -58,7 +48,7 @@ public static bool CheckCombo()

public static bool CheckJudgements()
{
foreach (var i in JudgementTextBoxes)
foreach (var i in ElementManager.JudgementTextBoxes)
{
if (i.Key != null && i.Key.Text.Any(char.IsLetter))
{
Expand Down
68 changes: 68 additions & 0 deletions Util/ElementManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using OsuParsers.Replays;

namespace RyuEdit.Util;

public static class ElementManager
{
private static readonly MainWindow? Form = Application.Current.Windows[0] as MainWindow;
private static readonly TextBox?[] AllTextBoxes =
{
Form?.ReplayUsernameTextbox,
Form?.ComboTextbox,
Form?.ReplayTimestampTextBox,
Form?._300CountTextBox,
Form?._100CountTextBox,
Form?._50CountTextBox,
Form?.MissCountTextBox,
Form?.GekiCountTextBox,
Form?.KatuCountTextBox
};

private static readonly Dictionary<TextBox?, string?> TextBoxToValue = new();

public static readonly IDictionary<TextBox?, string> JudgementTextBoxes = new Dictionary<TextBox, string>
{
{ Form?._300CountTextBox!, "number of 300s" },
{ Form?._100CountTextBox!, "number of 100s" },
{ Form?._50CountTextBox!, "number of 50s" },
{ Form?.MissCountTextBox!, "number of misses" },
{ Form?.GekiCountTextBox!, "number of Geki's" },
{ Form?.KatuCountTextBox!, "number of Katu's" }
// definitely not best practice but whatever, bad practice is my jam!
}!;

public static void LoadReplayInfo(Replay? replay)
{
if (TextBoxToValue.Count != 0)
TextBoxToValue.Clear();

TextBoxToValue.Add(AllTextBoxes[0], replay?.PlayerName);
TextBoxToValue.Add(AllTextBoxes[1], (replay?.Combo).ToString());
TextBoxToValue.Add(AllTextBoxes[2], replay?.ReplayTimestamp.ToLocalTime().ToString(CultureInfo.CurrentCulture));
TextBoxToValue.Add(AllTextBoxes[3], replay?.Count300.ToString());
TextBoxToValue.Add(AllTextBoxes[4], replay?.Count100.ToString());
TextBoxToValue.Add(AllTextBoxes[5], replay?.Count50.ToString());
TextBoxToValue.Add(AllTextBoxes[6], replay?.CountMiss.ToString());
TextBoxToValue.Add(AllTextBoxes[7], replay?.CountGeki.ToString());
TextBoxToValue.Add(AllTextBoxes[8], replay?.CountKatu.ToString());

foreach (var i in TextBoxToValue.Where(i => i.Key != null))
{
if (i.Key == null) continue;
i.Key.Text = i.Value;
i.Key.IsEnabled = true;
}

if (Form == null) return;
Form.IsPerfectComboCheckbox.Opacity = 1;
Form.SaveReplayButton.Opacity = 1;
Form.IsPerfectComboCheckbox.IsEnabled = true;
Form.SaveReplayButton.IsEnabled = true;
Form.OpenReplayButton.IsEnabled = true;
}
}

0 comments on commit dd7f1f9

Please sign in to comment.