Skip to content

Commit

Permalink
[HaRepacker] Default to avalon text editor for spine .atlas resource
Browse files Browse the repository at this point in the history
  • Loading branch information
lastbattle committed Dec 6, 2020
1 parent 1eca8b3 commit 090114e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 21 deletions.
62 changes: 41 additions & 21 deletions HaRepacker/GUI/Panels/MainPanel.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,13 @@ private void applyChangesButton_Click(object sender, EventArgs e)
}
else if (obj is WzStringProperty stringProperty)
{
stringProperty.Value = setText;
if (!stringProperty.IsSpineAtlasResources)
{
stringProperty.Value = setText;
} else
{
throw new NotSupportedException("Usage of textBoxProp for spine WzStringProperty.");
}
}
else if (obj is WzFloatProperty floatProperty)
{
Expand Down Expand Up @@ -803,6 +809,19 @@ private void TextEditor_SaveButtonClicked(object sender, EventArgs e)
string setText = textEditor.textEditor.Text;
byte[] encBytes = luaProp.EncodeDecode(Encoding.ASCII.GetBytes(setText));
luaProp.Value = encBytes;
}
else if (obj is WzStringProperty stringProp)
{
if (stringProp.IsSpineAtlasResources)
{
string setText = textEditor.textEditor.Text;

stringProp.Value = setText;
}
else
{
throw new NotSupportedException("Usage of TextEditor for non-spine WzStringProperty.");
}
}
}

Expand Down Expand Up @@ -1396,22 +1415,23 @@ private void ShowObjectValue(WzObject obj)
else if (bIsWzLuaProperty)
{
textEditor.Visibility = Visibility.Visible;
textEditor.SetHighlightingDefinitionIndex(2); // javascript

textEditor.textEditor.Text = obj.ToString();
}
else if (bIsWzStringProperty || bIsWzIntProperty || bIsWzLongProperty || bIsWzDoubleProperty || bIsWzFloatProperty || bIsWzShortProperty)
{
// Value
textPropBox.Visibility = Visibility.Visible;
textPropBox.Text = obj.ToString();

// If text is a string property, expand the textbox
if (bIsWzStringProperty)
{
WzStringProperty stringObj = (WzStringProperty)obj;

if (stringObj.IsSpineAtlasResources) // spine related resource
{
textEditor.Visibility = Visibility.Visible;
textEditor.SetHighlightingDefinitionIndex(20); // json
textEditor.textEditor.Text = obj.ToString();

Thread thread = new Thread(() =>
{
try
Expand All @@ -1434,30 +1454,30 @@ private void ShowObjectValue(WzObject obj)
textPropBox.AcceptsReturn = true;
textPropBox.Height = 700;
}
else if (stringObj.Name == PORTAL_NAME_OBJ_NAME) // Portal type name display - "pn" = portal name
{
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, obj.GetString());
}
}
else
{
textPropBox.AcceptsReturn = true;
if (stringObj.IsSpineRelatedResources)
// Value
textPropBox.Visibility = Visibility.Visible;
textPropBox.Text = obj.ToString();

if (stringObj.Name == PORTAL_NAME_OBJ_NAME) // Portal type name display - "pn" = portal name
{
textPropBox.Height = 700;
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, obj.GetString());
}
}
else
{
textPropBox.AcceptsReturn = true;

textPropBox.Height = 200;
}

}
}
else if (bIsWzLongProperty || bIsWzIntProperty)
Expand Down
9 changes: 9 additions & 0 deletions HaRepacker/GUI/Panels/SubPanels/AvalonTextEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ public AvalonTextEditor()
}

#region Data Context
/// <summary>
/// Sets the default syntax highlighting index
/// </summary>
/// <param name="index"></param>
public void SetHighlightingDefinitionIndex(int index)
{
this.HighlightingDefinition = _highlightingManager.HighlightingDefinitions[index]; // default to javascript
}

private readonly HighlightingManager _highlightingManager;
private IHighlightingDefinition _HighlightingDefinition;
/// <summary>
Expand Down

0 comments on commit 090114e

Please sign in to comment.