Finish adding ability to add things

This commit is contained in:
Li 2023-04-02 01:57:34 +13:00
parent c6248a3a0a
commit 376d2f628e
30 changed files with 162 additions and 35 deletions

View File

@ -15,7 +15,8 @@ namespace LibW4M.Data.Highscores
public override void Create()
{
throw new NotImplementedException();
HighscoreData highscore = new HighscoreData(this.fileBelongs, this.fileBelongs.CreateContainer("HighScoreData"), false);
this.collectiveEntries.Add(highscore);
}
public override void Load()

View File

@ -23,10 +23,14 @@ namespace LibW4M.Data.Highscores
public XomString WinnerName;
public int WinnerTime;
public HighscoreData(W4SaveFile fileBelongs, XomContainer mainContainer) : base(fileBelongs, mainContainer)
public HighscoreData(W4SaveFile fileBelongs, XomContainer mainContainer, bool load = true) : base(fileBelongs, mainContainer, load)
{
}
internal override void loadDefaults()
{
this.WinnerName = fileBelongs.LookupString("Untitled Highscore");
this.WinnerTime = 0;
}
public override void Load()
{
using (XomStreamReader reader = new XomStreamReader(new MemoryStream(mainContainer.GetData())))

View File

@ -29,7 +29,16 @@ namespace LibW4M.Data.InputMapping
}
}
public InputEventMappingData(W4SaveFile fileBelongs, XomContainer mainContainer) : base(fileBelongs, mainContainer)
internal override void loadDefaults()
{
this.Message = fileBelongs.LookupString("Untitled Mapping");
this.FEResourceID = fileBelongs.LookupString("");
this.AllowedDuplacates = new byte[0x0];
this.InputMappings = new InputMappingData[0x0];
this.Group = 0;
}
public InputEventMappingData(W4SaveFile fileBelongs, XomContainer mainContainer, bool load = true) : base(fileBelongs, mainContainer, load)
{
}
public override void DeleteEntries()

View File

@ -17,7 +17,8 @@ namespace LibW4M.Data.InputMapping
public override void Create()
{
throw new NotImplementedException();
InputEventMappingData eventMapping = new InputEventMappingData(this.fileBelongs, this.fileBelongs.CreateContainer("InputEventMappingContainer"), false);
this.collectiveEntries.Add(eventMapping);
}
public override void Load()

View File

@ -10,7 +10,7 @@ namespace LibW4M.Data.InputMapping
{
public class InputMappingData : SaveDataEntry
{
public InputMappingData(W4SaveFile fileBelongs, XomContainer mainContainer) : base(fileBelongs, mainContainer)
public InputMappingData(W4SaveFile fileBelongs, XomContainer mainContainer, bool load = true) : base(fileBelongs, mainContainer, load)
{
}
@ -39,6 +39,13 @@ namespace LibW4M.Data.InputMapping
}
}
internal override void loadDefaults()
{
this.Type = 0;
this.Key = 0;
this.JoystickAxis = 0;
}
public override void Save()
{
using (MemoryStream ms = new MemoryStream())

View File

@ -18,7 +18,8 @@ namespace LibW4M.Data.Stats
public override void Create()
{
throw new NotImplementedException();
StatsContainerData stat = new StatsContainerData(this.fileBelongs, this.fileBelongs.CreateContainer("StatsContainer"), false);
this.collectiveEntries.Add(stat);
}
public override void Load()

View File

@ -12,7 +12,7 @@ namespace LibW4M.Data.Stats
{
public int[] Values;
internal XomString? teamName;
public StatsContainerData(W4SaveFile fileBelongs, XomContainer mainContainer) : base(fileBelongs, mainContainer)
public StatsContainerData(W4SaveFile fileBelongs, XomContainer mainContainer, bool load=true) : base(fileBelongs, mainContainer, load)
{
}
@ -64,6 +64,10 @@ namespace LibW4M.Data.Stats
Values = reader.ReadInt32Array();
}
}
internal override void loadDefaults()
{
this.Values = new int[24];
}
public override void Save()
{

View File

@ -108,7 +108,13 @@ namespace LibW4M.Data.Stats
public override void Create()
{
throw new NotImplementedException();
// create stat container data
StatsContainerData stat = new StatsContainerData(this.fileBelongs, this.fileBelongs.CreateContainer("StatsContainer"), false);
// set team name
stat.teamName = this.fileBelongs.LookupString("Untitled Statistics");
this.TeamNames.Add(stat.teamName);
// add to collective
this.collectiveEntries.Add(stat);
}
}
}

