Skip to content

Commit

Permalink
Update 2.2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
KoraLyn committed Aug 9, 2020
2 parents ff287df + 2d71484 commit c28c751
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 16 deletions.
49 changes: 46 additions & 3 deletions FFXIV_TexTools/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
using xivModdingFramework.Cache;
using xivModdingFramework.General.Enums;
using xivModdingFramework.Helpers;
using xivModdingFramework.Items.Categories;
using xivModdingFramework.Items.Interfaces;
using xivModdingFramework.Mods.DataContainers;
using xivModdingFramework.Mods.FileTypes;
Expand Down Expand Up @@ -137,6 +138,9 @@ public MainWindow(string[] args)
// lines below, due to not having valid settings after Application.Shutdown() was already called.
if(_UPDATING)
{
// Shut down any other copies of TexTools that are active.
MainWindow.MakeHighlander();

if (Application.Current != null) {
Application.Current.Shutdown();
}
Expand Down Expand Up @@ -477,6 +481,43 @@ private void CheckForSettingsUpdate()
}
}

/// <summary>
/// There can only be one.
/// </summary>
public static void MakeHighlander()
{
try
{
List<Process> toKill = new List<Process>();
// Scan all processes for any processes with our name.
var self = Process.GetCurrentProcess();

Process[] processCollection = Process.GetProcesses();
foreach (Process p in processCollection)
{
if (p.ProcessName == self.ProcessName && p.Id != self.Id)
{
toKill.Add(p);
}
}

if (toKill.Count > 0)
{
FlexibleMessageBox.Show("More than one TexTools process detected. Shutting down other TexTools copies.", "Multi-Application Shutdown.", MessageBoxButtons.OK, MessageBoxIcon.Warning);

foreach (var p in toKill)
{
p.Kill();
}
}
}
catch
{
// If this fails because of some security issue on getting the process list or the like,
// just try to continue as normal.
}
}

private async void OnlyImport()
{
var gameDirectory = new DirectoryInfo(Settings.Default.FFXIV_Directory);
Expand Down Expand Up @@ -1168,9 +1209,11 @@ private async void Menu_ModConverter_Click(object sender, RoutedEventArgs e)
}

}
var list= new List<xivModdingFramework.Items.Interfaces.IItem>();
list.Add(ItemSelect.SelectedItem);
var modConverterView = new ModConverterView(list,ttmpFileName, ttmpData) { Owner = this,WindowStartupLocation=WindowStartupLocation.CenterOwner };
var gameDir = new DirectoryInfo(Settings.Default.FFXIV_Directory);
var lang = XivLanguages.GetXivLanguage(Settings.Default.Application_Language);
var gear = new Gear(gameDir, lang);
var gearList = await gear.GetGearList();
var modConverterView = new ModConverterView(gearList, ttmpFileName, ttmpData) { Owner = this,WindowStartupLocation=WindowStartupLocation.CenterOwner };
await progressController.CloseAsync();
modConverterView.ShowDialog();
}
Expand Down
4 changes: 2 additions & 2 deletions FFXIV_TexTools/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.2.0.0")]
[assembly: AssemblyFileVersion("2.2.0.0")]
[assembly: AssemblyVersion("2.2.0.1")]
[assembly: AssemblyFileVersion("2.2.0.1")]
2 changes: 1 addition & 1 deletion FFXIV_TexTools/Resources/UIStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion FFXIV_TexTools/Resources/UIStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
<value>Close</value>
</data>
<data name="Colors_Skins" xml:space="preserve">
<value>Colors &amp;amp; Skins</value>
<value>Colors &amp; Skins</value>
</data>
<data name="Count" xml:space="preserve">
<value>Count</value>
Expand Down
88 changes: 84 additions & 4 deletions FFXIV_TexTools/ViewModels/FullModelViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,6 @@ private async Task GetCharaSkinDictionary()
};

_charaRaceAndSkinDictionary = await character.GetRacesAndNumbersForTextures(xivChara);

FillSkeletonComboBox();
}

/// <summary>
Expand Down Expand Up @@ -509,9 +507,12 @@ private async Task UpdateSkeleton(XivRace selectedSkeleton)

