Skip to content

Commit

Permalink
Merge pull request #75 from lastbattle/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
LastBattle authored Oct 8, 2020
2 parents e6fc682 + 615188a commit 298ed68
Show file tree
Hide file tree
Showing 111 changed files with 59,014 additions and 386 deletions.
11 changes: 10 additions & 1 deletion HaCreator/GUI/HaRibbon.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,18 @@
<RibbonTab x:Name="toolsTab" Header="Tools" KeyTip="T">
<RibbonGroup x:Name="Tools" Header="Tools">
<RibbonButton Label="Settings" LargeImageSource="pack://application:,,,/HaCreator;component/Images/Settings_big.png" Command="ns:HaRibbon.Settings" Focusable="False"/>
<RibbonButton Label="Map Simulation" LargeImageSource="pack://application:,,,/HaCreator;component/Images/Play.png" Command="ns:HaRibbon.MapSim" Focusable="False"/>
<RibbonButton Label="Manage User Objects" LargeImageSource="pack://application:,,,/HaCreator;component/Images/UserObjs.png" Command="ns:HaRibbon.UserObjs" Focusable="False"/>
</RibbonGroup>
<RibbonGroup x:Name="SimulatorSettings" Header="Map Simulator">
<StackPanel Orientation="Horizontal">
<RibbonButton Label="Preview" LargeImageSource="pack://application:,,,/HaCreator;component/Images/Play.png" Command="ns:HaRibbon.MapSim" Focusable="False"/>

<ComboBox x:Name="comboBox_Resolution" Width="100"
Foreground="Black" VerticalAlignment="Center"
SelectionChanged="comboBox_Resolution_SelectionChanged">
</ComboBox>
</StackPanel>
</RibbonGroup>
<RibbonGroup x:Name="Options" Header="Options">
<RibbonToggleButton x:Name="minimapBtn" Label="Show Minimap" LargeImageSource="pack://application:,,,/HaCreator;component/Images/Minimap.png" Command="ns:HaRibbon.Minimap" Focusable="False"/>
<RibbonToggleButton x:Name="parallaxBtn" Label="Parallax BGs" LargeImageSource="pack://application:,,,/HaCreator;component/Images/diagram_parallax.png" Command="ns:HaRibbon.Parallax" Focusable="False"/>
Expand Down
40 changes: 40 additions & 0 deletions HaCreator/GUI/HaRibbon.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using HaCreator.CustomControls;
using HaCreator.MapEditor;
using HaSharedLibrary.Render.DX;
using MapleLib.WzLib.WzStructure.Data;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -33,6 +34,7 @@ public partial class HaRibbon : UserControl
public HaRibbon()
{
InitializeComponent();

this.PreviewMouseWheel += HaRibbon_PreviewMouseWheel;
}

Expand Down Expand Up @@ -64,6 +66,30 @@ private void Ribbon_Loaded(object sender, RoutedEventArgs e)
reducedHeight = (int)child.RowDefinitions[0].ActualHeight;
child.RowDefinitions[0].Height = new GridLength(0);
}

// Load map simulator resolutions
foreach (RenderResolution val in Enum.GetValues(typeof(RenderResolution)))
{
ComboBoxItem comboBoxItem = new ComboBoxItem
{
Tag = val,
Content = val.ToString().Replace("Res_", "").Replace("_", " ").Replace("PercScaled", "% scale")
};

comboBox_Resolution.Items.Add(comboBoxItem);
}
//comboBox_Resolution.DisplayMemberPath = "Content";

int i = 0;
foreach (ComboBoxItem item in comboBox_Resolution.Items)
{
if ((RenderResolution)item.Tag == UserSettings.SimulateResolution)
{
comboBox_Resolution.SelectedIndex = i;
break;
}
i++;
}
}

public static readonly RoutedUICommand New = new RoutedUICommand("New", "New", typeof(HaRibbon),
Expand Down Expand Up @@ -530,5 +556,19 @@ protected override void OnPreviewKeyDown(KeyEventArgs e)
RibbonKeyDown.Invoke(this, new System.Windows.Forms.KeyEventArgs((System.Windows.Forms.Keys)KeyInterop.VirtualKeyFromKey(e.Key)));
}
}

/// <summary>
/// On simulator preview resolution changed
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void comboBox_Resolution_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (comboBox_Resolution.SelectedItem == null)
return;

