Skip to content

Commit

Permalink
Removed Apply and Cancel buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
basilicon committed Sep 7, 2023
1 parent 4facb69 commit e25b29a
Show file tree
Hide file tree
Showing 19 changed files with 37 additions and 45 deletions.
Binary file modified .vs/ProjectEvaluation/smm2saveeditor.metadata.v7.bin
Binary file not shown.
Binary file modified .vs/ProjectEvaluation/smm2saveeditor.projects.v7.bin
Binary file not shown.
Binary file modified .vs/SMM2SaveEditor/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .vs/SMM2SaveEditor/v17/.futdcache.v2
Binary file not shown.
Binary file modified .vs/SMM2SaveEditor/v17/.suo
Binary file not shown.
12 changes: 6 additions & 6 deletions src/Level/Entities/Ground.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Kaitai;
using SMM2SaveEditor.Utility;
using Avalonia.Controls;
using System.Collections.Generic;
using Avalonia.Media.Imaging;

namespace SMM2SaveEditor.Entities
Expand Down Expand Up @@ -40,11 +39,7 @@ public void LoadFromStream(KaitaiStream io, Canvas? canvas = null)
id = io.ReadU1();
backgroundId = io.ReadU1();

Canvas.SetLeft(this, x * 160);
Canvas.SetBottom(this, y * 160);

sprite.Source = bitmap;
sprite.PointerPressed += (this as IEntity).OnClick;
UpdateSprite();
}

public byte[] GetBytes()
Expand All @@ -62,6 +57,11 @@ public byte[] GetBytes()
public void UpdateSprite()
{
// throw new System.NotImplementedException();
Canvas.SetLeft(this, x * 160);
Canvas.SetBottom(this, y * 160);

sprite.Source = bitmap;
sprite.PointerPressed += (this as IEntity).OnClick;
}
}
}
1 change: 1 addition & 0 deletions src/Level/Map.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public Map()
{
InitializeComponent();
myCanvas = this.Find<Canvas>("MapCanvas");
// myCanvas.PointerPressed += (this as IEntity).OnClick;
}

public void LoadFromStream(KaitaiStream io, Canvas? canvas = null)
Expand Down
16 changes: 3 additions & 13 deletions src/Utility/EditorHelpers/EntityEditor.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,7 @@
mc:Ignorable="d" d:DesignWidth="300" d:DesignHeight="500"
x:Class="SMM2SaveEditor.Utility.EditorHelpers.EntityEditor"
Background="DarkGray">
<DockPanel LastChildFill="False">
<Grid ColumnDefinitions="*,*" DockPanel.Dock="Bottom">
<Button Grid.Column="0" Name="Apply" HorizontalAlignment="Center">
<TextBlock Text="Apply" TextAlignment="Center"/>
</Button>
<Button Grid.Column="1" Name="Cancel" HorizontalAlignment="Center">
<TextBlock Text="Cancel" TextAlignment="Center"/>
</Button>
</Grid>
<ScrollViewer HorizontalScrollBarVisibility="Auto">
<Grid ColumnDefinitions="*,*" Name="EditorGrid" VerticalAlignment="Top"/>
</ScrollViewer>
</DockPanel>
<ScrollViewer HorizontalScrollBarVisibility="Auto">
<Grid ColumnDefinitions="*,*" Name="EditorGrid" VerticalAlignment="Top"/>
</ScrollViewer>
</UserControl>
25 changes: 7 additions & 18 deletions src/Utility/EditorHelpers/EntityEditor.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,16 @@ public partial class EntityEditor : UserControl
private List<string> labels;
private Grid grid;

private Button applyButton;
private Button cancelButton;

public EntityEditor()
{
Instance = this;
InitializeComponent();

grid = this.Find<Grid>("EditorGrid");
if (grid == null) throw new Exception("No grid found!");

applyButton = this.Find<Button>("Apply");
if (applyButton == null) throw new Exception("No apply button found!");

applyButton.Click += OnApply;

cancelButton = this.Find<Button>("Cancel");
if (cancelButton == null) throw new Exception("No cancel button found!");

cancelButton.Click += delegate
{
grid.Children.RemoveAll(grid.Children);
objRef = null;
};
}

