Skip to content

Commit

Permalink
add template switch hotkeys
Browse files Browse the repository at this point in the history
  • Loading branch information
igorseabra4 committed Jun 15, 2022
1 parent ee32415 commit 5c5e435
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 35 deletions.
3 changes: 1 addition & 2 deletions IndustrialPark/ArchiveEditor/ArchiveEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,10 +1173,9 @@ public List<uint> PlaceTemplate(Vector3 position, AssetTemplate template = Asset

private void ToolStripMenuItem_CreateGroup_Click(object sender, EventArgs e)
{
var items = (from a in CurrentlySelectedAssetIDs() select new AssetID(a)).ToArray();
var assetIDs = PlaceTemplate(new Vector3(), AssetTemplate.Group);
if (assetIDs != null && assetIDs.Count > 0)
((AssetGRUP)archive.GetFromAssetID(assetIDs[0])).Items = items;
((AssetGRUP)archive.GetFromAssetID(assetIDs[0])).AddItems(CurrentlySelectedAssetIDs());
SetupAssetVisibilityButtons();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static ToolStripMenuItem GetTemplateMenuItem(AssetTemplate template, Even
return item;
}

public static void PopulateTemplateMenusAt(ToolStripMenuItem menu, EventHandler eventHandler)
public static List<ToolStripMenuItem> PopulateTemplateMenusAt(ToolStripMenuItem menu, EventHandler eventHandler)
{
ToolStripMenuItem controllers = new ToolStripMenuItem("Stage Controllers");
controllers.DropDownItems.AddRange(new ToolStripItem[]
Expand Down Expand Up @@ -395,12 +395,34 @@ public static void PopulateTemplateMenusAt(ToolStripMenuItem menu, EventHandler
GetTemplateMenuItem(AssetTemplate.Empty_Streaming_Sound, eventHandler),
});

var paste = GetTemplateMenuItem(AssetTemplate.PasteClipboard, eventHandler);
var paste = GetTemplateMenuItem(AssetTemplate.Paste_Clipboard, eventHandler);

menu.DropDownItems.AddRange(new ToolStripItem[] { controllers, placeable, bfbb, tssm, scooby, incredibles, others, paste });
var items = new ToolStripItem[] { controllers, placeable, bfbb, tssm, scooby, incredibles, others, paste };
menu.DropDownItems.AddRange(items);

var result = new List<ToolStripMenuItem>();
foreach (var i in items)
if (i is ToolStripMenuItem item)
result.AddRange(GetAllItems(item));
return result;
}

private static List<ToolStripMenuItem> GetAllItems(ToolStripMenuItem item)
{
var result = new List<ToolStripMenuItem>();
if (item is ToolStripMenuItem tsmi)
{
if (tsmi.Tag is AssetTemplate)
result.Add(tsmi);
if (tsmi.HasDropDownItems)
foreach (var i in tsmi.DropDownItems)
if (i is ToolStripMenuItem tsmi2)
result.AddRange(GetAllItems(tsmi2));
}
return result;
}

private static string GetName(AssetTemplate template)
public static string GetName(AssetTemplate template)
{
switch (template)
{
Expand Down Expand Up @@ -554,15 +576,7 @@ private static string GetName(AssetTemplate template)
return "Floor Button (Super Smash)";
}

var tstring = template.ToString().Replace('_', ' ');
var result = new List<char>();
for (int i = 0; i < tstring.Length; i++)
{
if (i > 0 && tstring[i] >= 'A' && tstring[i] <= 'Z' && tstring[i-1] != ' ')
result.Add(' ');
result.Add(tstring[i]);
}
return template.ToString();
return template.ToString().Replace('_', ' ');
}

public void SetAssetPositionToView(uint assetID)
Expand Down Expand Up @@ -603,7 +617,7 @@ public void SetAssetPositionToView(uint assetID)

private Asset PlaceUserTemplate(Vector3 position, int layerIndex, ref List<uint> assetIDs, AssetTemplate template)
{
if (template == AssetTemplate.PasteClipboard)
if (template == AssetTemplate.Paste_Clipboard)
PasteAssetsFromClipboard(layerIndex, out assetIDs, dontReplace: true);
else
{
Expand Down Expand Up @@ -669,7 +683,7 @@ public Asset PlaceTemplate(Vector3 position, int layerIndex, ref List<uint> asse
{
if (template == AssetTemplate.Null)
template = CurrentAssetTemplate;
if (template == AssetTemplate.UserTemplate || template == AssetTemplate.PasteClipboard)
if (template == AssetTemplate.User_Template || template == AssetTemplate.Paste_Clipboard)
return PlaceUserTemplate(position, layerIndex, ref assetIDs, template);

bool ignoreNumber = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public InternalAssetEditor(Asset asset, ArchiveEditorFunctions archive)

if (asset is AssetCAM cam) SetupForCam(cam);
//else if (asset is AssetCSN csn) SetupForCsn(csn);
else if (asset is IAssetAddSelected aas) SetupForGrup(aas);
else if (asset is IAssetAddSelected aas) SetupForAddSelected(aas);
else if (asset is AssetRenderWareModel arwm) SetupForModel(arwm);
else if (asset is AssetSHRP shrp) SetupForShrp(shrp);
else if (asset is AssetWIRE wire) SetupForWire(wire);
Expand Down Expand Up @@ -111,7 +111,7 @@ private void SetupForCam(AssetCAM asset)
tableLayoutPanel1.Controls.Add(buttonGetDir);
}

private void SetupForGrup(IAssetAddSelected asset)
private void SetupForAddSelected(IAssetAddSelected asset)
{
AddRow();

Expand Down
4 changes: 2 additions & 2 deletions IndustrialPark/ArchiveEditor/Other/AssetTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
public enum AssetTemplate
{
Null,
PasteClipboard,
UserTemplate,
Paste_Clipboard,
User_Template,

// Controllers
Counter,
Expand Down
1 change: 1 addition & 0 deletions IndustrialPark/Assets/Binary/AssetALST.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public override void Verify(ref List<string> result)
Verify(assetID, ref result);
}

[Browsable(false)]
public string GetItemsText => "entries";

public void AddItems(List<uint> items)
Expand Down
1 change: 1 addition & 0 deletions IndustrialPark/Assets/Binary/AssetCOLL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public void Merge(AssetCOLL asset)
CollisionTable_Entries = entries.ToArray();
}

[Browsable(false)]
public string GetItemsText => "entries";

public void AddItems(List<uint> items)
Expand Down
1 change: 1 addition & 0 deletions IndustrialPark/Assets/Binary/AssetLODT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public void Merge(AssetLODT asset)
LODT_Entries = entries.ToArray();
}

[Browsable(false)]
public string GetItemsText => "entries";

public void AddItems(List<uint> items)
Expand Down
1 change: 1 addition & 0 deletions IndustrialPark/Assets/Binary/AssetPIPT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ public void Merge(AssetPIPT asset)
PIPT_Entries = entries.ToArray();
}

[Browsable(false)]
public string GetItemsText => "entries";

public void AddItems(List<uint> items)
Expand Down
1 change: 1 addition & 0 deletions IndustrialPark/Assets/Binary/AssetSHDW.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public void Merge(AssetSHDW asset)
SHDW_Entries = entries.ToArray();
}

[Browsable(false)]
public string GetItemsText => "entries";

public void AddItems(List<uint> items)
Expand Down
15 changes: 14 additions & 1 deletion IndustrialPark/Assets/DYNA/DynaTypes/DynaGObjectRingControl.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using HipHopFile;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace IndustrialPark
{
Expand All @@ -14,7 +15,7 @@ public enum DynaRingControlPlayerType
SonicWaveGuitar = 5
}

public class DynaGObjectRingControl : AssetDYNA
public class DynaGObjectRingControl : AssetDYNA, IAssetAddSelected
{
private const string dynaCategoryName = "game_object:RingControl";

Expand Down Expand Up @@ -122,5 +123,17 @@ public override void Verify(ref List<string> result)

base.Verify(ref result);
}

[Browsable(false)]
public string GetItemsText => "rings";

public void AddItems(List<uint> items)
{
var rings = Rings.ToList();
foreach (var u in items)
if (!rings.Contains(u))
rings.Add(u);
Rings = rings.ToArray();
}
}
}
1 change: 1 addition & 0 deletions IndustrialPark/Assets/ObjectAssets/AssetSGRP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public override void Verify(ref List<string> result)
}
}

