DropEditor: Implement multiple selection and display intersection

This commit is contained in:
2022-10-26 21:56:30 +08:00
parent 60e54b1c91
commit 74613a809d
3 changed files with 98 additions and 26 deletions

View File

@ -37,6 +37,7 @@
this.TxtItemFilter = new System.Windows.Forms.TextBox();
this.ListDropData = new System.Windows.Forms.ListBox();
this.GrpDropList = new System.Windows.Forms.GroupBox();
this.BtnCopyAll = new System.Windows.Forms.Button();
this.BtnClear = new System.Windows.Forms.Button();
this.BtnPaste = new System.Windows.Forms.Button();
this.BtnCopy = new System.Windows.Forms.Button();
@ -55,7 +56,6 @@
this.ListItems = new System.Windows.Forms.ListBox();
this.GrpMonsterList = new System.Windows.Forms.GroupBox();
this.GrpItemList = new System.Windows.Forms.GroupBox();
this.BtnCopyAll = new System.Windows.Forms.Button();
this.GrpDropList.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.NUDMaxWeight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.NUDMinWeight)).BeginInit();
@ -110,6 +110,7 @@
this.ListMonsters.ItemHeight = 17;
this.ListMonsters.Location = new System.Drawing.Point(6, 51);
this.ListMonsters.Name = "ListMonsters";
this.ListMonsters.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
this.ListMonsters.Size = new System.Drawing.Size(238, 344);
this.ListMonsters.TabIndex = 4;
this.ListMonsters.SelectedIndexChanged += new System.EventHandler(this.ListMonsters_SelectedIndexChanged);
@ -176,6 +177,17 @@
this.GrpDropList.TabStop = false;
this.GrpDropList.Text = "掉落列表";
//
// BtnCopyAll
//
this.BtnCopyAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.BtnCopyAll.Location = new System.Drawing.Point(87, 202);
this.BtnCopyAll.Name = "BtnCopyAll";
this.BtnCopyAll.Size = new System.Drawing.Size(75, 23);
this.BtnCopyAll.TabIndex = 22;
this.BtnCopyAll.Text = "复制全部";
this.BtnCopyAll.UseVisualStyleBackColor = true;
this.BtnCopyAll.Click += new System.EventHandler(this.BtnCopyAll_Click);
//
// BtnClear
//
this.BtnClear.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
@ -410,17 +422,6 @@
this.GrpItemList.TabStop = false;
this.GrpItemList.Text = "物品列表";
//
// BtnCopyAll
//
this.BtnCopyAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.BtnCopyAll.Location = new System.Drawing.Point(87, 202);
this.BtnCopyAll.Name = "BtnCopyAll";
this.BtnCopyAll.Size = new System.Drawing.Size(75, 23);
this.BtnCopyAll.TabIndex = 22;
this.BtnCopyAll.Text = "复制全部";
this.BtnCopyAll.UseVisualStyleBackColor = true;
this.BtnCopyAll.Click += new System.EventHandler(this.BtnCopyAll_Click);
//
// FormDropEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);

View File

