mirror of
https://github.com/jie65535/GrasscutterCommandGenerator.git
synced 2025-08-02 16:59:14 +08:00
Implement drop editor functions
This commit is contained in:
parent
74613a809d
commit
7d19876072
@ -85,7 +85,7 @@
|
||||
//
|
||||
this.BtnLoad.Location = new System.Drawing.Point(621, 12);
|
||||
this.BtnLoad.Name = "BtnLoad";
|
||||
this.BtnLoad.Size = new System.Drawing.Size(75, 23);
|
||||
this.BtnLoad.Size = new System.Drawing.Size(100, 23);
|
||||
this.BtnLoad.TabIndex = 2;
|
||||
this.BtnLoad.Text = "加载";
|
||||
this.BtnLoad.UseVisualStyleBackColor = true;
|
||||
@ -93,9 +93,9 @@
|
||||
//
|
||||
// BtnSave
|
||||
//
|
||||
this.BtnSave.Location = new System.Drawing.Point(702, 12);
|
||||
this.BtnSave.Location = new System.Drawing.Point(726, 12);
|
||||
this.BtnSave.Name = "BtnSave";
|
||||
this.BtnSave.Size = new System.Drawing.Size(75, 23);
|
||||
this.BtnSave.Size = new System.Drawing.Size(100, 23);
|
||||
this.BtnSave.TabIndex = 3;
|
||||
this.BtnSave.Text = "保存";
|
||||
this.BtnSave.UseVisualStyleBackColor = true;
|
||||
@ -182,7 +182,7 @@
|
||||
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.Size = new System.Drawing.Size(100, 23);
|
||||
this.BtnCopyAll.TabIndex = 22;
|
||||
this.BtnCopyAll.Text = "复制全部";
|
||||
this.BtnCopyAll.UseVisualStyleBackColor = true;
|
||||
@ -191,9 +191,9 @@
|
||||
// BtnClear
|
||||
//
|
||||
this.BtnClear.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.BtnClear.Location = new System.Drawing.Point(87, 230);
|
||||
this.BtnClear.Location = new System.Drawing.Point(113, 230);
|
||||
this.BtnClear.Name = "BtnClear";
|
||||
this.BtnClear.Size = new System.Drawing.Size(75, 23);
|
||||
this.BtnClear.Size = new System.Drawing.Size(100, 23);
|
||||
this.BtnClear.TabIndex = 21;
|
||||
this.BtnClear.Text = "× 清空";
|
||||
this.BtnClear.UseVisualStyleBackColor = true;
|
||||
@ -202,9 +202,9 @@
|
||||
// BtnPaste
|
||||
//
|
||||
this.BtnPaste.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.BtnPaste.Location = new System.Drawing.Point(168, 202);
|
||||
this.BtnPaste.Location = new System.Drawing.Point(193, 202);
|
||||
this.BtnPaste.Name = "BtnPaste";
|
||||
this.BtnPaste.Size = new System.Drawing.Size(75, 23);
|
||||
this.BtnPaste.Size = new System.Drawing.Size(100, 23);
|
||||
this.BtnPaste.TabIndex = 20;
|
||||
this.BtnPaste.Text = "粘贴";
|
||||
this.BtnPaste.UseVisualStyleBackColor = true;
|
||||
@ -232,9 +232,9 @@
|
||||
// BtnDelete
|
||||
//
|
||||
this.BtnDelete.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.BtnDelete.Location = new System.Drawing.Point(6, 230);
|
||||
this.BtnDelete.Location = new System.Drawing.Point(7, 230);
|
||||
this.BtnDelete.Name = "BtnDelete";
|
||||
this.BtnDelete.Size = new System.Drawing.Size(75, 23);
|
||||
this.BtnDelete.Size = new System.Drawing.Size(100, 23);
|
||||
this.BtnDelete.TabIndex = 18;
|
||||
this.BtnDelete.Text = "- 删除";
|
||||
this.BtnDelete.UseVisualStyleBackColor = true;
|
||||
@ -247,7 +247,7 @@
|
||||
this.BtnAddOrUpdate.Name = "BtnAddOrUpdate";
|
||||
this.BtnAddOrUpdate.Size = new System.Drawing.Size(196, 23);
|
||||
this.BtnAddOrUpdate.TabIndex = 17;
|
||||
this.BtnAddOrUpdate.Text = "+ 添加";
|
||||
this.BtnAddOrUpdate.Text = "√ 添加或更新";
|
||||
this.BtnAddOrUpdate.UseVisualStyleBackColor = true;
|
||||
this.BtnAddOrUpdate.Click += new System.EventHandler(this.BtnAddOrUpdate_Click);
|
||||
//
|
||||
@ -322,7 +322,7 @@
|
||||
this.NUDMaxCount.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.NUDMaxCount.Location = new System.Drawing.Point(190, 311);
|
||||
this.NUDMaxCount.Maximum = new decimal(new int[] {
|
||||
10000,
|
||||
1000000,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
|
@ -7,6 +7,7 @@ using System.Windows.Forms;
|
||||
using GrasscutterTools.Game;
|
||||
using GrasscutterTools.Game.Drop;
|
||||
using GrasscutterTools.Properties;
|
||||
using GrasscutterTools.Utils;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
@ -34,7 +35,12 @@ namespace GrasscutterTools.Forms
|
||||
/// 当前选中项的掉落列表
|
||||
/// (当选中多条时,数据为交集)
|
||||
/// </summary>
|
||||
private readonly List<DropData> DropList = new List<DropData>();
|
||||
private readonly List<DropData> SelectedDropList = new List<DropData>();
|
||||
|
||||
/// <summary>
|
||||
/// 掉落物剪贴板
|
||||
/// </summary>
|
||||
private readonly List<DropData> DropClipboard = new List<DropData>();
|
||||
|
||||
#endregion - 成员 -
|
||||
|
||||
@ -185,6 +191,15 @@ namespace GrasscutterTools.Forms
|
||||
ListMonsters.EndUpdate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 遍历选中项怪物Id集合
|
||||
/// </summary>
|
||||
private IEnumerable<int> SelectedMonsterIds()
|
||||
{
|
||||
foreach (string item in ListMonsters.SelectedItems)
|
||||
yield return int.Parse(item.Substring(0, item.IndexOf(':')).Trim());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 怪物列表选中项改变时触发
|
||||
/// </summary>
|
||||
@ -206,24 +221,23 @@ namespace GrasscutterTools.Forms
|
||||
}
|
||||
|
||||
// 获取选中项中相同的掉落物集合(仅物品、掉落数量、掉落概率完全一致的显示)
|
||||
DropList.Clear();
|
||||
SelectedDropList.Clear();
|
||||
var first = true;
|
||||
foreach (string item in ListMonsters.SelectedItems)
|
||||
foreach (var monsterId in SelectedMonsterIds())
|
||||
{
|
||||
var monsterId = int.Parse(item.Substring(0, item.IndexOf(':')).Trim());
|
||||
if (Banners.TryGetValue(monsterId, out List<DropData> dropList))
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
DropList.AddRange(dropList);
|
||||
SelectedDropList.AddRange(dropList);
|
||||
first = false;
|
||||
}
|
||||
else if (DropList.Count > 0)
|
||||
else if (SelectedDropList.Count > 0)
|
||||
{
|
||||
// 仅保留交集
|
||||
var intersect = DropList.Intersect(dropList).ToList();
|
||||
DropList.Clear();
|
||||
DropList.AddRange(intersect);
|
||||
var intersect = SelectedDropList.Intersect(dropList).ToList();
|
||||
SelectedDropList.Clear();
|
||||
SelectedDropList.AddRange(intersect);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -232,17 +246,26 @@ namespace GrasscutterTools.Forms
|
||||
}
|
||||
else
|
||||
{
|
||||
DropList.Clear();
|
||||
SelectedDropList.Clear();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ShowDropList(SelectedDropList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 显示指定掉落列表
|
||||
/// </summary>
|
||||
/// <param name="dropList">掉落物列表</param>
|
||||
private void ShowDropList(List<DropData> dropList)
|
||||
{
|
||||
// 显示到列表
|
||||
ListDropData.BeginUpdate();
|
||||
ListDropData.Items.Clear();
|
||||
if (DropList.Count > 0)
|
||||
if (dropList.Count > 0)
|
||||
{
|
||||
ListDropData.Items.AddRange(DropList.Select(it => it.ToString()).ToArray());
|
||||
ListDropData.Items.AddRange(dropList.Select(it => it.ToString()).ToArray());
|
||||
ListDropData.SelectedIndex = 0;
|
||||
}
|
||||
ListDropData.EndUpdate();
|
||||
@ -259,7 +282,7 @@ namespace GrasscutterTools.Forms
|
||||
{
|
||||
if (ListDropData.SelectedIndex == -1) return;
|
||||
|
||||
var dropData = DropList[ListDropData.SelectedIndex];
|
||||
var dropData = SelectedDropList[ListDropData.SelectedIndex];
|
||||
|
||||
TxtItem.Text = $"{dropData.ItemId} : {GameData.Items[dropData.ItemId]}";
|
||||
NUDMinCount.Value = dropData.MinCount;
|
||||
@ -272,30 +295,188 @@ namespace GrasscutterTools.Forms
|
||||
//BtnAddOrUpdate.Enabled = true;
|
||||
}
|
||||
|
||||
private void BtnCopy_Click(object sender, EventArgs e)
|
||||
/// <summary>
|
||||
/// 点击复制按钮时触发
|
||||
/// </summary>
|
||||
private async void BtnCopy_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ListDropData.SelectedIndex == -1) return;
|
||||
DropClipboard.Clear();
|
||||
DropClipboard.Add(SelectedDropList[ListDropData.SelectedIndex]);
|
||||
await UIUtil.ButtonComplete(BtnCopy);
|
||||
}
|
||||
|
||||
private void BtnCopyAll_Click(object sender, EventArgs e)
|
||||
/// <summary>
|
||||
/// 点击复制全部按钮时触发
|
||||
/// </summary>
|
||||
private async void BtnCopyAll_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (SelectedDropList.Count == 0) return;
|
||||
DropClipboard.Clear();
|
||||
DropClipboard.AddRange(SelectedDropList);
|
||||
await UIUtil.ButtonComplete(BtnCopyAll);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 点击粘贴按钮时触发
|
||||
/// </summary>
|
||||
private void BtnPaste_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (DropClipboard.Count == 0) return;
|
||||
foreach (var item in DropClipboard)
|
||||
AddOrUpdateDrop(item);
|
||||
ShowDropList(SelectedDropList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 点击删除按钮时触发
|
||||
/// </summary>
|
||||
private void BtnDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ListDropData.SelectedIndex == -1) return;
|
||||
|
||||
var dropData = SelectedDropList[ListDropData.SelectedIndex];
|
||||
RemoveDrop(dropData);
|
||||
ShowDropList(SelectedDropList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 点击清空按钮时触发
|
||||
/// </summary>
|
||||
private void BtnClear_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (SelectedDropList.Count == 0)
|
||||
return;
|
||||
if (MessageBox.Show(Resources.AskConfirmDeletion, Resources.Tips, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
for (int i = SelectedDropList.Count - 1; i >= 0; i--)
|
||||
RemoveDrop(SelectedDropList[i]);
|
||||
ShowDropList(SelectedDropList);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 点击添加或更新按钮时触发
|
||||
/// </summary>
|
||||
private void BtnAddOrUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ListMonsters.SelectedItems.Count == 0)
|
||||
return;
|
||||
try
|
||||
{
|
||||
AddOrUpdateDrop(GetInput());
|
||||
}
|
||||
catch (FormatException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
ShowDropList(SelectedDropList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取输入
|
||||
/// </summary>
|
||||
/// <returns>掉落物信息</returns>
|
||||
private DropData GetInput()
|
||||
{
|
||||
var dropData = new DropData();
|
||||
|
||||
var item = TxtItem.Text;
|
||||
dropData.ItemId = int.Parse(item.Substring(0, item.IndexOf(':')).Trim());
|
||||
//if (int.TryParse(item.Substring(0, item.IndexOf(':')).Trim(), out int itemId))
|
||||
//{
|
||||
// dropData.ItemId = itemId;
|
||||
//}
|
||||
|
||||
if (NUDMaxCount.Value < NUDMinCount.Value)
|
||||
{
|
||||
dropData.MinCount = (int)NUDMaxCount.Value;
|
||||
dropData.MaxCount = (int)NUDMinCount.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
dropData.MinCount = (int)NUDMinCount.Value;
|
||||
dropData.MaxCount = (int)NUDMaxCount.Value;
|
||||
}
|
||||
|
||||
if (NUDMaxWeight.Value < NUDMinWeight.Value)
|
||||
{
|
||||
dropData.MinWeight = (int)NUDMaxWeight.Value;
|
||||
dropData.MaxWeight = (int)NUDMinWeight.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
dropData.MinWeight = (int)NUDMinWeight.Value;
|
||||
dropData.MaxWeight = (int)NUDMaxWeight.Value;
|
||||
}
|
||||
|
||||
return dropData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加或更新掉落物到当前选中项
|
||||
/// </summary>
|
||||
/// <param name="data">掉落物信息</param>
|
||||
private void AddOrUpdateDrop(DropData data)
|
||||
{
|
||||
if (ListMonsters.SelectedItems.Count == 0)
|
||||
return;
|
||||
|
||||
foreach (var monsterId in SelectedMonsterIds())
|
||||
{
|
||||
if (!Banners.TryGetValue(monsterId, out List<DropData> dropList))
|
||||
{
|
||||
dropList = new List<DropData>();
|
||||
Banners[monsterId] = dropList;
|
||||
}
|
||||
|
||||
AddOrUpdateDrop(dropList, data);
|
||||
}
|
||||
|
||||
AddOrUpdateDrop(SelectedDropList, data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从当前选中项移除掉落物
|
||||
/// </summary>
|
||||
/// <param name="data">掉落物信息</param>
|
||||
private void RemoveDrop(DropData data)
|
||||
{
|
||||
if (ListMonsters.SelectedItems.Count == 0)
|
||||
return;
|
||||
|
||||
foreach (var monsterId in SelectedMonsterIds())
|
||||
{
|
||||
if (!Banners.TryGetValue(monsterId, out List<DropData> dropList))
|
||||
{
|
||||
dropList = new List<DropData>();
|
||||
Banners[monsterId] = dropList;
|
||||
}
|
||||
|
||||
dropList.Remove(data);
|
||||
}
|
||||
|
||||
SelectedDropList.Remove(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加或更新掉落物到指定列表中
|
||||
/// </summary>
|
||||
/// <param name="dropList">掉落物列表</param>
|
||||
/// <param name="data">掉落物信息</param>
|
||||
private void AddOrUpdateDrop(List<DropData> dropList, DropData data)
|
||||
{
|
||||
int i = 0;
|
||||
for (; i < dropList.Count; i++)
|
||||
if (dropList[i].ItemId == data.ItemId)
|
||||
break;
|
||||
if (i == dropList.Count)
|
||||
dropList.Add(data);
|
||||
else
|
||||
dropList[i] = data;
|
||||
}
|
||||
|
||||
|
||||
#endregion - 掉落物列表 -
|
||||
|
||||
#region - 物品列表 -
|
||||
|
@ -432,14 +432,14 @@ namespace GrasscutterTools.Forms
|
||||
{
|
||||
lnk.Tag = command;
|
||||
CustomCommandsChanged = true;
|
||||
await ButtonComplete(BtnSaveCustomCommand);
|
||||
await UIUtil.ButtonComplete(BtnSaveCustomCommand);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CustomCommandsChanged = true;
|
||||
AddCustomCommand(name, command);
|
||||
await ButtonComplete(BtnSaveCustomCommand);
|
||||
await UIUtil.ButtonComplete(BtnSaveCustomCommand);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -479,7 +479,7 @@ namespace GrasscutterTools.Forms
|
||||
CustomCommandsChanged = true;
|
||||
//TxtCustomName.Text = "";
|
||||
//TxtCommand.Text = "";
|
||||
await ButtonComplete(BtnRemoveCustomCommand);
|
||||
await UIUtil.ButtonComplete(BtnRemoveCustomCommand);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -1482,7 +1482,7 @@ namespace GrasscutterTools.Forms
|
||||
private async void BtnCopy_Click(object sender, EventArgs e)
|
||||
{
|
||||
CopyCommand();
|
||||
await ButtonComplete(BtnCopy);
|
||||
await UIUtil.ButtonComplete(BtnCopy);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -1620,21 +1620,6 @@ namespace GrasscutterTools.Forms
|
||||
|
||||
#region - 通用 General -
|
||||
|
||||
/// <summary>
|
||||
/// 播放按钮完成动画
|
||||
/// </summary>
|
||||
/// <param name="btn"></param>
|
||||
/// <returns></returns>
|
||||
private async Task ButtonComplete(Button btn)
|
||||
{
|
||||
var t = btn.Text;
|
||||
btn.Text = "√";
|
||||
btn.Enabled = false;
|
||||
await Task.Delay(300);
|
||||
btn.Text = t;
|
||||
btn.Enabled = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 窗口按键按下时触发
|
||||
/// </summary>
|
||||
|
@ -148,6 +148,7 @@
|
||||
<Compile Include="Utils\ArtifactUtils.cs" />
|
||||
<Compile Include="Utils\HttpHelper.cs" />
|
||||
<Compile Include="Utils\ReleaseAPI.cs" />
|
||||
<Compile Include="Utils\UIUtil.cs" />
|
||||
<EmbeddedResource Include="Forms\FormDropEditor.resx">
|
||||
<DependentUpon>FormDropEditor.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
23
Source/GrasscutterTools/Utils/UIUtil.cs
Normal file
23
Source/GrasscutterTools/Utils/UIUtil.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace GrasscutterTools.Utils
|
||||
{
|
||||
public static class UIUtil
|
||||
{
|
||||
/// <summary>
|
||||
/// 播放按钮完成动画
|
||||
/// </summary>
|
||||
/// <param name="btn"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task ButtonComplete(Button btn)
|
||||
{
|
||||
var t = btn.Text;
|
||||
btn.Text = "√";
|
||||
btn.Enabled = false;
|
||||
await Task.Delay(300);
|
||||
btn.Text = t;
|
||||
btn.Enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user