Worms4Editor/W4Gui/Tabs/HighscoresTab.cs

68 lines
2.4 KiB
C#

using LibW4M.Data.Highscores;
using LibW4M.Data.Teams;
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.Tabs
{
public partial class HighscoresTab : TabEntry
{
public HighscoresTab()
{
InitializeComponent();
this.highscoresList.List.Selected += highscoresList_Selected;
this.highscoresList.List.Unselected += highscoresList_Unselected;
}
public override void SaveFromControl()
{
if (this.highscoresList.List.IsItemSelected)
highscoresList_Unselected(null, null);
}
public override void LoadIntoControl()
{
this.highscoresList.List.LoadCollective(DataManager.SaveFile.HighscoreCollective);
highscoresPanel.Enabled = false;
}
private void highscoresList_Unselected(object? sender, EventArgs e)
{
HighscoreData highscoreData = DataManager.SaveFile.HighscoreCollective[highscoresList.List.LastSelected] as HighscoreData;
highscoresPanel.SaveHighscoreData(ref highscoreData);
highscoresList.List.UpdateName(highscoresList.List.LastSelected, highscoreData.FriendlyName);
}
private void highscoresList_Selected(object? sender, EventArgs e)
{
HighscoreData highscoreData = DataManager.SaveFile.HighscoreCollective[highscoresList.List.CurrentlySelected] as HighscoreData;
highscoresPanel.LoadHighscoreData(highscoreData);
highscoresPanel.Enabled = true;
}
private void highscoresList_NewButton(object sender, EventArgs e)
{
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)
{
int sel = highscoresList.List.CurrentlySelected;
HighscoreData highscoreData = DataManager.SaveFile.HighscoreCollective[sel] as HighscoreData;
DataManager.SaveFile.HighscoreCollective.Delete(highscoreData);
highscoresList.List.Delete(sel);
}
}
}