1 r2
.logicComponents
= {}
3 r2
.logicComponents
.logicEditors
= {
9 r2
.logicComponents
.undoRedoInstances
= {}
12 ----- INIT ALL EDITORS ----------------------------------------------------
13 function r2
.logicComponents
:initLogicEditors()
15 for k
, uiClass
in pairs(self
.logicEditors
) do
20 ------ SELECT ELEMENT --------------------------------------------
21 function r2
.logicComponents
:selectElement(classUI
, selectedButtonElt
)
23 if selectedButtonElt
== nil then
24 selectedButtonElt
= getUICaller()
26 assert(selectedButtonElt
)
28 local sequenceUI
= classUI
:currentSequUI()
31 local upDown
= sequenceUI
:find("order_group")
34 -- new selected element
35 if selectedButtonElt
.pushed
== true then
37 if classUI
:currentEltUIId() then
39 local lastSelectedElement
= classUI
:currentEltUI()
40 assert(lastSelectedElement
)
42 local lastEltsList
= lastSelectedElement
.parent
43 local editElt
= lastEltsList
:find("edit_element")
46 if classUI
:currentEltUIId() == selectedButtonElt
.parent
.parent
.parent
.id
then
50 lastSelectedElement
.active
= true
51 lastSelectedElement
:find("select").pushed
= false
53 editElt
.active
= false
56 classUI
:setCurrentEltUIId(selectedButtonElt
.parent
.parent
.parent
.id
)
58 local selectedElement
= selectedButtonElt
.parent
.parent
.parent
59 assert(selectedElement
)
61 -- update element editor position in list
62 local eltsList
= sequenceUI
:find("elements_list")
64 local editElt
= eltsList
:find("edit_element")
67 local indexSelectedElt
= eltsList
:getElementIndex(selectedElement
)
68 local indexEltEditor
= eltsList
:getElementIndex(editElt
)
70 if indexEltEditor
<indexSelectedElt
then
71 for i
=indexEltEditor
, indexSelectedElt
-1 do
72 eltsList
:downChild(editElt
)
75 for i
=indexSelectedElt
, indexEltEditor
-2 do
76 eltsList
:upChild(editElt
)
81 selectedElement
.active
= false
82 classUI
:updateElementEditor()
84 upDown
.active
= (classUI
.elementOrder
==true and eltsList
.childrenNb
>2)
86 -- cancel current selection
89 local lastSelectedElement
= classUI
:currentEltUI()
90 assert(lastSelectedElement
)
94 local lastEltsList
= lastSelectedElement
.parent
95 local editElt
= lastEltsList
:find("edit_element")
98 editElt
.active
= false
99 lastSelectedElement
.active
= true
101 classUI
:setCurrentEltUIId(nil)
105 ------ SELECT SEQUENCE --------------------------------------
106 function r2
.logicComponents
:selectSequence(classUI
, sequenceUI
)
108 local sequenceUI
= classUI
:currentSequUI()
111 -- select first chat of dialog
112 local eltsList
= sequenceUI
:find("elements_list")
114 -- if eltsList.childrenNb > 1 then
116 -- local firstElt = eltsList:getChild(0)
118 -- if r2.logicUI:getEltUIInstId(firstElt) == nil then
119 -- firstElt = eltsList:getChild(1)
122 -- local selectedButton = firstElt:find("select")
123 -- assert(selectedButton)
125 -- selectedButton.pushed = true
126 -- classUI:selectElement(selectedButton)
129 -- deselect old selected element
130 if classUI
:currentEltUIId() then
132 local lastSelectedElement
= classUI
:currentEltUI()
133 assert(lastSelectedElement
)
135 local lastEltsList
= lastSelectedElement
.parent
136 local editElt
= lastEltsList
:find("edit_element")
139 lastSelectedElement
.active
= true
140 lastSelectedElement
:find("select").pushed
= false
142 editElt
.active
= false
144 classUI
:setCurrentEltUIId(nil)
147 eltsList
.Env
.Minimize
= true
150 ------ CREATE EDITOR -----------------------------------------------
151 function r2
.logicComponents
:createElementEditor(classUI
)
153 -- not necessary current sequenceUI
154 local sequenceUI
= classUI
:updatedSequUI()
157 -- create element editor
158 local elementsList
= sequenceUI
:find("elements_list")
161 local newEditorElt
= createGroupInstance(classUI
.elementEditorTemplate
, elementsList
.id
, {id
="edit_element", active
="false"})
163 elementsList
:addChild(newEditorElt
)
164 elementsList
.parent
:updateCoords()
166 newEditorElt
.active
= false
171 ----- CLOSE ELEMENT EDITOR ---------------------------------------------
172 function r2
.logicComponents
:closeElementEditor(classUI
)
174 local selectedEltUI
= classUI
:currentEltUI()
175 if selectedEltUI
then
176 local selectedEltButton
= selectedEltUI
:find("select")
177 assert(selectedEltButton
)
179 selectedEltButton
.pushed
= false
180 classUI
:selectElement(selectedEltButton
)
184 ------ NEW ELEMENT INST ------------------------------------------
185 function r2
.logicComponents
:newElementInst(classUI
)
188 ------ UPDATE ELEMENT TITLE -------------------------------------------
189 function r2
.logicComponents
:updateElementTitle(classUI
, eltUI
, showPartIndex
)
191 local eltInst
= r2
:getInstanceFromId(r2
.logicUI
:getEltUIInstId(eltUI
))
197 if showPartIndex
then
198 local index
= self
:searchElementIndex(eltInst
)
199 partIndex
= classUI
.elementInitialName
.." "..index
.." : "
202 local eltName
= eltInst
:getName()
205 local title
= eltUI
:find("title")
207 local uc_title
= ucstring()
208 uc_title
:fromUtf8(partIndex
..eltName
)
209 title
.uc_hardtext_format
= uc_title
212 ------ REMOVE ELEMENT INST ----------------------------------------
213 function r2
.logicComponents
:removeElementInst(classUI
)
215 --r2.requestNewAction(i18n.get("uiR2EDRemoveLogicElementAction"))
217 local toErasedInstId
= classUI
:currentEltInstId()
218 assert(toErasedInstId
)
220 -- request erase node
221 if toErasedInstId
and r2
:getInstanceFromId(toErasedInstId
) then
222 r2
.requestEraseNode(toErasedInstId
, "", -1)
226 ------ UP ELEMENT INST -------------------------------------------
227 function r2
.logicComponents
:upElementInst(classUI
)
229 r2
.requestNewAction(i18n
.get("uiR2EDMoveLogicElementUpAction"))
231 local sequenceUI
= classUI
:currentSequUI()
234 local listElements
= sequenceUI
:find("elements_list")
237 local selectedElement
= classUI
:currentEltUI()
238 assert(selectedElement
)
240 local index
= listElements
:getElementIndex(selectedElement
)
243 local sequenceId
= classUI
:currentSequInstId()
246 r2
.requestMoveNode(sequenceId
, "Components", index
,
247 sequenceId
, "Components", index
-1)
251 ------ DOWN ELEMENT INST -----------------------------------------
252 function r2
.logicComponents
:downElementInst(classUI
)
254 r2
.requestNewAction(i18n
.get("uiR2EDMoveLogicElementDownAction"))
256 local sequenceUI
= classUI
:currentSequUI()
259 local listElements
= sequenceUI
:find("elements_list")
262 local selectedElement
= classUI
:currentEltUI()
263 assert(selectedElement
)
265 local index
= listElements
:getElementIndex(selectedElement
)
267 local sequenceId
= classUI
:currentSequInstId()
269 if index
< r2
:getInstanceFromId(sequenceId
).Components
.Size
-1 then
270 r2
.requestMoveNode(sequenceId
, "Components", index
,
271 sequenceId
, "Components", index
+1)
275 ---- TRANSLATE SECONDS IN HOURS, MINUTES AND ECONDS
276 function r2
.logicComponents
:calculHourMinSec(totalSecNb
)
278 local minSecNb
, hourNb
= totalSecNb
, 0
279 while minSecNb
> 3599 do
281 minSecNb
= minSecNb
- 3600
284 local minNb
, secNb
= 0, minSecNb
290 return hourNb
, minNb
, secNb
294 --- SEARCH INDEX OF INSTANCE IN COMPONENT TABLE
295 function r2
.logicComponents
:searchElementIndex(instance
, fun
)
297 local components
= instance
.Parent
300 for i
=0, components
.Size
-1 do
301 local comp
= components
[i
]
302 if fun
and not fun(comp
) then
303 decalSequ
= decalSequ
+1
304 elseif comp
.User
.Deleted
== true then
305 decalSequ
= decalSequ
+1
307 if comp
.InstanceId
== instance
.InstanceId
then