Merge branch 'fixes' into main/gingo-test
[ryzomcore.git] / ryzom / common / data_common / r2 / r2_dialogs.lua
blob286cf2a340aca92b6a5cbd3949f1a99030761ddb
1 r2.dialogs = {
3 uiId = "ui:interface:r2ed_dialogs",
4 ownCreatedInstances = {},
5 openFirst = nil,
6 elementsIdCounter = 0,
7 elementOrder = true,
8 fromEmoteIdToName= {},
9 maxAndMin = true,
10 eltTemplateParams = {
11 selectElt="r2.dialogs:selectElement()",
12 openEltEditor="",
13 maxMinElt="r2.dialogs:maximizeMinimizeElement()",
14 removeElt="r2.dialogs:removeElementInst()",
15 colOver="120 150 140 100",
16 colPushed="120 150 140 255",
17 multiMaxLine="3"
19 elementEditorTemplate = "template_edit_chat",
20 elementInitialName=i18n.get("uiR2EdChat"):toUtf8(),
21 sequenceInitialName=i18n.get("uiR2EDDialog"):toUtf8(),
23 keepOpenedEditor = false,
25 currentEltUIID = nil, -- initialisé quand l'editeur est ouvert ou fermé
27 whoToWhoTranslation = {
28 ["_DM"] = i18n.get("uiR2EdDonjonMaster"):toUtf8(),
29 ["_System"] = i18n.get("uiR2EdSystem"):toUtf8(),
30 ["_Nobody"] = i18n.get("uiR2EdNobody"):toUtf8(),
33 maxVisibleLine = 10,
38 -- sequence --------------------------------------------------
39 function r2.dialogs:currentSequUI()
40 return getUI(self.uiId):find("sequence_elts")
41 end
43 function r2.dialogs:currentSequInstId()
44 return self:currentSequUI().Env.InstanceId
45 end
47 -- initialisé quand selection dialog dans menu
48 function r2.dialogs:setSequUIInstId(sequUI, id)
49 sequUI.Env.InstanceId = id
50 end
52 function r2.dialogs:currentSequInst()
53 return r2:getInstanceFromId(self:currentSequInstId())
54 end
56 -- element ---------------------------------------------------
57 function r2.dialogs:currentEltUIId()
58 return self.currentEltUIID
59 end
61 function r2.dialogs:currentEltUI()
62 if self.currentEltUIID then
63 return getUI(self.currentEltUIID)
64 end
65 return nil
66 end
68 function r2.dialogs:setCurrentEltUIId(id)
69 self.currentEltUIID = id
70 end
72 function r2.dialogs:currentEltInstId()
73 if self.currentEltUIID then
74 return self:currentEltUI().Env.InstanceId
75 end
76 return nil
77 end
79 function r2.dialogs:currentEltInst()
80 if self.currentEltUIID and self:currentEltInstId() then
81 return r2:getInstanceFromId(self:currentEltInstId())
82 end
83 return nil
84 end
86 -- updated element and/or sequence (not necessary the same as current sequence or element)
87 function r2.dialogs:updatedSequUI()
88 return self:currentSequUI()
89 end
91 function r2.dialogs:setUpdatedSequUIId(sequUIId)
92 end
94 function r2.dialogs:updatedEltUI()
95 return self:currentEltUI()
96 end
98 function r2.dialogs:setUpdatedEltUIId(eltUIId)
99 end
102 ------------------ INIT DIALOGS EDITOR -------------------------
103 function r2.dialogs:initEditor()
105 local emoteTable = initEmotesMenu("ui:interface:r2ed_triggers_menu", "")
106 for id, name in pairs(emoteTable) do
107 self.fromEmoteIdToName[id] = name
111 ------ OPEN EDITOR ------------------------------------------
113 function r2.dialogs:checkDialog()
115 local dialogUI = getUI(self.uiId)
117 local dialog = r2:getSelectedInstance()
118 if not dialog or not dialog:isKindOf("ChatSequence") then
119 dialogUI.active = false
123 function r2.dialogs:openEditor()
125 local dialogUI = getUI(self.uiId)
127 if not dialogUI.active then
129 self:cleanEditor()
131 local sequenceUI = self:currentSequUI()
132 assert(sequenceUI)
134 -- select selected dialog in scene or first dialog of current act
135 local allDialogs = {}
136 r2:getCurrentAct():appendInstancesByType(allDialogs, "ChatSequence")
137 r2.Scenario:getBaseAct():appendInstancesByType(allDialogs, "ChatSequence")
139 if table.getn(allDialogs) > 0 then
140 sequenceUI.active = true
142 local selectedInstance = r2:getSelectedInstance()
143 if selectedInstance and selectedInstance:isKindOf("ChatSequence") then
144 self:selectSequence(selectedInstance.InstanceId)
145 else
146 local firstDialog
147 for k, dialog in pairs(allDialogs) do
148 firstDialog = dialog
149 break
151 self:selectSequence(firstDialog.InstanceId)
153 else
154 sequenceUI.active = false
155 local dialogName = dialogUI:find("dialogMenu"):find("menu"):find("text")
156 assert(dialogName)
157 dialogName.uc_hardtext = i18n.get("uiR2EdNoSelelection")
160 -- active editor
161 dialogUI.active = true
162 dialogUI:updateCoords()
164 if self.openFirst == nil then
165 self.openFirst = true
166 dialogUI:center()
168 else
169 setTopWindow(dialogUI)
170 dialogUI:blink(1)
174 ------ NEW SEQUENCE ------------------------------------------
176 function r2.dialogs:newSequenceInst(x, y, z)
178 r2.requestNewAction(i18n.get("uiR2EDNewChatSequenceAction"))
179 local dialog = r2.newComponent("ChatSequence")
180 assert(dialog)
182 dialog.Base = r2.Translator.getDebugBase("palette.entities.botobjects.dialog")
183 dialog.Name = r2:genInstanceName(i18n.get("uiR2EDDialog")):toUtf8()
184 dialog.Position.x = x
185 dialog.Position.y = y
186 dialog.Position.z = r2:snapZToGround(x, y)
188 if dialog.onComponentCreated then
189 dialog:onComponentCreated()
192 r2:setCookie(dialog.InstanceId, "DisplayProp", 1)
193 r2.requestInsertNode(r2:getCurrentAct().InstanceId, "Features", -1, "", dialog)
197 ------ CLOSE EDITOR ------------------------------------------
198 function r2.dialogs:closeEditor()
200 self:updateSaysWhat()
202 r2.logicUI:closeEditor(r2.dialogs)
205 ------ CLEAN EDITOR ------------------------------------------
206 function r2.dialogs:cleanEditor()
208 -- reset current dialog and current chat
209 self:setCurrentEltUIId(nil)
210 self:setUpdatedSequUIId(nil)
211 self:setUpdatedEltUIId(nil)
212 self.elementsIdCounter = 0
214 local sequenceUI = self:currentSequUI()
215 assert(sequenceUI)
216 local eltsList = sequenceUI:find("elements_list")
217 assert(eltsList)
218 eltsList:clear()
220 -- hide maximize/minimize
221 local minElts = sequenceUI:find("minimize_elements")
222 assert(minElts)
223 local maxElts = sequenceUI:find("maximize_elements")
224 assert(maxElts)
225 minElts.active = false
226 maxElts.active = false
228 -- hide down/up buttons
229 local upDown = sequenceUI:find("order_group")
230 assert(upDown)
231 upDown.active = false
234 ------ INIT DIALOGS MENU ------------------------------------------
235 function r2.dialogs:initDialogsMenu()
237 local dialogMenu = getUI("ui:interface:r2ed_triggers_menu")
238 assert(dialogMenu)
240 dialogMenu = dialogMenu:getRootMenu()
241 assert(dialogMenu)
243 dialogMenu:reset()
245 local allDialogs = {}
246 r2:getCurrentAct():appendInstancesByType(allDialogs, "ChatSequence")
248 local uc_dialog = ucstring()
249 for k, dialog in pairs(allDialogs) do
250 uc_dialog:fromUtf8(dialog.Name)
251 dialogMenu:addLine(uc_dialog, "lua", "r2:setSelectedInstanceId('" .. dialog.InstanceId .."')", dialog.InstanceId)
254 dialogMenu:setMaxVisibleLine(self.maxVisibleLine)
256 r2.logicUI:openLogicMenu(getUICaller())
259 ------ SELECT ELEMENT --------------------------------------------
260 function r2.dialogs:selectElement(selectedButtonElt)
262 r2.logicComponents:selectElement(self, selectedButtonElt)
264 local sequenceUI = self:currentSequUI()
265 assert(sequenceUI)
267 local editElt = sequenceUI:find("edit_element")
268 assert(editElt)
270 if editElt.active then
271 local editBox = editElt:find("says"):find("edit_box_group")
272 assert(editBox)
273 editBox:setFocusOnText()
277 ------ SELECT SEQUENCE --------------------------------------
278 function r2.dialogs:selectSequence(dialogId)
280 local ui = getUI(self.uiId)
281 assert(ui)
283 -- clean editor
284 self:cleanEditor()
286 self:setSequUIInstId(self:currentSequUI(), dialogId)
287 local sequenceInst = self:currentSequInst()
288 if sequenceInst==nil then return end
290 local sequenceUI = self:currentSequUI()
291 assert(sequenceUI)
293 sequenceUI.active = true
295 -- create dialog editor
296 self:createElementEditor()
298 -- init dialog UI -------------------------
299 -- add elts to sequence
300 local elts = sequenceInst.Components
301 for e = 0, elts.Size - 1 do
302 self:newElementUI(elts[e])
305 -- initialize repeat type
306 local repeatButton = ui:find("repeat"):find("toggle_butt")
307 assert(repeatButton)
308 repeatButton.pushed = (sequenceInst.Repeating == 0)
310 -- dialog editor title
311 local uc_dialog = ucstring()
312 uc_dialog:fromUtf8(i18n.get("uiR2EDChatSequenceEditor"):toUtf8() .. sequenceInst.Name)
313 ui.uc_title = uc_dialog
315 -- dialog name in menu box
316 local dialogName = ui:find("dialogMenu"):find("menu"):find("text")
317 assert(dialogName)
318 uc_dialog:fromUtf8(sequenceInst.Name)
319 dialogName.uc_hardtext = uc_dialog
321 -- initialize maximize/minimize
322 local maxElts = sequenceUI:find("maximize_elements")
323 assert(maxElts)
324 maxElts.active = (elts.Size > 0)
326 r2.logicComponents:selectSequence(r2.dialogs)
329 ------ CREATE EDITOR -----------------------------------------------
330 function r2.dialogs:createElementEditor()
332 r2.logicComponents:createElementEditor(r2.dialogs)
334 -- not necessary current sequence UI
335 local sequenceUI = self:updatedSequUI()
337 local newEditorElt = sequenceUI:find("edit_element")
338 assert(newEditorElt)
340 local editBox = newEditorElt:find("edit_box_group")
341 assert(editBox)
343 local scroll = newEditorElt:find("edit_box_scroll_ed")
344 assert(scroll)
346 scroll:setTarget(editBox.id)
349 ------ OPEN ELEMENT EDITOR -----------------------------------------------
350 function r2.dialogs:updateElementEditor()
352 local instanceChat = self:currentEltInst()
354 local dialogUI = getUI(self.uiId)
355 assert(dialogUI)
357 local sequenceUI = self:currentSequUI()
358 assert(sequenceUI)
360 local chatEditor = sequenceUI:find("edit_element")
361 assert(chatEditor)
363 -- chat name
364 local chatName = chatEditor:find("name")
365 assert(chatName)
367 -- time
368 local minutesText = chatEditor:find("minutes"):find("text")
369 assert(minutesText)
371 local secondsText = chatEditor:find("seconds"):find("text")
372 assert(secondsText)
374 -- update NPC name lists
375 local whoMenuText = chatEditor:find("whoMenu"):find("text")
376 assert(whoMenuText)
378 local toWhoMenuText = chatEditor:find("toWhoMenu"):find("text")
379 assert(toWhoMenuText)
381 local editBox = chatEditor:find("says"):find("edit_box_group")
382 assert(editBox)
384 local emoteButtonText = chatEditor:find("emote"):find("menu"):find("text")
385 assert(emoteButtonText)
387 if instanceChat then
389 local uc_chat = ucstring()
391 local index = r2.logicComponents:searchElementIndex(instanceChat)
392 if index~= nil then
393 uc_chat:fromUtf8(self.elementInitialName.." "..index.." : ")
394 else
395 uc_chat:fromUtf8(self.elementInitialName.." : ")
397 chatName.uc_hardtext = uc_chat
399 -- after value
400 local time = instanceChat.Time
401 assert(time)
402 local minNb, secNb = self:calculMinSec(time)
404 minutesText.uc_hardtext = tostring(minNb)
405 secondsText.uc_hardtext = tostring(secNb)
407 -- who
408 local whoInst = r2:getInstanceFromId(tostring(instanceChat.Actions[0].Who))
409 local hideToWhoAndEmote = false
410 if whoInst then
411 uc_chat:fromUtf8(whoInst.Name)
412 elseif instanceChat.Actions[0].WhoNoEntity=="_System" then
413 uc_chat = i18n.get("uiR2EdSystem")
414 hideToWhoAndEmote = true
415 elseif instanceChat.Actions[0].WhoNoEntity=="_DM" then
416 uc_chat = i18n.get("uiR2EdDonjonMaster")
417 hideToWhoAndEmote = true
418 else
419 uc_chat = ucstring("")
421 whoMenuText.uc_hardtext = uc_chat
423 -- says what
424 editBox:cancelFocusOnText()
425 local textID = instanceChat.Actions[0].Says
426 if textID ~= "" and r2:getInstanceFromId(textID) then
427 local uc_says_what = ucstring()
428 uc_says_what:fromUtf8(r2:getInstanceFromId(textID).Text)
429 editBox.uc_input_string = uc_says_what
430 else
431 editBox.uc_input_string = ""
434 local breakAtEnd = 0
436 if instanceChat.BreakAtEnd then
437 breakAtEnd = instanceChat.BreakAtEnd
439 local breakAtEndButton = chatEditor:find("break_group"):find("toggle_butt")
440 assert(breakAtEndButton)
441 breakAtEndButton.pushed = (breakAtEnd == 0)
443 chatEditor:find("toWhoMenu").active = not hideToWhoAndEmote
444 chatEditor:find("emote").active = not hideToWhoAndEmote
445 if hideToWhoAndEmote then
446 return
449 -- to who
450 local toWhoInst = r2:getInstanceFromId(tostring(instanceChat.Actions[0].Facing))
451 if toWhoInst then
452 uc_chat:fromUtf8(toWhoInst.Name)
453 else
454 uc_chat = i18n.get("uiR2EdNobody")
456 toWhoMenuText.uc_hardtext = uc_chat
458 -- emote
459 local emoteName = self.fromEmoteIdToName[instanceChat.Actions[0].Emote]
460 if emoteName then
461 uc_chat:fromUtf8(emoteName)
462 else
463 uc_chat = i18n.get("uiR2EdNoElt")
465 emoteButtonText.uc_hardtext = uc_chat
467 else
468 local uc_chat = ucstring()
469 uc_chat:fromUtf8(self.elementInitialName.." : ")
470 chatName.uc_hardtext = uc_chat
472 minutesText.uc_hardtext = tostring(0)
473 secondsText.uc_hardtext = tostring(0)
475 whoMenuText.uc_hardtext = ""
477 editBox.uc_input_string = ""
479 toWhoMenuText.uc_hardtext = ""
480 emoteButtonText.uc_hardtext = i18n.get("uiR2EdNoElt")
485 ----- CLOSE ELEMENT EDITOR ---------------------------------------------
486 function r2.dialogs:closeElementEditor()
488 r2.logicComponents:closeElementEditor(r2.dialogs)
491 ------ NEW ELEMENT INST ------------------------------------------
492 function r2.dialogs:newElementInst()
494 r2.requestNewAction(i18n.get("uiR2EDNewChatStepAction"))
496 local chatStep = r2.newComponent("ChatStep")
498 local sequenceInst = self:currentSequInst()
499 assert(sequenceInst)
501 if sequenceInst.Components.Size == 0 then
502 chatStep.Time = 0
503 else
504 chatStep.Time = 3
507 local chatAction = r2.newComponent("ChatAction")
508 chatAction.WhoNoEntity = "_System"
509 table.insert(chatStep.Actions, chatAction)
511 r2.requestInsertNode(sequenceInst.InstanceId, "Components", -1, "", chatStep)
513 self.ownCreatedInstances[chatStep.InstanceId] = true
515 r2.logicComponents:newElementInst(r2.dialogs)
518 ------ NEW ELEMENT UI ------------------------------------------
519 function r2.dialogs:newElementUI(newInst)
520 r2.logicUI:newElementUI(r2.dialogs, newInst, true)
523 ------ REMOVE ELEMENT INST ----------------------------------------
524 function r2.dialogs:removeElementInst()
526 r2.requestNewAction(i18n.get("uiR2EDRemoveLogicElementAction"))
528 local chatStep = self:currentEltInst()
529 assert(chatStep)
530 local says = chatStep.Actions[0].Says
532 r2.logicComponents:removeElementInst(r2.dialogs)
534 r2.unregisterTextFromId(chatStep.Actions[0].Says)
536 r2.requestEndAction()
539 ------ REMOVE ELEMENT UI -------------------------------------------
540 function r2.dialogs:removeElementUI(removedEltUI)
541 r2.logicUI:removeElementUI(r2.dialogs, removedEltUI)
544 ------ REMOVE SEQUENCE UI -------------------------------------------
545 function r2.dialogs:removeSequenceUI(instance)
547 local allDialogs = {}
548 if (not r2:getCurrentAct()) then return end
549 r2:getCurrentAct():appendInstancesByType(allDialogs, "ChatSequence")
550 -- be careful : instance is always in ChatSequences list
551 -- it's not removed yet when onErase is called
552 if table.getn(allDialogs) > 1 then
553 local firstDialog
554 for k, dialog in pairs(allDialogs) do
555 if dialog~=instance then
556 firstDialog = dialog
557 break
560 self:selectSequence(firstDialog.InstanceId)
561 else
562 self.keepOpenedEditor = false
566 ------ UPDATE SEQUENCE UI -------------------------------------------
567 function r2.dialogs:updateSequenceUI(sequenceInst)
569 local ui = getUI(self.uiId)
570 assert(ui)
572 -- initialize repeat type
573 local repeatButton = ui:find("repeat"):find("toggle_butt")
574 assert(repeatButton)
575 repeatButton.pushed = (sequenceInst.Repeating == 0)
577 -- dialog editor title
578 local uc_title = ucstring()
579 uc_title:fromUtf8(i18n.get("uiR2EDChatSequenceEditor"):toUtf8() .. sequenceInst.Name)
580 ui.uc_title = uc_title
582 -- dialog name in menu box
583 local dialogName = ui:find("dialogMenu"):find("menu"):find("text")
584 assert(dialogName)
585 dialogName.uc_hardtext = sequenceInst.Name
588 ------ UP ELEMENT INST -------------------------------------------
589 function r2.dialogs:upElementInst()
590 r2.logicComponents:upElementInst(r2.dialogs)
593 ------ DOWN ELEMENT INST -----------------------------------------
594 function r2.dialogs:downElementInst()
595 r2.logicComponents:downElementInst(r2.dialogs)
598 ------ MAX/MIN ELEMENTS UI -------------------------------------------
599 function r2.dialogs:maximizeMinimizeElements()
600 r2.logicUI:maximizeMinimizeElements(r2.dialogs)
603 ------ MAX/MIN ELEMENT UI -------------------------------------------
604 function r2.dialogs:maximizeMinimizeElement(element, allMinimize)
606 r2.logicUI:maximizeMinimizeElement(element, allMinimize)
609 ------ DOWN/UP ELEMENT UI -------------------------------------------
610 function r2.dialogs:downUpElementUI(elementUI, instance)
611 r2.logicUI:downUpElementUI(r2.dialogs, elementUI, instance)
614 ------ UPDATE ELEMENT TITLE -------------------------------------------
615 function r2.dialogs:updateElementTitle(chatUI)
616 r2.logicComponents:updateElementTitle(r2.dialogs, chatUI, true)
619 ------ UPDATE CHAT TEXT -------------------------------------------
620 function r2.dialogs:updateElementUI(elementUI)
622 local chatStep = r2:getInstanceFromId(r2.logicUI:getEltUIInstId(elementUI))
623 assert(chatStep)
625 local chatText = elementUI:find("text_list")
626 assert(chatText)
627 chatText:clear()
629 local who = tostring(chatStep.Actions[0].Who)
630 if who=="" then who=chatStep.Actions[0].WhoNoEntity end
631 if who and who ~= "" then
633 local text = ""
634 local textEmpty = true
636 local says = chatStep.Actions[0].Says
638 if r2:getInstanceFromId(says)~=nil and r2:getInstanceFromId(says).Text ~= "" then
639 text = "\n" .. r2:getInstanceFromId(says).Text
640 textEmpty = false
642 --text = text.."\n"
644 -- Add a white line that indicate that the dialog pause at end (ChatStep) in reduced view
645 chatText:addColoredTextChild(text, 220, 140, 100, 255)
646 if chatStep.BreakAtEnd and chatStep.BreakAtEnd == 1 then
647 chatText:addColoredTextChild("\n"..i18n.get("uiR2EDThenPause"):toUtf8(), 255, 255, 255, 255)
650 local sep = elementUI:find("sep")
651 assert(sep)
652 if textEmpty == false then
653 sep.active = true
654 else
655 chatText:clear()
656 sep.active = false
660 r2.logicUI:updateElementUI(r2.dialogs, elementUI)
663 -------------------- INIT TIME MENU --------------------------------
664 function r2.dialogs:initTimeMenu(timeFunction, isHours)
666 local timeMenu = getUI("ui:interface:r2ed_triggers_menu")
667 assert(timeMenu)
669 local timeMenu = timeMenu:getRootMenu()
670 assert(timeMenu)
672 timeMenu:reset()
674 for i=0,9 do
675 timeMenu:addLine(ucstring(tostring(i)), "lua", timeFunction .. "(" .. tostring(i) .. ")", tostring(i))
678 if isHours then
679 timeMenu:addLine(ucstring(tostring(10)), "lua", timeFunction .. "(" .. tostring(10) .. ")", tostring(10))
680 else
682 local lineNb = 9
683 for i=10, 50, 10 do
684 local lineStr = tostring(i).."/"..tostring(i+9)
685 timeMenu:addLine(ucstring(lineStr), "", "", tostring(i))
686 lineNb = lineNb+1
688 timeMenu:addSubMenu(lineNb)
689 local subMenu = timeMenu:getSubMenu(lineNb)
691 for s=0,9 do
692 lineStr = tostring(i+s)
693 subMenu:addLine(ucstring(lineStr), "lua", timeFunction .. "(" .. tostring(i+s) .. ")", lineStr)
696 timeMenu:setMaxVisibleLine(self.maxVisibleLine)
700 timeMenu:setMaxVisibleLine(self.maxVisibleLine)
702 r2.logicUI:openLogicMenu(getUICaller())
705 ----- CHAT MINUTES -----------------------------------------------------------------
706 function r2.dialogs:chatAfterMinutes(minNb)
708 -- recover "says what" (equiv change focus)
709 self:updateSaysWhat()
711 local chatStep = self:currentEltInst()
712 assert(chatStep)
714 local hours, mins, secs = r2.logicComponents:calculHourMinSec(chatStep.Time)
715 self:setTime(minNb*60 + secs)
718 -------------------- CHAT SECONDS -----------------------------------------------------------------
719 function r2.dialogs:chatAfterSeconds(secNb)
721 -- recover "says what" (equiv change focus)
722 self:updateSaysWhat()
724 local chatStep = self:currentEltInst()
725 assert(chatStep)
727 local hours, mins, secs = r2.logicComponents:calculHourMinSec(chatStep.Time)
728 self:setTime(mins*60 + secNb)
731 ---- SET TIME --------------------------------------------------------------------
732 function r2.dialogs:setTime(secNb)
734 r2.requestNewAction(i18n.get("uiR2EDSetDialogTime"))
736 local chatStepId = self:currentEltInstId()
737 assert(chatStepId)
739 r2.requestSetNode(chatStepId, "Time", secNb)
742 ---- SET BREAK AT END OF CHATSTEP --------------------------------------------------------------------
743 function r2.dialogs:setChatBreak()
744 self:updateSaysWhat()
745 local mustBreak = 0
746 if getUICaller().pushed==false then mustBreak = 1 end
748 r2.requestNewAction(i18n.get("uiR2EDSetDialogChatBreak"))
750 local chatStepId = self:currentEltInstId()
751 assert(chatStepId)
752 r2.requestSetNode(chatStepId, "BreakAtEnd", mustBreak)
755 ------- INIT ENTITIES MENU -----------------------------------------
756 function r2.dialogs:initWhoMenu(whoFunction, towho)
758 local menuName = "ui:interface:r2ed_triggers_menu"
760 local whoMenu = getUI(menuName)
761 local whoMenu = whoMenu:getRootMenu()
762 assert(whoMenu)
764 whoMenu:reset()
766 local npcTable = r2.Scenario:getAllInstancesByType("Npc")
768 if towho == true then
769 whoMenu:addLine(i18n.get("uiR2EdNobody"), "lua", whoFunction.."('" ..i18n.get("uiR2EdNobody"):toUtf8().. "')", "Nobody")
770 else
771 whoMenu:addLine(i18n.get("uiR2EdSystem"), "lua", whoFunction.."('_System')", "System")
772 whoMenu:addLine(i18n.get("uiR2EdDonjonMaster"), "lua", whoFunction.."('_DM')", "DonjonMaster")
775 local uc_who = ucstring()
776 for key, npc in pairs(npcTable) do
777 local addLine = true
779 if not npc:isBotObject() and not npc:isPlant() and not r2.isCreature(npc.InstanceId) then
780 if towho == true then
781 local chatStepInst= self:currentEltInst()
782 assert(chatStepInst)
784 local whoId = chatStepInst.Actions[0].Who
785 if whoId~="" and whoId == npc.InstanceId then
786 addLine = false
789 if addLine then
790 uc_who:fromUtf8(npc.Name)
791 whoMenu:addLine(uc_who, "lua", whoFunction.."('" ..npc.InstanceId.. "')", npc.InstanceId)
796 whoMenu:setMaxVisibleLine(self.maxVisibleLine)
798 r2.logicUI:openLogicMenu(getUICaller())
801 ---- UPDATE SAYS WHAT -----------------------------------------------------------------
802 function r2.dialogs:updateSaysWhat()
804 -- recover "says what" (equiv change focus)
805 local sequenceUI = self:currentSequUI()
806 if sequenceUI then
807 local chatEditor = sequenceUI:find("edit_element")
808 if chatEditor then
809 local saysWhat = chatEditor:find("says"):find("edit_box_group").uc_input_string:toUtf8()
810 self:setSaysWhat(saysWhat)
815 ---- SET WHO --------------------------------------------------------------------------
816 function r2.dialogs:setWho(who)
818 -- recover "says what" (equiv change focus)
819 self:updateSaysWhat()
821 r2.requestNewAction(i18n.get("uiR2EDChatSetWhoAction"))
823 local chatStep = self:currentEltInst()
824 assert(chatStep)
826 if r2:getInstanceFromId(who) then
827 r2.requestSetNode(chatStep.Actions[0].InstanceId, "Who", r2.RefId(who))
828 r2.requestSetNode(chatStep.Actions[0].InstanceId, "WhoNoEntity", "")
830 if who == chatStep.Actions[0].Facing then
831 self:setToWho(i18n.get("uiR2EdNobody"):toUtf8())
833 else
834 r2.requestSetNode(chatStep.Actions[0].InstanceId, "Who", r2.RefId(""))
835 r2.requestSetNode(chatStep.Actions[0].InstanceId, "WhoNoEntity", who)
837 r2.requestSetNode(chatStep.Actions[0].InstanceId, "Facing", r2.RefId(""))
841 ----- SET TO WHO -----------------------------------------------------------------------
842 function r2.dialogs:setToWho(toWho)
844 -- recover "says what" (equiv change focus)
845 self:updateSaysWhat()
847 r2.requestNewAction(i18n.get("uiR2EDChatSetToWhoAction"))
849 local chatStep = self:currentEltInst()
850 assert(chatStep)
852 if toWho == i18n.get("uiR2EdNobody"):toUtf8() then toWho="" end
853 r2.requestSetNode(chatStep.Actions[0].InstanceId, "Facing", r2.RefId(toWho))
856 -------------------- SAYS WHAT -------------------------------------------
857 function r2.dialogs:setSaysWhat(whatText)
859 if whatText == nil then
860 whatText = getUICaller().uc_input_string:toUtf8()
863 r2.requestNewAction(i18n.get("uiR2EDChatSetSayWhatAction"))
865 local chatStep = self:currentEltInst()
866 if chatStep ~= nil then
867 local oldSays = r2:getInstanceFromId(chatStep.Actions[0].Says)
868 if (oldSays==nil and whatText~="") or (oldSays~=nil and oldSays.Text~=whatText) then
870 r2.unregisterTextFromId(chatStep.Actions[0].Says)
871 local whatId=r2.registerText(whatText).InstanceId
872 r2.requestSetNode(chatStep.Actions[0].InstanceId, "Says", whatId)
876 r2.requestEndAction()
879 ----- INIT EMOTE MENU ---------------------------------------------------
880 function r2.dialogs:initEmoteMenu()
882 local menuName = "ui:interface:r2ed_triggers_menu"
884 local emoteMenu = getUI(menuName)
885 local emoteMenu = emoteMenu:getRootMenu()
886 assert(emoteMenu)
888 emoteMenu:reset()
889 initEmotesMenu(menuName, "r2.dialogs:setEmote")
890 r2.logicUI:openLogicMenu(getUICaller())
893 ----- SET EMOTE -------------------------------------------------------
894 function r2.dialogs:setEmote(emoteId)
896 -- recover "says what" (equiv change focus)
897 self:updateSaysWhat()
899 r2.requestNewAction(i18n.get("uiR2EDChatSetEmoteAction"))
901 local chatStep = self:currentEltInst()
902 assert(chatStep)
904 r2.requestSetNode(chatStep.Actions[0].InstanceId, "Emote", emoteId)
907 ------ REPEAT SEQUENCE -------------------------------------------
908 function r2.dialogs:repeatSequence()
910 r2.requestNewAction(i18n.get("uiR2EDChatRepeatSequenceAction"))
912 local dialogInst = self:currentSequInst()
913 if dialogInst==nil then return end
915 local sequenceType = 1
916 if getUICaller().pushed==true then sequenceType = 0 end
918 r2.requestSetNode(dialogInst.InstanceId, "Repeating", sequenceType)
921 ------- UTIL ---------------------------------------------------
922 function r2.dialogs:calculMinSec(totalSecNb)
924 assert(totalSecNb)
925 local minNb, secNb = 0, totalSecNb
926 while secNb > 59 do
927 minNb = minNb+1
928 secNb = secNb - 60
931 return minNb, secNb
940 --------------------------------------------------------------------------------------------------
941 -------------------------------- CHAT STEP DisplayerProperties------------------------------------
942 --------------------------------------------------------------------------------------------------
943 local chatStepPropertySheetDisplayerTable = clone(r2:propertySheetDisplayer())
945 ------------------------------------------------
946 function chatStepPropertySheetDisplayerTable:onPostCreate(instance)
948 if instance.Parent.Parent.InstanceId == r2.dialogs:currentSequInstId() then
949 r2.dialogs:newElementUI(instance)
950 end
952 ------------------------------------------------
953 function chatStepPropertySheetDisplayerTable:onErase(instance)
955 instance.User.Deleted = true
957 local elementUI = r2.logicUI:findElementUIFromInstance(r2.dialogs, instance)
959 if elementUI then
960 r2.dialogs:removeElementUI(elementUI)
963 ------------------------------------------------
964 function chatStepPropertySheetDisplayerTable:onPreHrcMove(instance)
966 ------------------------------------------------
967 function chatStepPropertySheetDisplayerTable:onPostHrcMove(instance)
969 local elementUI = r2.logicUI:findElementUIFromInstance(r2.dialogs, instance)
970 if elementUI then
971 r2.dialogs:downUpElementUI(elementUI, instance)
974 ------------------------------------------------
975 function chatStepPropertySheetDisplayerTable:onFocus(instance, hasFocus)
978 ------------------------------------------------
979 function chatStepPropertySheetDisplayerTable:onSelect(instance, isSelected)
982 ------------------------------------------------
983 function chatStepPropertySheetDisplayerTable:onAttrModified(instance, attributeName)
985 local elementUI = r2.logicUI:findElementUIFromInstance(r2.dialogs, instance)
986 if elementUI then
987 r2.dialogs:updateElementUI(elementUI)
989 end
991 --------------------------------------------------
992 function r2:chatStepPropertySheetDisplayer()
993 return chatStepPropertySheetDisplayerTable
998 --------------------------------------------------------------------------------------------------
999 -------------------------------- CHAT SEQUENCE DisplayerProperties ---------------------------
1000 --------------------------------------------------------------------------------------------------
1001 local chatSequencePropertySheetDisplayerTable = clone(r2:propertySheetDisplayer())
1003 ------------------------------------------------
1004 function chatSequencePropertySheetDisplayerTable:onPostCreate(instance)
1006 ------------------------------------------------
1007 function chatSequencePropertySheetDisplayerTable:onErase(instance)
1009 instance.User.Deleted = true
1011 local currentDialogId = r2.dialogs:currentSequInstId()
1012 if currentDialogId ~= instance.InstanceId then return end
1014 r2.dialogs:removeSequenceUI(instance)
1016 ------------------------------------------------
1017 function chatSequencePropertySheetDisplayerTable:onPreHrcMove(instance)
1019 ------------------------------------------------
1020 function chatSequencePropertySheetDisplayerTable:onPostHrcMove(instance)
1022 ------------------------------------------------
1023 function chatSequencePropertySheetDisplayerTable:onFocus(instance, hasFocus)
1026 ------------------------------------------------
1027 r2.dialogEditorRemainsOpened = false
1028 function chatSequencePropertySheetDisplayerTable:onSelect(instance, isSelected)
1030 r2:logicEntityPropertySheetDisplayer():onSelect(instance, isSelected)
1032 local dialogUI = getUI(r2.dialogs.uiId)
1033 assert(dialogUI)
1035 if not isSelected then
1036 r2.dialogs.keepOpenedEditor = dialogUI.active
1037 dialogUI.active = false
1039 elseif isSelected and r2.dialogs.keepOpenedEditor==true then
1040 r2.dialogs.keepOpenedEditor = false
1041 dialogUI.active = true
1042 r2.dialogs:selectSequence(instance.InstanceId)
1046 ------------------------------------------------
1047 function chatSequencePropertySheetDisplayerTable:onAttrModified(instance, attributeName)
1049 if attributeName == "Name" or attributeName == "Repeating" then
1051 local currentDialogId = r2.dialogs:currentSequInstId()
1052 if currentDialogId == instance.InstanceId then
1053 r2.dialogs:updateSequenceUI(instance)
1056 if r2.events.filteredLogicEntityId==instance.InstanceId then
1057 r2.events:updateSequenceUI()
1059 end
1060 end
1062 ------------------------------------------------
1063 function r2:chatSequencePropertySheetDisplayer()
1064 return chatSequencePropertySheetDisplayerTable -- returned shared displayer to avoid wasting memory
1069 --------------------------------------------------------------------------------------------------
1070 -------------------------------- CHAT ACTION DisplayerProperties -----------------------
1071 --------------------------------------------------------------------------------------------------
1072 local chatActionPropertySheetDisplayerTable = clone(r2:propertySheetDisplayer())
1074 ------------------------------------------------
1075 function chatActionPropertySheetDisplayerTable:onPostCreate(instance)
1077 ------------------------------------------------
1078 function chatActionPropertySheetDisplayerTable:onErase(instance)
1080 ------------------------------------------------
1081 function chatActionPropertySheetDisplayerTable:onPreHrcMove(instance)
1083 ------------------------------------------------
1084 function chatActionPropertySheetDisplayerTable:onPostHrcMove(instance)
1086 ------------------------------------------------
1087 function chatActionPropertySheetDisplayerTable:onFocus(instance, hasFocus)
1090 ------------------------------------------------
1091 function chatActionPropertySheetDisplayerTable:onSelect(instance, isSelected)
1094 ------------------------------------------------
1095 function chatActionPropertySheetDisplayerTable:onAttrModified(instance, attributeName)
1096 end
1098 ------------------------------------------------
1099 function chatActionPropertySheetDisplayerTable:onTargetInstanceEraseRequested(instance, refIdName, refIdIndexInArray)
1100 if refIdName == "Who" then
1101 r2.requestSetNode(instance.InstanceId, "Who", r2.RefId(""))
1102 r2.requestSetNode(instance.InstanceId, "WhoNoEntity", "_System")
1103 elseif refIdName == "Facing" then
1104 r2.requestSetNode(instance.InstanceId, "Facing", r2.RefId(""))
1107 ------------------------------------------------
1108 function chatActionPropertySheetDisplayerTable:onTargetInstanceAttrModified(instance, refIdName, refIdIndexInArray, targetAttrName, targetAttrIndexInArray)
1111 ------------------------------------------------
1112 function r2:chatActionPropertySheetDisplayer()
1113 return chatActionPropertySheetDisplayerTable -- returned shared displayer to avoid wasting memory