Skip to content

Commit

Permalink
Improved display of event entities + new event importer
Browse files Browse the repository at this point in the history
  • Loading branch information
AdAstra-LD committed Sep 3, 2022
1 parent 034f338 commit 6b95302
Show file tree
Hide file tree
Showing 10 changed files with 2,648 additions and 311 deletions.
9 changes: 9 additions & 0 deletions DS_Map/DSPRE.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AB.cs" />
<Compile Include="EventFileImport.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="EventFileImport.designer.cs">
<DependentUpon>EventFileImport.cs</DependentUpon>
</Compile>
<Compile Include="Extensions.cs" />
<Compile Include="GameCamera.cs" />
<Compile Include="Properties\Resources.Designer.cs">
Expand Down Expand Up @@ -263,6 +269,9 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources\writeText.Designer.cs" />
<EmbeddedResource Include="EventFileImport.resx">
<DependentUpon>EventFileImport.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="HeaderSearch.resx">
<DependentUpon>HeaderSearch.cs</DependentUpon>
</EmbeddedResource>
Expand Down
338 changes: 338 additions & 0 deletions DS_Map/EventFileImport.Designer.cs

Large diffs are not rendered by default.

96 changes: 96 additions & 0 deletions DS_Map/EventFileImport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using DSPRE;
using DSPRE.ROMFiles;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using static DSPRE.ROMFiles.EventFile;

namespace DSPRE {
public partial class EventFileImport : Form {
private static readonly int eventTypesCount = Enum.GetValues(typeof(serializationOrder)).Length;

private readonly bool[] toImport = new bool[eventTypesCount];
private readonly CheckedListBox[] listBoxes;
private readonly Button[,] checkButtons;

public readonly int[][] userSelected = new int[eventTypesCount][];

public EventFileImport(EventFile ef) {
InitializeComponent();

for(int i = 0; i < toImport.Length; i++) {
toImport[i] = true;
}

listBoxes = new CheckedListBox[] {
spawnablesCheckedListBox,
overworldsCheckedListBox,
warpsCheckedListBox,
triggersCheckedListBox
};

checkButtons = new Button[4, 2] {
{ spawnablesCheckAllButton, spawnablesUncheckAllButton },
{ overworldsCheckAllButton, overworldsUncheckAllButton },
{ warpsCheckAllButton, warpsUncheckAllButton },
{ triggersCheckAllButton, triggersUncheckAllButton }
};

foreach (Spawnable s in ef.spawnables) {
listBoxes[(int)serializationOrder.Spawnables].Items.Add(s);
}
foreach (Overworld ow in ef.overworlds) {
listBoxes[(int)serializationOrder.Overworlds].Items.Add(ow);
}
foreach (Warp w in ef.warps) {
listBoxes[(int)serializationOrder.Warps].Items.Add(w);
}
foreach (Trigger t in ef.triggers) {
listBoxes[(int)serializationOrder.Triggers].Items.Add(t);
}

foreach (CheckedListBox clb in listBoxes) {
clb.SetAllItemsChecked(true);
}
}

private void confirmButton_Click(object sender, EventArgs e) {
bool ok = false;
for (int i = 0; i < toImport.Length; i++) {
if (toImport[i] && listBoxes[i].CheckedItems.Count > 0) {
userSelected[i] = listBoxes[i].CheckedIndices.Cast<int>().ToArray();
if (userSelected[i].Length > 0) {
ok = true;
}
}
}

if (ok) {
DialogResult = DialogResult.OK;
this.Dispose();
return;
}
MessageBox.Show("You must tick at least one element.", "No selection performed", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

private void importCheckBoxChanged(object sender, EventArgs e) {
//Changing the checkboxes' columns in the GUI will break this
CheckBox c = sender as CheckBox;
int typeIndex = tableLayoutPanel1.GetPositionFromControl(c).Column;
bool v = toImport[typeIndex / 2] =
listBoxes[typeIndex / 2].Enabled
= c.Checked;

for (int i = 0; i < 2; i++) {
checkButtons[typeIndex / 2, i].Enabled = v;
}
}
private void checkAllButtonClicked(object sender, EventArgs e) {
listBoxes[tableLayoutPanel1.GetPositionFromControl(sender as Button).Column / 2].SetAllItemsChecked(true);
}
private void uncheckAllButtonClicked(object sender, EventArgs e) {
listBoxes[tableLayoutPanel1.GetPositionFromControl(sender as Button).Column / 2].SetAllItemsChecked(false);
}
}
}
Loading

0 comments on commit 6b95302

Please sign in to comment.