Skip to content

Commit

Permalink
Merge pull request #52 from KarlClinckspoor/SmallUIRevamp
Browse files Browse the repository at this point in the history
Small UI revamp
  • Loading branch information
KarlClinckspoor authored Mar 19, 2023
2 parents d03457c + 8421eb9 commit 8807d4c
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Reflection;
using System.Text.Json;
using NUnit.Framework;
using UWRandomizer;
using UWRandomizerWPF;
using UWRandomizerEditor;
using UWRandomizerEditor.LEVdotARK;
using UWRandomizerEditor.LEVdotARK.Blocks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Configuration;
using System.IO;
using NUnit.Framework;
using UWRandomizer;
using UWRandomizerWPF;
using UWRandomizerEditor.LEVdotARK;
using UWRandomizerEditor.LEVdotARK.Blocks;
using UWRandomizerEditor.LEVdotARK.GameObjects.Specifics;
Expand Down
2 changes: 1 addition & 1 deletion UWRandomizerUnitTests/Tools/TestWhatUltimateEditorFixes.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.IO;
using NUnit.Framework;
using UWRandomizer;
using UWRandomizerWPF;
using UWRandomizerEditor.LEVdotARK;
using UWRandomizerEditor.LEVdotARK.Blocks;
using UWRandomizerTools;
Expand Down
50 changes: 31 additions & 19 deletions UWRandomizerWPF/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Window x:Class="UWRandomizer.MainWindow"
<Window x:Class="UWRandomizerWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand All @@ -12,13 +12,13 @@
<RowDefinition Height="1*" />
<RowDefinition Height="8*" />
<RowDefinition Height="1*" />

</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>

<Grid Grid.Row="0" Grid.Column="0">
<Grid x:Name="HeaderGrid" Grid.ColumnSpan="2" Grid.Row="0" Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
Expand All @@ -29,39 +29,51 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<Label Grid.Column="0" Content="Path to lev.ark" VerticalContentAlignment="Center"
<Label Grid.Column="0" Content="Path to lev.ark" VerticalContentAlignment="Center"
HorizontalAlignment="Left" />
<TextBox Grid.Column="1" x:Name="TxtBox_PathToArk" TextWrapping="Wrap" Text=""
<TextBox Grid.Column="1" x:Name="TxtBoxPathToArk" TextWrapping="Wrap" Text=""
HorizontalContentAlignment="Stretch" MinWidth="250" MinHeight="10" />
<Button x:Name="Btn_Browse" Grid.Column="2" Content="Browse..." Click="Btn_Browse_Click" Margin="5" />
<Button x:Name="Btn_LoadLevArk" Grid.Column="3" Content="Load lev.ark" Click="Btn_LoadLevArk_Click"
<Button x:Name="BtnBrowse" Grid.Column="2" Content="Browse..." Click="Btn_Browse_Click" Margin="5" />
<Button x:Name="BtnLoadLevArk" Grid.Column="3" Content="Load lev.ark" Click="Btn_LoadLevArk_Click"
Margin="5" />
</Grid>


<GroupBox x:Name="GroupBox_Tools" Grid.Row="1" Header="Tools" Margin="0,10,0,0">
<StackPanel HorizontalAlignment="Left" x:Name="Stack_Tools" IsEnabled="False">
<Button x:Name="btn_BackupLevArk" Content="Backup lev.ark" HorizontalAlignment="Left"
<GroupBox x:Name="GroupBoxTools" Grid.Row="1" Grid.Column="0" Header="Tools" Margin="0,10,0,0">
<StackPanel HorizontalAlignment="Left" x:Name="StackTools" IsEnabled="False">
<Button x:Name="BtnBackupLevArk" Content="Backup lev.ark" HorizontalAlignment="Left"
VerticalAlignment="Center" Margin="5" Click="Btn_BackupLevArk_Click" />
<Button x:Name="btn_RestoreLevArk" Content="Restore lev.ark" HorizontalAlignment="Left"
<Button x:Name="BtnRestoreLevArk" Content="Restore lev.ark" HorizontalAlignment="Left"
VerticalAlignment="Center" Margin="5" Click="Btn_RestoreLevArk_Click" />
<Button x:Name="btn_RemoveAllLocks" Content="Remove all locks from doors" HorizontalAlignment="Left"
<Button x:Name="BtnRemoveAllLocks" Content="Remove all locks from doors" HorizontalAlignment="Left"
VerticalAlignment="Center" Margin="5" Click="Btn_RemoveAllLocks_Click" />
<Button x:Name="btn_ShuffleItems" Content="Shuffle items" HorizontalAlignment="Left"
<Button x:Name="BtnShuffleItems" Content="Shuffle items" HorizontalAlignment="Left"
VerticalAlignment="Center" Margin="5" Click="Btn_ShuffleItems_Click" />
<Button x:Name="btn_ExportSpoilerLog" Content="Export spoiler log" Margin="5"
<Button x:Name="BtnExportSpoilerLog" Content="Export spoiler log" Margin="5"
HorizontalAlignment="Left" Click="Btn_ExportSpoilerLog_Click" />
<GroupBox Header="Seed" Margin="5">
<StackPanel>
<TextBox x:Name="TxtBox_SeedValue" Text="42" Margin="5" />
<Button x:Name="Btn_SetSeed" Content="Set seed" Margin="5" Click="Btn_SetSeed_Click" />
<TextBox x:Name="TxtBoxSeedValue" Text="42" Margin="5" />
<Button x:Name="BtnSetSeed" Content="Set seed" Margin="5" Click="Btn_SetSeed_Click" />
</StackPanel>
</GroupBox>
</StackPanel>
</GroupBox>

