-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFormAddEffect.cs
141 lines (122 loc) · 4.7 KB
/
FormAddEffect.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace OphdTechEdit
{
public partial class FormAddEffect : Form
{
public Effect Effect { get; set; }
public FormAddEffect()
{
InitializeComponent();
}
public FormAddEffect(Effect _toEdit)
{
InitializeComponent();
Effect = _toEdit;
if (Effect.EffectType == Effect.Type.Modifier)
{
ComboEffectType.Text = "Modifier";
foreach (KeyValuePair<Effect.Modifier, string> item in Effect.ModifierToString)
{
_ = ComboEffectSubType.Items.Add(item.Value);
}
ComboEffectSubType.Text = Effect.ModifierToString[Effect.Modifies];
TextValue.Text = Convert.ToString(Effect.Value);
}
else
{
ComboEffectType.Text = "Unlock";
foreach (KeyValuePair<Effect.Unlock, string> item in Effect.UnlockToString)
{
_ = ComboEffectSubType.Items.Add(item.Value);
}
ComboEffectSubType.Text = Effect.UnlockToString[Effect.Unlocks];
TextValue.Text = Convert.ToString(Effect.Value);
}
}
private void TextValue_Enter(object sender, EventArgs e)
{
TextValue.BackColor = Control.DefaultBackColor;
}
private void ComboEffectSubType_Enter(object sender, EventArgs e)
{
ComboEffectSubType.BackColor = Control.DefaultBackColor;
}
private void ComboEffectType_Enter(object sender, EventArgs e)
{
ComboEffectType.BackColor = Control.DefaultBackColor;
}
private void ComboEffectType_SelectionChangeCommitted(object sender, EventArgs e)
{
string effectType = ComboEffectType.Text;
ComboEffectSubType.Items.Clear();
if (effectType == "Modifier")
{
foreach (KeyValuePair<Effect.Modifier, string> item in Effect.ModifierToString)
{
_ = ComboEffectSubType.Items.Add(item.Value);
}
}
else if(effectType == "Unlock")
{
foreach (KeyValuePair<Effect.Unlock, string> item in Effect.UnlockToString)
{
_ = ComboEffectSubType.Items.Add(item.Value);
}
}
}
private void ButtonAccept_Click(object sender, EventArgs e)
{
if(ComboEffectType.Text.Length == 0)
{
_ = MessageBox.Show("Must make a Type selection.", "Missing Value", MessageBoxButtons.OK, MessageBoxIcon.Error);
ComboEffectType.BackColor = Color.Yellow;
return;
}
if (ComboEffectSubType.Text.Length == 0)
{
_ = MessageBox.Show("Must make a Sub Type selection.", "Missing Value", MessageBoxButtons.OK, MessageBoxIcon.Error);
ComboEffectSubType.BackColor = Color.Yellow;
return;
}
if (TextValue.Text.Trim().Length == 0)
{
_ = MessageBox.Show("Value cannot be empty.", "Missing Value", MessageBoxButtons.OK, MessageBoxIcon.Error);
TextValue.BackColor = Color.Yellow;
return;
}
Effect effect;
if (ComboEffectType.Text == "Modifier")
{
try
{
effect = new Effect()
{
EffectType = Effect.Type.Modifier,
Modifies = Effect.StringToModifier[ComboEffectSubType.Text],
Value = Convert.ToDecimal(TextValue.Text)
};
}
catch(System.FormatException)
{
_ = MessageBox.Show("Value must be numeric.", "Invalid Value", MessageBoxButtons.OK, MessageBoxIcon.Error);
TextValue.BackColor = Color.Yellow;
return;
}
}
else
{
effect = new Effect()
{
EffectType = Effect.Type.Unlock,
Unlocks = Effect.StringToUnlock[ComboEffectSubType.Text],
Value = TextValue.Text
};
}
Effect = effect;
DialogResult = DialogResult.OK;
}
}
}