[Browsable(false)]
public string GetItemsText => "entries";

public void AddItems(List<uint> newItems)
Expand Down
81 changes: 68 additions & 13 deletions IndustrialPark/MainForm/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public MainForm()

SetUiAssetsVisibility(false);

ArchiveEditorFunctions.PopulateTemplateMenusAt(toolStripMenuItem_Templates, TemplateToolStripItemClick);
templateButtons = ArchiveEditorFunctions.PopulateTemplateMenusAt(toolStripMenuItem_Templates, TemplateToolStripItemClick);

renderer = new SharpRenderer(renderPanel);
}
Expand Down Expand Up @@ -599,6 +599,10 @@ private void MainForm_KeyDown(object sender, KeyEventArgs e)
DeleteSelectedAssets();
else if (e.KeyCode == Keys.U)
uIModeToolStripMenuItem_Click(null, null);
else if (e.KeyCode == Keys.B)
SelectPreviousTemplate();
else if (e.KeyCode == Keys.N)
SelectNextTemplate();

if (e.KeyCode == Keys.F1)
Program.ViewConfig.Show();
Expand Down Expand Up @@ -883,6 +887,8 @@ private void viewControlsToolStripMenuItem_Click(object sender, EventArgs e)
"Ctrl + (W, A, S, D): rotate view up, left, down, right\n" +
"Q, E: decrease interval, increase interval (view move speed)\n" +
"1, 3: decrease rotation interval, increase rotation interval (view rotation speed)\n" +
"B: select previous template\n" +
"N: select next template\n" +
"C: toggles backface culling\n" +
"F: toggles wireframe mode\n" +
"G: open Asset Data Editor for selected assets\n" +
Expand Down Expand Up @@ -928,9 +934,15 @@ private void renderPanel_MouseClick(object sender, MouseEventArgs e)
{
Vector3 Position = GetScreenClickedPosition(ViewRectangle, e.X, e.Y);

bool placed = false;
foreach (ArchiveEditor archiveEditor in archiveEditors)
if (archiveEditor.TemplateFocus)
{
archiveEditor.PlaceTemplate(Position);
placed = true;
}
if (!placed)
MessageBox.Show($"Your template has not been placed as no Archive Editors have Template Focus on.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else if (e.Button == MouseButtons.Right)
{
Expand Down Expand Up @@ -1303,28 +1315,71 @@ private void ensureAssociationsToolStripMenuItem_Click(object sender, EventArgs
FileAssociations.FileAssociations.EnsureAssociationsSet();
}

private void UnselectTemplateButtonRecursive(ToolStripItem t)
private void UnselectTemplateButtons()
{
foreach (var i in templateButtons)
i.Checked = false;
}

private void SelectPreviousTemplate()
{
if (ArchiveEditorFunctions.CurrentAssetTemplate == AssetTemplate.User_Template)
{
if (toolStripComboBoxUserTemplate.SelectedIndex == 0)
toolStripComboBoxUserTemplate.SelectedIndex = toolStripComboBoxUserTemplate.Items.Count - 1;
else
toolStripComboBoxUserTemplate.SelectedIndex -= 1;
}
else
{
for (int i = 1; i < templateButtons.Count; i++)
{
if (templateButtons[i].Checked)
{
templateButtons[i - 1].PerformClick();
return;
}
}
templateButtons.Last().PerformClick();
}
}

private void SelectNextTemplate()
{
if (t is ToolStripMenuItem toolStripMenuItem)
if (ArchiveEditorFunctions.CurrentAssetTemplate == AssetTemplate.User_Template)
{
if (toolStripMenuItem.HasDropDownItems)
foreach (ToolStripItem ti in toolStripMenuItem.DropDownItems)
UnselectTemplateButtonRecursive(ti);
if (toolStripComboBoxUserTemplate.SelectedIndex == toolStripComboBoxUserTemplate.Items.Count - 1)
toolStripComboBoxUserTemplate.SelectedIndex = 0;
else
toolStripMenuItem.Checked = false;
toolStripComboBoxUserTemplate.SelectedIndex += 1;
}
else
{
for (int i = 0; i < templateButtons.Count - 1; i++)
{
if (templateButtons[i].Checked)
{
templateButtons[i + 1].PerformClick();
return;
}
}
templateButtons[0].PerformClick();
}
}

private List<ToolStripMenuItem> templateButtons;

private void TemplateToolStripItemClick(object sender, EventArgs e)
{
var template = (AssetTemplate)((ToolStripItem)sender).Tag;
var item = (ToolStripMenuItem)sender;
var template = (AssetTemplate)item.Tag;

UnselectTemplateButtonRecursive(toolStripMenuItem_Templates);
UnselectTemplateButtons();

ArchiveEditorFunctions.CurrentAssetTemplate = template;
toolStripStatusLabelTemplate.Text = "Template: " + ArchiveEditorFunctions.CurrentAssetTemplate.ToString();
toolStripStatusLabelTemplate.Text = "Template: " + item.Text;
toolStripComboBoxUserTemplate.SelectedItem = null;
((ToolStripMenuItem)sender).Checked = true;
item.Checked = true;
}

private void userTemplateToolStripMenuItem_Click(object sender, EventArgs e)
Expand All @@ -1349,8 +1404,8 @@ private void toolStripComboBoxUserTemplate_SelectedIndexChanged(object sender, E
{
if (toolStripComboBoxUserTemplate.SelectedIndex != -1)
{
UnselectTemplateButtonRecursive(toolStripMenuItem_Templates);
ArchiveEditorFunctions.CurrentAssetTemplate = AssetTemplate.UserTemplate;
UnselectTemplateButtons();
ArchiveEditorFunctions.CurrentAssetTemplate = AssetTemplate.User_Template;
ArchiveEditorFunctions.CurrentUserTemplate = toolStripComboBoxUserTemplate.SelectedItem.ToString();
toolStripStatusLabelTemplate.Text = $"Template: {toolStripComboBoxUserTemplate.SelectedItem} (User)";
}
Expand Down

0 comments on commit 5c5e435

Please sign in to comment.