@ -10,14 +10,32 @@ using GrasscutterTools.Properties;
using Newtonsoft.Json;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
namespace GrasscutterTools.Forms
{
public partial class FormDropEditor : Form
{
#region - -
/// <summary>
/// 掉落池
/// Key:怪物ID
/// Value:掉落列表
/// </summary>
private Dictionary<int, List<DropData>> Banners;
/// <summary>
/// 怪物集
/// </summary>
private readonly string[] Monsters;
/// <summary>
/// 当前选中项的掉落列表
/// (当选中多条时,数据为交集)
/// </summary>
private readonly List<DropData> DropList = new List<DropData>();
#endregion - -
#region - -
@ -28,7 +46,12 @@ namespace GrasscutterTools.Forms
Icon = Resources.IconGrasscutter;
ListMonsters.Items.AddRange(GameData.Monsters.Lines);
Monsters = new string[GameData.Monsters.Lines.Length + GameData.Animals.Lines.Length];
GameData.Monsters.Lines.CopyTo(Monsters, 0);
GameData.Animals.Lines.CopyTo(Monsters, GameData.Monsters.Lines.Length);
Array.Sort(Monsters);
ListMonsters.Items.AddRange(Monsters);
ListItems.Items.AddRange(GameData.Items.Lines);
Banners = new Dictionary<int, List<DropData>>();
@ -158,7 +181,7 @@ namespace GrasscutterTools.Forms
var filter = TxtMonsterFilter.Text.Trim();
ListMonsters.BeginUpdate();
ListMonsters.Items.Clear();
ListMonsters.Items.AddRange(GameData.Monsters.Lines.Where(n => n.Contains(filter)).ToArray());
ListMonsters.Items.AddRange(Monsters.Where(n => n.Contains(filter)).ToArray());
ListMonsters.EndUpdate();
}
@ -167,13 +190,61 @@ namespace GrasscutterTools.Forms
/// </summary>
private void ListMonsters_SelectedIndexChanged(object sender, EventArgs e)
{
var monster = ListMonsters.SelectedItem as string;
if (string.IsNullOrEmpty(monster)) return;
var id = int.Parse(monster.Substring(0, monster.IndexOf(':')).Trim());
if (ListMonsters.SelectedItems.Count == 0) return;
// 掉落物列表标题显示
var sp = GrpDropList.Text.IndexOf(" | ");
if (sp >= 0) GrpDropList.Text = GrpDropList.Text.Remove(sp);
if (ListMonsters.SelectedItems.Count == 1)
{
var item = ListMonsters.SelectedItem as string;
GrpDropList.Text += " | " + item;
}
else
{
GrpDropList.Text += " | Monsters x" + ListMonsters.SelectedItems.Count.ToString();
}
// 获取选中项中相同的掉落物集合(仅物品、掉落数量、掉落概率完全一致的显示)
DropList.Clear();
var first = true;
foreach (string item in ListMonsters.SelectedItems)
{
var monsterId = int.Parse(item.Substring(0, item.IndexOf(':')).Trim());
if (Banners.TryGetValue(monsterId, out List<DropData> dropList))
{
if (first)
{
DropList.AddRange(dropList);
first = false;
}
else if (DropList.Count > 0)
{
// 仅保留交集
var intersect = DropList.Intersect(dropList).ToList();
DropList.Clear();
DropList.AddRange(intersect);
}
else
{
break;
}
}
else
{
DropList.Clear();
break;
}
}
// 显示到列表
ListDropData.BeginUpdate();
ListDropData.Items.Clear();
if (Banners.TryGetValue(id, out List<DropData> dropList))
ListDropData.Items.AddRange(dropList.ToArray());
if (DropList.Count > 0)
{
ListDropData.Items.AddRange(DropList.Select(it => it.ToString()).ToArray());
ListDropData.SelectedIndex = 0;
}
ListDropData.EndUpdate();
}
@ -186,8 +257,10 @@ namespace GrasscutterTools.Forms
/// </summary>
private void ListDropData_SelectedIndexChanged(object sender, EventArgs e)
{
var dropData = ListDropData.SelectedItem as DropData;
if (dropData == null) return;
if (ListDropData.SelectedIndex == -1) return;
var dropData = DropList[ListDropData.SelectedIndex];
TxtItem.Text = $"{dropData.ItemId} : {GameData.Items[dropData.ItemId]}";
NUDMinCount.Value = dropData.MinCount;
NUDMaxCount.Value = dropData.MaxCount;
@ -244,9 +317,7 @@ namespace GrasscutterTools.Forms
/// </summary>
private void ListItems_SelectedIndexChanged(object sender, EventArgs e)
{
var item = ListItems.SelectedItem as string;
if (string.IsNullOrEmpty(item)) return;
TxtItem.Text = item;
TxtItem.Text = ListItems.SelectedItem as string;
}
#endregion - -

View File

@ -2,7 +2,7 @@
namespace GrasscutterTools.Game.Drop
{
public class DropData
public struct DropData
{
/// <summary>
/// 物品ID