Skip to content

Commit

Permalink
Merge pull request #1049 from osdanova/master
Browse files Browse the repository at this point in the history
ObjectEditor - UI module
  • Loading branch information
Oathseeker authored Jun 8, 2024
2 parents 0e3067f + f52740d commit 415a410
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 4 deletions.
73 changes: 73 additions & 0 deletions OpenKh.Tools.Kh2ObjectEditor/Modules/UI/M_UI_Control.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<UserControl x:Class="OpenKh.Tools.Kh2ObjectEditor.Modules.UI.M_UI_Control"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:OpenKh.Tools.Kh2ObjectEditor.Modules.UI"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Background="SlateGray" HorizontalContentAlignment="Center" FontWeight="Bold">FACE</Label>
<Canvas Grid.Row="1">
<Canvas.ContextMenu>
<ContextMenu>
<MenuItem Header="Export as PNG" Click="Face_Export"/>
<MenuItem Header="Replace texture" Click="Face_Replace"/>
</ContextMenu>
</Canvas.ContextMenu>
<Canvas.Background>
<DrawingBrush TileMode="Tile" Viewport="0,0,32,32" ViewportUnits="Absolute">
<DrawingBrush.Drawing>
<GeometryDrawing Geometry="M0,0 H16 V16 H32 V32 H16 V16 H0Z" Brush="#80000000"/>
</DrawingBrush.Drawing>
</DrawingBrush>
</Canvas.Background>
<Image Name="FaceFrame"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Stretch="Uniform"/>
</Canvas>
</Grid>


<GridSplitter Grid.Column="1" Background="LightGray" HorizontalAlignment="Center" VerticalAlignment="Stretch" ShowsPreview="True" Width="5"/>

<Grid Grid.Column="2">
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Background="SlateGray" HorizontalContentAlignment="Center" FontWeight="Bold">COMMAND</Label>
<Canvas Grid.Row="1">
<Canvas.ContextMenu>
<ContextMenu>
<MenuItem Header="Export as PNG" Click="Command_Export"/>
<MenuItem Header="Replace texture" Click="Command_Replace"/>
</ContextMenu>
</Canvas.ContextMenu>
<Canvas.Background>
<DrawingBrush TileMode="Tile" Viewport="0,0,32,32" ViewportUnits="Absolute">
<DrawingBrush.Drawing>
<GeometryDrawing Geometry="M0,0 H16 V16 H32 V32 H16 V16 H0Z" Brush="#80000000"/>
</DrawingBrush.Drawing>
</DrawingBrush>
</Canvas.Background>
<Image Name="CommandFrame"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Stretch="Uniform"/>
</Canvas>
</Grid>
</Grid>
</UserControl>
72 changes: 72 additions & 0 deletions OpenKh.Tools.Kh2ObjectEditor/Modules/UI/M_UI_Control.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using OpenKh.AssimpUtils;
using OpenKh.Kh2;
using OpenKh.Tools.Common.Wpf;
using OpenKh.Tools.Kh2ObjectEditor.Services;
using OpenKh.Tools.Kh2ObjectEditor.Utils;
using System.IO;
using System.Windows.Controls;
using System.Windows.Media.Imaging;

