Skip to content

Commit 8592f2d

Browse files
committed
silent rename quantity
1 parent 7959483 commit 8592f2d

File tree

8 files changed

+97
-79
lines changed

8 files changed

+97
-79
lines changed
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
1+
using Newtonsoft.Json;
2+
13
namespace Intersect.GameObjects;
24

35
public partial class Drop
46
{
7+
private int _maxQuantity;
8+
59
public double Chance { get; set; }
610

711
public Guid ItemId { get; set; }
812

9-
public int Quantity { get; set; } = 1;
13+
[JsonProperty]
14+
[Obsolete(message: $"Use {nameof(MinQuantity)} instead, the Quantity property will be removed in 0.9-beta", error: true)]
15+
private int Quantity
16+
{
17+
/* Setter only [JsonProperty] annotated private property to "silently" rename Quantity to MinQuantity */
18+
set => MinQuantity = value;
19+
}
1020

21+
/* By renaming Quantity to MinQuantity the "automatic" range given an original "Quantity" value of 3 will be 3 to 3, instead of 1 to 3 or 0 to 3 */
1122
public int MinQuantity { get; set; } = 1;
12-
}
23+
24+
public int MaxQuantity
25+
{
26+
/* Special getter ensures that MaxQuantity can never be less than MinQuantity, and it doesn't need a non-zero default value as a result */
27+
get => Math.Max(_maxQuantity, MinQuantity);
28+
set => _maxQuantity = value;
29+
}
30+
}

Intersect.Editor/Forms/Editors/frmNpc.Designer.cs

Lines changed: 28 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Intersect.Editor/Forms/Editors/frmNpc.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private void InitLocalization()
211211

212212
grpDrops.Text = Strings.NpcEditor.drops;
213213
lblDropItem.Text = Strings.NpcEditor.dropitem;
214-
lblDropAmount.Text = Strings.NpcEditor.DropMaxAmount;
214+
lblDropMaxAmount.Text = Strings.NpcEditor.DropMaxAmount;
215215
lblDropMinAmount.Text = Strings.NpcEditor.DropMinAmount;
216216
lblDropChance.Text = Strings.NpcEditor.dropchance;
217217
btnDropAdd.Text = Strings.NpcEditor.dropadd;
@@ -449,7 +449,7 @@ private void UpdateDropValues(bool keepIndex = false)
449449
Strings.NpcEditor.dropdisplay.ToString(
450450
ItemBase.GetName(mEditorItem.Drops[i].ItemId),
451451
mEditorItem.Drops[i].MinQuantity,
452-
mEditorItem.Drops[i].Quantity,
452+
mEditorItem.Drops[i].MaxQuantity,
453453
mEditorItem.Drops[i].Chance
454454
)
455455
);
@@ -738,14 +738,14 @@ private void cmbDropItem_SelectedIndexChanged(object sender, EventArgs e)
738738
UpdateDropValues(true);
739739
}
740740

741-
private void nudDropAmount_ValueChanged(object sender, EventArgs e)
741+
private void nudDropMaxAmount_ValueChanged(object sender, EventArgs e)
742742
{
743743
if (lstDrops.SelectedIndex < 0 || lstDrops.SelectedIndex > lstDrops.Items.Count)
744744
{
745745
return;
746746
}
747747

748-
mEditorItem.Drops[lstDrops.SelectedIndex].Quantity = (int)nudDropAmount.Value;
748+
mEditorItem.Drops[lstDrops.SelectedIndex].MaxQuantity = (int)nudDropMaxAmount.Value;
749749
UpdateDropValues(true);
750750
}
751751

@@ -765,7 +765,7 @@ private void lstDrops_SelectedIndexChanged(object sender, EventArgs e)
765765
if (lstDrops.SelectedIndex > -1)
766766
{
767767
cmbDropItem.SelectedIndex = ItemBase.ListIndex(mEditorItem.Drops[lstDrops.SelectedIndex].ItemId) + 1;
768-
nudDropAmount.Value = mEditorItem.Drops[lstDrops.SelectedIndex].Quantity;
768+
nudDropMaxAmount.Value = mEditorItem.Drops[lstDrops.SelectedIndex].MaxQuantity;
769769
nudDropMinAmount.Value = mEditorItem.Drops[lstDrops.SelectedIndex].MinQuantity;
770770
nudDropChance.Value = (decimal)mEditorItem.Drops[lstDrops.SelectedIndex].Chance;
771771
}
@@ -774,10 +774,10 @@ private void lstDrops_SelectedIndexChanged(object sender, EventArgs e)
774774
private void btnDropAdd_Click(object sender, EventArgs e)
775775
{
776776
mEditorItem.Drops.Add(new Drop());
777-
mEditorItem.Drops[mEditorItem.Drops.Count - 1].ItemId = ItemBase.IdFromList(cmbDropItem.SelectedIndex - 1);
778-
mEditorItem.Drops[mEditorItem.Drops.Count - 1].Quantity = (int)nudDropAmount.Value;
779-
mEditorItem.Drops[mEditorItem.Drops.Count - 1].MinQuantity = (int)nudDropMinAmount.Value;
780-
mEditorItem.Drops[mEditorItem.Drops.Count - 1].Chance = (double)nudDropChance.Value;
777+
mEditorItem.Drops[^1].ItemId = ItemBase.IdFromList(cmbDropItem.SelectedIndex - 1);
778+
mEditorItem.Drops[^1].MaxQuantity = (int)nudDropMaxAmount.Value;
779+
mEditorItem.Drops[^1].MinQuantity = (int)nudDropMinAmount.Value;
780+
mEditorItem.Drops[^1].Chance = (double)nudDropChance.Value;
781781

782782
UpdateDropValues();
783783
}

