-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathItblCustomDialog.brs
More file actions
259 lines (232 loc) · 8.84 KB
/
ItblCustomDialog.brs
File metadata and controls
259 lines (232 loc) · 8.84 KB
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
sub init()
setLocals()
SetControls()
setTheme()
SetObservers()
SetDefaultFocus()
end sub
sub setLocals()
m.exitCalled = false
m.exitPopUpOpened = false
m.errorMessage = invalid
m.width = 540
m.buttonHeight = 64
m.buttonBorderSize = 3
m.buttonArray = []
m.focusedIndex = 0
m.defaultTheme = {
"backgroundColor" : "#1C1C1C"
"defaultBoldFont" : "font:MediumBoldSystemFont"
"defaultRegularFont": "font:MediumSystemFont"
"buttonBorderColor": "0xFFFFFF"
"buttonColorFocused": "0xB30041"
"buttonTextColorFocused": "0xFFFFFF"
"buttonColorUnFocused" : "0xFFFFFF"
"buttonTextColorUnFocused": "0xFFFFFF"
}
end sub
sub SetControls()
m.gContainer = m.top.findNode("gContainer")
m.gMainGroup = m.top.findNode("gMainGroup")
m.background = m.top.findNode("background")
m.mainDialog = m.top.findNode("mainDialog")
m.pImage = m.top.findNode("pImage")
m.lgMessage = m.top.findNode("lgMessage")
m.lgButton = m.top.findNode("lgButton")
end sub
sub setTheme()
end sub
sub SetObservers()
m.top.ObserveField("focusedChild", "OnFocusedChildChanged")
end sub
sub SetDefault()
m.buttonArray = []
m.focusedIndex = 0
m.background.uri = ""
m.background.uri = "pkg:/ItblImages/focus/white_fill_corner_radius_10.9.png"
m.background.blendColor = "#808080"
m.pImage.uri = ""
m.pImage.uri = "pkg:/ItblImages/focus/white_fill_corner_radius_10.9.png"
m.lgMessage.removeChildrenIndex(m.lgMessage.getChildCount() - 1, 0)
m.lgButton.removeChildrenIndex(m.lgButton.getChildCount() - 1, 0)
if m.errorMessage = invalid
m.gMainGroup.removeChild(m.errorMessage)
m.errorMessage = invalid
end if
end sub
sub SetDefaultFocus()
if m.buttonArray.count() > 0
m.focusedIndex = 0
m.buttonArray[m.focusedIndex].setFocus(true)
end if
end sub
sub OnContentSet(event as dynamic)
data = event.getData()
if data <> invalid
SetDefault()
payload = data.ottPayload
if payload.backgroundColor <> invalid and payload.backgroundColor <> ""
m.background.blendColor = payload.backgroundColor
else
m.background.blendColor = m.defaultTheme.backgroundColor
end if
if payload.fhd_image <> invalid and payload.fhd_image <> ""
m.pImage.uri = payload.fhd_image
end if
if payload.dialogHeader <> invalid and payload.dialogHeader <> ""
header = CreateLabel(payload.dialogHeader, 32, payload.dialogHeaderFont, m.defaultTheme.defaultBoldFont)
header.wrap = true
header.lineSpacing = 2
header.maxLines = 2
m.lgMessage.appendChild(header)
end if
if payload.dialogText <> invalid and payload.dialogText <> ""
message = CreateLabel(payload.dialogText, 26, payload.dialogBodyFont, m.defaultTheme.defaultRegularFont)
message.wrap = true
message.lineSpacing = 2
message.maxLines = 2
m.lgMessage.appendChild(message)
end if
if payload.buttons <> invalid
counter = 1
for each item in payload.buttons
button = CreateButton("button_"+counter.ToStr(), item, 30, payload.dialogButtonFont, m.defaultTheme.defaultRegularFont)
m.lgButton.appendChild(button)
counter++
end for
end if
boundingRect = m.gMainGroup.boundingRect()
m.background.height = boundingRect.height + (34*2)
m.background.width = boundingRect.width + (34*2)
end if
end sub
sub ShowHideErrorMessage(showMessage as boolean, errorMessage = "" as string)
if showMessage
if m.errorMessage = invalid
m.errorMessage = CreateLabel(errorMessage, 24, invalid, m.defaultTheme.defaultRegularFont)
m.errorMessage.wrap = true
m.errorMessage.color = "#FF0000"
m.errorMessage.maxLines = 1
boundingRect = m.mainDialog.boundingRect()
m.errorMessage.translation = [0,boundingRect.height + 10]
m.gMainGroup.appendChild(m.errorMessage)
else
m.errorMessage.text = errorMessage
end if
else
m.gMainGroup.removeChild(m.errorMessage)
m.errorMessage = invalid
end if
boundingRect = m.gMainGroup.boundingRect()
m.background.height = boundingRect.height + (34*2)
m.background.width = boundingRect.width + (34*2)
end sub
function CreateLabel(labelText as string, fontSize as integer, labelFont as object, defaultFont as string)
label = CreateObject("roSGNode", "Label")
label.text =labelText
label.width = m.width
if labelFont <> invalid and FileExists(labelFont)
fontPath = labelFont
font = CreateFont(fontPath, fontSize)
else
font = defaultFont
end if
label.font = font
return label
end function
function CreateButton(id as string, item as object, fontSize as integer, dialogButtonFont as object, defaultFont as string)
buttonBorderColor = item.buttonBorderColor
buttonColorFocused = item.buttonColorFocused
buttonColorUnFocused = item.buttonColorUnFocused
buttonTextColorFocused = item.buttonTextColorFocused
buttonTextColorUnFocused = item.buttonTextColorUnFocused
if buttonBorderColor = invalid or buttonBorderColor = "" then buttonBorderColor = m.defaultTheme.buttonBorderColor
if buttonColorFocused = invalid or buttonColorFocused = "" then buttonColorFocused = m.defaultTheme.buttonColorFocused
if buttonColorUnFocused = invalid or buttonColorUnFocused = "" then buttonColorUnFocused = m.defaultTheme.buttonColorUnFocused
if buttonTextColorFocused = invalid or buttonTextColorFocused = "" then buttonTextColorFocused = m.defaultTheme.buttonTextColorFocused
if buttonTextColorUnFocused = invalid or buttonTextColorUnFocused = "" then buttonTextColorUnFocused = m.defaultTheme.buttonTextColorUnFocused
if dialogButtonFont <> invalid and FileExists(dialogButtonFont)
fontPath = dialogButtonFont
font = CreateFont(fontPath, fontSize)
else
font = defaultFont
end if
borderData = {
"height" : m.buttonHeight,
"width" : m.width,
"size" : m.buttonBorderSize,
"buttonBorderColor" : buttonBorderColor,
"buttonColorFocused" : buttonColorFocused,
"buttonColorUnFocused" : buttonColorUnFocused,
"buttonTextColorFocused" : buttonTextColorFocused,
"buttonTextColorUnFocused" : buttonTextColorUnFocused
"font" : font
}
print "borderData "borderData
button = CreateObject("roSGNode", "ItblButton")
button.id = id
button.buttonText = item.buttonText
button.buttonDeeplink = item.buttonDeeplink
button.borderData = borderData
button.observeField("buttonSelected", "OnButtonSelected")
m.buttonArray.push(button)
return button
end function
sub OnButtonFocused(event as dynamic)
node = event.getRoSGNode()
child = node.getChild(0)
if node.hasFocus()
node.blendColor = node.focusedColor
child.color = child.focusedColor
else
node.blendColor = node.unFocusedColor
child.color = child.unFocusedColor
end if
end sub
sub SetFocusToButton(key)
buttonCount = m.buttonArray.count()
if buttonCount > 1
if key = "down"
if m.focusedIndex < (buttonCount - 1)
m.focusedIndex++
m.buttonArray[m.focusedIndex].setFocus(true)
end if
else if key = "up"
if m.focusedIndex > 0
m.focusedIndex--
m.buttonArray[m.focusedIndex].setFocus(true)
end if
end if
else if buttonCount > 0
SetDefaultFocus()
end if
end sub
sub OnFocusedChildChanged()
if m.top.hasFocus()
SetDefaultFocus()
end if
end sub
function OnkeyEvent(key as string, press as boolean) as boolean
result = false
if press
if key = "back"
if m.errorMessage = invalid
m.top.closeDialog = true
result = true
end if
else if key = "up" or key = "down"
ShowHideErrorMessage(false)
SetFocusToButton(key)
result = true
else if key = "OK"
ShowHideErrorMessage(false)
if m.buttonArray[m.focusedIndex].hasFocus()
m.top.clickEvent = { "buttonText": m.buttonArray[m.focusedIndex].buttonText, "buttonDeeplink": m.buttonArray[m.focusedIndex].buttonDeeplink, "action": "link", "isClick": true, "message" : m.buttonArray[m.focusedIndex].buttonDeeplink}
result = true
end if
else
ShowHideErrorMessage(false)
end if
end if
return result
end function