139 lines
3.6 KiB
C#
139 lines
3.6 KiB
C#
|
using LibW4M.Data;
|
|||
|
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;
|
|||
|
|
|||
|
namespace W4Gui.Components
|
|||
|
{
|
|||
|
public partial class CollectiveList : UserControl
|
|||
|
{
|
|||
|
private int lastSelected = -1;
|
|||
|
public int LastSelected
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return lastSelected;
|
|||
|
}
|
|||
|
}
|
|||
|
public int CurrentlySelected
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return lstCollective.SelectedIndex;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public bool IsItemSelected
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return this.CurrentlySelected >= 0;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public event EventHandler<EventArgs> Unselected;
|
|||
|
public event EventHandler<EventArgs> Selected;
|
|||
|
public event EventHandler<EventArgs> NewButton;
|
|||
|
public event EventHandler<EventArgs> DeleteButton;
|
|||
|
public CollectiveList()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
}
|
|||
|
private void unselectWithoutSaveTrigger()
|
|||
|
{
|
|||
|
this.lastSelected = -1;
|
|||
|
lstCollective.SelectedIndex = -1;
|
|||
|
}
|
|||
|
protected virtual void OnNewButton(EventArgs e)
|
|||
|
{
|
|||
|
EventHandler<EventArgs> handler = NewButton;
|
|||
|
if (handler != null)
|
|||
|
{
|
|||
|
handler(this, e);
|
|||
|
}
|
|||
|
}
|
|||
|
protected virtual void OnDeleteButton(EventArgs e)
|
|||
|
{
|
|||
|
EventHandler<EventArgs> handler = DeleteButton;
|
|||
|
if (handler != null)
|
|||
|
{
|
|||
|
handler(this, e);
|
|||
|
}
|
|||
|
}
|
|||
|
protected virtual void OnUnselected(EventArgs e)
|
|||
|
{
|
|||
|
EventHandler<EventArgs> handler = Unselected;
|
|||
|
if (handler != null)
|
|||
|
{
|
|||
|
handler(this, e);
|
|||
|
}
|
|||
|
}
|
|||
|
private string formatName(string name)
|
|||
|
{
|
|||
|
return (name);
|
|||
|
}
|
|||
|
protected virtual void OnSelected(EventArgs e)
|
|||
|
{
|
|||
|
EventHandler<EventArgs> handler = Selected;
|
|||
|
if (handler != null)
|
|||
|
{
|
|||
|
handler(this, e);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void lstCollective_SelectedIndexChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (LastSelected >= 0 && LastSelected != CurrentlySelected)
|
|||
|
OnUnselected(e);
|
|||
|
|
|||
|
if (CurrentlySelected >= 0 && LastSelected != CurrentlySelected)
|
|||
|
OnSelected(e);
|
|||
|
|
|||
|
lastSelected = CurrentlySelected;
|
|||
|
}
|
|||
|
|
|||
|
private void btnAdd_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
OnNewButton(e);
|
|||
|
}
|
|||
|
|
|||
|
private void btnDel_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (lstCollective.SelectedIndex >= 0)
|
|||
|
OnDeleteButton(e);
|
|||
|
}
|
|||
|
|
|||
|
public void Add(string name)
|
|||
|
{
|
|||
|
lstCollective.Items.Add(formatName(name));
|
|||
|
}
|
|||
|
|
|||
|
public void Delete(int idx)
|
|||
|
{
|
|||
|
unselectWithoutSaveTrigger();
|
|||
|
lstCollective.Items.RemoveAt(idx);
|
|||
|
}
|
|||
|
|
|||
|
public void UpdateName(int idx, string name)
|
|||
|
{
|
|||
|
lstCollective.Items[idx] = formatName(name);
|
|||
|
}
|
|||
|
public void LoadCollective(SaveDataCollective collective)
|
|||
|
{
|
|||
|
unselectWithoutSaveTrigger();
|
|||
|
lstCollective.Items.Clear();
|
|||
|
for (int i = 0; i < collective.Length; i++)
|
|||
|
{
|
|||
|
string name = collective[i].FriendlyName;
|
|||
|
lstCollective.Items.Add(formatName(name));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|