Skip to content

Commit

Permalink
DATA PAGE - Override states edit
Browse files Browse the repository at this point in the history
  • Loading branch information
PhantornRU committed Sep 25, 2024
1 parent 5360560 commit f27ae3f
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 20 deletions.
11 changes: 11 additions & 0 deletions Helpers/FilesSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,16 @@ public static List<string> GetDirectoriesWithoutOrigPath(string path, string sea

#endregion Directory


#region Path
public static string GetExportConfigPath(string configFileName, string fullpath)
{
string fullpathPart = fullpath.Replace(EnvironmentController.lastImportPath, "");
string configName = configFileName.Replace(EnvironmentController.configFormat, "");
string exportPath = $"{EnvironmentController.lastExportPath}\\{configName}\\{fullpathPart}";
return exportPath;
}

#endregion Path
}
}
41 changes: 35 additions & 6 deletions Processors/DMIStatesProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Windows.Media.Imaging;
using SixLabors.ImageSharp.Processing;
using AdaptiveSpritesDMItool.Resources;
using AdaptiveSpritesDMItool.Helpers;

namespace AdaptiveSpritesDMItool.Processors
{
Expand Down Expand Up @@ -105,7 +106,7 @@ public static void ProcessFileWithConfig(IProgress<int> progress, ConfigItem con
{
iter++;
progress?.Report(iter);
ProcessStateWithConfig(state, config, dataPixelStorage);
ProcessStateWithConfig(state, config, dataPixelStorage, path);
//Thread.Sleep(200);
}

Expand Down Expand Up @@ -135,6 +136,12 @@ public static void ProcessFileWithConfig(IProgress<int> progress, ConfigItem con
}

Debug.WriteLine($"[{iter}/{maxIter}] NOT SAVED {fileExportPath}");
foreach (DMIState state in file.States)
{
iter++;
iter += state.TotalFrames;
//Thread.Sleep(200);
}
}

#endregion Processors
Expand All @@ -143,12 +150,34 @@ public static void ProcessFileWithConfig(IProgress<int> progress, ConfigItem con
#region Draw


private static void ProcessStateWithConfig(DMIState state, ConfigItem config, DataPixelStorage dataPixelStorage)
private static void ProcessStateWithConfig(DMIState state, ConfigItem config, DataPixelStorage dataPixelStorage, string path)
{
// TODO: Checking that this state is already in the processed file
//if (!StatesController.isOverrideToggle)
// if (state.Name == state.Name)
// return;

if (!(state.Name == "vox1" || state.Name == "vox2" || state.Name == "vox3"))
{
return;
}

if (!StatesController.isOverrideToggle)
{
string exportPath = FilesSearcher.GetExportConfigPath(config.FileName, path);
//Debug.WriteLine($"PROCESS {exportPath} \n\t--- {path}");
if (File.Exists(exportPath) == false)
{
EditStateWithConfig(state, config, dataPixelStorage);
return;
}

DMIFile exportedDMIFile = new DMIFile(exportPath);
foreach (DMIState exportedState in exportedDMIFile.States)
{
if (state.Name == exportedState.Name)
{
iter += state.TotalFrames;
return;
}
}
}
EditStateWithConfig(state, config, dataPixelStorage);
}

Expand Down
4 changes: 4 additions & 0 deletions Resources/DataPixelStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ private void FillDataSimilarPoints(int width, int height)
public Point GetPointStorage(StateDirection direction, Point point)
{
var storagePoint = ConvertToStoragePoint(point);
storagePoint.x = Math.Max(storagePoint.x, 0);
storagePoint.y = Math.Max(storagePoint.y, 0);
return ConvertFromStoragePoint(pixelStorages[direction][storagePoint]);
}

public (int x, int y) GetPointStorage(StateDirection direction, (int x, int y) point)
{
point.x = Math.Max(point.x, 0);
point.y = Math.Max(point.y, 0);
return pixelStorages[direction][point];
}

Expand Down
81 changes: 71 additions & 10 deletions Views/Pages/DataPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ public partial class DataPage : INavigableView<DataViewModel>
/// <summary> Paths to files to be processed. </summary>
private List<string> filesPaths = new List<string>();

private Brush correctBrush = Brushes.ForestGreen;
private Brush incorrectBrush = Brushes.Orange;
private Brush correctBrush = Brushes.Green;
private Brush badBrush = Brushes.Red;
private Brush skipBrush = Brushes.Gray;
private Brush doneBrush = Brushes.GreenYellow;

public DataViewModel ViewModel { get; }
public DataPage(DataViewModel viewModel)
Expand Down Expand Up @@ -121,22 +123,55 @@ private TreeViewItem GetTreeViewItem(string directory, string file)
{
string headerFile = GetHeaderFile(file);
var fileTreeItem = new TreeViewItem { Header = headerFile };
if (!headerFile.Contains(EnvironmentController.defaultFileFormat))
fileTreeItem.Foreground = incorrectBrush;
else
string fullPath = $"{directory}\\{headerFile}";
fileTreeItem.Foreground = GetColorTreeItem(headerFile, fullPath);
if (headerFile.Contains(EnvironmentController.defaultFileFormat))
{
string fullPath = $"{directory}\\{headerFile}";
filesPaths.Add(fullPath);
}
return fileTreeItem;
}

private Brush GetColorTreeItem(string headerFile, string fullPath)
{
// No DMI file? No process.
if (!headerFile.Contains(EnvironmentController.defaultFileFormat))
return badBrush;

if (fullPath == string.Empty)
return badBrush;

// Work with configs & DMI file states
using DMIFile fileDmi = new DMIFile(fullPath);
if (fileDmi.States.Count == 0)
return badBrush;

if (StatesController.isOverrideToggle)
return correctBrush;

foreach (ConfigItem config in selectedConfigs)
{
string exportPath = FilesSearcher.GetExportConfigPath(config.FileName, fullPath);
if (File.Exists(exportPath) == false)
continue;
DMIFile exportedDMIFile = new DMIFile(exportPath);
foreach (DMIState state in fileDmi.States)
{
foreach (DMIState exportedState in exportedDMIFile.States)
{
if (state.Name == exportedState.Name)
return incorrectBrush;
}
}
}

return correctBrush;
}

#endregion Tree View


#region Buttons
#region Changed Events

public void TreeItemChanged(object sender, RoutedEventArgs e)
{
Expand Down Expand Up @@ -165,8 +200,14 @@ private void ConfigChanged(object sender, SelectionChangedEventArgs e)
ConfigItem? config = item as ConfigItem;
selectedConfigs.Add(config);
}
GenerateTreeItems();
}

#endregion Changed Events


#region Buttons

private void SetImportFolderButton_Click(object sender, RoutedEventArgs e)
{
string path = ViewModel.FolderImportPath;
Expand All @@ -183,12 +224,16 @@ private void OverrideButton_Click(object sender, RoutedEventArgs e)
var pressed = StatesController.GetPressedButtonAppearance();
var unpressed = StatesController.GetUnPressedButtonAppearance();
OverrideButton.Appearance = StatesController.isOverrideToggle ? pressed : unpressed;

string fullPath = EnvironmentController.lastImportPath;
GenerateTreeItems();
}

private void ConfigRemoveButton_Click(object sender, RoutedEventArgs e)
{
Button button = sender as Button;
ConfigItem config = button.DataContext as ConfigItem;
Button? button = sender as Button;
ConfigItem? config = button?.DataContext as ConfigItem;
if (config == null) return;
ViewModel.RemoveConfig(config);
}

Expand Down Expand Up @@ -262,14 +307,30 @@ private void ViewItemsFromSelectedDMI(string fullPath)
return;
ViewModel.ClearStatesCollection();


//var StateItems = new ObservableCollection<StateItem>();
using DMIFile fileDmi = new DMIFile(fullPath);
var states = fileDmi.States;
foreach (DMIState state in states)
{
WriteableBitmap writeableBitmap = ImageEncoder.GetBMPFromDMIState(state, StateDirection.South);
Brush color = Brushes.GreenYellow;

Brush color = correctBrush;
if (!StatesController.isOverrideToggle)
{
foreach (ConfigItem config in selectedConfigs)
{
string exportPath = FilesSearcher.GetExportConfigPath(config.FileName, fullPath);
if (File.Exists(exportPath) == false)
continue;
DMIFile exportedDMIFile = new DMIFile(exportPath);
foreach (DMIState exportedState in exportedDMIFile.States)
{
if (state.Name == exportedState.Name)
color = incorrectBrush;
}
}
}

StateItem stateItem = new StateItem(
"NoName",
fullPath,
Expand Down
10 changes: 6 additions & 4 deletions Views/Pages/StatesEditorPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,9 @@ private void StateChanged(object sender, SelectionChangedEventArgs e)

private void StateRemoveButton_Click(object sender, RoutedEventArgs e)
{
Button button = sender as Button;
StateItem state = button.DataContext as StateItem;
Button? button = sender as Button;
StateItem? state = button?.DataContext as StateItem;
if (state == null) return;
ViewModel.RemoveState(state);
}

Expand Down Expand Up @@ -730,8 +731,9 @@ private void ClearConfigButton_Click(object sender, RoutedEventArgs e)

private void ConfigRemoveButton_Click(object sender, RoutedEventArgs e)
{
Button button = sender as Button;
ConfigItem config = button.DataContext as ConfigItem;
Button? button = sender as Button;
ConfigItem? config = button?.DataContext as ConfigItem;
if (config == null) return;
ViewModel.RemoveConfig(config);
}

Expand Down

0 comments on commit f27ae3f

Please sign in to comment.