Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virindi Color Tool #85

Merged
merged 4 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ACViewer/ACViewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
<None Remove="Content\Content.mgcb" />
<None Remove="Content\Fonts\password.ttf" />
<None Remove="Icons\about.png" />
<None Remove="Icons\Armor.png" />
<None Remove="Icons\Checkmark_16x.png" />
<None Remove="Icons\export-file.png" />
<None Remove="Icons\help.png" />
<None Remove="Icons\HelpApplication_16x.png" />
<None Remove="Icons\OpenFile_16x.png" />
<None Remove="Icons\plume.png" />
<None Remove="Icons\portal.png" />
<None Remove="Icons\question-mark.png" />
<None Remove="Icons\Question_16x.png" />
Expand Down Expand Up @@ -60,11 +62,13 @@
<ItemGroup>
<Resource Include="Content\Fonts\password.ttf" />
<Resource Include="Icons\about.png" />
<Resource Include="Icons\armor.png" />
<Resource Include="Icons\Checkmark_16x.png" />
<Resource Include="Icons\export-file.png" />
<Resource Include="Icons\help.png" />
<Resource Include="Icons\HelpApplication_16x.png" />
<Resource Include="Icons\OpenFile_16x.png" />
<Resource Include="Icons\plume.png" />
<Resource Include="Icons\portal.png" />
<Resource Include="Icons\question-mark.png" />
<Resource Include="Icons\Question_16x.png" />
Expand All @@ -90,6 +94,9 @@
<None Update="Data\Locations.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Data\LootArmor.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<PropertyGroup>
Expand Down
1,798 changes: 1,798 additions & 0 deletions ACViewer/Data/LootArmor.txt

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions ACViewer/Data/LootArmorList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ACViewer.Data
{

public static class LootArmorList
{
public static Dictionary<uint, LootItem> Loot{ get; set; }

static LootArmorList()
{
Loot = new Dictionary<uint, LootItem>();
}

public static void Load()
{
var filename = @"Data\LootArmor.txt";

var lines = File.ReadAllLines(filename);

for (var i = 0; i < lines.Length; i++)
{
var line = lines[i];

// comment
if (line.StartsWith("#"))
continue;

var pieces = line.Split(',');

if (pieces.Length != 5)
{
Console.WriteLine($"LootArmor.Load({filename}): line {i + 1} length {pieces.Length}");
continue;
}

var wcid = pieces[0].Length > 0 ? Convert.ToUInt32(pieces[0]) : 0;
var name = pieces[1].Length > 0 ? pieces[1] : "";
var clothingBase = pieces[2].Length > 0 ? pieces[2].ToUpper() : "";
var palTemp = pieces[3].Length > 0 ? Convert.ToUInt32(pieces[3]) : 0;
var shade = pieces[4].Length > 0 ? Convert.ToSingle(pieces[4]) : 0;

var item = new LootItem(wcid);
item.Name = name;
item.ClothingBase = clothingBase;
item.PaletteTemplate = palTemp;
item.Shade = shade;

Loot.Add(wcid, item);
}
}

public static LootItem Get(uint wcid)
{
Loot.TryGetValue(wcid, out var lootItem);
return lootItem;
}
}
}
34 changes: 34 additions & 0 deletions ACViewer/Data/LootItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ACViewer.Data
{
public class LootItem : IEquatable<LootItem>
{
public uint WCID { get; set; }
public string Name { get; set; }
public string ClothingBase { get; set; }
public uint PaletteTemplate { get; set; }
public float Shade{ get; set; }

public LootItem() { }

public LootItem(uint wcid)
{
WCID = wcid;
}

public bool Equals(LootItem table)
{
return WCID.Equals(table.WCID);
}

public override int GetHashCode()
{
return WCID.GetHashCode();
}
}
}
Binary file added ACViewer/Icons/armor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ACViewer/Icons/plume.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions ACViewer/View/About.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ACViewer.View"
ShowInTaskbar="False"
mc:Ignorable="d"
Title="About" Height="170" Width="280" ResizeMode="NoResize" Icon="../Icons/Question_16x.png" Style="{DynamicResource CustomWindowStyle}">
<Grid>
Expand Down
3 changes: 3 additions & 0 deletions ACViewer/View/About.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public partial class About : Window
public About()
{
InitializeComponent();

this.Owner = App.Current.MainWindow;

DataContext = this;
}

Expand Down
36 changes: 36 additions & 0 deletions ACViewer/View/ArmorList.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Window x:Class="ACViewer.View.ArmorList"
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"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ACViewer.View"
mc:Ignorable="d"
WindowStartupLocation="CenterOwner"
ShowInTaskbar="False"
Icon="../Icons/armor.png"
Title="Search Armor..." Height="335" Width="350">
<Grid Margin="0,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="90" />
<RowDefinition Height=".1*" />
</Grid.RowDefinitions>
<Canvas Grid.Row="0">
<Label Content="Name:" HorizontalAlignment="Left" VerticalAlignment="Top" RenderTransformOrigin="0.5,1.173" Margin="19,10,0,0"/>
<TextBox Name="txtArmor" HorizontalAlignment="Left" Height="24" TextWrapping="Wrap" VerticalAlignment="Top" Width="257" Canvas.Left="63" Canvas.Top="12"/>
<Button Content="Close" HorizontalAlignment="Center" VerticalAlignment="Top" Width="75" RenderTransformOrigin="0.884,0.55" IsCancel="True" Canvas.Left="245" Canvas.Top="50"/>
</Canvas>
<DataGrid x:Name="dgArmorResults" Grid.Row="1">
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridCell}">
<EventSetter Event="MouseDoubleClick" Handler="DataGridCell_MouseDoubleClick"/>
</Style>
</DataGrid.Resources>

