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
12 LeftStaticQuota
= nil,
19 lockComboBoxes
= false,
20 -- chosen act in combo box
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")
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
))
48 table.sort(languages2
)
49 languageCB
:resetTexts()
50 for k
, lang
in pairs(languages2
) do
51 languageCB
:addText(lang
)
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))
62 for k
, type in pairs(types2
) do
69 if config
.R2EDExtendedDebug
== 1 then
70 table.insert(locked
, "RoSOnly")
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))
78 for k
, type in pairs(tmp
) do
87 levelCB
:addText(i18n
.get("uiRAP_Level".. tostring(i
)))
91 rulesCB
:addText(i18n
.get("uiR2EDstrict"))
92 rulesCB
:addText(i18n
.get("uiR2EDliberal"))
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()
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())
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
143 function r2
.ScenarioWindow
:getLeftQuota()
144 if r2
.UIMainLoop
.LeftQuotaModified
then
145 self
:updateLeftQuota()
148 if self
.LeftQuota
< self
.LeftStaticQuota
then
149 quota
= self
.LeftQuota
151 quota
= self
.LeftStaticQuota
153 return quota
, self
.LeftQuota
, self
.LeftStaticQuota
156 -----------------------------------------------------------------------------------------------------------
157 -- update display of left quota for the current act
158 function r2
.ScenarioWindow
:updateLeftQuota()
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()
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))
196 quotaViewText
.hardtext
= ""
197 quotaMacroViewText
.hardtext
= ""
199 r2
.UIMainLoop
.LeftQuotaModified
= false
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
)
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
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
))
264 tree
.active
= (tree
== currentAct
:getContentTree())
266 local macroTree
= container
:find("macro_act_tree_" .. tostring(i
))
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"))
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
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
]
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
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
]
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")
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()
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
)
463 local scenarioUI
= self
:getContainer()
466 local actGr
= scenarioUI
:find("act_properties")
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
)
494 local scenarioUI
= self
:getContainer()
497 local actGr
= scenarioUI
:find("act_properties")
500 local manualButton
= actGr
:find("manual_weather"):find("toggle_butt")
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
)
517 local scenarioUI
= self
:getContainer()
520 local actGr
= scenarioUI
:find("act_properties")
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
548 self
.showedActId
= act
.InstanceId
550 self
:updateActProperties()
552 local goButton
= self
:getContainer():find("go_to_act")
554 goButton
.active
= (act
~=r2
:getCurrentAct())
556 local deleteButton
= self
:getContainer():find("delete_act")
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
)
566 assert((not act
:isBaseAct()))
570 local scenarioUI
= self
:getContainer()
573 local actGr
= scenarioUI
:find("act_properties")
577 local location
= r2
:getInstanceFromId(act
.LocationId
)
578 if location
==nil then return end
579 local locationName
= actGr
:find("location_name")
581 local uc_location
= ucstring()
582 uc_location
:fromUtf8(location
.Name
)
583 locationName
.uc_hardtext
= uc_location
587 ["Spring"] = "uiR2EDSpring",
588 ["Summer"] = "uiR2EDSummer",
589 ["Autumn"] = "uiR2EDAutumn",
590 ["Winter"] = "uiR2EDWinter"
592 local season
= actGr
:find("season_name")
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
600 local weatherGr
= actGr
:find("weather")
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)
611 local weatherSlider
= weatherGr
:find("slider")
612 assert(weatherSlider
)
613 weatherSlider
.value
= act
.WeatherValue
617 local notesGr
= actGr
:find("act_notes")
619 local notesAct
= notesGr
:find("small_description")
621 local uc_notes
= ucstring()
622 uc_notes
:fromUtf8(act
.ShortDescription
)
623 notesAct
.uc_input_string
= uc_notes
628 local notesGr
= actGr
:find("pre_act_notes")
630 local notesAct
= notesGr
:find("small_description")
632 local uc_notes
= ucstring()
633 uc_notes
:fromUtf8(act
.PreActDescription
)
634 notesAct
.uc_input_string
= uc_notes
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()
661 local scenarioGr
= scenarioUI
:find("scenario_properties")
665 local levelCB
= scenarioGr
:find("level_combo_box")
667 levelCB
.selection
= r2
.Scenario
.Description
.LevelId
670 local cb
= scenarioGr
:find("locked_combo_box")
672 if r2
.Scenario
.Description
.OtherCharAccess
then
673 local access
= r2
.Scenario
.Description
.OtherCharAccess
674 cb
.selection_text
= i18n
.get("uiR2ED".. access
):toUtf8()
676 cb
.selection_text
= i18n
.get("uiR2EDFull"):toUtf8()
681 if r2
.Scenario
.Description
.NevraxScenario
then
682 local ui
= getUI("ui:interface:r2ed_palette")
684 local widget
= ui
:find("nevrax_scenario")
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")
693 local widget
= ui
:find("trial_allowed_scenario")
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")
702 local widget
= ui
:find("mission_tag")
704 local uc
= ucstring()
705 uc
:fromUtf8(scenario
.Description
.MissionTag
)
706 widget
:find("mission_tag_eb").eb
.uc_input_string
= uc
710 local rulesCB
= scenarioGr
:find("rules_combo_box")
711 if r2
.Scenario
.AccessRules
== "strict" then
712 rulesCB
.selection
= 0
714 rulesCB
.selection
= 1
718 local languageCB
= scenarioGr
:find("language_combo_box")
720 languageCB
.selection_text
= i18n
.get("uiR2ED"..r2
.Scenario
.Language
):toUtf8()
723 local typeCB
= scenarioGr
:find("type_combo_box")
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()
731 typeCB
.selection_text
= i18n
.get("uiR2ED"..r2
.Scenario
.Type
):toUtf8()
735 local ucTitle
= ucstring()
736 ucTitle
:fromUtf8(scenario
.Description
.Title
)
737 getUI("ui:interface:r2ed_scenario"):find("title_eb").eb
.uc_input_string
= ucTitle
740 local notesGr
= scenarioGr
:find("scenario_notes")
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
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()
763 local scenarioGr
= scenarioUI
:find("scenario_properties")
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
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()
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")
887 local widget
= scenarioUI
:find("nevrax_scenario")
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")
913 local widget
= ui
:find("trial_allowed_scenario")
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()