Skins.Clear();

foreach (var skinNum in _charaRaceAndSkinDictionary[selectedSkeleton.GetSkinRace()])
if (_charaRaceAndSkinDictionary != null)
{
Skins.Add(skinNum);
foreach (var skinNum in _charaRaceAndSkinDictionary[selectedSkeleton.GetSkinRace()])
{
Skins.Add(skinNum);
}
}

// Disable changes while model and viewport update
Expand Down Expand Up @@ -552,6 +553,12 @@ private async Task UpdateSkin(TTModel ttModel, Dictionary<int, ModelTextureData>
ModelModifiers.FixUpSkinReferences(ttModel, SelectedSkeleton.XivRace, null, bodyReplacement);
await UpdateBodyTextures(ttModel, itemModel, textureData);
}

// Change the tail texture for Au Ra
if (itemModel.Name.Equals(XivStrings.Tail) && (SelectedSkeleton.XivRace == XivRace.AuRa_Female || SelectedSkeleton.XivRace == XivRace.AuRa_Male))
{
await UpdateTailTextures(ttModel, textureData);
}
}

/// <summary>
Expand All @@ -574,6 +581,12 @@ private async Task UpdateAllSkin()
ModelModifiers.FixUpSkinReferences(shownModel.TtModel, SelectedSkeleton.XivRace, null, bodyReplacement);
await UpdateBodyTextures(shownModel.TtModel, shownModel.ItemModel, shownModel.ModelTextureData);
}

// Change the tail texture for Au Ra
if (shownModel.ItemModel.Name.Equals(XivStrings.Tail) && (SelectedSkeleton.XivRace == XivRace.AuRa_Female || SelectedSkeleton.XivRace == XivRace.AuRa_Male))
{
await UpdateTailTextures(shownModel.TtModel, shownModel.ModelTextureData);
}
}

ViewPortVM.UpdateSkin(SelectedSkeleton.XivRace);
Expand Down Expand Up @@ -631,6 +644,20 @@ private string GetBodyNum(TTModel ttModel)
return string.Empty;
}

/// <summary>
/// Gets the tail number from the model
/// </summary>
/// <param name="ttModel">The TT model</param>
/// <returns>The body number</returns>
private string GetTailNum(TTModel ttModel)
{
var bodyRegex = new Regex("(t[0-9]{4})");

var result = bodyRegex.Match(ttModel.Materials[0]);

return result.Success ? result.Value : string.Empty;
}

/// <summary>
/// Gets the face number from the model
/// </summary>
Expand Down Expand Up @@ -666,6 +693,16 @@ private async Task UpdateBodyTextures(TTModel ttModel, IItemModel item, Dictiona
var newMaterial = ttModel.Materials[bodyMaterialIndex];
var currBodyNum = GetBodyNum(ttModel);
var newBodyNum = $"b{SelectedSkin.ToString().PadLeft(4, '0')}";
var newTailNum = string.Empty;

// Change the tail texture for Au Ra
if (item.Name.Equals(XivStrings.Tail) && (SelectedSkeleton.XivRace == XivRace.AuRa_Female || SelectedSkeleton.XivRace == XivRace.AuRa_Male))
{
var currTailNum = GetTailNum(ttModel);


newTailNum = SelectedSkin > 100 ? $"t010{currTailNum}" : $"t000{currTailNum}";
}

// Replace the body number with the selected one
if (!currBodyNum.Equals(newBodyNum))
Expand Down Expand Up @@ -722,6 +759,49 @@ private async Task UpdateBodyTextures(TTModel ttModel, IItemModel item, Dictiona
}
}