private void OnApply(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
private void OnApply()
{
if (labels == null || objRef == null) return;

Expand Down Expand Up @@ -112,6 +95,7 @@ public void OpenOptions(Point p, IEntity entity)
{
EnumDropdown enumDropdown = new();
enumDropdown.SetEnum(type, kvp.Value);
enumDropdown.SelectionChanged += delegate { OnApply(); };

o = enumDropdown;
}
Expand All @@ -120,6 +104,8 @@ public void OpenOptions(Point p, IEntity entity)
{
FlagEditor flagEditor = new();
flagEditor.SetFlag((uint)kvp.Value);
flagEditor.ValueChanged += delegate { OnApply(); };

o = flagEditor;
}
else
Expand All @@ -128,13 +114,16 @@ public void OpenOptions(Point p, IEntity entity)
NumericUpDown numericUpDown = new();
numericUpDown.Increment = 1;
numericUpDown.Value = Convert.ToDecimal(kvp.Value);
numericUpDown.ValueChanged += delegate { OnApply(); };

o = numericUpDown;
}
else
{
TextBox valueBlock = new();
valueBlock.Text = kvp.Value.ToString();
valueBlock.TextInput += delegate { OnApply(); };

o = valueBlock;
}

Expand Down
11 changes: 9 additions & 2 deletions src/Utility/EditorHelpers/EnumDropdown.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@ public partial class EnumDropdown : UserControl

public object? enumValue;

public event EventHandler<SelectionChangedEventArgs> SelectionChanged;

public EnumDropdown()
{
InitializeComponent();

dropdown = this.Find<ComboBox>("Dropdown");
}

private void Dropdown_SelectionChanged(object? sender, SelectionChangedEventArgs e)
{
SelectionChanged.Invoke(sender, e);
}

public void SetEnum<T>(T defaultValue) where T : Enum
{
SetEnum(typeof(T), defaultValue);
Expand All @@ -35,11 +42,11 @@ public void SetEnum(Type T, object? defaultValue = null)
dropdown.Items.Add(item);
}

dropdown.SelectionChanged += delegate
dropdown.SelectionChanged += (sender, e) =>
{
if (dropdown.SelectedValue is ComboBoxItem item) {
enumValue = Enum.Parse(T, item.Content.ToString());
Debug.WriteLine($"New value: {enumValue}");
SelectionChanged.Invoke(sender, e);
}
};

Expand Down
17 changes: 11 additions & 6 deletions src/Utility/EditorHelpers/FlagEditor.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Avalonia.Controls;
using System.Diagnostics;
using System.Collections.Generic;
using System;

namespace SMM2SaveEditor.Utility.EditorHelpers
{
Expand All @@ -15,10 +16,13 @@ public partial class FlagEditor : UserControl
List<CheckBox> checkedList = new();

TextBox textBox;
Button button;
Button toggleExpandButton;

bool bIsExpanded = false;

public delegate void FlagEditorValueChangedHandler(object sender);
public event FlagEditorValueChangedHandler ValueChanged;

public FlagEditor()
{
InitializeComponent();
Expand All @@ -37,8 +41,8 @@ public FlagEditor()
grid = new();
SetupGrid();

button = this.Find<Button>("ToggleExpand");
button.Click += Button_Click;
toggleExpandButton = this.Find<Button>("ToggleExpand");
toggleExpandButton.Click += Button_Click;
}

public void SetFlag(uint newFlag)
Expand All @@ -54,13 +58,13 @@ private void Button_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs
{
textBox.Text = flag.ToString("X");
contentControl.Content = textBox;
button.Content = "Expand";
toggleExpandButton.Content = "Expand";
}
else
{
UpdateGrid();
contentControl.Content = scrollViewer;
button.Content = "Minimize";
toggleExpandButton.Content = "Minimize";
}

bIsExpanded ^= true;
Expand All @@ -76,6 +80,7 @@ private void TextBox_TextChanged(object? sender, TextChangedEventArgs e)
try
{
flag = uint.Parse(textBox.Text, System.Globalization.NumberStyles.AllowHexSpecifier);
ValueChanged.Invoke(this);
}
catch
{
Expand All @@ -100,7 +105,7 @@ private void SetupGrid()
Grid.SetRow(checkBox, i);

uint copy = counter;
checkBox.Click += delegate { flag ^= copy; };
checkBox.Click += delegate { flag ^= copy; ValueChanged.Invoke(this); };

counter <<= 1;
}
Expand Down

0 comments on commit e25b29a

Please sign in to comment.