mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-02 04:39:14 +01:00
compile bindings for texture base window
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
<Window xmlns="https://github.com/avaloniaui"
|
<Window xmlns="https://github.com/avaloniaui"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:starterNg="clr-namespace:StarterNG"
|
xmlns:starterNg="clr-namespace:StarterNG"
|
||||||
|
xmlns:views="clr-namespace:StarterNG.Views"
|
||||||
x:Class="StarterNG.Views.TextureBaseWindow"
|
x:Class="StarterNG.Views.TextureBaseWindow"
|
||||||
x:CompileBindings="False"
|
x:CompileBindings="True"
|
||||||
Title="{Binding [TextureBaseTitle], Source={x:Static starterNg:App.Loc}}"
|
Title="{Binding [TextureBaseTitle], Source={x:Static starterNg:App.Loc}}"
|
||||||
Width="980" Height="560"
|
Width="980" Height="560"
|
||||||
WindowStartupLocation="CenterOwner"
|
WindowStartupLocation="CenterOwner"
|
||||||
@@ -43,7 +44,7 @@
|
|||||||
Background="Transparent" ResizeDirection="Rows" />
|
Background="Transparent" ResizeDirection="Rows" />
|
||||||
<ListBox Name="modelList" Grid.Row="2" Classes="Compact">
|
<ListBox Name="modelList" Grid.Row="2" Classes="Compact">
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate x:DataType="views:TextureModelRow">
|
||||||
<Grid ColumnDefinitions="28,90,*" ColumnSpacing="4">
|
<Grid ColumnDefinitions="28,90,*" ColumnSpacing="4">
|
||||||
<TextBlock Grid.Column="0" Text="{Binding No}" Opacity="0.6" />
|
<TextBlock Grid.Column="0" Text="{Binding No}" Opacity="0.6" />
|
||||||
<TextBlock Grid.Column="1" Text="{Binding Klasa}" TextTrimming="CharacterEllipsis" />
|
<TextBlock Grid.Column="1" Text="{Binding Klasa}" TextTrimming="CharacterEllipsis" />
|
||||||
@@ -60,7 +61,7 @@
|
|||||||
|
|
||||||
<ListBox Name="textureList" DoubleTapped="TextureList_OnDoubleTapped">
|
<ListBox Name="textureList" DoubleTapped="TextureList_OnDoubleTapped">
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate x:DataType="views:TextureRow">
|
||||||
<Grid ColumnDefinitions="1.4*,0.9*,1.2*,90,*" ColumnSpacing="8">
|
<Grid ColumnDefinitions="1.4*,0.9*,1.2*,90,*" ColumnSpacing="8">
|
||||||
<TextBlock Grid.Column="0" Text="{Binding Skin}" TextTrimming="CharacterEllipsis" />
|
<TextBlock Grid.Column="0" Text="{Binding Skin}" TextTrimming="CharacterEllipsis" />
|
||||||
<TextBlock Grid.Column="1" Text="{Binding Mini}" Opacity="0.85" TextTrimming="CharacterEllipsis" />
|
<TextBlock Grid.Column="1" Text="{Binding Mini}" Opacity="0.85" TextTrimming="CharacterEllipsis" />
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace StarterNG.Views;
|
|||||||
public partial class TextureBaseWindow : Window
|
public partial class TextureBaseWindow : Window
|
||||||
{
|
{
|
||||||
private readonly VehicleDatabase _db = GameData.Instance.Vehicles;
|
private readonly VehicleDatabase _db = GameData.Instance.Vehicles;
|
||||||
private readonly List<Row> _all = new();
|
private readonly List<TextureRow> _all = new();
|
||||||
|
|
||||||
public VehicleTexture? Picked { get; private set; }
|
public VehicleTexture? Picked { get; private set; }
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ public partial class TextureBaseWindow : Window
|
|||||||
foreach (var t in _db.Textures)
|
foreach (var t in _db.Textures)
|
||||||
{
|
{
|
||||||
if (_db.IsSetFollower(t)) continue;
|
if (_db.IsSetFollower(t)) continue;
|
||||||
_all.Add(new Row(t, _db));
|
_all.Add(new TextureRow(t, _db));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var box in new Control[] { fName, fOp, fMini, fAuthor, fStation, fPhoto, fModel })
|
foreach (var box in new Control[] { fName, fOp, fMini, fAuthor, fStation, fPhoto, fModel })
|
||||||
@@ -51,8 +51,6 @@ public partial class TextureBaseWindow : Window
|
|||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
private sealed record ModelRow(string No, string Klasa, string Sciezka);
|
|
||||||
|
|
||||||
private void BuildModelList()
|
private void BuildModelList()
|
||||||
{
|
{
|
||||||
modelList.ItemsSource = null;
|
modelList.ItemsSource = null;
|
||||||
@@ -63,7 +61,7 @@ public partial class TextureBaseWindow : Window
|
|||||||
.Where(r => r.Mini.Length > 0)
|
.Where(r => r.Mini.Length > 0)
|
||||||
.GroupBy(r => r.Mini, StringComparer.OrdinalIgnoreCase)
|
.GroupBy(r => r.Mini, StringComparer.OrdinalIgnoreCase)
|
||||||
.OrderBy(g => g.Key, StringComparer.OrdinalIgnoreCase)
|
.OrderBy(g => g.Key, StringComparer.OrdinalIgnoreCase)
|
||||||
.Select((g, i) => new ModelRow($"{i + 1}.", g.Key, g.First().Directory))
|
.Select((g, i) => new TextureModelRow($"{i + 1}.", g.Key, g.First().Directory))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
modelList.ItemsSource = rows;
|
modelList.ItemsSource = rows;
|
||||||
@@ -89,7 +87,7 @@ public partial class TextureBaseWindow : Window
|
|||||||
|
|
||||||
private void Refresh()
|
private void Refresh()
|
||||||
{
|
{
|
||||||
IEnumerable<Row> q = _all;
|
IEnumerable<TextureRow> q = _all;
|
||||||
|
|
||||||
q = Filter(q, fNameOn, fName, r => r.Skin);
|
q = Filter(q, fNameOn, fName, r => r.Skin);
|
||||||
q = Filter(q, fOpOn, fOp, r => r.Operator);
|
q = Filter(q, fOpOn, fOp, r => r.Operator);
|
||||||
@@ -102,7 +100,7 @@ public partial class TextureBaseWindow : Window
|
|||||||
if ((typeList.SelectedItem as ListBoxItem)?.Tag is string cat)
|
if ((typeList.SelectedItem as ListBoxItem)?.Tag is string cat)
|
||||||
q = q.Where(r => string.Equals(r.Category, cat, StringComparison.OrdinalIgnoreCase));
|
q = q.Where(r => string.Equals(r.Category, cat, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
if (modelList.SelectedItem is ModelRow mr)
|
if (modelList.SelectedItem is TextureModelRow mr)
|
||||||
q = q.Where(r => string.Equals(r.Mini, mr.Klasa, StringComparison.OrdinalIgnoreCase));
|
q = q.Where(r => string.Equals(r.Mini, mr.Klasa, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
if (fRevFromOn.IsChecked == true && ParseDate(fRevFrom.Text) is { } from)
|
if (fRevFromOn.IsChecked == true && ParseDate(fRevFrom.Text) is { } from)
|
||||||
@@ -120,8 +118,8 @@ public partial class TextureBaseWindow : Window
|
|||||||
statusText.Text = $"{list.Count} / {_all.Count}";
|
statusText.Text = $"{list.Count} / {_all.Count}";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IEnumerable<Row> Filter(
|
private static IEnumerable<TextureRow> Filter(
|
||||||
IEnumerable<Row> src, CheckBox? on, TextBox? box, Func<Row, string> field)
|
IEnumerable<TextureRow> src, CheckBox? on, TextBox? box, Func<TextureRow, string> field)
|
||||||
{
|
{
|
||||||
if (on?.IsChecked != true) return src;
|
if (on?.IsChecked != true) return src;
|
||||||
string needle = box?.Text?.Trim() ?? "";
|
string needle = box?.Text?.Trim() ?? "";
|
||||||
@@ -131,14 +129,14 @@ public partial class TextureBaseWindow : Window
|
|||||||
|
|
||||||
private void TextureList_OnDoubleTapped(object? sender, TappedEventArgs e)
|
private void TextureList_OnDoubleTapped(object? sender, TappedEventArgs e)
|
||||||
{
|
{
|
||||||
if (textureList.SelectedItem is not Row row) return;
|
if (textureList.SelectedItem is not TextureRow row) return;
|
||||||
Picked = row.Texture;
|
Picked = row.Texture;
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TextureList_OnContextRequested(object? sender, ContextRequestedEventArgs e)
|
private void TextureList_OnContextRequested(object? sender, ContextRequestedEventArgs e)
|
||||||
{
|
{
|
||||||
if (textureList.SelectedItem is not Row row) return;
|
if (textureList.SelectedItem is not TextureRow row) return;
|
||||||
|
|
||||||
var menu = new ContextMenu();
|
var menu = new ContextMenu();
|
||||||
var copy = new MenuItem { Header = App.Loc["CopyTextureName"] };
|
var copy = new MenuItem { Header = App.Loc["CopyTextureName"] };
|
||||||
@@ -176,37 +174,40 @@ public partial class TextureBaseWindow : Window
|
|||||||
menu.Open(textureList);
|
menu.Open(textureList);
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private sealed class Row
|
internal sealed record TextureModelRow(string No, string Klasa, string Sciezka);
|
||||||
|
|
||||||
|
internal sealed class TextureRow
|
||||||
|
{
|
||||||
|
public VehicleTexture Texture { get; }
|
||||||
|
public string Skin { get; }
|
||||||
|
public string Mini { get; }
|
||||||
|
public string Operator { get; }
|
||||||
|
public string Revision { get; }
|
||||||
|
public string Author { get; }
|
||||||
|
public string Station { get; }
|
||||||
|
public string Photo { get; }
|
||||||
|
public string Model { get; }
|
||||||
|
public string Category { get; }
|
||||||
|
public string Directory { get; }
|
||||||
|
public DateTime? RevisionDate { get; }
|
||||||
|
|
||||||
|
public TextureRow(VehicleTexture t, VehicleDatabase db)
|
||||||
{
|
{
|
||||||
public VehicleTexture Texture { get; }
|
Texture = t;
|
||||||
public string Skin { get; }
|
Skin = Path.GetFileNameWithoutExtension(t.Skinfile);
|
||||||
public string Mini { get; }
|
Mini = db.ResolveMiniName(t) ?? t.ResolvedClass ?? "";
|
||||||
public string Operator { get; }
|
Operator = t.Meta?.Operator ?? "";
|
||||||
public string Revision { get; }
|
Revision = t.Meta?.RevisionDate ?? "";
|
||||||
public string Author { get; }
|
Author = t.Meta?.TextureAuthor ?? "";
|
||||||
public string Station { get; }
|
Station = t.Meta?.Depot ?? "";
|
||||||
public string Photo { get; }
|
Photo = t.Meta?.PhotoAuthor ?? "";
|
||||||
public string Model { get; }
|
Model = t.Model ?? "";
|
||||||
public string Category { get; }
|
Category = t.ResolvedCategory ?? "";
|
||||||
public string Directory { get; }
|
Directory = t.Directory ?? "";
|
||||||
public DateTime? RevisionDate { get; }
|
RevisionDate = DateTime.TryParse(Revision, System.Globalization.CultureInfo.InvariantCulture,
|
||||||
|
System.Globalization.DateTimeStyles.None, out var rev) ? rev : null;
|
||||||
public Row(VehicleTexture t, VehicleDatabase db)
|
|
||||||
{
|
|
||||||
Texture = t;
|
|
||||||
Skin = Path.GetFileNameWithoutExtension(t.Skinfile);
|
|
||||||
Mini = db.ResolveMiniName(t) ?? t.ResolvedClass ?? "";
|
|
||||||
Operator = t.Meta?.Operator ?? "";
|
|
||||||
Revision = t.Meta?.RevisionDate ?? "";
|
|
||||||
Author = t.Meta?.TextureAuthor ?? "";
|
|
||||||
Station = t.Meta?.Depot ?? "";
|
|
||||||
Photo = t.Meta?.PhotoAuthor ?? "";
|
|
||||||
Model = t.Model ?? "";
|
|
||||||
Category = t.ResolvedCategory ?? "";
|
|
||||||
Directory = t.Directory ?? "";
|
|
||||||
RevisionDate = DateTime.TryParse(Revision, System.Globalization.CultureInfo.InvariantCulture,
|
|
||||||
System.Globalization.DateTimeStyles.None, out var rev) ? rev : null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user