/// <summary>
/// Updates the tail textures for a given model
/// </summary>
/// <param name="ttModel">The model to update the body textures for</param>
/// <param name="item">The item associated with the model</param>
/// <param name="materialDictionary">The dictionary of materials for the current model</param>
private async Task UpdateTailTextures(TTModel ttModel, Dictionary<int, ModelTextureData> materialDictionary)
{
var _imc = new Imc(_gameDirectory);
var _mtrl = new Mtrl(_gameDirectory, IOUtil.GetDataFileFromPath(ttModel.Source), XivLanguage.None);
var _index = new Index(_gameDirectory);

// Determine which materials in the model need to be replaced
var currTailNum = GetTailNum(ttModel);
var newTailNum = SelectedSkin > 100 ? $"t010{currTailNum.Substring(4)}" : $"t000{currTailNum.Substring(4)}";
var newMaterial = ttModel.Materials[0].Replace(currTailNum, newTailNum);

// Temp MDL path so that races match when getting mtrl path
var tempMdlPath = ttModel.Source.Replace(currTailNum, newTailNum);

foreach (var meshGroup in ttModel.MeshGroups)
{
meshGroup.Material = newMaterial;
}

try
{
var mtrlVariant = 1;
materialDictionary[0].MaterialPath = newMaterial;

var mtrlPath = _mtrl.GetMtrlPath(tempMdlPath, newMaterial, mtrlVariant);
var mtrlOffset = await _index.GetDataOffset(mtrlPath);
var mtrl = await _mtrl.GetMtrlData(mtrlOffset, mtrlPath, 11);
var modelMaps = await ModelTexture.GetModelMaps(_gameDirectory, mtrl);

materialDictionary[0] = modelMaps;
}
catch (Exception ex)
{
throw new Exception(string.Format(UIMessages.UpdateBodyTextureError, ex.Message));
}
}

/// <summary>
/// Updates the face textures to the selected clan
/// </summary>
Expand Down
4 changes: 1 addition & 3 deletions FFXIV_TexTools/ViewModels/ModConverterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ModConverterViewModel((ModPackJson ModPackJson, Dictionary<string, Image>
LoadFromItemList();
}
public List<string> ItemTextList { get; set; }
public List<IItem> ItemList { get; set; }
public List<XivGear> ItemList { get; set; }
public ObservableCollection<string> FromItemList { get; private set; } = new ObservableCollection<string>();
public ObservableCollection<string> ConvertList { get; private set; } = new ObservableCollection<string>();
public ObservableCollection<AutoCompleteEntry> ToConverterItemList { get; set; } = new ObservableCollection<AutoCompleteEntry>();
Expand Down Expand Up @@ -105,8 +105,6 @@ private void AddToConvertList(object obj)
return;
if (!ItemList.Exists(it => it.Name == TargetItemName))
return;
if (obj == null)
return;
var jsons = GetModsJsonList(TTMPData.ModPackJson);
ModsJson fromItem=null;
foreach(var list in jsons)
Expand Down
3 changes: 2 additions & 1 deletion FFXIV_TexTools/Views/ModConverterView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Forms;
using xivModdingFramework.Items.DataContainers;
using xivModdingFramework.Items.Interfaces;
using xivModdingFramework.Mods.DataContainers;
using Image = SixLabors.ImageSharp.Image;
Expand All @@ -19,7 +20,7 @@ namespace FFXIV_TexTools.Views
public partial class ModConverterView
{
ProgressDialogController _progressController;
public ModConverterView(List<IItem> itemList,string ttmpPath, (ModPackJson ModPackJson, Dictionary<string, Image> ImageDictionary) ttmpData)
public ModConverterView(List<XivGear> itemList,string ttmpPath, (ModPackJson ModPackJson, Dictionary<string, Image> ImageDictionary) ttmpData)
{
var vm = new ModConverterViewModel(ttmpData);
vm.ItemList = itemList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public ImportWizardModPackControl(ModPackPageJson modPackPage, Dictionary<string
{
InitializeComponent();

MainWindow.MakeHighlander();

_imageDictionary = imageDictionary;

OptionsList.ItemsSource = new List<ModOptionJson>();
Expand Down
3 changes: 3 additions & 0 deletions FFXIV_TexTools/Views/ModPack/SimpleModPackImporter.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -149,6 +150,8 @@ private async void Initialize()

Dispatcher.Invoke(() =>
{
MainWindow.MakeHighlander();


// Resize columns to fit content
foreach (var column in GridViewCol.Columns)
Expand Down

0 comments on commit c28c751

Please sign in to comment.