namespace OpenKh.Tools.Kh2ObjectEditor.Modules.UI
{
public partial class M_UI_Control : UserControl
{
public M_UI_Control()
{
InitializeComponent();
loadImages();
}

private void loadImages()
{
if(ApdxService.Instance.ImgdFace != null)
{
BitmapSource faceBitmap = ApdxService.Instance.ImgdFace.GetBimapSource();
FaceFrame.Source = faceBitmap;
}
if (ApdxService.Instance.ImgdCommand != null)
{
BitmapSource commandBitmap = ApdxService.Instance.ImgdCommand.GetBimapSource();
CommandFrame.Source = commandBitmap;
}
}

private void Face_Export(object sender, System.Windows.RoutedEventArgs e)
{
exportImage(ApdxService.Instance.ImgdFace, "Face");
}
private void Face_Replace(object sender, System.Windows.RoutedEventArgs e)
{
Imgd loadedImgd = ImageUtils.loadPngFileAsImgd();
ApdxService.Instance.ImgdFace = loadedImgd;
loadImages();
}

private void Command_Export(object sender, System.Windows.RoutedEventArgs e)
{
exportImage(ApdxService.Instance.ImgdCommand, "Command");
}
private void Command_Replace(object sender, System.Windows.RoutedEventArgs e)
{
Imgd loadedImgd = ImageUtils.loadPngFileAsImgd();
ApdxService.Instance.ImgdCommand = loadedImgd;
loadImages();
}

private void exportImage(Imgd image, string imageName)
{
BitmapSource bitmapImage = image.GetBimapSource();

System.Windows.Forms.SaveFileDialog sfd;
sfd = new System.Windows.Forms.SaveFileDialog();
sfd.Title = "Export image as PNG";
sfd.FileName = imageName + ".png";
sfd.ShowDialog();
if (sfd.FileName != "")
{
MemoryStream memStream = new MemoryStream();
AssimpGeneric.ExportBitmapSourceAsPng(bitmapImage, sfd.FileName);
}
}
}
}
25 changes: 22 additions & 3 deletions OpenKh.Tools.Kh2ObjectEditor/Services/ApdxService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public class ApdxService
public Pax PaxFile { get; set; } // 979
// Wd (32, BGM Instrument Data) - 734
// Seb (31) - 734
public Imgd ImgdFile { get; set; } // 220
public Imgd ImgdFace { get; set; } // 220 (face + comd)
public Imgd ImgdCommand { get; set; }
// Seqd (25) - 220
// IopVoice (34) - 144
// Event (22) - 349
Expand Down Expand Up @@ -49,7 +50,14 @@ public void LoadFile(string filepath)
PaxFile = new Pax(barEntry.Stream);
break;
case Bar.EntryType.Imgd:
ImgdFile = Imgd.Read(barEntry.Stream);
if(barEntry.Name == "face")
{
ImgdFace = Imgd.Read(barEntry.Stream);
}
else if(barEntry.Name == "comd")
{
ImgdCommand = Imgd.Read(barEntry.Stream);
}
break;
case Bar.EntryType.Seqd:
//SqdFile = Sqd.Read(barEntry.Stream);
Expand All @@ -70,7 +78,18 @@ public void SaveToBar()
barEntry.Stream = PaxFile.getAsStream();
break;
case Bar.EntryType.Imgd:
//barEntry.Stream = ;
if (barEntry.Name == "face")
{
MemoryStream memStream = new MemoryStream();
ImgdFace.Write(memStream);
barEntry.Stream = memStream;
}
else if (barEntry.Name == "comd")
{
MemoryStream memStream = new MemoryStream();
ImgdCommand.Write(memStream);
barEntry.Stream = memStream;
}
break;
case Bar.EntryType.Seqd:
//barEntry.Stream = ;
Expand Down
1 change: 1 addition & 0 deletions OpenKh.Tools.Kh2ObjectEditor/ViewModel/ModuleLoader_VM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class ModuleLoader_VM : NotifyPropertyChangedBase
{
public Visibility TabModelEnabled { get { return MdlxService.Instance.MdlxBar == null ? Visibility.Collapsed : Visibility.Visible; } }
public Visibility TabTexturesEnabled { get { return MdlxService.Instance.MdlxBar == null ? Visibility.Collapsed : Visibility.Visible; } }
public Visibility TabUIEnabled { get { return (ApdxService.Instance.ImgdFace == null && ApdxService.Instance.ImgdCommand == null) ? Visibility.Collapsed : Visibility.Visible; } }
public Visibility TabMotionsEnabled { get { return MsetService.Instance.MsetBar == null ? Visibility.Collapsed : Visibility.Visible; } }
public Visibility TabCollisionsEnabled { get { return MdlxService.Instance.CollisionFile == null ? Visibility.Collapsed : Visibility.Visible; } }
public Visibility TabParticlesEnabled { get { return ApdxService.Instance.ApdxBar == null ? Visibility.Collapsed : Visibility.Visible; } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<StackPanel Grid.Column="1" Background="White">
<Label Visibility="Visible" x:Name="TabModel" MouseLeftButtonUp="TabClick_Model">Model</Label>
<Label Visibility="Visible" x:Name="TabTextures" MouseLeftButtonUp="TabClick_Textures">Textures</Label>
<Label Visibility="Visible" x:Name="TabUI" MouseLeftButtonUp="TabClick_UI">UI</Label>
<Label Visibility="Visible" x:Name="TabCollisions" MouseLeftButtonUp="TabClick_Collisions">Collisions</Label>
<Label Visibility="Visible" x:Name="TabMotions" MouseLeftButtonUp="TabClick_Motions">Motions</Label>
<Label Visibility="Visible" x:Name="TabParticles" MouseLeftButtonUp="TabClick_Particles">Particles</Label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using OpenKh.Tools.Kh2ObjectEditor.Modules.Collisions;
using OpenKh.Tools.Kh2ObjectEditor.Modules.Effects;
using OpenKh.Tools.Kh2ObjectEditor.Modules.Textures;
using OpenKh.Tools.Kh2ObjectEditor.Modules.UI;
using OpenKh.Tools.Kh2ObjectEditor.ViewModel;
using System;
using System.Windows.Controls;
Expand All @@ -23,6 +24,7 @@ public void reloadTabs()
{
TabModel.Visibility = ThisVM.TabModelEnabled;
TabTextures.Visibility = ThisVM.TabTexturesEnabled;
TabUI.Visibility = ThisVM.TabUIEnabled;
TabCollisions.Visibility = ThisVM.TabCollisionsEnabled;
TabMotions.Visibility = ThisVM.TabMotionsEnabled;
TabParticles.Visibility = ThisVM.TabParticlesEnabled;
Expand All @@ -47,7 +49,10 @@ private void TabClick_Model(object sender, System.Windows.Input.MouseButtonEvent
private void TabClick_Textures(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
contentFrame.Content = new ModuleTextures_Control();
//contentFrame.Content = new TextureAnimation_Control();
}
private void TabClick_UI(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
contentFrame.Content = new M_UI_Control();
}
private void TabClick_Collisions(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
Expand Down

0 comments on commit 415a410

Please sign in to comment.