RenderResolution selectedItem = (RenderResolution) (comboBox_Resolution.SelectedItem as ComboBoxItem).Tag;
UserSettings.SimulateResolution = selectedItem; // combo box selection. 800x600, 1024x768, 1280x720, 1920x1080
}
}
}
4 changes: 2 additions & 2 deletions HaCreator/HaCreator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,8 @@
<Project>{0b7155ef-1eb0-4fae-ba56-8064cbaf2bea}</Project>
<Name>Harepacker-resurrected</Name>
</ProjectReference>
<ProjectReference Include="..\HaSharedLirary\HaSharedLibrary.csproj">
<Project>{5411388B-F3CB-4D52-9F55-ABD15CFE966C}</Project>
<ProjectReference Include="..\HaSharedLibrary\HaSharedLibrary.csproj">
<Project>{5411388b-f3cb-4d52-9f55-abd15cfe966c}</Project>
<Name>HaSharedLibrary</Name>
</ProjectReference>
<ProjectReference Include="..\MapleLib\MapleLib.csproj">
Expand Down
58 changes: 46 additions & 12 deletions HaRepacker/AnimationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Drawing;
using MapleLib.WzLib.WzProperties;
using MapleLib.WzLib;
using SharpApng;

namespace HaRepacker
{
Expand All @@ -18,6 +17,40 @@ namespace HaRepacker
/// </summary>
public static class AnimationBuilder
{
#region Extras
/// <summary>
/// Is an animation object
/// </summary>
/// <param name="prop"></param>
/// <returns></returns>
public static bool IsValidAnimationWzObject(WzObject prop)
{
if (!(prop is WzSubProperty))
return false;

WzSubProperty castedProp = (WzSubProperty)prop;
List<WzCanvasProperty> props = new List<WzCanvasProperty>(castedProp.WzProperties.Count);
int foo;

foreach (WzImageProperty subprop in castedProp.WzProperties)
{
if (!(subprop is WzCanvasProperty))
continue;
if (!int.TryParse(subprop.Name, out foo))
return false;
props.Add((WzCanvasProperty)subprop);
}
if (props.Count < 2)
return false;

props.Sort(new Comparison<WzCanvasProperty>(AnimationBuilder.PropertySorter));
for (int i = 0; i < props.Count; i++)
if (i.ToString() != props[i].Name)
return false;
return true;
}
#endregion

private static Bitmap OptimizeBitmapTransparent(Bitmap source, WzVectorProperty origin, Point biggestPng, Point SmallestEmptySpace, Point MaximumMapEndingPts)
{
Point Size = new Point(biggestPng.X - SmallestEmptySpace.X, biggestPng.Y - SmallestEmptySpace.Y);
Expand Down Expand Up @@ -57,11 +90,11 @@ public static void ExtractAnimation(WzSubProperty parent, string savePath, bool
List<WzCanvasProperty> sortedProps = new List<WzCanvasProperty>();
foreach (WzImageProperty subprop in parent.WzProperties)
{
if (subprop is WzCanvasProperty)
if (subprop is WzCanvasProperty property)
{
sortedProps.Add((WzCanvasProperty)subprop);
WzPngProperty png = ((WzCanvasProperty)subprop).PngProperty;
System.Drawing.PointF origin = ((WzCanvasProperty)subprop).GetCanvasOriginPosition();
sortedProps.Add(property);
WzPngProperty png = property.PngProperty;
System.Drawing.PointF origin = property.GetCanvasOriginPosition();

Point StartPoints = new Point(biggestPng.X - (int) origin.X, biggestPng.Y - (int)origin.Y);
Point PngMapppingEndingPts = new Point(StartPoints.X + png.Width, StartPoints.Y + png.Height);
Expand All @@ -88,19 +121,20 @@ public static void ExtractAnimation(WzSubProperty parent, string savePath, bool
System.Drawing.PointF origin = subprop.GetCanvasOriginPosition();
bmpList.Add(OptimizeBitmapTransparent(bmp, new WzVectorProperty("", origin.X, origin.Y), biggestPng, SmallestEmptySpace, MaximumPngMappingEndingPts));

WzIntProperty delayProp = (WzIntProperty)subprop["delay"];
int delay = 100;
if (delayProp != null) delay = delayProp.Value;
delayList.Add(delay);
int? delay = subprop[WzCanvasProperty.AnimationDelayPropertyName]?.GetInt();
if (delay == null)
delay = 100;

delayList.Add((int) delay);
}
Apng apngBuilder = new Apng();
SharpApng.SharpApng apngBuilder = new SharpApng.SharpApng();
if (apngFirstFrame)
{
apngBuilder.AddFrame(new Frame(CreateIncompatibilityFrame(new Size(bmpList[0].Width, bmpList[0].Height)),1,1));
apngBuilder.AddFrame(new SharpApng.SharpApngFrame(CreateIncompatibilityFrame(new Size(bmpList[0].Width, bmpList[0].Height)),1,1));
}
for (int i = 0; i < bmpList.Count; i++)
{
apngBuilder.AddFrame(new Frame(bmpList[i], getNumByDelay(delayList[i]), getDenByDelay(delayList[i])));
apngBuilder.AddFrame(new SharpApng.SharpApngFrame(bmpList[i], getNumByDelay(delayList[i]), getDenByDelay(delayList[i])));
}
apngBuilder.WriteApng(savePath, apngFirstFrame, true);
}
Expand Down
20 changes: 5 additions & 15 deletions HaRepacker/GUI/MainForm.Designer.cs

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

70 changes: 10 additions & 60 deletions HaRepacker/GUI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ private void UpdateSelectedMainPanelTab()
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button_addTab_Click(object sender, EventArgs e)
private void Button_addTab_Click(object sender, EventArgs e)
{
AddTabsInternal();
}
Expand All @@ -516,10 +516,11 @@ private void AddTabsInternal(string defaultName = null)
{
Margin = new Padding(1, 1, 1, 1)
};
System.Windows.Forms.Integration.ElementHost elemHost = new System.Windows.Forms.Integration.ElementHost();
elemHost.Dock = DockStyle.Fill;
elemHost.Child = new MainPanel();

System.Windows.Forms.Integration.ElementHost elemHost = new System.Windows.Forms.Integration.ElementHost
{
Dock = DockStyle.Fill,
Child = new MainPanel()
};
tabPage.Controls.Add(elemHost);


Expand Down Expand Up @@ -1446,7 +1447,7 @@ private void searchToolStripMenuItem_Click(object sender, EventArgs e)
}

private static readonly string HelpFile = "Help.htm";
private void viewHelpToolStripMenuItem_Click(object sender, EventArgs e)
private void ViewHelpToolStripMenuItem_Click(object sender, EventArgs e)
{
string helpPath = Path.Combine(Application.StartupPath, HelpFile);
if (File.Exists(helpPath))
Expand All @@ -1455,43 +1456,21 @@ private void viewHelpToolStripMenuItem_Click(object sender, EventArgs e)
Warning.Error(string.Format(HaRepacker.Properties.Resources.MainHelpOpenFail, HelpFile));
}

private void copyToolStripMenuItem_Click(object sender, EventArgs e)
private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
{
MainPanel.DoCopy();
}

private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
{
MainPanel.DoPaste();
}

private void aPNGToolStripMenuItem_Click(object sender, EventArgs e)
{
if (MainPanel.DataTree.SelectedNode == null) return;
if (!ValidAnimation((WzObject)MainPanel.DataTree.SelectedNode.Tag))
Warning.Error(HaRepacker.Properties.Resources.MainAnimationFail);
else
{
SaveFileDialog dialog = new SaveFileDialog()
{
Title = HaRepacker.Properties.Resources.SelectOutApng,
Filter = string.Format("{0}|*.png", HaRepacker.Properties.Resources.ApngFilter)
};
if (dialog.ShowDialog() != DialogResult.OK)
{
return;
}
AnimationBuilder.ExtractAnimation((WzSubProperty)MainPanel.DataTree.SelectedNode.Tag, dialog.FileName,
Program.ConfigurationManager.UserSettings.UseApngIncompatibilityFrame);
}
}

/// <summary>
/// Wz string searcher tool
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolStripMenuItem_searchWzStrings_Click(object sender, EventArgs e)
private void ToolStripMenuItem_searchWzStrings_Click(object sender, EventArgs e)
{
// Map name load
string loadedWzVersion;
Expand Down Expand Up @@ -1538,35 +1517,6 @@ private void AbortButton_Click(object sender, EventArgs e)
}
}

#region Extras
private bool ValidAnimation(WzObject prop)
{
if (!(prop is WzSubProperty))
return false;

WzSubProperty castedProp = (WzSubProperty)prop;
List<WzCanvasProperty> props = new List<WzCanvasProperty>(castedProp.WzProperties.Count);
int foo;

foreach (WzImageProperty subprop in castedProp.WzProperties)
{
if (!(subprop is WzCanvasProperty))
continue;
if (!int.TryParse(subprop.Name, out foo))
return false;
props.Add((WzCanvasProperty)subprop);
}
if (props.Count < 2)
return false;

props.Sort(new Comparison<WzCanvasProperty>(AnimationBuilder.PropertySorter));
for (int i = 0; i < props.Count; i++)
if (i.ToString() != props[i].Name)
return false;
return true;
}
#endregion

#region Image directory add
/// <summary>
/// Add WzDirectory
Expand Down
Loading

0 comments on commit 298ed68

Please sign in to comment.