Skip to content

Commit

Permalink
Management of Map.wz fieldLimitType via checkboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
eaxvac committed Jun 9, 2018
1 parent c5b571f commit 5a2c789
Show file tree
Hide file tree
Showing 5 changed files with 307 additions and 33 deletions.

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

166 changes: 149 additions & 17 deletions HaRepackerLib/Controls/HaRepackerMainPanels/HaRepackerMainPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using WeifenLuo.WinFormsUI.Docking;
using System.Threading;
using HaRepacker.GUI.Interaction;
using MapleLib.WzLib.WzStructure.Data;

namespace HaRepackerLib.Controls.HaRepackerMainPanels
{
Expand All @@ -22,14 +23,57 @@ public partial class HaRepackerMainPanel : UserControl
private static List<WzObject> clipboard = new List<WzObject>();
private UndoRedoManager undoRedoMan;

// misc
private bool isSelectingWzMapFieldLimit = false;
private bool initializingListViewForFieldLimit = false;

public HaRepackerMainPanel()
{
InitializeComponent();

PopulateDefaultListView();

MainSplitContainer.Parent = MainDockPanel;
undoRedoMan = new UndoRedoManager(this);
}

#region Handlers
private void PopulateDefaultListView()
{
initializingListViewForFieldLimit = true;

// Populate FieldLimitType
if (listView_fieldLimitType.Items.Count == 0)
{
// dummy column
listView_fieldLimitType.Columns.Add(new ColumnHeader()
{
Text = "",
Name = "col1",
Width = 450,
});

int i_index = 0;
foreach (WzFieldLimitType limitType in Enum.GetValues(typeof(WzFieldLimitType)))
{
ListViewItem item1 = new ListViewItem(
string.Format("{0} - {1}", (i_index).ToString(), limitType.ToString().Replace("_", " ")));
item1.Tag = limitType; // starts from 0
listView_fieldLimitType.Items.Add(item1);

i_index++;
}
for (int i = i_index; i < i_index + 20; i++) // add 50 dummy values, we really dont have the field properties of future MS versions :(
{
ListViewItem item1 = new ListViewItem(string.Format("{0} - UNKNOWN", (i).ToString()));
item1.Tag = i;
listView_fieldLimitType.Items.Add(item1);
}
}

initializingListViewForFieldLimit = false;
}

private void RedockControls()
{
if (Width * Height == 0)
Expand Down Expand Up @@ -58,6 +102,23 @@ private void RedockControls()
saveImageButton.Location = new Point(changeImageButton.Location.X + changeImageButton.Width + changeImageButton.Margin.Right + 100, changeImageButton.Location.Y);
changeSoundButton.Location = changeImageButton.Location;
saveSoundButton.Location = saveImageButton.Location;

if (isSelectingWzMapFieldLimit)
{
listView_fieldLimitType.Visible = true;
listView_fieldLimitType.Size = new Size(
MainSplitContainer.Panel2.Width,
MainSplitContainer.Panel2.Height - pictureBoxPanel.Location.Y - saveImageButton.Height - saveImageButton.Margin.Top - 20);

textPropBox.Height = 30;
textPropBox.Enabled = false;
}
else
{
listView_fieldLimitType.Visible = false;
textPropBox.Height = MainSplitContainer.Panel2.Height;
textPropBox.Enabled = true;
}
}

private void MainSplitContainer_SplitterMoved(object sender, SplitterEventArgs e)
Expand Down Expand Up @@ -90,7 +151,13 @@ private void ShowObjectValue(WzObject obj)
mp3Player.SoundProperty = null;
nameBox.Text = obj is WzFile ? ((WzFile)obj).Header.Copyright : obj.Name;
nameBox.ButtonEnabled = false;

toolStripStatusLabel_additionalInfo.Text = "-"; // Reset additional info to default
if (isSelectingWzMapFieldLimit) // previously already selected. update again
{
isSelectingWzMapFieldLimit = false;
RedockControls();
}

if (obj is WzFile || obj is WzDirectory || obj is WzImage || obj is WzNullProperty || obj is WzSubProperty || obj is WzConvexProperty)
{
Expand Down Expand Up @@ -129,7 +196,7 @@ private void ShowObjectValue(WzObject obj)
saveImageButton.Visible = true;
changeSoundButton.Visible = false;
saveSoundButton.Visible = false;
}
}
else if (obj is WzUOLProperty)
{
nameBox.Visible = true;
Expand All @@ -151,7 +218,8 @@ private void ShowObjectValue(WzObject obj)
saveImageButton.Visible = true;

textPropBox.Size = new Size(textPropBox.Size.Width, 50);
} else
}
else
{

canvasPropBox.Visible = false;
Expand Down Expand Up @@ -200,14 +268,39 @@ private void ShowObjectValue(WzObject obj)
{
if (MapleLib.WzLib.WzStructure.Data.Tables.PortalTypeNames.ContainsKey(obj.GetString()))
{
toolStripStatusLabel_additionalInfo.Text =
string.Format(Properties.Resources.MainAdditionalInfo_PortalType, MapleLib.WzLib.WzStructure.Data.Tables.PortalTypeNames[obj.GetString()]);
} else
toolStripStatusLabel_additionalInfo.Text =
string.Format(Properties.Resources.MainAdditionalInfo_PortalType, MapleLib.WzLib.WzStructure.Data.Tables.PortalTypeNames[obj.GetString()]);
}
else
{
toolStripStatusLabel_additionalInfo.Text = string.Format(Properties.Resources.MainAdditionalInfo_PortalType, obj.GetString());
}
}
}
else if (obj is WzIntProperty)
{
WzIntProperty intProperty = (WzIntProperty)obj;

if (intProperty.Name == "fieldLimit")
{
isSelectingWzMapFieldLimit = true;


initializingListViewForFieldLimit = true;

// Fill checkboxes
//int maxFieldLimitType = FieldLimitTypeExtension.GetMaxFieldLimitType();
foreach (ListViewItem item in listView_fieldLimitType.Items)
{
item.Checked = FieldLimitTypeExtension.Check((int)item.Tag, intProperty.Value);
}
initializingListViewForFieldLimit = false;
ListView_fieldLimitType_ItemChecked(listView_fieldLimitType, null);

// Redock controls
RedockControls();
}
}
}
else if (obj is WzVectorProperty)
{
Expand All @@ -230,6 +323,44 @@ private void ShowObjectValue(WzObject obj)
}
}