<Button x:Name="Btn_SaveChanges" Grid.Row="2" Grid.Column="0" Content="Save changes" Margin="5"
Click="Btn_SaveChanges_Click" IsEnabled="False" />
<Grid x:Name="GridLog" Grid.Row="1" Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="10*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ListView Grid.Row="0" Grid.Column="0" x:Name="ListViewLog" Margin="5, 19, 5, 5" IsEnabled="True">
<ListViewItem Content="Welcome to the Ultima Underworld 1 randomizer. Please find LEV.ARK and load it."></ListViewItem>
</ListView>
<Button Grid.Row="1" Grid.Column="0" x:Name="BtnClearLog" Content="Clear Log" Margin="5, 0, 5, 0" Click="BtnClearLog_OnClick"/>

</Grid>

<Button x:Name="BtnSaveChanges" Grid.Row="2" Grid.ColumnSpan="2" Grid.Column="0" Content="Save changes" Margin="5"
Click="Btn_SaveChanges_Click" IsEnabled="False"/>


</Grid>
Expand Down
71 changes: 58 additions & 13 deletions UWRandomizerWPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
using System.Windows.Shapes;
using UWRandomizerEditor.LEVdotARK;
using UWRandomizerTools;
using Path = System.Windows.Shapes.Path;

namespace UWRandomizer;
namespace UWRandomizerWPF;

/// <summary>
/// Interaction logic for MainWindow.xaml
Expand All @@ -36,46 +37,69 @@ public MainWindow()

private void Btn_LoadLevArk_Click(object sender, RoutedEventArgs e)
{
ark = new ArkLoader(TxtBox_PathToArk.Text);
Stack_Tools.IsEnabled = true;
Btn_SaveChanges.IsEnabled = true;
AddMsgToLog($"Attempting to load lev.ark");
try
{
ark = new ArkLoader(TxtBoxPathToArk.Text);
StackTools.IsEnabled = true;
BtnSaveChanges.IsEnabled = true;
AddMsgToLog($"Loaded lev.ark");
}
catch (Exception exp)
{
AddMsgToLog($"Error when loading lev.ark. Exception: {exp}. Choose another file.");
}
}

private void Btn_SetSeed_Click(object sender, RoutedEventArgs e)
{
int.TryParse(TxtBox_SeedValue.Text, out int newSeed);
this.seed = newSeed;
Singletons.SeedRandomAndReset(seed);
AddMsgToLog($"Attempting to interpret {TxtBoxSeedValue.Text} as an integer to use as seed");
if (int.TryParse(TxtBoxSeedValue.Text, out var newSeed))
{
this.seed = newSeed;
Singletons.SeedRandomAndReset(seed);
AddMsgToLog($"Done replacing seed");
return;
}
AddMsgToLog($"Couldn't interpret {TxtBoxSeedValue.Text} as an integer");
}

private void Btn_ExportSpoilerLog_Click(object sender, RoutedEventArgs e)
{
string log = CreateSpoilerLog();
var openFileDlg = new Microsoft.Win32.OpenFileDialog();
bool? result = openFileDlg.ShowDialog();
var saveFileDialog = new Microsoft.Win32.SaveFileDialog();
bool? result = saveFileDialog.ShowDialog();

if (result == true)
{
File.WriteAllText(openFileDlg.FileName, log);
File.WriteAllText(saveFileDialog.FileName, log);
AddMsgToLog($"Saved spoiler log at {saveFileDialog.FileName}");
}
else
{
File.WriteAllText(log, "./UWspoilerlog.txt");
var tempname = "UWspoilerlog.txt";
File.WriteAllText(log, tempname);
AddMsgToLog($"Saved spoiler log to {System.IO.Path.Join(Directory.GetCurrentDirectory(), tempname)}");
}
}