Intersect.Editor/Forms/Editors/frmNpc.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,6 @@
179179
</value>
180180
</data>
181181
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
182-
<value>65</value>
182+
<value>54</value>
183183
</metadata>
184184
</root>

Intersect.Editor/Forms/Editors/frmResource.Designer.cs

Lines changed: 28 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Intersect.Editor/Forms/Editors/frmResource.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ private void InitLocalization()
196196

197197
grpDrops.Text = Strings.ResourceEditor.drops;
198198
lblDropItem.Text = Strings.ResourceEditor.dropitem;
199-
lblDropAmount.Text = Strings.ResourceEditor.DropMaxAmount;
199+
lblDropMaxAmount.Text = Strings.ResourceEditor.DropMaxAmount;
200200
lblDropMinAmount.Text = Strings.ResourceEditor.DropMinAmount;
201201
lblDropChance.Text = Strings.ResourceEditor.dropchance;
202202
btnDropAdd.Text = Strings.ResourceEditor.dropadd;
@@ -295,7 +295,7 @@ private void UpdateDropValues(bool keepIndex = false)
295295
Strings.ResourceEditor.dropdisplay.ToString(
296296
ItemBase.GetName(mEditorItem.Drops[i].ItemId),
297297
mEditorItem.Drops[i].MinQuantity,
298-
mEditorItem.Drops[i].Quantity,
298+
mEditorItem.Drops[i].MaxQuantity,
299299
mEditorItem.Drops[i].Chance
300300
)
301301
);
@@ -605,14 +605,14 @@ private void cmbDropItem_SelectedIndexChanged(object sender, EventArgs e)
605605
UpdateDropValues(true);
606606
}
607607

608-
private void nudDropAmount_ValueChanged(object sender, EventArgs e)
608+
private void nudDropMaxAmount_ValueChanged(object sender, EventArgs e)
609609
{
610610
if (lstDrops.SelectedIndex < 0 || lstDrops.SelectedIndex > lstDrops.Items.Count)
611611
{
612612
return;
613613
}
614614

615-
mEditorItem.Drops[lstDrops.SelectedIndex].Quantity = (int)nudDropAmount.Value;
615+
mEditorItem.Drops[lstDrops.SelectedIndex].MaxQuantity = (int)nudDropMaxAmount.Value;
616616
UpdateDropValues(true);
617617
}
618618

@@ -632,7 +632,7 @@ private void lstDrops_SelectedIndexChanged(object sender, EventArgs e)
632632
if (lstDrops.SelectedIndex > -1)
633633
{
634634
cmbDropItem.SelectedIndex = ItemBase.ListIndex(mEditorItem.Drops[lstDrops.SelectedIndex].ItemId) + 1;
635-
nudDropAmount.Value = mEditorItem.Drops[lstDrops.SelectedIndex].Quantity;
635+
nudDropMaxAmount.Value = mEditorItem.Drops[lstDrops.SelectedIndex].MaxQuantity;
636636
nudDropMinAmount.Value = mEditorItem.Drops[lstDrops.SelectedIndex].MinQuantity;
637637
nudDropChance.Value = (decimal)mEditorItem.Drops[lstDrops.SelectedIndex].Chance;
638638
}
@@ -641,10 +641,10 @@ private void lstDrops_SelectedIndexChanged(object sender, EventArgs e)
641641
private void btnDropAdd_Click(object sender, EventArgs e)
642642
{
643643
mEditorItem.Drops.Add(new Drop());
644-
mEditorItem.Drops[mEditorItem.Drops.Count - 1].ItemId = ItemBase.IdFromList(cmbDropItem.SelectedIndex - 1);
645-
mEditorItem.Drops[mEditorItem.Drops.Count - 1].Quantity = (int)nudDropAmount.Value;
646-
mEditorItem.Drops[mEditorItem.Drops.Count - 1].MinQuantity = (int)nudDropMinAmount.Value;
647-
mEditorItem.Drops[mEditorItem.Drops.Count - 1].Chance = (double)nudDropChance.Value;
644+
mEditorItem.Drops[^1].ItemId = ItemBase.IdFromList(cmbDropItem.SelectedIndex - 1);
645+
mEditorItem.Drops[^1].MaxQuantity = (int)nudDropMaxAmount.Value;
646+
mEditorItem.Drops[^1].MinQuantity = (int)nudDropMinAmount.Value;
647+
mEditorItem.Drops[^1].Chance = (double)nudDropChance.Value;
648648

649649
UpdateDropValues();
650650
}

0 commit comments

Comments
 (0)