/// <summary>
/// On WzFieldLimitType listview item checked
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ListView_fieldLimitType_ItemCheck(object sender, ItemCheckEventArgs e)
{
if (initializingListViewForFieldLimit)
return;

System.Diagnostics.Debug.WriteLine("Set index at " + e.Index + " to " + listView_fieldLimitType.Items[e.Index].Checked);
}

/// <summary>
/// On WzFieldLimitType listview item checked
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ListView_fieldLimitType_ItemChecked(object sender, ItemCheckedEventArgs e)
{
if (initializingListViewForFieldLimit)
return;

ulong fieldLimit = 0;
foreach (ListViewItem item in listView_fieldLimitType.Items)
{
if (item.Checked)
{
int numShift = ((int)item.Tag);

System.Diagnostics.Debug.WriteLine("Selected " + numShift + ", " + (long)(1L << numShift));
fieldLimit |= (ulong)(1L << numShift);
}
}
System.Diagnostics.Debug.WriteLine("Result " + fieldLimit);
textPropBox.Text = fieldLimit.ToString();
}

private void DataTree_DoubleClick(object sender, EventArgs e)
{
if (DataTree.SelectedNode != null && DataTree.SelectedNode.Tag is WzImage && DataTree.SelectedNode.Nodes.Count == 0)
Expand Down Expand Up @@ -262,7 +393,7 @@ private static void ParseOnDataTreeSelectedItem(WzNode selectedNode)
/// <param name="e"></param>
private void saveImageButton_Click(object sender, EventArgs e)
{
if (!(DataTree.SelectedNode.Tag is WzCanvasProperty) && !(DataTree.SelectedNode.Tag is WzUOLProperty))
if (!(DataTree.SelectedNode.Tag is WzCanvasProperty) && !(DataTree.SelectedNode.Tag is WzUOLProperty))
{
return;
}
Expand Down Expand Up @@ -727,7 +858,8 @@ private void changeImageButton_Click(object sender, EventArgs e)
// Add undo actions
//actions.Add(UndoRedoManager.ObjectRemoved((WzNode)parentCanvasNode, childInlinkNode));
childInlinkNode.Delete(); // Delete '_inlink' node
} else if (selectedWzCanvas.HaveOutlinkProperty()) // if its an inlink property, remove that before updating base image.
}
else if (selectedWzCanvas.HaveOutlinkProperty()) // if its an inlink property, remove that before updating base image.
{
selectedWzCanvas.RemoveProperty(selectedWzCanvas[WzCanvasProperty.OutlinkPropertyName]);

Expand All @@ -742,7 +874,7 @@ private void changeImageButton_Click(object sender, EventArgs e)

}
selectedWzCanvas.PngProperty.SetPNG(bmp);

// Updates
selectedWzCanvas.ParentImage.Changed = true;
canvasPropBox.Image = bmp;
Expand Down Expand Up @@ -835,7 +967,7 @@ public void DoRemoveImageResource()
foreach (WzNode node in DataTree.SelectedNodes)
{
WzObject wzObj = (WzObject)node.Tag;// CloneWzObject((WzObject)node.Tag);

}
}

Expand Down Expand Up @@ -1108,11 +1240,11 @@ private void btnFindAll_Click(object sender, EventArgs e)
dsr.searchResultsBox.Items.Add(result);
dsr.Show(MainDockPanel);
dsr.DockState = DockState.DockBottom;
// searchResults.AutoHide = false;
// searchResults.Visible = true;
// searchResultsContainer.Visible = true;
// dockSite8.Visible = true;
// panelDockContainer1.Visible = true;
// searchResults.AutoHide = false;
// searchResults.Visible = true;
// searchResultsContainer.Visible = true;
// dockSite8.Visible = true;
// panelDockContainer1.Visible = true;
findBox.Focus();
}

Expand Down Expand Up @@ -1149,9 +1281,9 @@ private void searchResultsContainer_VisibleChanged(object sender, System.EventAr

private WzNode GetNodeByName(TreeNodeCollection collection, string name)
{
foreach (WzNode node in collection)
if (node.Text == name)
return node;
foreach (WzNode node in collection)
if (node.Text == name)
return node;
return null;
}

Expand Down
Loading

0 comments on commit 5a2c789

Please sign in to comment.