/
itemEntry.cs
160 lines (141 loc) · 4.84 KB
/
itemEntry.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows;
using System.Reflection;
using SeeloewenLib;
namespace Random_Item_Giver_Updater
{
public class itemEntry
{
//Item attributes
public List<string> itemStackComponent;
public List<string> itemBody;
public string itemName { get; set; }
public string itemNBT { get; set; }
public string itemIndex { get; set; }
public string newName;
public enum changeType
{
NameChanged,
FunctionBodyAdded,
ItemStackComponentBodyAdded,
ItemStackComponentBodyRemoved,
NBTBodyAdded,
NBTBodyRemoved,
NBTChanged,
Deleted
}
public List<changeType> changes = new List<changeType>();
public bool hasLegacyNBT = false;
public bool hasItemStackComponent = false;
public bool hasFunctionBody = false;
//Canvas attributes
public SolidColorBrush canvasBackColor { get; set; }
//Important references
SeeloewenLibTools SeeloewenLibTools = new SeeloewenLibTools();
//-- Constructor --//
public itemEntry(string name, string nbt, int index, bool hasFunctionBody, List<string> itemBody)
{
//Initialize variables
this.hasFunctionBody = hasFunctionBody;
this.itemBody = itemBody;
itemName = name.TrimEnd('\r', '\n');
itemNBT = nbt.TrimEnd('\r', '\n'); ;
itemIndex = (index + 1).ToString();
newName = itemName;
hasLegacyNBT = true;
//Set the backcolor
canvasBackColor = SetBackColor();
}
public itemEntry(string name, List<string> itemStackComponent, int index, bool hasFunctionBody, List<string> itemBody)
{
//Initialize variables
this.itemStackComponent = itemStackComponent;
this.hasFunctionBody = hasFunctionBody;
this.itemBody = itemBody;
itemName = name.TrimEnd('\r', '\n');
itemIndex = (index + 1).ToString();
newName = itemName;
hasItemStackComponent = true;
//Set the backcolor
canvasBackColor = SetBackColor();
}
//-- Custom Methods --//
public void SetIndicatorState(object sender)
{
if (sender is Button button)
{
//Get the parent canvas
Canvas canvas = SeeloewenLibTools.FindVisualParent<Canvas>(button);
//Get the necessary controls
TextBlock textblock = canvas.FindName("tblIndicator") as TextBlock;
if (IsModified() == true && IsDeleted() == true)
{
//Item deleted, show indicator
textblock.Visibility = Visibility.Visible;
textblock.Text = "X";
textblock.Foreground = new SolidColorBrush(Colors.Red);
}
else if (IsModified() == true && IsDeleted() == false)
{
//Item modified, show indicator
textblock.Visibility = Visibility.Visible;
textblock.Text = "#";
textblock.Foreground = new SolidColorBrush(Colors.LightBlue);
}
else if (IsModified() == false && IsDeleted() == false)
{
//No changes, hide indicator
textblock.Visibility = Visibility.Hidden;
}
else
{
//Invalid state provided, hide indicator
textblock.Visibility = Visibility.Hidden;
}
}
}
public SolidColorBrush SetBackColor()
{
//Set the backcolor depending on the item index
if (Convert.ToInt32(itemIndex) % 2 == 0)
{
return new SolidColorBrush(Color.FromArgb(100, 70, 70, 70));
}
else
{
return new SolidColorBrush(Color.FromArgb(100, 90, 90, 90));
}
}
public bool IsModified()
{
//Check if the item is modified in any way
if (changes.Count != 0)
{
return true;
}
else
{
return false;
}
}
public bool IsDeleted()
{
//Check if the item was deleted
if(changes.Contains(changeType.Deleted))
{
return true;
}
else
{
return false;
}
}
}
}