Merge branch 'fixes' into main/gingo-test
[ryzomcore.git] / ryzom / common / data_common / r2 / r2_ui_scenario.lua
blobd627ab7b79d8ddf86d3647390ff14aca8b4b2395
1 -----------------
2 -- SCENARIO UI --
3 -----------------
6 r2.ScenarioWindow =
8 IgnoreActChange = false, -- when the content of the combo box is changed manually, allow to know we should not process the
9 -- the 'onchangeAct' msg
10 LeftQuota = nil,
12 LeftStaticQuota = nil,
14 Languages = {},
16 Types = {},
17 Locked = {},
19 lockComboBoxes = false,
20 -- chosen act in combo box
21 showedActId = nil,
23 TitleEditBoxLocked = false
26 -----------------------------------------------------------------------------------------------------------
27 -- init scenario window (language and scenario types from cfg files) --------------------------------------
28 function r2.ScenarioWindow:initScenarioWindow()
30 local languages = getClientCfgVar("ScenarioLanguages")
31 local types = getClientCfgVar("ScenarioTypes")
33 local locked = {"Full", "RunOnly"}
35 -- stores values and init combo boxes
36 local scenarioWnd = self:getContainer()
37 local languageCB = scenarioWnd:find("language_combo_box")
38 local typeCB = scenarioWnd:find("type_combo_box")
39 local lockCB = scenarioWnd:find("locked_combo_box")
40 local levelCB = scenarioWnd:find("level_combo_box")
41 local rulesCB = scenarioWnd:find("rules_combo_box")
43 local languages2 = {}
44 for k, lang in pairs(languages) do
45 self.Languages[i18n.get("uiR2ED"..lang):toUtf8()] = lang
46 table.insert(languages2, i18n.get("uiR2ED"..lang))
47 end
48 table.sort(languages2)
49 languageCB:resetTexts()
50 for k, lang in pairs(languages2) do
51 languageCB:addText(lang)
52 end
54 local types2 = {}
55 for k, type in pairs(types) do
56 self.Types[i18n.get("uiR2ED"..type):toUtf8()] = type
57 table.insert(types2, i18n.get("uiR2ED"..type))
58 end
59 table.sort(types2)
60 typeCB:resetTexts()
62 for k, type in pairs(types2) do
63 typeCB:addText(type)
64 end
68 local tmp = {}
69 if config.R2EDExtendedDebug == 1 then
70 table.insert(locked, "RoSOnly")
71 end
72 for k, type in pairs(locked) do
73 self.Locked[i18n.get("uiR2ED"..type):toUtf8()] = type
74 table.insert(tmp, i18n.get("uiR2ED"..type))
75 end
76 -- table.sort(tmp)
77 lockCB:resetTexts()
78 for k, type in pairs(tmp) do
79 lockCB:addText(type)
80 end
82 end
85 levelCB:resetTexts()
86 for i = 0, 5 do
87 levelCB:addText(i18n.get("uiRAP_Level".. tostring(i)))
88 end
90 rulesCB:resetTexts()
91 rulesCB:addText(i18n.get("uiR2EDstrict"))
92 rulesCB:addText(i18n.get("uiR2EDliberal"))
93 end
95 -----------------------------------------------------------------------------------------------------------
96 -- retrieve the table of acts (table that map each line of the combo box to an act, see r2.ActUIDisplayer)
97 function r2.ScenarioWindow:getActTable()
98 return r2.ActUIDisplayer:getActTable()
99 end
101 -----------------------------------------------------------------------------------------------------------
102 -- retrieve the 'scenario' window container (TODO nico : code duplicated with r2.ActUIDisplayer)
103 function r2.ScenarioWindow:getContainer()
104 return getUI("ui:interface:r2ed_scenario")
107 -----------------------------------------------------------------------------------------------------------
108 -- retrieve the 'acts' combo box (TODO nico : code duplicated with r2.ActUIDisplayer)
109 function r2.ScenarioWindow:getActComboBox()
110 return self:getContainer():find("act_combo_box")
113 -----------------------------------------------------------------------------------------------------------
114 -- handler selection of a new act by the user
115 function r2.ScenarioWindow:onChangeActFromUI()
116 if self.IgnoreActChange then return end
117 self:setAct(self:getActTable()[self:getActComboBox().selection + 1].Act)
120 -----------------------------------------------------------------------------------------------------------
121 -- update ui from the current act
122 function r2.ScenarioWindow:updateUIFromCurrentAct()
124 local act = r2:getCurrentAct()
125 -- look in the act table to change the selection
126 self.IgnoreActChange = true -- don't want to trigger the 'onChangeAct' msg here
127 if self.getActComboBox == nil then
128 debugInfo(debug.traceback())
129 inspect(self)
131 if not act:isBaseAct() then
132 self:getActComboBox().selection = self:findComboBoxLineFromAct(act)
134 self.IgnoreActChange = false
135 self:updateActTreeVisibility()
136 self:updateLeftQuota()
140 -----------------------------------------------------------------------------------------------------------
141 -- get left quota, possibly updating it if it was modified
142 -- called by client
143 function r2.ScenarioWindow:getLeftQuota()
144 if r2.UIMainLoop.LeftQuotaModified then
145 self:updateLeftQuota()
147 local quota = 0
148 if self.LeftQuota < self.LeftStaticQuota then
149 quota = self.LeftQuota
150 else
151 quota = self.LeftStaticQuota
153 return quota, self.LeftQuota, self.LeftStaticQuota
154 end
156 -----------------------------------------------------------------------------------------------------------
157 -- update display of left quota for the current act
158 function r2.ScenarioWindow:updateLeftQuota()
159 function protected()
160 if not r2.Scenario then return end
161 local quotaViewText = self:getContainer():find("left_quota")
162 local quotaTooltip = self:getContainer():find("tab4")
163 local quotaMacroViewText = self:getContainer():find("left_quota_macro")
164 local quotaMacroTooltip = self:getContainer():find("tab1")
165 local quotaViewTextMisc = self:getContainer():find("left_quota_misc")
166 local quotaViewTextMisc2 = self:getContainer():find("left_quota_misc_2")
167 local quotaMiscTooltip = self:getContainer():find("tab2")
169 local act = r2:getCurrentAct()
171 if act then
172 r2.updateActCost(act)
173 if not act:isBaseAct() then
174 r2.updateActCost(r2.Scenario:getBaseAct())
177 self.LeftQuota, self.LeftStaticQuota = act:getLeftQuota()
179 local uc_tooltip = ucstring()
180 quotaViewText.hardtext = string.format("(%d)", self.LeftQuota)
181 uc_tooltip:fromUtf8(i18n.get("uiR2EDScene"):toUtf8() .. " (" .. self.LeftQuota .. ")")
182 quotaTooltip.tooltip = uc_tooltip
183 quotaMacroViewText.hardtext = string.format("(%d)", self.LeftQuota)
184 uc_tooltip:fromUtf8(i18n.get("uiR2EDMacroComponents"):toUtf8() .. " (" .. self.LeftQuota .. ")")
185 quotaMacroTooltip.tooltip = uc_tooltip
186 quotaViewTextMisc.hardtext = string.format("(%d)", self.LeftStaticQuota)
187 quotaViewTextMisc2.hardtext = string.format("(%d)", self.LeftStaticQuota)
188 uc_tooltip:fromUtf8(i18n.get("uiR2EDbotObjects"):toUtf8() .. " (" .. self.LeftStaticQuota .. ")")
189 quotaMiscTooltip.tooltip = uc_tooltip
191 quotaViewText.color_rgba = select(self.LeftQuota >= 0, CRGBA(255, 255, 255), CRGBA(255, 0, 0))
192 quotaViewTextMisc.color_rgba = select(self.LeftStaticQuota >= 0, CRGBA(255, 255, 255), CRGBA(255, 0, 0))
193 quotaViewTextMisc2.color_rgba = select(self.LeftStaticQuota >= 0, CRGBA(255, 255, 255), CRGBA(255, 0, 0))
195 else
196 quotaViewText.hardtext = ""
197 quotaMacroViewText.hardtext = ""
198 end
199 r2.UIMainLoop.LeftQuotaModified = false
201 pcall(protected)
204 -----------------------------------------------------------------------------------------------------------
205 -- change act into editor, and in the ui
206 r2.ScenarioWindow.setActId = nil
207 function r2.ScenarioWindow:setAct(act)
209 if act ~= r2:getCurrentAct() then
210 self:updateComboBoxCurrentAct(act)
211 r2:setCurrentActFromId(act.InstanceId) -- will also trigger ui update (called by C++)
212 if act.InstanceId~=self.setActId then
213 if not r2:isClearingContent() then
214 displaySystemInfo(concatUCString(i18n.get("uiR2EDCurrentActNotify"), act:getDisplayName()), "BC")
216 self.setActId = act.InstanceId
221 -----------------------------------------------------------------------------------------------------------
223 function r2.ScenarioWindow:updateComboBoxCurrentAct(newAct)
225 local comboB = self:getActComboBox()
226 local text = ucstring()
227 local currentAct = r2:getCurrentAct()
228 if not (currentAct==nil or currentAct.isNil) then
229 local currentActIndex = r2.ScenarioWindow:findComboBoxLineFromAct(currentAct)
230 if currentActIndex then
231 text:fromUtf8(currentAct:getName())
232 comboB:setText(currentActIndex, text)
236 local newActIndex = r2.ScenarioWindow:findComboBoxLineFromAct(newAct)
237 if newActIndex then
238 text:fromUtf8(newAct:getName() .. " [" .. i18n.get("uiR2EDCurrentActComboBox"):toUtf8() .."]")
239 comboB:setText(newActIndex, text)
243 -----------------------------------------------------------------------------------------------------------
244 -- find line in combo box for the given act (index is 0 based)
245 function r2.ScenarioWindow:findComboBoxLineFromAct(act)
246 local actTable = self:getActTable()
247 for index, entry in pairs(actTable) do
248 if entry.Act == act then
249 return index - 1
251 end
252 return nil
255 -----------------------------------------------------------------------------------------------------------
256 -- selection of a new act (called by combo box)
257 function r2.ScenarioWindow:updateActTreeVisibility()
258 local currentAct = r2:getCurrentAct()
259 local container = self:getContainer()
260 -- show the good tree control
261 for i = 0, r2:getMaxNumberOfAdditionnalActs() - 1 do
262 local tree = container:find("act_tree_" .. tostring(i))
263 assert(tree)
264 tree.active = (tree == currentAct:getContentTree())
266 local macroTree = container:find("macro_act_tree_" .. tostring(i))
267 assert(macroTree)
268 macroTree.active = (macroTree == currentAct:getMacroContentTree())
270 -- allow to delete an act only if it is not the base act
271 container:find("delete_act").active = not currentAct:isBaseAct()
274 -----------------------------------------------------------------------------------------------------------
275 -- pop window for new act creation
277 function r2.ScenarioWindow:newAct()
279 if r2.Scenario.Acts.Size == r2:getMaxNumberOfAdditionnalActs() + 1 then -- '+1' because first act is the base add, which can't be deleted/created
280 messageBox(i18n.get("uiR2EDMaxActCountReached"))
281 return
282 end
284 r2.acts:openScenarioActEditor(false)
287 -----------------------------------------------------------------------------------------------------------
288 -- Ask the user to confirm deletion of act
289 function r2.ScenarioWindow:deleteAct()
290 validMessageBox(i18n.get("uiR2EDconfirmDeleteAct"), "lua", "r2.ScenarioWindow:confirmDeleteAct()", "lua", "r2.ScenarioWindow:cancelDeleteAct()", "ui:interface")
293 -----------------------------------------------------------------------------------------------------------
294 -- Act deletion has been confirmed
295 function r2.ScenarioWindow:confirmDeleteAct()
297 r2.requestNewAction(i18n.get("uiR2EDRemoveActAction"))
299 assert(not r2:getCurrentAct():isBaseAct())
300 local actId = r2:getCurrentAct().InstanceId
301 local firstAct = (r2.Scenario.Acts.Size>1 and (r2:getCurrentAct() == r2.Scenario.Acts[1]))
303 -- update other acts name
304 local afterDeletedAct = false
305 for i=0, r2.Scenario.Acts.Size-1 do
306 local act = r2.Scenario.Acts[i]
308 if (not act:isBaseAct()) and afterDeletedAct==true then
310 local name = act.Name
312 local firstPart = i18n.get("uiR2EDDefaultActTitle"):toUtf8() .. i
313 local firstPartSpace = i18n.get("uiR2EDDefaultActTitle"):toUtf8().. " " .. i
315 if name == firstPart or name == firstPartSpace then
316 name = i18n.get("uiR2EDDefaultActTitle"):toUtf8() .. " " .. (i-1)
317 r2.requestSetNode(act.InstanceId, "Name", name)
320 elseif act.InstanceId == actId then
321 afterDeletedAct = true
323 end
325 -- delete permanent content of the act's island if this one isn't used in another location
326 local pointToIsland = 0
327 local locationId = r2:getCurrentAct().LocationId
328 local islandName = r2:getInstanceFromId(locationId).IslandName
329 for i=0, r2.Scenario.Locations.Size-1 do
330 local location = r2.Scenario.Locations[i]
331 assert(location)
333 if location.IslandName == islandName then
334 pointToIsland = pointToIsland + 1
338 if pointToIsland <= 1 then
339 -- search island attributes
340 local islandTable = nil
341 for ecoSystem, ecoSysTable in pairs(r2.acts.islands) do
342 local islandNb = r2.acts:getIslandNb(islandName)
343 if ecoSysTable[islandNb] and ecoSysTable[islandNb].name == islandName then
344 ecoSysName = ecoSystem
345 islandTable = ecoSysTable[islandNb].table
346 break
350 -- delete permanent content positionned in deleted location
351 if false and islandTable then
352 local permanentContent = {}
353 local baseAct = r2.Scenario:getBaseAct()
354 baseAct:appendInstancesByType(permanentContent, "WorldObject")
355 for k, permObj in pairs(permanentContent) do
356 local isInX = (islandTable.xmin<=permObj.Position.x and permObj.Position.x<=islandTable.xmax)
357 local isInY = (islandTable.ymin<=permObj.Position.y and permObj.Position.y<=islandTable.ymax)
358 if isInX and isInY then
359 r2.requestEraseNode(permObj.InstanceId)
365 -- delete the act location if any other act doesn't point to this location
366 local pointToLocation = 0
367 for i=0, r2.Scenario.Acts.Size-1 do
368 local act = r2.Scenario.Acts[i]
369 assert(act)
371 if act.LocationId == locationId then
372 pointToLocation = pointToLocation + 1
376 if pointToLocation <= 1 then
377 r2.requestEraseNode(locationId)
380 -- if Act[1] is deleted, we must create another one
381 if actId==r2.Scenario.Acts[1].InstanceId and table.getn(r2.Scenario.Acts)<=2 then
382 r2.acts:openScenarioActEditor(false, true, true)
385 r2.requestEraseNode(actId)
387 r2.requestEndAction()
390 -----------------------------------------------------------------------------------------------------------
391 -- Act deletion has been canceled
392 function r2.ScenarioWindow:cancelDeleteAct()
393 debugInfo("Cancel deletion of current act")
396 -----------------------------------------------------------------------------------------------------------
397 -- Reset content of the scenario window
398 function r2.ScenarioWindow:resetWindow()
399 local function cleanContentTree(contentTree)
400 if contentTree and not contentTree.isNil then
401 r2:cleanTreeNode(contentTree, "people")
402 r2:cleanTreeNode(contentTree, "creatures")
403 contentTree:forceRebuild()
407 local function cleanContentMacroTree(contentTree)
408 if contentTree and not contentTree.isNil then
409 --r2:cleanTreeNode(contentTree, "macro_components")
410 r2:cleanTreeRootNode(contentTree)
411 contentTree:forceRebuild()
416 local container = self:getContainer()
417 if not container then
418 debugInfo("Scenario window not found")
419 return
422 -- content & geo now merged
423 local contentTree = container:find("content_tree_list")
424 if contentTree and not contentTree.isNil then
425 --r2:cleanTreeNode(contentTree, "scenery_objects")
426 r2:cleanTreeRootNode(contentTree)
427 contentTree:forceRebuild()
431 for i = 0, r2:getMaxNumberOfAdditionnalActs() - 1 do
432 local actTree = container:find("act_tree_" .. tostring(i))
433 actTree.active = false
434 cleanContentTree(actTree)
436 local actMacroTree = container:find("macro_act_tree_" .. tostring(i))
437 actMacroTree.active = false
438 cleanContentMacroTree(actMacroTree)
440 container:find("delete_act").active = false
441 -- clean list of acts
442 local comboBox = self:getActComboBox()
443 if comboBox then
444 while comboBox:getNumTexts() ~= 0 do
445 comboBox:removeTextByIndex(0)
448 self.IgnoreActChange = true -- don't whant to trigger a 'onChangeAct' request here (supposed to be called at init)
449 comboBox.selection = 0
450 self.IgnoreActChange = false
454 ----- WEATHER SLIDER VALUE ---------------------------------------------------------
455 function r2.ScenarioWindow:weatherValue(requestType)
457 if not self.showedActId or not r2:getInstanceFromId(self.showedActId) then return end
458 local act = r2:getInstanceFromId(self.showedActId)
459 assert(act)
461 self:setActNotes()
463 local scenarioUI = self:getContainer()
464 assert(scenarioUI)
466 local actGr = scenarioUI:find("act_properties")
467 assert(actGr)
469 local weatherValue = actGr:find("weather"):find("slider").value
470 r2.requestNewAction(i18n.get("uiR2EDChangeActWeather"))
472 if requestType == nil then
473 r2.requestSetNode(act.InstanceId, "WeatherValue", weatherValue)
474 elseif requestType == 'local' then
475 r2.requestSetLocalNode(act.InstanceId, "WeatherValue", weatherValue)
476 elseif requestType == 'commit' then
477 r2.requestCommitLocalNode(act.InstanceId, "WeatherValue")
478 elseif requestType == 'cancel' then
479 r2.requestRollbackLocalNode(act.InstanceId, "WeatherValue")
482 r2.requestEndAction()
485 ----- MANUAL WEATHER ACTIVATION -------------------------------------------------------
486 function r2.ScenarioWindow:manualWeather()
488 if not self.showedActId or not r2:getInstanceFromId(self.showedActId) then return end
489 local act = r2:getInstanceFromId(self.showedActId)
490 assert(act)
492 self:setActNotes()
494 local scenarioUI = self:getContainer()
495 assert(scenarioUI)
497 local actGr = scenarioUI:find("act_properties")
498 assert(actGr)
500 local manualButton = actGr:find("manual_weather"):find("toggle_butt")
501 assert(manualButton)
502 local manual=1
503 if manualButton.pushed==true then manual=0 end
505 r2.requestNewAction(i18n.get("uiR2EDChangeActWeatherManual"))
506 r2.requestSetNode(act.InstanceId, "ManualWeather", manual)
507 r2.requestEndAction()
510 --------------------- set act notes ----------------------------------------------------
511 function r2.ScenarioWindow:setActNotes()
513 if not self.showedActId or not r2:getInstanceFromId(self.showedActId) then return end
514 local act = r2:getInstanceFromId(self.showedActId)
515 assert(act)
517 local scenarioUI = self:getContainer()
518 assert(scenarioUI)
520 local actGr = scenarioUI:find("act_properties")
521 assert(actGr)
523 local preActNotes = actGr:find("pre_act_notes"):find("small_description").uc_input_string:toUtf8()
524 local actNotes = actGr:find("act_notes"):find("small_description").uc_input_string:toUtf8()
526 if act==nil then act = r2:getCurrentAct() end
527 if actNotes~=act.ShortDescription then
528 r2.requestSetNode(act.InstanceId, "ShortDescription", actNotes)
531 if preActNotes~=act.PreActDescription then
532 r2.requestSetNode(act.InstanceId, "PreActDescription", preActNotes)
537 --------------------- update act properties in scenario window -------------------------
539 function r2.ScenarioWindow:showActProperties()
541 local actNb = self:getActComboBox().selection + 1
542 local actTable = self:getActTable()
543 if actTable[actNb]==nil then return end
544 local act = actTable[actNb].Act
545 if act==nil then act=r2:getCurrentAct() end
547 self:setActNotes()
548 self.showedActId = act.InstanceId
550 self:updateActProperties()
552 local goButton = self:getContainer():find("go_to_act")
553 assert(goButton)
554 goButton.active = (act~=r2:getCurrentAct())
556 local deleteButton = self:getContainer():find("delete_act")
557 assert(deleteButton)
558 deleteButton.active = (act==r2:getCurrentAct())
561 function r2.ScenarioWindow:updateActProperties()
563 if not self.showedActId or not r2:getInstanceFromId(self.showedActId) then return end
564 local act = r2:getInstanceFromId(self.showedActId)
565 assert(act)
566 assert((not act:isBaseAct()))
568 act:updateWeather()
570 local scenarioUI = self:getContainer()
571 assert(scenarioUI)
573 local actGr = scenarioUI:find("act_properties")
574 assert(actGr)
576 -- location name
577 local location = r2:getInstanceFromId(act.LocationId)
578 if location==nil then return end
579 local locationName = actGr:find("location_name")
580 assert(locationName)
581 local uc_location = ucstring()
582 uc_location:fromUtf8(location.Name)
583 locationName.uc_hardtext = uc_location
585 -- season
586 local seasons = {
587 ["Spring"] = "uiR2EDSpring",
588 ["Summer"] = "uiR2EDSummer",
589 ["Autumn"] = "uiR2EDAutumn",
590 ["Winter"] = "uiR2EDWinter"
592 local season = actGr:find("season_name")
593 assert(season)
594 local uc_season = ucstring()
595 local seasonStr = seasons[location.Season]
596 uc_season:fromUtf8(i18n.get(seasonStr):toUtf8())
597 season.uc_hardtext = uc_season
599 -- manual weather
600 local weatherGr = actGr:find("weather")
601 assert(weatherGr)
602 local weatherManual = weatherGr:find("manual_weather")
603 assert(weatherManual)
604 weatherManual:find("toggle_butt").pushed = (act.ManualWeather == 0)
606 local weatherSlider = actGr:find("weather_slider")
607 assert(weatherSlider)
608 weatherSlider.active = (act.ManualWeather==1)
610 -- weather value
611 local weatherSlider = weatherGr:find("slider")
612 assert(weatherSlider)
613 weatherSlider.value = act.WeatherValue
615 -- notes
617 local notesGr = actGr:find("act_notes")
618 assert(notesGr)
619 local notesAct = notesGr:find("small_description")
620 assert(notesAct)
621 local uc_notes = ucstring()
622 uc_notes:fromUtf8(act.ShortDescription)
623 notesAct.uc_input_string = uc_notes
626 -- pre act notes
628 local notesGr = actGr:find("pre_act_notes")
629 assert(notesGr)
630 local notesAct = notesGr:find("small_description")
631 assert(notesAct)
632 local uc_notes = ucstring()
633 uc_notes:fromUtf8(act.PreActDescription)
634 notesAct.uc_input_string = uc_notes
638 -- budget
639 if act==r2:getCurrentAct() then
640 local entityBudgetText = scenarioUI:find("entity_budget_text")
641 local macroBudgetText = scenarioUI:find("macro_budget_text")
642 local ucBudget = ucstring()
643 ucBudget:fromUtf8(i18n.get("uiR2EDMacroComponentsInAct"):toUtf8() .. act:getName())
644 macroBudgetText.uc_hardtext = ucBudget
645 ucBudget:fromUtf8(i18n.get("uiR2EDEntitiesInAct"):toUtf8() .. act:getName())
646 entityBudgetText.uc_hardtext = ucBudget
651 --------------------- update scenario properties in scenario window -------------------------
652 function r2.ScenarioWindow:updateScenarioProperties()
654 self.lockComboBoxes = true
656 local scenario = r2.Scenario
658 local scenarioUI = self:getContainer()
659 assert(scenarioUI)
661 local scenarioGr = scenarioUI:find("scenario_properties")
662 assert(scenarioGr)
664 -- scenario level
665 local levelCB = scenarioGr:find("level_combo_box")
666 assert(levelCB)
667 levelCB.selection = r2.Scenario.Description.LevelId
670 local cb = scenarioGr:find("locked_combo_box")
671 assert(cb)
672 if r2.Scenario.Description.OtherCharAccess then
673 local access = r2.Scenario.Description.OtherCharAccess
674 cb.selection_text = i18n.get("uiR2ED".. access):toUtf8()
675 else
676 cb.selection_text = i18n.get("uiR2EDFull"):toUtf8()
681 if r2.Scenario.Description.NevraxScenario then
682 local ui = getUI("ui:interface:r2ed_palette")
683 assert(ui)
684 local widget = ui:find("nevrax_scenario")
685 assert(widget)
686 local ok = r2.Scenario.Description.NevraxScenario == "1"
687 widget:find("toggle_butt").pushed = not ok
690 if r2.Scenario.Description.TrialAllowed then
691 local ui = getUI("ui:interface:r2ed_palette")
692 assert(ui)
693 local widget = ui:find("trial_allowed_scenario")
694 assert(widget)
695 local ok = r2.Scenario.Description.TrialAllowed == "1"
696 widget:find("toggle_butt").pushed = not ok
699 if r2.Scenario.Description.MissionTag then
700 local ui = getUI("ui:interface:r2ed_palette")
701 assert(ui)
702 local widget = ui:find("mission_tag")
703 assert(widget)
704 local uc = ucstring()
705 uc:fromUtf8(scenario.Description.MissionTag)
706 widget:find("mission_tag_eb").eb.uc_input_string = uc
709 -- scenario rules
710 local rulesCB = scenarioGr:find("rules_combo_box")
711 if r2.Scenario.AccessRules == "strict" then
712 rulesCB.selection = 0
713 else
714 rulesCB.selection = 1
717 -- scenario language
718 local languageCB = scenarioGr:find("language_combo_box")
719 assert(languageCB)
720 languageCB.selection_text = i18n.get("uiR2ED"..r2.Scenario.Language):toUtf8()
722 -- scenario type
723 local typeCB = scenarioGr:find("type_combo_box")
724 assert(typeCB)
725 -- special case for old enums
726 if r2.Scenario.Type =="Combat" then
727 typeCB.selection_text = i18n.get("uiR2EDso_hack_slash"):toUtf8()
728 elseif r2.Scenario.Type =="Roleplay" then
729 typeCB.selection_text = i18n.get("uiR2EDso_story_telling"):toUtf8()
730 else
731 typeCB.selection_text = i18n.get("uiR2ED"..r2.Scenario.Type):toUtf8()
734 -- scenario title
735 local ucTitle = ucstring()
736 ucTitle:fromUtf8(scenario.Description.Title)
737 getUI("ui:interface:r2ed_scenario"):find("title_eb").eb.uc_input_string = ucTitle
739 -- scenario notes
740 local notesGr = scenarioGr:find("scenario_notes")
741 assert(notesGr)
742 local notesScenario = notesGr:find("small_description")
743 assert(notesScenario)
744 local uc_notes = ucstring()
745 uc_notes:fromUtf8(scenario.Description.ShortDescription)
746 notesScenario.uc_input_string = uc_notes
748 -- scenario name
749 local scenarioName = scenarioUI:find("scenario_name_text")
750 local uc_name = ucstring()
751 uc_name:fromUtf8(i18n.get("uiR2EDScenarioFilename"):toUtf8() .. " " ..ucstring(scenario:getName()):toUtf8())
752 scenarioName.uc_hardtext = uc_name
754 self.lockComboBoxes = false
757 --------------------- set scenario notes ----------------------------------------------------
758 function r2.ScenarioWindow:setScenarioNotes()
760 local scenarioUI = self:getContainer()
761 assert(scenarioUI)
763 local scenarioGr = scenarioUI:find("scenario_properties")
764 assert(scenarioGr)
766 local scenarioNotes = scenarioGr:find("scenario_notes"):find("small_description").uc_input_string:toUtf8()
768 if r2.Scenario and scenarioNotes~= r2.Scenario.Description.ShortDescription then
769 r2.requestNewAction(i18n.get("uiR2EDChangeScenarioDescription"))
770 r2.requestSetNode(r2.Scenario.Description.InstanceId, "ShortDescription", scenarioNotes)
771 r2.requestEndAction()
775 --------------------- set scenario level ----------------------------------------------------
776 function r2.ScenarioWindow:scenarioLevel()
777 if self.lockComboBoxes then return end
779 self:setScenarioNotes()
780 self:onTitleChanged()
782 local scenarioWnd = self:getContainer()
783 local levelCB = scenarioWnd:find("level_combo_box")
784 r2.requestNewAction(i18n.get("uiR2EDChangeScenarioLevel"))
785 r2.requestSetNode(r2.Scenario.Description.InstanceId, "LevelId", levelCB.selection)
786 r2.requestEndAction()
789 --------------------- set scenario rules ----------------------------------------------------
790 function r2.ScenarioWindow:scenarioRules()
791 if self.lockComboBoxes then return end
793 self:setScenarioNotes()
794 self:onTitleChanged()
796 local scenarioWnd = self:getContainer()
797 local rulesCB = scenarioWnd:find("rules_combo_box")
798 local rules = {[0]="strict", [1]="liberal"}
799 r2.requestNewAction(i18n.get("uiR2EDChangeScenarioRules"))
800 r2.requestSetNode(r2.Scenario.InstanceId, "AccessRules", rules[rulesCB.selection])
801 r2.requestEndAction()
804 ------------- set scenario language ----------------------------------------------------------
805 function r2.ScenarioWindow:scenarioLanguage()
807 if self.lockComboBoxes then return end
809 self:setScenarioNotes()
810 self:onTitleChanged()
812 local comboB = getUICaller()
813 local language = self.Languages[comboB.selection_text]
815 r2.requestNewAction(i18n.get("uiR2EDChangeScenarioLanguage"))
816 r2.requestSetNode(r2.Scenario.InstanceId, "Language", language)
817 r2.requestEndAction()
820 ------------- set scenario type ---------------------------------------------------------------
821 function r2.ScenarioWindow:scenarioType()
823 if self.lockComboBoxes then return end
825 self:setScenarioNotes()
826 self:onTitleChanged()
828 local comboB = getUICaller()
829 local type = self.Types[comboB.selection_text]
831 r2.requestNewAction(i18n.get("uiR2EDChangeScenarioType"))
832 r2.requestSetNode(r2.Scenario.InstanceId, "Type", type)
833 r2.requestEndAction()
836 ------------- set scenario type ---------------------------------------------------------------
837 function r2.ScenarioWindow:scenarioEditionLocked()
839 if self.lockComboBoxes then return end
841 self:setScenarioNotes()
842 self:onTitleChanged()
844 local comboB = getUICaller()
846 local type = self.Locked[comboB.selection_text]
847 -- RoS not usefull anymore
848 if type == "RoSOnly" and config.R2EDExtendedDebug ~= 1 then
849 type = "Full"
850 self.lockComboBoxes = true
851 comboB.selection_text = i18n.get("uiR2EDFull")
852 self.lockComboBoxes = false
854 r2.requestNewAction(i18n.get("uiR2EDChangeScenarioEditionLock"))
855 r2.requestSetNode(r2.Scenario.Description.InstanceId, "OtherCharAccess", type)
856 r2.requestEndAction()
858 --------------------------------------------------------------------------
859 -- the scenario title was changed by the user
860 function r2.ScenarioWindow:onTitleChanged()
861 if self.lockComboBoxes then return end
862 local newTitle = getUI("ui:interface:r2ed_scenario"):find("title_eb").eb.uc_input_string:toUtf8()
863 if newTitle ~= r2.Scenario.Description.Title then
864 r2.requestNewAction(i18n.get("uiR2EDChangeScenarioTitle"))
865 r2.requestSetNode(r2.Scenario.Description.InstanceId, "Title", newTitle)
866 r2.requestEndAction()
870 ----------------------- cancel focus on text of all edit box when select a new tab --------------
871 function r2.ScenarioWindow:cancelFocusOnText()
872 local editBox = getUICaller()
873 assert(editBox)
874 editBox:cancelFocusOnText()
879 --------------------- set nevrax scenario ----------------------------------------------------
880 function r2.ScenarioWindow:nevraxScenario()
881 if self.lockComboBoxes then return end
882 if config.R2EDExtendedDebug ~= 1 then return end
884 local scenarioUI = getUI("ui:interface:r2ed_palette")
885 assert(scenarioUI)
887 local widget = scenarioUI:find("nevrax_scenario")
888 assert(widget)
891 local val = "0"
892 if widget:find("toggle_butt").pushed then val = "0" else val = "1" end
894 self:setScenarioNotes()
895 self:onTitleChanged()
898 r2.requestNewAction(i18n.get("uiR2EDChangeScenarioNevraxTag"))
899 r2.requestSetNode(r2.Scenario.Description.InstanceId, "NevraxScenario", val)
900 r2.requestEndAction()
905 --------------------- set nevrax scenario ----------------------------------------------------
906 function r2.ScenarioWindow:trialAllowed()
907 if self.lockComboBoxes then return end
908 if config.R2EDExtendedDebug ~= 1 then return end
910 local ui = getUI("ui:interface:r2ed_palette")
911 assert(ui)
913 local widget = ui:find("trial_allowed_scenario")
914 assert(widget)
916 local val = "0"
917 if widget:find("toggle_butt").pushed then val = "0" else val = "1" end
919 self:setScenarioNotes()
920 self:onTitleChanged()
922 r2.requestNewAction(i18n.get("uiR2EDChangeTrialAllowedTag"))
923 r2.requestSetNode(r2.Scenario.Description.InstanceId, "TrialAllowed", val )
924 r2.requestEndAction()
928 --------------------------------------------------------------------------
929 -- the scenario title was changed by the user
930 function r2.ScenarioWindow:onScenarioMissionTagChanged()
931 if self.lockComboBoxes then return end
932 if config.R2EDExtendedDebug ~= 1 then return end
933 local newTag = getUI("ui:interface:r2ed_palette"):find("mission_tag"):find("mission_tag_eb").eb.uc_input_string:toUtf8()
935 self:setScenarioNotes()
936 self:onTitleChanged()
938 if newTag ~= r2.Scenario.Description.MissionTag then
939 r2.requestNewAction(i18n.get("uiR2EDChangeMissionTag"))
940 r2.requestSetNode(r2.Scenario.Description.InstanceId, "MissionTag", newTag)
941 r2.requestEndAction()