private void Btn_ShuffleItems_Click(object sender, RoutedEventArgs e)
{
AddMsgToLog("In-level shuffling of items in all levels");
ShuffleItems.ShuffleAllLevels(ark, Singletons.RandomInstance, _itemSettings);
AddMsgToLog("Done. Check either UltimateUnderworldEditor or export the spoiler log if you want.");
}

private void Btn_RemoveAllLocks_Click(object sender, RoutedEventArgs e)
{
AddMsgToLog("Removing all locks from doors");
RandoTools.RemoveAllDoorReferencesToLocks(ark);
AddMsgToLog("Done");
}

private void Btn_BackupLevArk_Click(object sender, RoutedEventArgs e)
{
AddMsgToLog($"Saving LEV.ARK as LEV.ARK.BCK.");
var tempArk = new ArkLoader(ark.Path);
UWRandomizerEditor.Utils.StdSaveBuffer(tempArk, System.IO.Path.GetDirectoryName(tempArk.Path), "LEV.ARK.BCK");
}
Expand All @@ -86,23 +110,28 @@ private void Btn_Browse_Click(object sender, RoutedEventArgs e)
bool? result = openFileDlg.ShowDialog();
if (result == true)
{
TxtBox_PathToArk.Text = openFileDlg.FileName;
TxtBoxPathToArk.Text = openFileDlg.FileName;
AddMsgToLog($"Selected file {openFileDlg.FileName}");
}
}

private void Btn_SaveChanges_Click(object sender, RoutedEventArgs e)
{
AddMsgToLog("Attempting to save the current lev.ark over the old one.");
UWRandomizerEditor.Utils.StdSaveBuffer(ark, System.IO.Path.GetDirectoryName(ark.Path), "LEV.ARK");
AddMsgToLog("Save successful.");
}

private string CreateSpoilerLog()
{
var sb = new StringBuilder();
sb.AppendLine($"Spoiler log: lev.ark, seed {seed}");
AddMsgToLog("Creating spoiler log, 1-indexed.");
sb.AppendLine($"Spoiler log: lev.ark, seed {seed}. Entries are XY pos (starts from bottom left) and the number is the object ID.");
int level = 0; // 1 indexed
foreach (var block in ark.TileMapObjectsBlocks)
{
level++;
AddMsgToLog($"Processing level {level}");
sb.AppendLine($"Level {level}");

foreach (var tile in block.TileInfos)
Expand All @@ -117,6 +146,7 @@ private string CreateSpoilerLog()
}
}

AddMsgToLog("Done creating spoiler log string");
return sb.ToString();
}

Expand All @@ -125,9 +155,24 @@ private void Btn_RestoreLevArk_Click(object sender, RoutedEventArgs e)
string backupPath = System.IO.Path.Join(System.IO.Path.GetDirectoryName(ark.Path), "LEV.ARK.BCK");
if (File.Exists(backupPath))
{
AddMsgToLog($"Found backup file LEV.ARK.BCK at '{backupPath}', deleting current lev.ark");
File.Delete(ark.Path);
AddMsgToLog($"Renaming backup to LEV.ARK");
File.Copy(backupPath, ark.Path);
AddMsgToLog($"Reloading LEV.ARK");
ark = new ArkLoader(ark.Path);
return;
}
AddMsgToLog("Couldn't find backup file LEV.ARK.BCK. Didn't do anything");
}

private void AddMsgToLog(string message)
{
ListViewLog.Items.Add(new ListViewItem() {Content = message});
}

private void BtnClearLog_OnClick(object sender, RoutedEventArgs e)
{
ListViewLog.Items.Clear();
}
}
2 changes: 1 addition & 1 deletion UWRandomizerWPF/Singletons.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace UWRandomizer;
namespace UWRandomizerWPF;

public static class Singletons
{
Expand Down
5 changes: 4 additions & 1 deletion UWRandomizerWPF/UWRandomizerWPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<PackageVersion>0.1.0</PackageVersion>
<RootNamespace>UWRandomizer</RootNamespace>
<LangVersion>10</LangVersion>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 8807d4c

Please sign in to comment.