<DataGrid.Columns>
<DataGridTextColumn Header="WCID" Binding="{Binding Path=WCID}" IsReadOnly="True" Width="60"/>
<DataGridTextColumn Header="Name" Binding="{Binding Path=Name}" IsReadOnly="True" Width="1*"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>

</Grid>
</Window>
134 changes: 134 additions & 0 deletions ACViewer/View/ArmorList.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
using System;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

using ACViewer.Data;
using ACE.DatLoader;

namespace ACViewer.View
{
/// <summary>
/// Interaction logic for ArmorList.xaml
/// </summary>
public partial class ArmorList : Window
{
public ArmorList()
{
InitializeComponent();

this.Owner = App.Current.MainWindow;

txtArmor.TextChanged += new TextChangedEventHandler(txtArmor_TextChanged);
txtArmor.Focus();
}

private void txtArmor_TextChanged(object sender, TextChangedEventArgs e)
{
SearchArmor(txtArmor.Text.Trim());
}

private void SearchArmor(string criteria)
{
if (criteria != "")
{
dgArmorResults.Items.Clear();

criteria = criteria.ToLower();
var results = LootArmorList.Loot.Where(x => x.Value.Name.ToLower().Contains(criteria)).OrderBy(x => x.Key);
foreach (var s in results)
{
dgArmorResults.Items.Add(s.Value);
}
}
}

// Get the ClothingBase of the item and load it in the window
// - This should be so much easier, Optim hates WPF
// Ref https://wpfadventures.wordpress.com/2008/12/02/wpf-datagrid-detecting-clicked-cell-and-row/
private void DataGridCell_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (DatManager.PortalDat == null)
{
MessageBox.Show($"Please load the DATs before trying to view item.");
return;
}

DependencyObject dep = (DependencyObject)e.OriginalSource;

// iteratively traverse the visual tree
while ((dep != null) &&
!(dep is DataGridRow))
{
dep = VisualTreeHelper.GetParent(dep);
}

if (dep == null)
return;

DataGridRow row = dep as DataGridRow;
// find the object that is related to this row
object data = row.Item;

// extract the property value
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(data);
PropertyDescriptor cbProperty = properties["ClothingBase"];
string clothingBaseString = cbProperty.GetValue(data).ToString();

PropertyDescriptor wcidProperty = properties["WCID"];
uint wcid = Convert.ToUInt32(wcidProperty.GetValue(data));
var lootItem = LootArmorList.Get(wcid);

if (!uint.TryParse(lootItem.ClothingBase, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var clothingBase))
{
// input invalid -- throw error?
MessageBox.Show($"Invalid DID format: {lootItem.ClothingBase}");
return;
}


uint filetype = 0;

if (DatManager.PortalDat.AllFiles.TryGetValue(clothingBase, out var portalFile))
{
filetype = clothingBase >> 24;
var fileTypeSelect = FileExplorer.FileTypes.FirstOrDefault(i => i.ID == filetype);
if (fileTypeSelect == null)
{
Console.WriteLine($"Unknown filetype {clothingBase:X8} found in Portal Dat");
return;
}

var items = FileExplorer.Instance.FileType.Items;

foreach (var item in items)
{
if (item is Entity.FileType entityFileType && entityFileType.ID == filetype)
{
FileExplorer.Instance.FileType.SelectedItem = item;
var didStr = clothingBase.ToString("X8");
foreach (var file in FileExplorer.Instance.Files.Items)
{
if (file.ToString().Equals(didStr))
{
FileExplorer.Instance.Files.SelectedItem = file;
FileExplorer.Instance.Files.ScrollIntoView(file);

var clothing = DatManager.PortalDat.ReadFromDat<ACE.DatLoader.FileTypes.ClothingTable>(clothingBase);
ClothingTableList.Instance.OnClickClothingBase(clothing, clothingBase, lootItem.PaletteTemplate, lootItem.Shade);
this.Close();
}
}
break;
}

}
}
}

}
}
7 changes: 5 additions & 2 deletions ACViewer/View/ClothingTableList.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
</Grid.RowDefinitions>
<ListBox Name="SetupIds" Width="170" Margin="7.5,7.5,0,0" SelectionChanged="SetupIDs_OnClick" />
<ListBox Name="PaletteTemplates" Grid.Row="1" Width="170" Margin="7.5,7.5,0,0" SelectionChanged="PaletteTemplates_OnClick" />
<Slider Name="Shades" Grid.Row="2" Width="170" Margin="7.5,7.5,0,0" IsEnabled="False" ValueChanged="Shades_ValueChanged" SmallChange="1" IsSnapToTickEnabled="True" />
<Grid Grid.Row="2" Margin="7.5,7.5,0,0" Width="170">
<Slider Name="Shades" Width="170" IsEnabled="False" ValueChanged="Shades_ValueChanged" SmallChange="1" IsSnapToTickEnabled="True" />
<Label x:Name="lblShade" Content="Shade: 0.1234" HorizontalAlignment="Left" Margin="0,21,0,0" VerticalAlignment="Top" Width="145"/>
</Grid>
</Grid>
</UserControl>
</UserControl>
Loading