3 MenuName
= "ui:interface:r2ed_triggers_menu",
7 function r2
.logicUI
:openLogicMenu(caller
)
9 launchContextMenuInGame(self
.MenuName
)
10 if self
.Menu
== nil or self
.Menu
.isNil
then
11 self
.Menu
= getUI(self
.MenuName
)
14 local menu
= self
.Menu
16 menu
:setParentPos(caller
)
17 menu
:setPosRef("BL TL")
19 local root
= menu
:getRootMenu()
20 if (caller
.y_real
- root
.h_real
< 0) then
21 menu
.y
= root
.h_real
+ caller
.h_real
29 function r2
.logicUI
:getEltUIInstId(eltUI
)
30 return eltUI
.Env
.InstanceId
33 function r2
.logicUI
:setEltUIInstId(eltUI
, id
)
34 eltUI
.Env
.InstanceId
= id
37 function r2
.logicUI
:setSequUIInstId(sequUI
, id
)
38 sequUI
.Env
.InstanceId
= id
41 function r2
.logicUI
:getSequUIInstId(sequUI
)
42 return sequUI
.Env
.InstanceId
45 ------- NEW ELEMENT UI ---------------------------------------------
46 function r2
.logicUI
:newElementUI(classUI
, newInst
, withOrder
)
48 local templateParams
= classUI
.eltTemplateParams
50 --not necessary current sequenceUI
51 local sequenceUI
= classUI
:updatedSequUI()
54 local listElements
= sequenceUI
:find("elements_list")
57 for i
=0, listElements
.childrenNb
-1 do
58 local elt
= listElements
:getChild(i
)
59 local instId
= self
:getEltUIInstId(elt
)
60 if instId
==newInst
.InstanceId
then return end
63 classUI
.elementsIdCounter
= classUI
.elementsIdCounter
+1
65 local elementId
= "elt"..classUI
.elementsIdCounter
68 local newElement
= createGroupInstance("element_template", listElements
.id
,
69 {id
=elementId
, posref
="TL TL", x
="0", y
="0", sizeref
="w", hardtext
="",
70 select_elt
=templateParams
.selectElt
, open_elt_editor
=templateParams
.openEltEditor
,
71 max_min_elt
=templateParams
.maxMinElt
, remove_elt
=templateParams
.removeElt
, open_chat
=templateParams
.openChat
,
72 col_over
=templateParams
.colOver
, col_pushed
=templateParams
.colPushed
, multi_max_line
=templateParams
.multiMaxLine
})
75 -- add element to list
78 local comps
= newInst
.Parent
79 for i
=0, comps
.Size
-1 do
81 if comp
.InstanceId
== newInst
.InstanceId
then
86 local eltEditor
= listElements
:find("edit_element")
88 local indexEltEditor
= listElements
:getElementIndex(eltEditor
)
89 if indexEltEditor
<= eltIndex
then eltIndex
=eltIndex
+1 end
91 eltIndex
= listElements
.childrenNb
94 listElements
:addChildAtIndex(newElement
, eltIndex
)
95 listElements
.parent
:updateCoords()
97 -- active global minimize / maximize button
98 if classUI
.maxAndMin
then
100 classUI
:maximizeMinimizeElement(newElement
)
102 if listElements
.childrenNb
== 2 then
103 local maxElts
= sequenceUI
:find("maximize_elements")
105 maxElts
.active
= true
109 -- scroll goes down to new element
110 local scrollBar
= sequenceUI
:find("scroll_objects")
112 scrollBar
.trackPos
= 0
115 local scroll
= newElement
:find("scroll_bar_text")
118 local scrollText
= newElement
:find("scroll_text_gr")
120 scroll
:setTarget(scrollText
.id
)
122 self
:setEltUIInstId(newElement
, newInst
.InstanceId
)
124 -- update next elements title
125 if eltIndex
<listElements
.childrenNb
-1 then
126 for i
=eltIndex
+1, listElements
.childrenNb
-1 do
127 local elt
= listElements
:getChild(i
)
128 if r2
.logicUI
:getEltUIInstId(elt
) then
129 classUI
:updateElementTitle(elt
)
134 if classUI
.ownCreatedInstances
[newInst
.InstanceId
] == true
135 or r2
.logicComponents
.undoRedoInstances
[newInst
.InstanceId
]==true then
137 local select
= newElement
:find("select")
140 classUI
:selectElement(select
, self
:getSequUIInstId(sequenceUI
))
141 classUI
.ownCreatedInstances
[newInst
.InstanceId
] = nil
142 r2
.logicComponents
.undoRedoInstances
[newInst
.InstanceId
] = nil
145 classUI
:updateElementUI(newElement
)
148 ------ REMOVE ELEMENT UI -------------------------------------------
149 function r2
.logicUI
:removeElementUI(classUI
, removedEltUI
)
151 local sequenceUI
= classUI
:currentSequUI()
154 local listElements
= sequenceUI
:find("elements_list")
157 -- update follow elements number
158 local removedIndex
= listElements
:getElementIndex(removedEltUI
)
159 for i
= removedIndex
+1, (listElements
.childrenNb
-1) do
160 local element
= listElements
:getChild(i
)
163 -- if this element is not the element editor, update its title
164 if self
:getEltUIInstId(element
) then
165 classUI
:updateElementTitle(element
)
169 -- delete element and update coordinates of elements list
170 if removedEltUI
== classUI
:currentEltUI() then
172 classUI
:setCurrentEltUIId(nil)
174 -- inactive element editor
175 local eltEditor
= listElements
:find("edit_element")
177 eltEditor
.active
= false
179 -- disactive up and down element buttons
180 local orderGr
= sequenceUI
:find("order_group")
182 orderGr
.active
= false
185 listElements
:delChild(removedEltUI
)
186 listElements
.parent
:invalidateCoords()
188 -- if any elements in list, disactive global minimize / maximize button
189 if listElements
.childrenNb
== 1 then
190 local minElts
= sequenceUI
:find("minimize_elements")
193 local maxElts
= sequenceUI
:find("maximize_elements")
196 minElts
.active
= false
197 maxElts
.active
= false
201 ------ UPDATE ELEMENT UI -------------------------------------------
202 function r2
.logicUI
:updateElementUI(classUI
, elementUI
)
204 local instance
= r2
:getInstanceFromId(self
:getEltUIInstId(elementUI
))
207 classUI
:updateElementTitle(elementUI
)
209 if instance
.InstanceId
== classUI
:currentEltInstId() then
210 classUI
:updateElementEditor()
215 ------ DOWN/UP ELEMENT UI -------------------------------------------
216 function r2
.logicUI
:downUpElementUI(classUI
, elementUI
, instance
)
218 local listElements
= elementUI
.parent
221 local eltEditor
= listElements
:find("edit_element")
224 local index
= listElements
:getElementIndex(elementUI
)
225 local indexEditor
= listElements
:getElementIndex(eltEditor
)
227 local indexInstance
= -1
228 for i
=0, instance
.Parent
.Size
-1 do
229 if instance
.Parent
[i
]==instance
then
235 if index
>=0 and indexEditor
>=0 and indexInstance
>=0 then
237 local finalIndex
= indexInstance
239 if indexEditor
-1 <= indexInstance
then finalIndex
=finalIndex
+1 end
241 local selectedEltUI
= classUI
:currentEltUI()
242 local isSelected
= (selectedEltUI
==elementUI
)
244 local loop
= math
.abs(finalIndex
-index
)
247 -- replace element UI
249 if finalIndex
< index
then
250 listElements
:upChild(elementUI
)
252 listElements
:downChild(elementUI
)
256 -- replace element editor
259 if finalIndex
< index
then
260 listElements
:upChild(eltEditor
)
262 listElements
:downChild(eltEditor
)
267 local firstIndex
= math
.min(index
, finalIndex
)
268 local lastIndex
= math
.min(listElements
.childrenNb
-1, math
.max(index
, finalIndex
)+1)
269 for i
=firstIndex
, lastIndex
do
270 local eltUI
= listElements
:getChild(i
)
271 if eltUI
~=eltEditor
then
272 classUI
:updateElementTitle(eltUI
)
276 if selectedEltUI
~=nil then
277 selectedEltUI
.active
=false
278 classUI
:updateElementEditor()
284 ------ MAX/MIN ELEMENT UI -------------------------------------------
285 function r2
.logicUI
:maximizeMinimizeElement(element
, allMinimize
)
287 if element
== nil then
288 element
= getUICaller().parent
.parent
.parent
.parent
.parent
.parent
292 local eltText
= element
:find("element_text")
295 local allMin
, allMax
= true, true
296 if allMinimize
~= nil then
301 local maxButton
= element
:find("maximize_element")
303 local minButton
= element
:find("minimize_element")
307 if allMax
and eltText
.active
==false then
308 eltText
.active
= true
309 maxButton
.active
= false
310 minButton
.active
= true
313 elseif allMin
and eltText
.active
==true then
314 eltText
.active
= false
315 maxButton
.active
= true
316 minButton
.active
= false
320 ------ MAX/MIN ELEMENTS UI -------------------------------------------
321 function r2
.logicUI
:maximizeMinimizeElements(classUI
)
323 local sequenceUI
= classUI
:currentSequUI()
326 local elements
= sequenceUI
:find("elements_list")
329 elements
.Env
.Minimize
= not elements
.Env
.Minimize
331 for i
= 0, elements
.childrenNb
-1 do
332 local element
= elements
:getChild(i
)
335 -- if element is not the element editor
336 if self
:getEltUIInstId(element
) and element
~=classUI
:currentEltUI() then
337 classUI
:maximizeMinimizeElement(element
, elements
.Env
.Minimize
)
341 local minElts
= sequenceUI
:find("minimize_elements")
343 local maxElts
= sequenceUI
:find("maximize_elements")
346 if elements
.Env
.Minimize
== true then
347 minElts
.active
= false
348 maxElts
.active
= true
350 minElts
.active
= true
351 maxElts
.active
= false
356 ------ CLOSE EDITOR ------------------------------------------
357 function r2
.logicUI
:closeEditor(classUI
)
359 -- reset current dialog and current chat
360 classUI
:setCurrentEltUIId(nil)
364 ------- UTILS ------------------------------------------------
366 function r2
.logicUI
:findElementUIFromInstance(classUI
, instance
)
368 local sequenceUI
= classUI
:currentSequUI()
371 local eltsList
= sequenceUI
:find("elements_list")
374 for i
=0,eltsList
.childrenNb
-1 do
375 local element
= eltsList
:getChild(i
)
376 if r2
.logicUI
:getEltUIInstId(element
) == instance
.InstanceId
then