Merge branch 'fixes' into main/gingo-test
[ryzomcore.git] / ryzom / common / data_common / r2 / r2_ui_acts.lua
blob51b7675dfa2e2987467fb691c3fce28e33e23498
1 r2.acts = {
3 newLocation = "new location",
4 enlargingFactor = 2,
5 islands = {},
6 ecoSystemName = "r2_desert",
7 islandButtonColors =
9 ["r2_desert"] = "157 110 74 255",
10 ["r2_jungle"] = "47 110 54 255",
11 ["r2_forest"] = "74 52 0 255",
12 ["r2_lakes"] = "95 93 67 255",
13 ["r2_roots"] = "66 52 41 255",
16 islandSelectedButtonColors =
18 ["r2_desert"] = "152 60 39",
19 ["r2_jungle"] = "18 156 51",
20 ["r2_forest"] = "133 36 13",
21 ["r2_lakes"] = "109 149 106",
22 ["r2_roots"] = "73 148 122",
25 islandOverButtonColors =
27 ["r2_desert"] = "127 48 33",
28 ["r2_jungle"] = "0 51 20",
29 ["r2_forest"] = "90 28 0",
30 ["r2_lakes"] = "55 53 37",
31 ["r2_roots"] = "36 22 11",
34 ecosystemNames =
36 ["r2_desert"] = i18n.get("uiR2EDEcosystemDesert"):toUtf8(),
37 ["r2_jungle"] = i18n.get("uiR2EDEcosystemJungle"):toUtf8(),
38 ["r2_forest"] = i18n.get("uiR2EDEcosystemForest"):toUtf8(),
39 ["r2_lakes"] = i18n.get("uiR2EDEcosystemLacustre"):toUtf8(),
40 ["r2_roots"] = i18n.get("uiR2EDEcosystemPrimeRoots"):toUtf8(),
43 selectedIslandButtonId = nil,
44 selectedIslandName = nil,
46 createNewScenario = true,
47 deleteOldScenario = false,
48 createNewLocation = true,
50 currentScenario =
52 name="",
53 level = 0,
54 rules = "strict",
55 notes = ""
58 currentAct =
60 name="",
61 weather = 0,
62 manualWeather = true,
63 notes = "",
66 currentLocation =
68 name="",
69 islandName = "",
70 instanceId = "",
71 season = "spring",
72 manualSeason = true,
73 notes = "",
74 entryPoint = "",
78 -------------------------- to sort islands in function of their translated name -----------
79 function r2.acts:getIslandNb(islandName)
81 local islandTrans = i18n.get(islandName):toUtf8()
82 local islandNb = string.sub(islandTrans, -5)
83 local endLen = 6
84 if string.sub(islandNb, 1, 1) ~= " " then
85 islandNb = string.sub(islandNb, 3)
86 endLen = endLen-1
87 else
88 islandNb = string.sub(islandNb, 2)
89 end
91 -- outland test
92 local outland = string.sub(islandTrans, 1, -endLen)
93 outland = string.sub(outland, -7)
94 if outland=="Outland" then return nil end
96 islandNb = string.sub(islandNb, 1, -2)
97 return tonumber(islandNb)
98 end
100 --------------------------------------------------------------------------------------
101 --------------------------- init location editor -------------------------------------
102 function r2.acts:initActsEditor()
104 -- create scenario/act window
105 local actsUI = getUI("ui:interface:r2ed_acts")
106 assert(actsUI)
108 self.islands = {}
109 local islands = getCompleteIslands()
111 for islandName, islandAtts in pairs(islands) do
112 local ecoSystemName = islandAtts.continent
113 if self.islands[ecoSystemName] == nil then
114 self.islands[ecoSystemName] = {}
117 local islandNb = self:getIslandNb(islandName)
118 if islandNb then
119 self.islands[ecoSystemName][islandNb] = {["name"] =islandName, ["table"] = islandAtts}
123 local ecoList = actsUI:find("ecosystem_list_2")
124 assert(ecoList)
125 ecoList:clear()
127 local ecoButtonsGr = actsUI:find("choose_ecosystem")
128 assert(ecoButtonsGr)
130 local buttonDim = 78
131 local maxWLine = actsUI:find("choose_island_2"):find("back_gr").w_real - 1
132 local nbButtonsInLine = math.floor(maxWLine/(buttonDim+2))
133 local addW = math.floor((maxWLine - buttonDim*nbButtonsInLine)/nbButtonsInLine)
135 -- for each ecosystem group, create all islands buttons
136 for ecoSysName, ecoSysTable in pairs(self.islands) do
138 local ecoGr = createGroupInstance("template_lines", ecoList.id, {id=ecoSysName})
139 assert(ecoGr)
140 ecoList:addChild(ecoGr)
141 ecoGr.active = false
143 local maxPackage = 0
144 local islandsNb = 0
145 for k, v in pairs(ecoSysTable) do
146 local package = r2.getIslandRingAccess(v.name)
147 if r2.RingAccess.testAccess(package) then
148 local package = tonumber(string.sub(package, 2, 2))
149 if package>maxPackage then maxPackage = package end
150 islandsNb=islandsNb+1
153 local nbLines = math.ceil(islandsNb/nbButtonsInLine)
155 local ecoButton = ecoButtonsGr:find(ecoSysName):find("eco_button")
156 assert(ecoButton)
158 local uc_package = ucstring()
159 uc_package:fromUtf8(i18n.get("uiR2EDEcosystemPackage"):toUtf8().." : "..maxPackage)
160 ecoButton.tooltip = uc_package
162 for i=0, nbLines-1 do
163 local lineGr = createGroupInstance("template_line", ecoGr.id, {id="line"..i, h=buttonDim})
164 assert(lineGr)
165 ecoGr:addChild(lineGr)
166 end
168 if ecoGr.childrenNb >0 then
169 local currentLine = ecoGr:getChild(0)
170 assert(currentLine)
172 local currentEltInLine = 0
173 local currentLineNb = 0
175 for islandNb, islandAttrs in pairs(ecoSysTable) do
177 local islandName = islandAttrs.name
178 local islandTable = islandAttrs.table
180 local textureName = islandName.."_sp_little.tga"
181 local ringAccess = r2.RingAccess.testAccess( r2.getIslandRingAccess(islandName) )
182 if fileExists(textureName) and ringAccess then
184 local tooltip = islandName
186 local islandW = islandTable.xmax - islandTable.xmin
187 local islandH = islandTable.ymax - islandTable.ymin
188 local maxDim = math.max(islandW, islandH)
189 local ratio = 64/maxDim
190 local width = math.floor(islandW*ratio)
191 local height = math.floor(islandH*ratio)
193 local maxDim = buttonDim - 20 -- buttonDim - 2*(8+2)
194 local w_button_texture
195 local h_button_texture
196 local x_button_texture
197 local y_button_texture
198 local scale = "false"
200 scale, w_button_texture, h_button_texture, width, height =
201 self:textureRedimension(textureName, maxDim, maxDim, width, height)
203 scale = tostring(scale)
205 -- center button island
206 x_button_texture =((maxDim-width)/2 + 10) -- (8 + (maxDim-width)/2 + 2)
207 y_button_texture =-((maxDim-height)/2 + 10) -- (-((maxDim-height)/2 + 8 + 2))
209 local tmplParams =
211 id=islandName,
212 posparent="parent",
213 posref="TL TL",
214 sizeref= "",
215 h = buttonDim+2,
216 w = buttonDim+addW,
218 x_button="0",
219 y_button="0",
220 w_button = -addW,
221 h_button = "-2",
223 icon = textureName,
224 tooltip = tooltip,
225 w_button_texture = w_button_texture,
226 h_button_texture = h_button_texture,
227 x_button_texture = x_button_texture,
228 y_button_texture = y_button_texture,
229 scale = scale,
230 color= self.islandButtonColors[ecoSysName],
231 back_color= self.islandButtonColors[ecoSysName],
232 selected_color = self.islandSelectedButtonColors[ecoSysName].." 255",
233 col_over = self.islandOverButtonColors[ecoSysName].." 80",
234 group_params_l="r2.acts:openIslandCardFromButton('"..ecoSysName.."', '" ..islandName.."')",
235 params_l="r2.acts:openIslandCardFromButton('"..ecoSysName.."', '" ..islandName.."')",
237 local buttonIsland = createGroupInstance("act_button_template", currentLine.id, tmplParams)
239 if buttonIsland then
240 currentLine:addChild(buttonIsland)
241 buttonIsland.Env.Name = islandName
244 currentEltInLine = currentEltInLine+1
245 if currentEltInLine==nbButtonsInLine then
246 currentLineNb = currentLineNb+1
247 if currentLineNb < ecoGr.childrenNb then
248 currentLine = ecoGr:getChild(currentLineNb)
250 currentEltInLine = 0
257 local newLocationMode = actsUI:find("new_location_mode_2")
258 assert(newLocationMode)
259 newLocationMode.Env.Name = self.newLocation
261 local ringLevel = actsUI:find("ring_level")
262 ringLevel.hardtext = "Ring level : " .. r2.getCharacterRingAccess()
265 --------------------------------------------------------------------------------------
266 --------------------------- open scenario editor -------------------------------------
267 function r2.acts:openScenarioActEditor(newScenario, noCancelOption, rebuildFirstAct)
269 setKeyboardContext("r2ed_scenario_creation")
271 local actsUI = getUI("ui:interface:r2ed_acts")
272 assert(actsUI)
274 local locationEditor = actsUI:find("location")
275 assert(locationEditor)
277 local prevLocationEditor = actsUI:find("previous_location")
278 assert(prevLocationEditor)
280 actsUI.active = true
281 setTopWindow(actsUI)
283 self.createNewScenario = newScenario
284 locationEditor.active = (newScenario==true or rebuildFirstAct==true)
285 prevLocationEditor.active = not locationEditor.active
286 self.createNewLocation = true
288 local islandCancel = actsUI:find("island_cancel")
289 assert(islandCancel)
290 islandCancel.active = (noCancelOption~=true)
292 local islandPrecedent = actsUI:find("island_precedent")
293 assert(islandPrecedent)
294 islandPrecedent.active = (self.createNewScenario~=true and rebuildFirstAct~=true)
296 -----------------------------------------
297 -- init scenario/act/location properties
298 self.currentScenario.level = 0
299 self.currentScenario.rules = "strict"
301 self.currentAct.weather = math.random(0,1022)
302 self.currentAct.manualWeather = true
303 self.currentLocation.manualSeason = true
305 local seasonNb = math.random(1,4)
306 local seasons = {[1]="Spring", [2]="Summer", [3]="Autumn", [4]="Winter"}
307 self.currentLocation.season = seasons[seasonNb]
309 -- location season
310 local seasonGr = actsUI:find("island_season")
311 assert(seasonGr)
312 local seasonButton = seasonGr:find(self.currentLocation.season)
313 assert(seasonButton)
314 self:selectButtonTemplate(seasonButton)
316 local seasonManual = seasonGr:find("manual_season_2")
317 assert(seasonManual)
318 seasonManual:find("toggle_butt").pushed = not self.currentLocation.manualSeason
320 -- act and scenario names
321 if self.createNewScenario or rebuildFirstAct then
322 self.currentAct.name = i18n.get("uiR2EDDefaultActTitle"):toUtf8() .. " 1"
323 else
324 local actNb = r2.Scenario.Acts.Size
325 self.currentAct.name = i18n.get("uiR2EDDefaultActTitle"):toUtf8() .. " " .. actNb
328 if self.createNewScenario == true then
329 self.currentScenario.name = i18n.get("uiR2EDNewScenario"):toUtf8()
330 else
331 r2.ScenarioWindow:setActNotes()
333 -- select "new island" mode
334 local newLocationMode = actsUI:find("new_location_mode_2")
335 assert(newLocationMode)
336 newLocationMode:find("button").active = false
337 newLocationMode:find("selected_button").active = true
338 self.currentLocation.islandName = ""
339 self.currentLocation.instanceId = ""
341 -- clean list of old previous locations
342 local locationList = actsUI:find("location_list")
343 assert(locationList)
344 locationList:clear()
346 self:openPreviousIslandsActs()
348 local scrollPreviousLoc = actsUI:find("scroll_previous_islands")
349 assert(scrollPreviousLoc)
350 scrollPreviousLoc.trackPos = scrollPreviousLoc.h_real
353 self:openEcosystemIslands("r2_desert")
356 function r2.acts:backPreviousLocations()
358 local actsUI = getUI("ui:interface:r2ed_acts")
359 assert(actsUI)
361 local newLocationMode = actsUI:find("new_location_mode_2")
362 assert(newLocationMode)
364 self:locationIsland(newLocationMode:find("button"))
366 local locationEditor = actsUI:find("location")
367 assert(locationEditor)
369 local prevLocationEditor = actsUI:find("previous_location")
370 assert(prevLocationEditor)
372 locationEditor.active = false
373 prevLocationEditor.active = true
376 -------------------------------------------------------------------------------------------------------
377 function r2.acts:openPreviousIslandsActs()
379 local actsUI = getUI("ui:interface:r2ed_acts")
380 assert(actsUI)
382 local locationList = actsUI:find("location_list")
383 assert(locationList)
385 local enlargingFactor = self.enlargingFactor
387 local locationActs = {}
388 for key, act in specPairs(r2.Scenario.Acts) do
389 local locationId = act.LocationId
390 if locationActs[locationId]==nil then locationActs[locationId]={} end
391 table.insert(locationActs[locationId], act.InstanceId)
394 for key, location in specPairs(r2.Scenario.Locations) do
396 local islandName = location.IslandName
398 local textureName = islandName .. "_sp.tga"
400 local actsUI = getUI("ui:interface:r2ed_acts")
401 assert(actsUI)
403 local islandTable
404 local ecoSysName = nil
405 for ecoSystem, ecoSysTable in pairs(self.islands) do
406 local islandNb = self:getIslandNb(islandName)
407 if ecoSysTable[islandNb] and ecoSysTable[islandNb].name == islandName then
408 ecoSysName = ecoSystem
409 islandTable = ecoSysTable[islandNb].table
410 break
414 if ecoSysName then
416 local backTexture = ecoSysName .. "_back.tga"
418 local islandW, islandH = (islandTable.xmax - islandTable.xmin)*enlargingFactor, (islandTable.ymax - islandTable.ymin)*enlargingFactor
420 -- resize island button to see all island whitout deformation
421 local totalDim = 200
422 local maxDim = totalDim-2*8
423 local w_button_texture
424 local h_button_texture
425 local x_button_texture
426 local y_button_texture
427 local scale = "false"
429 local initW, initH = islandW, islandH
431 scale, w_button_texture, h_button_texture, islandW, islandH =
432 self:textureRedimension(textureName, maxDim, maxDim, islandW, islandH)
434 scale = tostring(scale)
436 -- center button island
437 x_button_texture = (maxDim-islandW)/2 + 8 -- 8 + (maxDim-width)/2 + 2
438 y_button_texture = -((maxDim-islandH)/2 + 8) -- -((maxDim-height)/2 + 8 + 2)
440 local h, h_button, y_button, h_text, y_text
441 local marge=15
442 if locationList.childrenNb == 0 then
443 h=totalDim
444 h_button="0"
445 y_button="0"
446 h_text="0"
447 y_text="0"
448 else
449 h=totalDim+marge
450 h_button=-marge
451 y_button=-marge
452 h_text=-marge
453 y_text=-marge
456 local tmplParams =
458 id=islandName,
459 posparent="parent",
460 posref="BR TR",
461 sizeref="w",
462 w="0",
463 h=h,
464 x="0",
465 y="0",
467 sizeref_act="h",
468 w_act = totalDim,
469 h_act="0",
470 x_act="0",
471 y_act="0",
472 y_button=y_button,
473 h_button=h_button,
475 icon = textureName,
476 w_button_texture = w_button_texture,
477 h_button_texture = h_button_texture,
478 x_button_texture = x_button_texture,
479 y_button_texture = y_button_texture,
480 scale = scale,
481 color= self.islandButtonColors[ecoSysName],
482 back_color= "255 255 255 255",
483 selected_color = self.islandSelectedButtonColors[ecoSysName].." 255",
484 col_over = self.islandSelectedButtonColors[ecoSysName].." 80",
485 group_params_l="r2.acts:locationIsland(getUICaller())",
486 params_l="r2.acts:locationIsland()",
487 back_texture=backTexture,
489 x_text=marge,
490 w_text= -(totalDim + marge + 15),
491 h_text=h_text,
492 y_text=y_text,
494 local buttonIsland = createGroupInstance("previous_loc_template", locationList.id, tmplParams)
496 if buttonIsland then
497 locationList:addChild(buttonIsland)
498 buttonIsland.Env.InstanceId = location.InstanceId
500 local uc_island = ucstring()
501 uc_island:fromUtf8(location.Name)
502 buttonIsland:find("button"):find("center_button").tooltip = uc_island
503 buttonIsland:find("selected_button"):find("center_button").tooltip = uc_island
505 -- init text
506 local textList = buttonIsland:find("text_list")
507 assert(textList)
509 local prevText = textList:find("previous_text")
510 assert(prevText)
512 local text = "'" .. location.Name .. "' Location used in acts :\n"
513 prevText:addColoredTextChild(text, 200, 0, 0, 255)
515 local acts = locationActs[location.InstanceId]
516 for k, actId in pairs(acts) do
517 local act = r2:getInstanceFromId(actId)
518 local act_text = act.Name
519 if act.ShortDescription~="" then
520 act_text = act_text .. " : "
523 prevText:addColoredTextChild(act_text, 200, 120, 0, 255)
525 if act.ShortDescription~="" then
526 act_text = act.ShortDescription
527 local uc_act = ucstring()
528 uc_act:fromUtf8(act_text)
529 prevText:addTextChild(uc_act)
533 -- init scroll target
534 local scroll = textList:find("scroll_previous")
535 assert(scroll)
536 local list = textList:find("list")
537 assert(list)
538 scroll:setTarget(list.id)
545 --------------------------------------------------------------------------------------
546 --------------------------- texture button redimension -------------------------------
547 function r2.acts:textureRedimension(textureName, maxW, maxH, islandW, islandH)
549 local scale = false
550 local w, h
552 if maxW<islandW or maxH<islandH then
553 local ratioW = islandW/maxW
554 local ratioH = islandH/maxH
555 local maxRatio = math.max(ratioW, ratioH)
557 local textureW, textureH = getTextureSize(textureName)
558 local newW = math.floor(textureW/maxRatio)
559 local newH = math.floor(textureH/maxRatio)
561 scale = true
562 w = newW
563 h = newH
565 islandW = math.floor(islandW/maxRatio)
566 islandH = math.floor(islandH/maxRatio)
567 else
568 w = islandW
569 h = islandH
572 return scale, w, h, islandW, islandH
575 --------------------------------------------------------------------------------------
576 --------------------------- open islands list of an ecosystem ------------------------
577 function r2.acts:openEcosystemIslands(ecoSystemName)
579 self.ecoSystemName = ecoSystemName
581 local actsUI = getUI("ui:interface:r2ed_acts")
582 assert(actsUI)
584 -- ecosystem buttons
585 local ecoSystemList = actsUI:find("ecosystem_list")
586 assert(ecoSystemList)
588 local selectedEcoSystemGr = ecoSystemList:find(ecoSystemName)
589 assert(selectedEcoSystemGr)
591 local selectedIslandsLists = selectedEcoSystemGr:find("two_lists")
592 assert(selectedIslandsLists)
594 -- ecosystem islands lists
595 local ecoSystemList2 = actsUI:find("ecosystem_list_2")
596 assert(ecoSystemList2)
598 local selectedEcoSystemGr2 = ecoSystemList2:find(ecoSystemName)
599 assert(selectedEcoSystemGr2)
601 if selectedEcoSystemGr2.active then
602 local ecoButton = selectedEcoSystemGr:find("eco_button")
603 assert(ecoButton)
604 ecoButton.pushed = true
605 --return
608 local index = ecoSystemList2:getElementIndex(selectedEcoSystemGr2)
609 for i=0, index do
610 ecoSystemList2:upChild(selectedEcoSystemGr2)
613 -- all islands list inactive instead of selected ecosystem (inverse)
614 for i=0, ecoSystemList2.childrenNb-1 do
615 local ecosystemGr2 = ecoSystemList2:getChild(i)
616 assert(ecosystemGr2)
617 ecosystemGr2.active = (ecosystemGr2.id == selectedEcoSystemGr2.id)
620 for i=0, ecoSystemList.childrenNb-1 do
622 local ecosystemGr = ecoSystemList:getChild(i)
623 assert(ecosystemGr)
625 local islandsList = ecosystemGr:find("two_lists")
626 assert(islandsList)
628 local ecoButton = ecosystemGr:find("eco_button")
629 assert(ecoButton)
631 ecoButton.pushed = (islandsList.id == selectedIslandsLists.id)
633 ecosystemGr.child_resize_h = false
634 ecosystemGr.h = 32
635 if islandsList.id == selectedIslandsLists.id then
636 ecosystemGr.h = 38
640 -- open first island image
641 local selectedIslandsList = selectedEcoSystemGr2:find("line0")
643 local islandCard = actsUI:find("island_current_image")
644 assert(islandCard)
646 local islandOk = actsUI:find("island_ok")
647 assert(islandOk)
649 if selectedIslandsList and (selectedIslandsList.childrenNb > 0) then
651 -- color
652 local ecoColor = self.islandSelectedButtonColors[self.ecoSystemName].." 255"
653 local ecoColorBack = self.islandSelectedButtonColors[self.ecoSystemName].." 100"
655 islandCard.active = true
657 islandCard:find("bl").color = ecoColor
658 islandCard:find("tl").color = ecoColor
659 islandCard:find("tr").color = ecoColor
660 islandCard:find("br").color = ecoColor
661 islandCard:find("bottom").color = ecoColor
662 islandCard:find("top").color = ecoColor
663 islandCard:find("left").color = ecoColor
664 islandCard:find("right").color = ecoColor
665 islandCard:find("bg").color = ecoColorBack
667 islandOk.active = true
669 local firstIsland = selectedIslandsList:getChild(0)
670 assert(firstIsland)
671 self:openIslandCardFromButton(self.ecoSystemName, firstIsland.Env.Name)
672 else
673 local islandBitmap = actsUI:find("island_bitmap")
674 assert(islandBitmap)
676 islandBitmap.texture = ""
678 islandCard.active = false
680 islandOk.active = false
683 local scrollIslands = actsUI:find("scroll_islands_2")
684 assert(scrollIslands)
685 scrollIslands.trackPos = scrollIslands.h_real
687 -- "choose island" title
688 local title = actsUI:find("choose_island"):find("choose_island_title")
689 assert(title)
690 -- doesn't work in all language local titleText = " " .. i18n.get("uiR2EDChooseIsland"):toUtf8() .." " .. self.ecosystemNames[self.ecoSystemName] .. " " .. i18n.get("uiR2EDEcosystem"):toUtf8() .. " "
691 local titleText = " " .. i18n.get("uiR2EDChooseIsland"):toUtf8() .. self.ecosystemNames[self.ecoSystemName] .. " "
692 local uc_title = ucstring()
693 uc_title:fromUtf8(titleText)
694 title.uc_hardtext = uc_title
697 --------------------------------------------------------------------------------------
698 --------------------------- open island card and images ------------------------------
699 function r2.acts:openIslandCardFromButton(ecosystem, islandName)
701 local actsUI = getUI("ui:interface:r2ed_acts")
702 assert(actsUI)
704 local ecosystemList = actsUI:find("ecosystem_list_2")
705 assert(ecosystemList)
707 local ecosystemGr = ecosystemList:find(ecosystem)
708 assert(ecosystemGr)
710 local islandButton = ecosystemGr:find(islandName)
711 assert(islandButton)
713 -- unselect last selection
714 if self.selectedIslandButtonId~=nil then
715 local lastSelectedIsland = getUI(self.selectedIslandButtonId)
716 if lastSelectedIsland ~= nil then
717 lastSelectedIsland:find("button").active = true
718 lastSelectedIsland:find("selected_button").active = false
722 -- select button
723 islandButton:find("button").active = false
724 islandButton:find("selected_button").active = true
726 self.selectedIslandButtonId = islandButton.id
728 self.selectedIslandName = islandButton.Env.Name
730 self.currentLocation.islandName = self.selectedIslandName
732 self:openIslandCard(self.selectedIslandName)
735 --------------------------------------------------------------------------------------
736 --------------------------- open island card -----------------------------------------
737 function r2.acts:openIslandCard(islandName)
739 local enlargingFactor = self.enlargingFactor
741 local textureName = islandName .. "_sp.tga"
743 local actsUI = getUI("ui:interface:r2ed_acts")
744 assert(actsUI)
746 local islandBitmap = actsUI:find("island_bitmap")
747 assert(islandBitmap)
749 -- load texture
750 islandBitmap.texture = textureName
752 -- card title
753 local title = actsUI:find("island_images"):find("card_title")
754 assert(title)
755 -- doesn't work in all language local titleText = " " .. i18n.get("uiR2EDZoomOn"):toUtf8() .." '" .. i18n.get(islandName):toUtf8() .. "' " .. i18n.get("uiR2EDIsland"):toUtf8() .. " "
756 local titleText = " " .. i18n.get("uiR2EDZoomOn"):toUtf8() .. i18n.get(islandName):toUtf8() .. " "
757 local uc_title = ucstring()
758 uc_title:fromUtf8(titleText)
759 title.uc_hardtext = uc_title
761 local islandTable = self.islands[self.ecoSystemName][self:getIslandNb(islandName)].table
762 local islandW, islandH = (islandTable.xmax - islandTable.xmin)*enlargingFactor, (islandTable.ymax - islandTable.ymin)*enlargingFactor
763 local islandCard = actsUI:find("island_current_image")
764 assert(islandCard)
766 -- resize island button to see all island whitout deformation
767 local maxW, maxH = islandCard.w_real-12, islandCard.h_real-12
769 local initW, initH = islandW, islandH
770 islandBitmap.scale, islandBitmap.w, islandBitmap.h, islandW, islandH =
771 self:textureRedimension(textureName, maxW, maxH, islandW, islandH)
773 local cardButton = islandCard:find("selected_button")
774 assert(cardButton)
776 cardButton.w = - (maxW - islandW)
777 cardButton.h = - (maxH - islandH)
778 cardButton.x = (maxW - islandW)/2
779 cardButton.y = - (maxH - islandH)/2
781 -- center button island
782 islandBitmap.x = 6
783 islandBitmap.y = -6
785 -- entry points
786 local entryNb = 0
787 for location, entry in pairs(islandTable.entrypoints) do
789 local entryPoinButton = actsUI:find("entrypoint"..entryNb):find("flag")
790 entryPoinButton.active = true
791 entryPoinButton.x = (enlargingFactor*(entry.x - islandTable.xmin)/initW)*islandW
792 entryPoinButton.y = (enlargingFactor*(entry.y - islandTable.ymax)/initH)*islandH
794 entryPoinButton.tooltip = i18n.get(location)
795 entryPoinButton.parent.Env.Name = location
796 if entryNb == 0 then
797 entryPoinButton.texture = "r2ed_entry_point_pushed.tga"
798 self.currentLocation.entryPoint = location
799 else
800 entryPoinButton.texture = "r2ed_entry_point.tga"
803 entryNb = entryNb+1
804 if entryNb==9 then break end
807 if entryNb < 9 then
808 for i=entryNb, 9 do
809 local entryPointGr = actsUI:find("entrypoint"..i)
810 assert(entryPointGr)
811 local entryPoinButton = entryPointGr:find("flag")
812 entryPoinButton.active = false
816 -- enlarge selected ecosystem button
817 local ecoButton = actsUI:find(self.ecoSystemName)
818 assert(ecoButton)
820 local ecoList = ecoButton.parent
821 assert(ecoList)
823 for i=0, ecoList.childrenNb-1 do
824 local button = ecoList:getChild(i)
825 if button == ecoButton then
826 button:find("eco_button").wmin = 164
827 else
828 button:find("eco_button").wmin = 160
832 actsUI:invalidateCoords()
833 actsUI:updateCoords()
836 --------------------------------------------------------------------------------------
837 --------------------------- select an entry point ---------------------------------------
838 function r2.acts:selectEntryPoint()
840 local actsUI = getUI("ui:interface:r2ed_acts")
841 assert(actsUI)
843 for i=0, 9 do
844 local entryPoinButton = actsUI:find("entrypoint"..i):find("flag")
845 assert(entryPoinButton)
847 if entryPoinButton == getUICaller() then
848 getUICaller().texture = "r2ed_entry_point_pushed.tga"
849 self.currentLocation.entryPoint = getUICaller().parent.Env.Name
850 else
851 entryPoinButton.texture = "r2ed_entry_point.tga"
853 end
856 --------------------------------------------------------------------------------------
857 --------------------------- choose a name for location -------------------------------
858 function r2.acts:chooseLocationName()
860 local actsUI = getUI("ui:interface:r2ed_acts")
861 assert(actsUI)
863 local chooseNamePopup = getUI("ui:interface:r2ed_choose_location_name")
864 assert(chooseNamePopup)
866 local editText = chooseNamePopup:find("edit_box_group")
867 assert(editText)
869 local name = editText.uc_input_string:toUtf8()
871 -- check location name duplication
872 if not self.createNewScenario then
873 for i=0, r2.Scenario.Locations.Size-1 do
874 local location = r2.Scenario.Locations[i]
875 if location.Name == name then
876 messageBox(i18n.get("uiR2EDLocationNameDuplicated"))
877 return
882 if name~="" then
884 self.currentLocation.name = name
886 chooseNamePopup.active = false
887 actsUI.active = false
889 disableModalWindow()
890 setKeyboardContext("r2ed")
892 if self.createNewScenario==true then
893 self:createScenario()
894 else
895 self:createAct()
897 else
898 editText:setFocusOnText()
902 --------------------------------------------------------------------------------------
903 --------------------------- choose a name for scenario/act ---------------------------
904 function r2.acts:chooseScenarioActName()
906 local actsUI = getUI("ui:interface:r2ed_acts")
907 assert(actsUI)
909 local chooseNamePopup = getUI("ui:interface:r2ed_choose_scenario_act_name")
910 assert(chooseNamePopup)
912 -- act name
913 local actGr = chooseNamePopup:find("act_name")
914 assert(actGr)
915 local actEditText = actGr:find("edit_box_group")
916 assert(actEditText)
917 local actName = actEditText.uc_input_string:toUtf8()
918 local scenarioName = ""
920 local scenarioEditText
921 if self.createNewScenario == true then
922 -- scenario name
923 local scenarioGr = chooseNamePopup:find("scenario_name")
924 assert(scenarioGr)
926 scenarioEditText = scenarioGr:find("edit_box_group")
927 assert(scenarioEditText)
929 scenarioName = scenarioEditText.uc_input_string:toUtf8()
932 if (self.createNewScenario and scenarioName~="" and actName~="") or (not self.createNewScenario and actName~="") then
933 chooseNamePopup.active = false
934 disableModalWindow()
936 self.currentScenario.name = scenarioName
937 self.currentAct.name = actName
939 if self.createNewLocation == true then
940 local locationGr = actsUI:find("location")
941 assert(locationGr)
943 local scenarioActGr = actsUI:find("scenario_act")
944 assert(scenarioActGr)
946 scenarioActGr.active = false
947 locationGr.active = true
949 self:openEcosystemIslands("r2_desert")
950 else
951 actsUI.active = false
952 if self.createNewScenario==true then
953 self:createScenario()
954 else
955 self:createAct()
957 setKeyboardContext("r2ed")
960 elseif self.createNewScenario and scenarioName==""then
961 scenarioEditText:setFocusOnText()
963 elseif actName=="" then
964 actEditText:setFocusOnText()
968 --------------------------------------------------------------------------------------
969 --------------------------------- createScenario -------------------------------------
970 function r2.acts:createScenario()
972 local actsUI = getUI("ui:interface:r2ed_acts")
973 assert(actsUI)
975 -- scenario/act/location notes
976 local scenarioNotes, actNotes
977 scenarioNotes = ""
978 actNotes = ""
980 r2.resetNameGiver()
981 -- create scenario component
982 local scenario= r2.newComponent("Scenario")
983 scenario.Ghost_Name = self.currentScenario.name
984 scenario.Description.ShortDescription = scenarioNotes
985 if r2.Scenario and r2.Scenario.Language then
986 scenario.Language = r2.Scenario.Language
988 scenario.AccessRules = self.currentScenario.rules
989 scenario.Description.LevelId = self.currentScenario.level
990 scenario.Description.CreationDate = os.date()
991 scenario.Description.Creator = r2:getUserEntityName()
992 scenario.Description.CreatorMD5 = r2.getCharIdMd5()
996 -- create permanent act component
997 local act =r2.newComponent("Act")
998 local features = act.Features
999 local tmpDefault = r2.newComponent("DefaultFeature")
1000 act.Name = i18n.get("uiR2EDBaseAct"):toUtf8()
1001 table.insert(features, tmpDefault)
1002 table.insert(scenario.Acts, act)
1004 -- create act 1 component
1005 act = r2.newComponent("Act")
1006 local features = act.Features
1007 local tmpDefault = r2.newComponent("DefaultFeature")
1008 r2.ActUIDisplayer.LastSelfCreatedActInstanceId = act.InstanceId
1009 --act.Name = i18n.get("uiR2EDAct1"):toUtf8() .. ":" .. r2.currentAct.name
1010 act.Name = self.currentAct.name
1011 act.WeatherValue = self.currentAct.weather
1012 local manualWeather = 0
1013 if self.currentAct.manualWeather == true then manualWeather = 1 end
1014 act.ManualWeather = manualWeather
1015 act.ShortDescription = actNotes
1016 table.insert(features, tmpDefault)
1017 table.insert(scenario.Acts, act)
1019 -- create location
1020 local location = r2.newComponent("Location")
1021 location.Season = self.currentLocation.season
1022 location.IslandName = self.currentLocation.islandName
1023 location.Name = self.currentLocation.name
1024 location.EntryPoint = self.currentLocation.entryPoint
1025 local manualSeason = 0
1026 if self.currentLocation.manualSeason == true then manualSeason = 1 end
1027 location.ManualSeason = manualSeason
1028 table.insert(scenario.Locations, location)
1029 act.LocationId = location.InstanceId
1031 r2.requestCreateScenario(scenario)
1032 r2:waitScenarioScreen()
1034 self.deleteOldScenario = true
1037 function r2.acts:createAct()
1039 r2.requestNewAction(i18n.get("uiR2EDNewActAction"))
1041 local actsUI = getUI("ui:interface:r2ed_acts")
1042 assert(actsUI)
1044 -- act/location notes
1045 local actNotes = ""
1047 -- create act component
1048 local act =r2.newComponent("Act")
1049 local features = act.Features
1050 local tmpDefault = r2.newComponent("DefaultFeature")
1051 if (tmpDefault == nil) then
1052 debugWarning("Failed to create default feature");
1053 return
1054 end
1055 r2.ActUIDisplayer.LastSelfCreatedActInstanceId = act.InstanceId
1056 local actNb = r2.Scenario.Acts.Size
1057 --act.Name = i18n.get("uiR2EDDefaultActTitle"):toUtf8() .. actNb .. ":" .. r2.currentAct.name
1058 act.Name = self.currentAct.name
1059 act.WeatherValue = self.currentAct.weather
1060 local manualWeather = 0
1061 if self.currentAct.manualWeather == true then manualWeather = 1 end
1062 act.ManualWeather = manualWeather
1063 act.ShortDescription = actNotes
1064 table.insert(features, tmpDefault)
1065 if (act == nil) then
1066 debugWarning("Failed to create additionnal 'Act'");
1067 return
1068 end
1070 -- create location
1071 local location
1072 if self.createNewLocation then
1074 location = r2.newComponent("Location")
1075 location.Season = self.currentLocation.season
1076 location.IslandName = self.currentLocation.islandName
1077 location.Name = self.currentLocation.name
1078 location.EntryPoint = self.currentLocation.entryPoint
1079 local manualSeason = 0
1080 if self.currentLocation.manualSeason == true then manualSeason = 1 end
1081 location.ManualSeason = manualSeason
1082 act.LocationId = location.InstanceId
1084 r2.requestInsertNode(r2.Scenario.InstanceId, "Locations", -1, "", location)
1085 else
1086 act.LocationId = self.currentLocation.instanceId
1089 r2.requestInsertNode(r2.Scenario.InstanceId, "Acts", -1, "", act)
1092 --------------------------------------------------------------------------------------
1093 --------------------------- choose location name popup -------------------------------
1094 function r2.acts:openLocationName()
1096 local chooseNamePopup = getUI("ui:interface:r2ed_choose_location_name")
1097 assert(chooseNamePopup)
1099 local actsUI = getUI("ui:interface:r2ed_acts")
1100 assert(actsUI)
1102 if not actsUI.active then return end
1104 local okButton = actsUI:find("island_ok")
1105 assert(okButton)
1107 enableModalWindow(okButton, chooseNamePopup.id)
1109 local editText = chooseNamePopup:find("edit_box_group")
1110 assert(editText)
1111 editText.uc_input_string = i18n.get(self.currentLocation.islandName)
1112 editText:setFocusOnText()
1115 ------------------------ SELECT BUTTON IN LIST --------------------------------
1116 -- only one button can be selected --------------------------------------------
1117 function r2.acts:selectButtonTemplate(buttonTemplate)
1119 local list = buttonTemplate.parent
1120 assert(list)
1122 for i=0,list.childrenNb-1 do
1123 local child = list:getChild(i)
1124 assert(child)
1125 child:find("button").active = true
1126 child:find("selected_button").active = false
1129 buttonTemplate:find("button").active = false
1130 buttonTemplate:find("selected_button").active = true
1133 function r2.acts:selectButton(button)
1135 local list = button.parent
1136 assert(list)
1138 for i=0,list.childrenNb-1 do
1139 local child = list:getChild(i)
1140 assert(child)
1141 child:find("button").pushed = false
1144 button:find("button").pushed = true
1147 --------------------------- CHOOSE LOCATION SEASON ---------------------------------------
1148 function r2.acts:locationSeason(caller)
1150 local buttonTemplate
1151 if caller == nil then
1152 caller = getUICaller()
1153 buttonTemplate = caller.parent.parent
1154 else
1155 buttonTemplate = caller.parent
1158 self:selectButtonTemplate(buttonTemplate)
1160 local list = buttonTemplate.parent
1161 local seasons = {[0]="Spring", [1]="Summer", [2]="Autumn", [3]="Winter"}
1162 local seasonNb = list:getElementIndex(buttonTemplate)
1163 self.currentLocation.season = seasons[seasonNb]
1166 ----- MANUAL SEASON ACTIVATION -------------------------------------------------------
1167 function r2.acts:manualSeason()
1169 local actsUI = getUI("ui:interface:r2ed_acts")
1170 assert(actsUI)
1172 local manualButton = actsUI:find("manual_season_2"):find("toggle_butt")
1173 assert(manualButton)
1175 self.currentLocation.manualSeason = (manualButton.pushed==false)
1177 local seasonList = actsUI:find("season_list_2")
1178 assert(seasonList)
1180 seasonList.active = self.currentLocation.manualSeason
1183 --- OPEN POPUP NAME FOR ACT/SCENARIO OR LOCATION -----------------------------------------
1184 function r2.acts:openPopupName()
1186 local actsUI = getUI("ui:interface:r2ed_acts")
1187 assert(actsUI)
1189 local createLocationGr = actsUI:find("location")
1190 assert(createLocationGr)
1191 local prevLocationGr = actsUI:find("previous_location")
1192 assert(prevLocationGr)
1194 if prevLocationGr.active then
1195 self:createLocationOrCreateAct()
1196 else
1197 self:openLocationName()
1202 --- CANCEL ACT/SCENARIO CREATION --------------------------------------------------------
1203 function r2.acts:cancelActCreation()
1205 local actsUI = getUI("ui:interface:r2ed_acts")
1206 assert(actsUI)
1208 actsUI.active =false
1210 setKeyboardContext("r2ed")
1214 --------------------- update palette UI when change act ------------------------------
1215 function r2.acts:updatePaletteFromEcosystem()
1217 local ecosystemTrees =
1219 ["r2_desert"] = "fytrees",
1220 ["r2_forest"] = "fotrees",
1221 ["r2_jungle"] = "jutrees",
1222 ["r2_lakes"] = "trtrees",
1223 ["r2_roots"] = "prtrees",
1226 local currentAct = r2:getCurrentAct()
1227 assert(currentAct)
1229 local botObjectsPalette = {}
1230 if not r2.Palette.BotEntries then
1231 return -- special case for the 'light' palette
1234 botObjectsPalette = r2.Palette.BotEntries
1236 if not currentAct:isBaseAct() then
1237 local currentLocation = r2:getInstanceFromId(currentAct.LocationId)
1238 if currentLocation==nil then return end
1240 -- search for ecosystem of current location
1241 local islandEcosystem
1242 for ecoName, v in pairs(self.islands) do
1243 if self.islands[ecoName][self:getIslandNb(currentLocation.IslandName)].name==currentLocation.IslandName then
1244 islandEcosystem = ecoName
1245 break
1249 -- flag to display only vegetation of current ecosystem
1250 if islandEcosystem and ecosystemTrees[islandEcosystem] then
1251 for ecoName, v in pairs(ecosystemTrees) do
1252 botObjectsPalette[ecosystemTrees[ecoName]].Display = (ecoName==islandEcosystem)
1255 else
1256 for ecoName, v in pairs(ecosystemTrees) do
1257 botObjectsPalette[ecosystemTrees[ecoName]].Display = false
1261 r2:buildPaletteUI()
1264 ----------------------------------------------------------------------------------------------
1265 function r2.acts:locationIsland(caller)
1267 local actsUI = getUI("ui:interface:r2ed_acts")
1268 assert(actsUI)
1270 local buttonTemplate
1271 if caller == nil then
1272 caller = getUICaller()
1273 buttonTemplate = caller.parent.parent
1274 else
1275 buttonTemplate = caller.parent
1278 if buttonTemplate.Env.Name == self.newLocation then
1280 -- select "create new location" mode
1281 buttonTemplate:find("button").active = false
1282 buttonTemplate:find("selected_button").active = true
1283 self.createNewLocation = true
1285 -- deselect all previous locations
1286 local prevLocationList = actsUI:find("location_list")
1287 assert(prevLocationList)
1288 for i=0,prevLocationList.childrenNb-1 do
1289 local child = prevLocationList:getChild(i)
1290 assert(child)
1291 child:find("button").active = true
1292 child:find("selected_button").active = false
1294 self.currentLocation.islandName = ""
1295 self.currentLocation.intanceId = ""
1296 else
1297 -- select this previous location
1298 self:selectButtonTemplate(buttonTemplate.parent)
1299 self.currentLocation.instanceId = buttonTemplate.parent.Env.InstanceId
1301 -- deselect "create new location" mode
1302 local newLocationMode = actsUI:find("new_location_mode_2")
1303 assert(newLocationMode)
1304 newLocationMode:find("button").active = true
1305 newLocationMode:find("selected_button").active = false
1306 self.createNewLocation = false
1310 --------------------------------------------------------------------------------------
1311 --------------------------- choose a name for scenario/act ---------------------------
1312 function r2.acts:createLocationOrCreateAct()
1314 local actsUI = getUI("ui:interface:r2ed_acts")
1315 assert(actsUI)
1317 if self.createNewLocation then
1319 local createLocationGr = actsUI:find("location")
1320 assert(createLocationGr)
1321 local prevLocationGr = actsUI:find("previous_location")
1322 assert(prevLocationGr)
1324 createLocationGr.active = true
1325 prevLocationGr.active = false
1327 self:openEcosystemIslands("r2_desert")
1328 else
1329 actsUI.active = false
1331 disableModalWindow()
1332 setKeyboardContext("r2ed")
1334 self:createAct()