Worms4Editor/W4Gui/Tabs/WeaponsTab.cs

71 lines
2.6 KiB
C#

using LibW4M.Data.Teams;
using LibW4M.Data.WeaponFactory;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using W4Gui.Components;
namespace W4Gui.Tabs
{
public partial class WeaponsTab : TabEntry
{
public override void SaveFromControl()
{
if(weaponList.List.IsItemSelected)
weaponList_Unselected(null, null);
}
public override void LoadIntoControl()
{
weaponList.List.LoadCollective(DataManager.SaveFile.WeaponFactoryCollective);
weaponClusterTabControl.Enabled = false;
}
public WeaponsTab()
{
InitializeComponent();
this.weaponList.List.Selected += weaponList_Selected;
this.weaponList.List.Unselected += weaponList_Unselected;
}
private void weaponList_Unselected(object sender, EventArgs e)
{
WeaponStore store = DataManager.SaveFile.WeaponFactoryCollective[weaponList.List.LastSelected] as WeaponStore;
weaponPanel.SaveWeaponData(ref store.Weapon);
clusterPanel.SaveWeaponData(ref store.Cluster);
store.StockWeapon = selStockWeapon.Checked;
weaponList.List.UpdateName(weaponList.List.LastSelected, store.Weapon.Name.Value);
}
private void weaponList_Selected(object sender, EventArgs e)
{
WeaponStore store = DataManager.SaveFile.WeaponFactoryCollective[weaponList.List.CurrentlySelected] as WeaponStore;
weaponPanel.LoadWeaponData(store.Weapon);
clusterPanel.LoadWeaponData(store.Cluster);
selStockWeapon.Checked = store.StockWeapon;
weaponClusterTabControl.Enabled = true;
}
private void weaponList_NewButton(object sender, EventArgs e)
{
DataManager.SaveFile.WeaponFactoryCollective.Create();
weaponList.List.Add(DataManager.SaveFile.WeaponFactoryCollective.Last().FriendlyName);
weaponList.List.SelectedIndex = (weaponList.List.Items.Count - 1);
}
private void weaponList_DeleteButton(object sender, EventArgs e)
{
int sel = weaponList.List.CurrentlySelected;
WeaponStore store = DataManager.SaveFile.WeaponFactoryCollective[sel] as WeaponStore;
DataManager.SaveFile.WeaponFactoryCollective.Delete(store);
weaponList.List.Delete(sel);
}
}
}