Merge branch 'fixes' into main/gingo-test
[ryzomcore.git] / ryzom / common / data_common / r2 / r2_ui_triggers.lua
blob72a5e9cf5643548b977161eb0bf07a8f61cee390
1 r2.maxActivities = 14
2 r2.sequencesNb = 0
4 r2.TimeLimitsProp = {
5 [tostring(i18n.get("uiR2EdNoTimeLimit"))]="No Limit",
6 --["Until a certain time"]="Until",
7 [tostring(i18n.get("uiR2EdWhileChat"))]="Chat",
8 [tostring(i18n.get("uiR2EdForCertainTime"))]="Few Sec"
10 r2.TimeLimitsCB = {
11 ["No Limit"]=tostring(i18n.get("uiR2EdNoTimeLimit")),
12 --["Until"]="Until a certain time",
13 ["Chat"]=tostring(i18n.get("uiR2EdWhileChat")),
14 ["Few Sec"]=tostring(i18n.get("uiR2EdForCertainTime")),
17 r2.activityTypeMenu = {
18 ["Inactive"]=tostring(i18n.get("uiR2EdInactive")),
19 ["Stand Still"]=tostring(i18n.get("uiR2EdStandStill")),
20 ["Follow Route"]=tostring(i18n.get("uiR2EdFollowRoad")),
21 ["Patrol"]=tostring(i18n.get("uiR2EdPatrol")),
22 ["Repeat Road"]=tostring(i18n.get("uiR2EdRepeatRoad")),
23 --["Deploy"]=tostring(i18n.get("uiR2EdDeploy")),
24 ["Wander"]=tostring(i18n.get("uiR2EdWander")),
25 ["Stand On Start Point"]=tostring(i18n.get("uiR2EdStandOnStartPoint")),
26 ["Go To Start Point"]=tostring(i18n.get("uiR2EdGoToStartPoint")),
27 ["Go To Zone"]=tostring(i18n.get("uiR2EdGoToZone")),
28 ["Sit Down"]=tostring(i18n.get("uiR2EdSitDown")),
29 ["Stand Up"]=tostring(i18n.get("uiR2EdStandUp")),
33 r2.fromNPCNameToId = {}
34 r2.fromEmoteIdToName = {}
36 r2.ownCreatedInstances = {}
39 ------------------ INIT TRIGGERS EDITOR ----------------------------------------------------------------
40 function r2:initTriggersEditor()
42 -- emote
43 local menuName = "ui:interface:r2ed_triggers_menu"
44 local emoteMenu = getUI(menuName)
45 local emoteMenu = emoteMenu:getRootMenu()
46 assert(emoteMenu)
47 emoteMenu:reset()
49 local emoteTable = initEmotesMenu(menuName, "")
50 for id, name in pairs(emoteTable) do
51 r2.fromEmoteIdToName[id] = name
52 end
53 end
55 ------------------ INIT TRIGGERS EDITOR ----------------------------------------------------------------
56 function r2:initActivityEditor(activityEditor)
58 -- time limit
59 local timeLimitCB = activityEditor:find("time_limit"):find("combo_box")
60 assert(timeLimitCB)
61 timeLimitCB:resetTexts()
62 timeLimitCB:addText(ucstring(i18n.get("uiR2EdNoTimeLimit")))
63 --timeLimitCB:addText(ucstring("Until a certain time"))
64 timeLimitCB:addText(ucstring(i18n.get("uiR2EdForCertainTime")))
65 timeLimitCB:addText(ucstring(i18n.get("uiR2EdWhileChat")))
66 end
68 ----------------------------------------------------------------------------------------------------
69 function r2:getSelectedEltUI(uiName)
70 local id = r2:getSelectedEltUIId(uiName)
71 if id then
72 return getUI(id)
73 else
74 return nil
75 end
76 end
78 ----------------------------------------------------------------------------------------------------
79 function r2:getSelectedEltUIId(uiName)
81 if uiName == nil then
82 dumpCallStack(1)
83 assert(false)
84 end
85 local windowUI = getUI("ui:interface:"..uiName)
86 assert(windowUI)
88 return windowUI.Env.selectedElementId
89 end
91 ----------------------------------------------------------------------------------------------------
92 function r2:setSelectedEltUIId(uiName, eltUIId)
93 local windowUI = getUI("ui:interface:"..uiName)
94 assert(windowUI)
96 windowUI.Env.selectedElementId = eltUIId
97 end
99 ----------------------------------------------------------------------------------------------------
100 function r2:getSelectedEltInstId(uiName)
102 local element = r2:getSelectedEltUI(uiName)
103 if element ~= nil then
104 return element.Env.elementId
105 else
106 return nil
110 ----------------------------------------------------------------------------------------------------
111 function r2:setSelectedEltInstId(uiName, instId)
112 local element = r2:getSelectedEltUI(uiName)
113 assert(element)
114 element.Env.elementId = instId
117 ----------------------------------------------------------------------------------------------------
118 function r2:getSelectedEltInst(uiName)
119 local id = r2:getSelectedEltInstId(uiName)
120 if id then
121 return r2:getInstanceFromId(id)
122 else
123 return nil
127 ----------------------------------------------------------------------------------------------------
128 function r2:getSelectedSequInstId(uiName)
129 local windowUI = getUI("ui:interface:"..uiName)
130 assert(windowUI)
132 local tab = windowUI:find("sequence_tabs")
133 assert(tab)
135 local sequence = windowUI:find(tab.associatedGroupSelection)
136 assert(sequence)
138 if sequence.Env == nil then return nil end
140 return sequence.Env.sequenceId
143 ----------------------------------------------------------------------------------------------------
144 function r2:getSelectedSequInst(uiName)
145 local id = r2:getSelectedSequInstId(uiName)
146 if id then
147 return r2:getInstanceFromId(id)
148 else
149 return nil
153 ----------------------------------------------------------------------------------------------------
154 function r2:getSelectedSequ(uiName)
155 local windowUI = getUI("ui:interface:"..uiName)
156 assert(windowUI)
158 local tab = windowUI:find("sequence_tabs")
160 if tab~=nil then
161 local associatedGroup = tab.associatedGroupSelection
162 if associatedGroup == "" then
163 return nil
166 local sequence = windowUI:find(associatedGroup)
167 assert(sequence)
169 return sequence
170 else
171 return windowUI:find("sequence_elts")
175 ----------------------------------------------------------------------------------------------------
176 function r2:setSelectedSequInstId(uiName, instanceId)
178 local windowUI = getUI("ui:interface:"..uiName)
179 assert(windowUI)
181 local tab = windowUI:find("sequence_tabs")
182 assert(tab)
184 local sequence = windowUI:find(tab.associatedGroupSelection)
185 assert(sequence)
187 sequence.Env.sequenceId = instanceId
190 ------------------ CLOSE ALL UI --------------------------------------------------------------------
191 function r2:closeActivitySequenceUI()
193 local window = getUI("ui:interface:r2ed_edit_activity_sequence")
194 if window~=nil then
195 window.active = false
197 r2:openAndUpdateMiniActivityView()
201 ------------------ NEW SEQUENCE --------------------------------------------------------------------
202 function r2:newActivitiesSequence(firstRequest, activitySequence, reset)
205 local triggersUI = getUI("ui:interface:r2ed_triggers")
206 assert(triggersUI)
208 local tab = triggersUI:find("sequence_tabs")
209 assert(tab)
211 if firstRequest and tab.tabButtonNb == 7 then return -1 end
213 if firstRequest == true then
214 activitySequence = r2.newComponent("ActivitySequence")
216 --local name = tostring(i18n.get("uiR2EdSeq"))..tab.tabButtonNb+1
217 --activitySequence.Name = name
219 local npcGroup = r2:getSelectedInstance()
220 assert(npcGroup)
222 r2.requestInsertNode(npcGroup:getBehavior().InstanceId, "Activities", -1, "", activitySequence)
223 -- r2.requestInsertNode(npcGroup.InstanceId,"ActivitiesId",-1,"",activitySequence.InstanceId)
224 -- r2.requestInsertNode(r2:getCurrentAct().InstanceId,"ActivitiesIds",-1,"",activitySequence.InstanceId)
226 r2.ownCreatedInstances[activitySequence.InstanceId] = true
228 return activitySequence.InstanceId
229 else
231 local updateMiniActivityView = r2.ownCreatedInstances[activitySequence.InstanceId]
232 if reset then
233 r2.ownCreatedInstances[activitySequence.InstanceId] = true
236 local templateParams = {
237 newElt="r2:newActivity(true)",
238 newEltText=tostring(i18n.get("uiR2EdNewActivity")),
239 eltOrderText=tostring(i18n.get("uiR2EdActivityOrder")),
240 upElt="r2:upActivity()",
241 downElt="r2:downActivity()",
242 maxMinElts="r2:maximizeMinimizeActivities()",
243 downUpColor="200 120 80 255",
244 colPushed = "200 80 80 255",
245 paramsL= "r2:selectSequenceTab('r2ed_triggers', "..tostring(tab.tabButtonNb)..")"
248 local editorEltTemplate = "template_edit_activity"
249 local sequence = r2:newElementsSequence("r2ed_triggers", templateParams, editorEltTemplate,
250 activitySequence, tostring(i18n.get("uiR2EdSeq")))
251 r2:initActivityEditor(sequence:find("edit_element"))
253 local activities = activitySequence.Components
254 for a = 0, activities.Size - 1 do
255 r2:newActivity(false, nil, activities[a])
258 -- new MiniActivity sequence
259 if updateMiniActivityView==true then
260 --r2:updateSequencesButtonBar(tab.tabButtonNb-1, activitySequence.Name)
261 r2:updateSequencesButtonBar(tab.tabButtonNb-1, r2:getSequenceName(activitySequence))
262 r2:openAndUpdateMiniActivityView()
267 ------------------ REMOVE SEQUENCE -----------------------------------------------------------------
268 function r2:removeActivitiesSequence()
270 local sequenceId = r2:removeElementsSequence("r2ed_triggers", "Activities", tostring(i18n.get("uiR2EdSeq")))
272 -- local group = r2:getSelectedInstance()
273 -- assert(group)
274 -- local sequenceIndex = -1
275 -- for i=0,group.ActivitiesId.Size-1 do
276 -- if group.ActivitiesId[i] == sequenceId then
277 -- sequenceIndex = i
278 -- break
279 -- end
280 -- end
281 -- if sequenceIndex ~= -1 then
282 -- r2.requestEraseNode(group.InstanceId, "ActivitiesId", sequenceIndex)
283 -- end
285 -- local currentAct = r2:getCurrentAct()
286 -- sequenceIndex = -1
287 -- for i=0,currentAct.ActivitiesIds.Size-1 do
288 -- if currentAct.ActivitiesIds[i] == sequenceId then
289 -- sequenceIndex = i
290 -- break
291 -- end
292 -- end
293 -- if sequenceIndex ~= -1 then
294 -- r2.requestEraseNode(currentAct.InstanceId, "ActivitiesIds", sequenceIndex)
295 -- end
298 function r2:removeActivitiesSequenceUI(tabIndex)
299 local firstEltName = r2:removeElementsSequenceUI(tabIndex, "r2ed_triggers", "Activities", tostring(i18n.get("uiR2EdSeq")))
301 r2:updateSequencesButtonBar(0, firstEltName)
304 ------------------ SELECT ACTIVITY ------------------------------------------------------------------
305 function r2:selectActivity()
306 r2:selectTriggerElement(nil, "r2ed_triggers")
308 if getUICaller().pushed == true then
309 r2:updateActivityEditor()
313 ------------------ NEW ACTIVITY --------------------------------------------------------------------
314 function r2:newActivity(firstRequest, tableInit, instanceElement, sequenceUI, sequenceInstId)
318 local uiName = "r2ed_triggers"
320 if sequenceUI == nil then
321 sequenceUI = r2:getSelectedSequ(uiName)
323 local activityList
324 if sequenceUI~=nil then
325 activityList = sequenceUI:find("elements_list")
326 assert(activityList)
328 if activityList.childrenNb-1 == r2.maxActivities then return false end
331 if firstRequest == true then
333 instanceElement = r2.newComponent("ActivityStep")
335 if tableInit ~= nil then
336 instanceElement.Activity = tableInit.Activity
337 instanceElement.ActivityZoneId = r2.RefId(tableInit.ActivityZoneId)
338 instanceElement.TimeLimit = tableInit.TimeLimit
339 instanceElement.TimeLimitValue = tableInit.TimeLimitValue
340 else
341 instanceElement.TimeLimit = "No Limit"
342 instanceElement.Activity = "Stand Still"
345 if sequenceInstId == nil then
346 sequenceInstId = r2:getSelectedSequInstId(uiName)
348 assert(sequenceInstId)
350 r2.requestInsertNode(sequenceInstId, "Components", -1, "", instanceElement)
352 r2.ownCreatedInstances[instanceElement.InstanceId] = true
353 else
355 local templateParams = {
356 selectElt="r2:selectActivity()",
357 openEltEditor="r2:openActivityEditor()",
358 maxMinElt="r2:maximizeMinimizeActivity()",
359 removeElt="r2:removeActivity()",
360 colOver="200 120 80 120",
361 colPushed="200 120 80 255"
364 local element = r2:newTriggerElement(uiName, tostring(i18n.get("uiR2EdActivity")), templateParams, sequenceUI, instanceElement.InstanceId)
366 r2:updateActivityChatSequence(element)
368 -- active chat button if a chat sequence is associated to this activity
369 if instanceElement.Chat ~= "" then
371 local activityEditor = sequenceUI:find("edit_element")
372 assert(activityEditor)
373 local chatButtonEditor = activityEditor:find("open_chat_sequence")
374 assert(chatButtonEditor)
376 chatButtonEditor.active = true
380 return true
384 function r2:buildActivityTitle(activityUI, erase)
386 local activityInst = r2:getInstanceFromId(activityUI.Env.elementId)
387 assert(activityInst)
389 -- part1
390 local index = r2:searchElementIndex(activityInst)
391 if erase==true then index = index-1 end
392 local part1 = tostring(i18n.get("uiR2EdActivity")).." "..index.." : "
394 -- part2
395 if not r2.activityTypeMenu[activityInst.Activity] then
396 debugInfo(colorTag(255,0,0).."The activity '".. activityInst.Activity.."' is not properly registred")
399 local part2 = r2.activityTypeMenu[activityInst.Activity].." "
400 if activityInst.ActivityZoneId~= "" then
401 local place = r2:getInstanceFromId(tostring(activityInst.ActivityZoneId))
402 if place~=nil then
403 part2 = part2.. place.Name .." "
404 end
407 -- part3
408 local part3 = ""
409 if activityInst.TimeLimit == "Few Sec" then
411 local hourNb, minNb, secNb = r2:calculHourMinSec(tonumber(activityInst.TimeLimitValue))
413 local timeLimitText = tostring(i18n.get("uiR2EdFor")) .. " "
414 if hourNb ~= 0 then timeLimitText = timeLimitText .. hourNb .. tostring(i18n.get("uiR2EdShortHours")) .. " " end
415 if minNb ~= 0 then timeLimitText = timeLimitText .. minNb .. tostring(i18n.get("uiR2EdShortMinutes")) .. " " end
416 timeLimitText = timeLimitText .. secNb .. tostring(i18n.get("uiR2EdShortSeconds"))
418 part3 = timeLimitText
420 elseif r2.TimeLimitsCB[activityInst.TimeLimit] ~= nil then
421 part3 = string.lower(r2.TimeLimitsCB[activityInst.TimeLimit])
424 -- title
425 local title = activityUI:find("title")
426 assert(title)
427 title.uc_hardtext= part1..part2..part3
430 function r2:getActivityName(activityInst)
432 -- part1
433 local index = r2:searchElementIndex(activityInst)
434 if erase==true then index = index-1 end
435 local part1 = tostring(i18n.get("uiR2EdActivity")).." "..index.." : "
437 -- part2
438 if not r2.activityTypeMenu[activityInst.Activity] then
439 debugInfo(colorTag(255,0,0).."The activity '".. activityInst.Activity.."' is not properly registred")
442 local part2 = r2.activityTypeMenu[activityInst.Activity].." "
443 if activityInst.ActivityZoneId~= "" then
444 local place = r2:getInstanceFromId(tostring(activityInst.ActivityZoneId))
445 if place~=nil then
446 part2 = part2.. place.Name .." "
447 end
450 -- part3
451 local part3 = ""
452 if activityInst.TimeLimit == "Few Sec" then
454 local hourNb, minNb, secNb = r2:calculHourMinSec(tonumber(activityInst.TimeLimitValue))
456 local timeLimitText = tostring(i18n.get("uiR2EdFor")) .. " "
457 if hourNb ~= 0 then timeLimitText = timeLimitText .. hourNb .. tostring(i18n.get("uiR2EdShortHours")) .. " " end
458 if minNb ~= 0 then timeLimitText = timeLimitText .. minNb .. tostring(i18n.get("uiR2EdShortMinutes")) .. " " end
459 timeLimitText = timeLimitText .. secNb .. tostring(i18n.get("uiR2EdShortSeconds"))
461 part3 = timeLimitText
463 elseif r2.TimeLimitsCB[activityInst.TimeLimit] ~= nil then
464 part3 = string.lower(r2.TimeLimitsCB[activityInst.TimeLimit])
467 return part1..part2..part3
470 function r2:getElementName(elementInst)
472 if elementInst:isKindOf("ActivityStep") then
473 return r2:getActivityName(elementInst)
474 elseif elementInst:isKindOf("ChatStep") then
475 return r2:getChatName(elementInst)
476 elseif elementInst:isKindOf("LogicEntityAction") then
477 return r2:getActionName(elementInst)
478 elseif elementInst:isKindOf("LogicEntityReaction") then
479 return r2:getReactionName(elementInst)
480 elseif elementInst:isKindOf("ChatSequence") or elementInst:isKindOf("ActivitySequence") then
481 return r2:getSequenceName(elementInst)
484 return ""
487 function r2:updateActivityChatSequence(elementUI, canceledChatStepId)
489 if elementUI == nil then
490 elementUI = r2:getSelectedEltUI("r2ed_triggers")
492 assert(elementUI)
494 local instance = r2:getInstanceFromId(elementUI.Env.elementId)
495 assert(instance)
497 local chatSequence = r2:getInstanceFromId(tostring(instance.Chat))
499 local activityText = elementUI:find("text_list")
500 assert(activityText)
502 local sep = elementUI:find("sep")
503 assert(sep)
505 activityText:clear()
507 if chatSequence ~= nil then
508 local counterTime = 0
510 if chatSequence.Components.Size > 0 then
512 local emptyText = true
514 activityText:addColoredTextChild("\n"..tostring(i18n.get("uiR2EdSequenceStart")), 255, 175, 135, 255)
516 for c = 0, chatSequence.Components.Size - 1 do
517 local chat = chatSequence.Components[c]
519 if chat.InstanceId ~= canceledChatStepId then
520 counterTime = counterTime + tonumber(chat.Time)
522 local firstLine = true
524 local who = tostring(chat.Actions[0].Who)
525 if who ~= "" then
527 local facing = tostring(chat.Actions[0].Facing)
528 local emote = chat.Actions[0].Emote
529 local says = chat.Actions[0].Says
531 local minNb, secNb = r2:calculMinSec(counterTime)
532 local countInfo = "*"
533 if minNb ~= 0 then
534 countInfo = countInfo..tostring(minNb)..tostring(i18n.get("uiR2EdShortMinutes"))
536 countInfo = countInfo.." "..tostring(secNb)..tostring(i18n.get("uiR2EdShortSeconds"))..":"
538 if facing ~= "" then
539 facing = r2:getInstanceFromId(who).Name .. " "..tostring(i18n.get("uiR2EdFaces")).." " .. r2:getInstanceFromId(facing).Name
540 if firstLine then
541 activityText:addColoredTextChild(countInfo, 220, 140, 100, 255)
542 firstLine = false
544 activityText:addTextChild(ucstring(facing))
545 emptyText = false
547 if r2.fromEmoteIdToName[emote] ~= nil then
548 emote = r2:getInstanceFromId(who).Name .. " "..string.lower(tostring(i18n.get("uiR2EdEmote"))).." : " .. r2.fromEmoteIdToName[emote]
549 if firstLine then
550 activityText:addColoredTextChild(countInfo, 220, 140, 100, 255)
551 firstLine = false
553 activityText:addTextChild(ucstring(emote))
554 emptyText = false
556 if r2:getInstanceFromId(says)~=nil and r2:getInstanceFromId(says).Text ~= "" then
557 says = r2:getInstanceFromId(who).Name .. " "..tostring(i18n.get("uiR2EdSays")).." : " .. r2:getInstanceFromId(says).Text
558 if firstLine then
559 activityText:addColoredTextChild(countInfo, 220, 140, 100, 255)
560 firstLine = false
562 activityText:addTextChild(ucstring(says))
563 emptyText = false
566 end
569 if emptyText == true then
570 activityText:clear()
571 sep.active = false
572 else
573 sep.active = true
575 local hourNb, minNb, secNb = r2:calculHourMinSec(counterTime)
576 local totalChatTime = ""
577 if hourNb ~= 0 then
578 totalChatTime = tostring(hourNb)..tostring(i18n.get("uiR2EdShortHours"))
580 if minNb ~= 0 then
581 totalChatTime = totalChatTime.." "..tostring(minNb)..tostring(i18n.get("uiR2EdShortMinutes"))
583 totalChatTime = totalChatTime.." "..tostring(secNb)..tostring(i18n.get("uiR2EdShortSeconds"))
584 activityText:addColoredTextChild(tostring(i18n.get("uiR2EdSequenceEnd")).." (".. totalChatTime ..")\n", 255, 175, 135, 255)
586 end
587 else
588 sep.active = false
591 --update title
592 r2:buildActivityTitle(elementUI, false)
594 if r2:getSelectedEltInstId("r2ed_triggers") == instance.InstanceId then
595 local eltEditor = r2:getSelectedSequ("r2ed_triggers"):find("edit_element")
596 assert(eltEditor)
597 r2:updateActivityEditor()
600 r2:updateMiniActivityView()
603 function r2:updateActivitiesWhithThisChatSequence(chatStep, canceled)
605 local chatSequenceId = chatStep.Parent.Parent.InstanceId
607 local chatStepId = nil
608 if canceled == true then chatStepId = chatStep.InstanceId end
610 local triggersUI = getUI("ui:interface:r2ed_triggers")
611 assert(triggersUI)
613 local tab = triggersUI:find("sequence_tabs")
614 assert(tab)
616 for s = 0,tab.tabButtonNb-1 do
617 local activitySequence = tab:getGroup(s)
618 assert(activitySequence)
620 local activityList = activitySequence:find("elements_list")
621 assert(activityList)
623 for a=0, activityList.childrenNb-1 do
624 local activity = activityList:getChild(a)
625 assert(activity)
627 if activity.Env.elementId~=nil then
628 local activityInst = r2:getInstanceFromId(activity.Env.elementId)
629 assert(activityInst)
630 if tostring(activityInst.Chat) == chatSequenceId then
631 r2:updateActivityChatSequence(activity, chatStepId)
638 ------------------ REMOVE ACTIVITY ------------------------------------------------------------------
639 function r2:removeActivity()
640 r2:removeTriggerElement("r2ed_triggers", tostring(i18n.get("uiR2EdActivity")))
643 function r2:removeActivityUI(sequenceUI, elementUI)
645 r2:removeElementUI(sequenceUI, "r2ed_triggers", elementUI)
646 r2:closeActivitySequenceUI()
648 local activityList = sequenceUI:find("elements_list")
649 assert(activityList)
652 ------------------ UP ACTIVITY -----------------------------------------------------------------------
653 function r2:upActivity()
654 r2:upTriggerElement("r2ed_triggers")
657 ------------------ DOWN ACTIVITY ---------------------------------------------------------------------
658 function r2:downActivity()
659 r2:downTriggerElement("r2ed_triggers")
662 ------------------ MAXIMIZE MINIMIZE ACTIVITIES ------------------------------------------------------
663 function r2:maximizeMinimizeActivities()
664 r2:maximizeMinimizeTriggerElements("r2ed_triggers")
667 ------------------ MAXIMIZE MINIMIZE ACTIVITY ------------------------------------------------------
668 function r2:maximizeMinimizeActivity()
669 r2:maximizeMinimizeElement("r2ed_triggers")
672 ------------------ OPEN ACTIVITY EDITOR ----------------------------------------------------------------
673 function r2:openActivityEditor()
674 r2:updateActivityEditor()
675 r2:openElementEditor("r2ed_triggers", "uiR2EDActivityStepEditor")
678 function r2:updateActivityEditor()
680 local uiName = "r2ed_triggers"
681 local instanceActivity = r2:getSelectedEltInst(uiName)
683 local activityEditor = r2:getSelectedSequ(uiName):find("edit_element")
684 assert(activityEditor)
686 -- activity name
687 local activityName = activityEditor:find("name")
688 assert(activityName)
690 -- activity type
691 local activityButtonText = activityEditor:find("activity"):find("text")
692 assert(activityButtonText)
694 -- time limit
695 local comboBox = activityEditor:find("time_limit").combo_box
696 assert(comboBox)
698 -- chat sequence
699 local chatMenuButton = activityEditor:find("chat_script"):find("menu"):find("text")
700 assert(chatMenuButton)
702 local chatButtonEditor = activityEditor:find("open_chat_sequence")
703 assert(chatButtonEditor)
705 if instanceActivity then
707 local index = r2:searchElementIndex(instanceActivity)
708 if index~= nil then
709 activityName.uc_hardtext = tostring(i18n.get("uiR2EdActivity")).." "..index.." : "
710 else
711 activityName.uc_hardtext = tostring(i18n.get("uiR2EdActivity")).." : "
714 -- activity type
715 local activityText = r2.activityTypeMenu[instanceActivity.Activity]
716 if activityText then
717 activityButtonText.uc_hardtext = activityText
719 if instanceActivity.ActivityZoneId ~= "" then
720 local place = r2:getInstanceFromId(instanceActivity.ActivityZoneId)
721 assert(place)
723 activityButtonText.uc_hardtext = activityButtonText.hardtext .. " " .. place.Name
726 -- time limit
727 local timeLimit = instanceActivity.TimeLimit
729 local certainTime = activityEditor:find("certain_time")
730 assert(certainTime)
732 comboBox.Env.locked = true
733 if timeLimit == "Few Sec" then
734 local timeLimitValue = tonumber(instanceActivity.TimeLimitValue)
736 if timeLimitValue ~= nil then
738 local hoursNb, minNb, secNb = r2:calculHourMinSec(timeLimitValue)
740 local timeLimitText = tostring(i18n.get("uiR2EdFor")) .. " "
741 if hoursNb ~= 0 then timeLimitText = timeLimitText .. hoursNb .. tostring(i18n.get("uiR2EdShortHours")) .. " " end
742 if minNb ~= 0 then timeLimitText = timeLimitText .. minNb .. tostring(i18n.get("uiR2EdShortMinutes")) .. " " end
743 timeLimitText = timeLimitText .. secNb .. tostring(i18n.get("uiR2EdShortSeconds"))
745 certainTime.active = true
746 local hoursMenu = certainTime:find("hours"):find("text")
747 assert(hoursMenu)
748 hoursMenu.uc_hardtext = tostring(hoursNb)
750 local minutesMenu = certainTime:find("minutes"):find("text")
751 assert(minutesMenu)
752 minutesMenu.uc_hardtext = tostring(minNb)
754 local secondsMenu = certainTime:find("seconds"):find("text")
755 assert(secondsMenu)
756 secondsMenu.uc_hardtext = tostring(secNb)
758 comboBox.view_text = timeLimitText
760 else
761 certainTime.active = false
762 timeLimit = r2.TimeLimitsCB[timeLimit]
763 if timeLimit~= nil then
764 comboBox.selection_text = timeLimit
767 comboBox.Env.locked = false
769 -- chat sequence TEMP TEMP TEMP TEMP
770 local sequenceChat = r2:getInstanceFromId(tostring(instanceActivity.Chat))
771 local repeatLabelButton = activityEditor:find("repeat")
772 assert(repeatLabelButton)
774 if sequenceChat ~= nil then
775 --chatMenuButton.uc_hardtext = sequenceChat.Name
776 chatMenuButton.uc_hardtext = r2:getSequenceName(sequenceChat)
778 repeatLabelButton.active = true
779 local repeatButton = repeatLabelButton:find("toggle_butt")
780 assert(repeatButton)
781 repeatButton.pushed = not (instanceActivity.Type == "Repeating")
783 chatButtonEditor.active = true
784 else
785 repeatLabelButton.active = false
786 chatMenuButton.uc_hardtext = i18n.get("uiR2EdNoElt")
788 chatButtonEditor.active = false
790 -- TEMP TEMP TEMP
792 else
794 local name = tostring(i18n.get("uiR2EdActivity")).." : "
795 activityName.uc_hardtext = name
797 activityButtonText.uc_hardtext = i18n.get("uiR2EdStandStill")
798 comboBox.selection_text = i18n.get("uiR2EdNoTimeLimit")
799 chatMenuButton.uc_hardtext = i18n.get("uiR2EdNoElt")
801 chatButtonEditor.active = false
805 ------------------ REPEAT ACTIVITY SEQUENCE -------------------------------------------------------------
806 function r2:repeatActivitySequence()
807 r2.requestNewAction(i18n.get("uiR2EDRepeatActivitySequenceAction"))
809 local sequenceInstId = r2:getSelectedSequInstId("r2ed_triggers")
810 assert(sequenceInstId)
812 local sequenceType = not getUICaller().pushed
813 if sequenceType==false then sequenceType=0 else sequenceType=1 end
815 r2.requestSetNode(sequenceInstId, "Repeating", sequenceType)
818 ------------------ CLOSE ACTIVITY EDITOR ----------------------------------------------------------------
819 function r2:closeChatSequencesUI()
821 local window = getUI("ui:interface:r2ed_chat_sequence")
822 assert(window)
823 window.active = false
825 window = getUI("ui:interface:r2ed_edit_chat_sequence")
826 assert(window)
827 window.active = false
830 ------------------ OPEN ACTIVITY MENU -------------------------------------------------------------------
831 function r2:openActivityMenu()
833 local menuName = "ui:interface:r2ed_triggers_menu"
834 local activityMenu = getUI(menuName)
835 local activityMenu = activityMenu:getRootMenu()
836 assert(activityMenu)
837 activityMenu:reset()
839 -- Inactive
840 -- activityMenu:addLine(ucstring(i18n.get("uiR2EdInactive")), "lua", "r2:setActivity('Inactive')", "Inactive")
842 -- Stand still
843 activityMenu:addLine(ucstring(i18n.get("uiR2EdStandStill")), "lua", "r2:setActivity('Stand Still')", "Stand Still")
845 -- Follow route
846 activityMenu:addLine(ucstring(i18n.get("uiR2EdFollowRoad")), "", "", "Follow Route")
847 local menuButton = createGroupInstance("r2_menu_button", "", { bitmap = "r2ed_icon_road.tga", size="14" })
848 activityMenu:setUserGroupLeft(1, menuButton)
849 activityMenu:addSubMenu(1)
850 local roadsMenu = activityMenu:getSubMenu(1)
851 local roadsTable = r2.Scenario:getAllInstancesByType("Road")
852 for key, road in pairs(roadsTable) do
853 roadsMenu:addLine(ucstring(road.Name), "lua", "r2:setActivity('Follow Route', '".. road.InstanceId .."')", road.InstanceId)
855 if table.getn(roadsTable) == 0 then
856 roadsMenu:addLine(ucstring(i18n.get("uiR2EdNoSelelection")), "lua", "r2:setActivity()", "")
859 -- Patrol
860 activityMenu:addLine(ucstring(i18n.get("uiR2EdPatrol")), "", "", "Patrol")
861 menuButton = createGroupInstance("r2_menu_button", "", { bitmap = "r2ed_icon_road.tga", size="14"})
862 activityMenu:setUserGroupLeft(2, menuButton)
863 activityMenu:addSubMenu(2)
864 roadsMenu = activityMenu:getSubMenu(2)
865 for key, road in pairs(roadsTable) do
866 roadsMenu:addLine(ucstring(road.Name), "lua", "r2:setActivity('Patrol', '".. road.InstanceId .."')", road.InstanceId)
868 if table.getn(roadsTable) == 0 then
869 roadsMenu:addLine(ucstring(i18n.get("uiR2EdNoSelelection")), "lua", "r2:setActivity()", "")
872 -- Repeat Road
873 activityMenu:addLine(ucstring(i18n.get("uiR2EdRepeatRoad")), "", "", "Repeat Road")
874 menuButton = createGroupInstance("r2_menu_button", "", { bitmap = "r2ed_icon_road.tga", size="14"})
875 activityMenu:setUserGroupLeft(3, menuButton)
876 activityMenu:addSubMenu(3)
877 roadsMenu = activityMenu:getSubMenu(3)
878 for key, road in pairs(roadsTable) do
879 roadsMenu:addLine(ucstring(road.Name), "lua", "r2:setActivity('Repeat Road', '".. road.InstanceId .."')", road.InstanceId)
881 if table.getn(roadsTable) == 0 then
882 roadsMenu:addLine(ucstring(i18n.get("uiR2EdNoSelelection")), "lua", "r2:setActivity()", "")
885 -- Wander
886 activityMenu:addLine(ucstring(i18n.get("uiR2EdWander")), "", "", "Wander")
887 menuButton = createGroupInstance("r2_menu_button", "", { bitmap = "r2ed_icon_region.tga", size="14"})
888 activityMenu:setUserGroupLeft(4, menuButton)
889 activityMenu:addSubMenu(4)
890 local regionsMenu = activityMenu:getSubMenu(4)
891 local regionsTable = r2.Scenario:getAllInstancesByType("Region")
892 for key, region in pairs(regionsTable) do
893 regionsMenu:addLine(ucstring(region.Name), "lua", "r2:setActivity('Wander', '".. region.InstanceId .."')", region.InstanceId)
895 if table.getn(regionsTable) == 0 then
896 regionsMenu:addLine(ucstring(i18n.get("uiR2EdNoSelelection")), "lua", "r2:setActivity()", "")
899 -- Deploy
900 -- activityMenu:addLine(ucstring(i18n.get("uiR2EdDeploy")), "", "", "Deploy")
901 -- menuButton = createGroupInstance("r2_menu_button", "", { bitmap = "r2ed_icon_region.tga", size="14"})
902 -- activityMenu:setUserGroupLeft(6, menuButton)
903 -- activityMenu:addSubMenu(6)
904 -- local regionsMenu = activityMenu:getSubMenu(6)
905 -- local regionsTable = r2.Scenario:getAllInstancesByType("Region")
906 -- for key, region in pairs(regionsTable) do
907 -- regionsMenu:addLine(ucstring(region.Name), "lua", "r2:setActivity('Deploy', '".. region.InstanceId .."')", region.InstanceId)
908 -- end
909 -- if table.getn(regionsTable) == 0 then
910 -- regionsMenu:addLine(ucstring(i18n.get("uiR2EdNoSelelection")), "lua", "r2:setActivity()", "")
911 -- end
913 r2:openTriggersMenu(getUICaller())
916 function r2:setActivity(activityType, placeId)
920 local activityInstId = r2:getSelectedEltInstId("r2ed_triggers")
921 assert(activityInstId)
923 if activityType == nil then
924 return
925 elseif placeId == nil then
926 r2.requestSetNode(activityInstId, "Activity", activityType)
927 r2.requestSetNode(activityInstId, "ActivityZoneId", r2.RefId(""))
928 else
929 r2.requestSetNode(activityInstId, "Activity", activityType)
930 r2.requestSetNode(activityInstId, "ActivityZoneId", r2.RefId(placeId))
934 ------------------ SET TIME LIMIT --------------------------------------------------------------------
935 function r2:setTimeLimit(timeLimit)
937 if timeLimit == nil then
938 timeLimit = getUICaller().selection_text
939 if getUICaller().Env.locked then return end
942 local uiName = "r2ed_triggers"
943 local activity = r2:getSelectedEltUI(uiName)
944 if activity == nil then return end
946 local viewText
947 local hasTimeLimitValue = false
949 if timeLimit == tostring(i18n.get("uiR2EdForCertainTime")) then
950 hasTimeLimitValue = true
951 viewText = tostring(i18n.get("uiR2EdFor")) .. " 20" .. tostring(i18n.get("uiR2EdShortSeconds"))
953 local eltEditor = r2:getSelectedSequ(uiName):find("edit_element")
954 assert(eltEditor)
955 local comboTime = eltEditor:find("time_limit"):find("combo_box")
956 assert(comboTime)
957 comboTime.view_text = viewText
958 else
959 viewText = timeLimit
962 timeLimit = r2.TimeLimitsProp[timeLimit]
964 local activityInstId = r2:getSelectedEltInstId(uiName)
965 r2.requestSetNode(activityInstId, "TimeLimit", timeLimit)
967 if hasTimeLimitValue then
968 r2.requestSetNode(activityInstId, "TimeLimitValue", tostring(20))
969 else
970 r2.requestSetNode(activityInstId, "TimeLimitValue", "")
974 function r2:calculHourMinSec(totalSecNb)
976 local minSecNb, hourNb = totalSecNb, 0
977 while minSecNb > 3599 do
978 hourNb = hourNb+1
979 minSecNb = minSecNb - 3600
982 local minNb, secNb = 0, minSecNb
983 while secNb > 59 do
984 minNb = minNb+1
985 secNb = secNb - 60
988 return hourNb, minNb, secNb
991 function r2:calculMinSec(totalSecNb)
993 local minNb, secNb = 0, totalSecNb
994 while secNb > 59 do
995 minNb = minNb+1
996 secNb = secNb - 60
999 return minNb, secNb
1002 function r2:activityForHours(hourNb)
1004 local activityInst = r2:getSelectedEltInst("r2ed_triggers")
1005 assert(activityInst)
1007 local lastHourNb, minNb, secNb = r2:calculHourMinSec(tonumber(activityInst.TimeLimitValue))
1009 r2:setLimitTimeValue(hourNb, minNb, secNb)
1012 function r2:activityForMinutes(minNb)
1014 local activityInst = r2:getSelectedEltInst("r2ed_triggers")
1015 assert(activityInst)
1017 local hoursNb, lastMinNb, secNb = r2:calculHourMinSec(tonumber(activityInst.TimeLimitValue))
1019 r2:setLimitTimeValue(hoursNb, minNb, secNb)
1022 function r2:activityForSeconds(secNb)
1024 local activityInst = r2:getSelectedEltInst("r2ed_triggers")
1025 assert(activityInst)
1027 local hoursNb, minNb, lastSecNb = r2:calculHourMinSec(tonumber(activityInst.TimeLimitValue))
1029 r2:setLimitTimeValue(hoursNb, minNb, secNb)
1032 ------------------ SET LIMIT TIME VALUE -------------------------------------------------------------------
1033 function r2:setLimitTimeValue(hourNb, minNb, secNb)
1035 local totalSec = tostring(hourNb*3600 + minNb*60 + secNb)
1036 r2.requestSetNode(r2:getSelectedEltInstId("r2ed_triggers"), "TimeLimitValue", totalSec)
1040 ------------------ OPEN SELECT CHAT MENU -------------------------------------------------------------------
1041 function r2:openSelectChatMenu()
1043 -- triggers menu initialization
1044 local chatMenu = getUI("ui:interface:r2ed_triggers_menu")
1045 assert(chatMenu)
1047 local chatMenu = chatMenu:getRootMenu()
1048 assert(chatMenu)
1050 chatMenu:reset()
1052 -- first line "None"
1053 chatMenu:addLine(ucstring(i18n.get("uiR2EdNoElt")), "lua", "r2:selectChatSequence('None')", "None")
1055 -- second line "More"
1056 chatMenu:addLine(ucstring(i18n.get("uiR2EdMore")), "lua", "r2:openChatSequences()", "More")
1058 local entityInst = r2:getSelectedInstance()
1059 assert(entityInst)
1061 -- list of avoidable chat sequences
1062 local chatSequences = entityInst:getBehavior().ChatSequences
1063 for i=0, chatSequences.Size-1 do
1064 local chatS = chatSequences[i]
1065 assert(chatS)
1066 --chatMenu:addLine(ucstring(chatS.Name), "lua", "r2:selectChatSequence('" .. chatS.InstanceId .. "')", chatS.InstanceId)
1067 chatMenu:addLine(ucstring(r2:getSequenceName(chatS)), "lua", "r2:selectChatSequence('" .. chatS.InstanceId .. "')", chatS.InstanceId)
1070 r2:openTriggersMenu(getUICaller())
1073 function r2:openChatSequences()
1074 local chatSequencesUI = getUI("ui:interface:r2ed_chat_sequence")
1075 assert(chatSequencesUI)
1077 chatSequencesUI.active = true
1078 chatSequencesUI:updateCoords()
1080 if chatSequencesUI.Env.openFirst == nil then
1081 chatSequencesUI:center()
1082 chatSequencesUI.Env.openFirst = true
1086 -----------------------------------------------------------------------------------------------------------
1087 -- the commun "logic entity" menu is open
1088 function r2:openTriggersMenu(caller)
1090 local menuName = "ui:interface:r2ed_triggers_menu"
1091 launchContextMenuInGame(menuName)
1092 local menu = getUI(menuName)
1094 menu:updateCoords()
1095 menu.y = caller.y_real - (menu.h + 2)
1096 menu.x = caller.x_real
1097 menu:setMinW(caller.w)
1098 menu:updateCoords()
1101 ------------------ SELECT CHAT SEQUENCE -------------------------------------------------------------
1102 function r2:selectChatSequence(choice, activityId)
1104 local chatSequenceUI = getUI("ui:interface:r2ed_chat_sequence")
1105 assert(chatSequenceUI)
1107 local uiName = "r2ed_triggers"
1109 if activityId == nil then
1110 activityId = r2:getSelectedEltInstId(uiName)
1113 local activityUI = r2:getSelectedEltUI(uiName)
1114 assert(activityUI)
1116 if choice == "None" then
1117 r2.requestSetNode(activityId, "Chat", r2.RefId(""))
1118 local sep = activityUI:find("sep")
1119 assert(sep)
1120 sep.active = false
1121 elseif choice == "More" then
1122 r2:openChatSequences()
1123 elseif choice then
1124 local chatSId = choice
1125 local activityInstId = r2:getSelectedEltInstId(uiName)
1126 r2.requestSetNode(activityId, "Chat", r2.RefId(chatSId))
1127 r2.requestSetNode(activityInstId, "Type", "Non Repeating")
1128 else
1129 debugInfo("r2:selectChatSequence : unknown menu selection")
1133 ------------------ REPEAT OR NOT CHAT SEQUENCE ------------------------------------------------------
1134 function r2:repeatChatSequence()
1136 local activityInstId = r2:getSelectedEltInstId("r2ed_triggers")
1137 assert(activityInstId)
1139 local sequenceType = "Repeating"
1140 if getUICaller().pushed then sequenceType = "Non Repeating" end
1142 r2.requestSetNode(activityInstId, "Type", sequenceType)
1145 ------------------ NEW CHAT SEQUENCE -------------------------------------------------------------
1146 function r2:newChatsSequence(firstRequest, instanceSequence, reset)
1148 local chatSequencesUI = getUI("ui:interface:r2ed_chat_sequence")
1149 assert(chatSequencesUI)
1151 local tab = chatSequencesUI:find("sequence_tabs")
1152 assert(tab)
1154 -- limit sequences number
1155 if firstRequest and tab.tabButtonNb == 7 then return -1 end
1157 if firstRequest == true then
1158 instanceSequence = r2.newComponent("ChatSequence")
1160 --local name = tostring(i18n.get("uiR2EdChat"))..tab.tabButtonNb+1
1161 --instanceSequence.Name = name
1163 local npcGroup = r2:getSelectedInstance()
1164 assert(npcGroup)
1166 r2.requestInsertNode(npcGroup:getBehavior().InstanceId, "ChatSequences", -1, "", instanceSequence)
1168 r2.ownCreatedInstances[instanceSequence.InstanceId] = true
1169 else
1171 local templateParams = {
1172 newElt="r2:newChat(true)",
1173 newEltText=tostring(i18n.get("uiR2EdNewChat")),
1174 eltOrderText=tostring(i18n.get("uiR2EdChatOrder")),
1175 upElt="r2:upChat()",
1176 downElt="r2:downChat()",
1177 maxMinElts="r2:maximizeMinimizeChats()",
1178 downUpColor="120 150 140 255",
1179 colPushed = "0 255 0 255",
1180 paramsL= "r2:selectSequenceTab('r2ed_chat_sequence', "..tostring(tab.tabButtonNb)..")"
1183 if reset == true then
1184 r2.ownCreatedInstances[instanceSequence.InstanceId] = true
1187 local editorEltTemplate = "template_edit_chat"
1188 local sequence = r2:newElementsSequence("r2ed_chat_sequence", templateParams, editorEltTemplate,
1189 instanceSequence, tostring(i18n.get("uiR2EdSequChat")))
1191 local chats = instanceSequence.Components
1192 for c = 0, chats.Size - 1 do
1193 r2:newChat(false, chats[c])
1196 local eltEditor = sequence:find("edit_element")
1197 assert(eltEditor)
1199 local editBox = eltEditor:find("edit_box_group")
1200 assert(editBox)
1202 local scroll = sequence:find("edit_box_scroll_ed")
1203 assert(scroll)
1205 scroll:setTarget(editBox.id)
1208 return instanceSequence.InstanceId
1211 ------------------- REMOVE CHATS SEQUENCE ---------------------------------------------------------
1212 function r2:removeChatsSequence()
1214 -- remove sequence
1215 r2:removeElementsSequence("r2ed_chat_sequence", "ChatSequences", tostring(i18n.get("uiR2EdSequChat")))
1218 function r2:removeChatsSequenceUI(sequIndex)
1220 r2:closeChatEditor()
1222 -- remove sequence UI
1223 r2:removeElementsSequenceUI(sequIndex, "r2ed_chat_sequence", "ChatSequences", tostring(i18n.get("uiR2EdSequChat")))
1226 ------------------- SELECT CHAT -------------------------------------------------------------------
1227 function r2:selectChat()
1228 r2:selectTriggerElement(nil, "r2ed_chat_sequence")
1230 if getUICaller().pushed == true then
1231 r2:updateChatEditor()
1235 ------------------- OPEN CHAT EDITOR --------------------------------------------------------------
1236 function r2:openChatEditor()
1237 r2:updateChatEditor()
1238 r2:openElementEditor("r2ed_chat_sequence", "uiR2EDChatStepEditor")
1241 function r2:updateChatEditor()
1243 local instanceChat = r2:getSelectedEltInst("r2ed_chat_sequence")
1245 local chatEditor = r2:getSelectedSequ("r2ed_chat_sequence"):find("edit_element")
1246 assert(chatEditor)
1248 -- chat name
1249 local chatName = chatEditor:find("name")
1250 assert(chatName)
1252 -- time
1253 local minutesText = chatEditor:find("minutes"):find("text")
1254 assert(minutesText)
1256 local secondsText = chatEditor:find("seconds"):find("text")
1257 assert(secondsText)
1259 -- update NPC name lists
1260 local whoMenuText = chatEditor:find("whoMenu"):find("text")
1261 assert(whoMenuText)
1263 local toWhoMenuText = chatEditor:find("toWhoMenu"):find("text")
1264 assert(toWhoMenuText)
1266 local editBox = chatEditor:find("says"):find("edit_box_group")
1267 assert(editBox)
1269 local emoteButtonText = chatEditor:find("emote"):find("menu"):find("text")
1270 assert(emoteButtonText)
1272 if instanceChat then
1274 local index = r2:searchElementIndex(instanceChat)
1275 if index~= nil then
1276 chatName.uc_hardtext = tostring(i18n.get("uiR2EdChat")).." "..index.." : "
1277 else
1278 chatName.uc_hardtext = tostring(i18n.get("uiR2EdChat")).." : "
1281 -- after value
1282 local time = instanceChat.Time
1283 local minNb, secNb = r2:calculMinSec(time)
1285 minutesText.uc_hardtext = tostring(minNb)
1286 secondsText.uc_hardtext = tostring(secNb)
1288 -- who
1289 local whoInst = r2:getInstanceFromId(tostring(instanceChat.Actions[0].Who))
1290 whoMenuText.uc_hardtext = whoInst.Name
1292 -- says what
1293 local textID = instanceChat.Actions[0].Says
1294 if textID ~= "" then
1295 editBox.uc_input_string = r2:getInstanceFromId(textID).Text
1296 else
1297 editBox.uc_input_string = ""
1300 -- to who
1301 local toWhoInst = r2:getInstanceFromId(tostring(instanceChat.Actions[0].Facing))
1302 if toWhoInst then
1303 toWhoMenuText.uc_hardtext = toWhoInst.Name
1304 else
1305 toWhoMenuText.uc_hardtext = tostring(i18n.get("uiR2EdNobody"))
1308 -- emote
1309 local emoteName = r2.fromEmoteIdToName[instanceChat.Actions[0].Emote]
1310 if emoteName then
1311 emoteButtonText.uc_hardtext = emoteName
1312 else
1313 emoteButtonText.uc_hardtext = tostring(i18n.get("uiR2EdNoElt"))
1316 else
1318 local name = tostring(i18n.get("uiR2EdChat")).." : "
1319 chatName.uc_hardtext = name
1321 minutesText.uc_hardtext = tostring(0)
1322 secondsText.uc_hardtext = tostring(0)
1324 whoMenuText.uc_hardtext = ""
1326 editBox.uc_input_string = ""
1328 toWhoMenuText.uc_hardtext = tostring(i18n.get("uiR2EdNobody"))
1330 emoteButtonText.uc_hardtext = tostring(i18n.get("uiR2EdNoElt"))
1334 ------------------ OPEN CHAT SEQUENCE EDITOR --------------------------------------------------
1335 function r2:openChatSequenceEditor()
1337 local editor = getUI("ui:interface:r2ed_edit_chat_sequence")
1338 assert(editor)
1340 local chatsUI = getUI("ui:interface:r2ed_chat_sequence")
1341 assert(chatsUI)
1343 editor.x = chatsUI.x
1344 editor.y = chatsUI.y
1345 editor.active = true
1348 ------------------- MAX / MIN CHAT ----------------------------------------------------------------
1349 function r2:maximizeMinimizeChat()
1350 r2:maximizeMinimizeElement("r2ed_chat_sequence")
1353 -------------------- NEW CHAT ---------------------------------------------------------------------
1354 function r2:newChat(firstRequest, instanceElement, sequenceUI)
1356 local uiName = "r2ed_chat_sequence"
1358 if firstRequest == true then
1359 instanceElement = r2.newComponent("ChatStep")
1361 instanceElement.Time = 3
1363 local who
1364 local selectedInst = r2:getSelectedInstance()
1365 assert(selectedInst)
1367 if selectedInst:isGrouped() then
1368 who = r2:getLeader(selectedInst)
1369 else
1370 who = selectedInst
1372 local chatAction = r2.newComponent("ChatAction")
1373 chatAction.Who = who.InstanceId
1374 table.insert(instanceElement.Actions, chatAction)
1376 local sequenceInstId = r2:getSelectedSequInstId(uiName)
1378 r2.requestInsertNode(sequenceInstId, "Components", -1, "", instanceElement)
1380 r2.ownCreatedInstances[instanceElement.InstanceId] = true
1381 else
1383 local templateParams = {
1384 selectElt="r2:selectChat()",
1385 openEltEditor="r2:openChatEditor()",
1386 maxMinElt="r2:maximizeMinimizeChat()",
1387 removeElt="r2:removeChat()",
1388 colOver="120 150 140 100",
1389 colPushed="120 150 140 255"
1392 if sequenceUI == nil then
1393 sequenceUI = r2:getSelectedSequ(uiName)
1395 local element = r2:newTriggerElement(uiName, tostring(i18n.get("uiR2EdChat")), templateParams, sequenceUI, instanceElement.InstanceId)
1397 r2:updateChatText(element)
1401 function r2:searchElementIndex(eltInst)
1403 local components = eltInst.Parent
1404 local index
1405 for i=0, components.Size-1 do
1406 local elt = components[i]
1407 if elt.InstanceId == eltInst.InstanceId then
1408 return (i+1)
1413 function r2:buildChatTitle(chatUI, erase)
1415 local chatInst = r2:getInstanceFromId(chatUI.Env.elementId)
1416 assert(chatInst)
1418 -- part1
1419 local index = r2:searchElementIndex(chatInst)
1420 if erase==true then index = index-1 end
1421 local part1 = tostring(i18n.get("uiR2EdChat")).." "..index.." : "
1423 -- part2
1424 local minNb, secNb = r2:calculMinSec(chatInst.Time)
1425 local time = ""
1426 if minNb ~= 0 then
1427 time = tostring(minNb)..tostring(i18n.get("uiR2EdShortMinutes"))
1429 time = time.." " ..tostring(secNb)..tostring(i18n.get("uiR2EdShortSeconds"))
1430 local part2 = "(" ..tostring(i18n.get("uiR2EdAfter")).." ".. time..") "
1432 -- part3
1433 local part3 = ""
1434 local action = chatInst.Actions[0]
1435 local who = action.Who
1436 if who ~= "" then
1437 who = r2:getInstanceFromId(who)
1438 assert(who)
1439 part3 = who.Name .. " " ..tostring(i18n.get("uiR2EdSays")).. " "
1441 local says = action.Says
1442 if says ~= "" then
1443 says = r2:getInstanceFromId(says).Text
1444 says = string.substr(says, 0, 4)
1447 part3 = part3 .. says .. "..."
1450 -- title
1451 local title = chatUI:find("title")
1452 assert(title)
1453 title.uc_hardtext= part1..part2..part3
1456 function r2:getChatName(chatInst)
1458 -- part1
1459 local index = r2:searchElementIndex(chatInst)
1460 if erase==true then index = index-1 end
1461 local part1 = tostring(i18n.get("uiR2EdChat")).." "..index.." : "
1463 -- part2
1464 local minNb, secNb = r2:calculMinSec(chatInst.Time)
1465 local time = ""
1466 if minNb ~= 0 then
1467 time = tostring(minNb)..tostring(i18n.get("uiR2EdShortMinutes"))
1469 time = time.." " ..tostring(secNb)..tostring(i18n.get("uiR2EdShortSeconds"))
1470 local part2 = "(" ..tostring(i18n.get("uiR2EdAfter")).." ".. time..") "
1472 -- part3
1473 local part3 = ""
1474 local action = chatInst.Actions[0]
1475 local who = action.Who
1476 if who ~= "" then
1477 who = r2:getInstanceFromId(who)
1478 assert(who)
1479 part3 = who.Name .. " " ..tostring(i18n.get("uiR2EdSays")).. " "
1481 local says = action.Says
1482 if says ~= "" then
1483 says = r2:getInstanceFromId(says).Text
1484 says = string.sub(says, 1, 4)
1487 part3 = part3 .. says .. "..."
1490 return part1..part2..part3
1494 function r2:updateChatText(elementUI)
1496 if elementUI == nil then
1497 elementUI = r2:getSelectedEltUI("r2ed_chat_sequence")
1499 assert(elementUI)
1501 local instance = r2:getInstanceFromId(elementUI.Env.elementId)
1502 assert(instance)
1504 local chatText = elementUI:find("text_list")
1505 assert(chatText)
1507 chatText:clear()
1509 local who = tostring(instance.Actions[0].Who)
1510 if who ~= "" then
1512 local text = ""
1513 local textEmpty = true
1515 local facing = tostring(instance.Actions[0].Facing)
1516 local emote = instance.Actions[0].Emote
1517 local says = instance.Actions[0].Says
1519 if facing ~= "" then
1520 text = "\n"..r2:getInstanceFromId(who).Name .." "..tostring(i18n.get("uiR2EdFaces")).." ".. r2:getInstanceFromId(facing).Name
1521 textEmpty = false
1523 if r2.fromEmoteIdToName[emote] ~= nil then
1524 text = text .. "\n" .. r2:getInstanceFromId(who).Name .. " "..string.lower(tostring(i18n.get("uiR2EdEmote"))).." : " .. r2.fromEmoteIdToName[emote]
1525 textEmpty = false
1527 if r2:getInstanceFromId(says)~=nil and r2:getInstanceFromId(says).Text ~= "" then
1528 text = text.."\n"..r2:getInstanceFromId(who).Name .. " "..tostring(i18n.get("uiR2EdSays")).." : " .. r2:getInstanceFromId(says).Text
1529 textEmpty = false
1531 text = text.."\n"
1533 chatText:addTextChild(ucstring(text))
1535 local sep = elementUI:find("sep")
1536 assert(sep)
1537 if textEmpty == false then
1538 sep.active = true
1539 else
1540 chatText:clear()
1541 sep.active = false
1545 r2:buildChatTitle(elementUI, false)
1547 local chatEditor = r2:getSelectedSequ("r2ed_chat_sequence"):find("edit_element")
1548 assert(chatEditor)
1550 if instance.InstanceId == r2:getSelectedEltInstId("r2ed_chat_sequence") then
1551 r2:updateChatEditor()
1554 r2:updateActivitiesWhithThisChatSequence(instance, false)
1558 -------------------- UP CHAT ----------------------------------------------------------------------
1559 function r2:upChat()
1560 r2:upTriggerElement("r2ed_chat_sequence")
1563 -------------------- DOWN CHAT --------------------------------------------------------------------
1564 function r2:downChat()
1565 r2:downTriggerElement("r2ed_chat_sequence")
1568 -------------------- MAX / MIN CHATS --------------------------------------------------------------
1569 function r2:maximizeMinimizeChats()
1570 r2:maximizeMinimizeTriggerElements("r2ed_chat_sequence")
1573 -------------------- REMOVE CHAT ------------------------------------------------------------------
1574 function r2:removeChat()
1575 r2:removeTriggerElement("r2ed_chat_sequence", tostring(i18n.get("uiR2EdChat")))
1578 -------------------- CHAT TIME --------------------------------------------------------------------
1579 function r2:setTime(minNb, secNb)
1581 local chatSequenceId = r2:getSelectedEltInstId("r2ed_chat_sequence")
1583 r2.requestSetNode(chatSequenceId, "Time", minNb*60+secNb)
1586 -------------------- INIT TIME MENU -----------------------------------------------------------------
1587 function r2:initTimeMenu(timeFunction, isHours)
1589 local timeMenu = getUI("ui:interface:r2ed_triggers_menu")
1590 assert(timeMenu)
1592 local timeMenu = timeMenu:getRootMenu()
1593 assert(timeMenu)
1595 timeMenu:reset()
1597 for i=0,9 do
1598 timeMenu:addLine(ucstring(tostring(i)), "lua", timeFunction .. "(" .. tostring(i) .. ")", tostring(i))
1601 if isHours == true then
1602 timeMenu:addLine(ucstring(tostring(10)), "lua", timeFunction .. "(" .. tostring(10) .. ")", tostring(10))
1603 else
1605 local lineNb = 9
1606 for i=10, 50, 10 do
1607 local lineStr = tostring(i).."/"..tostring(i+9)
1608 timeMenu:addLine(ucstring(lineStr), "", "", tostring(i))
1609 lineNb = lineNb+1
1611 timeMenu:addSubMenu(lineNb)
1612 local subMenu = timeMenu:getSubMenu(lineNb)
1614 for s=0,9 do
1615 lineStr = tostring(i+s)
1616 subMenu:addLine(ucstring(lineStr), "lua", timeFunction .. "(" .. tostring(i+s) .. ")", lineStr)
1621 r2:openTriggersMenu(getUICaller())
1624 -------------------- CHAT SECONDS -----------------------------------------------------------------
1625 function r2:chatAfterSeconds(secNb)
1627 local chatStepInst = r2:getSelectedEltInst("r2ed_chat_sequence")
1629 local lastTime = chatStepInst.Time
1631 local minNb = 0
1632 while lastTime > 59 do
1633 lastTime = lastTime - 60
1634 minNb = minNb + 1
1637 r2:setTime(minNb, secNb)
1639 -- recover "says what" (equiv change focus)
1640 local chatEditor = r2:getSelectedSequ("r2ed_chat_sequence"):find("edit_element")
1641 assert(chatEditor)
1643 local saysWhat = chatEditor:find("says"):find("edit_box_group").input_string
1644 if chatStepInst.Actions[0].Says ~= r2.registerText(saysWhat).InstanceId then
1645 r2:setSaysWhat(saysWhat)
1649 -------------------- CHAT MINUTES -----------------------------------------------------------------
1650 function r2:chatAfterMinutes(minNb)
1652 local chatStepInst = r2:getSelectedEltInst("r2ed_chat_sequence")
1654 local lastTime = chatStepInst.Time
1656 local secNb = lastTime
1657 while secNb > 59 do
1658 secNb = secNb - 60
1661 r2:setTime(minNb, secNb)
1663 -- recover "says what" (equiv change focus)
1664 local chatEditor = r2:getSelectedSequ("r2ed_chat_sequence"):find("edit_element")
1665 assert(chatEditor)
1667 local saysWhat = chatEditor:find("says"):find("edit_box_group").input_string
1668 if chatStepInst.Actions[0].Says ~= r2.registerText(saysWhat).InstanceId then
1669 r2:setSaysWhat(saysWhat)
1673 -------------------- WHO --------------------------------------------------------------------------
1674 function r2:setWho(who, chatStepInst)
1676 if chatStepInst == nil then
1677 chatStepInst = r2:getSelectedEltInst("r2ed_chat_sequence")
1679 assert(chatStepInst)
1681 r2.requestSetNode(chatStepInst.Actions[0].InstanceId, "Who", r2.RefId(who))
1683 if who == chatStepInst.Actions[0].Facing then
1684 r2:setToWho(tostring(i18n.get("uiR2EdNobody")))
1687 -- recover "says what" (equiv change focus)
1688 local chatEditor = r2:getSelectedSequ("r2ed_chat_sequence"):find("edit_element")
1689 assert(chatEditor)
1691 local saysWhat = chatEditor:find("says"):find("edit_box_group").input_string
1692 if chatStepInst.Actions[0].Says ~= r2.registerText(saysWhat).InstanceId then
1693 r2:setSaysWhat(saysWhat)
1697 function r2:openWhoMenu(whoFunction, towho)
1699 local menuName = "ui:interface:r2ed_triggers_menu"
1701 local whoMenu = getUI(menuName)
1702 local whoMenu = whoMenu:getRootMenu()
1703 assert(whoMenu)
1705 whoMenu:reset()
1707 local npcTable = r2.Scenario:getAllInstancesByType("Npc")
1709 if towho == true then
1710 whoMenu:addLine(ucstring(i18n.get("uiR2EdNobody")), "lua", whoFunction.."('" ..tostring(i18n.get("uiR2EdNobody")).. "')", "Nobody")
1713 for key, npc in npcTable do
1714 local addLine = true
1715 if not npc:isBotObject() and not npc:isPlant() and not r2.isCreature(npc.InstanceId) then
1716 if towho == true then
1717 local chatStepInst= r2:getSelectedEltInst("r2ed_chat_sequence")
1718 assert(chatStepInst)
1720 local whoId = chatStepInst.Actions[0].Who
1721 if whoId~="" and whoId == npc.InstanceId then
1722 addLine = false
1725 if addLine then
1726 whoMenu:addLine(ucstring(npc.Name), "lua", whoFunction.."('" ..npc.InstanceId.. "')", npc.InstanceId)
1731 r2:openTriggersMenu(getUICaller())
1734 -------------------- SAYS WHAT --------------------------------------------------------------------
1735 function r2:setSaysWhat(what)
1737 if what == nil then
1738 what = getUICaller().input_string
1741 local says = what
1743 local chatStep = r2:getSelectedEltInst("r2ed_chat_sequence")
1744 if chatStep ~= nil then
1745 if what ~= "" then
1746 what=r2.registerText(what).InstanceId
1748 r2.requestSetNode(chatStep.Actions[0].InstanceId, "Says", what)
1750 local chatStepUI = r2:getSelectedEltUI("r2ed_chat_sequence")
1751 assert(chatStepUI)
1755 -------------------- CLOSE CHAT EDITOR ------------------------------------------------------------
1756 function r2:closeChatEditor(chatEditor)
1758 if chatEditor == nil then
1759 chatEditor = r2:getSelectedSequ("r2ed_chat_sequence"):find("edit_element")
1761 assert(chatEditor)
1763 local editSaysWhat = chatEditor:find("says"):find("edit_box_group")
1764 assert(editSaysWhat)
1766 if r2.callSetSaysWhat == true then
1767 r2:setSaysWhat(editSaysWhat.input_string)
1771 -------------------- TO WHO -----------------------------------------------------------------------
1772 function r2:setToWho(toWho)
1774 local chatSequence = r2:getSelectedEltInst("r2ed_chat_sequence")
1775 assert(chatSequence)
1777 local chatEditor = r2:getSelectedSequ("r2ed_chat_sequence"):find("edit_element")
1778 assert(chatEditor)
1780 -- recover "says what" (equiv change focus)
1781 local saysWhat = chatEditor:find("says"):find("edit_box_group").input_string
1782 if chatSequence.Actions[0].Says ~= r2.registerText(saysWhat).InstanceId then
1783 r2:setSaysWhat(saysWhat)
1786 if toWho == tostring(i18n.get("uiR2EdNobody")) then toWho="" end
1788 r2.requestSetNode(chatSequence.Actions[0].InstanceId, "Facing", r2.RefId(toWho))
1791 -------------------- EMOTE ------------------------------------------------------------------------
1792 function r2:openEmoteMenu()
1794 local menuName = "ui:interface:r2ed_triggers_menu"
1796 local emoteMenu = getUI(menuName)
1797 local emoteMenu = emoteMenu:getRootMenu()
1798 assert(emoteMenu)
1800 emoteMenu:reset()
1801 initEmotesMenu(menuName, "r2:setEmote")
1802 r2:openTriggersMenu(getUICaller())
1805 function r2:setEmote(emoteId)
1807 local chatSequence = r2:getSelectedEltInst("r2ed_chat_sequence")
1808 assert(chatSequence)
1810 r2.requestSetNode(chatSequence.Actions[0].InstanceId, "Emote", emoteId)
1812 -- recover "says what" (equiv change focus)
1813 local chatEditor = r2:getSelectedSequ("r2ed_chat_sequence"):find("edit_element")
1814 assert(chatEditor)
1816 local saysWhat = chatEditor:find("says"):find("edit_box_group").input_string
1817 if chatSequence.Actions[0].Says ~= r2.registerText(saysWhat).InstanceId then
1818 r2:setSaysWhat(saysWhat)
1822 ------------------ SELECT CHAT SEQUENCE ---------------------------------------------------------
1823 function r2:selectChatsSequence(index)
1824 r2:selectElementsSequence("r2ed_chat_sequence", index)
1825 r2:updateMiniActivityView()
1828 ---------------------------------------------------------------------------------------------------
1829 ------------------------------ FACTORISATION ----------------------------------------------------
1830 ---------------------------------------------------------------------------------------------------
1832 ------------------------------ Remove element ---------------------------------------------------
1833 function r2:removeTriggerElement(uiName, elementName)
1835 local wndUI = getUI("ui:interface:"..uiName)
1836 assert(wndUI)
1838 local tab = wndUI:find("sequence_tabs")
1839 assert(tab)
1841 local sequenceUI = wndUI:find(tab.associatedGroupSelection)
1842 assert(sequenceUI)
1844 r2:removeElement(sequenceUI, uiName, elementName)
1847 -----------------------------------------------------------------------------------------------------
1848 function r2:removeElement(sequence, uiName, elementName, removedElement)
1850 local listElements = sequence:find("elements_list")
1851 assert(listElements)
1853 local toErasedInstId
1854 if removedElement == nil then
1855 toErasedInstId = r2:getSelectedEltInstId(uiName)
1856 else
1857 toErasedInstId = removedElement.Env.elementId
1859 assert(toErasedInstId)
1861 -- request erase node
1862 if toErasedInstId ~= nil and r2:getInstanceFromId(toErasedInstId) ~= nil then
1863 r2.requestEraseNode(toErasedInstId, "", -1)
1867 function r2:removeElementUI(sequence, uiName, removedElement)
1869 local listElements = sequence:find("elements_list")
1870 assert(listElements)
1872 -- update follow elements number
1873 local removedIndex = listElements:getElementIndex(removedElement)
1874 for i = removedIndex+1, (listElements.childrenNb-1) do
1875 local element = listElements:getChild(i)
1876 assert(element)
1878 if not element.Env.isEditor then
1879 r2:buildElementTitle(uiName, element, true)
1883 -- delete element and update coordinates of elements list
1884 if removedElement == r2:getSelectedEltUI(uiName) then
1885 r2:setSelectedEltUIId(uiName, nil)
1887 -- inactive element editor
1888 local eltEditor = listElements:find("edit_element")
1889 assert(eltEditor)
1890 eltEditor.active = false
1892 -- disactive up and down element buttons
1893 local upElement = sequence:find("up_element")
1894 assert(upElement)
1895 local downElement = sequence:find("down_element")
1896 assert(downElement)
1897 local elementOrder = sequence:find("element_order")
1898 assert(elementOrder)
1900 upElement.active = false
1901 downElement.active = false
1902 elementOrder.active = false
1904 listElements.Env.elementsNb = listElements.Env.elementsNb - 1
1906 listElements:delChild(removedElement)
1907 listElements.parent:invalidateCoords()
1909 -- if any activity in list, disactive global minimize / maximize button
1910 if listElements.childrenNb == 1 then
1911 local minElts = sequence:find("minimize_elements")
1912 assert(minElts)
1914 local maxElts = sequence:find("maximize_elements")
1915 assert(maxElts)
1917 minElts.active = false
1918 maxElts.active = false
1922 ------------------------------ Max / Min elements -----------------------------------------------
1923 function r2:maximizeMinimizeTriggerElements(uiName)
1925 local sequence = r2:getSelectedSequ(uiName)
1926 assert(sequence)
1928 r2:maximizeMinimizeElements(sequence, uiName)
1931 ------------------------------ Max / Min elements -----------------------------------------------
1932 function r2:maximizeMinimizeElements(sequence, uiName)
1934 local elements = sequence:find("elements_list")
1935 assert(elements)
1937 if elements.Env.minimize == nil then
1938 elements.Env.minimize = true
1941 elements.Env.minimize = not elements.Env.minimize
1943 for i = 0, elements.childrenNb-1 do
1944 local element = elements:getChild(i)
1945 assert(element)
1947 if element.Env.isEditor ~= true then
1948 r2:maximizeMinimizeElement(uiName, element, elements.Env.minimize)
1952 local minElts = sequence:find("minimize_elements")
1953 assert(minElts)
1954 local maxElts = sequence:find("maximize_elements")
1955 assert(maxElts)
1957 if elements.Env.minimize == true then
1958 minElts.active = false
1959 maxElts.active = true
1960 else
1961 minElts.active = true
1962 maxElts.active = false
1966 ------------------------------ Max / Min element ------------------------------------------------
1967 function r2:maximizeMinimizeElement(uiName, element, allMinimize)
1969 if element == nil then
1970 element = getUICaller().parent.parent.parent.parent.parent.parent
1972 assert(element)
1974 local eltText = element:find("element_text")
1975 assert(eltText)
1977 local allMin, allMax = true, true
1978 if allMinimize ~= nil then
1979 allMin = allMinimize
1980 allMax = not allMin
1983 local maxButton = element:find("maximize_element")
1984 assert(maxButton)
1985 local minButton = element:find("minimize_element")
1986 assert(minButton)
1988 -- maximize
1989 if allMax and eltText.active==false then
1990 eltText.active = true
1991 maxButton.active = false
1992 minButton.active = true
1994 -- minimize
1995 elseif allMin and eltText.active==true then
1996 eltText.active = false
1997 maxButton.active = true
1998 minButton.active = false
2002 ------------------------------------ Down element --------------------------------------------------
2003 function r2:downTriggerElement(uiName)
2005 local eltSequenceUI = getUI("ui:interface:"..uiName)
2006 assert(eltSequenceUI)
2008 local tab = eltSequenceUI:find("sequence_tabs")
2009 assert(tab)
2011 local sequence = eltSequenceUI:find(tab.associatedGroupSelection)
2012 assert(sequence)
2014 local listElements = sequence:find("elements_list")
2015 assert(listElements)
2017 local selectedElement = r2:getSelectedEltUI(uiName)
2018 local index = listElements:getElementIndex(selectedElement)
2020 local sequenceId = r2:getSelectedSequInstId(uiName)
2021 if index < r2:getInstanceFromId(sequenceId).Components.Size-1 then
2022 r2.requestMoveNode(sequenceId, "Components", index+1,
2023 sequenceId, "Components", index)
2027 ------------------------------------ Down or up element UI ------------------------------------------
2029 function r2:downUpElement(elementUI, uiName)
2031 local listElements = elementUI.parent
2032 assert(listElements)
2034 local eltEditor = listElements:find("edit_element")
2035 assert(eltEditor)
2037 local index = listElements:getElementIndex(elementUI)
2039 if index > 0 then
2040 local previousElement = listElements:getChild(index - 1)
2042 local editorBetweenBothElts = false
2043 if previousElement.Env.elementId==nil then
2044 previousElement = listElements:getChild(index - 2)
2045 editorBetweenBothElts = true
2048 listElements:upChild(elementUI)
2049 if editorBetweenBothElts==true then
2050 listElements:upChild(elementUI)
2053 local selectedEltUI = r2:getSelectedEltUI(uiName)
2054 if selectedEltUI~=nil then
2055 local selectedEltIndex = listElements:getElementIndex(selectedEltUI)
2056 local eltEditorIndex = listElements:getElementIndex(eltEditor)
2057 if eltEditorIndex~=selectedEltIndex+1 then
2058 if eltEditorIndex<selectedEltIndex then
2059 for i=eltEditorIndex, selectedEltIndex-1 do
2060 listElements:downChild(eltEditor)
2062 else
2063 for i=selectedEltIndex, eltEditorIndex-2 do
2064 listElements:upChild(eltEditor)
2070 if selectedEltUI==previousElement then
2071 previousElement.active = false
2072 elseif selectedEltUI==elementUI then
2073 elementUI.active = false
2076 r2:updateElementEditor(uiName)
2079 r2:buildElementTitle(uiName, previousElement, false)
2080 r2:buildElementTitle(uiName, elementUI, false)
2084 function r2:updateElementEditor(uiName)
2086 if uiName == "r2ed_triggers" then
2087 r2:updateActivityEditor()
2088 elseif uiName == "r2ed_chat_sequence" then
2089 r2:updateChatEditor()
2093 function r2:buildElementTitle(uiName, elementUI, erase)
2095 if uiName == "r2ed_triggers" then
2096 r2:buildActivityTitle(elementUI, erase)
2097 elseif uiName == "r2ed_chat_sequence" then
2098 r2:buildChatTitle(elementUI, erase)
2099 elseif uiName == r2.logicEntityUIPath.."actions" then
2100 r2:buildActionTitle(elementUI, erase)
2101 elseif uiName == r2.logicEntityUIPath.."reactions" then
2102 r2:buildReactionTitle(elementUI, erase)
2106 ------------------------------------ Up element ------------------------------------------------------
2107 function r2:upTriggerElement(uiName)
2109 local eltSequenceUI = getUI("ui:interface:"..uiName)
2110 assert(eltSequenceUI)
2112 local tab = eltSequenceUI:find("sequence_tabs")
2113 assert(tab)
2115 local sequence = eltSequenceUI:find(tab.associatedGroupSelection)
2116 assert(sequence)
2118 local listElements = sequence:find("elements_list")
2119 assert(listElements)
2121 local selectedElement = r2:getSelectedEltUI(uiName)
2122 local index = listElements:getElementIndex(selectedElement)
2124 if index>0 then
2125 local sequenceId = r2:getSelectedSequInstId(uiName)
2126 r2.requestMoveNode(sequenceId, "Components", index,
2127 sequenceId, "Components", index-1)
2131 ---------------------------------------------------------------------------------------------------
2132 function r2:selectTriggerElement(sequenceUI, uiName, selectedButtonElt)
2134 if sequenceUI == nil then
2135 sequenceUI = r2:getSelectedSequ(uiName)
2137 r2:selectElement(sequenceUI, uiName, true, selectedButtonElt)
2140 ---------------------------------------------------------------------------------------------------
2141 function r2:closeElementEditor(uiName)
2143 if uiName == "r2ed_chat_sequence" then
2144 r2:closeChatEditor(getUICaller())
2147 local sequenceUI = r2:getSelectedSequ(uiName)
2148 assert(sequenceUI)
2150 local selectedEltUI = r2:getSelectedEltUI(uiName)
2151 assert(selectedEltUI)
2153 local selectedEltButton = selectedEltUI:find("select")
2154 assert(selectedEltButton)
2156 selectedEltButton.pushed = false
2158 r2:selectElement(sequenceUI, uiName, false, selectedEltButton)
2161 ---------------- SELECT ELEMENT -------------------------------------------------------------------
2162 function r2:selectElement(sequence, uiName, eltOrder, selectedButtonElt)
2164 local upElement = sequence:find("up_element")
2165 assert(upElement)
2166 local downElement = sequence:find("down_element")
2167 assert(downElement)
2168 local orderElt = sequence:find("element_order")
2170 if selectedButtonElt == nil then
2171 selectedButtonElt = getUICaller()
2174 -- new selected element
2175 if selectedButtonElt.pushed == true then
2177 if r2:getSelectedEltUIId(uiName) then
2179 local lastSelectedElement = r2:getSelectedEltUI(uiName)
2180 assert(lastSelectedElement)
2182 local lastEltsList = lastSelectedElement.parent
2183 local editElt = lastEltsList:find("edit_element")
2184 assert(editElt)
2186 if r2:getSelectedEltUIId(uiName) == selectedButtonElt.parent.parent.parent.id then
2187 return
2190 lastSelectedElement.active = true
2191 lastSelectedElement:find("select").pushed = false
2193 editElt.active = false
2196 r2:setSelectedEltUIId(uiName, selectedButtonElt.parent.parent.parent.id)
2198 local selectedElement = selectedButtonElt.parent.parent.parent
2199 assert(selectedElement)
2201 if eltOrder then
2202 upElement.active = true
2203 downElement.active = true
2204 orderElt.active = true
2207 -- update element editor position in list
2208 local eltsList = sequence:find("elements_list")
2209 assert(eltsList)
2210 local editElt = eltsList:find("edit_element")
2211 assert(editElt)
2213 local indexSelectedElt = eltsList:getElementIndex(selectedElement)
2214 local indexEltEditor = eltsList:getElementIndex(editElt)
2216 if indexEltEditor<indexSelectedElt then
2217 for i=indexEltEditor, indexSelectedElt-1 do
2218 eltsList:downChild(editElt)
2220 else
2221 for i=indexSelectedElt, indexEltEditor-2 do
2222 eltsList:upChild(editElt)
2226 editElt.active = true
2227 selectedElement.active = false
2229 -- cancel current selection
2230 else
2231 local lastSelectedElement = r2:getSelectedEltUI(uiName)
2232 r2:setSelectedEltUIId(uiName, nil)
2234 upElement.active = false
2235 downElement.active = false
2236 orderElt.active = false
2238 local lastEltsList = lastSelectedElement.parent
2239 local editElt = lastEltsList:find("edit_element")
2240 assert(editElt)
2242 editElt.active = false
2243 lastSelectedElement.active = true
2247 ------------------ SELECT SEQUENCE ---------------------------------------------------------
2248 function r2:selectElementsSequence(uiName, index)
2249 local eltsWnd = getUI("ui:interface:"..uiName)
2250 assert(eltsWnd)
2252 local sequencesTab = eltsWnd:find("sequence_tabs")
2253 assert(sequencesTab)
2255 if (index>=0) and (sequencesTab.tabButtonNb > index) then
2256 sequencesTab.selection = tonumber(index)
2258 local repeatButton = eltsWnd:find("repeat_group"):find("repeat"):find("toggle_butt")
2259 assert(repeatButton)
2261 local sequenceUI = sequencesTab:getGroup(index)
2262 assert(sequenceUI)
2263 local sequenceInstId = sequenceUI.Env.sequenceId
2265 if sequenceInstId and r2:getInstanceFromId(sequenceInstId) then
2266 local sequenceInst = r2:getInstanceFromId(sequenceInstId)
2267 repeatButton.pushed = (sequenceInst.Repeating == 0)
2273 ---------------------------------------- Open element editor --------------------------------------
2274 function r2:openElementEditor(uiName, title, baseWindowName)
2276 local elementEditor = r2:getSelectedSequ(uiName):find("edit_element")
2277 assert(elementEditor)
2279 local selectedElement = r2:getSelectedEltUI(uiName)
2280 assert(selectedElement)
2282 elementEditor.active = true
2283 selectedElement.active = false
2286 ----------------------------------- Remove elements sequence --------------------------------------
2287 function r2:removeElementsSequence(uiName, elementsTable, sequName)
2289 local eltSequenceUI = getUI("ui:interface:"..uiName)
2290 assert(eltSequenceUI)
2292 local tab = eltSequenceUI:find("sequence_tabs")
2293 assert(tab)
2295 local activeLogicEntity = r2:getSelectedInstance()
2296 assert(activeLogicEntity)
2297 local activitySequences = activeLogicEntity:getBehavior()[elementsTable]
2299 --local seq = sequName
2301 --for i=tab.selection+1,(tab.tabButtonNb-1) do
2302 -- local buttonTab = tab:find("tab"..i)
2303 -- assert(buttonTab)
2305 -- if activitySequences[i].Name == seq..(i+1) then
2306 -- local newText = seq..(i)
2307 -- r2.requestSetNode(activitySequences[i].InstanceId, "Name", newText)
2308 -- end
2309 --end
2311 local sequenceId = r2:getSelectedSequInstId(uiName)
2312 -- request erase node
2313 r2.requestEraseNode(sequenceId, "", -1)
2315 return sequenceId
2318 function r2:removeElementsSequenceUI(tabIndex, uiName, elementsTable, sequName)
2320 local wndUI = getUI("ui:interface:"..uiName)
2321 assert(wndUI)
2323 local tab = wndUI:find("sequence_tabs")
2324 assert(tab)
2326 local activeLogicEntity = r2:getSelectedInstance()
2327 assert(activeLogicEntity)
2328 local activitySequences = activeLogicEntity:getBehavior()[elementsTable]
2330 for i=tabIndex+1,(tab.tabButtonNb-1) do
2331 local buttonTab = tab:find("tab"..i)
2332 assert(buttonTab)
2334 buttonTab.params_l = "r2:selectSequenceTab('"..uiName.."', "..tostring(i-1)..")"
2336 if buttonTab.hardtext == sequName..(i+1) then
2337 buttonTab.uc_hardtext = sequName..i
2341 -- recover name of the future "first sequence"
2342 local firstEltName
2343 local indexName
2344 if tab.tabButtonNb > 1 then
2345 if tabIndex==0 then
2346 indexName = 1
2347 else
2348 indexName = 0
2350 --if activitySequences[indexName].Name==sequName..(indexName+1) then
2351 if r2:getSequenceName(activitySequences[indexName])==sequName..(indexName+1) then
2352 firstEltName = sequName.."1"
2353 else
2354 --firstEltName = activitySequences[indexName].Name
2355 firstEltName = r2:getSequenceName(activitySequences[indexName])
2357 else
2358 firstEltName = tostring(i18n.get("uiR2EDSequences"))
2361 local selectedElt = r2:getSelectedEltUI(uiName)
2362 if selectedElt and selectedElt.parent.parent.parent.id == r2:getSelectedSequ(uiName).id then
2363 r2:setSelectedEltUIId(uiName, nil)
2366 tab:removeTab(tabIndex)
2368 if tab.tabButtonNb == 0 then
2369 r2:cleanSequenceEditor(wndUI)
2372 return firstEltName
2375 function r2:cleanSequenceEditor(eltSequenceUI)
2377 local sepTop = eltSequenceUI:find("sep_top")
2378 assert(sepTop)
2380 local sepBottom = eltSequenceUI:find("sep_bottom")
2381 assert(sepBottom)
2383 local sepLeft = eltSequenceUI:find("sep_left")
2384 assert(sepLeft)
2386 local sepRight = eltSequenceUI:find("sep_right")
2387 assert(sepRight)
2389 local removeSequence = eltSequenceUI:find("remove_sequence_button")
2390 assert(removeSequence)
2392 local editSequence = eltSequenceUI:find("edit_sequence")
2393 assert(editSequence)
2395 sepTop.active = false
2396 sepBottom.active = false
2397 sepLeft.active= false
2398 sepRight.active= false
2399 removeSequence.active = false
2400 editSequence.active = false
2402 local repeatButtonGr = eltSequenceUI:find("repeat_group")
2403 repeatButtonGr.active = false
2406 ------------------ new elements sequence -------------------------------------------------------------
2407 function r2:newElementsSequence(uiName, templateParams, editorEltTemplate, instance, sequName)
2409 local eltSequenceUI = getUI("ui:interface:"..uiName)
2410 assert(eltSequenceUI)
2412 local menu = eltSequenceUI:find("sequence_menu")
2413 assert(menu)
2415 local tab = menu:find("sequence_tabs")
2416 assert(tab)
2418 local newTabNb = tab.tabButtonNb+1
2419 local posParent, posRef, id, hardText, group
2420 if newTabNb == 1 then
2421 posParent = "parent"
2422 posRef = "TL TL"
2423 else
2424 posParent = "tab"..(newTabNb-2)
2425 posRef = "TR TL"
2428 id = "tab"..(newTabNb-1)
2429 local group = "sequence"..r2.sequencesNb
2431 r2.sequencesNb = r2.sequencesNb + 1
2433 local newTabGroup = createUIElement("sequence_elements_template", menu.id, {id=group,
2434 new_elt=templateParams.newElt, new_elt_text=templateParams.newEltText,
2435 elt_order_text=templateParams.eltOrderText, up_elt=templateParams.upElt,
2436 down_elt=templateParams.downElt, max_min_elts=templateParams.maxMinElts,
2437 down_up_color=templateParams.downUpColor})
2438 assert(newTabGroup)
2440 menu:addGroup(newTabGroup)
2442 newTabGroup.Env.sequenceId = instance.InstanceId
2444 local tabName
2445 if instance.Name~= "" then
2446 tabName = instance.Name
2447 else
2448 local comps = instance.Parent
2449 for i=0, comps.Size-1 do
2450 if comps[i].InstanceId == instance.InstanceId then
2451 tabName = sequName..(i+1)
2452 break
2457 local newTab = createUIElement("sequence_tab_template", tab.id,
2458 {id=id, posparent=posParent, posref=posRef, hardtext=tabName, group=group,
2459 col_pushed =templateParams.colPushed, params_l=templateParams.paramsL})
2460 assert(newTab)
2462 tab:addTab(newTab)
2464 if r2.ownCreatedInstances[instance.InstanceId] == true then
2465 tab.selection = tab.tabButtonNb-1
2466 r2.ownCreatedInstances[instance.InstanceId] = nil
2468 --local repeatButton = eltSequenceUI:find("repeat_group"):find("repeat"):find("toggle_butt")
2469 --assert(repeatButton)
2470 --repeatButton.pushed = (instance.Repeating == 0)
2472 r2:selectElementsSequence(uiName, tab.tabButtonNb-1)
2475 if tab.tabButtonNb == 1 then
2476 local sepTop = menu:find("sep_top")
2477 assert(sepTop)
2479 local sepBottom = menu:find("sep_bottom")
2480 assert(sepBottom)
2482 local sepLeft = menu:find("sep_left")
2483 assert(sepLeft)
2485 local sepRight = menu:find("sep_right")
2486 assert(sepRight)
2488 local removeSequence = eltSequenceUI:find("remove_sequence_button")
2489 assert(removeSequence)
2491 local editSequence = eltSequenceUI:find("edit_sequence")
2492 assert(editSequence)
2494 sepTop.active = true
2495 sepBottom.active = true
2496 sepLeft.active= true
2497 sepRight.active= true
2498 removeSequence.active = true
2499 editSequence.active = true
2501 if uiName == "r2ed_triggers" then --TEMP TEMP TEMP
2502 local repeatButtonGr = eltSequenceUI:find("repeat_group")
2503 repeatButtonGr.active = true
2504 end --TEMP TEMP TEMP
2507 local listElements = newTabGroup:find("elements_list")
2508 assert(listElements)
2509 listElements.Env.elementsCount = nil
2511 -- add element editor in list
2512 local newEditorElt = createGroupInstance(editorEltTemplate, listElements.id, {id="edit_element", active="false"})
2513 assert(newEditorElt)
2514 listElements:addChild(newEditorElt)
2515 listElements.parent:updateCoords()
2517 newEditorElt.Env.isEditor = true
2519 newEditorElt.active = false
2521 return newTabGroup
2524 ---------------------------- new element --------------------------------------------------------------
2525 function r2:newTriggerElement(uiName, elementName, templateParams, sequenceUI, instanceId)
2527 if sequenceUI == nil then
2528 eltSequenceUI = getUI("ui:interface:"..uiName)
2529 assert(eltSequenceUI)
2531 local tab = eltSequenceUI:find("sequence_tabs")
2532 assert(tab)
2534 local sequenceUI = eltSequenceUI:find(tab.associatedGroupSelection)
2536 assert(sequenceUI)
2538 local newElement = r2:newElement(sequenceUI, elementName, templateParams, true)
2540 newElement.Env.elementId = instanceId
2542 if r2.ownCreatedInstances[instanceId] == true then
2543 newElement:find("select").pushed = true
2544 r2:selectTriggerElement(sequenceUI, uiName, newElement:find("select"))
2545 r2.ownCreatedInstances[instanceId] = nil
2547 if uiName == "r2ed_triggers" then
2548 r2:updateActivityEditor()
2549 elseif uiName == "r2ed_chat_sequence" then
2550 r2:updateChatEditor()
2554 r2:maximizeMinimizeElement(uiName, newElement)
2556 return newElement
2559 ---------------------------- new base element --------------------------------------------------------------
2560 function r2:newElement(sequence, elementName, templateParams, eltOrder)
2562 local listElements = sequence:find("elements_list")
2563 assert(listElements)
2565 -- counter for element group id
2566 if listElements.Env.elementsCount == nil then
2567 listElements.Env.elementsCount = 0
2568 listElements.Env.elementsNb = 1
2569 else
2570 listElements.Env.elementsCount = listElements.Env.elementsCount+1
2571 listElements.Env.elementsNb = listElements.Env.elementsNb+1
2574 local elementId = "elt"..listElements.Env.elementsCount
2576 local hardText = elementName.." "..listElements.Env.elementsNb.." : "
2578 -- create new element
2579 local newElement = createGroupInstance("element_template", listElements.id,
2580 {id=elementId, posref="TL TL", x="0", y="0", sizeref="w", hardtext=hardText,
2581 select_elt=templateParams.selectElt, open_elt_editor=templateParams.openEltEditor,
2582 max_min_elt=templateParams.maxMinElt, remove_elt=templateParams.removeElt, open_chat=templateParams.openChat,
2583 col_over=templateParams.colOver, col_pushed=templateParams.colPushed})
2585 -- add element to list
2586 listElements:addChild(newElement)
2587 listElements.parent:updateCoords()
2589 -- active global minimize / maximize button
2590 if listElements.childrenNb == 2 then
2591 local maxElts = sequence:find("maximize_elements")
2592 assert(maxElts)
2593 maxElts.active = true
2595 if eltOrder then
2597 local elementOrder = sequence:find("element_order")
2598 assert(elementOrder)
2599 elementOrder.active=true
2603 -- scroll goes down to new element
2604 local sequenceContent = newElement.parent.parent.parent
2605 assert(sequenceContent)
2607 local scrollBar = sequenceContent:find("scroll_objects")
2608 assert(scrollBar)
2609 scrollBar.trackPos = 0
2611 -- target sroll text
2612 local scroll = newElement:find("scroll_bar_text")
2613 assert(scroll)
2615 local scrollText = newElement:find("scroll_text_gr")
2616 assert(scrollText)
2617 scroll:setTarget(scrollText.id)
2619 return newElement
2622 ------------------ OPEN SEQUENCE EDITOR --------------------------------------------------
2623 function r2:openSequenceEditor(uiName, editorName)
2625 local editor = getUI("ui:interface:"..editorName)
2626 assert(editor)
2628 local eltsUI = getUI("ui:interface:"..uiName)
2629 assert(eltsUI)
2631 editor.x = eltsUI.x
2632 editor.y = eltsUI.y
2633 editor.active = true
2635 -- update edit box text with current sequence name
2636 local editName = editor:find("sequence_name"):find("edit_box_group")
2637 assert(editName)
2639 local tab = eltsUI:find("sequence_tabs")
2640 assert(tab)
2642 local buttonTab = tab:find("tab"..tab.selection)
2643 assert(buttonTab)
2645 editName.uc_input_string = buttonTab.uc_hardtext
2648 ------------------ SET SEQUENCE NAME -----------------------------------------------------
2649 function r2:setSequenceName(uiName, editorName)
2651 local editor = getUI("ui:interface:"..editorName)
2652 assert(editor)
2654 local editName = editor:find("sequence_name"):find("edit_box_group")
2655 assert(editName)
2657 local name = editName.input_string
2659 local sequenceInstId = r2:getSelectedSequInstId(uiName)
2660 r2.requestSetNode(sequenceInstId, "Name", name)
2663 function r2:updateSequenceName(uiName, instance)
2665 --local name = instance.Name
2666 local name = r2:getSequenceName(instance)
2667 local sequInstId = instance.InstanceId
2669 local eltsUI = getUI("ui:interface:"..uiName)
2670 assert(eltsUI)
2672 local tab = eltsUI:find("sequence_tabs")
2673 assert(tab)
2675 local tabId
2676 for i=0, tab.tabButtonNb-1 do
2677 local sequenceUI = tab:getGroup(i)
2678 if sequenceUI.Env.sequenceId == sequInstId then
2679 tabId = i
2680 break
2684 local buttonTab = tab:find("tab"..tabId)
2685 assert(buttonTab)
2687 buttonTab.uc_hardtext = name
2689 if uiName == "r2ed_triggers" then
2690 r2:updateSequencesButtonBar(tabId, name)
2694 function r2:updateSequenceRepeatingOption(uiName, instance)
2696 local sequenceUI = r2:getSelectedSequ(uiName)
2698 if sequenceUI.Env.sequenceId == instance.InstanceId then
2700 local eltsUI = getUI("ui:interface:"..uiName)
2701 local repeatButton = eltsUI:find("repeat_group"):find("repeat"):find("toggle_butt")
2702 repeatButton.pushed = (instance.Repeating == 0)
2707 --------------------------------------------------------------------------------------------------
2708 -------------------------- ACTIVE LOGIC ENTITY DisplayerProperties -----------------------------------------
2709 --------------------------------------------------------------------------------------------------
2711 local activeLogicEntityPropertySheetDisplayerTable = clone(r2:propertySheetDisplayer())
2713 ------------------------------------------------
2714 function activeLogicEntityPropertySheetDisplayerTable:onPostCreate(instance)
2716 ------------------------------------------------
2717 function activeLogicEntityPropertySheetDisplayerTable:onErase(instance)
2719 ------------------------------------------------
2720 function activeLogicEntityPropertySheetDisplayerTable:onPreHrcMove(instance)
2722 ------------------------------------------------
2723 function activeLogicEntityPropertySheetDisplayerTable:onPostHrcMove(instance)
2725 ------------------------------------------------
2726 function activeLogicEntityPropertySheetDisplayerTable:onFocus(instance, hasFocus)
2729 ------------------------------------------------
2730 r2.activitiesAndChatsUIUpdate = false
2731 function activeLogicEntityPropertySheetDisplayerTable:onSelect(instance, isSelected)
2733 r2:logicEntityPropertySheetDisplayer():onSelect(instance, isSelected)
2735 local triggersUI = getUI("ui:interface:r2ed_triggers")
2736 assert(triggersUI)
2738 if not isSelected then
2739 triggersUI.active = false
2740 r2:closeMiniActivityView()
2741 r2:closeChatSequencesUI()
2743 r2:cleanActivitiesAndChatsUI()
2744 r2:cleanLogicEntityUI()
2745 else
2746 r2.activitiesAndChatsUIUpdate = false
2750 r2.callSetSaysWhat = true
2751 ------------------------------------------------
2752 function r2:cleanActivitiesAndChatsUI()
2754 -- update chat sequence combo box
2755 local triggersUI = getUI("ui:interface:r2ed_triggers")
2756 assert(triggersUI)
2757 local chatSequencesUI = getUI("ui:interface:r2ed_chat_sequence")
2758 assert(chatSequencesUI)
2760 -- remove all tabs
2761 local sequenceMenu = triggersUI:find("sequence_menu")
2762 assert(sequenceMenu)
2764 local tabActivities = triggersUI:find("sequence_tabs")
2765 assert(tabActivities)
2767 for i=0, tabActivities.tabButtonNb-1 do
2768 local groupTab = tabActivities:getGroup(i)
2769 assert(groupTab)
2770 sequenceMenu:delGroup(groupTab)
2773 tabActivities:removeAll()
2774 r2:setSelectedEltUIId("r2ed_triggers", nil)
2775 r2:cleanSequenceEditor(triggersUI)
2777 -- delete chat sequences
2778 sequenceMenu = chatSequencesUI:find("sequence_menu")
2779 assert(sequenceMenu)
2781 local tabChats = chatSequencesUI:find("sequence_tabs")
2782 assert(tabChats)
2784 for i=0, tabChats.tabButtonNb-1 do
2785 local groupTab = tabChats:getGroup(i)
2786 assert(groupTab)
2787 sequenceMenu:delGroup(groupTab)
2790 tabChats:removeAll()
2791 r2:setSelectedEltUIId("r2ed_chat_sequence", nil)
2792 r2:cleanSequenceEditor(chatSequencesUI)
2795 function r2:updateActivitiesAndChatsUI(instance)
2797 if r2.activitiesAndChatsUIUpdate==true then
2798 return
2801 r2.activitiesAndChatsUIUpdate = true
2803 if r2.lastSelectedActivitySequence==nil then
2805 r2:cleanActivitiesAndChatsUI()
2807 -- update chat sequence combo box
2808 local triggersUI = getUI("ui:interface:r2ed_triggers")
2809 assert(triggersUI)
2810 local chatSequencesUI = getUI("ui:interface:r2ed_chat_sequence")
2811 assert(chatSequencesUI)
2813 -- remove all tabs
2814 local tabActivities = triggersUI:find("sequence_tabs")
2815 assert(tabActivities)
2817 -- delete chat sequences
2818 local tabChats = chatSequencesUI:find("sequence_tabs")
2819 assert(tabChats)
2822 local activitySequences = instance:getBehavior().Activities
2823 local chatSequences = instance:getBehavior().ChatSequences
2825 -- build sequences of selected NPC group
2826 local uiName = "r2ed_triggers"
2828 for s = 0, activitySequences.Size - 1 do
2829 local sequence = activitySequences[s]
2830 r2:newActivitiesSequence(false, sequence, true)
2833 if tabActivities.tabButtonNb>1 then
2834 tabActivities.selection = 0
2835 r2:selectElementsSequence(uiName, 0)
2837 for s=0, tabActivities.tabButtonNb-1 do
2838 local sequenceUI = tabActivities:getGroup(s)
2839 assert(sequenceUI)
2841 local eltsList = sequenceUI:find("elements_list")
2842 assert(eltsList)
2843 if eltsList.childrenNb > 1 then
2844 local firstElt = eltsList:getChild(1)
2845 local selectedButton = firstElt:find("select")
2846 selectedButton.pushed = true
2848 r2:selectElement(sequenceUI, uiName, true, selectedButton)
2850 r2:updateActivityEditor()
2852 break
2856 uiName = "r2ed_chat_sequence"
2857 r2.callSetSaysWhat = false
2858 for s = 0, chatSequences.Size - 1 do
2859 local sequence = chatSequences[s]
2860 r2:newChatsSequence(false, sequence, true)
2862 r2.callSetSaysWhat = true
2863 if tabChats.tabButtonNb>1 then
2864 tabChats.selection = 0
2865 r2:selectElementsSequence(uiName, 0)
2867 for s=0, tabChats.tabButtonNb-1 do
2868 local sequenceUI = tabChats:getGroup(s)
2869 assert(sequenceUI)
2871 local eltsList = sequenceUI:find("elements_list")
2872 assert(eltsList)
2873 if eltsList.childrenNb > 1 then
2874 local firstElt = eltsList:getChild(1)
2875 local selectedButton = firstElt:find("select")
2876 r2.callSetSaysWhat = false
2877 selectedButton.pushed = true
2879 r2:selectElement(sequenceUI, uiName, true, selectedButton)
2881 r2.callSetSaysWhat = true
2883 r2:updateChatEditor()
2887 triggersUI.uc_title = tostring(i18n.get("uiR2EDActivitySequenceEditor")) .. r2:getSelectedInstance().Name
2888 chatSequencesUI.uc_title = tostring(i18n.get("uiR2EDChatSequenceEditor")) .. r2:getSelectedInstance().Name
2892 ------------------------------------------------
2893 function activeLogicEntityPropertySheetDisplayerTable:onAttrModified(instance, attributeName)
2895 r2:logicEntityPropertySheetDisplayer():onAttrModified(instance, attributeName)
2897 if not r2.activitiesAndChatsUIUpdate or instance ~= r2:getSelectedInstance() then
2898 return
2901 if attributeName == "Name" then
2903 local triggersUI = getUI("ui:interface:r2ed_triggers")
2904 assert(triggersUI)
2906 local chatSequencesUI = getUI("ui:interface:r2ed_chat_sequence")
2907 assert(chatSequencesUI)
2909 triggersUI.uc_title = tostring(i18n.get("uiR2EDActivitySequenceEditor")) .. instance[attributeName]
2910 chatSequencesUI.uc_title = tostring(i18n.get("uiR2EDChatSequenceEditor")) .. instance[attributeName]
2912 end
2914 ------------------------------------------------
2915 function r2:activeLogicEntityPropertySheetDisplayer()
2916 return activeLogicEntityPropertySheetDisplayerTable -- returned shared displayer to avoid wasting memory
2920 --------------------------------------------------------------------------------------------------
2921 -------------------------- NPC GROUP DisplayerProperties -----------------------------------------
2922 --------------------------------------------------------------------------------------------------
2924 local npcGroupPropertySheetDisplayerTable = clone(r2:propertySheetDisplayer())
2926 ------------------------------------------------
2927 function npcGroupPropertySheetDisplayerTable:onPostCreate(instance)
2929 ------------------------------------------------
2930 function npcGroupPropertySheetDisplayerTable:onErase(instance)
2932 ------------------------------------------------
2933 function npcGroupPropertySheetDisplayerTable:onPreHrcMove(instance)
2935 ------------------------------------------------
2936 function npcGroupPropertySheetDisplayerTable:onPostHrcMove(instance)
2938 ------------------------------------------------
2939 function npcGroupPropertySheetDisplayerTable:onFocus(instance, hasFocus)
2942 ------------------------------------------------
2943 function npcGroupPropertySheetDisplayerTable:onSelect(instance, isSelected)
2944 r2:activeLogicEntityPropertySheetDisplayer():onSelect(instance, isSelected)
2947 ------------------------------------------------
2948 function npcGroupPropertySheetDisplayerTable:onAttrModified(instance, attributeName)
2949 r2:activeLogicEntityPropertySheetDisplayer():onAttrModified(instance, attributeName)
2950 end
2952 ------------------------------------------------
2953 function r2:npcGroupPropertySheetDisplayer()
2954 return npcGroupPropertySheetDisplayerTable -- returned shared displayer to avoid wasting memory
2962 --------------------------------------------------------------------------------------------------
2963 -------------------------------- ACTIVITY SEQUENCE DisplayerProperties ---------------------------
2964 --------------------------------------------------------------------------------------------------
2965 local activitySequencePropertySheetDisplayerTable = clone(r2:propertySheetDisplayer())
2967 ------------------------------------------------
2968 function activitySequencePropertySheetDisplayerTable:onPostCreate(instance)
2970 local activeLogicEntity = r2:getSelectedInstance()
2971 local activeLogicEntityParent = instance.Parent.Parent.Parent
2973 if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
2974 return
2977 r2:newActivitiesSequence(false, instance, false)
2979 ------------------------------------------------
2980 function activitySequencePropertySheetDisplayerTable:onErase(instance)
2982 local activeLogicEntity = r2:getSelectedInstance()
2983 local activeLogicEntityParent = instance.Parent.Parent.Parent
2985 if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
2986 return
2989 local triggersUI = getUI("ui:interface:r2ed_triggers")
2990 assert(triggersUI)
2992 local sequenceTabs = triggersUI:find("sequence_tabs")
2993 assert(sequenceTabs)
2995 local sequIndex
2996 for i=0,sequenceTabs.tabButtonNb-1 do
2997 local sequence = sequenceTabs:getGroup(i)
2998 if sequence.Env.sequenceId == instance.InstanceId then
2999 sequIndex = i
3000 break
3004 if sequIndex~=nil then
3005 r2:removeActivitiesSequenceUI(sequIndex)
3008 ------------------------------------------------
3009 function activitySequencePropertySheetDisplayerTable:onPreHrcMove(instance)
3011 ------------------------------------------------
3012 function activitySequencePropertySheetDisplayerTable:onPostHrcMove(instance)
3014 ------------------------------------------------
3015 function activitySequencePropertySheetDisplayerTable:onFocus(instance, hasFocus)
3018 ------------------------------------------------
3019 function activitySequencePropertySheetDisplayerTable:onSelect(instance, isSelected)
3022 ------------------------------------------------
3023 function activitySequencePropertySheetDisplayerTable:onAttrModified(instance, attributeName)
3025 local activeLogicEntity = r2:getSelectedInstance()
3026 local activeLogicEntityParent = instance.Parent.Parent.Parent
3028 if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
3029 return
3032 if attributeName == "Name" then
3033 r2:updateSequenceName("r2ed_triggers", instance)
3034 elseif attributeName == "Repeating" then
3035 r2:updateSequenceRepeatingOption("r2ed_triggers", instance)
3036 end
3037 end
3039 ------------------------------------------------
3040 function r2:activitySequencePropertySheetDisplayer()
3041 return activitySequencePropertySheetDisplayerTable -- returned shared displayer to avoid wasting memory
3045 --------------------------------------------------------------------------------------------------
3046 -------------------------------- CHAT SEQUENCE DisplayerProperties ---------------------------
3047 --------------------------------------------------------------------------------------------------
3048 local chatSequencePropertySheetDisplayerTable = clone(r2:propertySheetDisplayer())
3050 ------------------------------------------------
3051 function chatSequencePropertySheetDisplayerTable:onPostCreate(instance)
3053 local activeLogicEntity = r2:getSelectedInstance()
3054 local activeLogicEntityParent = instance.Parent.Parent.Parent
3056 if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
3057 return
3060 r2:newChatsSequence(false, instance)
3062 ------------------------------------------------
3063 function chatSequencePropertySheetDisplayerTable:onErase(instance)
3065 local activeLogicEntity = r2:getSelectedInstance()
3066 local activeLogicEntityParent = instance.Parent.Parent.Parent
3068 if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
3069 return
3072 local chatsUI = getUI("ui:interface:r2ed_chat_sequence")
3073 assert(chatsUI)
3075 local sequenceTabs = chatsUI:find("sequence_tabs")
3076 assert(sequenceTabs)
3078 local sequIndex
3079 for i=0,sequenceTabs.tabButtonNb-1 do
3080 local sequence = sequenceTabs:getGroup(i)
3081 if sequence.Env.sequenceId == instance.InstanceId then
3082 sequIndex = i
3083 break
3087 if sequIndex~=nil then
3088 r2:removeChatsSequenceUI(sequIndex)
3091 r2:updateMiniActivityView()
3093 ------------------------------------------------
3094 function chatSequencePropertySheetDisplayerTable:onPreHrcMove(instance)
3096 ------------------------------------------------
3097 function chatSequencePropertySheetDisplayerTable:onPostHrcMove(instance)
3099 ------------------------------------------------
3100 function chatSequencePropertySheetDisplayerTable:onFocus(instance, hasFocus)
3103 ------------------------------------------------
3104 function chatSequencePropertySheetDisplayerTable:onSelect(instance, isSelected)
3107 ------------------------------------------------
3108 function chatSequencePropertySheetDisplayerTable:onAttrModified(instance, attributeName)
3110 local activeLogicEntity = r2:getSelectedInstance()
3111 local activeLogicEntityParent = instance.Parent.Parent.Parent
3113 if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
3114 return
3117 if attributeName == "Name" then
3118 r2:updateSequenceName("r2ed_chat_sequence", instance)
3119 elseif attributeName == "Repeating" then
3120 r2:updateSequenceRepeatingOption("r2ed_chat_sequence", instance)
3121 end
3122 end
3124 ------------------------------------------------
3125 function r2:chatSequencePropertySheetDisplayer()
3126 return chatSequencePropertySheetDisplayerTable -- returned shared displayer to avoid wasting memory
3130 --------------------------------------------------------------------------------------------------
3131 -------------------------------- ACTIVITY STEP DisplayerProperties--------------------------------
3132 --------------------------------------------------------------------------------------------------
3133 local activityStepPropertySheetDisplayerTable = clone(r2:propertySheetDisplayer())
3135 ------------------------------------------------
3136 function activityStepPropertySheetDisplayerTable:onPostCreate(instance)
3138 local activeLogicEntity = r2:getSelectedInstance()
3139 local activeLogicEntityParent = instance.Parent.Parent.Parent.Parent.Parent
3141 if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
3142 return
3145 local activitySequInst = instance.Parent.Parent
3147 local triggersUI = getUI("ui:interface:r2ed_triggers")
3148 assert(triggersUI)
3150 local sequenceTabs = triggersUI:find("sequence_tabs")
3151 assert(sequenceTabs)
3153 local sequenceUI
3154 for i=0,sequenceTabs.tabButtonNb-1 do
3155 local sequence = sequenceTabs:getGroup(i)
3156 if sequence.Env.sequenceId == activitySequInst.InstanceId then
3157 sequenceUI = sequence
3158 break
3162 r2:newActivity(false, nil, instance, sequenceUI)
3164 ------------------------------------------------
3165 function activityStepPropertySheetDisplayerTable:onErase(instance)
3167 local activeLogicEntity = r2:getSelectedInstance()
3168 local activeLogicEntityParent = instance.Parent.Parent.Parent.Parent.Parent
3170 if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
3171 return
3174 local sequenceUI, elementUI = r2:findSequenceAndElementUIFromInstance(instance, "r2ed_triggers")
3176 if elementUI ~= nil then
3177 r2:removeActivityUI(sequenceUI, elementUI)
3180 ------------------------------------------------
3181 function activityStepPropertySheetDisplayerTable:onPreHrcMove(instance)
3183 ------------------------------------------------
3184 function activityStepPropertySheetDisplayerTable:onPostHrcMove(instance)
3186 local activeLogicEntity = r2:getSelectedInstance()
3187 local activeLogicEntityParent = instance.Parent.Parent.Parent.Parent.Parent
3189 if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
3190 return
3193 local sequenceUI, activityStepUI = r2:findSequenceAndElementUIFromInstance(instance, "r2ed_triggers")
3194 if activityStepUI then
3195 r2:downUpElement(activityStepUI, "r2ed_triggers")
3196 end
3198 ------------------------------------------------
3199 function activityStepPropertySheetDisplayerTable:onFocus(instance, hasFocus)
3202 ------------------------------------------------
3203 function activityStepPropertySheetDisplayerTable:onSelect(instance, isSelected)
3206 ------------------------------------------------
3207 function activityStepPropertySheetDisplayerTable:onAttrModified(instance, attributeName)
3209 local activeLogicEntity = r2:getSelectedInstance()
3210 local activeLogicEntityParent = instance.Parent.Parent.Parent.Parent.Parent
3212 if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
3213 return
3216 local sequenceUI, elementUI = r2:findSequenceAndElementUIFromInstance(instance, "r2ed_triggers")
3217 if elementUI then
3218 r2:updateActivityChatSequence(elementUI)
3220 end
3222 ------------------------------------------------
3223 function activityStepPropertySheetDisplayerTable:onTargetInstanceEraseRequested(instance, refIdName, refIdIndexInArray)
3225 if refIdName == "ActivityZoneId" then
3226 r2.requestSetNode(instance.InstanceId, "Activity", "Stand Still")
3227 r2.requestSetNode(instance.InstanceId, "ActivityZoneId", r2.RefId(""))
3228 r2.requestSetNode(instance.InstanceId, "TimeLimit", "No Limit")
3229 r2.requestSetNode(instance.InstanceId, "TimeLimitValue", "")
3230 elseif refIdName == "Chat" then
3231 r2.requestSetNode(instance.InstanceId, "Chat", r2.RefId(""))
3234 ------------------------------------------------
3235 function activityStepPropertySheetDisplayerTable:onTargetInstanceAttrModified(instance, refIdName, refIdIndexInArray, targetAttrName, targetAttrIndexInArray)
3238 -------------------------------------------------
3239 function r2:activityStepPropertySheetDisplayer()
3240 return activityStepPropertySheetDisplayerTable -- returned shared displayer to avoid wasting memory
3245 --------------------------------------------------------------------------------------------------
3246 -------------------------------- CHAT STEP DisplayerProperties------------------------------------
3247 --------------------------------------------------------------------------------------------------
3248 local chatStepPropertySheetDisplayerTable = clone(r2:propertySheetDisplayer())
3250 ------------------------------------------------
3251 function chatStepPropertySheetDisplayerTable:onPostCreate(instance)
3253 local activeLogicEntity = r2:getSelectedInstance()
3254 local activeLogicEntityParent = instance.Parent.Parent.Parent.Parent.Parent
3256 if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
3257 return
3260 local chatSequInst = instance.Parent.Parent
3262 local chatsUI = getUI("ui:interface:r2ed_chat_sequence")
3263 assert(chatsUI)
3265 local sequenceTabs = chatsUI:find("sequence_tabs")
3266 assert(sequenceTabs)
3268 local sequenceUI
3269 for i=0,sequenceTabs.tabButtonNb-1 do
3270 local sequence = sequenceTabs:getGroup(i)
3271 if sequence.Env.sequenceId == chatSequInst.InstanceId then
3272 sequenceUI = sequence
3273 break
3277 r2:newChat(false, instance, sequenceUI)
3279 ------------------------------------------------
3280 function chatStepPropertySheetDisplayerTable:onErase(instance)
3282 local activeLogicEntity = r2:getSelectedInstance()
3283 local activeLogicEntityParent = instance.Parent.Parent.Parent.Parent.Parent
3285 if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
3286 return
3289 local sequenceUI, elementUI = r2:findSequenceAndElementUIFromInstance(instance, "r2ed_chat_sequence")
3291 if elementUI ~= nil then
3292 local chatStepInst = r2:getInstanceFromId(elementUI.Env.elementId)
3293 assert(chatStepInst)
3294 r2:updateActivitiesWhithThisChatSequence(chatStepInst, true)
3295 r2:removeElementUI(sequenceUI, "r2ed_chat_sequence", elementUI)
3298 ------------------------------------------------
3299 function chatStepPropertySheetDisplayerTable:onPreHrcMove(instance)
3301 ------------------------------------------------
3302 function chatStepPropertySheetDisplayerTable:onPostHrcMove(instance)
3304 local activeLogicEntity = r2:getSelectedInstance()
3305 local activeLogicEntityParent = instance.Parent.Parent.Parent.Parent.Parent
3307 if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
3308 return
3311 r2:updateActivitiesWhithThisChatSequence(instance, false)
3313 local sequenceUI, chatStepUI = r2:findSequenceAndElementUIFromInstance(instance, "r2ed_chat_sequence")
3314 if chatStepUI then
3315 r2:downUpElement(chatStepUI, "r2ed_chat_sequence")
3318 ------------------------------------------------
3319 function chatStepPropertySheetDisplayerTable:onFocus(instance, hasFocus)
3322 ------------------------------------------------
3323 function chatStepPropertySheetDisplayerTable:onSelect(instance, isSelected)
3326 ------------------------------------------------
3327 function chatStepPropertySheetDisplayerTable:onAttrModified(instance, attributeName)
3329 local activeLogicEntity = r2:getSelectedInstance()
3330 local activeLogicEntityParent = instance.Parent.Parent.Parent.Parent.Parent
3332 if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
3333 return
3336 local sequenceUI, chatStepUI = r2:findSequenceAndElementUIFromInstance(instance, "r2ed_chat_sequence")
3337 if chatStepUI then
3338 r2:updateChatText(chatStepUI)
3340 end
3342 function r2:findSequenceAndElementUIFromInstance(instance, uiName)
3344 local sequenceInst = instance.Parent.Parent
3346 local wndUI = getUI("ui:interface:"..uiName)
3347 assert(wndUI)
3349 local sequenceTabs = wndUI:find("sequence_tabs")
3350 assert(sequenceTabs)
3352 local sequenceUI
3353 for i=0,sequenceTabs.tabButtonNb-1 do
3354 local sequence = sequenceTabs:getGroup(i)
3355 if sequence.Env.sequenceId == sequenceInst.InstanceId then
3356 sequenceUI = sequence
3357 break
3361 if sequenceUI ~= nil then
3362 local eltsList = sequenceUI:find("elements_list")
3363 assert(eltsList)
3365 for i=0,eltsList.childrenNb-1 do
3366 local element = eltsList:getChild(i)
3367 if element.Env.elementId == instance.InstanceId then
3368 return sequenceUI, element
3374 --------------------------------------------------
3375 function r2:chatStepPropertySheetDisplayer()
3376 return chatStepPropertySheetDisplayerTable -- returned shared displayer to avoid wasting memory
3381 --------------------------------------------------------------------------------------------------
3382 -------------------------------- CHAT ACTION DisplayerProperties -----------------------
3383 --------------------------------------------------------------------------------------------------
3384 local chatActionPropertySheetDisplayerTable = clone(r2:propertySheetDisplayer())
3386 ------------------------------------------------
3387 function chatActionPropertySheetDisplayerTable:onPostCreate(instance)
3389 ------------------------------------------------
3390 function chatActionPropertySheetDisplayerTable:onErase(instance)
3392 ------------------------------------------------
3393 function chatActionPropertySheetDisplayerTable:onPreHrcMove(instance)
3395 ------------------------------------------------
3396 function chatActionPropertySheetDisplayerTable:onPostHrcMove(instance)
3398 ------------------------------------------------
3399 function chatActionPropertySheetDisplayerTable:onFocus(instance, hasFocus)
3402 ------------------------------------------------
3403 function chatActionPropertySheetDisplayerTable:onSelect(instance, isSelected)
3406 ------------------------------------------------
3407 function chatActionPropertySheetDisplayerTable:onAttrModified(instance, attributeName)
3408 end
3410 ------------------------------------------------
3411 function chatActionPropertySheetDisplayerTable:onTargetInstanceEraseRequested(instance, refIdName, refIdIndexInArray)
3412 if refIdName == "Who" then
3413 r2.requestSetNode(instance.InstanceId, "Who", r2.RefId(""))
3414 r2.requestSetNode(instance.InstanceId, "Says", "")
3415 r2.requestSetNode(instance.InstanceId, "Emote", "")
3416 r2.requestSetNode(instance.InstanceId, "Facing", r2.RefId(""))
3417 elseif refIdName == "Facing" then
3418 r2.requestSetNode(instance.InstanceId, "Facing", r2.RefId(""))
3421 ------------------------------------------------
3422 function chatActionPropertySheetDisplayerTable:onTargetInstanceAttrModified(instance, refIdName, refIdIndexInArray, targetAttrName, targetAttrIndexInArray)
3425 ------------------------------------------------
3426 function r2:chatActionPropertySheetDisplayer()
3427 return chatActionPropertySheetDisplayerTable -- returned shared displayer to avoid wasting memory
3440 r2.lastSelectedActivitySequence = nil
3442 r2.activityTexture = { ["Follow Route"] = "r2_mini_activity_follow_road.tga",
3443 ["Patrol"] = "r2_mini_activity_patrol_road.tga",
3444 ["Repeat Road"] = "r2_mini_activity_repeat_road.tga",
3445 ["Wander"] = "r2_mini_activity_wander_zone.tga",
3446 ["Stand Still"] = "r2_mini_activity_stand_still.tga",
3447 -- ["Inactive"] = "r2_mini_activity_inactive.tga"
3450 ---------------------------------------------------------------------------------------------------------
3451 -- Show the mini activity view for this instance
3452 function r2:setupMiniActivityView(instance)
3453 if instance and instance:isKindOf("ActiveLogicEntity") then
3454 local selectedTab = 0
3455 if r2.lastSelectedActivitySequence then
3456 selectedTab = r2.lastSelectedActivitySequence
3458 r2:selectActivitiesSequence(selectedTab)
3459 r2:updateSequencesButtonBar(selectedTab)
3463 ------------------ SELECT ACTIVITY SEQUENCE ---------------------------------------------------------
3464 function r2:selectActivitiesSequence(index)
3465 r2:selectElementsSequence("r2ed_triggers", index)
3466 r2:openAndUpdateMiniActivityView(index)
3469 ------------------ UPDATE SEQUENCES BUTTON BAR ---------------------------------------------------------
3470 function r2:updateSequencesButtonBar(index, sequenceName)
3472 local selectBar = getUI("ui:interface:r2ed_select_bar")
3473 assert(selectBar)
3475 local sequencesButton = selectBar:find("sequences")
3476 assert(sequencesButton)
3478 local activeLogicEntity = r2:getSelectedInstance()
3479 if activeLogicEntity then
3480 if sequenceName==nil and (index >=0) and (index < activeLogicEntity:getBehavior().Activities.Size) then
3481 local activitySequence = activeLogicEntity:getBehavior().Activities[index]
3482 assert(activitySequence)
3483 --sequencesButton.uc_hardtext = activitySequence.Name
3484 sequencesButton.uc_hardtext = r2:getSequenceName(activitySequence)
3485 elseif sequenceName~= nil then
3486 sequencesButton.uc_hardtext = sequenceName
3487 else
3488 sequencesButton.uc_hardtext = i18n.get("uiR2EDSequences")
3494 function r2:newMiniActivitySequence()
3495 return r2:newActivitiesSequence(true)
3498 function r2:openAndUpdateMiniActivityView(index)
3499 r2:openMiniActivityView()
3500 -- update activities list
3502 r2:updateMiniActivityView(index)
3505 function r2:openMiniActivityView()
3506 local triggersUI = getUI("ui:interface:r2ed_triggers")
3507 assert(triggersUI)
3509 local selectedInst = r2:getSelectedInstance()
3511 if selectedInst and not selectedInst:isBotObject() and not selectedInst:isPlant() and not triggersUI.active then
3512 local miniActivityView = getUI("ui:interface:r2ed_mini_activity_view")
3513 assert(miniActivityView)
3514 miniActivityView.active = true
3519 function r2:updateMiniActivityView(index)
3521 local miniActivityView = getUI("ui:interface:r2ed_mini_activity_view")
3522 assert(miniActivityView)
3524 local miniActivities = miniActivityView:find("mini_activities")
3525 assert(miniActivities)
3527 local noActivityLabel = miniActivityView:find("no_activity")
3528 assert(noActivityLabel)
3530 local startCount = 0
3531 local sequence
3532 if index~=nil then
3533 local activities = r2:getSelectedInstance():getBehavior().Activities
3534 if index < activities.Size then
3535 sequence = activities[index]
3537 else
3538 sequence = r2:getSelectedSequInst("r2ed_triggers")
3541 if sequence~=nil then
3543 --label "No activity"
3544 if sequence.Components.Size == 0 then
3545 noActivityLabel.active = true
3546 noActivityLabel.uc_hardtext = tostring(i18n.get("uiR2EdNoActivity"))
3547 else
3548 noActivityLabel.active = false
3551 for i=0, sequence.Components.Size-1 do
3553 local activityInst = sequence.Components[i]
3554 assert(activityInst)
3556 if activityInst then
3558 local activityIndex = i
3559 if afterEltEditor==true then activityIndex = i-1 end
3561 local miniActivity = miniActivities[tostring(activityIndex)]
3562 assert(miniActivity)
3564 miniActivity.active = true
3565 miniActivity.Env.id = activityIndex
3567 -- chat button
3568 local chatButton = miniActivity:find("chat_sequence"):find("button")
3569 assert(chatButton)
3570 if tostring(activityInst.Chat) ~= "" then
3571 local chatTexture = "r2_mini_activity_chat.tga"
3572 chatButton.texture = chatTexture
3573 chatButton.texture_pushed = chatTexture
3574 chatButton.texture_over = chatTexture
3575 else
3576 local chatTexture = "r2_mini_activity_empty_chat.tga"
3577 chatButton.texture = chatTexture
3578 chatButton.texture_pushed = chatTexture
3579 chatButton.texture_over = chatTexture
3580 end
3582 -- activity type button
3583 local activityButton = miniActivity:find("activity"):find("button")
3584 assert(activityButton)
3585 local activityTexture = r2.activityTexture[activityInst.Activity]
3586 if activityTexture then
3587 activityButton.texture = activityTexture
3588 activityButton.texture_pushed = activityTexture
3589 activityButton.texture_over = activityTexture
3592 -- activity type text
3593 local activityText = miniActivity:find("activity_name")
3594 assert(activityText)
3595 activityText.uc_hardtext = activityInst.Activity
3598 startCount = sequence.Components.Size
3599 else
3600 noActivityLabel.active = true
3601 noActivityLabel.uc_hardtext = tostring(i18n.get("uiR2EdNoSequence"))
3604 -- hide remaining mini activity templates
3605 for i=startCount, r2.maxActivities-1 do
3606 local miniActivity = miniActivities[tostring(i)]
3607 assert(miniActivity)
3608 miniActivity.active = false
3613 function r2:closeMiniActivityView()
3614 local miniActivityView = getUI("ui:interface:r2ed_mini_activity_view")
3615 assert(miniActivityView)
3616 miniActivityView.active = false
3619 function r2:openActivitiesSequence()
3621 r2:updateActivitiesAndChatsUI(r2:getSelectedInstance())
3623 local triggersUI = getUI("ui:interface:r2ed_triggers")
3624 assert(triggersUI)
3626 triggersUI.active = true
3627 triggersUI:updateCoords()
3629 if triggersUI.Env.openFirst == nil then
3630 triggersUI:center()
3631 triggersUI.Env.openFirst = true
3634 r2:closeMiniActivityView()
3638 function r2:chooseOrOpenSelectedChatSequence()
3640 r2:updateActivitiesAndChatsUI(r2:getSelectedInstance())
3642 -- init menu
3643 local menuName = "ui:interface:r2ed_chat_sequences_menu"
3644 launchContextMenuInGame(menuName)
3645 local menu = getUI(menuName)
3647 local rootMenu = menu:getRootMenu()
3648 assert(rootMenu)
3649 rootMenu:reset()
3651 -- update menu
3652 local miniActivity = getUICaller().parent.parent.parent
3653 assert(miniActivity)
3655 local miniActivityNb = tonumber(miniActivity.Env.id)
3656 local activitySequence = r2:getSelectedSequInst("r2ed_triggers")
3657 assert(activitySequence)
3658 local activityInst = activitySequence.Components[miniActivityNb]
3660 local chatSequenceId = tostring(activityInst.Chat)
3662 local newLine = 3
3663 --title "Chat sequence"
3664 local chatSequence
3665 if chatSequenceId ~= "" then
3666 chatSequence = r2:getInstanceFromId(chatSequenceId)
3667 assert(chatSequence)
3668 --rootMenu:addLine(ucstring(tostring(i18n.get("uiR2EDChatSequence")).." " .. chatSequence.Name .." : "), "lua", "", "Title")
3669 rootMenu:addLine(ucstring(tostring(i18n.get("uiR2EDChatSequence")).." " .. r2:getSequenceName(chatSequence) .." : "), "lua", "", "Title")
3670 else
3671 rootMenu:addLine(ucstring(tostring(i18n.get("uiR2EDChatSequence")).." : "), "lua", "", "Title")
3674 rootMenu:addSeparator()
3676 -- "Open chat sequence"
3677 if chatSequenceId ~= "" then
3678 --rootMenu:addLine(ucstring(tostring(i18n.get("uiR2EDOpen")).." "..chatSequence.Name), "lua", "r2:openMiniActivityChatSequence("..tostring(miniActivityNb)..")", "Open")
3679 rootMenu:addLine(ucstring(tostring(i18n.get("uiR2EDOpen")).." "..r2:getSequenceName(chatSequence)), "lua", "r2:openMiniActivityChatSequence("..tostring(miniActivityNb)..")", "Open")
3680 newLine = newLine + 1
3683 -- "Any chat sequence"
3684 rootMenu:addLine(ucstring(i18n.get("uiR2EdNoChat")), "lua", "r2:setSequenceChatToMiniActivity("..tostring(miniActivityNb)..")", "None")
3687 -- "new chat sequence"
3688 rootMenu:addLine(ucstring(tostring(i18n.get("uiR2EdNewChat")).."..."), "lua", "r2:newChatsSequenceAndSelect("..tostring(miniActivityNb)..")", "None")
3689 local menuButton = createGroupInstance("r2_menu_button", "", { bitmap = "r2_icon_create.tga", size="14" })
3690 rootMenu:setUserGroupLeft(newLine, menuButton)
3692 rootMenu:addSeparator()
3694 local activeLogicEntity = r2:getSelectedInstance()
3695 assert(activeLogicEntity)
3697 for i=0, activeLogicEntity:getBehavior().ChatSequences.Size-1 do
3698 local sequence = activeLogicEntity:getBehavior().ChatSequences[i]
3699 assert(sequence)
3701 --rootMenu:addLine(ucstring(sequence.Name), "lua", "r2:setSequenceChatToMiniActivity("..tostring(miniActivityNb)..", " .. tostring(i)..")", sequence.InstanceId)
3702 rootMenu:addLine(ucstring(r2:getSequenceName(sequence)), "lua", "r2:setSequenceChatToMiniActivity("..tostring(miniActivityNb)..", " .. tostring(i)..")", sequence.InstanceId)
3705 -- display menu
3706 menu:updateCoords()
3707 local ref = getUICaller()
3708 menu.y = ref.y_real - (menu.h - ref.h_real)
3709 menu.x = ref.x_real
3710 menu:updateCoords()
3713 function r2:openMiniActivityChatSequence(miniActivityNb, chatSequenceId)
3715 local activitySequence = r2:getSelectedSequInst("r2ed_triggers")
3716 assert(activitySequence)
3717 local activityInst = activitySequence.Components[miniActivityNb]
3719 if chatSequenceId == nil then
3720 chatSequenceId = tostring(activityInst.Chat)
3723 r2:openChatSequence(chatSequenceId)
3726 function r2:openChatSequence(chatSequenceId)
3728 if chatSequenceId == nil then
3729 chatSequenceId = r2:getSelectedEltInst("r2ed_triggers").Chat
3732 local chatSequences = getUI("ui:interface:r2ed_chat_sequence")
3733 assert(chatSequences)
3735 local tab = chatSequences:find("sequence_tabs")
3736 assert(tab)
3738 local selectedTab
3739 local sequenceUI
3740 for i=0, tab.tabButtonNb-1 do
3741 sequence = tab:getGroup(i)
3742 assert(sequence)
3743 if sequence.Env.sequenceId == chatSequenceId then
3744 sequenceUI = sequence
3745 selectedTab = i
3746 break
3750 if selectedTab then
3751 tab.selection = selectedTab
3753 local repeatButton = chatSequences:find("repeat_group"):find("repeat"):find("toggle_butt")
3754 assert(repeatButton)
3756 local sequenceInstId = sequenceUI.Env.sequenceId
3757 local sequenceInst = r2:getInstanceFromId(sequenceInstId)
3759 repeatButton.pushed = (sequenceInst.Repeating == 0)
3762 r2:openChatSequences()
3765 function r2:newChatsSequenceAndSelect(miniActivityNb)
3766 local chatSequenceId = r2:newChatsSequence(true)
3768 if chatSequenceName ~= -1 then
3769 r2:setSequenceChatToMiniActivity(miniActivityNb, -1, chatSequenceId)
3770 r2:openMiniActivityChatSequence(miniActivityNb, chatSequenceId)
3774 function r2:setSequenceChatToMiniActivity(miniActivityNb, sequenceNb, chatSequenceId)
3776 local miniActivityView = getUI("ui:interface:r2ed_mini_activity_view")
3777 assert(miniActivityView)
3779 local miniActivities = miniActivityView:find("mini_activities")
3780 assert(miniActivities)
3782 local miniActivity = miniActivities[tostring(miniActivityNb)]
3783 assert(miniActivity)
3785 local activitySequence = r2:getSelectedSequInst("r2ed_triggers")
3786 assert(activitySequence)
3787 local activityInst = activitySequence.Components[miniActivityNb]
3789 local chatTexture
3791 if sequenceNb == nil then
3792 r2:selectChatSequence("None", activityInst.InstanceId)
3793 chatTexture = "r2_mini_activity_empty_chat.tga"
3794 else
3795 local activeLogicEntity = r2:getSelectedInstance()
3796 assert(activeLogicEntity)
3798 if chatSequenceId == nil then
3799 local chatSequence = activeLogicEntity:getBehavior().ChatSequences[tonumber(sequenceNb)]
3800 assert(chatSequence)
3801 chatSequenceId = chatSequence.InstanceId
3804 r2:selectChatSequence(chatSequenceId, activityInst.InstanceId)
3806 chatTexture = "r2_mini_activity_chat.tga"
3809 local chatButton = miniActivity:find("chat_sequence"):find("button")
3810 assert(chatButton)
3811 chatButton.texture = chatTexture
3812 chatButton.texture_pushed = chatTexture
3813 chatButton.texture_over = chatTexture
3816 function r2:openActivity()
3818 r2:updateActivitiesAndChatsUI(r2:getSelectedInstance())
3820 local miniActivity = getUICaller().parent.parent.parent
3821 assert(miniActivity)
3823 local sequenceUI = r2:getSelectedSequ("r2ed_triggers")
3824 assert(sequenceUI)
3826 local activityList = sequenceUI:find("elements_list")
3827 assert(activityList)
3829 local eltEditor = activityList:find("edit_element")
3830 assert(eltEditor)
3831 local indexEltEditor = activityList:getElementIndex(eltEditor)
3833 local activityIndex = miniActivity.Env.id
3834 if indexEltEditor<=activityIndex then activityIndex=activityIndex+1 end
3836 local activityUI = activityList:getChild(activityIndex)
3837 assert(activityUI)
3839 local selectedButtonElt = activityUI:find("select")
3840 assert(selectedButtonElt)
3842 selectedButtonElt.pushed = true
3843 r2:selectTriggerElement(nil, "r2ed_triggers", selectedButtonElt)
3845 r2:updateActivityEditor()
3846 r2:openActivitiesSequence()
3849 function r2:selectSequenceTab(uiName, index)
3851 if uiName == "r2ed_triggers" then
3852 r2:updateSequencesButtonBar(index)
3855 local eltsUI = getUI("ui:interface:"..uiName)
3856 assert(eltsUI)
3858 local sequencesTab = eltsUI:find("sequence_tabs")
3859 assert(sequencesTab)
3861 local repeatButton = eltsUI:find("repeat_group"):find("repeat"):find("toggle_butt")
3862 assert(repeatButton)
3864 local sequenceUI = sequencesTab:getGroup(index)
3865 assert(sequenceUI)
3866 local sequenceInstId = sequenceUI.Env.sequenceId
3868 if sequenceInstId and r2:getInstanceFromId(sequenceInstId) then
3869 local sequenceInst = r2:getInstanceFromId(sequenceInstId)
3870 repeatButton.pushed = (sequenceInst.Repeating == 0)
3876 function r2:getSequenceName(sequenceInst)
3878 local name = sequenceInst.Name
3879 local index = -1
3880 if name == "" then
3881 local components = sequenceInst.Parent
3882 for i=0, components.Size-1 do
3883 if components[i].InstanceId == sequenceInst.InstanceId then
3884 index = i
3885 break
3889 if index >= 0 then
3890 local startName
3891 if sequenceInst:isKindOf("ChatSequence") then
3892 startName = tostring(i18n.get("uiR2EdSequChat"))
3893 elseif sequenceInst:isKindOf("ActivitySequence") then
3894 startName = tostring(i18n.get("uiR2EdSeq"))
3897 name = startName..(index+1)
3901 return name