Skip to content

Commit 080fedb

Browse files
authored
Multiple UI changes, bug fixes (#164)
* working dedicated window for hex viewer * separate view for dat objects, confirmation of deletion * remove redundant confirmation box * fix crash when loading buggy scenarios/saves * move some data templates to application * rework cargo categories in the ui to be more user friendly * disable object viewer for now
1 parent c581d7d commit 080fedb

30 files changed

+1050
-665
lines changed

Dat/ObjectIndex.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,5 +164,8 @@ public record ObjectIndexEntry(
164164
uint32_t DatChecksum,
165165
ObjectType ObjectType,
166166
ObjectSource ObjectSource,
167-
VehicleType? VehicleType = null);
167+
VehicleType? VehicleType = null)
168+
{
169+
public string SimpleText => $"{DatName} | {Filename}";
170+
}
168171
}

Dat/Objects/Vehicle/VehicleObject.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@ public ReadOnlySpan<byte> Load(ReadOnlySpan<byte> remainingData)
166166
var ptr = BitConverter.ToUInt16(remainingData[0..2]);
167167
while (ptr != (uint16_t)CargoCategory.NULL)
168168
{
169-
var vehicleCargoCategory = (CargoCategory)BitConverter.ToUInt16(remainingData[0..2]);
169+
var cargoCategory = (CargoCategory)BitConverter.ToUInt16(remainingData[0..2]);
170170
remainingData = remainingData[2..]; // uint16_t
171171

172172
var cargoTypeSpriteOffset = remainingData[0];
173173
remainingData = remainingData[1..]; // uint8_t
174174

175-
CompatibleCargoCategories[index].Add(vehicleCargoCategory);
175+
CompatibleCargoCategories[index].Add(cargoCategory);
176176

177-
if (!CargoTypeSpriteOffsets.TryAdd(vehicleCargoCategory, cargoTypeSpriteOffset))
177+
if (!CargoTypeSpriteOffsets.TryAdd(cargoCategory, cargoTypeSpriteOffset))
178178
{
179179
// invalid object - shouldn't have 2 cargo types that are the same
180180
}
@@ -261,12 +261,15 @@ public ReadOnlySpan<byte> Save()
261261
// cargo types
262262
for (var i = 0; i < CompatibleCargoTypesLength; ++i) // CompatibleCargoTypesLength should == CompatibleCargoCategories.Length
263263
{
264-
ms.WriteByte(MaxCargo[i]);
265-
266-
if (MaxCargo[i] == 0)
264+
if (MaxCargo.Count < i)
267265
{
266+
ms.WriteByte(0); // write a 0 for MaxCargo - this indicates no more cargo and we skip the rest
268267
continue;
269268
}
269+
else
270+
{
271+
ms.WriteByte(MaxCargo[i]);
272+
}
270273

271274
foreach (var cc in CompatibleCargoCategories[i])
272275
{

Gui/App.axaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,37 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:materialIcons="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
55
xmlns:local="using:OpenLoco.Gui"
6+
xmlns:vm="using:OpenLoco.Gui.ViewModels"
7+
xmlns:vi="using:OpenLoco.Gui.Views"
8+
xmlns:oldt="using:OpenLoco.Dat.Types"
9+
xmlns:pgc="clr-namespace:Avalonia.PropertyGrid.Controls;assembly=Avalonia.PropertyGrid"
610
x:Class="OpenLoco.Gui.App"
711
RequestedThemeVariant="Default">
812
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
913

1014
<Application.DataTemplates>
1115
<local:ViewLocator/>
16+
<DataTemplate DataType="vm:S5HeaderViewModel">
17+
<pgc:PropertyGrid x:Name="propertyGrid_S5HeaderVm" DataContext="{Binding}" Margin="2" ShowTitle="False" AllowFilter="False" AllowQuickFilter="False" ShowStyle="Tiled"></pgc:PropertyGrid>
18+
</DataTemplate>
19+
<DataTemplate DataType="vm:ObjectHeaderViewModel">
20+
<pgc:PropertyGrid x:Name="propertyGrid_ObjectHeaderVm" DataContext="{Binding}" Margin="2" ShowTitle="False" AllowFilter="False" AllowQuickFilter="False" ShowStyle="Tiled"></pgc:PropertyGrid>
21+
</DataTemplate>
22+
<DataTemplate DataType="oldt:S5Header">
23+
<pgc:PropertyGrid x:Name="propertyGrid_S5Header" DataContext="{Binding}" Margin="2" ShowTitle="False" AllowFilter="False" AllowQuickFilter="False" ShowStyle="Tiled"></pgc:PropertyGrid>
24+
</DataTemplate>
25+
<DataTemplate DataType="oldt:ObjectHeader">
26+
<pgc:PropertyGrid x:Name="propertyGrid_ObjectHeader" DataContext="{Binding}" Margin="2" ShowTitle="False" AllowFilter="False" AllowQuickFilter="False" ShowStyle="Tiled"></pgc:PropertyGrid>
27+
</DataTemplate>
28+
<DataTemplate DataType="vm:SCV5ViewModel">
29+
<vi:SCV5View />
30+
</DataTemplate>
31+
<DataTemplate DataType="vm:ImageTableViewModel">
32+
<vi:ImageTableView />
33+
</DataTemplate>
34+
<DataTemplate DataType="vm:DatObjectEditorViewModel">
35+
<vi:DatObjectEditorView />
36+
</DataTemplate>
1237
</Application.DataTemplates>
1338

1439
<Application.Styles>

Gui/Gui.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<PackageReference Include="bodong.Avalonia.PropertyGrid" Version="11.1.4.2" />
5252
<PackageReference Include="bodong.PropertyModels" Version="11.1.4.2" />
5353
<PackageReference Include="Material.Icons.Avalonia" Version="2.1.10" />
54+
<PackageReference Include="MessageBox.Avalonia" Version="3.2.0" />
5455
<PackageReference Include="NAudio" Version="2.2.1" />
5556
<PackageReference Include="ReactiveUI.Fody" Version="19.5.41" />
5657
<PackageReference Include="ReactiveUI.Validation" Version="4.1.1" />
@@ -62,4 +63,10 @@
6263
<ProjectReference Include="..\Common\Common.csproj" />
6364
<ProjectReference Include="..\Definitions\Definitions.csproj" />
6465
</ItemGroup>
66+
67+
<ItemGroup>
68+
<Compile Update="Views\DatObjectEditorView.axaml.cs">
69+
<DependentUpon>DatObjectEditorView.axaml</DependentUpon>
70+
</Compile>
71+
</ItemGroup>
6572
</Project>

Gui/PlatformSpecific.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Avalonia;
22
using Avalonia.Controls.ApplicationLifetimes;
33
using Avalonia.Platform.Storage;
4+
using OpenLoco.Common.Logging;
45
using System;
56
using System.Collections.Generic;
67
using System.Diagnostics;
@@ -12,7 +13,19 @@ namespace OpenLoco.Gui
1213
{
1314
public static class PlatformSpecific
1415
{
15-
public static void FolderOpenInDesktop(string directory)
16+
public static void FolderOpenInDesktop(string directory, ILogger logger)
17+
{
18+
try
19+
{
20+
FolderOpenInDesktopCore(directory);
21+
}
22+
catch (Exception ex)
23+
{
24+
logger.Error(ex);
25+
}
26+
}
27+
28+
public static void FolderOpenInDesktopCore(string directory)
1629
{
1730
if (!Directory.Exists(directory))
1831
{
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using MsBox.Avalonia;
2+
using MsBox.Avalonia.Enums;
3+
using OpenLoco.Common.Logging;
4+
using OpenLoco.Gui.Models;
5+
using ReactiveUI;
6+
using ReactiveUI.Fody.Helpers;
7+
using System.Reactive;
8+
using System.Threading.Tasks;
9+
10+
namespace OpenLoco.Gui.ViewModels
11+
{
12+
public abstract class BaseLocoFileViewModel : ReactiveObject, ILocoFileViewModel
13+
{
14+
protected BaseLocoFileViewModel(FileSystemItem currentFile, ObjectEditorModel model)
15+
{
16+
CurrentFile = currentFile;
17+
Model = model;
18+
19+
ReloadCommand = ReactiveCommand.Create(Load);
20+
SaveCommand = ReactiveCommand.Create(Save);
21+
SaveAsCommand = ReactiveCommand.Create(SaveAs);
22+
DeleteLocalFileCommand = ReactiveCommand.CreateFromTask(DeleteWrapper);
23+
}
24+
25+
[Reactive]
26+
public FileSystemItem CurrentFile { get; init; }
27+
public ObjectEditorModel Model { get; init; }
28+
29+
protected ILogger logger => Model.Logger;
30+
31+
public ReactiveCommand<Unit, Unit> ReloadCommand { get; init; }
32+
public ReactiveCommand<Unit, Unit> SaveCommand { get; init; }
33+
public ReactiveCommand<Unit, Unit> SaveAsCommand { get; init; }
34+
public ReactiveCommand<Unit, Unit> DeleteLocalFileCommand { get; init; }
35+
36+
public abstract void Load();
37+
public abstract void Save();
38+
public abstract void SaveAs();
39+
40+
async Task DeleteWrapper()
41+
{
42+
var box = MessageBoxManager
43+
.GetMessageBoxStandard("Confirm Delete", "Are you sure you would like to delete?", ButtonEnum.YesNo);
44+
var result = await box.ShowAsync();
45+
46+
if (result == ButtonResult.Yes)
47+
{
48+
Delete();
49+
}
50+
}
51+
52+
public virtual void Delete() { }
53+
54+
public string ReloadText => CurrentFile.FileLocation == FileLocation.Local ? "Reload" : "Redownload";
55+
public string SaveText => CurrentFile.FileLocation == FileLocation.Local ? "Save" : "Download";
56+
public string SaveAsText => $"{SaveText} As";
57+
public string DeleteLocalFileText => "Delete File";
58+
59+
public string ReloadIcon => CurrentFile.FileLocation == FileLocation.Local ? "DatabaseRefresh" : "FileSync";
60+
public string SaveIcon => CurrentFile.FileLocation == FileLocation.Local ? "ContentSave" : "FileDownload";
61+
public string SaveAsIcon => CurrentFile.FileLocation == FileLocation.Local ? "ContentSavePlus" : "FileDownloadOutline";
62+
public string DeleteLocalFileIcon => "DeleteForever";
63+
}
64+
}

0 commit comments

Comments
 (0)