|
| 1 | +using System.ComponentModel; |
1 | 2 | using System.Drawing.Imaging; |
2 | 3 | using DarkUI.Forms; |
3 | 4 | using Intersect.Editor.Content; |
|
13 | 14 |
|
14 | 15 | namespace Intersect.Editor.Forms.Editors; |
15 | 16 |
|
16 | | - |
17 | 17 | public partial class FrmNpc : EditorForm |
18 | 18 | { |
19 | 19 |
|
20 | | - private List<NpcBase> mChanged = new List<NpcBase>(); |
| 20 | + private List<NpcBase> mChanged = []; |
21 | 21 |
|
22 | 22 | private string mCopiedItem; |
23 | 23 |
|
24 | 24 | private NpcBase mEditorItem; |
25 | 25 |
|
26 | | - private List<string> mKnownFolders = new List<string>(); |
| 26 | + private List<string> mKnownFolders = []; |
| 27 | + |
| 28 | + private BindingList<NotifiableDrop> _dropList = []; |
27 | 29 |
|
28 | 30 | public FrmNpc() |
29 | 31 | { |
@@ -112,6 +114,9 @@ private void frmNpc_Load(object sender, EventArgs e) |
112 | 114 | cmbScalingStat.Items.Add(Globals.GetStatName(x)); |
113 | 115 | } |
114 | 116 |
|
| 117 | + lstDrops.DataSource = _dropList; |
| 118 | + lstDrops.DisplayMember = nameof(NotifiableDrop.DisplayName); |
| 119 | + |
115 | 120 | nudStr.Maximum = Options.Instance.Player.MaxStat; |
116 | 121 | nudMag.Maximum = Options.Instance.Player.MaxStat; |
117 | 122 | nudDef.Maximum = Options.Instance.Player.MaxStat; |
@@ -211,7 +216,8 @@ private void InitLocalization() |
211 | 216 |
|
212 | 217 | grpDrops.Text = Strings.NpcEditor.drops; |
213 | 218 | lblDropItem.Text = Strings.NpcEditor.dropitem; |
214 | | - lblDropAmount.Text = Strings.NpcEditor.dropamount; |
| 219 | + lblDropMaxAmount.Text = Strings.NpcEditor.DropMaxAmount; |
| 220 | + lblDropMinAmount.Text = Strings.NpcEditor.DropMinAmount; |
215 | 221 | lblDropChance.Text = Strings.NpcEditor.dropchance; |
216 | 222 | btnDropAdd.Text = Strings.NpcEditor.dropadd; |
217 | 223 | btnDropRemove.Text = Strings.NpcEditor.dropremove; |
@@ -426,40 +432,18 @@ private void DrawNpcSprite() |
426 | 432 | picNpc.BackgroundImage = picSpriteBmp; |
427 | 433 | } |
428 | 434 |
|
429 | | - private void UpdateDropValues(bool keepIndex = false) |
| 435 | + private void UpdateDropValues() |
430 | 436 | { |
431 | | - var index = lstDrops.SelectedIndex; |
432 | | - lstDrops.Items.Clear(); |
433 | | - |
434 | | - var drops = mEditorItem.Drops.ToArray(); |
435 | | - foreach (var drop in drops) |
| 437 | + _dropList.Clear(); |
| 438 | + foreach (var drop in mEditorItem.Drops) |
436 | 439 | { |
437 | | - if (ItemBase.Get(drop.ItemId) == null) |
| 440 | + _dropList.Add(new NotifiableDrop |
438 | 441 | { |
439 | | - mEditorItem.Drops.Remove(drop); |
440 | | - } |
441 | | - } |
442 | | - |
443 | | - for (var i = 0; i < mEditorItem.Drops.Count; i++) |
444 | | - { |
445 | | - if (mEditorItem.Drops[i].ItemId != Guid.Empty) |
446 | | - { |
447 | | - lstDrops.Items.Add( |
448 | | - Strings.NpcEditor.dropdisplay.ToString( |
449 | | - ItemBase.GetName(mEditorItem.Drops[i].ItemId), mEditorItem.Drops[i].Quantity, |
450 | | - mEditorItem.Drops[i].Chance |
451 | | - ) |
452 | | - ); |
453 | | - } |
454 | | - else |
455 | | - { |
456 | | - lstDrops.Items.Add(TextUtils.None); |
457 | | - } |
458 | | - } |
459 | | - |
460 | | - if (keepIndex && index < lstDrops.Items.Count) |
461 | | - { |
462 | | - lstDrops.SelectedIndex = index; |
| 442 | + ItemId = drop.ItemId, |
| 443 | + MinQuantity = drop.MinQuantity, |
| 444 | + MaxQuantity = drop.MaxQuantity, |
| 445 | + Chance = drop.Chance |
| 446 | + }); |
463 | 447 | } |
464 | 448 | } |
465 | 449 |
|
@@ -724,71 +708,98 @@ private void nudExp_ValueChanged(object sender, EventArgs e) |
724 | 708 | mEditorItem.Experience = (int)nudExp.Value; |
725 | 709 | } |
726 | 710 |
|
| 711 | + private void lstDrops_SelectedIndexChanged(object sender, EventArgs e) |
| 712 | + { |
| 713 | + if (lstDrops.SelectedIndex > -1) |
| 714 | + { |
| 715 | + cmbDropItem.SelectedIndex = ItemBase.ListIndex(mEditorItem.Drops[lstDrops.SelectedIndex].ItemId) + 1; |
| 716 | + nudDropMaxAmount.Value = mEditorItem.Drops[lstDrops.SelectedIndex].MaxQuantity; |
| 717 | + nudDropMinAmount.Value = mEditorItem.Drops[lstDrops.SelectedIndex].MinQuantity; |
| 718 | + nudDropChance.Value = (decimal)mEditorItem.Drops[lstDrops.SelectedIndex].Chance; |
| 719 | + } |
| 720 | + } |
| 721 | + |
727 | 722 | private void cmbDropItem_SelectedIndexChanged(object sender, EventArgs e) |
728 | 723 | { |
729 | | - if (lstDrops.SelectedIndex > -1 && lstDrops.SelectedIndex < mEditorItem.Drops.Count) |
| 724 | + int index = lstDrops.SelectedIndex; |
| 725 | + if (index < 0 || index > lstDrops.Items.Count) |
730 | 726 | { |
731 | | - mEditorItem.Drops[lstDrops.SelectedIndex].ItemId = ItemBase.IdFromList(cmbDropItem.SelectedIndex - 1); |
| 727 | + return; |
732 | 728 | } |
733 | 729 |
|
734 | | - UpdateDropValues(true); |
| 730 | + mEditorItem.Drops[index].ItemId = ItemBase.IdFromList(cmbDropItem.SelectedIndex - 1); |
| 731 | + _dropList[index].ItemId = mEditorItem.Drops[index].ItemId; |
735 | 732 | } |
736 | 733 |
|
737 | | - private void nudDropAmount_ValueChanged(object sender, EventArgs e) |
| 734 | + private void nudDropMaxAmount_ValueChanged(object sender, EventArgs e) |
738 | 735 | { |
739 | | - // This should never be below 1. We shouldn't accept giving 0 items! |
740 | | - nudDropAmount.Value = Math.Max(1, nudDropAmount.Value); |
741 | | - |
742 | | - if (lstDrops.SelectedIndex < lstDrops.Items.Count) |
| 736 | + int index = lstDrops.SelectedIndex; |
| 737 | + if (index < 0 || index > lstDrops.Items.Count) |
743 | 738 | { |
744 | 739 | return; |
745 | 740 | } |
746 | 741 |
|
747 | | - mEditorItem.Drops[(int)lstDrops.SelectedIndex].Quantity = (int)nudDropAmount.Value; |
748 | | - UpdateDropValues(true); |
| 742 | + mEditorItem.Drops[index].MaxQuantity = (int)nudDropMaxAmount.Value; |
| 743 | + _dropList[index].MaxQuantity = mEditorItem.Drops[index].MaxQuantity; |
749 | 744 | } |
750 | 745 |
|
751 | | - private void lstDrops_SelectedIndexChanged(object sender, EventArgs e) |
| 746 | + private void nudDropMinAmount_ValueChanged(object sender, EventArgs e) |
752 | 747 | { |
753 | | - if (lstDrops.SelectedIndex > -1) |
| 748 | + int index = lstDrops.SelectedIndex; |
| 749 | + if (index < 0 || index > lstDrops.Items.Count) |
754 | 750 | { |
755 | | - cmbDropItem.SelectedIndex = ItemBase.ListIndex(mEditorItem.Drops[lstDrops.SelectedIndex].ItemId) + 1; |
756 | | - nudDropAmount.Value = mEditorItem.Drops[lstDrops.SelectedIndex].Quantity; |
757 | | - nudDropChance.Value = (decimal)mEditorItem.Drops[lstDrops.SelectedIndex].Chance; |
| 751 | + return; |
758 | 752 | } |
| 753 | + |
| 754 | + mEditorItem.Drops[index].MinQuantity = (int)nudDropMinAmount.Value; |
| 755 | + _dropList[index].MinQuantity = mEditorItem.Drops[index].MinQuantity; |
759 | 756 | } |
760 | 757 |
|
761 | | - private void btnDropAdd_Click(object sender, EventArgs e) |
| 758 | + private void nudDropChance_ValueChanged(object sender, EventArgs e) |
762 | 759 | { |
763 | | - mEditorItem.Drops.Add(new Drop()); |
764 | | - mEditorItem.Drops[mEditorItem.Drops.Count - 1].ItemId = ItemBase.IdFromList(cmbDropItem.SelectedIndex - 1); |
765 | | - mEditorItem.Drops[mEditorItem.Drops.Count - 1].Quantity = (int)nudDropAmount.Value; |
766 | | - mEditorItem.Drops[mEditorItem.Drops.Count - 1].Chance = (double)nudDropChance.Value; |
| 760 | + int index = lstDrops.SelectedIndex; |
| 761 | + if (index < 0 || index > lstDrops.Items.Count) |
| 762 | + { |
| 763 | + return; |
| 764 | + } |
767 | 765 |
|
768 | | - UpdateDropValues(); |
| 766 | + mEditorItem.Drops[index].Chance = (double)nudDropChance.Value; |
| 767 | + _dropList[index].Chance = mEditorItem.Drops[index].Chance; |
769 | 768 | } |
770 | 769 |
|
771 | | - private void btnDropRemove_Click(object sender, EventArgs e) |
| 770 | + private void btnDropAdd_Click(object sender, EventArgs e) |
772 | 771 | { |
773 | | - if (lstDrops.SelectedIndex > -1) |
| 772 | + var drop = new Drop() |
774 | 773 | { |
775 | | - var i = lstDrops.SelectedIndex; |
776 | | - lstDrops.Items.RemoveAt(i); |
777 | | - mEditorItem.Drops.RemoveAt(i); |
778 | | - } |
| 774 | + ItemId = ItemBase.IdFromList(cmbDropItem.SelectedIndex - 1), |
| 775 | + MaxQuantity = (int)nudDropMaxAmount.Value, |
| 776 | + MinQuantity = (int)nudDropMinAmount.Value, |
| 777 | + Chance = (double)nudDropChance.Value |
| 778 | + }; |
779 | 779 |
|
780 | | - UpdateDropValues(true); |
| 780 | + mEditorItem.Drops.Add(drop); |
| 781 | + |
| 782 | + _dropList.Add(new NotifiableDrop |
| 783 | + { |
| 784 | + ItemId = drop.ItemId, |
| 785 | + MinQuantity = drop.MinQuantity, |
| 786 | + MaxQuantity = drop.MaxQuantity, |
| 787 | + Chance = drop.Chance |
| 788 | + }); |
| 789 | + |
| 790 | + lstDrops.SelectedIndex = _dropList.Count - 1; |
781 | 791 | } |
782 | 792 |
|
783 | | - private void nudDropChance_ValueChanged(object sender, EventArgs e) |
| 793 | + private void btnDropRemove_Click(object sender, EventArgs e) |
784 | 794 | { |
785 | | - if (lstDrops.SelectedIndex < lstDrops.Items.Count) |
| 795 | + if (lstDrops.SelectedIndex < 0) |
786 | 796 | { |
787 | 797 | return; |
788 | 798 | } |
789 | 799 |
|
790 | | - mEditorItem.Drops[(int)lstDrops.SelectedIndex].Chance = (double)nudDropChance.Value; |
791 | | - UpdateDropValues(true); |
| 800 | + var index = lstDrops.SelectedIndex; |
| 801 | + mEditorItem.Drops.RemoveAt(index); |
| 802 | + _dropList.RemoveAt(index); |
792 | 803 | } |
793 | 804 |
|
794 | 805 | private void chkIndividualLoot_CheckedChanged(object sender, EventArgs e) |
|
0 commit comments