Merge branch 'fixes' into main/gingo-test
[ryzomcore.git] / ryzom / common / data_common / r2 / r2_mini_activities.lua
blob716b8e74bbfb40d427f36488db683b48b489abce
1 r2.miniActivities = {
4 activityTextures = { ["Follow Route"] = "r2_mini_activity_follow_road.tga",
5 ["Patrol"] = "r2_mini_activity_patrol_road.tga",
6 ["Repeat Road"] = "r2_mini_activity_repeat_road.tga",
7 ["Wander"] = "r2_mini_activity_wander_zone.tga",
8 ["Stand Still"] = "r2_mini_activity_stand_still.tga",
9 ["Rest In Zone"] = "r2_mini_activity_rest_zone.tga",
10 ["Feed In Zone"] = "r2_mini_activity_feed_zone.tga",
11 ["Work In Zone"] = "r2_mini_activity_work_zone.tga",
12 ["Hunt In Zone"] = "r2_mini_activity_hunt_zone.tga",
13 ["Guard Zone"] = "r2_mini_activity_guard_zone.tga",
16 maxActivities = 14,
18 uiId = "ui:interface:r2ed_mini_activity_view",
22 ---------------------------------------------------------------------------------------------------------
23 -- Show the mini activity view for this instance
24 function r2.miniActivities:openEditor()
26 local selectedInstance = r2:getSelectedInstance()
27 if not (selectedInstance:isPlant() or selectedInstance:isBotObject()) then
28 r2.miniActivities:updateMiniActivityView()
29 r2.miniActivities:updateSequenceButtonBar()
31 local miniActivityView = getUI(self.uiId)
32 assert(miniActivityView)
34 miniActivityView.active = true
35 end
36 end
38 ------ CLOSE EDITOR ------------------------------------------------------
39 function r2.miniActivities:closeEditor()
41 local ui = getUI(self.uiId)
42 assert(ui)
43 if ui.active then
44 ui.active = false
45 end
46 end
48 --- UPDATE SEQUENCE BUTTON BAR -------------------------------------------------
49 function r2.miniActivities:updateSequenceButtonBar()
51 local selectBar = getUI("ui:interface:r2ed_select_bar")
52 assert(selectBar)
54 local sequencesButton = selectBar:find("sequences")
55 assert(sequencesButton)
57 local sequenceInst
58 if r2.activities.isInitialized then
59 sequenceInst = r2.activities:currentSequInst()
60 else
61 local logicEntity = r2:getSelectedInstance()
62 if logicEntity== nil then return end
64 if logicEntity:getBehavior().Activities.Size > 0 then
65 sequenceInst = logicEntity:getBehavior().Activities[logicEntity:getSelectedSequenceIndex()]
66 end
67 end
69 local uc_sequ = ucstring()
70 if sequenceInst and sequenceInst.User.Deleted~=true then
71 uc_sequ:fromUtf8(sequenceInst:getName())
72 else
73 uc_sequ = i18n.get("uiR2EDSequences")
74 end
75 sequencesButton.uc_hardtext = uc_sequ
76 end
79 --- UPDATE MINI ACTIVITIES VIEW ----------------------------------------------------
80 function r2.miniActivities:updateMiniActivityView()
82 local miniActivityView = getUI(self.uiId)
83 assert(miniActivityView)
85 local miniActivities = miniActivityView:find("mini_activities")
86 assert(miniActivities)
88 local noActivityLabel = miniActivityView:find("no_activity")
89 assert(noActivityLabel)
91 local startCount = 0
93 local sequenceInst
94 if r2.activities.isInitialized then
95 sequenceInst = r2.activities:currentSequInst()
96 else
97 local logicEntity = r2:getSelectedInstance()
98 if logicEntity == nil then return end
100 if logicEntity:getBehavior().Activities.Size > 0 then
101 sequenceInst = logicEntity:getBehavior().Activities[logicEntity:getSelectedSequenceIndex()]
105 if sequenceInst~=nil and sequenceInst.User.Deleted~=true then
107 local decalErased = 0
109 for i=0, sequenceInst.Components.Size-1 do
111 local activityInst = sequenceInst.Components[i]
112 assert(activityInst)
114 if activityInst then
116 local activityZoneId = activityInst.ActivityZoneId
117 if activityInst.User.Deleted~=true
118 -- this zone just has been deleted
119 and not (activityZoneId~="" and r2:getInstanceFromId(activityZoneId)==nil) then
121 local miniIndex = i - decalErased
123 local miniActivity = miniActivities[tostring(miniIndex)]
124 assert(miniActivity)
126 miniActivity.active = true
127 miniActivity.Env.InstanceId = activityInst.InstanceId
129 -- activity type button
130 local activityButton = miniActivity:find("activity"):find("button")
131 assert(activityButton)
132 local activityTexture = activityInst:getMiniButtonTexture()
133 if activityTexture then
134 activityButton.texture = activityTexture
135 activityButton.texture_pushed = activityTexture
136 activityButton.texture_over = activityTexture
139 -- activity type text
140 local activityText = miniActivity:find("activity_name")
141 assert(activityText)
142 local activityType = activityInst:getVerb()
143 if activityZoneId~="" then
144 local place = r2:getInstanceFromId(activityZoneId)
145 assert(place)
146 activityType = activityType .. " '" .. place.Name .."'"
148 local uc_type = ucstring()
149 uc_type:fromUtf8(activityType)
150 activityText.uc_hardtext = uc_type
151 else
152 decalErased = decalErased+1
156 startCount = sequenceInst.Components.Size - decalErased
158 --label "No activity"
159 if (sequenceInst.Components.Size==0) or (sequenceInst.Components.Size==1 and erasedInstId~=nil)
160 or (startCount == 0) then
161 noActivityLabel.active = true
162 noActivityLabel.uc_hardtext = i18n.get("uiR2EdNoActivity")
163 else
164 noActivityLabel.active = false
167 else
169 noActivityLabel.active = true
170 noActivityLabel.uc_hardtext = i18n.get("uiR2EdNoSequence")
173 -- hide remaining mini activity templates
174 for i=startCount, r2.activities.maxElements-1 do
175 local miniActivity = miniActivities[tostring(i)]
176 assert(miniActivity)
177 miniActivity.active = false
181 -- OPEN ACTIVITIES EDITOR ON SELECTED MINI ACTIVITY -------------------------------
182 function r2.miniActivities:openActivity()
184 r2.activities:openEditor()
186 local miniActivity = getUICaller().parent.parent.parent
187 assert(miniActivity)
189 local sequenceUI = r2.activities:currentSequUI()
190 assert(sequenceUI)
192 local activityList = sequenceUI:find("elements_list")
193 assert(activityList)
195 local activityUI
196 for i=0, activityList.childrenNb-1 do
197 local activity = activityList:getChild(i)
198 assert(activity)
200 if r2.logicUI:getEltUIInstId(activity) == miniActivity.Env.InstanceId then
201 activityUI = activity
202 break
206 if activityUI then
207 local selectedButtonElt = activityUI:find("select")
208 assert(selectedButtonElt)
210 selectedButtonElt.pushed = true
211 r2.activities:selectElement(selectedButtonElt)