View File

@ -67,6 +67,29 @@ namespace LibW4M.Data.X
}
}
public void CreateInt()
{
intResourceDetails.Add(new IntResourceDetail(this.fileBelongs, this.fileBelongs.CreateContainer("XIntResourceDetails"), false));
}
public void CreateUInt()
{
uintResourceDetails.Add(new UIntResourceDetail(this.fileBelongs, this.fileBelongs.CreateContainer("XUintResourceDetails"), false));
}
public void CreateString()
{
stringResourceDetails.Add(new StringResourceDetail(this.fileBelongs, this.fileBelongs.CreateContainer("XStringResourceDetails"), false));
}
public void CreateFloat()
{
floatResourceDetails.Add(new FloatResourceDetail(this.fileBelongs, this.fileBelongs.CreateContainer("XFloatResourceDetails"), false));
}
public void CreateVector()
{
vectorResourceDetails.Add(new VectorResourceDetail(this.fileBelongs, this.fileBelongs.CreateContainer("XVectorResourceDetails"), false));
}
public void Delete(IntResourceDetail detail)
{

View File

@ -11,7 +11,7 @@ namespace LibW4M.Data.X
public class FloatResourceDetail : ResourceDetail<float>
{
public FloatResourceDetail(W4SaveFile fileBelongs, XomContainer mainContainer) : base(fileBelongs, mainContainer)
public FloatResourceDetail(W4SaveFile fileBelongs, XomContainer mainContainer, bool load = true) : base(fileBelongs, mainContainer, load)
{
}

View File

@ -10,7 +10,7 @@ namespace LibW4M.Data.X
{
public class IntResourceDetail : ResourceDetail<Int32>
{
public IntResourceDetail(W4SaveFile fileBelongs, XomContainer mainContainer) : base(fileBelongs, mainContainer)
public IntResourceDetail(W4SaveFile fileBelongs, XomContainer mainContainer, bool load=true) : base(fileBelongs, mainContainer, load)
{
}
@ -25,6 +25,7 @@ namespace LibW4M.Data.X
}
}
public override void Save()
{
using (MemoryStream ms = new MemoryStream())

View File

@ -20,9 +20,17 @@ namespace LibW4M.Data.X
}
}
public ResourceDetail(W4SaveFile fileBelongs, XomContainer mainContainer) : base(fileBelongs, mainContainer)
public ResourceDetail(W4SaveFile fileBelongs, XomContainer mainContainer, bool load=true) : base(fileBelongs, mainContainer, load)
{
}
internal override void loadDefaults()
{
this.Name = this.fileBelongs.LookupString("Untitled Variable");
this.Flags = 96;
}
public abstract override void Load();
public abstract override void Save();

View File

@ -11,7 +11,7 @@ namespace LibW4M.Data.X
public class StringResourceDetail : ResourceDetail<XomString>
{
public StringResourceDetail(W4SaveFile fileBelongs, XomContainer mainContainer) : base(fileBelongs, mainContainer)
public StringResourceDetail(W4SaveFile fileBelongs, XomContainer mainContainer, bool load = true) : base(fileBelongs, mainContainer, load)
{
}
@ -26,6 +26,11 @@ namespace LibW4M.Data.X
}
}
internal override void loadDefaults()
{
base.loadDefaults();
this.Value = this.fileBelongs.LookupString("");
}
public override void Save()
{
using (MemoryStream ms = new MemoryStream())

View File

@ -11,7 +11,7 @@ namespace LibW4M.Data.X
public class UIntResourceDetail : ResourceDetail<UInt32>
{
public UIntResourceDetail(W4SaveFile fileBelongs, XomContainer mainContainer) : base(fileBelongs, mainContainer)
public UIntResourceDetail(W4SaveFile fileBelongs, XomContainer mainContainer, bool load = true) : base(fileBelongs, mainContainer, load)
{
}

View File

@ -10,7 +10,7 @@ namespace LibW4M.Data.X
{
public class VectorResourceDetail : ResourceDetail<XomVector>
{
public VectorResourceDetail(W4SaveFile fileBelongs, XomContainer mainContainer) : base(fileBelongs, mainContainer)
public VectorResourceDetail(W4SaveFile fileBelongs, XomContainer mainContainer, bool load = true) : base(fileBelongs, mainContainer, load)
{
}
@ -25,6 +25,11 @@ namespace LibW4M.Data.X
}
}
internal override void loadDefaults()
{
base.loadDefaults();
this.Value = new XomVector(0.0f, 0.0f, 0.0f);
}
public override void Save()
{
using (MemoryStream ms = new MemoryStream())

View File

@ -262,6 +262,8 @@ namespace LibW4M
return new byte[0x10] { 0x72, 0x58, 0xDC, 0x7C, 0xA3, 0x2C, 0xCC, 0x4F, 0xAE, 0x66, 0x43, 0x10, 0x71, 0xE5, 0xCE, 0x67 };
case "XFloatResourceDetails":
return new byte[0x10] { 0x5F, 0x9D, 0x88, 0x08, 0x39, 0x80, 0xEA, 0x4C, 0xBA, 0x5B, 0x9C, 0x05, 0x9A, 0xC0, 0x57, 0x0E };
case "XVectorResourceDetails":
return new byte[0x10] { 0x63, 0x45, 0x1F, 0x07, 0xB3, 0x8C, 0x96, 0x49, 0xB7, 0x9F, 0xB0, 0xF5, 0xCA, 0xEC, 0x9D, 0x99 };
case "XContainerResourceDetails":
return new byte[0x10] { 0x20, 0xBF, 0xB6, 0xE0, 0x0B, 0xF8, 0x29, 0x43, 0xB6, 0xEB, 0x19, 0x98, 0xED, 0x8A, 0xEC, 0x1F };
case "XDataBank":
@ -273,7 +275,7 @@ namespace LibW4M
}
}
private int findInStringArray(string str, string[] arr)
private static int findInStringArray(string str, string[] arr)
{
for(int i = 0; i < arr.Length; i++)
{
@ -306,6 +308,7 @@ namespace LibW4M
"XUintResourceDetails",
"XStringResourceDetails",
"XFloatResourceDetails",
"XVectorResourceDetails",
"XContainerResourceDetails",
"XDataBank",
"XContainer"

View File

@ -139,7 +139,7 @@ namespace LibXom.Streams
int padLen = len - str.Length;
if (padLen > 0)
Skip(padLen);
WritePadding(0x00, padLen);
}
public void WriteStr(string str)

View File

@ -45,6 +45,9 @@ namespace W4Gui.Components
if (handler != null)
{
handler(this, e);
if (this.List.Items.Count <= 0)
this.btnDel.Enabled = false;
}
}

View File

@ -15,6 +15,7 @@ namespace W4Gui.Components
{
this.SelectedIndexChanged += selectedIndexChanged;
}
private bool blockEventTriggers = false;
private int totalUntitled = 0;
private int lastSelected = -1;
public int LastSelected
@ -42,19 +43,24 @@ namespace W4Gui.Components
private void unselectWithoutSaveTrigger()
{
toggleEvents();
this.lastSelected = -1;
this.SelectedIndex = -1;
toggleEvents();
}
public event EventHandler<EventArgs> Unselected;
public event EventHandler<EventArgs> Selected;
private void toggleEvents()
{
this.blockEventTriggers = !this.blockEventTriggers;
}
protected virtual void OnUnselected(EventArgs e)
{
EventHandler<EventArgs> handler = Unselected;
if (handler != null)
if (handler != null && !blockEventTriggers)
{
handler(this, e);
}
@ -62,7 +68,7 @@ namespace W4Gui.Components
protected virtual void OnSelected(EventArgs e)
{
EventHandler<EventArgs> handler = Selected;
if (handler != null)
if (handler != null && !blockEventTriggers)
{
handler(this, e);
}
@ -86,11 +92,15 @@ namespace W4Gui.Components
public void Delete(int idx)
{
toggleEvents();
int selIndx = this.SelectedIndex;
unselectWithoutSaveTrigger();
this.Items.RemoveAt(idx);
toggleEvents();
if (selIndx == idx)
{
if((selIndx - 1) < 0 && this.Items.Count > 0)
@ -122,12 +132,20 @@ namespace W4Gui.Components
public void UpdateName(int idx, string name)
{
if (idx >= this.Items.Count) return;
if (idx < 0) return;
if(name != "")
{
toggleEvents();
this.Items[idx] = name;
toggleEvents();
}
}
public void LoadArray(SaveDataEntry[] arr)
{
toggleEvents();
unselectWithoutSaveTrigger();
this.Items.Clear();
for (int i = 0; i < arr.Length; i++)
@ -135,10 +153,12 @@ namespace W4Gui.Components
string name = arr[i].FriendlyName;
this.Items.Add(processName(name));
}
toggleEvents();
}
public void LoadCollective(SaveDataCollective collective)
{
toggleEvents();
unselectWithoutSaveTrigger();
this.Items.Clear();
for (int i = 0; i < collective.Length; i++)
@ -146,6 +166,7 @@ namespace W4Gui.Components
string name = collective[i].FriendlyName;
this.Items.Add(processName(name));
}
toggleEvents();
}
}

View File

@ -198,13 +198,13 @@
this.selInputMappings.Size = new System.Drawing.Size(689, 381);
this.selInputMappings.TabIndex = 0;
//
// InputSettingsPanel
// InputEventMappingPanel
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.LightGray;
this.Controls.Add(this.inputSettingTabControl);
this.Name = "InputSettingsPanel";
this.Name = "InputEventMappingPanel";
this.Size = new System.Drawing.Size(707, 419);
this.inputSettingTabControl.ResumeLayout(false);
this.generalTab.ResumeLayout(false);

View File

@ -50,7 +50,9 @@ namespace W4Gui.Tabs
private void highscoresList_NewButton(object sender, EventArgs e)
{
throw new NotImplementedException("Adding new highscores from here not implemented yet ;)");
DataManager.SaveFile.HighscoreCollective.Create();
highscoresList.List.Add(DataManager.SaveFile.HighscoreCollective.Last().FriendlyName);
highscoresList.List.SelectedIndex = (highscoresList.List.Items.Count - 1);
}
private void highscoresList_DelButton(object sender, EventArgs e)

View File

@ -50,7 +50,9 @@ namespace W4Gui.Tabs
private void inputEventMappingList_NewButton(object sender, EventArgs e)
{
throw new NotImplementedException("Adding new inputEventMapping from here not implemented yet ;)");
DataManager.SaveFile.InputMappingCollective.Create();
inputEventMappingList.List.Add(DataManager.SaveFile.InputMappingCollective.Last().FriendlyName);
inputEventMappingList.List.SelectedIndex = (inputEventMappingList.List.Items.Count - 1);
}
private void inputEventMappingList_DelButton(object sender, EventArgs e)

View File

@ -42,6 +42,8 @@ namespace W4Gui.Tabs.OtherTabs
public void LoadData(ref InputMappingData[] data)
{
this.inputMappingsList.List.LoadArray(data);
this.mappingData.Clear();
inputMappingsPanel.Enabled = false;
mappingData.AddRange(data);
}
@ -62,16 +64,21 @@ namespace W4Gui.Tabs.OtherTabs
private void inputMappingsList_NewButton(object sender, EventArgs e)
{
throw new NotImplementedException("Adding new inputMappings from here not implemented yet ;)");
InputMappingData mapping = new InputMappingData(DataManager.SaveFile, DataManager.SaveFile.CreateContainer("InputDetailsContainer"), false);
this.mappingData.Add(mapping);
this.inputMappingsList.List.Add(mapping.FriendlyName);
}
private void inputMappingsList_DelButton(object sender, EventArgs e)
{
int sel = inputMappingsList.List.CurrentlySelected;
InputMappingData inputMappingsData = mappingData[inputMappingsList.List.CurrentlySelected] as InputMappingData;
inputMappingsData.DeleteEntries();
mappingData.RemoveAt(inputMappingsList.List.CurrentlySelected);
InputMappingData inputMappingsData = mappingData[sel] as InputMappingData;
mappingData.RemoveAt(sel);
inputMappingsList.List.Delete(sel);
inputMappingsData.DeleteEntries();
}
}

View File

@ -50,7 +50,9 @@ namespace W4Gui.Tabs.StatsTab
private void statisticsList_NewButton(object sender, EventArgs e)
{
throw new NotImplementedException("Adding new statistics from here not implemented yet ;)");
DataManager.SaveFile.StatsCollective.Create();
statisticsList.List.Add(DataManager.SaveFile.StatsCollective.Last().FriendlyName);
statisticsList.List.SelectedIndex = (statisticsList.List.Items.Count - 1);
}
private void statisticsList_DelButton(object sender, EventArgs e)

View File

@ -50,7 +50,9 @@ namespace W4Gui.Tabs.StatsTab
private void teamStatisticsList_NewButton(object sender, EventArgs e)
{
throw new NotImplementedException("Adding new team statistics from here not implemented yet ;)");
DataManager.SaveFile.TeamStatsCollective.Create();
teamStatisticsList.List.Add(DataManager.SaveFile.TeamStatsCollective.Last().FriendlyName);
teamStatisticsList.List.SelectedIndex = (teamStatisticsList.List.Items.Count - 1);
}
private void teamStatisticsList_DelButton(object sender, EventArgs e)

View File

@ -53,7 +53,9 @@ namespace W4Gui.Tabs.VariablesTab
private void variablesList_NewButton(object sender, EventArgs e)
{
throw new NotImplementedException("Adding new variables from here not implemented yet ;)");
DataManager.SaveFile.XDataBank.CreateFloat();
variablesList.List.Add(DataManager.SaveFile.XDataBank.FloatResourceDetails.Last().FriendlyName);
variablesList.List.SelectedIndex = (variablesList.List.Items.Count - 1);
}
private void variablesList_DelButton(object sender, EventArgs e)

View File

@ -51,7 +51,9 @@ namespace W4Gui.Tabs.VariablesTab
private void variablesList_NewButton(object sender, EventArgs e)
{
throw new NotImplementedException("Adding new variables from here not implemented yet ;)");
DataManager.SaveFile.XDataBank.CreateInt();
variablesList.List.Add(DataManager.SaveFile.XDataBank.IntResourceDetails.Last().FriendlyName);
variablesList.List.SelectedIndex = (variablesList.List.Items.Count - 1);
}
private void variablesList_DelButton(object sender, EventArgs e)

View File

@ -52,7 +52,9 @@ namespace W4Gui.Tabs.VariablesTab
private void variablesList_NewButton(object sender, EventArgs e)
{
throw new NotImplementedException("Adding new variables from here not implemented yet ;)");
DataManager.SaveFile.XDataBank.CreateString();
variablesList.List.Add(DataManager.SaveFile.XDataBank.StringResourceDetails.Last().FriendlyName);
variablesList.List.SelectedIndex = (variablesList.List.Items.Count - 1);
}
private void variablesList_DelButton(object sender, EventArgs e)

View File

@ -52,7 +52,9 @@ namespace W4Gui.Tabs.VariablesTab
private void variablesList_NewButton(object sender, EventArgs e)
{
throw new NotImplementedException("Adding new variables from here not implemented yet ;)");
DataManager.SaveFile.XDataBank.CreateUInt();
variablesList.List.Add(DataManager.SaveFile.XDataBank.UIntResourceDetails.Last().FriendlyName);
variablesList.List.SelectedIndex = (variablesList.List.Items.Count - 1);
}
private void variablesList_DelButton(object sender, EventArgs e)

View File

@ -52,7 +52,9 @@ namespace W4Gui.Tabs.VariablesTab
private void variablesList_NewButton(object sender, EventArgs e)
{
throw new NotImplementedException("Adding new variables from here not implemented yet ;)");
DataManager.SaveFile.XDataBank.CreateVector();
variablesList.List.Add(DataManager.SaveFile.XDataBank.VectorResourceDetails.Last().FriendlyName);
variablesList.List.SelectedIndex = (variablesList.List.Items.Count - 1);
}
private void variablesList_DelButton(object sender, EventArgs e)