-
Notifications
You must be signed in to change notification settings - Fork 4
/
LoadingExtension.cs
245 lines (209 loc) · 9.98 KB
/
LoadingExtension.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
using System;
using System.Collections.Generic;
using ColossalFramework;
using ColossalFramework.Packaging;
using ColossalFramework.Plugins;
using ColossalFramework.UI;
using ICities;
using UnityEngine;
namespace MoreBeautification
{
public class LoadingExtension : LoadingExtensionBase
{
public override void OnLevelLoaded(LoadMode mode)
{
base.OnLevelLoaded(mode);
UITabstrip tabstrip = (UITabstrip)ToolsModifierControl.mainToolbar.component;
UITabstrip beautificationTabstrip = this.BeautificationTabstrip(tabstrip);
if (beautificationTabstrip != null && !this.IsCreated(beautificationTabstrip))
{
this.AddPropsPanels(beautificationTabstrip, new EditorProps[] {
new EditorProps ("PropsBillboards", new string[] {
"PropsBillboardsLogo",
"PropsBillboardsSmallBillboard",
"PropsBillboardsMediumBillboard",
"PropsBillboardsLargeBillboard",
}, "ToolbarIconPropsBillboards", "Billboards"),
new EditorProps ("PropsSpecialBillboards", new string[] {
"PropsBillboardsRandomLogo",
"PropsSpecialBillboardsRandomSmallBillboard",
"PropsSpecialBillboardsRandomMediumBillboard",
"PropsSpecialBillboardsRandomLargeBillboard",
"PropsSpecialBillboards3DBillboard",
"PropsSpecialBillboardsAnimatedBillboard",
}, "ToolbarIconPropsSpecialBillboards", "Special Billboards"),
new EditorProps ("PropsIndustrial", new string[] {
"PropsIndustrialContainers",
"PropsIndustrialConstructionMaterials",
"PropsIndustrialStructures",
}, "ToolbarIconPropsIndustrial", "Industrial"),
new EditorProps ("PropsParks", new string[] {
"PropsParksPlaygrounds",
"PropsParksFlowersAndPlants",
"PropsParksParkEquipment",
"PropsParksFountains",
}, "ToolbarIconPropsParks", "Parks"),
new EditorProps ("PropsCommon", new string[] {
"PropsCommonAccessories",
"PropsCommonGarbage",
"PropsCommonCommunications",
"PropsCommonStreets"
}, "ToolbarIconPropsCommon", "Common"),
new EditorProps ("PropsResidential", new string[] {
"PropsResidentialHomeYard",
"PropsResidentialGroundTiles",
"PropsResidentialRooftopAccess",
"PropsResidentialRandomRooftopAccess",
}, "ToolbarIconPropsResidential", "Residential"),
new EditorProps ("PropsLights", new string[] {
"PropsCommonStreets",
"PropsCommonLights",
PrefabInfo.kDefaultCategory,
PrefabInfo.kSameAsGameCategory,
}, "SubBarPropsCommonLights", "Lights"),
new EditorProps ("PropsUnsorted", new string[] {
PrefabInfo.kDefaultCategory,
PrefabInfo.kSameAsGameCategory,
"PropsMarkers"
}, "ToolbarIconHelp", "Unsorted"),
});
}
// CreateGroupItem (new GeneratedGroupPanel.GroupInfo ("PropsParksParkEquipment", this.GetCategoryOrder (base.name), "Props"), "PROPS_CATEGORY");
}
private struct EditorProps
{
public string m_category;
public string[] m_categories;
public string m_icon;
public string m_tooltip;
public EditorProps(string category, string[] categories, string icon, string tooltip)
{
this.m_category = category;
this.m_categories = categories;
this.m_icon = icon;
this.m_tooltip = tooltip;
}
}
private void AddPropsPanels(UITabstrip tabstrip, EditorProps[] props)
{
foreach (EditorProps prop in props)
{
UIButton button = this.AddButton(typeof(EditorPropsPanel), tabstrip, prop.m_category, prop.m_categories, prop.m_tooltip, true);
if (button == null)
{
continue;
}
this.SetButtonSprites(button, prop.m_icon, "SubBarButtonBase");
}
}
private UIButton[] AllButtons(UITabstrip s)
{
List<UIButton> buttons = new List<UIButton>();
foreach (UIComponent component in s.components)
{
if (component != null && component is UIButton)
{
UIButton button = (UIButton)component;
buttons.Add(button);
}
}
return buttons.ToArray();
}
private UIButton FindButton(UITabstrip s, string name)
{
UIButton[] buttons = this.AllButtons(s);
return Array.Find(buttons, b => b.name == name);
}
private bool IsCreated(UITabstrip strip)
{
UIButton button = this.FindButton(strip, "TerrainDefault");
return button != null;
}
private UITabstrip BeautificationTabstrip(UITabstrip s)
{
UIButton button = this.FindButton(s, "Beautification");
if (button == null)
{
return null;
}
Type groupPanelType = typeof(BeautificationGroupPanel);
GeneratedGroupPanel groupPanel = (GeneratedGroupPanel)s.GetComponentInContainer(button, groupPanelType);
if (groupPanel == null)
{
return null;
}
UITabstrip strip = groupPanel.Find<UITabstrip>("GroupToolstrip");
if (strip == null)
{
return null;
}
return strip;
}
private UIButton AddButton(Type type, UITabstrip strip, string category, string tooltip, bool enabled)
{
return this.AddButton(type, strip, category, null, tooltip, enabled);
}
private UIButton AddButton(Type type, UITabstrip strip, string category, string[] editorCategories, string tooltip, bool enabled)
{
if (GameObject.Find(String.Format("{0}Panel", category)) != null)
{
return null;
}
GameObject subbarButtonTemplate = UITemplateManager.GetAsGameObject("SubbarButtonTemplate");
GameObject subbarPanelTemplate = UITemplateManager.GetAsGameObject("SubbarPanelTemplate");
UIButton button = (UIButton)strip.AddTab(category, subbarButtonTemplate, subbarPanelTemplate, type);
button.isEnabled = enabled;
GeneratedScrollPanel generatedScrollPanel = (GeneratedScrollPanel)strip.GetComponentInContainer(button, type);
if (generatedScrollPanel != null)
{
generatedScrollPanel.component.isInteractive = true;
generatedScrollPanel.m_OptionsBar = ToolsModifierControl.mainToolbar.m_OptionsBar;
generatedScrollPanel.m_DefaultInfoTooltipAtlas = ToolsModifierControl.mainToolbar.m_DefaultInfoTooltipAtlas;
if (generatedScrollPanel is EditorPropsPanel)
{
((EditorPropsPanel)generatedScrollPanel).m_editorCategories = editorCategories;
((EditorPropsPanel) generatedScrollPanel).category = category;
}
if (enabled)
{
generatedScrollPanel.RefreshPanel();
}
}
button.tooltip = tooltip;
return button;
}
private void SetButtonSprites(UIButton button, string backgroundSpriteBase, string foregroundSpriteBase)
{
this.SetButtonSprites(button, foregroundSpriteBase, backgroundSpriteBase, "", "");
}
private void SetButtonSprites(UIButton button, string backgroundSpriteBase, string foregroundSpriteBase, string normalBgPostfix)
{
this.SetButtonSprites(button, foregroundSpriteBase, backgroundSpriteBase, normalBgPostfix, "");
}
private void SetButtonSprites(UIButton button, string backgroundSpriteBase, string foregroundSpriteBase, string normalBgPostfix, string normalFgPostfix)
{
button.atlas = ResourceUtils.CreateAtlas(new string[] {
backgroundSpriteBase + normalBgPostfix,
backgroundSpriteBase + "Focused",
backgroundSpriteBase + "Hovered",
backgroundSpriteBase + "Pressed",
backgroundSpriteBase + "Disabled",
foregroundSpriteBase + normalFgPostfix,
foregroundSpriteBase + "Focused",
foregroundSpriteBase + "Hovered",
foregroundSpriteBase + "Pressed",
foregroundSpriteBase + "Disabled"
});
button.normalBgSprite = backgroundSpriteBase + normalBgPostfix;
button.focusedBgSprite = backgroundSpriteBase + "Focused";
button.hoveredBgSprite = backgroundSpriteBase + "Hovered";
button.pressedBgSprite = backgroundSpriteBase + "Pressed";
button.disabledBgSprite = backgroundSpriteBase + "Disabled";
button.normalFgSprite = foregroundSpriteBase + normalFgPostfix;
button.focusedFgSprite = foregroundSpriteBase + "Focused";
button.hoveredFgSprite = foregroundSpriteBase + "Hovered";
button.pressedFgSprite = foregroundSpriteBase + "Pressed";
button.disabledFgSprite = foregroundSpriteBase + "Disabled";
}
}
}