-
Notifications
You must be signed in to change notification settings - Fork 6
/
UITitleContainer.cs
116 lines (97 loc) · 3.57 KB
/
UITitleContainer.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
using ColossalFramework.UI;
using System;
using UnityEngine;
namespace CS_EmploymentDetailsExtender
{
/**
* Title Bar source code from Skylines-ExtendedPublicTransport
* https://github.com/justacid/Skylines-ExtendedPublicTransport/tree/master/ExtendedPublicTransportUI
**/
public class UITitleContainer : UIPanel
{
private UISprite _icon;
private UILabel _title;
private UIButton _close;
private UIButton _lock;
private UIDragHandle _drag;
public string IconSprite { get; set; }
public string TitleText
{
get { return _title.text; }
set { _title.text = value; }
}
public float Height
{
get { return height; }
set { height = value; }
}
public float Width
{
get { return width; }
set { width = value; }
}
public bool Locked { get; set; }
public override void Awake()
{
base.Awake();
_icon = AddUIComponent<UISprite>();
_title = AddUIComponent<UILabel>();
_close = AddUIComponent<UIButton>();
_lock = AddUIComponent<UIButton>();
_drag = AddUIComponent<UIDragHandle>();
height = 40;
width = 450;
TitleText = "(None)";
IconSprite = "";
Locked = false;
}
public override void Start()
{
base.Start();
if (parent == null)
{
Debug.Log(String.Format("Parent not set in {0}", this.GetType().Name));
return;
}
width = parent.width;
relativePosition = Vector3.zero;
isVisible = true;
canFocus = true;
isInteractive = true;
_drag.width = width - 80;
_drag.height = height;
_drag.relativePosition = Vector3.zero;
_drag.target = parent;
_icon.spriteName = IconSprite;
_icon.relativePosition = new Vector3(5, 0);
_title.relativePosition = new Vector3(50, 13);
_title.text = TitleText;
_lock.relativePosition = new Vector3(width - 70, 2);
_lock.normalBgSprite = "LocationMarkerNormal";
_lock.hoveredBgSprite = "LocationMarkerHovered";
_lock.pressedBgSprite = "LocationMarkerPressed";
_lock.eventClick += (component, param) => LockButtonOnEventClick(component, param);
_close.relativePosition = new Vector3(width - 35, 2);
_close.normalBgSprite = "buttonclose";
_close.hoveredBgSprite = "buttonclosehover";
_close.pressedBgSprite = "buttonclosepressed";
_close.eventClick += (component, param) => parent.Hide();
}
private void LockButtonOnEventClick(UIComponent component, UIMouseEventParameter eventParam)
{
Locked = !Locked;
if (Locked)
{
_lock.normalBgSprite = "LocationMarkerActiveNormal";
_lock.hoveredBgSprite = "LocationMarkerActiveHovered";
_lock.pressedBgSprite = "LocationMarkerActivePressed";
}
else
{
_lock.normalBgSprite = "LocationMarkerNormal";
_lock.hoveredBgSprite = "LocationMarkerHovered";
_lock.pressedBgSprite = "LocationMarkerPressed";
}
}
}
}