should be called by a widget")
- return
- end
- local container = getUICaller().parent:getEnclosingContainer()
- if container.Env.Form ~= nil then
- -- this is a form (update is done in local)
- local form = container.Env.Form
- local prop = form.NameToProp[propName]
- if prop.convertFromWidgetValue ~= nil then
- -- if there's a conversion function then use it
- value = prop.convertFromWidgetValue(value)
- end
- container.Env.FormInstance[propName] = value
- container.Env.setter(propName, value)
- else
- -- this is a property sheet
- local target = r2:getPropertySheetTarget()
- local class = r2:getClass(target)
- local prop = class.NameToProp[propName]
- --debugInfo(string.format("Setting node : prop name = %s, value = %s", tostring(propName), tostring(value)))
- r2.requestRollbackLocalNode(target.InstanceId, propName)
- end
- -- no op for forms (no 'commit' notion)
-end
-
--------------------------------------------------------------------------------------
--- get the object whose property sheet is currently displayed
--- should be used only with property sheets
-function r2:getPropertySheetTarget()
- if not r2.CurrentPropertyWindow then return nil end
- -- can only be the selection for now ...
- return r2.CurrentPropertyWindow.Env.TargetInstance
-end
-
-
-------------------------------------------------------------------------------------------------------------
--- get name of ui for default property sheet from the class name
-function r2:getDefaultPropertySheetUIPath(className)
- return "ui:interface:r2ed_property_sheet_" .. className
-end
-
-------------------------------------------------------------------------------------------------------------
--- get definition of property edited from its widget
-function r2:getPropertyDefinition(propName, uiCaller)
- -- useful infos are stored in the parent container
- assert(uiCaller)
- local container = uiCaller:getEnclosingContainer()
- if container.Env.Form ~= nil then
- -- this is a form (update is done in local)
- return container.Env.Form.NameToProp[propName]
- else
- -- this is a property sheet
- local target = r2:getPropertySheetTarget()
- local class = r2:getClass(target)
- return class.NameToProp[propName]
- end
-end
-
-
-
-
-------------------------------------------------------------------------------------------------------------
--- return pointer to a property sheet of an object from its class name
-function r2:getPropertySheet(instance)
- local class = instance:getClass()
- local uiPath = r2:evalProp(class.PropertySheetUIPath, instance, r2:getDefaultPropertySheetUIPath(class.Name))
- return getUI(uiPath)
-end
-
-------------------------------------------------------------------------------------------------------------
--- get a form from its name
-function r2:getForm(name)
- assert(name) -- why is name nil???
- return getUI("ui:interface:r2ed_form_" .. name)
-end
-
---/////////////////////
---// NUMBER WIDGETS //
---/////////////////////
-
--- widget styles for 'Numbers'
-r2.WidgetStyles.Number =
-{
- --------------------------------------------------------------------------------------------------------------------
- Default = function(prop, className)
- local function setter(widget, prop, value)
- widget.eb.input_string = tostring(value)
- widget.eb.Env.CurrString = tostring(value)
- end
- local onChangeAction =
- string.format(
- [[
- local editBox = getUICaller()
- if editBox.input_string == editBox.Env.CurrString then
- return
- end
- editBox.Env.CurrString = editBox.input_string
- local newValue = tonumber(getUICaller().input_string)
- if newValue == nil then
- debugInfo('Invalid number value : ' .. getUICaller().input_string)
- return
- end
- local prop = r2:getPropertyDefinition('%s', getUICaller())
- assert(prop)
- local clamped = false
- if prop.Min and newValue < tonumber(prop.Min) then
- newValue = tonumber(prop.Min)
- clamped = true
- end
- if prop.Max and newValue > tonumber(prop.Max) then
- newValue = tonumber(prop.Max)
- clamped = true
- end
- if clamped then
- editBox.input_string = tostring(newValue)
- editBox.Env.CurrString = tostring(newValue)
- end
- r2:requestSetObjectProperty('%s', newValue)
- ]], prop.Name, prop.Name)
- return r2:buildEditBox(prop, "TR TR", "integer", false, 16, onChangeAction, onChangeAction), setter, nil
- end,
- --------------------------------------------------------------------------------------------------------------------
- Boolean = function(prop, className)
- local function setter(widget, prop, value)
- --debugInfo("setter : " .. tostring(value))
- -- widget is a pointer to the enclosing group
- if value == 1 then
- value = true
- else
- value = false
- end
- widget.butt.pushed = value
- --widget.text_true.active = value
- --widget.text_false.active = not value
- end
- local function buildCoverAllButton(prop)
- return [[
- ]]
- end
--- local widgetXml =
--- string.format([[
---
---
---
---
---
--- ]], prop.Name, prop.Name)
- local widgetXml =
- string.format([[
- ]]
- .. buildCoverAllButton(prop) .. [[
-
-
- ]], prop.Name, prop.Name)
- -- Caption is special here :
- -- It contains a button to avoid to have to click in the tiny checkbox, which is inconvenient
- local iwidth0 = defaulting(prop.CaptionWidth, 35)
- local width0 = string.format("%d%%", iwidth0)
- local width1 = string.format("%d%%", 100 - iwidth0)
- local invertWidget = defaulting(prop.InvertWidget, false)
-
- if invertWidget then
- local tmp = width0
- width0 = width1
- width1 = tmp
- end
-
- local part0 = [[ ]]
-
-
- local tooltipTextId, tooltipTextIdFound = buildPropTooltipName(className, prop.Name)
- part0 = part0 .. [["
- part0 = part0 .. buildCoverAllButton(prop)
-
- local color = "255 255 255 255"
- local globalColor = "true"
- local hardText
- local found
- hardText, found = r2:getPropertyTranslationId(prop)
- if not found and config.R2EDExtendedDebug == 1 then
- color = "255 0 0 255"
- globalColor = "false"
- hardText = hardText .. " (NOT TRANSLATED)"
- end
-
- part0 = part0 .. [[ ]]
- part0 = part0 .. ""
- part0 = part0 .. " | "
-
- --dumpSplittedString(widgetXml)
- return widgetXml, setter, part0
- end,
- --------------------------------------------------------------------------------------------------------------------
- Slider = function(prop, className)
- local function setter(widget, prop, value)
- if widget.c.value ~= nil then
- widget.c.value = value
- end
- end
- --
- local widgetXml =
- string.format([[
- " .. [[
-
-
-
-
-
-
-
-
-
-
-
- ""
-
- ""
- ]], prop.Name, prop.Name, prop.Name, defaulting(prop.Min, 0), defaulting(prop.Max, 100), defaulting(prop.StepValue, 1),
- defaulting(prop.ActiveBitmaps, 'false'), defaulting(prop.LeftBitmap, ""), defaulting(prop.MiddleBitmap, ""), defaulting(prop.RightBitmap, ""))
- --
- --debugInfo(string.format("Creating slider widget, min = %s, max = %s", defaulting(prop.Min, 0), defaulting(prop.Min, 100)))
- return widgetXml, setter
- end,
- --------------------------------------------------------------------------------------------------------------------
- EnumDropDown = function(prop, className)
- if type(prop.Enum) ~= "table" then
- debugInfo("Can't create enum combo box, the 'Enum' table is not found or of bad type")
- return ""
- end
- local function setter(widget, prop, value)
- if widget.selection ~= nil then
- widget.parent.Env.Locked = true
- widget.selection = value
- widget.parent.Env.Locked = false
- end
- end
- local result =
- [[
- "
- result = result .. [[]]
- -- append enumerated values
-
- for k, v in pairs(prop.Enum) do
- result = result .. [[]]
- end
- result = result .. ""
- return result, setter
- end,
-}
-
-
-------------------------------------------------------------------------------------------------------------
--- build a widget from the definition of the property
-function r2:buildPropWidget(prop, className)
- local widgetFactory = r2.WidgetStyles[prop.Type]
- if widgetFactory == nil then
- --debugInfo("Type '" .. tostring(prop.Type) .. "' not found. Widget not built")
- return nil
- end
- local widgetStyle = prop.WidgetStyle
- if widgetStyle == nil then
- widgetStyle = "Default"
- end
- if widgetFactory[widgetStyle] == nil then
- debugInfo("Widget style '" .. tostring(widgetStyle) .. "' not found for type '" .. tostring(prop.Type) ..
- "', widget not built" )
- return nil
- end
- local result, setter, caption = widgetFactory[widgetStyle](prop, className)
- -- add common functionnality of setter
- if setter ~= nil then
- -- if there's a conversion function on set, then call it
- if prop.convertToWidgetValue ~= nil then
- if type(setter) == "function" then
- local oldSetter = setter
- setter = function(widget, prop, value)
- oldSetter(widget, prop, prop.convertToWidgetValue(value))
- end
- else
- assert(type(setter) == "table")
- if (setter.onSet) then
- local oldSetter = setter.onSet
- function setter:onSet(widget, prop, value)
- self:oldSetter(widget, prop, prop.convertToWidgetValue(value))
- end
- end
- end
- end
- end
- return result, setter, caption
-end
-
-------------------------------------------------------------------------------------------------------------
--- create a table of properties
-function r2:createPropertyXmlTable(props, className, posparent, posref, x, y, widgetEventHandlerTable)
- local result = "" -- the resulting xml
- -- add a new string to the resulting string
- local function add(value)
- result = result .. value
- end
- add([[
- ]])
-
- for key, prop in pairs(props) do
- local widgetXmlDesc, setter, captionXmlDesc = self:buildPropWidget(prop, className)
- if widgetXmlDesc ~= nil then
- add("")
- -- build the caption
- local color = "255 255 255 255"
- local globalColor = "true"
- --if SeenNames[prop.Name] == nil then
- -- debugInfo(prop.Name)
- -- SeenNames[prop.Name] = true
- --end
-
- local hardText
- local found
- hardText, found = r2:getPropertyTranslationId(prop)
- if not found and config.R2EDExtendedDebug == 1 then
- color = "255 0 0 255"
- globalColor = "false"
- hardText = hardText .. " (NOT TRANSLATED)"
- end
- --
- local iwidth0 = defaulting(prop.CaptionWidth, 35)
- local width0 = string.format("%d%%", iwidth0)
- local width1 = string.format("%d%%", 100 - iwidth0)
- local invertWidget = defaulting(prop.InvertWidget, false)
-
- if invertWidget then
- local tmp = width0
- width0 = width1
- width1 = tmp
- end
-
- local tooltipTextId, tooltipTextIdFound = buildPropTooltipName(className, prop.Name)
- --debugInfo(string.format("%60s %s", tooltipTextId, " [@{F00F} FILL ME ! :" .. prop.Name .. "]"))
-
- local part0
- if not captionXmlDesc then
- part0 = [[ ]]
-
- part0 = part0 .. [["
- part0 = part0 .. [[ ]]
- part0 = part0 .. ""
- part0 = part0 .. " | "
- else
- part0 = captionXmlDesc
- end
-
- -- build the widget
- local part1 = [[ ]]
- part1 = part1 .. [["
- part1 = part1 .. widgetXmlDesc .. [[ | ]]
-
- if invertWidget then
- add(part1 .. part0)
- else
- add(part0 .. part1)
- end
- -- add the setter function in the table
- --debugInfo("inserting entry" .. prop.Name)
- if type(setter) == "function" then
- -- setter is a plain 'set' function
- -- => event handler is a simple table with a 'onSet' method ...
- widgetEventHandlerTable[prop.Name] =
- {
- onSet= function(this, widget, prop, value)
- setter(widget, prop, value)
- end
- }
- else
- -- debugInfo(prop.Name .. " : " .. type(setter))
- -- setter is a complete object (a lua table) with event handling methods
- if type(setter) ~= "table" then
- debugInfo(type(setter))
- inspect(setter)
- assert(0)
- end
- widgetEventHandlerTable[prop.Name] = setter
- end
- add("
")
- end
- end
- add([[]])
- return result
-end
-
-------------------------------------------------------------------------------------------------------------
--- build xml for a rollout containing a table of properties
-function r2:buildPropRolloutXml2(className, caption, id, posparent, posref, props, rolloutY, widgetEventHandlerTable, isForm)
- local content = self:createPropertyXmlTable(props, className, "caption", "BL TL", 0, -4, widgetEventHandlerTable)
- -- todo : use something more clear than string.format !!!
- local global_color_over = "255 255 255 192"
- local params_l = "r2:openCloseRollout('prop_table')"
- if isForm then
- global_color_over = "127 127 127 127"
- params_l = ""
- end
- local result = string.format(
- [[
-
-
- ]], id, rolloutY, posparent, posref, global_color_over, params_l)
-
-
- if not isForm then
- result = result ..
- string.format([[
-
-
-
-
- ]], caption)
- else
- result = result ..
- string.format([[]], caption)
- end
-
- result = result .. string.format(
- [[
-
-
-
-
-
- %s
-
- ]],content)
-
- return result
-end
-
--- build xml for a rollout containing a table of properties
-function r2:buildPropRolloutXml(caption, id, posparent, posref, props, className, rolloutY, widgetEventHandlerTable, isForm)
- local content = self:createPropertyXmlTable(props, className, "caption", "BL TL", 0, -4, widgetEventHandlerTable)
- -- add the caption
- local result = string.format(
- [[ ]], id, rolloutY, posparent, posref)
-
- local color = "255 255 255 255"
- local globalColor = "true"
- --if SeenRolloutCaptions[caption] == nil then
- -- debugInfo(caption)
- -- SeenRolloutCaptions[caption] = true
- --end
- if not i18n.hasTranslation(caption) then
- if config.R2EDExtendedDebug == 1 then
- color = "255 0 0 255"
- globalColor = "false"
- caption = caption .. "(NOT TRANSLATED)"
- end
- end
-
- -- add the rollout bar
- if not isForm then
- result = result ..
- [[ ]]
- else
- result = result ..
- [[ ]]
- end
-
- -- add the content
- result = result .. content
-
- -- close
- result = result .. ""
-
- return result
-end
-
-
-
-
-
-----------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------
--- Generation of property sheet ui xml code from a class definition
--- this function will return 2 values :
--- xml code to generate the dialog to edit instance of the class
--- A registration function for that dialog, that must be called prior to use (and once the ui has been created from the xml code)
--- Note : Registration isn't done at creation in order to pack several class descriptions in
--- a single xml script to speed up parsing
-
-function r2:buildPropertySheetXml(class, className, id, title, isForm)
-
- -- The following table contains for each property a set method that allow to change it from the outside
- -- these value is filled by each widget "ctor" function.
- -- In a similar way, each widget is given a setter function.
- local widgetEventHandlerTable = {}
- --
- --local function dump()
- -- for key, value in pairs(widgetEventHandlerTable) do
- -- debugInfo('*')
- -- debugInfo(tostring(key, value))
- -- end
- --end
- --
- local result = "" -- the resulting xml
- -- add a new string to the resulting string
- local function add(value)
- result = result .. value
- end
-
-
- local rolloutsX = 12
- local rolloutsW = -14
- if isForm then
- rolloutsX = 0
- rolloutsW = -2
- end
-
-
-
-
- add(
- [[
- ]])
-
-
-
- if className == "NpcCustom" then
- add(
- [[
-
- ]])
- elseif r2.hasDisplayInfo(className) == 1 or string.find(className, "_Form") ~= nil then
- debugInfo("Adding help header for "..className)
- local featureName = className
- if string.find(className, "_Form") ~= nil then
- local len = string.len(featureName)
- featureName = string.sub(featureName, 1, len - 5)
- end
-
- add(
- [[
-
- ]])
- else
- add([[]])
- end
-
-
- add([[
-
-
-
-
-
- ]])
-
-
-
- -- sort properties by category
- local categories = {}
- local numCategories = 0
- for key, prop in pairs(class.Prop) do
- if prop.Visible ~= false then
- local category = prop.Category
- if category == nil then
- category = "uiR2EDRollout_Default"
- end
- if categories[category] == nil then
- --debugInfo("Adding new category " .. tostring(category))
- -- create a new table if no entries for that category of properties
- categories[category] = {}
- numCategories = numCategories + 1
- end
- table.insert(categories[category], prop)
- end
- end
-
- local posparent = "parent"
- local posref= "TL TL"
- local rolloutY = -4
-
- -- if there's a xml property sheet header, use it
- if class.PropertySheetHeader then
- -- enclose the header in a group to keep good width
-
- add([[]]
- )
- posref="BL TL"
- posparent="sheet_header"
- end
-
- -- if there's just a 'default' category, then don't create a rollout
- if numCategories == 1 and categories["uiR2EDRollout_Default"] ~= nil then
- add(self:createPropertyXmlTable(categories["uiR2EDRollout_Default"], className, posparent, posref, 0, rolloutY, widgetEventHandlerTable))
- posparent="prop_table"
- else
- -- add each rollout and its properties
- rolloutY = -2
- local categoryIndex = 0
- for k, v in pairs(categories) do
- add(self:buildPropRolloutXml(k, tostring(categoryIndex), posparent, posref, v, className, rolloutY, widgetEventHandlerTable, isForm))
- posparent = tostring(categoryIndex)
- posref ="BL TL"
- rolloutY = -4
- categoryIndex = categoryIndex + 1
- end
- end
-
- -- if the dialog is a form, then add 'ok' & 'cancel' button
- if isForm then
- add([[
-
-
-
- ]])
- end
-
-
- -- close the dialog
- add([[ ]])
- if not isForm then
- -- scroll bar for property sheet only
- add([[ ]])
- end
- add([[
-
-
-
-
-
- ]])
-
-
---///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
---///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
- -- THE REGISTRATION FUNCTION, called after the ui has been created for real from the xml definition
- local function registrationFunction()
- local propertySheet = getUI("ui:interface:" .. id) -- tmp : hardcoded name here
- local form = propertySheet -- alias, if the dialog is actually a form
- local propNameToWidget = {}
- local propNameToLCaption= {}
- local propNameToRCaption= {}
- -- keep a pointer to each widget
- -- can only do it now, because this registration is called only once the ui has been created
- for k, prop in pairs(class.Prop) do
- propNameToWidget[prop.Name] = propertySheet:find(prop.Name)
- propNameToLCaption[prop.Name] = propertySheet:find("l_" .. prop.Name)
- propNameToRCaption[prop.Name] = propertySheet:find("r_" .. prop.Name)
- end
- -- Fucntion to retrieve a reference on the currently edited object
- local function getTargetInstance()
- if isForm then
- return form.Env.FormInstance
- else
- return r2:getPropertySheetTarget()
- end
- end
- ------------------------------------------------------
- if propertySheet ~= nil then -- should not be nil if parsing succeeded
- -- create a handleEvent function and put it in the lua environment of the property sheet
- -- (in the C++ code, each group in the interface, such as a container, has a 'Env' lua table attached to it)
- function propertySheet.Env.handleEvent(eventName, attributeName, args)
- -- TODO nico : arrays not handled yet
- if propertySheet.active == false then
- return -- no update if dialog not visible (updateAll() is called when dialog is shown again)
- end
- local targetInstance = getTargetInstance()
- local widgetEventHandler = widgetEventHandlerTable[attributeName] -- closure here : use locally defined widgetEventHandlerTable
- if widgetEventHandler == nil then
- return -- no display for that widget
- end
- local handlingMethod = widgetEventHandler[eventName]
- if handlingMethod == nil then
- -- no handler for this event, just return
- debugInfo("Event not handled for : " .. attributeName)
- inspect(getTargetInstance())
- return
- end
- local propWidget = propNameToWidget[attributeName] -- closure here : use locally defined propertySheet
- -- find the name of the widget by its id
- if propWidget == nil then
- debugInfo("Can't retrieve widget associated with property '" .. attributeName .. "'")
- return
- end
- -- call the actual event handler with the widget as its first parameter
- handlingMethod(widgetEventHandler, propWidget, class.NameToProp[attributeName], getTargetInstance()[attributeName], unpack(args))
- end
- local handleEventFunction = propertySheet.Env.handleEvent
- -- syntaxic sugar : 'setter' function for simple set operation
- function propertySheet.Env.setter(attributeName, value)
- table.clear(eventArgs)
- table.insert(eventArgs, value)
- handleEventFunction("onSet", attributeName, eventArgs)
- end
- local setter = propertySheet.Env.setter
- ------------------------------------------------------------------------------------------------------------------
- -- this function is called when the property sheet is shown for the first time
- -- in order to update its content
- local function updateAll()
- --debugInfo("updateAll")
- local target = getTargetInstance()
- if not target then return end -- 'updateAll' will be triggered at init time when
- -- windows are positionned
- for k, prop in pairs(class.Prop) do
- -- update the 'visible' state of each property
- local active = true
- if type(prop.Visible) == "function" then
- active = prop.Visible(target)
-
-
- local oldActive = propNameToLCaption[prop.Name].active
- propNameToLCaption[prop.Name].active = active
- propNameToRCaption[prop.Name].active = active
-
- if oldActive ~= active then
- propNameToLCaption[prop.Name]:invalidateCoords()
- propNameToLCaption[prop.Name]:updateCoords()
- end
-
-
- end
- setter(prop.Name, target[prop.Name]) -- retrieve value from object and assign to setter
- end
- propertySheet:invalidateCoords()
- propertySheet:updateCoords()
- debugInfo("*")
- end
-
- propertySheet.Env.updateAll = updateAll
- end
- ------------------------------------------------------------------------------------------------------------------
- -- this function is called by forms or proprty sheets to update visible properties
- -- when visibility depends on other properties
- local function updatePropVisibility()
- local target = getTargetInstance()
- local modified = false
- for k, prop in pairs(class.Prop) do
- -- update the 'visible' state of each property
- local active = true
- if type(prop.Visible) == "function" then
- local active = prop.Visible(target)
- if active ~= propNameToLCaption[prop.Name].active then
- modified = true
- propNameToLCaption[prop.Name].active = active
- propNameToRCaption[prop.Name].active = active
- propNameToRCaption[prop.Name]:invalidateContent()
- end
- end
- end
- return modified
- end
- ------------------------------------------------------
- propertySheet.active = false
- -- if this is a form, then the dialog should be resized when text is entered (for multi line texts)
- -- (else no-op for update coords)
- -- We should resize it by script, because by default, container impose size of their children
- if isForm then
- function propertySheet.Env.updateSize()
- local rollouts = propertySheet:find("rollouts")
- local deltaH = 40
- propertySheet:invalidateCoords()
- propertySheet:updateCoords()
- local newHReal = rollouts.h_real
- -- must resize the parent
- local newH = newHReal + deltaH
- local yOffset = newH - propertySheet.h
- --propertySheet.h = newH
- propertySheet.y = propertySheet.y + yOffset / 2
- propertySheet.pop_min_h = newH
- propertySheet.pop_max_h = newH
- propertySheet:invalidateCoords()
- propertySheet:updateCoords()
- end
- propertySheet.Env.updatePropVisibility = function()
- local modified = updatePropVisibility() -- call local function defined above
- -- for forms, update size if content was modified
- if modified then
- propertySheet.Env.updateSize()
- end
- end
- else
- propertySheet.Env.updatePropVisibility = updatePropVisibility -- call local function defined above
- function propertySheet.Env.updateSize()
- -- no op for property sheet (user can change the size of the window)
- end
- end
- end
-
-
- return result, registrationFunction
-end
-
---///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
---///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-
-------------------------------------------------------------------------------------------------------------
--- called when the user has clicked on a rollout
--- TODO nico : also used by the scenario window, so factor the code
-function r2:setRolloutOpened(rollout, content, opened)
- if not rollout or not content then
- debugInfo("r2:setRolloutOpened : rollout or content is nil")
- return
- end
- content.active = opened
- rollout:find("open_indicator").opened.active = opened
- rollout:find("open_indicator").closed.active = not opened
-end
-
-
-------------------------------------------------------------------------------------------------------------
-function r2:buildAllPropertySheetsAndForms()
- -- TMP TMP
- --SeenNames = {}
- --SeenRolloutCaptions = {}
- local xmlScript = ""
- local registrationFunctions = {}
- --debugInfo('building property sheets')
- local mustReparse = false
- for k, class in pairs(r2.Classes) do
- -- only build if class require a property sheet
- --if class.BuildPropertySheet == true then
- if true then
- -- to avoid costly parsing, see in the cache if the class was not already parsed
- local mustRebuild = true
- local propSheetCacheInfo
- if class.ClassMethods then
- propSheetCacheInfo = class.ClassMethods.getGenericPropertySheetCacheInfos(class)
- if r2ClassDescCache[class.Name] ~= nil then
- if isEqualIgnoreFunctions(r2ClassDescCache[class.Name], propSheetCacheInfo) then
- mustRebuild = false
- else
- debugInfo("Class " .. class.Name .. " found in cache, but different, rebuilding")
- end
- end
- end
- local result, registerFunc = r2:buildPropertySheetXml(class, class.Name, "r2ed_property_sheet_" .. class.Name, "uiR2EDProperties", false)
- table.insert(registrationFunctions, registerFunc)
- if mustRebuild then
- xmlScript = xmlScript .. result
- mustReparse = true
- r2ClassDescCache[class.Name] = propSheetCacheInfo -- update cache
- --debugInfo("Rebuilding property sheet")
- end
- end
- end
-
-
- -- register feature Forms
- do
- local k, feature = next (r2.Features, nil)
- while k do
- if feature.registerForms then
- feature.registerForms()
- end
- k, feature = next (r2.Features, k)
- end
- end
-
- -- register userComponentManager forms
- do
- if r2_core.UserComponentManager then
- debugInfo("Registering UserComponentManager forms...")
- r2_core.UserComponentManager.registerForms()
- end
- end
-
- --debugInfo('building forms')
- if r2.Forms ~= nil then
- for formName, form in pairs(r2.Forms) do
- local mustRebuild = true
- if r2FormsCache[formName] ~= nil then
- if isEqualIgnoreFunctions(r2FormsCache[formName], form.Prop) then
- mustRebuild = false
- end
- end
- local result, registerFunc = r2:buildPropertySheetXml(form, formName, "r2ed_form_" .. formName, "uiR2EDForm", true)
- table.insert(registrationFunctions, registerFunc)
- if mustRebuild then
- xmlScript = xmlScript .. result
- mustReparse = true
- r2FormsCache[formName] = form.Prop -- updating cache
- --debugInfo("Rebuilding property form")
- end
- end
- end
- --debugInfo('parsing')
- if mustReparse then
- debugInfo(colorTag(255, 0, 255) .. "Reparsing generated xml")
- local startTime = nltime.getLocalTime()
- -- TMP TMP
- --local f = io.open("testui.log", "w")
- --f:write(r2:encloseXmlScript(xmlScript))
- --f:flush()
- --f:close()
- parseInterfaceFromString(ucstring(r2:encloseXmlScript(xmlScript)):toUtf8())
- local endTime = nltime.getLocalTime()
- debugInfo(string.format("Reparsing generated xml took %f second", (endTime - startTime) / 1000))
- end
- -- do the registration
- for k, regFunc in pairs(registrationFunctions) do
- regFunc()
- end
- -- center all windows at start
- local function initPropertySheetPos(wnd)
- if wnd == nil then return end
- wnd.active = true
- r2:initDefaultPropertyWindowPosition(wnd) -- position definition in r2_ui_windows.lua
- wnd.active = false
- end
- --
- for k, class in pairs(r2.Classes) do
- -- only build if class require a property sheet
- if class.BuildPropertySheet == true then
- --debugInfo('*3')
- local wnd = getUI(r2:getDefaultPropertySheetUIPath(class.Name))
- if wnd ~= nil then
- r2:adjustPropertySheetTitleClampSize(wnd)
- initPropertySheetPos(wnd)
- end
- end
- end
- if r2.Forms ~= nil then
--- for formName, form in pairs(r2.Forms) do
- for formName, form in pairs(r2.Forms) do
- local wnd = r2:getForm(formName)
- if wnd then
-
- -- prevent update of window content here (no selection exists)
- local oldOnActiveParams = wnd.on_active_params
- local oldOnDeactiveParams = wnd.on_deactive_params
- wnd.on_active_params = ""
- wnd.on_deactive_params = ""
- wnd.active = true
- r2:adjustPropertySheetTitleClampSize(wnd)
- wnd.Env.updateSize()
- wnd.active = false
- wnd.on_active_params = oldOnActiveParams
- wnd.on_deactive_params = oldOnDeactiveParams
-
-
- --wnd.active = true
- --wnd:invalidateCoords()
- --wnd:updateCoords()
- --local maxH = wnd:find("rollouts").h_real
- --wnd.pop_max_h = maxH + 40
- --wnd.pop_min_h = maxH + 40
- --wnd:center()
- --wnd:invalidateCoords()
- --wnd:updateCoords()
- --wnd:center()
- -- force the y size (no scroll) by evaluating content size
- --wnd.active = false
- end
- end
--- end
- end
-
- -- force to center all windows at start
- --debugInfo('*4')
- initPropertySheetPos(getUI("ui:interface:r2ed_property_sheet_no_properties"))
- initPropertySheetPos(getUI("ui:interface:r2ed_property_sheet_no_selection"))
-
- --debugInfo('*5')
-end
-
-------------------------------------------------------------------------------------------------------------
--- TMP
-function r2:testPropertySheet()
- -- tmp
- local result, registrationFunction = r2:buildPropertySheetXml(r2.Classes.MapDescription, "r2ed_property_sheet")
- -- parse & register
- parseInterfaceFromString(r2:encloseXmlScript(result)) -- parseInterfaceFromString :C++ function exported from the interface manager to parse an new interface
- -- from its xml description
- registrationFunction()
- local propertySheet = getUI("ui:interface:r2ed_property_sheet")
- if propertySheet ~= nil then
- propertySheet.active = false
- propertySheet.active = true -- force an update
- propertySheet:center()
- updateAllLocalisedElements()
- end
-end
-
-
-------------------------------------------------------------------------------------------------------------
--- Displayer to update the content of the property sheet
-local propertySheetDisplayerTable = {}
-
-------------------------------------------------
-function propertySheetDisplayerTable:onCreate(instance)
-end
-------------------------------------------------
-function propertySheetDisplayerTable:onErase(instance)
-end
-------------------------------------------------
-function propertySheetDisplayerTable:onPreHrcMove(instance)
-end
-------------------------------------------------
-function propertySheetDisplayerTable:onPostHrcMove(instance)
-end
-------------------------------------------------
-function propertySheetDisplayerTable:onFocus(instance, hasFocus)
-end
-------------------------------------------------
-function propertySheetDisplayerTable:onSelect(instance, isSelected)
-end
-
-------------------------------------------------
--- handle an event on a property, possibly with additionnal parameters
-function propertySheetDisplayerTable:handleAttrEvent(eventName, instance, attributeName, args)
- -- TODO nico : arrays not handled yet
- local class = instance:getClass()
- if not class.BuildPropertySheet then
- return false
- end
- local propertySheet = r2:getPropertySheet(instance)
- if propertySheet == nil or propertySheet.active == false then
- return false
- end
- --debugInfo("Property sheet test")
- --debugInfo(ct .. "Instance " .. instance.InstanceId .." has an attribute modified : " .. attributeName)
- -- call event handler into the ui
- propertySheet.Env.handleEvent(eventName, attributeName, args)
- return true
-end
-------------------------------------------------
-function propertySheetDisplayerTable:onAttrModified(instance, attributeName, indexInArray)
- -- TODO nico : arrays not handled yet
- if self.handleAttrEvent and self:handleAttrEvent("onSet", instance, attributeName, emptyArgs) then
- -- special case for "Name" : title of the container depends on it
- -- update if the property sheet is visible
- local propertySheet = r2:getPropertySheet(instance)
- if propertySheet then
- if attributeName == "Name" and instance == r2:getSelectedInstance() then
- propertySheet.uc_title = concatUCString(i18n.get("uiRE2DPropertiesOf"), instance:getDisplayName())
- end
- propertySheet.Env.updatePropVisibility()
- end
- end
-end
-------------------------------------------------
-function propertySheetDisplayerTable:onTargetInstanceCreated(instance, refIdName, refIdIndexInArray)
- -- TODO nico : arrays not handled yet
- self:handleAttrEvent("onTargetCreated", instance, refIdName, emptyArgs)
-end
-------------------------------------------------
-function propertySheetDisplayerTable:onTargetInstanceErased(instance, refIdName, refIdIndexInArray)
- -- TODO nico : arrays not handled yet
- self:handleAttrEvent("onTargetErased", instance, refIdName, emptyArgs)
-end
-------------------------------------------------
-function propertySheetDisplayerTable:onTargetInstancePreHrcMove(instance, refIdName, refIdIndexInArray)
- -- TODO nico : arrays not handled yet
- self:handleAttrEvent("onTargetPreHrcMove", instance, refIdName, emptyArgs)
-end
-------------------------------------------------
-function propertySheetDisplayerTable:onTargetInstancePostHrcMove(instance, refIdName, refIdIndexInArray)
- -- TODO nico : arrays not handled yet
- self:handleAttrEvent("onTargetPostHrcMove", instance, refIdName, emptyArgs)
-end
-
-------------------------------------------------
-function propertySheetDisplayerTable:onTargetInstanceAttrModified(instance, refIdName, refIdIndexInArray, targetAttrName, targetAttrIndexInArray)
- -- TODO nico : arrays not handled yet
- --debugInfo(tostring(refIdName))
- --debugInfo(tostring(refIdIndexInArray))
- --debugInfo(tostring(targetAttrName))
- --debugInfo(tostring(targetAttrIndexInArray))
- table.clear(eventArgs)
- table.insert(eventArgs, targetAttrName)
- table.insert(eventArgs, targetAttrIndexInArray)
- self:handleAttrEvent("onTargetAttrModified", instance, refIdName) -- additionnal parameters
-end
-
-function r2:propertySheetDisplayer()
- return propertySheetDisplayerTable -- generic property displayer is shared by all instance
-end
-
-
--- last coordinate of property window (for generic property window)
-r2.PropertyWindowCoordsBackup = nil
-
--- see if a property sheet window coords must be backuped
-function r2:getPropertySheetBackupFlag(wnd)
- local result = true
- if not wnd then return false end
- local targetInstance = wnd.Env.TargetInstance
- if targetInstance then
- local targetClass = r2:getClass(targetInstance)
- if targetClass and not targetClass.isNil then
- result = defaulting(targetClass.BackupPropertySheetSize, true)
- end
- end
- return result
-end
-
-------------------------------------------------------------------------------------------------------------
--- 'show properties' handler : display properties for selected instance
--- TODO nico : maybe would better fit inside 'r2_ui_windows.lua' ?
-function r2:showProperties(instance)
-
- r2.PropertyWindowVisible = false
- -- alias on r2.PropertyWindowCoordsBackup
- local wndCoord = r2.PropertyWindowCoordsBackup
- -- hide previous window
- if r2:getPropertySheetBackupFlag(r2.CurrentPropertyWindow) then
- wndCoord = r2:backupWndCoords(r2.CurrentPropertyWindow)
- end
- if r2.CurrentPropertyWindow then
- r2.CurrentPropertyWindow.active = false
- end
- local newPropWindow
- if instance == nil then
- -- display the 'no selected instance window'
- newPropWindow = getUI("ui:interface:r2ed_property_sheet_no_selection")
- else
- local class = instance:getClass()
- if class.BuildPropertySheet ~= true then
- newPropWindow = getUI("ui:interface:r2ed_property_sheet_no_properties")
- else
- newPropWindow = r2:getPropertySheet(instance)
- end
- end
- r2.CurrentPropertyWindow = newPropWindow
-
- if newPropWindow ~= nil then
- if instance ~= nil then
- newPropWindow.Env.TargetInstance = instance -- set the instance being edited
- end
- newPropWindow.active = false
- newPropWindow:invalidateCoords()
- newPropWindow.active = true
- r2.PropertyWindowVisible = true
- -- see if window want to restore size from previous property sheet (for generic property windows)
- if r2:getPropertySheetBackupFlag(r2.CurrentPropertyWindow) then
- if wndCoord ~= nil then
- newPropWindow.x = wndCoord.x
- newPropWindow.y = wndCoord.y
- newPropWindow.w = math.max(wndCoord.w, newPropWindow.w)
- newPropWindow.h = math.max(wndCoord.h, newPropWindow.h)
- end
- end
- if instance and instance:getClass().BuildPropertySheet then
- newPropWindow.uc_title = concatUCString(i18n.get("uiRE2DPropertiesOf"), instance:getDisplayName())
- end
- end
- r2.CurrentPropertyWindow = newPropWindow
-
- return newPropWindow
-end
-
-
-r2.CurrentForm = nil
-
-------------------------------------------------------------------------------------------------------------
--- display a form with the given init parameters, & call a function to notify when ok has been pressed
--- the callback is called with
-function r2:doForm(formName, initialTable, validateCallback, cancelCallback)
- if r2.CurrentForm then r2:cancelForm(r2.CurrentForm) end
- local form = r2.Forms[formName]
- if form == nil then
- debugInfo(" Can't retrieve form with name " .. tostring(formName))
- return
- end
- if form.Prop == nil then
- debugInfo(" no properties found for form with name " .. tostring(formName))
- return
- end
- local formUI = r2:getForm(formName)
- if form.Prop == nil then
- debugInfo(" can't find ui for form with name " .. tostring(formName))
- return
- end
- -- fill all properties with their default values
- for k, prop in pairs(form.Prop) do
- if initialTable[prop.Name] == nil then
- if prop.Default ~= nil then
- initialTable[prop.Name] = prop.Default
- else
- -- TODO nico : add a table here when more types are available
- if prop.Type == "String" then
- initialTable[prop.Name] = ""
- else
- initialTable[prop.Name] = 0
- end
- end
- end
- end
- --
- formUI.Env.Choice = nil -- no choice made yet
- formUI.Env.Form = form
- formUI.Env.FormInstance = initialTable
- formUI.Env.onValidate = validateCallback
- formUI.Env.onCancel = cancelCallback
- -- TMP for debug : directly call the callback
- --validateCallback(formUI.Env.FormInstance)
-
- formUI.active = true
- formUI.Env.updateAll()
- formUI.Env.updateSize()
- formUI:updateCoords()
- formUI:center()
- formUI:updateCoords()
- if form.Caption ~= nil then
- formUI.uc_title = i18n.get(form.Caption)
- else
- formUI.uc_title = i18n.get("uiR2EDForm")
- end
- r2.CurrentForm = formUI
- if type(form.onShow) == "function" then
- form.onShow(initialTable)
- end
- --runAH(nil, "enter_modal", "group=" .. formUI.id)
-end
-
--- called when the user hit the 'ok' boutton of a form
-function r2:validateForm(form)
- form.Env.Choice="Ok"
- form.active = false
- if form.Env.onValidate then
- form.Env.onValidate(form.Env.FormInstance, form)
- end
-
- --r2.CurrentForm = nil
-end
-
--- called when the user hit the 'cancel' boutton of a form
-function r2:cancelForm(form)
- form.Env.Choice="Cancel"
- form.active = false
- r2.CurrentForm = nil
- if form.Env.onCancel then
- form.Env.onCancel(form.Env.FormInstance, form)
- end
-
-end
-
--- test if there's an help button in the window. If so, clamp more of the title
-function r2:adjustPropertySheetTitleClampSize(wnd)
- if wnd.header_opened == nil then return end
- local helpBut = wnd.header_opened.help
- if helpBut ~= nil and helpBut.active then
- helpBut:getViewText():updateCoords()
- helpBut:updateCoords()
- if wnd.title_delta_max_w == r2.DefaultPropertySheetTitleClampSize then
- wnd.title_delta_max_w = wnd.title_delta_max_w - helpBut.w_real - 4
- end
- end
-end
-
--- test of forms
-function r2:testForm()
- local function onOk(resultTable)
- debugInfo('ok was pressed')
- inspect(resultTable)
- end
- local function onCancel()
- debugInfo('cancel was pressed')
- end
- r2:doForm("TestForm", {}, onOk, onCancel)
-end
-
---function mysetDbProp(dbpath, value)
--- debugInfo("Setting " .. dbpath .. " to " .. tostring(value))
--- setDbProp(dbpath, value)
---end
-
---function mygetDbProp(dbPath)
--- debugInfo("Getting" .. dbPath .. " -> value is " .. tostring(getDbProp(dbPath)))
--- return getDbProp(dbPath)
---end
-
-
-
-
-function r2:onContAlphaSettingsChanged(dbPath)
- --debugInfo("onContAlphaSettingsChanged " .. dbPath)
- --debugInfo('1')
- local cont = getUICaller()
- setDbProp("UI:SAVE:" .. dbPath ..":CONTAINER_ALPHA", cont.container_alpha)
- setDbProp("UI:SAVE:" .. dbPath ..":CONTENT_ALPHA", cont.content_alpha)
- setDbProp("UI:SAVE:" .. dbPath ..":ROLLOVER_CONTENT_ALPHA", cont.rollover_content_alpha)
- setDbProp("UI:SAVE:" .. dbPath ..":ROLLOVER_CONTAINER_ALPHA", cont.rollover_container_alpha)
- setDbProp("UI:SAVE:" .. dbPath ..":USE_GLOBAL_ALPHA_SETTINGS", select(cont.use_global_alpha_settings, 1, 0))
- --debugInfo('2')
-end
-
--- called by action handler attached to the container when alpha settings of a property sheets have been modified
-function r2:onPropertySheetAlphaSettingsChanged()
- --debugInfo("onPropertySheetAlphaSettingsChanged")
- r2:onContAlphaSettingsChanged("R2_PROP_SHEET")
-end
-
--- called by action handler attached to the container when alpha settings of a form have been modified
-function r2:onFormAlphaSettingsChanged()
- --debugInfo("onFormAlphaSettingsChanged")
- r2:onContAlphaSettingsChanged("R2_FORM")
-end
-
--- called by action handler attached to the container when it is opened to restore
--- its alpha settings from the databse (this is because all prop / forms window share the same alpha settings)
-function r2:restoreContAlphaSettings(dbPath)
- --debugInfo('restoreContAlphaSettings ' .. dbPath)
- local cont = getUICaller()
- local oldHandler = cont.on_alpha_settings_changed
- cont.on_alpha_settings_changed = ""
- cont.container_alpha = getDbProp("UI:SAVE:" .. dbPath ..":CONTAINER_ALPHA")
- cont.content_alpha = getDbProp("UI:SAVE:" .. dbPath ..":CONTENT_ALPHA")
- cont.rollover_content_alpha = getDbProp("UI:SAVE:" .. dbPath ..":ROLLOVER_CONTENT_ALPHA")
- cont.rollover_container_alpha = getDbProp("UI:SAVE:" .. dbPath ..":ROLLOVER_CONTAINER_ALPHA")
- local use_global_alpha_settings = getDbProp("UI:SAVE:" .. dbPath ..":USE_GLOBAL_ALPHA_SETTINGS")
- --debugInfo("use_global_alpha_settings = " .. tostring(use_global_alpha_settings))
- cont.use_global_alpha_settings = use_global_alpha_settings ~= 0
- cont.on_alpha_settings_changed = oldHandler
-end
-
diff --git a/code/ryzom/common/data_common/r2/r2_ui_reset.lua b/code/ryzom/common/data_common/r2/r2_ui_reset.lua
deleted file mode 100644
index aca6a351b..000000000
--- a/code/ryzom/common/data_common/r2/r2_ui_reset.lua
+++ /dev/null
@@ -1,566 +0,0 @@
--- Reset ui & manage desktop change (one desktop per editor mode)
-
-
-
-------------------------------------------------------------------------------------
-function setActive(wndName, active)
- local wnd = getUI(wndName, r2.Config.VerboseGetUI)
- if wnd ~= nil then
- wnd.active = active
- end
-end
-
-------------------------------------------------------------------------------------
-function hide(wndName)
- setActive(wndName, false)
-end
-
-------------------------------------------------------------------------------------
-function show(wndName)
- setActive(wndName, true)
-end
-
-
-function r2:hide(wndName)
- hide(wndName)
-end
-
--- Reset windows placement in each desktop (one desktop per mode of the editor, so no virtual desktop are available in r2ed)
-function r2:resetDesktop(desktopIndex)
- local scrW, scrH = getWindowSize()
-
- ----------------------------------------------------------------------------------------------------------
- -- reset the EDITION desktop
- if desktopIndex == 0 then
- hideAllWindows()
- local palette = getUI("ui:interface:r2ed_palette")
- if palette then
- palette.active = true
- palette.x = 4
- palette.y = scrH - 85
- palette.w = 225
- palette.h = 245
- end
- local scenario = getUI("ui:interface:r2ed_scenario")
- if scenario then
- scenario.active = false
- --scenario.w = 315
- scenario.w = 350
- scenario.h = 450
- scenario.x = scrW - scenario.w - 5
- scenario.y = scrH - 65
- -- by default the 'scene rollout' is opened
- --r2:setRolloutOpened(scenario:find("geo_tree").caption, scenario:find("geo_tree_list"), true)
- -- by default the 'permanent content' is opened
- --r2:setRolloutOpened(scenario:find("content_tree").caption, scenario:find("content_tree_list"), true)
- -- by default the 'act' rollout is opened
- --r2:setRolloutOpened(scenario:find("acts").caption, scenario:find("act_tree_enclosing"), true)
- end
- local webAdmin = getUI("ui:interface:r2ed_web_admin")
- webAdmin.active = false
- --if webAdmin then
- -- webAdmin.active = false
- -- webAdmin.w = 250
- -- webAdmin.h = 255
- -- webAdmin.x = scrW - webAdmin.w - 5
- -- if scenario then
- -- webAdmin.y = scenario.y - scenario.h - 5
- -- else
- -- webAdmin.y = scrH - 5
- -- end
- -- end
-
- local toolbar = getUI("ui:interface:r2ed_toolbar")
- if toolbar then
- toolbar.active = true
- toolbar:invalidateCoords()
- toolbar:updateCoords()
- end
-
-
- if r2.Scenario then
- r2:setSelectedInstanceId("") -- force a real select
- r2:setSelectedInstanceId(r2.Scenario.InstanceId)
- end
- --
- --
- --
- --
- --
-
- ----------------------------------------------------------------------------------------------------------
- -- reset the TEST dektop
- elseif desktopIndex == 1 then
- hideAllWindows()
- -- show game related windows in test mode
- -- (same as virtual desktop 0 in game)
-
- -- Target
- runAH(nil, "set", "target='ui:interface:target:active'|value=1")
- runAH(nil, "set", "target='ui:interface:target:locked'|value=0")
- runAH(nil, "set", "target='ui:interface:target:x'|value=sub(sub(getprop('ui:interface:w'),getprop('ui:interface:target:w')),4)")
- runAH(nil, "set", "target='ui:interface:target:y'|value=sub(getprop('ui:interface:h'),4)")
-
- -- gestion sets
- runAH(nil, "set", "target='ui:interface:gestionsets:active'|value=1")
- runAH(nil, "set", "target='ui:interface:gestionsets:x'|value=div(sub(getprop('ui:interface:w'),getprop('ui:interface:gestionsets:w')),2)")
- runAH(nil, "set", "target='ui:interface:gestionsets:y'|value=sub(getprop('ui:interface:h'),4)")
-
- -- player
- runAH(nil, "set", "target='ui:interface:player:active'|value=1")
- runAH(nil, "set", "target='ui:interface:player:x'|value=4")
- runAH(nil, "set", "target='ui:interface:player:y'|value=sub(getprop('ui:interface:h'),4)" )
- runAH(nil, "set", "target='ui:interface:player:locked'|value=0")
- runAH(nil, "set_transparent", "ui:interface:player")
-
- local webAdmin = getUI("ui:interface:r2ed_web_admin")
- webAdmin.active = false
- --if webAdmin then
- -- webAdmin.active = true
- -- webAdmin.w = 250
- -- webAdmin.h = 255
- -- webAdmin.x = scrW - webAdmin.w - 5
- -- webAdmin.y = scrH - 75
- --end
-
- -- bonus malus window
- runAH(nil, "set", "target='ui:interface:bonus_malus:active'|value=1")
- runAH(nil, "set", "target='ui:interface:bonus_malus:x'|value=188")
- runAH(nil, "set", "target='ui:interface:bonus_malus:y'|value=sub(getprop('ui:interface:h'),4)")
- runAH(nil, "set", "target='ui:interface:bonus_malus:locked'|value=1")
-
- -- Compass
- --runAH(nil, "set", "target='ui:interface:compass:x'|value=sub(sub(getprop('ui:interface:w'),getprop('ui:interface:compass:w')),4)")
- --runAH(nil, "set", "target='ui:interface:compass:y'|value=sub(sub(getprop('ui:interface:h'),getprop('ui:interface:target:h')),8)")
-
- -- Help
- --runAH(nil, "set", "target='ui:interface:help_browser:active'|value=1")
- --runAH(nil, "set", "target='ui:interface:help_browser:locked'|value=0")
- --runAH(nil, "set", "target='ui:interface:help_browser:w'|value=410")
- --runAH(nil, "set", "target='ui:interface:help_browser:h'|value=128")
- --runAH(nil, "set", "target='ui:interface:help_browser:x'|value=sub(sub(getprop('ui:interface:w'),getprop('ui:interface:help_browser:w')),4)")
- --runAH(nil, "set", "target='ui:interface:help_browser:y'|value=add(getprop('ui:interface:help_browser:h'),4)")
-
- -- System Info
- --runAH(nil, "set", "target='ui:interface:system_info:w'|value=div(sub(getprop('ui:interface:w'),add(getprop('ui:interface:help_browser:w'),16)),2)")
- --runAH(nil, "set", "target='ui:interface:system_info:h'|value=128")
- --runAH(nil, "set", "target='ui:interface:system_info:x'|value=4")
- --runAH(nil, "set", "target='ui:interface:system_info:y'|value=add(getprop('ui:interface:system_info:h'),4)")
-
- -- Main Chat
- -- runAH(nil, "set", "target='ui:interface:main_chat:w'|value=getprop('ui:interface:system_info:w')")
- -- runAH(nil, "set", "target='ui:interface:main_chat:h'|value=128")
- -- runAH(nil, "set", "target='ui:interface:main_chat:x'|value=add(getprop('ui:interface:system_info:w'),8)")
- -- runAH(nil, "set", "target='ui:interface:main_chat:y'|value=add(getprop('ui:interface:system_info:h'),4)")
-
-
- -- Mission Journal
- --runAH(nil, "set", "target='ui:interface:info_player_journal:active'|value=1")
- --runAH(nil, "set", "target='ui:interface:info_player_journal:locked'|value=0")
- --runAH(nil, "set", "target='ui:interface:info_player_journal:x'|value=4")
- --runAH(nil, "set", "target='ui:interface:info_player_journal:y'|value=add(add(getprop('ui:interface:system_info:h'),getprop('ui:interface:info_player_journal:h')),8)")
-
-
- -- Milko Pad
- --runAH(nil, "set", "target='ui:interface:milko:x'|value=sub(sub(getprop('ui:interface:w'),getprop('ui:interface:milko:w')),4)")
- --runAH(nil, "set", "target='ui:interface:milko:y'|value=sub(sub(getprop('ui:interface:compass:y'),getprop('ui:interface:compass:h')),4)")
-
- -- Hands
-
- local toolbarWindow = getUI("ui:interface:r2ed_toolbar_window")
- toolbarWindow.x=32
- toolbarWindow.y=0
-
- local milkoPad = getUI("ui:interface:milko_pad")
- milkoPad.y = 0
- milkoPad.x = scrW - milkoPad.w
-
- ----------------------------------------------------------------------------------------------------------
- -- reset the DM destop
- elseif desktopIndex == 2 then
-
- hideAllWindows()
- local webAdmin = getUI("ui:interface:r2ed_web_admin")
- webAdmin.active = false
- --if webAdmin then
- -- webAdmin.active = true
- -- webAdmin.w = 250
- -- webAdmin.h = 255
- -- webAdmin.x = scrW - webAdmin.w - 5
- -- webAdmin.y = scrH - 5
- --end
- local toolbar = getUI("ui:interface:r2ed_toolbar")
- if toolbar then
- toolbar.active = true
- toolbar:invalidateCoords()
- toolbar:updateCoords()
- end
-
- local dmToolbar = getUI("ui:interface:r2ed_windows_dm_bar")
- if dmToolbar then
- dmToolbar.active = true
- dmToolbar:invalidateCoords()
- dmToolbar:updateCoords()
- end
-
- hide("ui:interface:bonus_malus") -- patch for the bonus-malus window
- elseif desktopIndex == 3 then
- hideAllWindows()
- end
- r2:resetDesktopVisibleWindows(desktopIndex)
-end
-
-
-local function cleanEnv(contName)
- local cont = getUI("ui:interface" .. contName, r2.Config.VerboseGetUI)
- if cont then
- cont:deleteLUAEnvTable(true) -- recursively delete lua environments
- cont:setOnDraw("")
- end
-end
-
-
-
-----------------------------------------------------------------------------------------------------------
-function r2:adjustToolbarGap()
- local toolbar = getUI("ui:interface:r2ed_toolbar")
- local dx = 0
- local numGroups = toolbar:getNumGroups()
- for k = 0, numGroups - 1 do
- local gr = toolbar:getGroup(k)
- if gr.active then
- gr.x = dx
- dx = 4
- else
- gr.x = 0
- end
- end
-end
-
-----------------------------------------------------------------------------------------------------------
--- common to r2:onChangeDesktop & r2:resetDesktop
-function r2:resetDesktopVisibleWindows(desktopIndex)
- -- reset the EDIT desktop
- if desktopIndex == 0 then
- if (r2.CurrentPropertyWindow) then
- r2.CurrentPropertyWindow.active = false
- r2.CurrentPropertyWindow = nil
- end
- r2.PropertyWindowVisible = false
- show("ui:interface:r2ed_tool_context_help")
- if config.R2EDExtendedDebug == 1 then
- show("ui:interface:r2ed_current_session")
- else
- hide("ui:interface:r2ed_current_session")
- end
- hide("ui:interface:welcome_info")
- hide("ui:interface:compass")
- show("ui:interface:r2ed_main_menu_button")
- show("ui:interface:r2ed_main_bl")
- show("ui:interface:r2ed_select_bar")
- hide("ui:interface:r2ed_select_bar:buttons")
- hide("ui:interface:r2ed_select_bar:sequences")
- hide("ui:interface:milko_pad")
- hide("ui:interface:windows")
- hide("ui:interface:r2ed_npc")
- hide("ui:interface:ring_chars_tracking")
- local b1 = getUI("ui:interface:r2ed_select_bar"):find("b1")
- if b1 then
- b1:updateCoords() -- force to update the coords, icon position not good otherwise
- end
- hide("ui:interface:bonus_malus") -- patch for the bonus-malus window
- r2.ToolUI:updateUndoRedo()
- hide("ui:interface:r2ed_connect")
- hide("ui:interface:r2ed_toolbar_window")
- -- reset the TEST desktop
- elseif desktopIndex == 1 then
- if config.R2EDExtendedDebug == 1 then
- show("ui:interface:r2ed_current_session")
- else
- hide("ui:interface:r2ed_current_session")
- end
- hide("ui:interface:compass")
- hide("ui:interface:welcome_info")
- show("ui:interface:r2ed_main_bl")
- hide("ui:interface:r2ed_testbar")
- hide("ui:interface:r2ed_main_menu_button")
- show("ui:interface:milko_pad")
- hide("ui:interface:windows")
- hide("ui:interface:r2ed_connect")
- hide("ui:interface:ring_chars_tracking")
- if not r2.isSessionOwner() and r2.AccessMode ~= "Editor" then
- hide("ui:interface:r2ed_toolbar_window")
- else
- show("ui:interface:r2ed_toolbar_window")
- end
-
- -- reset the DM desktop
- elseif desktopIndex == 2 then
- hide("ui:interface:compass")
- if config.R2EDExtendedDebug == 1 then
- show("ui:interface:r2ed_current_session")
- else
- hide("ui:interface:r2ed_current_session")
- end
- hide("ui:interface:r2ed_main_bl")
- show("ui:interface:r2ed_testbar")
- show("ui:interface:r2ed_main_menu_button")
- hide("ui:interface:milko_pad")
- hide("ui:interface:windows")
- hide("ui:interface:bonus_malus") -- patch for the bonus-malus window
- hide("ui:interface:r2ed_connect")
- hide("ui:interface:r2ed_toolbar_window")
- hide("ui:interface:ring_chars_tracking")
- else
- hide("ui:interface:bonus_malus") -- patch for the bonus-malus window
- end
-
- hide("ui:interface:team_share") -- patch for the 'team share' window
-
- game:updateMissionJournalMode()
- r2:disableAnimals()
-end
-
--- called by C ++ : reset non savable parts after a desktop change
-function r2:onChangeDesktop(desktopIndex)
- --debugInfo("On change desktop = " .. tostring(desktopIndex))
- hideAllNonSavableWindows();
-
- -- in each case, hide welcom and ring access windows
- getUI("ui:interface:npc_web_browser").active=false
-
- ----------------------------------------------------------------------------------------------------------
- -- set the EDITION desktop
- if desktopIndex == 0 then
- r2:setFixedLighting(false)
- hide("ui:interface:feature_help")
- r2.ui.AnimBar:clearActions()
- local toolbar = getUI("ui:interface:r2ed_toolbar")
- if toolbar then
- toolbar.active = true
- toolbar.r2ed_tool_select.active = true
- toolbar.r2ed_tool_rotate.active = true
- toolbar.r2ed_tool_undo.active = true
- toolbar.r2ed_tool_redo.active = true
- toolbar.r2ed_tool_copy.active = true
- toolbar.r2ed_tool_paste.active = true
- toolbar.r2ed_tool_teleport.active = true
- toolbar.r2ed_tool_display_mode.active = true
- toolbar.r2ed_tool_start.active = true
- toolbar.r2ed_tool_stop.active = false
- toolbar.r2ed_stop_live.active = false
- --toolbar.r2ed_tool_teleport.x = 4
- r2:adjustToolbarGap()
- toolbar.r2ed_freeze_bot_objects.x = 4
- toolbar.r2ed_unfreeze_bot_objects.x = 0
- toolbar:invalidateCoords()
- toolbar:updateCoords()
- toolbar.r2ed_live.active = false
-
-
- end
- local windowsDMBar = getUI("ui:interface:r2ed_windows_dm_bar")
- if windowsDMBar then
- windowsDMBar.active=false
- windowsDMBar:invalidateCoords()
- windowsDMBar:updateCoords()
- end
- cleanEnv("r2ed_scenario")
- cleanEnv("r2ed_bbox_edit")
- cleanEnv("r2ed_toolbar")
- cleanEnv("r2ed_windowbar")
- cleanEnv("r2ed_testbar")
- cleanEnv("r2ed_toolbar_admin")
- cleanEnv("r2ed_table_test")
- cleanEnv("r2ed_editbox_test")
- cleanEnv("lua_inspector")
- cleanEnv("r2ed_palette")
- cleanEnv("r2ed_connect")
- cleanEnv("r2ed_property_sheet_no_selection")
- cleanEnv("r2ed_property_sheet_no_properties")
- cleanEnv("r2ed_scenario")
- r2.ScenarioWindow:resetWindow()
- r2.ContextualCommands:setupToolbar(nil)
-
- -- set new title for th "keys" window
- local keys = getUI("ui:interface:keys")
- if keys then
- keys.uc_title = i18n.get("uiR2EDEditingKeys")
- end
-
- if r2.UserComponentsManager then
- r2.UserComponentsManager:updateUserComponentsUi()
- end
- r2:setupFreezeBotObjectButton()
- local goTestButton = getUI("ui:interface:r2ed_toolbar"):find("r2ed_tool_start").unselected.button
- local goTestMenu = getUI("ui:interface:r2ed_main_menu"):find("go_test")
- goTestButton.frozen = false
- goTestMenu.grayed = false
- ----------------------------------------------------------------------------------------------------------
- -- set the TEST desktop OR player desktop
- elseif desktopIndex == 1 then
- r2:setFixedLighting(false)
- hide("ui:interface:feature_help")
- r2.ui.AnimBar:clearActions()
- r2.ui.AnimBar:update()
- local toolbar = getUI("ui:interface:r2ed_toolbar")
- toolbar.active = false
- local toolbarWindow = getUI("ui:interface:r2ed_toolbar_window")
- toolbarWindow:find("r2ed_anim_dm_mode").active = (r2.AccessMode == "Editor")
- toolbarWindow:find("r2ed_stop_live").active = not (r2.AccessMode == "Editor") and r2.isSessionOwner()
- toolbarWindow:find("player_control").active = (not (r2.AccessMode == "Editor")) and r2.isSessionOwner()
- toolbarWindow:find("r2ed_live").active = false
-
- -- resize the toolbarWindow depending on content
- r2:resizeToolbarWindow()
-
- local windowsDMBar = getUI("ui:interface:r2ed_windows_dm_bar")
- if windowsDMBar then
- windowsDMBar.r2ed_live.active = (not (r2.AccessMode == "Editor")) and r2.isSessionOwner()
- windowsDMBar.player_control.active = (not (r2.AccessMode == "Editor")) and r2.isSessionOwner()
- windowsDMBar:invalidateCoords()
- windowsDMBar:updateCoords()
- end
-
- r2:adjustToolbarGap()
-
- local keys = getUI("ui:interface:keys")
- if keys then
- keys.uc_title = i18n.get("uiR2EDTestOrDMKeys")
- end
-
- ----------------------------------------------------------------------------------------------------------
- -- reset the DM desktop
- elseif desktopIndex == 2 then
- r2:setFixedLighting(false)
- hide("ui:interface:feature_help")
- r2.ui.AnimBar:clearActions()
- local toolbar = getUI("ui:interface:r2ed_toolbar")
- if toolbar then
- toolbar.active = true
- toolbar.r2ed_freeze_bot_objects.active = false
- toolbar.r2ed_unfreeze_bot_objects.active = false
- toolbar.r2ed_tool_select.active = false
- toolbar.r2ed_tool_rotate.active = false
- toolbar.r2ed_tool_undo.active = false
- toolbar.r2ed_tool_redo.active = false
- toolbar.r2ed_tool_copy.active = false
- toolbar.r2ed_tool_paste.active = false
- toolbar.r2ed_tool_teleport.active = true
- toolbar.r2ed_tool_display_mode.active = false
- toolbar.r2ed_tool_start.active = false
- toolbar.r2ed_tool_stop.active = (r2.AccessMode == "Editor")
- toolbar.r2ed_stop_live.active = (not (r2.AccessMode == "Editor")) and r2.isSessionOwner()
- --toolbar.r2ed_tool_teleport.x = -20 -- compensate x from previous buttons
- --toolbar.r2ed_stop_live.x = -8 -- compensate x from previous buttons
- toolbar.r2ed_live.active = (r2.AccessMode=="Editor" or r2.Mode=="DM")
- r2:adjustToolbarGap()
- toolbar:invalidateCoords()
- toolbar:updateCoords()
- end
-
-
- local windowsDMBar = getUI("ui:interface:r2ed_windows_dm_bar")
- if windowsDMBar then
- windowsDMBar.active=true
- windowsDMBar.r2ed_live.active = (not (r2.AccessMode == "Editor")) and r2.isSessionOwner()
- windowsDMBar.player_control.active = (not (r2.AccessMode == "Editor")) and r2.isSessionOwner()
-
- windowsDMBar:invalidateCoords()
- windowsDMBar:updateCoords()
- end
- r2.ui.AnimBar:update()
- r2.ui.AnimBar:updateDMControlledEntitiesWindow()
- local keys = getUI("ui:interface:keys")
- if keys then
- keys.uc_title = i18n.get("uiR2EDTestOrDMKeys")
- end
- end
-
- -- special : if "key" window is visible on current desktop, hide, then show it again to force a refresh of its content
- local keys = getUI("ui:interface:keys")
- if keys.active then
- keys.active = false
- keys.active = true
- end
-
- r2:resetDesktopVisibleWindows(desktopIndex)
- r2.ToolUI:updateToggleWindowButtons()
- r2.ToolUI:updateToggleWindowDMButtons()
-end
-
-function r2:resizeToolbarWindow()
- local toolbarWindow = getUI("ui:interface:r2ed_toolbar_window")
- toolbarWindow:updateCoords()
- local w = toolbarWindow:find("enclosing").w_real + 16
- toolbarWindow.w = w
- toolbarWindow.pop_min_w = w
- toolbarWindow.pop_max_w = w
- toolbarWindow:updateCoords()
-end
-
--- for masterless mode only : display option to control player & quit
-function r2:initDMToolbarWindowPos()
-
- if not r2.isSessionOwner() then return end
-
- local scrW, scrH = getWindowSize()
- -- init dm toolbar default pos
- local toolbarWindow = getUI("ui:interface:r2ed_toolbar_window")
- toolbarWindow.active = true
- toolbarWindow.x= 11
- toolbarWindow.y=scrH - 190
-end
-
--- for masterless mode only : display option to control player & quit
-function r2:popDMToolbarWindow()
- local toolbarWindow = getUI("ui:interface:r2ed_toolbar_window")
- toolbarWindow.active = true
- toolbarWindow:find("r2ed_anim_dm_mode").active = false
- toolbarWindow:find("r2ed_stop_live").active = true
- toolbarWindow:find("r2ed_live").active = true
- toolbarWindow:find("player_control").active = true
- r2:resizeToolbarWindow()
- setTopWindow(toolbarWindow)
- hide("ui:interface:r2ed_main_bl")
- game:updateMissionJournalMode()
- r2:disableAnimals()
- getUI("ui:interface:welcome_info").active=false
-end
-
-
--- fix for previous versions : dm toolbar was shown on players desktop
-function r2:playerModeUIFix()
- local toolbarWindow = getUI("ui:interface:r2ed_toolbar_window")
- toolbarWindow.active = false
- hide("ui:interface:r2ed_main_bl")
- game:updateMissionJournalMode()
- r2:disableAnimals()
- getUI("ui:interface:welcome_info").active=false
-end
-
-
-function r2:disableAnimals()
- local animals = getUI("ui:interface:animal_global")
- animals.content.no_available_animals.active = true
- animals.list.active = false
- animals.header_opened.active = false
- animals.header_closed.active = true
-end
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/code/ryzom/common/data_common/r2/r2_ui_scenario.lua b/code/ryzom/common/data_common/r2/r2_ui_scenario.lua
deleted file mode 100644
index d627ab7b7..000000000
--- a/code/ryzom/common/data_common/r2/r2_ui_scenario.lua
+++ /dev/null
@@ -1,944 +0,0 @@
------------------
--- SCENARIO UI --
------------------
-
-
-r2.ScenarioWindow =
-{
- IgnoreActChange = false, -- when the content of the combo box is changed manually, allow to know we should not process the
- -- the 'onchangeAct' msg
- LeftQuota = nil,
-
- LeftStaticQuota = nil,
-
- Languages = {},
-
- Types = {},
- Locked = {},
-
- lockComboBoxes = false,
- -- chosen act in combo box
- showedActId = nil,
-
- TitleEditBoxLocked = false
-}
-
------------------------------------------------------------------------------------------------------------
--- init scenario window (language and scenario types from cfg files) --------------------------------------
-function r2.ScenarioWindow:initScenarioWindow()
-
- local languages = getClientCfgVar("ScenarioLanguages")
- local types = getClientCfgVar("ScenarioTypes")
-
- local locked = {"Full", "RunOnly"}
-
- -- stores values and init combo boxes
- local scenarioWnd = self:getContainer()
- local languageCB = scenarioWnd:find("language_combo_box")
- local typeCB = scenarioWnd:find("type_combo_box")
- local lockCB = scenarioWnd:find("locked_combo_box")
- local levelCB = scenarioWnd:find("level_combo_box")
- local rulesCB = scenarioWnd:find("rules_combo_box")
-
- local languages2 = {}
- for k, lang in pairs(languages) do
- self.Languages[i18n.get("uiR2ED"..lang):toUtf8()] = lang
- table.insert(languages2, i18n.get("uiR2ED"..lang))
- end
- table.sort(languages2)
- languageCB:resetTexts()
- for k, lang in pairs(languages2) do
- languageCB:addText(lang)
- end
-
- local types2 = {}
- for k, type in pairs(types) do
- self.Types[i18n.get("uiR2ED"..type):toUtf8()] = type
- table.insert(types2, i18n.get("uiR2ED"..type))
- end
- table.sort(types2)
- typeCB:resetTexts()
-
- for k, type in pairs(types2) do
- typeCB:addText(type)
- end
-
- do
-
- local tmp = {}
- if config.R2EDExtendedDebug == 1 then
- table.insert(locked, "RoSOnly")
- end
- for k, type in pairs(locked) do
- self.Locked[i18n.get("uiR2ED"..type):toUtf8()] = type
- table.insert(tmp, i18n.get("uiR2ED"..type))
- end
--- table.sort(tmp)
- lockCB:resetTexts()
- for k, type in pairs(tmp) do
- lockCB:addText(type)
- end
-
- end
-
-
- levelCB:resetTexts()
- for i = 0, 5 do
- levelCB:addText(i18n.get("uiRAP_Level".. tostring(i)))
- end
-
- rulesCB:resetTexts()
- rulesCB:addText(i18n.get("uiR2EDstrict"))
- rulesCB:addText(i18n.get("uiR2EDliberal"))
-end
-
------------------------------------------------------------------------------------------------------------
--- retrieve the table of acts (table that map each line of the combo box to an act, see r2.ActUIDisplayer)
-function r2.ScenarioWindow:getActTable()
- return r2.ActUIDisplayer:getActTable()
-end
-
------------------------------------------------------------------------------------------------------------
--- retrieve the 'scenario' window container (TODO nico : code duplicated with r2.ActUIDisplayer)
-function r2.ScenarioWindow:getContainer()
- return getUI("ui:interface:r2ed_scenario")
-end
-
------------------------------------------------------------------------------------------------------------
--- retrieve the 'acts' combo box (TODO nico : code duplicated with r2.ActUIDisplayer)
-function r2.ScenarioWindow:getActComboBox()
- return self:getContainer():find("act_combo_box")
-end
-
------------------------------------------------------------------------------------------------------------
--- handler selection of a new act by the user
-function r2.ScenarioWindow:onChangeActFromUI()
- if self.IgnoreActChange then return end
- self:setAct(self:getActTable()[self:getActComboBox().selection + 1].Act)
-end
-
------------------------------------------------------------------------------------------------------------
--- update ui from the current act
-function r2.ScenarioWindow:updateUIFromCurrentAct()
-
- local act = r2:getCurrentAct()
- -- look in the act table to change the selection
- self.IgnoreActChange = true -- don't want to trigger the 'onChangeAct' msg here
- if self.getActComboBox == nil then
- debugInfo(debug.traceback())
- inspect(self)
- end
- if not act:isBaseAct() then
- self:getActComboBox().selection = self:findComboBoxLineFromAct(act)
- end
- self.IgnoreActChange = false
- self:updateActTreeVisibility()
- self:updateLeftQuota()
-end
-
-
------------------------------------------------------------------------------------------------------------
--- get left quota, possibly updating it if it was modified
--- called by client
-function r2.ScenarioWindow:getLeftQuota()
- if r2.UIMainLoop.LeftQuotaModified then
- self:updateLeftQuota()
- end
- local quota = 0
- if self.LeftQuota < self.LeftStaticQuota then
- quota = self.LeftQuota
- else
- quota = self.LeftStaticQuota
- end
- return quota, self.LeftQuota, self.LeftStaticQuota
-end
-
------------------------------------------------------------------------------------------------------------
--- update display of left quota for the current act
-function r2.ScenarioWindow:updateLeftQuota()
- function protected()
- if not r2.Scenario then return end
- local quotaViewText = self:getContainer():find("left_quota")
- local quotaTooltip = self:getContainer():find("tab4")
- local quotaMacroViewText = self:getContainer():find("left_quota_macro")
- local quotaMacroTooltip = self:getContainer():find("tab1")
- local quotaViewTextMisc = self:getContainer():find("left_quota_misc")
- local quotaViewTextMisc2 = self:getContainer():find("left_quota_misc_2")
- local quotaMiscTooltip = self:getContainer():find("tab2")
-
- local act = r2:getCurrentAct()
-
- if act then
- r2.updateActCost(act)
- if not act:isBaseAct() then
- r2.updateActCost(r2.Scenario:getBaseAct())
- end
-
- self.LeftQuota, self.LeftStaticQuota = act:getLeftQuota()
-
- local uc_tooltip = ucstring()
- quotaViewText.hardtext = string.format("(%d)", self.LeftQuota)
- uc_tooltip:fromUtf8(i18n.get("uiR2EDScene"):toUtf8() .. " (" .. self.LeftQuota .. ")")
- quotaTooltip.tooltip = uc_tooltip
- quotaMacroViewText.hardtext = string.format("(%d)", self.LeftQuota)
- uc_tooltip:fromUtf8(i18n.get("uiR2EDMacroComponents"):toUtf8() .. " (" .. self.LeftQuota .. ")")
- quotaMacroTooltip.tooltip = uc_tooltip
- quotaViewTextMisc.hardtext = string.format("(%d)", self.LeftStaticQuota)
- quotaViewTextMisc2.hardtext = string.format("(%d)", self.LeftStaticQuota)
- uc_tooltip:fromUtf8(i18n.get("uiR2EDbotObjects"):toUtf8() .. " (" .. self.LeftStaticQuota .. ")")
- quotaMiscTooltip.tooltip = uc_tooltip
-
- quotaViewText.color_rgba = select(self.LeftQuota >= 0, CRGBA(255, 255, 255), CRGBA(255, 0, 0))
- quotaViewTextMisc.color_rgba = select(self.LeftStaticQuota >= 0, CRGBA(255, 255, 255), CRGBA(255, 0, 0))
- quotaViewTextMisc2.color_rgba = select(self.LeftStaticQuota >= 0, CRGBA(255, 255, 255), CRGBA(255, 0, 0))
-
- else
- quotaViewText.hardtext = ""
- quotaMacroViewText.hardtext = ""
- end
- r2.UIMainLoop.LeftQuotaModified = false
- end
- pcall(protected)
-end
-
------------------------------------------------------------------------------------------------------------
--- change act into editor, and in the ui
-r2.ScenarioWindow.setActId = nil
-function r2.ScenarioWindow:setAct(act)
-
- if act ~= r2:getCurrentAct() then
- self:updateComboBoxCurrentAct(act)
- r2:setCurrentActFromId(act.InstanceId) -- will also trigger ui update (called by C++)
- if act.InstanceId~=self.setActId then
- if not r2:isClearingContent() then
- displaySystemInfo(concatUCString(i18n.get("uiR2EDCurrentActNotify"), act:getDisplayName()), "BC")
- end
- self.setActId = act.InstanceId
- end
- end
-end
-
------------------------------------------------------------------------------------------------------------
---
-function r2.ScenarioWindow:updateComboBoxCurrentAct(newAct)
-
- local comboB = self:getActComboBox()
- local text = ucstring()
- local currentAct = r2:getCurrentAct()
- if not (currentAct==nil or currentAct.isNil) then
- local currentActIndex = r2.ScenarioWindow:findComboBoxLineFromAct(currentAct)
- if currentActIndex then
- text:fromUtf8(currentAct:getName())
- comboB:setText(currentActIndex, text)
- end
- end
-
- local newActIndex = r2.ScenarioWindow:findComboBoxLineFromAct(newAct)
- if newActIndex then
- text:fromUtf8(newAct:getName() .. " [" .. i18n.get("uiR2EDCurrentActComboBox"):toUtf8() .."]")
- comboB:setText(newActIndex, text)
- end
-end
-
------------------------------------------------------------------------------------------------------------
--- find line in combo box for the given act (index is 0 based)
-function r2.ScenarioWindow:findComboBoxLineFromAct(act)
- local actTable = self:getActTable()
- for index, entry in pairs(actTable) do
- if entry.Act == act then
- return index - 1
- end
- end
- return nil
-end
-
------------------------------------------------------------------------------------------------------------
--- selection of a new act (called by combo box)
-function r2.ScenarioWindow:updateActTreeVisibility()
- local currentAct = r2:getCurrentAct()
- local container = self:getContainer()
- -- show the good tree control
- for i = 0, r2:getMaxNumberOfAdditionnalActs() - 1 do
- local tree = container:find("act_tree_" .. tostring(i))
- assert(tree)
- tree.active = (tree == currentAct:getContentTree())
-
- local macroTree = container:find("macro_act_tree_" .. tostring(i))
- assert(macroTree)
- macroTree.active = (macroTree == currentAct:getMacroContentTree())
- end
- -- allow to delete an act only if it is not the base act
- container:find("delete_act").active = not currentAct:isBaseAct()
-end
-
------------------------------------------------------------------------------------------------------------
--- pop window for new act creation
-
-function r2.ScenarioWindow:newAct()
-
- if r2.Scenario.Acts.Size == r2:getMaxNumberOfAdditionnalActs() + 1 then -- '+1' because first act is the base add, which can't be deleted/created
- messageBox(i18n.get("uiR2EDMaxActCountReached"))
- return
- end
-
- r2.acts:openScenarioActEditor(false)
-end
-
------------------------------------------------------------------------------------------------------------
--- Ask the user to confirm deletion of act
-function r2.ScenarioWindow:deleteAct()
- validMessageBox(i18n.get("uiR2EDconfirmDeleteAct"), "lua", "r2.ScenarioWindow:confirmDeleteAct()", "lua", "r2.ScenarioWindow:cancelDeleteAct()", "ui:interface")
-end
-
------------------------------------------------------------------------------------------------------------
--- Act deletion has been confirmed
-function r2.ScenarioWindow:confirmDeleteAct()
-
- r2.requestNewAction(i18n.get("uiR2EDRemoveActAction"))
-
- assert(not r2:getCurrentAct():isBaseAct())
- local actId = r2:getCurrentAct().InstanceId
- local firstAct = (r2.Scenario.Acts.Size>1 and (r2:getCurrentAct() == r2.Scenario.Acts[1]))
-
- -- update other acts name
- local afterDeletedAct = false
- for i=0, r2.Scenario.Acts.Size-1 do
- local act = r2.Scenario.Acts[i]
-
- if (not act:isBaseAct()) and afterDeletedAct==true then
-
- local name = act.Name
-
- local firstPart = i18n.get("uiR2EDDefaultActTitle"):toUtf8() .. i
- local firstPartSpace = i18n.get("uiR2EDDefaultActTitle"):toUtf8().. " " .. i
-
- if name == firstPart or name == firstPartSpace then
- name = i18n.get("uiR2EDDefaultActTitle"):toUtf8() .. " " .. (i-1)
- r2.requestSetNode(act.InstanceId, "Name", name)
- end
-
- elseif act.InstanceId == actId then
- afterDeletedAct = true
- end
- end
-
- -- delete permanent content of the act's island if this one isn't used in another location
- local pointToIsland = 0
- local locationId = r2:getCurrentAct().LocationId
- local islandName = r2:getInstanceFromId(locationId).IslandName
- for i=0, r2.Scenario.Locations.Size-1 do
- local location = r2.Scenario.Locations[i]
- assert(location)
-
- if location.IslandName == islandName then
- pointToIsland = pointToIsland + 1
- end
- end
-
- if pointToIsland <= 1 then
- -- search island attributes
- local islandTable = nil
- for ecoSystem, ecoSysTable in pairs(r2.acts.islands) do
- local islandNb = r2.acts:getIslandNb(islandName)
- if ecoSysTable[islandNb] and ecoSysTable[islandNb].name == islandName then
- ecoSysName = ecoSystem
- islandTable = ecoSysTable[islandNb].table
- break
- end
- end
-
- -- delete permanent content positionned in deleted location
- if false and islandTable then
- local permanentContent = {}
- local baseAct = r2.Scenario:getBaseAct()
- baseAct:appendInstancesByType(permanentContent, "WorldObject")
- for k, permObj in pairs(permanentContent) do
- local isInX = (islandTable.xmin<=permObj.Position.x and permObj.Position.x<=islandTable.xmax)
- local isInY = (islandTable.ymin<=permObj.Position.y and permObj.Position.y<=islandTable.ymax)
- if isInX and isInY then
- r2.requestEraseNode(permObj.InstanceId)
- end
- end
- end
- end
-
- -- delete the act location if any other act doesn't point to this location
- local pointToLocation = 0
- for i=0, r2.Scenario.Acts.Size-1 do
- local act = r2.Scenario.Acts[i]
- assert(act)
-
- if act.LocationId == locationId then
- pointToLocation = pointToLocation + 1
- end
- end
-
- if pointToLocation <= 1 then
- r2.requestEraseNode(locationId)
- end
-
- -- if Act[1] is deleted, we must create another one
- if actId==r2.Scenario.Acts[1].InstanceId and table.getn(r2.Scenario.Acts)<=2 then
- r2.acts:openScenarioActEditor(false, true, true)
- end
-
- r2.requestEraseNode(actId)
-
- r2.requestEndAction()
-end
-
------------------------------------------------------------------------------------------------------------
--- Act deletion has been canceled
-function r2.ScenarioWindow:cancelDeleteAct()
- debugInfo("Cancel deletion of current act")
-end
-
------------------------------------------------------------------------------------------------------------
--- Reset content of the scenario window
-function r2.ScenarioWindow:resetWindow()
- local function cleanContentTree(contentTree)
- if contentTree and not contentTree.isNil then
- r2:cleanTreeNode(contentTree, "people")
- r2:cleanTreeNode(contentTree, "creatures")
- contentTree:forceRebuild()
- end
- end
-
- local function cleanContentMacroTree(contentTree)
- if contentTree and not contentTree.isNil then
- --r2:cleanTreeNode(contentTree, "macro_components")
- r2:cleanTreeRootNode(contentTree)
- contentTree:forceRebuild()
- end
- end
-
- --
- local container = self:getContainer()
- if not container then
- debugInfo("Scenario window not found")
- return
- end
-
- -- content & geo now merged
- local contentTree = container:find("content_tree_list")
- if contentTree and not contentTree.isNil then
- --r2:cleanTreeNode(contentTree, "scenery_objects")
- r2:cleanTreeRootNode(contentTree)
- contentTree:forceRebuild()
- end
-
- --
- for i = 0, r2:getMaxNumberOfAdditionnalActs() - 1 do
- local actTree = container:find("act_tree_" .. tostring(i))
- actTree.active = false
- cleanContentTree(actTree)
-
- local actMacroTree = container:find("macro_act_tree_" .. tostring(i))
- actMacroTree.active = false
- cleanContentMacroTree(actMacroTree)
- end
- container:find("delete_act").active = false
- -- clean list of acts
- local comboBox = self:getActComboBox()
- if comboBox then
- while comboBox:getNumTexts() ~= 0 do
- comboBox:removeTextByIndex(0)
- end
- end
- self.IgnoreActChange = true -- don't whant to trigger a 'onChangeAct' request here (supposed to be called at init)
- comboBox.selection = 0
- self.IgnoreActChange = false
-end
-
-
------ WEATHER SLIDER VALUE ---------------------------------------------------------
-function r2.ScenarioWindow:weatherValue(requestType)
-
- if not self.showedActId or not r2:getInstanceFromId(self.showedActId) then return end
- local act = r2:getInstanceFromId(self.showedActId)
- assert(act)
-
- self:setActNotes()
-
- local scenarioUI = self:getContainer()
- assert(scenarioUI)
-
- local actGr = scenarioUI:find("act_properties")
- assert(actGr)
-
- local weatherValue = actGr:find("weather"):find("slider").value
- r2.requestNewAction(i18n.get("uiR2EDChangeActWeather"))
-
- if requestType == nil then
- r2.requestSetNode(act.InstanceId, "WeatherValue", weatherValue)
- elseif requestType == 'local' then
- r2.requestSetLocalNode(act.InstanceId, "WeatherValue", weatherValue)
- elseif requestType == 'commit' then
- r2.requestCommitLocalNode(act.InstanceId, "WeatherValue")
- elseif requestType == 'cancel' then
- r2.requestRollbackLocalNode(act.InstanceId, "WeatherValue")
- end
-
- r2.requestEndAction()
-end
-
------ MANUAL WEATHER ACTIVATION -------------------------------------------------------
-function r2.ScenarioWindow:manualWeather()
-
- if not self.showedActId or not r2:getInstanceFromId(self.showedActId) then return end
- local act = r2:getInstanceFromId(self.showedActId)
- assert(act)
-
- self:setActNotes()
-
- local scenarioUI = self:getContainer()
- assert(scenarioUI)
-
- local actGr = scenarioUI:find("act_properties")
- assert(actGr)
-
- local manualButton = actGr:find("manual_weather"):find("toggle_butt")
- assert(manualButton)
- local manual=1
- if manualButton.pushed==true then manual=0 end
-
- r2.requestNewAction(i18n.get("uiR2EDChangeActWeatherManual"))
- r2.requestSetNode(act.InstanceId, "ManualWeather", manual)
- r2.requestEndAction()
-end
-
---------------------- set act notes ----------------------------------------------------
-function r2.ScenarioWindow:setActNotes()
-
- if not self.showedActId or not r2:getInstanceFromId(self.showedActId) then return end
- local act = r2:getInstanceFromId(self.showedActId)
- assert(act)
-
- local scenarioUI = self:getContainer()
- assert(scenarioUI)
-
- local actGr = scenarioUI:find("act_properties")
- assert(actGr)
-
- local preActNotes = actGr:find("pre_act_notes"):find("small_description").uc_input_string:toUtf8()
- local actNotes = actGr:find("act_notes"):find("small_description").uc_input_string:toUtf8()
-
- if act==nil then act = r2:getCurrentAct() end
- if actNotes~=act.ShortDescription then
- r2.requestSetNode(act.InstanceId, "ShortDescription", actNotes)
- end
-
- if preActNotes~=act.PreActDescription then
- r2.requestSetNode(act.InstanceId, "PreActDescription", preActNotes)
- end
-end
-
-
---------------------- update act properties in scenario window -------------------------
-
-function r2.ScenarioWindow:showActProperties()
-
- local actNb = self:getActComboBox().selection + 1
- local actTable = self:getActTable()
- if actTable[actNb]==nil then return end
- local act = actTable[actNb].Act
- if act==nil then act=r2:getCurrentAct() end
-
- self:setActNotes()
- self.showedActId = act.InstanceId
-
- self:updateActProperties()
-
- local goButton = self:getContainer():find("go_to_act")
- assert(goButton)
- goButton.active = (act~=r2:getCurrentAct())
-
- local deleteButton = self:getContainer():find("delete_act")
- assert(deleteButton)
- deleteButton.active = (act==r2:getCurrentAct())
-end
-
-function r2.ScenarioWindow:updateActProperties()
-
- if not self.showedActId or not r2:getInstanceFromId(self.showedActId) then return end
- local act = r2:getInstanceFromId(self.showedActId)
- assert(act)
- assert((not act:isBaseAct()))
-
- act:updateWeather()
-
- local scenarioUI = self:getContainer()
- assert(scenarioUI)
-
- local actGr = scenarioUI:find("act_properties")
- assert(actGr)
-
- -- location name
- local location = r2:getInstanceFromId(act.LocationId)
- if location==nil then return end
- local locationName = actGr:find("location_name")
- assert(locationName)
- local uc_location = ucstring()
- uc_location:fromUtf8(location.Name)
- locationName.uc_hardtext = uc_location
-
- -- season
- local seasons = {
- ["Spring"] = "uiR2EDSpring",
- ["Summer"] = "uiR2EDSummer",
- ["Autumn"] = "uiR2EDAutumn",
- ["Winter"] = "uiR2EDWinter"
- }
- local season = actGr:find("season_name")
- assert(season)
- local uc_season = ucstring()
- local seasonStr = seasons[location.Season]
- uc_season:fromUtf8(i18n.get(seasonStr):toUtf8())
- season.uc_hardtext = uc_season
-
- -- manual weather
- local weatherGr = actGr:find("weather")
- assert(weatherGr)
- local weatherManual = weatherGr:find("manual_weather")
- assert(weatherManual)
- weatherManual:find("toggle_butt").pushed = (act.ManualWeather == 0)
-
- local weatherSlider = actGr:find("weather_slider")
- assert(weatherSlider)
- weatherSlider.active = (act.ManualWeather==1)
-
- -- weather value
- local weatherSlider = weatherGr:find("slider")
- assert(weatherSlider)
- weatherSlider.value = act.WeatherValue
-
- -- notes
- do
- local notesGr = actGr:find("act_notes")
- assert(notesGr)
- local notesAct = notesGr:find("small_description")
- assert(notesAct)
- local uc_notes = ucstring()
- uc_notes:fromUtf8(act.ShortDescription)
- notesAct.uc_input_string = uc_notes
- end
-
- -- pre act notes
- do
- local notesGr = actGr:find("pre_act_notes")
- assert(notesGr)
- local notesAct = notesGr:find("small_description")
- assert(notesAct)
- local uc_notes = ucstring()
- uc_notes:fromUtf8(act.PreActDescription)
- notesAct.uc_input_string = uc_notes
- end
-
-
- -- budget
- if act==r2:getCurrentAct() then
- local entityBudgetText = scenarioUI:find("entity_budget_text")
- local macroBudgetText = scenarioUI:find("macro_budget_text")
- local ucBudget = ucstring()
- ucBudget:fromUtf8(i18n.get("uiR2EDMacroComponentsInAct"):toUtf8() .. act:getName())
- macroBudgetText.uc_hardtext = ucBudget
- ucBudget:fromUtf8(i18n.get("uiR2EDEntitiesInAct"):toUtf8() .. act:getName())
- entityBudgetText.uc_hardtext = ucBudget
- end
-end
-
-
---------------------- update scenario properties in scenario window -------------------------
-function r2.ScenarioWindow:updateScenarioProperties()
-
- self.lockComboBoxes = true
-
- local scenario = r2.Scenario
-
- local scenarioUI = self:getContainer()
- assert(scenarioUI)
-
- local scenarioGr = scenarioUI:find("scenario_properties")
- assert(scenarioGr)
-
- -- scenario level
- local levelCB = scenarioGr:find("level_combo_box")
- assert(levelCB)
- levelCB.selection = r2.Scenario.Description.LevelId
-
- do
- local cb = scenarioGr:find("locked_combo_box")
- assert(cb)
- if r2.Scenario.Description.OtherCharAccess then
- local access = r2.Scenario.Description.OtherCharAccess
- cb.selection_text = i18n.get("uiR2ED".. access):toUtf8()
- else
- cb.selection_text = i18n.get("uiR2EDFull"):toUtf8()
- end
-
- end
-
- if r2.Scenario.Description.NevraxScenario then
- local ui = getUI("ui:interface:r2ed_palette")
- assert(ui)
- local widget = ui:find("nevrax_scenario")
- assert(widget)
- local ok = r2.Scenario.Description.NevraxScenario == "1"
- widget:find("toggle_butt").pushed = not ok
- end
-
- if r2.Scenario.Description.TrialAllowed then
- local ui = getUI("ui:interface:r2ed_palette")
- assert(ui)
- local widget = ui:find("trial_allowed_scenario")
- assert(widget)
- local ok = r2.Scenario.Description.TrialAllowed == "1"
- widget:find("toggle_butt").pushed = not ok
- end
-
- if r2.Scenario.Description.MissionTag then
- local ui = getUI("ui:interface:r2ed_palette")
- assert(ui)
- local widget = ui:find("mission_tag")
- assert(widget)
- local uc = ucstring()
- uc:fromUtf8(scenario.Description.MissionTag)
- widget:find("mission_tag_eb").eb.uc_input_string = uc
- end
-
- -- scenario rules
- local rulesCB = scenarioGr:find("rules_combo_box")
- if r2.Scenario.AccessRules == "strict" then
- rulesCB.selection = 0
- else
- rulesCB.selection = 1
- end
-
- -- scenario language
- local languageCB = scenarioGr:find("language_combo_box")
- assert(languageCB)
- languageCB.selection_text = i18n.get("uiR2ED"..r2.Scenario.Language):toUtf8()
-
- -- scenario type
- local typeCB = scenarioGr:find("type_combo_box")
- assert(typeCB)
- -- special case for old enums
- if r2.Scenario.Type =="Combat" then
- typeCB.selection_text = i18n.get("uiR2EDso_hack_slash"):toUtf8()
- elseif r2.Scenario.Type =="Roleplay" then
- typeCB.selection_text = i18n.get("uiR2EDso_story_telling"):toUtf8()
- else
- typeCB.selection_text = i18n.get("uiR2ED"..r2.Scenario.Type):toUtf8()
- end
-
- -- scenario title
- local ucTitle = ucstring()
- ucTitle:fromUtf8(scenario.Description.Title)
- getUI("ui:interface:r2ed_scenario"):find("title_eb").eb.uc_input_string = ucTitle
-
- -- scenario notes
- local notesGr = scenarioGr:find("scenario_notes")
- assert(notesGr)
- local notesScenario = notesGr:find("small_description")
- assert(notesScenario)
- local uc_notes = ucstring()
- uc_notes:fromUtf8(scenario.Description.ShortDescription)
- notesScenario.uc_input_string = uc_notes
-
- -- scenario name
- local scenarioName = scenarioUI:find("scenario_name_text")
- local uc_name = ucstring()
- uc_name:fromUtf8(i18n.get("uiR2EDScenarioFilename"):toUtf8() .. " " ..ucstring(scenario:getName()):toUtf8())
- scenarioName.uc_hardtext = uc_name
-
- self.lockComboBoxes = false
-end
-
---------------------- set scenario notes ----------------------------------------------------
-function r2.ScenarioWindow:setScenarioNotes()
-
- local scenarioUI = self:getContainer()
- assert(scenarioUI)
-
- local scenarioGr = scenarioUI:find("scenario_properties")
- assert(scenarioGr)
-
- local scenarioNotes = scenarioGr:find("scenario_notes"):find("small_description").uc_input_string:toUtf8()
-
- if r2.Scenario and scenarioNotes~= r2.Scenario.Description.ShortDescription then
- r2.requestNewAction(i18n.get("uiR2EDChangeScenarioDescription"))
- r2.requestSetNode(r2.Scenario.Description.InstanceId, "ShortDescription", scenarioNotes)
- r2.requestEndAction()
- end
-end
-
---------------------- set scenario level ----------------------------------------------------
-function r2.ScenarioWindow:scenarioLevel()
- if self.lockComboBoxes then return end
-
- self:setScenarioNotes()
- self:onTitleChanged()
-
- local scenarioWnd = self:getContainer()
- local levelCB = scenarioWnd:find("level_combo_box")
- r2.requestNewAction(i18n.get("uiR2EDChangeScenarioLevel"))
- r2.requestSetNode(r2.Scenario.Description.InstanceId, "LevelId", levelCB.selection)
- r2.requestEndAction()
-end
-
---------------------- set scenario rules ----------------------------------------------------
-function r2.ScenarioWindow:scenarioRules()
- if self.lockComboBoxes then return end
-
- self:setScenarioNotes()
- self:onTitleChanged()
-
- local scenarioWnd = self:getContainer()
- local rulesCB = scenarioWnd:find("rules_combo_box")
- local rules = {[0]="strict", [1]="liberal"}
- r2.requestNewAction(i18n.get("uiR2EDChangeScenarioRules"))
- r2.requestSetNode(r2.Scenario.InstanceId, "AccessRules", rules[rulesCB.selection])
- r2.requestEndAction()
-end
-
-------------- set scenario language ----------------------------------------------------------
-function r2.ScenarioWindow:scenarioLanguage()
-
- if self.lockComboBoxes then return end
-
- self:setScenarioNotes()
- self:onTitleChanged()
-
- local comboB = getUICaller()
- local language = self.Languages[comboB.selection_text]
-
- r2.requestNewAction(i18n.get("uiR2EDChangeScenarioLanguage"))
- r2.requestSetNode(r2.Scenario.InstanceId, "Language", language)
- r2.requestEndAction()
-end
-
-------------- set scenario type ---------------------------------------------------------------
-function r2.ScenarioWindow:scenarioType()
-
- if self.lockComboBoxes then return end
-
- self:setScenarioNotes()
- self:onTitleChanged()
-
- local comboB = getUICaller()
- local type = self.Types[comboB.selection_text]
-
- r2.requestNewAction(i18n.get("uiR2EDChangeScenarioType"))
- r2.requestSetNode(r2.Scenario.InstanceId, "Type", type)
- r2.requestEndAction()
-end
-
-------------- set scenario type ---------------------------------------------------------------
-function r2.ScenarioWindow:scenarioEditionLocked()
-
- if self.lockComboBoxes then return end
-
- self:setScenarioNotes()
- self:onTitleChanged()
-
- local comboB = getUICaller()
-
- local type = self.Locked[comboB.selection_text]
- -- RoS not usefull anymore
- if type == "RoSOnly" and config.R2EDExtendedDebug ~= 1 then
- type = "Full"
- self.lockComboBoxes = true
- comboB.selection_text = i18n.get("uiR2EDFull")
- self.lockComboBoxes = false
- end
- r2.requestNewAction(i18n.get("uiR2EDChangeScenarioEditionLock"))
- r2.requestSetNode(r2.Scenario.Description.InstanceId, "OtherCharAccess", type)
- r2.requestEndAction()
-end
---------------------------------------------------------------------------
--- the scenario title was changed by the user
-function r2.ScenarioWindow:onTitleChanged()
- if self.lockComboBoxes then return end
- local newTitle = getUI("ui:interface:r2ed_scenario"):find("title_eb").eb.uc_input_string:toUtf8()
- if newTitle ~= r2.Scenario.Description.Title then
- r2.requestNewAction(i18n.get("uiR2EDChangeScenarioTitle"))
- r2.requestSetNode(r2.Scenario.Description.InstanceId, "Title", newTitle)
- r2.requestEndAction()
- end
-end
-
------------------------ cancel focus on text of all edit box when select a new tab --------------
-function r2.ScenarioWindow:cancelFocusOnText()
- local editBox = getUICaller()
- assert(editBox)
- editBox:cancelFocusOnText()
-end
-
-
-
---------------------- set nevrax scenario ----------------------------------------------------
-function r2.ScenarioWindow:nevraxScenario()
- if self.lockComboBoxes then return end
- if config.R2EDExtendedDebug ~= 1 then return end
-
- local scenarioUI = getUI("ui:interface:r2ed_palette")
- assert(scenarioUI)
-
- local widget = scenarioUI:find("nevrax_scenario")
- assert(widget)
-
-
- local val = "0"
- if widget:find("toggle_butt").pushed then val = "0" else val = "1" end
-
- self:setScenarioNotes()
- self:onTitleChanged()
-
-
- r2.requestNewAction(i18n.get("uiR2EDChangeScenarioNevraxTag"))
- r2.requestSetNode(r2.Scenario.Description.InstanceId, "NevraxScenario", val)
- r2.requestEndAction()
-
-
-end
-
---------------------- set nevrax scenario ----------------------------------------------------
-function r2.ScenarioWindow:trialAllowed()
- if self.lockComboBoxes then return end
- if config.R2EDExtendedDebug ~= 1 then return end
-
- local ui = getUI("ui:interface:r2ed_palette")
- assert(ui)
-
- local widget = ui:find("trial_allowed_scenario")
- assert(widget)
-
- local val = "0"
- if widget:find("toggle_butt").pushed then val = "0" else val = "1" end
-
- self:setScenarioNotes()
- self:onTitleChanged()
-
- r2.requestNewAction(i18n.get("uiR2EDChangeTrialAllowedTag"))
- r2.requestSetNode(r2.Scenario.Description.InstanceId, "TrialAllowed", val )
- r2.requestEndAction()
-
-end
-
---------------------------------------------------------------------------
--- the scenario title was changed by the user
-function r2.ScenarioWindow:onScenarioMissionTagChanged()
- if self.lockComboBoxes then return end
- if config.R2EDExtendedDebug ~= 1 then return end
- local newTag = getUI("ui:interface:r2ed_palette"):find("mission_tag"):find("mission_tag_eb").eb.uc_input_string:toUtf8()
-
- self:setScenarioNotes()
- self:onTitleChanged()
-
- if newTag ~= r2.Scenario.Description.MissionTag then
- r2.requestNewAction(i18n.get("uiR2EDChangeMissionTag"))
- r2.requestSetNode(r2.Scenario.Description.InstanceId, "MissionTag", newTag)
- r2.requestEndAction()
- end
-end
-
diff --git a/code/ryzom/common/data_common/r2/r2_ui_scenario_scores.lua b/code/ryzom/common/data_common/r2/r2_ui_scenario_scores.lua
deleted file mode 100644
index d8f9de85a..000000000
--- a/code/ryzom/common/data_common/r2/r2_ui_scenario_scores.lua
+++ /dev/null
@@ -1,311 +0,0 @@
--------------------------------------------------------------------------------------------------------------
----------------------------------- SCENARIO SCORES --------------------------------------------------
--------------------------------------------------------------------------------------------------------------
-
-ScenarioScores =
-{
- emptyScore = "",
- emptyAverage = "-",
-}
-
---------------------------------------------------------------------------------------------------------------
---
-function ScenarioScores:getWindow()
- local ui = getUI("ui:interface:r2ed_scenario_scores")
- assert(ui)
- return ui
-end
-
---------------------------------------------------------------------------------------------------------------
---
-
-function ScenarioScores:initScenarioScores()
-
-end
-
-function ScenarioScores:initScenarioScoresOLD()
-
- local ui = self:getWindow()
-
- local noRatingsGr = ui:find("no_ratings")
- assert(noRatingsGr)
-
- local ratingsGr = ui:find("ratings")
- assert(ratingsGr)
-
- local averagesGr = ui:find("average_ratings")
- assert(averagesGr)
-
- noRatingsGr.active= not isInRingMode()
- if isInRingMode() then
-
- local isDm = false
- if r2.Mode == "DM" or r2.Mode == "AnimationModeDm" then isDm = true end
-
- local header = r2.getScenarioHeader()
- local seeAverages = (isDm or r2.hasCharacterSameCharacterIdMd5(tostring(header.CreatorMD5)))
- ratingsGr.active = not seeAverages
- averagesGr.active = seeAverages
- else
- ratingsGr.active = false
- averagesGr.active = false
- end
-
- if isInRingMode() then
-
- if ratingsGr.active then
- if game.getScenarioScores then
- game.getScenarioScores()
- end
-
- local rateFunUI = ratingsGr:find("fun_rate"):find("edit_rate"):find("eb")
- rateFunUI.input_string= self.emptyScore
-
- local rateDifficultyUI = ratingsGr:find("diff_rate"):find("edit_rate"):find("eb")
- rateDifficultyUI.input_string= self.emptyScore
-
- local rateAccessibilityUI = ratingsGr:find("access_rate"):find("edit_rate"):find("eb")
- rateAccessibilityUI.input_string= self.emptyScore
-
- local rateOriginalityUI = ratingsGr:find("originality_rate"):find("edit_rate"):find("eb")
- rateOriginalityUI.input_string= self.emptyScore
-
- local rateDirectionUI = ratingsGr:find("direction_rate"):find("edit_rate"):find("eb")
- rateDirectionUI.input_string= self.emptyScore
-
- else
- if game.getSessionAverageScores then
- game.getSessionAverageScores()
- end
-
- local rateFunUI = averagesGr:find("fun_rate"):find("score_text")
- rateFunUI.hardtext= self.emptyAverage
-
- local rateDifficultyUI = averagesGr:find("diff_rate"):find("score_text")
- rateDifficultyUI.hardtext= self.emptyAverage
-
- local rateAccessibilityUI = averagesGr:find("access_rate"):find("score_text")
- rateAccessibilityUI.hardtext= self.emptyAverage
-
- local rateOriginalityUI = averagesGr:find("originality_rate"):find("score_text")
- rateOriginalityUI.hardtext= self.emptyAverage
-
- local rateDirectionUI = averagesGr:find("direction_rate"):find("score_text")
- rateDirectionUI.hardtext= self.emptyAverage
- end
- end
-
- -- windows title
- if ratingsGr.active then
- ui.uc_title = i18n.get("uiR2EDMyScenarioScores")
- else
- ui.uc_title = i18n.get("uiR2EDScenarioScores")
- end
-end
-
---------------------------------------------------------------------------------------------------------------
---
-function ScenarioScores:onScenarioScoresReceived(scores)
-
- self:fill(scores)
-end
-
---------------------------------------------------------------------------------------------------------------
---
-function ScenarioScores:onAverageScoresReceived(averages)
-
- self:fillAverages(averages)
-end
-
---------------------------------------------------------------------------------------------------------------
---
-function ScenarioScores:onScenarioAverageScoresReceived(averages)
-
- self:fillScenarioAverages(averages)
-end
-
---------------------------------------------------------------------------------------------------------------
---
-function ScenarioScores:fill(scores)
-
- local ui = self:getWindow()
- local ratingsGr = ui:find("ratings")
- assert(ratingsGr)
-
- local rateFunUI = ratingsGr:find("fun_rate"):find("edit_rate"):find("eb")
- if scores.ScenarioRated==0 then
- rateFunUI.input_string= tostring(self.emptyScore)
- else
- rateFunUI.input_string= tostring(scores.RateFun)
- end
-
- local rateDifficultyUI = ratingsGr:find("diff_rate"):find("edit_rate"):find("eb")
- if scores.ScenarioRated==0 then
- rateDifficultyUI.input_string= tostring(self.emptyScore)
- else
- rateDifficultyUI.input_string= tostring(scores.RateDifficulty)
- end
-
- local rateAccessibilityUI = ratingsGr:find("access_rate"):find("edit_rate"):find("eb")
- if scores.ScenarioRated==0 then
- rateAccessibilityUI.input_string= tostring(self.emptyScore)
- else
- rateAccessibilityUI.input_string= tostring(scores.RateAccessibility)
- end
-
- local rateOriginalityUI = ratingsGr:find("originality_rate"):find("edit_rate"):find("eb")
- if scores.ScenarioRated==0 then
- rateOriginalityUI.input_string= tostring(self.emptyScore)
- else
- rateOriginalityUI.input_string= tostring(scores.RateOriginality)
- end
-
- local rateDirectionUI = ratingsGr:find("direction_rate"):find("edit_rate"):find("eb")
- if scores.ScenarioRated==0 then
- rateDirectionUI.input_string= tostring(self.emptyScore)
- else
- rateDirectionUI.input_string= tostring(scores.RateDirection)
- end
-end
-
---------------------------------------------------------------------------------------------------------------
---
-function ScenarioScores:fillAverages(averages)
-
- local ui = self:getWindow()
- local averagesGr = ui:find("average_ratings")
- assert(averagesGr)
-
- local rateFunUI = averagesGr:find("fun_rate"):find("score_text")
- if averages.ScenarioRated==0 then
- rateFunUI.hardtext= self.emptyAverage
- else
- rateFunUI.hardtext= tostring(math.min(100, averages.RateFun))
- end
-
- local rateDifficultyUI = averagesGr:find("diff_rate"):find("score_text")
- if averages.ScenarioRated==0 then
- rateDifficultyUI.hardtext= self.emptyAverage
- else
- rateDifficultyUI.hardtext= tostring(math.min(100, averages.RateDifficulty))
- end
-
- local rateAccessibilityUI = averagesGr:find("access_rate"):find("score_text")
- if averages.ScenarioRated==0 then
- rateAccessibilityUI.hardtext= self.emptyAverage
- else
- rateAccessibilityUI.hardtext= tostring(math.min(100, averages.RateAccessibility))
- end
-
- local rateOriginalityUI = averagesGr:find("originality_rate"):find("score_text")
- if averages.ScenarioRated==0 then
- rateOriginalityUI.hardtext= self.emptyAverage
- else
- rateOriginalityUI.hardtext= tostring(math.min(100, averages.RateOriginality))
- end
-
- local rateDirectionUI = averagesGr:find("direction_rate"):find("score_text")
- if averages.ScenarioRated==0 then
- rateDirectionUI.hardtext= self.emptyAverage
- else
- rateDirectionUI.hardtext= tostring(math.min(100, averages.RateDirection))
- end
-end
-
---------------------------------------------------------------------------------------------------------------
---
-function ScenarioScores:fillScenarioAverages(averages)
-
- local ui = getUI("ui:interface:ring_scenario_loading_window")--self:getWindow()
- assert(ui)
-
- local rateFunUI = ui:find("FunRating")
- rateFunUI.hardtext= tostring(math.min(100, averages.RateFun))
-
- local rateDifficultyUI = ui:find("DifficultyRating")
- rateDifficultyUI.hardtext= tostring(math.min(100, averages.RateDifficulty))
-
- local rateAccessibilityUI = ui:find("AccessibilityRating")
- rateAccessibilityUI.hardtext= tostring(math.min(100, averages.RateAccessibility))
-
- local rateOriginalityUI = ui:find("OriginalityRating")
- rateOriginalityUI.hardtext= tostring(math.min(100, averages.RateOriginality))
-
- local rateDirectionUI = ui:find("DirectionRating")
- rateDirectionUI.hardtext= tostring(math.min(100, averages.RateDirection))
-
- local rrpTotal = ui:find("RRPTotal")
- rrpTotal.hardtext= tostring(math.min(100, averages.RRPTotal))
-
- local rollouts = ui:find("rollouts")
- local deltaH = 40
- ui:invalidateCoords()
- ui:updateCoords()
- local newHReal = rollouts.h_real
- -- must resize the parent
- local newH = newHReal + deltaH
- local yOffset = newH - ui.h
- --propertySheet.h = newH
- ui.y = ui.y + yOffset / 2
- ui.pop_min_h = newH
- ui.pop_max_h = newH
- ui:invalidateCoords()
- ui:updateCoords()
-
-end
-
---------------------------------------------------------------------------------------------------------------
---
-function ScenarioScores:limitRating()
-
- local editBox = getUICaller()
- local rating = editBox.input_string
-
- if rating~="" and tonumber(rating) > 100 then
- editBox.input_string = tostring(100)
- end
-end
-
---------------------------------------------------------------------------------------------------------------
---
-function ScenarioScores:updateScores()
-
- local ui = self:getWindow()
-
- local rateFunUI = ui:find("fun_rate"):find("edit_rate"):find("eb")
- local rateFun = 0
- if rateFunUI.input_string~="" and rateFunUI.input_string~=self.emptyScore then
- rateFun = math.min(100, tonumber(rateFunUI.input_string))
- end
-
- local rateDifficultyUI = ui:find("diff_rate"):find("edit_rate"):find("eb")
- local rateDifficulty = 0
- if rateDifficultyUI.input_string~=self.emptyScore then
- rateDifficulty = math.min(100, tonumber(rateDifficultyUI.input_string))
- end
-
- local rateAccessibilityUI = ui:find("access_rate"):find("edit_rate"):find("eb")
- local rateAccessibility = 0
- if rateAccessibilityUI.input_string~=self.emptyScore then
- rateAccessibility = math.min(100, tonumber(rateAccessibilityUI.input_string))
- end
-
- local rateOriginalityUI = ui:find("originality_rate"):find("edit_rate"):find("eb")
- local rateOriginality = 0
- if rateOriginalityUI.input_string~=self.emptyScore then
- rateOriginality = math.min(100, tonumber(rateOriginalityUI.input_string))
- end
-
- local rateDirectionUI = ui:find("direction_rate"):find("edit_rate"):find("eb")
- local rateDirection = 0
- if rateDirectionUI.input_string~=self.emptyScore then
- rateDirection = math.min(100, tonumber(rateDirectionUI.input_string))
- end
-
- if game.updateScenarioScores then
- game.updateScenarioScores(rateFun, rateDifficulty, rateAccessibility, rateOriginality, rateDirection)
- end
-
- ui.active=false
-end
-
diff --git a/code/ryzom/common/data_common/r2/r2_ui_select_bar.lua b/code/ryzom/common/data_common/r2/r2_ui_select_bar.lua
deleted file mode 100644
index 6dab1505a..000000000
--- a/code/ryzom/common/data_common/r2/r2_ui_select_bar.lua
+++ /dev/null
@@ -1,337 +0,0 @@
--- réed selection bar
-
-
-r2.SelectBar =
-{
- Content={}, -- array of instance for the current select bar that is displayed
- ObserverHandles = {}, -- for each observed instance, gives its observer handle
- Touched = false
-}
-
-
--- select bar observer : allows to know when a targeted object has been modified, or
--- if its name has changed
-local selectBarObserver = {}
-
-function selectBarObserver:onInstanceCreated(instance)
- -- no-op
-end
-
-function selectBarObserver:onInstanceErased(instance)
- debugInfo(tostring(instance))
- -- nb : we don't use the 'instance' as a key because it is a pointer
- -- to the C++ "weak pointer object", thus 2 references to the same instance may have a different
- -- value when tested with rawequal ( == operator gives correct results however ...)
- r2:removeInstanceObserver(r2.SelectBar.ObserverHandles[instance.InstanceId])
- r2.SelectBar.ObserverHandles[instance.InstanceId] = nil
- -- object is not erased yet, so need to clean the table before the update
- local maxElem = r2.SelectBar:getMaxNumEntries()
- for k, v in pairs(r2.SelectBar.Content) do
- if v == instance then
- for index = k, maxElem do
- r2.SelectBar.Content[index] = nil
- end
- break
- end
- end
- if instance ~= r2:getSelectedInstance() then
- -- nb : if instance is the selection, no need to update the bar right now, because setSelecteInstance(nil) is
- -- called just after 'erase' notification messages have been sent
- r2.SelectBar:touch()
- end
-end
-
-function selectBarObserver:onAttrModified(instance, attrName, attrIndex)
- if attrName == "Name" or attrName == "Title" then
- r2.SelectBar:touch()
- end
-end
-
---------------------------------------------------------
--- retrieve a reference to the select bar
-function r2.SelectBar:getBar()
- return getUI("ui:interface:r2ed_select_bar:buttons")
-end
-
---------------------------------------------------------
--- get a button in the bar
-function r2.SelectBar:getButton(index)
- return self:getBar():find(string.format("b%d", index))
-end
-
---------------------------------------------------------
--- return the max number of button in the select bar
-function r2.SelectBar:getMaxNumEntries()
- return tonumber(getDefine("r2ed_max_num_select_bar_button"))
-end
-
---------------------------------------------------------
--- init the select bar
-function r2.SelectBar:init()
- assert(next(self.ObserverHandles) == nil) -- observer table should be empty
- local bar = self:getBar()
- bar:clear()
- for k = 1, self:getMaxNumEntries() do
- debugInfo(tostring(k))
- local butt = createGroupInstance("r2ed_select_bar_button", bar.id,
- {
- id = string.format("b%d", k),
- onclick_l="lua",
- params_l=string.format("r2.SelectBar:onButtonPushed(%d)", k),
- onclick_r="lua",
- params_r=string.format("r2.SelectBar:onRightButtonPushed(%d)", k)
- })
- butt.active = false
- bar:addChild(butt)
- end
-end
-
---------------------------------------------------------
--- mark the select bar as modified for update
-function r2.SelectBar:touch()
- self.Touched = true
-end
-
---------------------------------------------------------
--- update select bar content if necessary
-function r2.SelectBar:update()
- if not self.Touched then return end
- self.Touched = false
- -- clear the observer table
- for k, v in pairs(self.ObserverHandles) do
- r2:removeInstanceObserver(v)
- end
- table.clear(self.ObserverHandles)
- local selection = r2:getSelectedInstance()
- self:getBar().active = true
- -- count number of elligible elements for display in the select bar
- local buttCount = 0
- local currElem = selection
-
- -- setup a button from an instance
- local function setupButton(butt, instance)
- butt.active = true
- butt.b.pushed = (instance == selection)
- butt.b.uc_hardtext = instance:getDisplayName()
- local icon = instance:getSelectBarIcon()
- if icon ~= "" and icon ~= nil then
- butt.icon.texture = icon
- butt.icon.active = true
- -- butt.icon.color_rgba = CRGBA(255, 255, 255, 255)
- butt.b.text_x = 28
- butt.b.wmargin = 10
- else
- -- butt.icon.color_rgba = CRGBA(127, 127, 127, 255)
- butt.icon.active = false
- butt.b.text_x = 12
- butt.b.wmargin = 12
- end
- butt:invalidateCoords()
- end
-
-
- if selection then
- while currElem do
- if currElem:displayInSelectBar() then
- buttCount = buttCount + 1
- end
- currElem = currElem.ParentInstance
- end
- end
- buttCount =math.min(buttCount, self:getMaxNumEntries())
- local target = selection
- if buttCount < 2 then
- target = r2:getCurrentAct() -- ensure that at least 'scenario' and 'act' are visible
- buttCount = 2
- end
- -- add the buttons for real
- -- parents
- local buttIndex = buttCount
- local currElem = target
- while currElem do
- if currElem:displayInSelectBar() then
- local butt =
- setupButton(self:getButton(buttIndex), currElem)
- self.Content[buttIndex] = currElem
- self.ObserverHandles[currElem.InstanceId] = r2:addInstanceObserver(currElem.InstanceId, selectBarObserver)
- buttIndex = buttIndex - 1
- end
- currElem = currElem.ParentInstance
- end
- -- sons
- -- preserve previous sons if they where in previous selection,
- -- possibly renaming them
- -- (nb : update may be triggered by modification of sons from a third party, so
- -- the simpler approach 'if curr selection was in previous then leave unchanged'
- -- doesn't work here ...)
- buttIndex = buttCount + 1
- -- get next son that can be displayed in the select bar
- local currParent = target
- while self.Content[buttIndex] ~= nil and not self.Content[buttIndex].isNil do
- currElem = self.Content[buttIndex]
- if currElem:getFirstSelectBarParent() == currParent then
- -- there's a match so keep this entry
- setupButton(self:getButton(buttIndex), currElem)
- currParent = self.Content[buttIndex]
- buttIndex = buttIndex + 1
- self.ObserverHandles[currElem.InstanceId] = r2:addInstanceObserver(currElem.InstanceId, selectBarObserver)
- else
- -- no match -> exit
- break
- end
- end
-
- -- hide remaining buttons
- for k = buttIndex, self:getMaxNumEntries() do
- self:getButton(k).active = false
- self.Content[k] = nil
- end
-
- -- show/hide sequence browser if necessary
- local sequenceMenuButton = self:getSequenceButton()
- if not selection then
- sequenceMenuButton.active = false
- else
- sequenceMenuButton.active = selection:isSequencable() and (selection.Ghost ~= true)
- end
-end
-
---------------------------------------------------------
--- called by the ui when one of the select bar button has been pushed
-function r2.SelectBar:onButtonPushed(index)
- local instanceId = self.Content[index].InstanceId
- local selectedInstance = r2:getSelectedInstance()
- if selectedInstance and instanceId == selectedInstance.InstanceId then
- -- on second click the contextual menu is displayed
- self:popMenu(index)
- end
- r2:setSelectedInstanceId(instanceId)
- self:getButton(index).b.pushed = true
-end
-
---------------------------------------------------------
--- called by the ui when one of the select bar button has been pushed with the right button
-function r2.SelectBar:onRightButtonPushed(index)
- r2:setSelectedInstanceId(self.Content[index].InstanceId)
- self:update()
- self:onButtonPushed(index)
-end
-
-
---------------------------------------------------------
--- get root menu for the select bar
-function r2.SelectBar:getRootMenu()
- local menu = getUI("ui:interface:r2ed_select_bar_menu")
- return menu:getRootMenu()
-end
-
---------------------------------------------------------
--- get menu for the select bar
-function r2.SelectBar:getMenu()
- return getUI("ui:interface:r2ed_select_bar_menu")
-end
-
---------------------------------------------------------
--- get the 'sequences' button
-function r2.SelectBar:getSequenceButton()
- return getUI("ui:interface:r2ed_select_bar:sequences")
-end
-
---------------------------------------------------------
--- display sub-instance menu for the given button
-function r2.SelectBar:popMenu(index)
- local target = r2:getInstanceFromId(self.Content[index].InstanceId)
- --r2:setSelectedInstanceId(target.InstanceId)
- local menu = getUI("ui:interface:r2ed_select_bar_menu")
- local rm = self:getRootMenu()
- r2:clearMenu(rm)
- local st = os.clock()
- -- retrieve all sons (to optimize if needed ...)
- local allSons = {}
- if target:isKindOf("Scenario") then
- -- special case for scenario : 'appendInstancesByType' would only add the active act, and we want them all
- for k, v in specPairs(target.Acts) do
- table.insert(allSons, v)
- end
- else
- target:appendInstancesByType(allSons, "BaseClass")
- end
- local et = os.clock()
- debugInfo("#1 " .. tostring(et - st))
- st = os.clock()
- local sons = {}
- -- retrieve direct selectable sons
- for k,v in pairs(allSons) do
- if v:displayInSelectBar() and v:getFirstSelectBarParent() == target then
- table.insert(sons, v)
- end
- end
- et = os.clock()
- debugInfo("#2 " .. tostring(et - st))
- st = os.clock()
- -- sort by category, then by icon
- local function sorter(lhs, rhs)
- if lhs:getClassName() ~= rhs:getClassName() then return lhs:getClassName() < rhs:getClassName() end
- if lhs:getSelectBarIcon() ~= rhs:getSelectBarIcon() then return lhs:getSelectBarIcon() < rhs:getSelectBarIcon() end
- return lhs:getDisplayName() < rhs:getDisplayName()
- end
- table.sort(sons, sorter)
- et = os.clock()
- debugInfo("#3 " .. tostring(et - st))
- st = os.clock()
- -- fill menu
- local currentLine = 0
- for k, v in pairs(sons) do
- r2:addMenuLine(rm, v:getDisplayName(), "lua", "r2:setSelectedInstanceId('" .. v.InstanceId .."')", tostring(k), v:getSelectBarIcon(), 14)
- --rm:addLine(v:getDisplayName(), "lua", "r2:setSelectedInstanceId('" .. v.InstanceId .."')", tostring(k))
- --if v:getSelectBarIcon() ~= "" then
- -- local menuButton = createGroupInstance("r2_menu_button", "", { bitmap = v:getSelectBarIcon(), size="14" })
- -- if menuButton then
- -- rm:setUserGroupLeft(currentLine, menuButton)
- -- end
- -- end
- currentLine = currentLine + 1
- end
- target:completeSelectBarMenu(rm)
- if rm:getNumLine() == 0 then
- rm:addLine(i18n.get("uiR2EDEmpty"), "", "", "empty")
- end
- et = os.clock()
- debugInfo("#4 " .. tostring(et - st))
- et = os.clock()
- launchContextMenuInGame(menu.id)
- local butt = self:getButton(index)
- menu.x = butt.x_real
- menu.y = butt.y_real + butt.h_real
- menu:updateCoords()
- et = os.clock()
- debugInfo("#5 " .. tostring(et - st))
-end
-
---------------------------------------------------------
--- TMP placeholder: called when the "sequence" menu is clicked
-function r2.SelectBar:browseSequences()
-
- --r2:updateActivitiesAndChatsUI(r2:getSelectedInstance())
- r2.activities:initEditorAfterFirstCall()
-
- local logicEntity = r2:getSelectedInstance()
- local activitySequences = logicEntity:getBehavior().Activities
-
- local menu = self:getMenu()
- local rm = menu:getRootMenu()
- r2:clearMenu(rm)
- for s = 0, activitySequences.Size - 1 do
- local sequence = activitySequences[s]
- rm:addLine(ucstring(r2:getSequenceName(sequence)), "lua", "r2:selectActivitiesSequence(".. tostring(s) .. ")", "s")
- end
- rm:addSeparator()
- r2:addMenuLine(rm, i18n.get("uiR2EDNewSequence"), "lua", "r2:newMiniActivitySequence()", "new_sequence", "r2_icon_create.tga", 14)
-
- local sequenceMenuButton = self:getSequenceButton()
- sequenceMenuButton:updateCoords()
- launchContextMenuInGame(menu.id)
- menu.x = sequenceMenuButton.x_real
- menu.y = sequenceMenuButton.y_real + sequenceMenuButton.h_real
- menu:updateCoords()
-end
diff --git a/code/ryzom/common/data_common/r2/r2_ui_select_bar_2.lua b/code/ryzom/common/data_common/r2/r2_ui_select_bar_2.lua
deleted file mode 100644
index 92a299c83..000000000
--- a/code/ryzom/common/data_common/r2/r2_ui_select_bar_2.lua
+++ /dev/null
@@ -1,578 +0,0 @@
--- réed selection bar
-
-
-r2.SelectBar =
-{
- Content={}, -- array of instance for the current select bar that is displayed
- ObserverHandles = {}, -- for each observed instance, gives its observer handle
- Touched = false,
- LastMenuPopper = nil, -- last instance in the scenario that popped the mnu
- LastMenuHideTrigger = nil, -- last element that triggered the disparition of the select bar menu
- InstancesType = "",
- InstancesTypes = {
- {["type"]=i18n.get("uiR2EDScene"):toUtf8(), ["icon"]="r2_palette_entities.tga" },
- {["type"]=i18n.get("uiR2EDMacroComponents"):toUtf8(), ["icon"]="r2_palette_components.tga" },
- {["type"]=i18n.get("uiR2EDbotObjects"):toUtf8(), ["icon"]="r2_palette_objets.tga" },
- {["type"]=i18n.get("uiR2EDPlotItems"):toUtf8(), ["icon"]="ICO_mission_purse.tga" }
- },
-}
-
-
--- select bar observer : allows to know when a targeted object has been modified, or
--- if its name has changed
-local selectBarObserver = {}
-
-function selectBarObserver:onInstanceCreated(instance)
- -- no-op
-end
-
-function selectBarObserver:onInstanceErased(instance)
- -- debugInfo(tostring(instance))
- -- nb : we don't use the 'instance' as a key because it is a pointer
- -- to the C++ "weak pointer object", thus 2 references to the same instance may have a different
- -- value when tested with rawequal ( == operator gives correct results however ...)
- r2:removeInstanceObserver(r2.SelectBar.ObserverHandles[instance.InstanceId])
- r2.SelectBar.ObserverHandles[instance.InstanceId] = nil
- -- object is not erased yet (notification is sent before the true erase), so need to clean the table before the update
- local maxElem = r2.SelectBar:getMaxNumEntries()
- for k, v in pairs(r2.SelectBar.Content) do
- if v == instance then
- for index = k, maxElem do
- r2.SelectBar.Content[index] = nil
- end
- break
- end
- end
- if instance ~= r2:getSelectedInstance() then
- -- nb : if instance is the selection, no need to update the bar right now, because setSelecteInstance(nil) is
- -- called just after 'erase' notification messages have been sent
- r2.SelectBar:touch()
- end
- r2.SelectBar:touch()
-end
-
-function selectBarObserver:onPostHrcMove(instance)
- r2.SelectBar:touch()
-end
-
-function selectBarObserver:onAttrModified(instance, attrName, attrIndex)
- if attrName == "Name" or attrName == "Title" then
- r2.SelectBar:touch()
- end
-end
-
---------------------------------------------------------
--- retrieve a reference to the select bar
-function r2.SelectBar:getBar()
- return getUI("ui:interface:r2ed_select_bar:buttons")
-end
-
---------------------------------------------------------
--- get a button in the bar
-function r2.SelectBar:getButton(index)
- return self:getBar():find(string.format("b%d", index))
-end
-
---------------------------------------------------------
--- return the max number of button in the select bar
-function r2.SelectBar:getMaxNumEntries()
- return tonumber(getDefine("r2ed_max_num_select_bar_button"))
-end
-
---------------------------------------------------------
--- init the select bar
-function r2.SelectBar:init()
-
- assert(next(self.ObserverHandles) == nil) -- observer table should be empty
- local bar = self:getBar()
- bar:clear()
- for k = 1, self:getMaxNumEntries() do
- local butt = createGroupInstance("r2ed_select_bar_button", bar.id,
- {
- id = string.format("b%d", k),
- onclick_l="lua",
- onclick_r="lua",
- params_l=string.format("r2.SelectBar:onButtonPushed(%d)", k),
- params_r=string.format("r2.SelectBar:onRightButtonPushed(%d)", k),
- })
- butt.active = false
- bar:addChild(butt)
- end
- bar.active = false
-end
-
---------------------------------------------------------
--- mark the select bar as modified for update
-function r2.SelectBar:touch()
- self.Touched = true
- local selection = r2:getSelectedInstance()
- if selection and selection:isKindOf("Act") then
- self.InstancesType = ""
- end
-end
-
----------------------------------------------------------------
--- update bar in special case of act
-function r2.SelectBar:openInstancesOfType(instancesType)
- r2.SelectBar:touch()
- self.InstancesType = instancesType
-end
---------------------------------------------------------
--- update select bar content if necessary
-function r2.SelectBar:update()
-
- if not self.Touched then return end
- if r2.Scenario == nil then
- return -- no scenario created for now
- end
- self.Touched = false
-
- -- clear the observer table
- for k, v in pairs(self.ObserverHandles) do
- r2:removeInstanceObserver(v)
- end
- table.clear(self.ObserverHandles)
- local selection = r2:getSelectedInstance()
- if selection then
- self:getBar().active = (selection.Ghost ~= true)
- else
- self:getBar().active = true
- end
-
-
-
- local function setupButtonWithIconAndText(butt, text, icon, buttIndex)
- butt.active = true
- butt.b.uc_hardtext = text
- local icon = icon
- if icon ~= "" and icon ~= nil then
- butt.icon.texture = icon
- butt.icon.active = true
- -- butt.icon.color_rgba = CRGBA(255, 255, 255, 255)
- butt.b.text_x = 28
- butt.b.wmargin = 10
- else
- -- butt.icon.color_rgba = CRGBA(127, 127, 127, 255)
- butt.icon.active = false
- butt.b.text_x = 12
- butt.b.wmargin = 12
- end
- --butt.b.pushed = (instance == selection)
- butt:invalidateCoords()
- end
-
- -- setup a button from an instance
- local function setupButton(butt, instance, buttIndex)
- setupButtonWithIconAndText(butt, instance:getDisplayName(), instance:getSelectBarIcon(), buttIndex)
- butt.Env.Types = false
- end
-
- -- setup a button from a type
- local function setupButtonType(butt, type, buttIndex)
- local icon
- for k, v in pairs(self.InstancesTypes) do
- if v.type == type then
- icon = v.icon
- break
- end
- end
- setupButtonWithIconAndText(butt, ucstring(type), icon, buttIndex)
- butt.Env.Types = true
- end
-
- -- count number of elligible elements for display in the select bar
- local buttCount = 0
- local currElem = selection
- if selection then
- while currElem do
- if currElem:displayInSelectBar() then
- buttCount = buttCount + 1
-
- if currElem:isKindOf("Act") and self.InstancesType~="" then
- buttCount = buttCount + 1
- end
- end
- currElem = currElem.ParentInstance
- end
- end
-
- local target = selection
- if buttCount < 1 then
- target = r2:getCurrentAct() -- ensure that at least an act is visible
- buttCount = 1
- if self.InstancesType~="" then
- buttCount = buttCount + 1
- end
- end
-
- local buttIndex = buttCount
- -- special case for scenario wide objects (only plot items for now)
- if selection and selection:isGlobalObject() then
-
- -- current act
- currElem = r2:getCurrentAct()
- setupButton(self:getButton(1), currElem, 1)
- self.Content[1] = currElem
- self.ObserverHandles[currElem.InstanceId] = r2:addInstanceObserver(currElem.InstanceId, selectBarObserver)
-
- -- special button for type
- if self.InstancesType~="" then
- setupButtonType(self:getButton(2), self.InstancesType, 2)
- self.Content[2] = currElem
- end
-
- -- plot item
- currElem = selection
- setupButton(self:getButton(3), currElem, 3)
- self.Content[3] = currElem
- self.ObserverHandles[currElem.InstanceId] = r2:addInstanceObserver(currElem.InstanceId, selectBarObserver)
- buttIndex = 4
-
- -- special case if current selection is the scenario (display a single button)
- elseif selection and selection:isSameObjectThan(r2.Scenario) then
- setupButton(self:getButton(1), selection, buttIndex)
- self.Content[1] = selection
- self.ObserverHandles[selection.InstanceId] = r2:addInstanceObserver(selection.InstanceId, selectBarObserver)
- buttIndex = 2
- target = r2:getCurrentAct() -- continue with sons of current act
- else
- -- special case for plot items
- -- add the buttons for real
- -- parents
- local currElem = target
- while currElem do
- if currElem:displayInSelectBar() then
- if buttIndex <= self:getMaxNumEntries() then
- if currElem:isKindOf("Act") then
- if currElem:isBaseAct() then
- currElem = r2:getCurrentAct()
- end
-
- if self.InstancesType~="" then
- -- special button for different types
- local ucname = ucstring()
- ucname:fromUtf8(self.InstancesType)
- setupButtonType(self:getButton(buttIndex), ucname, buttIndex)
- self.Content[buttIndex] = currElem
- buttIndex = buttIndex - 1
- end
- end
- setupButton(self:getButton(buttIndex), currElem, buttIndex)
- self.Content[buttIndex] = currElem
- self.ObserverHandles[currElem.InstanceId] = r2:addInstanceObserver(currElem.InstanceId, selectBarObserver)
- end
- buttIndex = buttIndex - 1
- end
- currElem = currElem.ParentInstance
- end
- buttIndex = buttCount + 1
- -- sons
- -- preserve previous sons if they where in previous selection,
- -- possibly renaming them
- -- (nb : update may be triggered by modification of sons from a third party, so
- -- the simpler approach 'if curr selection was in previous then leave unchanged'
- -- doesn't work here ...)
- -- get next son that can be displayed in the select bar
- --local currParent = target
- --while self.Content[buttIndex] ~= nil and not self.Content[buttIndex].isNil do
- -- currElem = self.Content[buttIndex]
- -- if currElem:getFirstSelectBarParent() == currParent then
- -- -- there's a match so keep this entry
- -- setupButton(self:getButton(buttIndex), currElem)
- -- currParent = self.Content[buttIndex]
- -- buttIndex = buttIndex + 1
- -- self.ObserverHandles[currElem.InstanceId] = r2:addInstanceObserver(currElem.InstanceId, selectBarObserver)
- -- else
- -- -- no match -> exit
- -- break
- -- end
- --end
- end
-
- -- old version
- -- walk down sons until we reach the max number of buttons
- -- local currSon = target:getFirstSelectBarSon()
- -- while currSon and buttIndex <= self:getMaxNumEntries() do
- -- setupButton(self:getButton(buttIndex), currSon)
- -- self.Content[buttIndex] = currSon
- -- self.ObserverHandles[currSon.InstanceId] = r2:addInstanceObserver(currSon.InstanceId, selectBarObserver)
- -- currSon = currSon:getFirstSelectBarSon()
- -- buttIndex = buttIndex +1
- -- end
-
-
- -- if there's room, add a selection button to traverse down the hierarchy
- if buttIndex <= self:getMaxNumEntries() then
- local butt = self:getButton(buttIndex)
- butt.active = true
- butt.b.uc_hardtext = i18n.get("uiR2EDSelectSubObject")
- butt.icon.active = false
- butt.b.text_x = 12
- butt.b.wmargin = 12
- butt:invalidateCoords()
- --butt.b.pushed = false
- self.Content[buttIndex] = nil
- buttIndex = buttIndex + 1
- end
-
- -- hide remaining buttons
- for k = buttIndex, self:getMaxNumEntries() do
- self:getButton(k).active = false
- self.Content[k] = nil
- end
-
- -- show/hide sequence browser if necessary
- local sequenceMenuButton = self:getSequenceButton()
- if not selection then
- sequenceMenuButton.active = false
- else
- sequenceMenuButton.active = selection:isSequencable() and (selection.Ghost ~= true)
- end
- -- touch the contextual toolbar, because it y depends on us
- r2.ContextualCommands:getToolbar():invalidateCoords()
-end
-
---------------------------------------------------------
--- called by the ui when one of the select bar button has been pushed
--- function r2.SelectBar:onButtonPushed(index)
--- local instanceId = self.Content[index].InstanceId
--- local selectedInstance = r2:getSelectedInstance()
--- if selectedInstance and instanceId == selectedInstance.InstanceId then
--- -- on second click the contextual menu is displayed
--- self:popMenu(index)
--- end
--- r2:setSelectedInstanceId(instanceId)
--- self:getButton(index).b.pushed = true
--- end
---
--- --------------------------------------------------------
--- -- called by the ui when one of the select bar button has been pushed with the right button
--- function r2.SelectBar:onRightButtonPushed(index)
--- r2:setSelectedInstanceId(self.Content[index].InstanceId)
--- self:update()
--- self:onButtonPushed(index)
--- end
-
-
---------------------------------------------------------
--- mark the select bar as modified for update
-function r2.SelectBar:onMenuPostClickOut()
- local uiCaller = getUICaller()
- if uiCaller and uiCaller.parent and uiCaller.parent.parent then
- local parentGroup = uiCaller.parent.parent
- if parentGroup == getUI("ui:interface:r2ed_select_bar:buttons") then
- self.LastMenuHideTrigger = getUICaller()
- return
- end
- end
- self.LastMenuHideTrigger = nil
- self.LastMenuPopper = nil
-end
-
-
---------------------------------------------------------
--- called by the ui when one of the select bar button has been pushed
-function r2.SelectBar:onButtonPushed(index)
- local butt = self:getButton(index)
- local selectedInstance = self.Content[index]
- if selectedInstance == nil then
- -- pop menu for sons of parents
- self:popMenu(index)
- return
- end
- if butt.b == self.LastMenuHideTrigger and selectedInstance == self.LastMenuPopper then
- self.LastMenuHideTrigger = nil
- return
- end
- self.LastMenuPopper = selectedInstance
- self.LastMenuHideTrigger = nil
- r2:setSelectedInstanceId(selectedInstance.InstanceId)
- self:touch()
- -- on second click the contextual menu is displayed
- self:popMenu(index)
-end
-
---------------------------------------------------------
--- called by the ui when one of the select bar button has been pushed with the right button
-function r2.SelectBar:onRightButtonPushed(index)
- self:onButtonPushed(index)
-end
-
-
-
---------------------------------------------------------
--- get root menu for the select bar
-function r2.SelectBar:getRootMenu()
- local menu = getUI("ui:interface:r2ed_select_bar_menu")
- return menu:getRootMenu()
-end
-
---------------------------------------------------------
--- get menu for the select bar
-function r2.SelectBar:getMenu()
- return getUI("ui:interface:r2ed_select_bar_menu")
-end
-
---------------------------------------------------------
--- get the 'sequences' button
-function r2.SelectBar:getSequenceButton()
- return getUI("ui:interface:r2ed_select_bar:sequences")
-end
-
-
-
---------------------------------------------------------
--- display sub-instance menu for the given button
-function r2.SelectBar:getMenu()
- return getUI("ui:interface:r2ed_select_bar_menu")
-end
-
-local allSons = {}
-
---------------------------------------------------------
--- display sub-instance menu for the given button
-function r2.SelectBar:popMenu(index)
-
- local target
- if self.Content[index] == nil then
- -- the "select" button was pressed
- target = r2:getSelectedInstance()
- if target == nil then
- target = r2:getCurrentAct()
- end
- else
- target = r2:getInstanceFromId(self.Content[index].InstanceId)
- if not target:isSameObjectThan(r2.Scenario) then
- -- to get objects of same type, just enumerate from the parent (except for scenario)
- target = target:getFirstSelectBarParent()
- end
- end
-
- --r2:setSelectedInstanceId(target.InstanceId)
- local menu = self:getMenu()
- local rm = self:getRootMenu()
- r2:clearMenu(rm)
- local st = os.clock()
- -- retrieve all sons (optimize this if needed ...)
- table.clear(allSons)
-
- if target:isKindOf("Scenario") then
- -- special case for scenario : 'appendInstancesByType' would only add the active act, and we want them all
- for k, v in specPairs(target.Acts) do
- if not v:isBaseAct() then
- table.insert(allSons, v)
- end
- end
- elseif target:isKindOf("Act") and self:getButton(index).Env.Types~=true then
-
- for k, v in specPairs(r2.Scenario.PlotItems) do
- table.insert(allSons, v)
- end
- r2.Scenario:getBaseAct():appendInstancesByType(allSons, "BaseClass")
- r2.Scenario:getCurrentAct():appendInstancesByType(allSons, "BaseClass")
- local allSonsTemp = {}
- for k, v in pairs(allSons) do
- if v:getSelectBarType()==self.InstancesType then
- table.insert(allSonsTemp, v)
- end
- end
- allSons = allSonsTemp
-
- elseif target ~= nil then
- target:appendInstancesByType(allSons, "BaseClass")
- end
-
- local et = os.clock()
- --debugInfo("#1 " .. tostring(et - st))
- st = os.clock()
- local sons = {}
- -- retrieve direct selectable sons
- for k,v in pairs(allSons) do
- if v:displayInSelectBar() and (v:getFirstSelectBarParent()==target or (target:isKindOf("Act") and v:getFirstSelectBarParent()==r2.Scenario:getBaseAct())) then
- table.insert(sons, v)
- end
- end
-
- et = os.clock()
- --debugInfo("#2 " .. tostring(et - st))
- st = os.clock()
- -- sort by category, then by icon
- local function sorter(lhs, rhs)
- if lhs:getClassName() ~= rhs:getClassName() then return lhs:getClassName() < rhs:getClassName() end
- if lhs:getSelectBarIcon() ~= rhs:getSelectBarIcon() then return lhs:getSelectBarIcon() < rhs:getSelectBarIcon() end
- return lhs:getDisplayName() < rhs:getDisplayName()
- end
- table.sort(sons, sorter)
- et = os.clock()
- --debugInfo("#3 " .. tostring(et - st))
- st = os.clock()
- -- fill menu
-
- -- special case for act
- if index==2 then
- for k, v in pairs(self.InstancesTypes) do
- local ucname = ucstring()
- ucname:fromUtf8(v.type)
- r2:addMenuLine(rm, ucname, "lua", "r2.SelectBar:openInstancesOfType('".. v.type .."','" .. v.icon .."')", v.type, v.icon, 14)
- end
- else
- for k, v in pairs(sons) do
- r2:addMenuLine(rm, v:getDisplayName(), "lua", "r2:setSelectedInstanceId('" .. v.InstanceId .."')", tostring(k), v:getSelectBarIcon(), 14)
- end
- end
-
- target:completeSelectBarMenu(rm)
- if rm:getNumLine() == 0 then
- rm:addLine(i18n.get("uiR2EDEmpty"), "", "", "empty")
- end
- if self.Content[index] and self.Content[index].InstanceId == r2:getSelectedInstance().InstanceId then
- if r2:getSelectedInstance().BuildPropertySheet then
- rm:addSeparator()
- r2:addMenuLine(rm, concatUCString(i18n.get("uiRE2DPropertiesOf"), r2:getSelectedInstance():getDisplayName()), "lua", "r2:showProperties(r2:getSelectedInstance())", "prop", "r2_icon_properties.tga", 14)
- end
- end
- et = os.clock()
- --debugInfo("#4 " .. tostring(et - st))
- et = os.clock()
-
- rm:setMaxVisibleLine(15)
- launchContextMenuInGame(menu.id)
- local butt = self:getButton(index)
- menu.x = butt.x_real
- menu.y = butt.y_real + butt.h_real
- menu:updateCoords()
- et = os.clock()
- --debugInfo("#5 " .. tostring(et - st))
-end
-
---------------------------------------------------------
--- TMP placeholder: called when the "sequence" menu is clicked
---------------------------------------------------------
--- called when the "sequence" menu is clicked
-function r2.SelectBar:browseSequences()
-
- --r2:updateActivitiesAndChatsUI(r2:getSelectedInstance())
- r2.activities:initEditorAfterFirstCall()
-
- local logicEntity = r2:getSelectedInstance()
- local activitySequences = logicEntity:getBehavior().Activities
-
- local menu = self:getMenu()
- local rm = menu:getRootMenu()
- r2:clearMenu(rm)
- for s = 0, activitySequences.Size - 1 do
- local sequence = activitySequences[s]
- local uc_sequ = ucstring()
- uc_sequ:fromUtf8(sequence:getName())
- rm:addLine(uc_sequ, "lua", "r2.activities:triggerSelectSequence('".. sequence.InstanceId .. "')", sequence.InstanceId)
- end
- rm:addSeparator()
- r2:addMenuLine(rm, i18n.get("uiR2EDNewSequence"), "lua", "r2.activities:newSequenceInst()", "new_sequence", "r2_icon_create.tga", 14)
-
- local sequenceMenuButton = self:getSequenceButton()
- sequenceMenuButton:updateCoords()
- launchContextMenuInGame(menu.id)
- menu.x = sequenceMenuButton.x_real
- menu.y = sequenceMenuButton.y_real + sequenceMenuButton.h_real
- menu:updateCoords()
-end
diff --git a/code/ryzom/common/data_common/r2/r2_ui_toolbar_base.lua b/code/ryzom/common/data_common/r2/r2_ui_toolbar_base.lua
deleted file mode 100644
index 57dde5245..000000000
--- a/code/ryzom/common/data_common/r2/r2_ui_toolbar_base.lua
+++ /dev/null
@@ -1,193 +0,0 @@
-----------------------------
--- GENERIC TOOLBAR SYSTEM --
-----------------------------
-
--- Generic code for toolbar
---
--- A toolbar is a set of 'buttons' that triggers 'commands'
--- A 'command' is a structure returned by a function like baseClass.getAvailableCommand (see there for doc)
--- A 'button' is a widget thet may have any form you want, derivers should just tell how to setup a button from a command
---
--- Usage :
---
--- -- 1°) creation
--- myToolBar = r2.newToolbar()
---
--- -- 2°) definition of toolbar behavior. Function that should be given by the deriver are given in section below
--- function myTooBar:getToolbar()
--- ...
--- end
--- function myToolbar ...
---
--- NB : command index are starting at 0 in the ui, and at 1 in lua
-
-
---
---
---
-local toolbarTemplate = {}
-
-
-------------------------------------
--- TO BE IMPLEMENTED BY DERIVERS --
-------------------------------------
-
--- return a reference on the toolbar ui
-function toolbarTemplate:getToolbar()
- assert(false) -- ! SHOULD BE IMPLEMENTED BY DERIVER
-end
-
--- return the max number of commands that the toolbar may contains
-function toolbarTemplate:getMaxNumCommands()
- assert(false) -- ! SHOULD BE IMPLEMENTED BY DERIVER
-end
-
--- get a button from its index in the toolbar (starting from 0)
-function toolbarTemplate:getButton(index)
- assert(false) -- ! SHOULD BE IMPLEMENTED BY DERIVER
-end
-
--- setup a button from a commandDesc.
-function toolbarTemplate:setupButton(button, commandDesc, buttonIndex)
- assert(false) -- ! SHOULD BE IMPLEMENTED BY DERIVER
-end
-
--- retrieve a command list for the given instance
-function toolbarTemplate:getAvailableCommands(instance, dest)
- assert(false) -- ! SHOULD BE IMPLEMENTED BY DERIVER
-end
-
------------------------
--- PUBLIC INTERFACE --
------------------------
-
-----------------------------------------------------------------------------------------------------
--- Setup the contextual toolbar for the given instance
--- passing nil just hides the toolbar
-function toolbarTemplate:setupToolbar(instance)
- assert(false)
-end
-
-----------------------------------------------------------------------------------------------------
--- run a command in the toolbar from its index
-function toolbarTemplate:runCommand(index)
- assert(false)
-end
-
-
-
-----------------------------------------------------------------------------------------------------
--- call this to create a new toolbar, then specialize it
-function r2.newToolbar()
- local tb = clone(toolbarTemplate)
-
- -- description of each command
- tb.ToolbarCommands={}
- -- map index of each command to the matching toolbar button
- tb.IndexToButton = {}
- -- Current instance for which this contextual toolbar is displayed
- tb.CurrentInstance = nil
- -- Index of last triggered command
- tb.LastTriggeredCommandIndex = nil
- -- Cache for current commands
- tb.CurrentCommands = {}
- -- Command id to button
- tb.CommandIdToIndex = {}
-
-
- ----------------------------------------------------------------------------
- -- Setup the contextual toolbar for the given instance
- -- passing nil just hides the toolbar
- function tb:setupToolbar(instance)
- self.CurrentInstance = instance
- -- clear current list of commands
- table.clear(self.ToolbarCommands)
- table.clear(self.CurrentCommands)
- table.clear(self.IndexToButton)
- table.clear(self.CommandIdToIndex)
- self.LastTriggeredCommandIndex = nil
- local toolbar = self:getToolbar()
- local buttonList = toolbar:find("buttons")
- if not instance then
- toolbar.active = false
- return
- end
- local commands = self.CurrentCommands
- table.clear(commands)
- self:getAvailableCommands(instance, commands)
- assert(self.ToolbarCommands)
- toolbar.active = true
- local buttonIndex = 0
- local maxNumButtons = self:getMaxNumCommands()
- for index, commandDesc in pairs(commands) do
- local button
- if commandDesc.ButtonBitmap ~= "" and commandDesc.ButtonBitmap ~= nil then
- -- new button wanted
- local button = self:getButton(buttonIndex)
- if not button then
- inspect(buttonList)
- assert(button)
- end
- self:setupButton(button, commandDesc, buttonIndex)
- self.IndexToButton[index] = button
- self.ToolbarCommands[buttonIndex + 1] = commandDesc
- self.CommandIdToIndex[commandDesc.Id] = index
- buttonIndex = buttonIndex + 1
- if buttonIndex == maxNumButtons then break end
- end
- end
- -- hide buttons that are not visible anymore
- for index = buttonIndex, maxNumButtons - 1 do
- local button = self:getButton(index)
- button.active = false
- end
-
-
-
- end
-
- ----------------------------------------------------------------------------
- -- Run the command with the given index
- function tb:runCommand(index)
- assert(self.CurrentInstance)
- assert(self.ToolbarCommands[index] ~= nil)
- self.LastTriggeredCommandIndex = index
- -- do actual call
- self.ToolbarCommands[index].DoCommand(self.CurrentInstance)
- end
- return tb
-end
-
-----------------------------------------------------------------------------
--- Private : execute a command triggered by a toolbar button
-function r2.runBaseToolbarCommand(toolbar, index)
- assert(toolbar) -- deriver should provide the "Toolbar" field in the groups containing control that can trigger commands!
- toolbar:runCommand(index + 1)
-end
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/code/ryzom/common/data_common/r2/r2_ui_tools.lua b/code/ryzom/common/data_common/r2/r2_ui_tools.lua
deleted file mode 100644
index 8b2c75143..000000000
--- a/code/ryzom/common/data_common/r2/r2_ui_tools.lua
+++ /dev/null
@@ -1,149 +0,0 @@
-----------
--- TOOL --
-----------
--- Manage display of current selected tool into the ui
-------------------------------------------------------------------------------------------------------------
-
-
--- base Name for the tool bar in the ui
-local toolBarPath = "ui:interface:r2ed_toolbar:"
-local geoToolPath = "ui:interface:r2ed_palette:content:sbtree_geo:geo_features:enclosing:geo_feature_list:"
-local featuresToolPath = "ui:interface:r2ed_palette:content:sbtree_features:features:enclosing:feature_list:"
-
-
-r2.ToolUI =
-{
- -- ref to current hightlighted tool in the ui
- ActiveToolUI = nil,
-
- -- For named tools, map the name to the ui path
- ToolNameToUIPath =
- {
- selectMove = toolBarPath .. "r2ed_tool_select",
- selectRotate = toolBarPath .. "r2ed_tool_rotate",
- teleport = toolBarPath .. "r2ed_tool_teleport",
- drawRoad = geoToolPath .. "r2ed_tool_draw_road:tool",
- drawRegion = geoToolPath .. "r2ed_tool_draw_region:tool",
- createFeatureBanditCamp = featuresToolPath .. "r2ed_create_feature_bandit_camp:tool",
- createFeatureTimer = featuresToolPath .. "r2ed_create_feature_timer:tool",
- createFeatureTimeTrigger = featuresToolPath .. "r2ed_create_feature_time_trigger:tool",
- createFeatureFauna = featuresToolPath .. "r2ed_create_feature_fauna:tool",
- createFeatureBossSpawner = featuresToolPath .. "r2ed_create_feature_boss_spawner:tool",
- createFeatureZoneTrigger = featuresToolPath .. "r2ed_create_feature_zone_trigger:tool",
- createFeatureUserTrigger = featuresToolPath .. "r2ed_create_user_trigger:tool",
- createFeatureEasterEgg = featuresToolPath .."r2ed_create_easter:tool",
- createFeatureLootSpawner = featuresToolPath .."r2ed_create_feature_loot_spawner:tool",
- createDialog = featuresToolPath .."r2ed_create_dialog:tool",
- createFeatureGiveItem = featuresToolPath .."r2ed_create_feature_give_item:tool",
- createFeatureRequestItem = featuresToolPath .."r2ed_create_feature_request_item:tool",
- createFeatureTalkTo = featuresToolPath .."r2ed_create_feature_talk_to:tool",
- createFeatureAmbush = featuresToolPath.."r2ed_create_feature_ambush:tool",
- createFeatureTimedSpawner = featuresToolPath.."r2ed_create_feature_timed_spawner:tool",
- createFeatureManHunt = featuresToolPath.."r2ed_create_feature_man_hunt:tool",
-
-
- }
-}
-
-------------------------------------------------------------------------------------------------------------
--- PRIVATE : hightlight a tool button by a ref on the tool ui
-function r2.ToolUI:highlightToolUI(tool, hightlighted)
- if not tool then return end
- tool:find("selected").active = hightlighted
- tool:find("unselected").active = not hightlighted
-end
-
-------------------------------------------------------------------------------------------------------------
--- Get reference to a tool in the ui by its name (for named tools)
-function r2.ToolUI:getToolUIByName(toolName)
- if toolName == "" then return nil end
- -- get Name of the ui button from the tool Name
- local uiPath = self.ToolNameToUIPath[toolName]
- if uiPath == nil then
- debugWarning("Can't find ui for tool : " .. tostring(toolName))
- return nil
- end
- return getUI(uiPath)
-end
-
-------------------------------------------------------------------------------------------------------------
--- Get the current highlighted tool
-function r2.ToolUI:getActiveToolUI()
- if self.CurrentToolUI and not self.CurrentToolUI.isNil then
- return self.CurrentToolUI
- else
- return nil
- end
-end
-
-
-------------------------------------------------------------------------------------------------------------
--- Set the current highlighted tool
-function r2.ToolUI:setActiveToolUI(tool)
- if self:getActiveToolUI() then
- self:highlightToolUI(self:getActiveToolUI(), false)
- end
- self.CurrentToolUI = tool
- self:highlightToolUI(tool, true)
-end
-
-
-------------------------------------------------------------------------------------------------------------
--- This function will be called by the framework when it wants to highlight a tool in the
--- ui. It doesn't change the actual tool in the editor, just the ui
-function r2.ToolUI:setActiveToolUIByName(toolName)
- self:setActiveToolUI(self:getToolUIByName(toolName))
-end
-
-------------------------------------------------------------------------------------------------------------
-function r2.ToolUI:updateTooltip(onClickL, paramsL)
- onClickL = defaulting(onClickL, getUICaller().onclick_l)
- paramsL = defaulting(paramsL, getUICaller().params_l)
- local expr = string.format("getKey('%s', '%s')", onClickL, paramsL)
- local keyName = ucstring(runExpr(expr))
- if keyName == i18n.get("uiNotAssigned") then
- -- no associated key
- setContextHelpText(getUICaller().tooltip)
- else
- setContextHelpText(concatUCString(getUICaller().tooltip, "@{6F6F} (", keyName, ")"))
- end
-end
-
-----------------------------------------------------------------------------
--- Update the undo / redo buttons grayed states
-function r2.ToolUI:updateUndoRedo()
- local toolbar = getUI("ui:interface:r2ed_toolbar")
- toolbar:find("r2ed_tool_undo").unselected.active = r2:canUndo()
- toolbar:find("r2ed_tool_undo").disabled.active = not r2:canUndo()
- toolbar:find("r2ed_tool_redo").unselected.active = r2:canRedo()
- toolbar:find("r2ed_tool_redo").disabled.active = not r2:canRedo()
-end
-
-
-----------------------------------------------------------------------------
--- Update the toggle windows buttons
-function r2.ToolUI:updateToggleWindowButtons()
- local windowsBar = getUI("ui:interface:r2ed_windows_bar")
- local active = (r2.Mode == "Edit")
- windowsBar.active = active
- if active then
- windowsBar:find("r2ed_tool_map_window").selected.active = getUI("ui:interface:map").active
- windowsBar:find("r2ed_tool_map_window").unselected.active = not getUI("ui:interface:map").active
- windowsBar:find("r2ed_tool_scenario_window").selected.active = getUI("ui:interface:r2ed_scenario").active
- windowsBar:find("r2ed_tool_scenario_window").unselected.active = not getUI("ui:interface:r2ed_scenario").active
- windowsBar:find("r2ed_tool_palette_window").selected.active = getUI("ui:interface:r2ed_palette").active
- windowsBar:find("r2ed_tool_palette_window").unselected.active = not getUI("ui:interface:r2ed_palette").active
- end
-end
-
-----------------------------------------------------------------------------
--- Update the toggle windows buttons
-function r2.ToolUI:updateToggleWindowDMButtons()
- local windowsDMBar = getUI("ui:interface:r2ed_windows_dm_bar")
- windowsDMBar:find("r2ed_live").selected.active = getUI("ui:interface:r2ed_scenario_control").active
- windowsDMBar:find("r2ed_live").unselected.active = not getUI("ui:interface:r2ed_scenario_control").active
- windowsDMBar:find("player_control").selected.active = getUI("ui:interface:ring_chars_tracking").active
- windowsDMBar:find("player_control").unselected.active = not getUI("ui:interface:ring_chars_tracking").active
-end
-
-
diff --git a/code/ryzom/common/data_common/r2/r2_ui_triggers.lua b/code/ryzom/common/data_common/r2/r2_ui_triggers.lua
deleted file mode 100644
index 72a5e9cf5..000000000
--- a/code/ryzom/common/data_common/r2/r2_ui_triggers.lua
+++ /dev/null
@@ -1,3931 +0,0 @@
-r2.maxActivities = 14
-r2.sequencesNb = 0
-
-r2.TimeLimitsProp = {
- [tostring(i18n.get("uiR2EdNoTimeLimit"))]="No Limit",
- --["Until a certain time"]="Until",
- [tostring(i18n.get("uiR2EdWhileChat"))]="Chat",
- [tostring(i18n.get("uiR2EdForCertainTime"))]="Few Sec"
- }
-r2.TimeLimitsCB = {
- ["No Limit"]=tostring(i18n.get("uiR2EdNoTimeLimit")),
- --["Until"]="Until a certain time",
- ["Chat"]=tostring(i18n.get("uiR2EdWhileChat")),
- ["Few Sec"]=tostring(i18n.get("uiR2EdForCertainTime")),
- }
-
-r2.activityTypeMenu = {
- ["Inactive"]=tostring(i18n.get("uiR2EdInactive")),
- ["Stand Still"]=tostring(i18n.get("uiR2EdStandStill")),
- ["Follow Route"]=tostring(i18n.get("uiR2EdFollowRoad")),
- ["Patrol"]=tostring(i18n.get("uiR2EdPatrol")),
- ["Repeat Road"]=tostring(i18n.get("uiR2EdRepeatRoad")),
- --["Deploy"]=tostring(i18n.get("uiR2EdDeploy")),
- ["Wander"]=tostring(i18n.get("uiR2EdWander")),
- ["Stand On Start Point"]=tostring(i18n.get("uiR2EdStandOnStartPoint")),
- ["Go To Start Point"]=tostring(i18n.get("uiR2EdGoToStartPoint")),
- ["Go To Zone"]=tostring(i18n.get("uiR2EdGoToZone")),
- ["Sit Down"]=tostring(i18n.get("uiR2EdSitDown")),
- ["Stand Up"]=tostring(i18n.get("uiR2EdStandUp")),
-
- }
-
-r2.fromNPCNameToId = {}
-r2.fromEmoteIdToName = {}
-
-r2.ownCreatedInstances = {}
-
-
------------------- INIT TRIGGERS EDITOR ----------------------------------------------------------------
-function r2:initTriggersEditor()
-
- -- emote
- local menuName = "ui:interface:r2ed_triggers_menu"
- local emoteMenu = getUI(menuName)
- local emoteMenu = emoteMenu:getRootMenu()
- assert(emoteMenu)
- emoteMenu:reset()
-
- local emoteTable = initEmotesMenu(menuName, "")
- for id, name in pairs(emoteTable) do
- r2.fromEmoteIdToName[id] = name
- end
-end
-
------------------- INIT TRIGGERS EDITOR ----------------------------------------------------------------
-function r2:initActivityEditor(activityEditor)
-
- -- time limit
- local timeLimitCB = activityEditor:find("time_limit"):find("combo_box")
- assert(timeLimitCB)
- timeLimitCB:resetTexts()
- timeLimitCB:addText(ucstring(i18n.get("uiR2EdNoTimeLimit")))
- --timeLimitCB:addText(ucstring("Until a certain time"))
- timeLimitCB:addText(ucstring(i18n.get("uiR2EdForCertainTime")))
- timeLimitCB:addText(ucstring(i18n.get("uiR2EdWhileChat")))
-end
-
-----------------------------------------------------------------------------------------------------
-function r2:getSelectedEltUI(uiName)
- local id = r2:getSelectedEltUIId(uiName)
- if id then
- return getUI(id)
- else
- return nil
- end
-end
-
-----------------------------------------------------------------------------------------------------
-function r2:getSelectedEltUIId(uiName)
-
- if uiName == nil then
- dumpCallStack(1)
- assert(false)
- end
- local windowUI = getUI("ui:interface:"..uiName)
- assert(windowUI)
-
- return windowUI.Env.selectedElementId
-end
-
-----------------------------------------------------------------------------------------------------
-function r2:setSelectedEltUIId(uiName, eltUIId)
- local windowUI = getUI("ui:interface:"..uiName)
- assert(windowUI)
-
- windowUI.Env.selectedElementId = eltUIId
-end
-
-----------------------------------------------------------------------------------------------------
-function r2:getSelectedEltInstId(uiName)
-
- local element = r2:getSelectedEltUI(uiName)
- if element ~= nil then
- return element.Env.elementId
- else
- return nil
- end
-end
-
-----------------------------------------------------------------------------------------------------
-function r2:setSelectedEltInstId(uiName, instId)
- local element = r2:getSelectedEltUI(uiName)
- assert(element)
- element.Env.elementId = instId
-end
-
-----------------------------------------------------------------------------------------------------
-function r2:getSelectedEltInst(uiName)
- local id = r2:getSelectedEltInstId(uiName)
- if id then
- return r2:getInstanceFromId(id)
- else
- return nil
- end
-end
-
-----------------------------------------------------------------------------------------------------
-function r2:getSelectedSequInstId(uiName)
- local windowUI = getUI("ui:interface:"..uiName)
- assert(windowUI)
-
- local tab = windowUI:find("sequence_tabs")
- assert(tab)
-
- local sequence = windowUI:find(tab.associatedGroupSelection)
- assert(sequence)
-
- if sequence.Env == nil then return nil end
-
- return sequence.Env.sequenceId
-end
-
-----------------------------------------------------------------------------------------------------
-function r2:getSelectedSequInst(uiName)
- local id = r2:getSelectedSequInstId(uiName)
- if id then
- return r2:getInstanceFromId(id)
- else
- return nil
- end
-end
-
-----------------------------------------------------------------------------------------------------
-function r2:getSelectedSequ(uiName)
- local windowUI = getUI("ui:interface:"..uiName)
- assert(windowUI)
-
- local tab = windowUI:find("sequence_tabs")
-
- if tab~=nil then
- local associatedGroup = tab.associatedGroupSelection
- if associatedGroup == "" then
- return nil
- end
-
- local sequence = windowUI:find(associatedGroup)
- assert(sequence)
-
- return sequence
- else
- return windowUI:find("sequence_elts")
- end
-end
-
-----------------------------------------------------------------------------------------------------
-function r2:setSelectedSequInstId(uiName, instanceId)
-
- local windowUI = getUI("ui:interface:"..uiName)
- assert(windowUI)
-
- local tab = windowUI:find("sequence_tabs")
- assert(tab)
-
- local sequence = windowUI:find(tab.associatedGroupSelection)
- assert(sequence)
-
- sequence.Env.sequenceId = instanceId
-end
-
------------------- CLOSE ALL UI --------------------------------------------------------------------
-function r2:closeActivitySequenceUI()
-
- local window = getUI("ui:interface:r2ed_edit_activity_sequence")
- if window~=nil then
- window.active = false
-
- r2:openAndUpdateMiniActivityView()
- end
-end
-
------------------- NEW SEQUENCE --------------------------------------------------------------------
-function r2:newActivitiesSequence(firstRequest, activitySequence, reset)
-
-
- local triggersUI = getUI("ui:interface:r2ed_triggers")
- assert(triggersUI)
-
- local tab = triggersUI:find("sequence_tabs")
- assert(tab)
-
- if firstRequest and tab.tabButtonNb == 7 then return -1 end
-
- if firstRequest == true then
- activitySequence = r2.newComponent("ActivitySequence")
-
- --local name = tostring(i18n.get("uiR2EdSeq"))..tab.tabButtonNb+1
- --activitySequence.Name = name
-
- local npcGroup = r2:getSelectedInstance()
- assert(npcGroup)
-
- r2.requestInsertNode(npcGroup:getBehavior().InstanceId, "Activities", -1, "", activitySequence)
--- r2.requestInsertNode(npcGroup.InstanceId,"ActivitiesId",-1,"",activitySequence.InstanceId)
--- r2.requestInsertNode(r2:getCurrentAct().InstanceId,"ActivitiesIds",-1,"",activitySequence.InstanceId)
-
- r2.ownCreatedInstances[activitySequence.InstanceId] = true
-
- return activitySequence.InstanceId
- else
-
- local updateMiniActivityView = r2.ownCreatedInstances[activitySequence.InstanceId]
- if reset then
- r2.ownCreatedInstances[activitySequence.InstanceId] = true
- end
-
- local templateParams = {
- newElt="r2:newActivity(true)",
- newEltText=tostring(i18n.get("uiR2EdNewActivity")),
- eltOrderText=tostring(i18n.get("uiR2EdActivityOrder")),
- upElt="r2:upActivity()",
- downElt="r2:downActivity()",
- maxMinElts="r2:maximizeMinimizeActivities()",
- downUpColor="200 120 80 255",
- colPushed = "200 80 80 255",
- paramsL= "r2:selectSequenceTab('r2ed_triggers', "..tostring(tab.tabButtonNb)..")"
- }
-
- local editorEltTemplate = "template_edit_activity"
- local sequence = r2:newElementsSequence("r2ed_triggers", templateParams, editorEltTemplate,
- activitySequence, tostring(i18n.get("uiR2EdSeq")))
- r2:initActivityEditor(sequence:find("edit_element"))
-
- local activities = activitySequence.Components
- for a = 0, activities.Size - 1 do
- r2:newActivity(false, nil, activities[a])
- end
-
- -- new MiniActivity sequence
- if updateMiniActivityView==true then
- --r2:updateSequencesButtonBar(tab.tabButtonNb-1, activitySequence.Name)
- r2:updateSequencesButtonBar(tab.tabButtonNb-1, r2:getSequenceName(activitySequence))
- r2:openAndUpdateMiniActivityView()
- end
- end
-end
-
------------------- REMOVE SEQUENCE -----------------------------------------------------------------
-function r2:removeActivitiesSequence()
-
- local sequenceId = r2:removeElementsSequence("r2ed_triggers", "Activities", tostring(i18n.get("uiR2EdSeq")))
-
--- local group = r2:getSelectedInstance()
--- assert(group)
--- local sequenceIndex = -1
--- for i=0,group.ActivitiesId.Size-1 do
--- if group.ActivitiesId[i] == sequenceId then
--- sequenceIndex = i
--- break
--- end
--- end
--- if sequenceIndex ~= -1 then
--- r2.requestEraseNode(group.InstanceId, "ActivitiesId", sequenceIndex)
--- end
---
--- local currentAct = r2:getCurrentAct()
--- sequenceIndex = -1
--- for i=0,currentAct.ActivitiesIds.Size-1 do
--- if currentAct.ActivitiesIds[i] == sequenceId then
--- sequenceIndex = i
--- break
--- end
--- end
--- if sequenceIndex ~= -1 then
--- r2.requestEraseNode(currentAct.InstanceId, "ActivitiesIds", sequenceIndex)
--- end
-end
-
-function r2:removeActivitiesSequenceUI(tabIndex)
- local firstEltName = r2:removeElementsSequenceUI(tabIndex, "r2ed_triggers", "Activities", tostring(i18n.get("uiR2EdSeq")))
-
- r2:updateSequencesButtonBar(0, firstEltName)
-end
-
------------------- SELECT ACTIVITY ------------------------------------------------------------------
-function r2:selectActivity()
- r2:selectTriggerElement(nil, "r2ed_triggers")
-
- if getUICaller().pushed == true then
- r2:updateActivityEditor()
- end
-end
-
------------------- NEW ACTIVITY --------------------------------------------------------------------
-function r2:newActivity(firstRequest, tableInit, instanceElement, sequenceUI, sequenceInstId)
-
-
-
- local uiName = "r2ed_triggers"
-
- if sequenceUI == nil then
- sequenceUI = r2:getSelectedSequ(uiName)
- end
- local activityList
- if sequenceUI~=nil then
- activityList = sequenceUI:find("elements_list")
- assert(activityList)
-
- if activityList.childrenNb-1 == r2.maxActivities then return false end
- end
-
- if firstRequest == true then
-
- instanceElement = r2.newComponent("ActivityStep")
-
- if tableInit ~= nil then
- instanceElement.Activity = tableInit.Activity
- instanceElement.ActivityZoneId = r2.RefId(tableInit.ActivityZoneId)
- instanceElement.TimeLimit = tableInit.TimeLimit
- instanceElement.TimeLimitValue = tableInit.TimeLimitValue
- else
- instanceElement.TimeLimit = "No Limit"
- instanceElement.Activity = "Stand Still"
- end
-
- if sequenceInstId == nil then
- sequenceInstId = r2:getSelectedSequInstId(uiName)
- end
- assert(sequenceInstId)
-
- r2.requestInsertNode(sequenceInstId, "Components", -1, "", instanceElement)
-
- r2.ownCreatedInstances[instanceElement.InstanceId] = true
- else
-
- local templateParams = {
- selectElt="r2:selectActivity()",
- openEltEditor="r2:openActivityEditor()",
- maxMinElt="r2:maximizeMinimizeActivity()",
- removeElt="r2:removeActivity()",
- colOver="200 120 80 120",
- colPushed="200 120 80 255"
- }
-
- local element = r2:newTriggerElement(uiName, tostring(i18n.get("uiR2EdActivity")), templateParams, sequenceUI, instanceElement.InstanceId)
-
- r2:updateActivityChatSequence(element)
-
- -- active chat button if a chat sequence is associated to this activity
- if instanceElement.Chat ~= "" then
-
- local activityEditor = sequenceUI:find("edit_element")
- assert(activityEditor)
- local chatButtonEditor = activityEditor:find("open_chat_sequence")
- assert(chatButtonEditor)
-
- chatButtonEditor.active = true
- end
- end
-
- return true
-end
-
-
-function r2:buildActivityTitle(activityUI, erase)
-
- local activityInst = r2:getInstanceFromId(activityUI.Env.elementId)
- assert(activityInst)
-
- -- part1
- local index = r2:searchElementIndex(activityInst)
- if erase==true then index = index-1 end
- local part1 = tostring(i18n.get("uiR2EdActivity")).." "..index.." : "
-
- -- part2
- if not r2.activityTypeMenu[activityInst.Activity] then
- debugInfo(colorTag(255,0,0).."The activity '".. activityInst.Activity.."' is not properly registred")
- end
-
- local part2 = r2.activityTypeMenu[activityInst.Activity].." "
- if activityInst.ActivityZoneId~= "" then
- local place = r2:getInstanceFromId(tostring(activityInst.ActivityZoneId))
- if place~=nil then
- part2 = part2.. place.Name .." "
- end
- end
-
- -- part3
- local part3 = ""
- if activityInst.TimeLimit == "Few Sec" then
-
- local hourNb, minNb, secNb = r2:calculHourMinSec(tonumber(activityInst.TimeLimitValue))
-
- local timeLimitText = tostring(i18n.get("uiR2EdFor")) .. " "
- if hourNb ~= 0 then timeLimitText = timeLimitText .. hourNb .. tostring(i18n.get("uiR2EdShortHours")) .. " " end
- if minNb ~= 0 then timeLimitText = timeLimitText .. minNb .. tostring(i18n.get("uiR2EdShortMinutes")) .. " " end
- timeLimitText = timeLimitText .. secNb .. tostring(i18n.get("uiR2EdShortSeconds"))
-
- part3 = timeLimitText
-
- elseif r2.TimeLimitsCB[activityInst.TimeLimit] ~= nil then
- part3 = string.lower(r2.TimeLimitsCB[activityInst.TimeLimit])
- end
-
- -- title
- local title = activityUI:find("title")
- assert(title)
- title.uc_hardtext= part1..part2..part3
-end
-
-function r2:getActivityName(activityInst)
-
- -- part1
- local index = r2:searchElementIndex(activityInst)
- if erase==true then index = index-1 end
- local part1 = tostring(i18n.get("uiR2EdActivity")).." "..index.." : "
-
- -- part2
- if not r2.activityTypeMenu[activityInst.Activity] then
- debugInfo(colorTag(255,0,0).."The activity '".. activityInst.Activity.."' is not properly registred")
- end
-
- local part2 = r2.activityTypeMenu[activityInst.Activity].." "
- if activityInst.ActivityZoneId~= "" then
- local place = r2:getInstanceFromId(tostring(activityInst.ActivityZoneId))
- if place~=nil then
- part2 = part2.. place.Name .." "
- end
- end
-
- -- part3
- local part3 = ""
- if activityInst.TimeLimit == "Few Sec" then
-
- local hourNb, minNb, secNb = r2:calculHourMinSec(tonumber(activityInst.TimeLimitValue))
-
- local timeLimitText = tostring(i18n.get("uiR2EdFor")) .. " "
- if hourNb ~= 0 then timeLimitText = timeLimitText .. hourNb .. tostring(i18n.get("uiR2EdShortHours")) .. " " end
- if minNb ~= 0 then timeLimitText = timeLimitText .. minNb .. tostring(i18n.get("uiR2EdShortMinutes")) .. " " end
- timeLimitText = timeLimitText .. secNb .. tostring(i18n.get("uiR2EdShortSeconds"))
-
- part3 = timeLimitText
-
- elseif r2.TimeLimitsCB[activityInst.TimeLimit] ~= nil then
- part3 = string.lower(r2.TimeLimitsCB[activityInst.TimeLimit])
- end
-
- return part1..part2..part3
-end
-
-function r2:getElementName(elementInst)
-
- if elementInst:isKindOf("ActivityStep") then
- return r2:getActivityName(elementInst)
- elseif elementInst:isKindOf("ChatStep") then
- return r2:getChatName(elementInst)
- elseif elementInst:isKindOf("LogicEntityAction") then
- return r2:getActionName(elementInst)
- elseif elementInst:isKindOf("LogicEntityReaction") then
- return r2:getReactionName(elementInst)
- elseif elementInst:isKindOf("ChatSequence") or elementInst:isKindOf("ActivitySequence") then
- return r2:getSequenceName(elementInst)
- end
-
- return ""
-end
-
-function r2:updateActivityChatSequence(elementUI, canceledChatStepId)
-
- if elementUI == nil then
- elementUI = r2:getSelectedEltUI("r2ed_triggers")
- end
- assert(elementUI)
-
- local instance = r2:getInstanceFromId(elementUI.Env.elementId)
- assert(instance)
-
- local chatSequence = r2:getInstanceFromId(tostring(instance.Chat))
-
- local activityText = elementUI:find("text_list")
- assert(activityText)
-
- local sep = elementUI:find("sep")
- assert(sep)
-
- activityText:clear()
-
- if chatSequence ~= nil then
- local counterTime = 0
-
- if chatSequence.Components.Size > 0 then
-
- local emptyText = true
-
- activityText:addColoredTextChild("\n"..tostring(i18n.get("uiR2EdSequenceStart")), 255, 175, 135, 255)
-
- for c = 0, chatSequence.Components.Size - 1 do
- local chat = chatSequence.Components[c]
-
- if chat.InstanceId ~= canceledChatStepId then
- counterTime = counterTime + tonumber(chat.Time)
-
- local firstLine = true
-
- local who = tostring(chat.Actions[0].Who)
- if who ~= "" then
-
- local facing = tostring(chat.Actions[0].Facing)
- local emote = chat.Actions[0].Emote
- local says = chat.Actions[0].Says
-
- local minNb, secNb = r2:calculMinSec(counterTime)
- local countInfo = "*"
- if minNb ~= 0 then
- countInfo = countInfo..tostring(minNb)..tostring(i18n.get("uiR2EdShortMinutes"))
- end
- countInfo = countInfo.." "..tostring(secNb)..tostring(i18n.get("uiR2EdShortSeconds"))..":"
-
- if facing ~= "" then
- facing = r2:getInstanceFromId(who).Name .. " "..tostring(i18n.get("uiR2EdFaces")).." " .. r2:getInstanceFromId(facing).Name
- if firstLine then
- activityText:addColoredTextChild(countInfo, 220, 140, 100, 255)
- firstLine = false
- end
- activityText:addTextChild(ucstring(facing))
- emptyText = false
- end
- if r2.fromEmoteIdToName[emote] ~= nil then
- emote = r2:getInstanceFromId(who).Name .. " "..string.lower(tostring(i18n.get("uiR2EdEmote"))).." : " .. r2.fromEmoteIdToName[emote]
- if firstLine then
- activityText:addColoredTextChild(countInfo, 220, 140, 100, 255)
- firstLine = false
- end
- activityText:addTextChild(ucstring(emote))
- emptyText = false
- end
- if r2:getInstanceFromId(says)~=nil and r2:getInstanceFromId(says).Text ~= "" then
- says = r2:getInstanceFromId(who).Name .. " "..tostring(i18n.get("uiR2EdSays")).." : " .. r2:getInstanceFromId(says).Text
- if firstLine then
- activityText:addColoredTextChild(countInfo, 220, 140, 100, 255)
- firstLine = false
- end
- activityText:addTextChild(ucstring(says))
- emptyText = false
- end
- end
- end
- end
-
- if emptyText == true then
- activityText:clear()
- sep.active = false
- else
- sep.active = true
-
- local hourNb, minNb, secNb = r2:calculHourMinSec(counterTime)
- local totalChatTime = ""
- if hourNb ~= 0 then
- totalChatTime = tostring(hourNb)..tostring(i18n.get("uiR2EdShortHours"))
- end
- if minNb ~= 0 then
- totalChatTime = totalChatTime.." "..tostring(minNb)..tostring(i18n.get("uiR2EdShortMinutes"))
- end
- totalChatTime = totalChatTime.." "..tostring(secNb)..tostring(i18n.get("uiR2EdShortSeconds"))
- activityText:addColoredTextChild(tostring(i18n.get("uiR2EdSequenceEnd")).." (".. totalChatTime ..")\n", 255, 175, 135, 255)
- end
- end
- else
- sep.active = false
- end
-
- --update title
- r2:buildActivityTitle(elementUI, false)
-
- if r2:getSelectedEltInstId("r2ed_triggers") == instance.InstanceId then
- local eltEditor = r2:getSelectedSequ("r2ed_triggers"):find("edit_element")
- assert(eltEditor)
- r2:updateActivityEditor()
- end
-
- r2:updateMiniActivityView()
-end
-
-function r2:updateActivitiesWhithThisChatSequence(chatStep, canceled)
-
- local chatSequenceId = chatStep.Parent.Parent.InstanceId
-
- local chatStepId = nil
- if canceled == true then chatStepId = chatStep.InstanceId end
-
- local triggersUI = getUI("ui:interface:r2ed_triggers")
- assert(triggersUI)
-
- local tab = triggersUI:find("sequence_tabs")
- assert(tab)
-
- for s = 0,tab.tabButtonNb-1 do
- local activitySequence = tab:getGroup(s)
- assert(activitySequence)
-
- local activityList = activitySequence:find("elements_list")
- assert(activityList)
-
- for a=0, activityList.childrenNb-1 do
- local activity = activityList:getChild(a)
- assert(activity)
-
- if activity.Env.elementId~=nil then
- local activityInst = r2:getInstanceFromId(activity.Env.elementId)
- assert(activityInst)
- if tostring(activityInst.Chat) == chatSequenceId then
- r2:updateActivityChatSequence(activity, chatStepId)
- end
- end
- end
- end
-end
-
------------------- REMOVE ACTIVITY ------------------------------------------------------------------
-function r2:removeActivity()
- r2:removeTriggerElement("r2ed_triggers", tostring(i18n.get("uiR2EdActivity")))
-end
-
-function r2:removeActivityUI(sequenceUI, elementUI)
-
- r2:removeElementUI(sequenceUI, "r2ed_triggers", elementUI)
- r2:closeActivitySequenceUI()
-
- local activityList = sequenceUI:find("elements_list")
- assert(activityList)
-end
-
------------------- UP ACTIVITY -----------------------------------------------------------------------
-function r2:upActivity()
- r2:upTriggerElement("r2ed_triggers")
-end
-
------------------- DOWN ACTIVITY ---------------------------------------------------------------------
-function r2:downActivity()
- r2:downTriggerElement("r2ed_triggers")
-end
-
------------------- MAXIMIZE MINIMIZE ACTIVITIES ------------------------------------------------------
-function r2:maximizeMinimizeActivities()
- r2:maximizeMinimizeTriggerElements("r2ed_triggers")
-end
-
------------------- MAXIMIZE MINIMIZE ACTIVITY ------------------------------------------------------
-function r2:maximizeMinimizeActivity()
- r2:maximizeMinimizeElement("r2ed_triggers")
-end
-
------------------- OPEN ACTIVITY EDITOR ----------------------------------------------------------------
-function r2:openActivityEditor()
- r2:updateActivityEditor()
- r2:openElementEditor("r2ed_triggers", "uiR2EDActivityStepEditor")
-end
-
-function r2:updateActivityEditor()
-
- local uiName = "r2ed_triggers"
- local instanceActivity = r2:getSelectedEltInst(uiName)
-
- local activityEditor = r2:getSelectedSequ(uiName):find("edit_element")
- assert(activityEditor)
-
- -- activity name
- local activityName = activityEditor:find("name")
- assert(activityName)
-
- -- activity type
- local activityButtonText = activityEditor:find("activity"):find("text")
- assert(activityButtonText)
-
- -- time limit
- local comboBox = activityEditor:find("time_limit").combo_box
- assert(comboBox)
-
- -- chat sequence
- local chatMenuButton = activityEditor:find("chat_script"):find("menu"):find("text")
- assert(chatMenuButton)
-
- local chatButtonEditor = activityEditor:find("open_chat_sequence")
- assert(chatButtonEditor)
-
- if instanceActivity then
-
- local index = r2:searchElementIndex(instanceActivity)
- if index~= nil then
- activityName.uc_hardtext = tostring(i18n.get("uiR2EdActivity")).." "..index.." : "
- else
- activityName.uc_hardtext = tostring(i18n.get("uiR2EdActivity")).." : "
- end
-
- -- activity type
- local activityText = r2.activityTypeMenu[instanceActivity.Activity]
- if activityText then
- activityButtonText.uc_hardtext = activityText
- end
- if instanceActivity.ActivityZoneId ~= "" then
- local place = r2:getInstanceFromId(instanceActivity.ActivityZoneId)
- assert(place)
-
- activityButtonText.uc_hardtext = activityButtonText.hardtext .. " " .. place.Name
- end
-
- -- time limit
- local timeLimit = instanceActivity.TimeLimit
-
- local certainTime = activityEditor:find("certain_time")
- assert(certainTime)
-
- comboBox.Env.locked = true
- if timeLimit == "Few Sec" then
- local timeLimitValue = tonumber(instanceActivity.TimeLimitValue)
-
- if timeLimitValue ~= nil then
-
- local hoursNb, minNb, secNb = r2:calculHourMinSec(timeLimitValue)
-
- local timeLimitText = tostring(i18n.get("uiR2EdFor")) .. " "
- if hoursNb ~= 0 then timeLimitText = timeLimitText .. hoursNb .. tostring(i18n.get("uiR2EdShortHours")) .. " " end
- if minNb ~= 0 then timeLimitText = timeLimitText .. minNb .. tostring(i18n.get("uiR2EdShortMinutes")) .. " " end
- timeLimitText = timeLimitText .. secNb .. tostring(i18n.get("uiR2EdShortSeconds"))
-
- certainTime.active = true
- local hoursMenu = certainTime:find("hours"):find("text")
- assert(hoursMenu)
- hoursMenu.uc_hardtext = tostring(hoursNb)
-
- local minutesMenu = certainTime:find("minutes"):find("text")
- assert(minutesMenu)
- minutesMenu.uc_hardtext = tostring(minNb)
-
- local secondsMenu = certainTime:find("seconds"):find("text")
- assert(secondsMenu)
- secondsMenu.uc_hardtext = tostring(secNb)
-
- comboBox.view_text = timeLimitText
- end
- else
- certainTime.active = false
- timeLimit = r2.TimeLimitsCB[timeLimit]
- if timeLimit~= nil then
- comboBox.selection_text = timeLimit
- end
- end
- comboBox.Env.locked = false
-
- -- chat sequence TEMP TEMP TEMP TEMP
- local sequenceChat = r2:getInstanceFromId(tostring(instanceActivity.Chat))
- local repeatLabelButton = activityEditor:find("repeat")
- assert(repeatLabelButton)
-
- if sequenceChat ~= nil then
- --chatMenuButton.uc_hardtext = sequenceChat.Name
- chatMenuButton.uc_hardtext = r2:getSequenceName(sequenceChat)
-
- repeatLabelButton.active = true
- local repeatButton = repeatLabelButton:find("toggle_butt")
- assert(repeatButton)
- repeatButton.pushed = not (instanceActivity.Type == "Repeating")
-
- chatButtonEditor.active = true
- else
- repeatLabelButton.active = false
- chatMenuButton.uc_hardtext = i18n.get("uiR2EdNoElt")
-
- chatButtonEditor.active = false
- end
- -- TEMP TEMP TEMP
-
- else
-
- local name = tostring(i18n.get("uiR2EdActivity")).." : "
- activityName.uc_hardtext = name
-
- activityButtonText.uc_hardtext = i18n.get("uiR2EdStandStill")
- comboBox.selection_text = i18n.get("uiR2EdNoTimeLimit")
- chatMenuButton.uc_hardtext = i18n.get("uiR2EdNoElt")
-
- chatButtonEditor.active = false
- end
-end
-
------------------- REPEAT ACTIVITY SEQUENCE -------------------------------------------------------------
-function r2:repeatActivitySequence()
- r2.requestNewAction(i18n.get("uiR2EDRepeatActivitySequenceAction"))
-
- local sequenceInstId = r2:getSelectedSequInstId("r2ed_triggers")
- assert(sequenceInstId)
-
- local sequenceType = not getUICaller().pushed
- if sequenceType==false then sequenceType=0 else sequenceType=1 end
-
- r2.requestSetNode(sequenceInstId, "Repeating", sequenceType)
-end
-
------------------- CLOSE ACTIVITY EDITOR ----------------------------------------------------------------
-function r2:closeChatSequencesUI()
-
- local window = getUI("ui:interface:r2ed_chat_sequence")
- assert(window)
- window.active = false
-
- window = getUI("ui:interface:r2ed_edit_chat_sequence")
- assert(window)
- window.active = false
-end
-
------------------- OPEN ACTIVITY MENU -------------------------------------------------------------------
-function r2:openActivityMenu()
-
- local menuName = "ui:interface:r2ed_triggers_menu"
- local activityMenu = getUI(menuName)
- local activityMenu = activityMenu:getRootMenu()
- assert(activityMenu)
- activityMenu:reset()
-
- -- Inactive
--- activityMenu:addLine(ucstring(i18n.get("uiR2EdInactive")), "lua", "r2:setActivity('Inactive')", "Inactive")
-
- -- Stand still
- activityMenu:addLine(ucstring(i18n.get("uiR2EdStandStill")), "lua", "r2:setActivity('Stand Still')", "Stand Still")
-
- -- Follow route
- activityMenu:addLine(ucstring(i18n.get("uiR2EdFollowRoad")), "", "", "Follow Route")
- local menuButton = createGroupInstance("r2_menu_button", "", { bitmap = "r2ed_icon_road.tga", size="14" })
- activityMenu:setUserGroupLeft(1, menuButton)
- activityMenu:addSubMenu(1)
- local roadsMenu = activityMenu:getSubMenu(1)
- local roadsTable = r2.Scenario:getAllInstancesByType("Road")
- for key, road in pairs(roadsTable) do
- roadsMenu:addLine(ucstring(road.Name), "lua", "r2:setActivity('Follow Route', '".. road.InstanceId .."')", road.InstanceId)
- end
- if table.getn(roadsTable) == 0 then
- roadsMenu:addLine(ucstring(i18n.get("uiR2EdNoSelelection")), "lua", "r2:setActivity()", "")
- end
-
- -- Patrol
- activityMenu:addLine(ucstring(i18n.get("uiR2EdPatrol")), "", "", "Patrol")
- menuButton = createGroupInstance("r2_menu_button", "", { bitmap = "r2ed_icon_road.tga", size="14"})
- activityMenu:setUserGroupLeft(2, menuButton)
- activityMenu:addSubMenu(2)
- roadsMenu = activityMenu:getSubMenu(2)
- for key, road in pairs(roadsTable) do
- roadsMenu:addLine(ucstring(road.Name), "lua", "r2:setActivity('Patrol', '".. road.InstanceId .."')", road.InstanceId)
- end
- if table.getn(roadsTable) == 0 then
- roadsMenu:addLine(ucstring(i18n.get("uiR2EdNoSelelection")), "lua", "r2:setActivity()", "")
- end
-
- -- Repeat Road
- activityMenu:addLine(ucstring(i18n.get("uiR2EdRepeatRoad")), "", "", "Repeat Road")
- menuButton = createGroupInstance("r2_menu_button", "", { bitmap = "r2ed_icon_road.tga", size="14"})
- activityMenu:setUserGroupLeft(3, menuButton)
- activityMenu:addSubMenu(3)
- roadsMenu = activityMenu:getSubMenu(3)
- for key, road in pairs(roadsTable) do
- roadsMenu:addLine(ucstring(road.Name), "lua", "r2:setActivity('Repeat Road', '".. road.InstanceId .."')", road.InstanceId)
- end
- if table.getn(roadsTable) == 0 then
- roadsMenu:addLine(ucstring(i18n.get("uiR2EdNoSelelection")), "lua", "r2:setActivity()", "")
- end
-
- -- Wander
- activityMenu:addLine(ucstring(i18n.get("uiR2EdWander")), "", "", "Wander")
- menuButton = createGroupInstance("r2_menu_button", "", { bitmap = "r2ed_icon_region.tga", size="14"})
- activityMenu:setUserGroupLeft(4, menuButton)
- activityMenu:addSubMenu(4)
- local regionsMenu = activityMenu:getSubMenu(4)
- local regionsTable = r2.Scenario:getAllInstancesByType("Region")
- for key, region in pairs(regionsTable) do
- regionsMenu:addLine(ucstring(region.Name), "lua", "r2:setActivity('Wander', '".. region.InstanceId .."')", region.InstanceId)
- end
- if table.getn(regionsTable) == 0 then
- regionsMenu:addLine(ucstring(i18n.get("uiR2EdNoSelelection")), "lua", "r2:setActivity()", "")
- end
-
- -- Deploy
--- activityMenu:addLine(ucstring(i18n.get("uiR2EdDeploy")), "", "", "Deploy")
--- menuButton = createGroupInstance("r2_menu_button", "", { bitmap = "r2ed_icon_region.tga", size="14"})
--- activityMenu:setUserGroupLeft(6, menuButton)
--- activityMenu:addSubMenu(6)
--- local regionsMenu = activityMenu:getSubMenu(6)
--- local regionsTable = r2.Scenario:getAllInstancesByType("Region")
--- for key, region in pairs(regionsTable) do
--- regionsMenu:addLine(ucstring(region.Name), "lua", "r2:setActivity('Deploy', '".. region.InstanceId .."')", region.InstanceId)
--- end
--- if table.getn(regionsTable) == 0 then
--- regionsMenu:addLine(ucstring(i18n.get("uiR2EdNoSelelection")), "lua", "r2:setActivity()", "")
--- end
-
- r2:openTriggersMenu(getUICaller())
-end
-
-function r2:setActivity(activityType, placeId)
-
-
-
- local activityInstId = r2:getSelectedEltInstId("r2ed_triggers")
- assert(activityInstId)
-
- if activityType == nil then
- return
- elseif placeId == nil then
- r2.requestSetNode(activityInstId, "Activity", activityType)
- r2.requestSetNode(activityInstId, "ActivityZoneId", r2.RefId(""))
- else
- r2.requestSetNode(activityInstId, "Activity", activityType)
- r2.requestSetNode(activityInstId, "ActivityZoneId", r2.RefId(placeId))
- end
-end
-
------------------- SET TIME LIMIT --------------------------------------------------------------------
-function r2:setTimeLimit(timeLimit)
-
- if timeLimit == nil then
- timeLimit = getUICaller().selection_text
- if getUICaller().Env.locked then return end
- end
-
- local uiName = "r2ed_triggers"
- local activity = r2:getSelectedEltUI(uiName)
- if activity == nil then return end
-
- local viewText
- local hasTimeLimitValue = false
-
- if timeLimit == tostring(i18n.get("uiR2EdForCertainTime")) then
- hasTimeLimitValue = true
- viewText = tostring(i18n.get("uiR2EdFor")) .. " 20" .. tostring(i18n.get("uiR2EdShortSeconds"))
-
- local eltEditor = r2:getSelectedSequ(uiName):find("edit_element")
- assert(eltEditor)
- local comboTime = eltEditor:find("time_limit"):find("combo_box")
- assert(comboTime)
- comboTime.view_text = viewText
- else
- viewText = timeLimit
- end
-
- timeLimit = r2.TimeLimitsProp[timeLimit]
-
- local activityInstId = r2:getSelectedEltInstId(uiName)
- r2.requestSetNode(activityInstId, "TimeLimit", timeLimit)
-
- if hasTimeLimitValue then
- r2.requestSetNode(activityInstId, "TimeLimitValue", tostring(20))
- else
- r2.requestSetNode(activityInstId, "TimeLimitValue", "")
- end
-end
-
-function r2:calculHourMinSec(totalSecNb)
-
- local minSecNb, hourNb = totalSecNb, 0
- while minSecNb > 3599 do
- hourNb = hourNb+1
- minSecNb = minSecNb - 3600
- end
-
- local minNb, secNb = 0, minSecNb
- while secNb > 59 do
- minNb = minNb+1
- secNb = secNb - 60
- end
-
- return hourNb, minNb, secNb
-end
-
-function r2:calculMinSec(totalSecNb)
-
- local minNb, secNb = 0, totalSecNb
- while secNb > 59 do
- minNb = minNb+1
- secNb = secNb - 60
- end
-
- return minNb, secNb
-end
-
-function r2:activityForHours(hourNb)
-
- local activityInst = r2:getSelectedEltInst("r2ed_triggers")
- assert(activityInst)
-
- local lastHourNb, minNb, secNb = r2:calculHourMinSec(tonumber(activityInst.TimeLimitValue))
-
- r2:setLimitTimeValue(hourNb, minNb, secNb)
-end
-
-function r2:activityForMinutes(minNb)
-
- local activityInst = r2:getSelectedEltInst("r2ed_triggers")
- assert(activityInst)
-
- local hoursNb, lastMinNb, secNb = r2:calculHourMinSec(tonumber(activityInst.TimeLimitValue))
-
- r2:setLimitTimeValue(hoursNb, minNb, secNb)
-end
-
-function r2:activityForSeconds(secNb)
-
- local activityInst = r2:getSelectedEltInst("r2ed_triggers")
- assert(activityInst)
-
- local hoursNb, minNb, lastSecNb = r2:calculHourMinSec(tonumber(activityInst.TimeLimitValue))
-
- r2:setLimitTimeValue(hoursNb, minNb, secNb)
-end
-
------------------- SET LIMIT TIME VALUE -------------------------------------------------------------------
-function r2:setLimitTimeValue(hourNb, minNb, secNb)
-
- local totalSec = tostring(hourNb*3600 + minNb*60 + secNb)
- r2.requestSetNode(r2:getSelectedEltInstId("r2ed_triggers"), "TimeLimitValue", totalSec)
-end
-
-
------------------- OPEN SELECT CHAT MENU -------------------------------------------------------------------
-function r2:openSelectChatMenu()
-
- -- triggers menu initialization
- local chatMenu = getUI("ui:interface:r2ed_triggers_menu")
- assert(chatMenu)
-
- local chatMenu = chatMenu:getRootMenu()
- assert(chatMenu)
-
- chatMenu:reset()
-
- -- first line "None"
- chatMenu:addLine(ucstring(i18n.get("uiR2EdNoElt")), "lua", "r2:selectChatSequence('None')", "None")
-
- -- second line "More"
- chatMenu:addLine(ucstring(i18n.get("uiR2EdMore")), "lua", "r2:openChatSequences()", "More")
-
- local entityInst = r2:getSelectedInstance()
- assert(entityInst)
-
- -- list of avoidable chat sequences
- local chatSequences = entityInst:getBehavior().ChatSequences
- for i=0, chatSequences.Size-1 do
- local chatS = chatSequences[i]
- assert(chatS)
- --chatMenu:addLine(ucstring(chatS.Name), "lua", "r2:selectChatSequence('" .. chatS.InstanceId .. "')", chatS.InstanceId)
- chatMenu:addLine(ucstring(r2:getSequenceName(chatS)), "lua", "r2:selectChatSequence('" .. chatS.InstanceId .. "')", chatS.InstanceId)
- end
-
- r2:openTriggersMenu(getUICaller())
-end
-
-function r2:openChatSequences()
- local chatSequencesUI = getUI("ui:interface:r2ed_chat_sequence")
- assert(chatSequencesUI)
-
- chatSequencesUI.active = true
- chatSequencesUI:updateCoords()
-
- if chatSequencesUI.Env.openFirst == nil then
- chatSequencesUI:center()
- chatSequencesUI.Env.openFirst = true
- end
-end
-
------------------------------------------------------------------------------------------------------------
--- the commun "logic entity" menu is open
-function r2:openTriggersMenu(caller)
-
- local menuName = "ui:interface:r2ed_triggers_menu"
- launchContextMenuInGame(menuName)
- local menu = getUI(menuName)
-
- menu:updateCoords()
- menu.y = caller.y_real - (menu.h + 2)
- menu.x = caller.x_real
- menu:setMinW(caller.w)
- menu:updateCoords()
-end
-
------------------- SELECT CHAT SEQUENCE -------------------------------------------------------------
-function r2:selectChatSequence(choice, activityId)
-
- local chatSequenceUI = getUI("ui:interface:r2ed_chat_sequence")
- assert(chatSequenceUI)
-
- local uiName = "r2ed_triggers"
-
- if activityId == nil then
- activityId = r2:getSelectedEltInstId(uiName)
- end
-
- local activityUI = r2:getSelectedEltUI(uiName)
- assert(activityUI)
-
- if choice == "None" then
- r2.requestSetNode(activityId, "Chat", r2.RefId(""))
- local sep = activityUI:find("sep")
- assert(sep)
- sep.active = false
- elseif choice == "More" then
- r2:openChatSequences()
- elseif choice then
- local chatSId = choice
- local activityInstId = r2:getSelectedEltInstId(uiName)
- r2.requestSetNode(activityId, "Chat", r2.RefId(chatSId))
- r2.requestSetNode(activityInstId, "Type", "Non Repeating")
- else
- debugInfo("r2:selectChatSequence : unknown menu selection")
- end
-end
-
------------------- REPEAT OR NOT CHAT SEQUENCE ------------------------------------------------------
-function r2:repeatChatSequence()
-
- local activityInstId = r2:getSelectedEltInstId("r2ed_triggers")
- assert(activityInstId)
-
- local sequenceType = "Repeating"
- if getUICaller().pushed then sequenceType = "Non Repeating" end
-
- r2.requestSetNode(activityInstId, "Type", sequenceType)
-end
-
------------------- NEW CHAT SEQUENCE -------------------------------------------------------------
-function r2:newChatsSequence(firstRequest, instanceSequence, reset)
-
- local chatSequencesUI = getUI("ui:interface:r2ed_chat_sequence")
- assert(chatSequencesUI)
-
- local tab = chatSequencesUI:find("sequence_tabs")
- assert(tab)
-
- -- limit sequences number
- if firstRequest and tab.tabButtonNb == 7 then return -1 end
-
- if firstRequest == true then
- instanceSequence = r2.newComponent("ChatSequence")
-
- --local name = tostring(i18n.get("uiR2EdChat"))..tab.tabButtonNb+1
- --instanceSequence.Name = name
-
- local npcGroup = r2:getSelectedInstance()
- assert(npcGroup)
-
- r2.requestInsertNode(npcGroup:getBehavior().InstanceId, "ChatSequences", -1, "", instanceSequence)
-
- r2.ownCreatedInstances[instanceSequence.InstanceId] = true
- else
-
- local templateParams = {
- newElt="r2:newChat(true)",
- newEltText=tostring(i18n.get("uiR2EdNewChat")),
- eltOrderText=tostring(i18n.get("uiR2EdChatOrder")),
- upElt="r2:upChat()",
- downElt="r2:downChat()",
- maxMinElts="r2:maximizeMinimizeChats()",
- downUpColor="120 150 140 255",
- colPushed = "0 255 0 255",
- paramsL= "r2:selectSequenceTab('r2ed_chat_sequence', "..tostring(tab.tabButtonNb)..")"
- }
-
- if reset == true then
- r2.ownCreatedInstances[instanceSequence.InstanceId] = true
- end
-
- local editorEltTemplate = "template_edit_chat"
- local sequence = r2:newElementsSequence("r2ed_chat_sequence", templateParams, editorEltTemplate,
- instanceSequence, tostring(i18n.get("uiR2EdSequChat")))
-
- local chats = instanceSequence.Components
- for c = 0, chats.Size - 1 do
- r2:newChat(false, chats[c])
- end
-
- local eltEditor = sequence:find("edit_element")
- assert(eltEditor)
-
- local editBox = eltEditor:find("edit_box_group")
- assert(editBox)
-
- local scroll = sequence:find("edit_box_scroll_ed")
- assert(scroll)
-
- scroll:setTarget(editBox.id)
- end
-
- return instanceSequence.InstanceId
-end
-
-------------------- REMOVE CHATS SEQUENCE ---------------------------------------------------------
-function r2:removeChatsSequence()
-
- -- remove sequence
- r2:removeElementsSequence("r2ed_chat_sequence", "ChatSequences", tostring(i18n.get("uiR2EdSequChat")))
-end
-
-function r2:removeChatsSequenceUI(sequIndex)
-
- r2:closeChatEditor()
-
- -- remove sequence UI
- r2:removeElementsSequenceUI(sequIndex, "r2ed_chat_sequence", "ChatSequences", tostring(i18n.get("uiR2EdSequChat")))
-end
-
-------------------- SELECT CHAT -------------------------------------------------------------------
-function r2:selectChat()
- r2:selectTriggerElement(nil, "r2ed_chat_sequence")
-
- if getUICaller().pushed == true then
- r2:updateChatEditor()
- end
-end
-
-------------------- OPEN CHAT EDITOR --------------------------------------------------------------
-function r2:openChatEditor()
- r2:updateChatEditor()
- r2:openElementEditor("r2ed_chat_sequence", "uiR2EDChatStepEditor")
-end
-
-function r2:updateChatEditor()
-
- local instanceChat = r2:getSelectedEltInst("r2ed_chat_sequence")
-
- local chatEditor = r2:getSelectedSequ("r2ed_chat_sequence"):find("edit_element")
- assert(chatEditor)
-
- -- chat name
- local chatName = chatEditor:find("name")
- assert(chatName)
-
- -- time
- local minutesText = chatEditor:find("minutes"):find("text")
- assert(minutesText)
-
- local secondsText = chatEditor:find("seconds"):find("text")
- assert(secondsText)
-
- -- update NPC name lists
- local whoMenuText = chatEditor:find("whoMenu"):find("text")
- assert(whoMenuText)
-
- local toWhoMenuText = chatEditor:find("toWhoMenu"):find("text")
- assert(toWhoMenuText)
-
- local editBox = chatEditor:find("says"):find("edit_box_group")
- assert(editBox)
-
- local emoteButtonText = chatEditor:find("emote"):find("menu"):find("text")
- assert(emoteButtonText)
-
- if instanceChat then
-
- local index = r2:searchElementIndex(instanceChat)
- if index~= nil then
- chatName.uc_hardtext = tostring(i18n.get("uiR2EdChat")).." "..index.." : "
- else
- chatName.uc_hardtext = tostring(i18n.get("uiR2EdChat")).." : "
- end
-
- -- after value
- local time = instanceChat.Time
- local minNb, secNb = r2:calculMinSec(time)
-
- minutesText.uc_hardtext = tostring(minNb)
- secondsText.uc_hardtext = tostring(secNb)
-
- -- who
- local whoInst = r2:getInstanceFromId(tostring(instanceChat.Actions[0].Who))
- whoMenuText.uc_hardtext = whoInst.Name
-
- -- says what
- local textID = instanceChat.Actions[0].Says
- if textID ~= "" then
- editBox.uc_input_string = r2:getInstanceFromId(textID).Text
- else
- editBox.uc_input_string = ""
- end
-
- -- to who
- local toWhoInst = r2:getInstanceFromId(tostring(instanceChat.Actions[0].Facing))
- if toWhoInst then
- toWhoMenuText.uc_hardtext = toWhoInst.Name
- else
- toWhoMenuText.uc_hardtext = tostring(i18n.get("uiR2EdNobody"))
- end
-
- -- emote
- local emoteName = r2.fromEmoteIdToName[instanceChat.Actions[0].Emote]
- if emoteName then
- emoteButtonText.uc_hardtext = emoteName
- else
- emoteButtonText.uc_hardtext = tostring(i18n.get("uiR2EdNoElt"))
- end
-
- else
-
- local name = tostring(i18n.get("uiR2EdChat")).." : "
- chatName.uc_hardtext = name
-
- minutesText.uc_hardtext = tostring(0)
- secondsText.uc_hardtext = tostring(0)
-
- whoMenuText.uc_hardtext = ""
-
- editBox.uc_input_string = ""
-
- toWhoMenuText.uc_hardtext = tostring(i18n.get("uiR2EdNobody"))
-
- emoteButtonText.uc_hardtext = tostring(i18n.get("uiR2EdNoElt"))
- end
-end
-
------------------- OPEN CHAT SEQUENCE EDITOR --------------------------------------------------
-function r2:openChatSequenceEditor()
-
- local editor = getUI("ui:interface:r2ed_edit_chat_sequence")
- assert(editor)
-
- local chatsUI = getUI("ui:interface:r2ed_chat_sequence")
- assert(chatsUI)
-
- editor.x = chatsUI.x
- editor.y = chatsUI.y
- editor.active = true
-end
-
-------------------- MAX / MIN CHAT ----------------------------------------------------------------
-function r2:maximizeMinimizeChat()
- r2:maximizeMinimizeElement("r2ed_chat_sequence")
-end
-
--------------------- NEW CHAT ---------------------------------------------------------------------
-function r2:newChat(firstRequest, instanceElement, sequenceUI)
-
- local uiName = "r2ed_chat_sequence"
-
- if firstRequest == true then
- instanceElement = r2.newComponent("ChatStep")
-
- instanceElement.Time = 3
-
- local who
- local selectedInst = r2:getSelectedInstance()
- assert(selectedInst)
-
- if selectedInst:isGrouped() then
- who = r2:getLeader(selectedInst)
- else
- who = selectedInst
- end
- local chatAction = r2.newComponent("ChatAction")
- chatAction.Who = who.InstanceId
- table.insert(instanceElement.Actions, chatAction)
-
- local sequenceInstId = r2:getSelectedSequInstId(uiName)
-
- r2.requestInsertNode(sequenceInstId, "Components", -1, "", instanceElement)
-
- r2.ownCreatedInstances[instanceElement.InstanceId] = true
- else
-
- local templateParams = {
- selectElt="r2:selectChat()",
- openEltEditor="r2:openChatEditor()",
- maxMinElt="r2:maximizeMinimizeChat()",
- removeElt="r2:removeChat()",
- colOver="120 150 140 100",
- colPushed="120 150 140 255"
- }
-
- if sequenceUI == nil then
- sequenceUI = r2:getSelectedSequ(uiName)
- end
- local element = r2:newTriggerElement(uiName, tostring(i18n.get("uiR2EdChat")), templateParams, sequenceUI, instanceElement.InstanceId)
-
- r2:updateChatText(element)
- end
-end
-
-function r2:searchElementIndex(eltInst)
-
- local components = eltInst.Parent
- local index
- for i=0, components.Size-1 do
- local elt = components[i]
- if elt.InstanceId == eltInst.InstanceId then
- return (i+1)
- end
- end
-end
-
-function r2:buildChatTitle(chatUI, erase)
-
- local chatInst = r2:getInstanceFromId(chatUI.Env.elementId)
- assert(chatInst)
-
- -- part1
- local index = r2:searchElementIndex(chatInst)
- if erase==true then index = index-1 end
- local part1 = tostring(i18n.get("uiR2EdChat")).." "..index.." : "
-
- -- part2
- local minNb, secNb = r2:calculMinSec(chatInst.Time)
- local time = ""
- if minNb ~= 0 then
- time = tostring(minNb)..tostring(i18n.get("uiR2EdShortMinutes"))
- end
- time = time.." " ..tostring(secNb)..tostring(i18n.get("uiR2EdShortSeconds"))
- local part2 = "(" ..tostring(i18n.get("uiR2EdAfter")).." ".. time..") "
-
- -- part3
- local part3 = ""
- local action = chatInst.Actions[0]
- local who = action.Who
- if who ~= "" then
- who = r2:getInstanceFromId(who)
- assert(who)
- part3 = who.Name .. " " ..tostring(i18n.get("uiR2EdSays")).. " "
-
- local says = action.Says
- if says ~= "" then
- says = r2:getInstanceFromId(says).Text
- says = string.substr(says, 0, 4)
- end
-
- part3 = part3 .. says .. "..."
- end
-
- -- title
- local title = chatUI:find("title")
- assert(title)
- title.uc_hardtext= part1..part2..part3
-end
-
-function r2:getChatName(chatInst)
-
- -- part1
- local index = r2:searchElementIndex(chatInst)
- if erase==true then index = index-1 end
- local part1 = tostring(i18n.get("uiR2EdChat")).." "..index.." : "
-
- -- part2
- local minNb, secNb = r2:calculMinSec(chatInst.Time)
- local time = ""
- if minNb ~= 0 then
- time = tostring(minNb)..tostring(i18n.get("uiR2EdShortMinutes"))
- end
- time = time.." " ..tostring(secNb)..tostring(i18n.get("uiR2EdShortSeconds"))
- local part2 = "(" ..tostring(i18n.get("uiR2EdAfter")).." ".. time..") "
-
- -- part3
- local part3 = ""
- local action = chatInst.Actions[0]
- local who = action.Who
- if who ~= "" then
- who = r2:getInstanceFromId(who)
- assert(who)
- part3 = who.Name .. " " ..tostring(i18n.get("uiR2EdSays")).. " "
-
- local says = action.Says
- if says ~= "" then
- says = r2:getInstanceFromId(says).Text
- says = string.sub(says, 1, 4)
- end
-
- part3 = part3 .. says .. "..."
- end
-
- return part1..part2..part3
-
-end
-
-function r2:updateChatText(elementUI)
-
- if elementUI == nil then
- elementUI = r2:getSelectedEltUI("r2ed_chat_sequence")
- end
- assert(elementUI)
-
- local instance = r2:getInstanceFromId(elementUI.Env.elementId)
- assert(instance)
-
- local chatText = elementUI:find("text_list")
- assert(chatText)
-
- chatText:clear()
-
- local who = tostring(instance.Actions[0].Who)
- if who ~= "" then
-
- local text = ""
- local textEmpty = true
-
- local facing = tostring(instance.Actions[0].Facing)
- local emote = instance.Actions[0].Emote
- local says = instance.Actions[0].Says
-
- if facing ~= "" then
- text = "\n"..r2:getInstanceFromId(who).Name .." "..tostring(i18n.get("uiR2EdFaces")).." ".. r2:getInstanceFromId(facing).Name
- textEmpty = false
- end
- if r2.fromEmoteIdToName[emote] ~= nil then
- text = text .. "\n" .. r2:getInstanceFromId(who).Name .. " "..string.lower(tostring(i18n.get("uiR2EdEmote"))).." : " .. r2.fromEmoteIdToName[emote]
- textEmpty = false
- end
- if r2:getInstanceFromId(says)~=nil and r2:getInstanceFromId(says).Text ~= "" then
- text = text.."\n"..r2:getInstanceFromId(who).Name .. " "..tostring(i18n.get("uiR2EdSays")).." : " .. r2:getInstanceFromId(says).Text
- textEmpty = false
- end
- text = text.."\n"
-
- chatText:addTextChild(ucstring(text))
-
- local sep = elementUI:find("sep")
- assert(sep)
- if textEmpty == false then
- sep.active = true
- else
- chatText:clear()
- sep.active = false
- end
- end
-
- r2:buildChatTitle(elementUI, false)
-
- local chatEditor = r2:getSelectedSequ("r2ed_chat_sequence"):find("edit_element")
- assert(chatEditor)
-
- if instance.InstanceId == r2:getSelectedEltInstId("r2ed_chat_sequence") then
- r2:updateChatEditor()
- end
-
- r2:updateActivitiesWhithThisChatSequence(instance, false)
-end
-
-
--------------------- UP CHAT ----------------------------------------------------------------------
-function r2:upChat()
- r2:upTriggerElement("r2ed_chat_sequence")
-end
-
--------------------- DOWN CHAT --------------------------------------------------------------------
-function r2:downChat()
- r2:downTriggerElement("r2ed_chat_sequence")
-end
-
--------------------- MAX / MIN CHATS --------------------------------------------------------------
-function r2:maximizeMinimizeChats()
- r2:maximizeMinimizeTriggerElements("r2ed_chat_sequence")
-end
-
--------------------- REMOVE CHAT ------------------------------------------------------------------
-function r2:removeChat()
- r2:removeTriggerElement("r2ed_chat_sequence", tostring(i18n.get("uiR2EdChat")))
-end
-
--------------------- CHAT TIME --------------------------------------------------------------------
-function r2:setTime(minNb, secNb)
-
- local chatSequenceId = r2:getSelectedEltInstId("r2ed_chat_sequence")
-
- r2.requestSetNode(chatSequenceId, "Time", minNb*60+secNb)
-end
-
--------------------- INIT TIME MENU -----------------------------------------------------------------
-function r2:initTimeMenu(timeFunction, isHours)
-
- local timeMenu = getUI("ui:interface:r2ed_triggers_menu")
- assert(timeMenu)
-
- local timeMenu = timeMenu:getRootMenu()
- assert(timeMenu)
-
- timeMenu:reset()
-
- for i=0,9 do
- timeMenu:addLine(ucstring(tostring(i)), "lua", timeFunction .. "(" .. tostring(i) .. ")", tostring(i))
- end
-
- if isHours == true then
- timeMenu:addLine(ucstring(tostring(10)), "lua", timeFunction .. "(" .. tostring(10) .. ")", tostring(10))
- else
-
- local lineNb = 9
- for i=10, 50, 10 do
- local lineStr = tostring(i).."/"..tostring(i+9)
- timeMenu:addLine(ucstring(lineStr), "", "", tostring(i))
- lineNb = lineNb+1
-
- timeMenu:addSubMenu(lineNb)
- local subMenu = timeMenu:getSubMenu(lineNb)
-
- for s=0,9 do
- lineStr = tostring(i+s)
- subMenu:addLine(ucstring(lineStr), "lua", timeFunction .. "(" .. tostring(i+s) .. ")", lineStr)
- end
- end
- end
-
- r2:openTriggersMenu(getUICaller())
-end
-
--------------------- CHAT SECONDS -----------------------------------------------------------------
-function r2:chatAfterSeconds(secNb)
-
- local chatStepInst = r2:getSelectedEltInst("r2ed_chat_sequence")
-
- local lastTime = chatStepInst.Time
-
- local minNb = 0
- while lastTime > 59 do
- lastTime = lastTime - 60
- minNb = minNb + 1
- end
-
- r2:setTime(minNb, secNb)
-
- -- recover "says what" (equiv change focus)
- local chatEditor = r2:getSelectedSequ("r2ed_chat_sequence"):find("edit_element")
- assert(chatEditor)
-
- local saysWhat = chatEditor:find("says"):find("edit_box_group").input_string
- if chatStepInst.Actions[0].Says ~= r2.registerText(saysWhat).InstanceId then
- r2:setSaysWhat(saysWhat)
- end
-end
-
--------------------- CHAT MINUTES -----------------------------------------------------------------
-function r2:chatAfterMinutes(minNb)
-
- local chatStepInst = r2:getSelectedEltInst("r2ed_chat_sequence")
-
- local lastTime = chatStepInst.Time
-
- local secNb = lastTime
- while secNb > 59 do
- secNb = secNb - 60
- end
-
- r2:setTime(minNb, secNb)
-
- -- recover "says what" (equiv change focus)
- local chatEditor = r2:getSelectedSequ("r2ed_chat_sequence"):find("edit_element")
- assert(chatEditor)
-
- local saysWhat = chatEditor:find("says"):find("edit_box_group").input_string
- if chatStepInst.Actions[0].Says ~= r2.registerText(saysWhat).InstanceId then
- r2:setSaysWhat(saysWhat)
- end
-end
-
--------------------- WHO --------------------------------------------------------------------------
-function r2:setWho(who, chatStepInst)
-
- if chatStepInst == nil then
- chatStepInst = r2:getSelectedEltInst("r2ed_chat_sequence")
- end
- assert(chatStepInst)
-
- r2.requestSetNode(chatStepInst.Actions[0].InstanceId, "Who", r2.RefId(who))
-
- if who == chatStepInst.Actions[0].Facing then
- r2:setToWho(tostring(i18n.get("uiR2EdNobody")))
- end
-
- -- recover "says what" (equiv change focus)
- local chatEditor = r2:getSelectedSequ("r2ed_chat_sequence"):find("edit_element")
- assert(chatEditor)
-
- local saysWhat = chatEditor:find("says"):find("edit_box_group").input_string
- if chatStepInst.Actions[0].Says ~= r2.registerText(saysWhat).InstanceId then
- r2:setSaysWhat(saysWhat)
- end
-end
-
-function r2:openWhoMenu(whoFunction, towho)
-
- local menuName = "ui:interface:r2ed_triggers_menu"
-
- local whoMenu = getUI(menuName)
- local whoMenu = whoMenu:getRootMenu()
- assert(whoMenu)
-
- whoMenu:reset()
-
- local npcTable = r2.Scenario:getAllInstancesByType("Npc")
-
- if towho == true then
- whoMenu:addLine(ucstring(i18n.get("uiR2EdNobody")), "lua", whoFunction.."('" ..tostring(i18n.get("uiR2EdNobody")).. "')", "Nobody")
- end
-
- for key, npc in npcTable do
- local addLine = true
- if not npc:isBotObject() and not npc:isPlant() and not r2.isCreature(npc.InstanceId) then
- if towho == true then
- local chatStepInst= r2:getSelectedEltInst("r2ed_chat_sequence")
- assert(chatStepInst)
-
- local whoId = chatStepInst.Actions[0].Who
- if whoId~="" and whoId == npc.InstanceId then
- addLine = false
- end
- end
- if addLine then
- whoMenu:addLine(ucstring(npc.Name), "lua", whoFunction.."('" ..npc.InstanceId.. "')", npc.InstanceId)
- end
- end
- end
-
- r2:openTriggersMenu(getUICaller())
-end
-
--------------------- SAYS WHAT --------------------------------------------------------------------
-function r2:setSaysWhat(what)
-
- if what == nil then
- what = getUICaller().input_string
- end
-
- local says = what
-
- local chatStep = r2:getSelectedEltInst("r2ed_chat_sequence")
- if chatStep ~= nil then
- if what ~= "" then
- what=r2.registerText(what).InstanceId
- end
- r2.requestSetNode(chatStep.Actions[0].InstanceId, "Says", what)
-
- local chatStepUI = r2:getSelectedEltUI("r2ed_chat_sequence")
- assert(chatStepUI)
- end
-end
-
--------------------- CLOSE CHAT EDITOR ------------------------------------------------------------
-function r2:closeChatEditor(chatEditor)
-
- if chatEditor == nil then
- chatEditor = r2:getSelectedSequ("r2ed_chat_sequence"):find("edit_element")
- end
- assert(chatEditor)
-
- local editSaysWhat = chatEditor:find("says"):find("edit_box_group")
- assert(editSaysWhat)
-
- if r2.callSetSaysWhat == true then
- r2:setSaysWhat(editSaysWhat.input_string)
- end
-end
-
--------------------- TO WHO -----------------------------------------------------------------------
-function r2:setToWho(toWho)
-
- local chatSequence = r2:getSelectedEltInst("r2ed_chat_sequence")
- assert(chatSequence)
-
- local chatEditor = r2:getSelectedSequ("r2ed_chat_sequence"):find("edit_element")
- assert(chatEditor)
-
- -- recover "says what" (equiv change focus)
- local saysWhat = chatEditor:find("says"):find("edit_box_group").input_string
- if chatSequence.Actions[0].Says ~= r2.registerText(saysWhat).InstanceId then
- r2:setSaysWhat(saysWhat)
- end
-
- if toWho == tostring(i18n.get("uiR2EdNobody")) then toWho="" end
-
- r2.requestSetNode(chatSequence.Actions[0].InstanceId, "Facing", r2.RefId(toWho))
-end
-
--------------------- EMOTE ------------------------------------------------------------------------
-function r2:openEmoteMenu()
-
- local menuName = "ui:interface:r2ed_triggers_menu"
-
- local emoteMenu = getUI(menuName)
- local emoteMenu = emoteMenu:getRootMenu()
- assert(emoteMenu)
-
- emoteMenu:reset()
- initEmotesMenu(menuName, "r2:setEmote")
- r2:openTriggersMenu(getUICaller())
-end
-
-function r2:setEmote(emoteId)
-
- local chatSequence = r2:getSelectedEltInst("r2ed_chat_sequence")
- assert(chatSequence)
-
- r2.requestSetNode(chatSequence.Actions[0].InstanceId, "Emote", emoteId)
-
- -- recover "says what" (equiv change focus)
- local chatEditor = r2:getSelectedSequ("r2ed_chat_sequence"):find("edit_element")
- assert(chatEditor)
-
- local saysWhat = chatEditor:find("says"):find("edit_box_group").input_string
- if chatSequence.Actions[0].Says ~= r2.registerText(saysWhat).InstanceId then
- r2:setSaysWhat(saysWhat)
- end
-end
-
------------------- SELECT CHAT SEQUENCE ---------------------------------------------------------
-function r2:selectChatsSequence(index)
- r2:selectElementsSequence("r2ed_chat_sequence", index)
- r2:updateMiniActivityView()
-end
-
----------------------------------------------------------------------------------------------------
------------------------------- FACTORISATION ----------------------------------------------------
----------------------------------------------------------------------------------------------------
-
------------------------------- Remove element ---------------------------------------------------
-function r2:removeTriggerElement(uiName, elementName)
-
- local wndUI = getUI("ui:interface:"..uiName)
- assert(wndUI)
-
- local tab = wndUI:find("sequence_tabs")
- assert(tab)
-
- local sequenceUI = wndUI:find(tab.associatedGroupSelection)
- assert(sequenceUI)
-
- r2:removeElement(sequenceUI, uiName, elementName)
-end
-
------------------------------------------------------------------------------------------------------
-function r2:removeElement(sequence, uiName, elementName, removedElement)
-
- local listElements = sequence:find("elements_list")
- assert(listElements)
-
- local toErasedInstId
- if removedElement == nil then
- toErasedInstId = r2:getSelectedEltInstId(uiName)
- else
- toErasedInstId = removedElement.Env.elementId
- end
- assert(toErasedInstId)
-
- -- request erase node
- if toErasedInstId ~= nil and r2:getInstanceFromId(toErasedInstId) ~= nil then
- r2.requestEraseNode(toErasedInstId, "", -1)
- end
-end
-
-function r2:removeElementUI(sequence, uiName, removedElement)
-
- local listElements = sequence:find("elements_list")
- assert(listElements)
-
- -- update follow elements number
- local removedIndex = listElements:getElementIndex(removedElement)
- for i = removedIndex+1, (listElements.childrenNb-1) do
- local element = listElements:getChild(i)
- assert(element)
-
- if not element.Env.isEditor then
- r2:buildElementTitle(uiName, element, true)
- end
- end
-
- -- delete element and update coordinates of elements list
- if removedElement == r2:getSelectedEltUI(uiName) then
- r2:setSelectedEltUIId(uiName, nil)
-
- -- inactive element editor
- local eltEditor = listElements:find("edit_element")
- assert(eltEditor)
- eltEditor.active = false
-
- -- disactive up and down element buttons
- local upElement = sequence:find("up_element")
- assert(upElement)
- local downElement = sequence:find("down_element")
- assert(downElement)
- local elementOrder = sequence:find("element_order")
- assert(elementOrder)
-
- upElement.active = false
- downElement.active = false
- elementOrder.active = false
- end
- listElements.Env.elementsNb = listElements.Env.elementsNb - 1
-
- listElements:delChild(removedElement)
- listElements.parent:invalidateCoords()
-
- -- if any activity in list, disactive global minimize / maximize button
- if listElements.childrenNb == 1 then
- local minElts = sequence:find("minimize_elements")
- assert(minElts)
-
- local maxElts = sequence:find("maximize_elements")
- assert(maxElts)
-
- minElts.active = false
- maxElts.active = false
- end
-end
-
------------------------------- Max / Min elements -----------------------------------------------
-function r2:maximizeMinimizeTriggerElements(uiName)
-
- local sequence = r2:getSelectedSequ(uiName)
- assert(sequence)
-
- r2:maximizeMinimizeElements(sequence, uiName)
-end
-
------------------------------- Max / Min elements -----------------------------------------------
-function r2:maximizeMinimizeElements(sequence, uiName)
-
- local elements = sequence:find("elements_list")
- assert(elements)
-
- if elements.Env.minimize == nil then
- elements.Env.minimize = true
- end
-
- elements.Env.minimize = not elements.Env.minimize
-
- for i = 0, elements.childrenNb-1 do
- local element = elements:getChild(i)
- assert(element)
-
- if element.Env.isEditor ~= true then
- r2:maximizeMinimizeElement(uiName, element, elements.Env.minimize)
- end
- end
-
- local minElts = sequence:find("minimize_elements")
- assert(minElts)
- local maxElts = sequence:find("maximize_elements")
- assert(maxElts)
-
- if elements.Env.minimize == true then
- minElts.active = false
- maxElts.active = true
- else
- minElts.active = true
- maxElts.active = false
- end
-end
-
------------------------------- Max / Min element ------------------------------------------------
-function r2:maximizeMinimizeElement(uiName, element, allMinimize)
-
- if element == nil then
- element = getUICaller().parent.parent.parent.parent.parent.parent
- end
- assert(element)
-
- local eltText = element:find("element_text")
- assert(eltText)
-
- local allMin, allMax = true, true
- if allMinimize ~= nil then
- allMin = allMinimize
- allMax = not allMin
- end
-
- local maxButton = element:find("maximize_element")
- assert(maxButton)
- local minButton = element:find("minimize_element")
- assert(minButton)
-
- -- maximize
- if allMax and eltText.active==false then
- eltText.active = true
- maxButton.active = false
- minButton.active = true
-
- -- minimize
- elseif allMin and eltText.active==true then
- eltText.active = false
- maxButton.active = true
- minButton.active = false
- end
-end
-
------------------------------------- Down element --------------------------------------------------
-function r2:downTriggerElement(uiName)
-
- local eltSequenceUI = getUI("ui:interface:"..uiName)
- assert(eltSequenceUI)
-
- local tab = eltSequenceUI:find("sequence_tabs")
- assert(tab)
-
- local sequence = eltSequenceUI:find(tab.associatedGroupSelection)
- assert(sequence)
-
- local listElements = sequence:find("elements_list")
- assert(listElements)
-
- local selectedElement = r2:getSelectedEltUI(uiName)
- local index = listElements:getElementIndex(selectedElement)
-
- local sequenceId = r2:getSelectedSequInstId(uiName)
- if index < r2:getInstanceFromId(sequenceId).Components.Size-1 then
- r2.requestMoveNode(sequenceId, "Components", index+1,
- sequenceId, "Components", index)
- end
-end
-
------------------------------------- Down or up element UI ------------------------------------------
-
-function r2:downUpElement(elementUI, uiName)
-
- local listElements = elementUI.parent
- assert(listElements)
-
- local eltEditor = listElements:find("edit_element")
- assert(eltEditor)
-
- local index = listElements:getElementIndex(elementUI)
-
- if index > 0 then
- local previousElement = listElements:getChild(index - 1)
-
- local editorBetweenBothElts = false
- if previousElement.Env.elementId==nil then
- previousElement = listElements:getChild(index - 2)
- editorBetweenBothElts = true
- end
-
- listElements:upChild(elementUI)
- if editorBetweenBothElts==true then
- listElements:upChild(elementUI)
- end
-
- local selectedEltUI = r2:getSelectedEltUI(uiName)
- if selectedEltUI~=nil then
- local selectedEltIndex = listElements:getElementIndex(selectedEltUI)
- local eltEditorIndex = listElements:getElementIndex(eltEditor)
- if eltEditorIndex~=selectedEltIndex+1 then
- if eltEditorIndex0 then
- local sequenceId = r2:getSelectedSequInstId(uiName)
- r2.requestMoveNode(sequenceId, "Components", index,
- sequenceId, "Components", index-1)
- end
-end
-
----------------------------------------------------------------------------------------------------
-function r2:selectTriggerElement(sequenceUI, uiName, selectedButtonElt)
-
- if sequenceUI == nil then
- sequenceUI = r2:getSelectedSequ(uiName)
- end
- r2:selectElement(sequenceUI, uiName, true, selectedButtonElt)
-end
-
----------------------------------------------------------------------------------------------------
-function r2:closeElementEditor(uiName)
-
- if uiName == "r2ed_chat_sequence" then
- r2:closeChatEditor(getUICaller())
- end
-
- local sequenceUI = r2:getSelectedSequ(uiName)
- assert(sequenceUI)
-
- local selectedEltUI = r2:getSelectedEltUI(uiName)
- assert(selectedEltUI)
-
- local selectedEltButton = selectedEltUI:find("select")
- assert(selectedEltButton)
-
- selectedEltButton.pushed = false
-
- r2:selectElement(sequenceUI, uiName, false, selectedEltButton)
-end
-
----------------- SELECT ELEMENT -------------------------------------------------------------------
-function r2:selectElement(sequence, uiName, eltOrder, selectedButtonElt)
-
- local upElement = sequence:find("up_element")
- assert(upElement)
- local downElement = sequence:find("down_element")
- assert(downElement)
- local orderElt = sequence:find("element_order")
-
- if selectedButtonElt == nil then
- selectedButtonElt = getUICaller()
- end
-
- -- new selected element
- if selectedButtonElt.pushed == true then
-
- if r2:getSelectedEltUIId(uiName) then
-
- local lastSelectedElement = r2:getSelectedEltUI(uiName)
- assert(lastSelectedElement)
-
- local lastEltsList = lastSelectedElement.parent
- local editElt = lastEltsList:find("edit_element")
- assert(editElt)
-
- if r2:getSelectedEltUIId(uiName) == selectedButtonElt.parent.parent.parent.id then
- return
- end
-
- lastSelectedElement.active = true
- lastSelectedElement:find("select").pushed = false
-
- editElt.active = false
- end
-
- r2:setSelectedEltUIId(uiName, selectedButtonElt.parent.parent.parent.id)
-
- local selectedElement = selectedButtonElt.parent.parent.parent
- assert(selectedElement)
-
- if eltOrder then
- upElement.active = true
- downElement.active = true
- orderElt.active = true
- end
-
- -- update element editor position in list
- local eltsList = sequence:find("elements_list")
- assert(eltsList)
- local editElt = eltsList:find("edit_element")
- assert(editElt)
-
- local indexSelectedElt = eltsList:getElementIndex(selectedElement)
- local indexEltEditor = eltsList:getElementIndex(editElt)
-
- if indexEltEditor=0) and (sequencesTab.tabButtonNb > index) then
- sequencesTab.selection = tonumber(index)
-
- local repeatButton = eltsWnd:find("repeat_group"):find("repeat"):find("toggle_butt")
- assert(repeatButton)
-
- local sequenceUI = sequencesTab:getGroup(index)
- assert(sequenceUI)
- local sequenceInstId = sequenceUI.Env.sequenceId
-
- if sequenceInstId and r2:getInstanceFromId(sequenceInstId) then
- local sequenceInst = r2:getInstanceFromId(sequenceInstId)
- repeatButton.pushed = (sequenceInst.Repeating == 0)
- end
- end
-end
-
-
----------------------------------------- Open element editor --------------------------------------
-function r2:openElementEditor(uiName, title, baseWindowName)
-
- local elementEditor = r2:getSelectedSequ(uiName):find("edit_element")
- assert(elementEditor)
-
- local selectedElement = r2:getSelectedEltUI(uiName)
- assert(selectedElement)
-
- elementEditor.active = true
- selectedElement.active = false
-end
-
------------------------------------ Remove elements sequence --------------------------------------
-function r2:removeElementsSequence(uiName, elementsTable, sequName)
-
- local eltSequenceUI = getUI("ui:interface:"..uiName)
- assert(eltSequenceUI)
-
- local tab = eltSequenceUI:find("sequence_tabs")
- assert(tab)
-
- local activeLogicEntity = r2:getSelectedInstance()
- assert(activeLogicEntity)
- local activitySequences = activeLogicEntity:getBehavior()[elementsTable]
-
- --local seq = sequName
-
- --for i=tab.selection+1,(tab.tabButtonNb-1) do
- -- local buttonTab = tab:find("tab"..i)
- -- assert(buttonTab)
-
- -- if activitySequences[i].Name == seq..(i+1) then
- -- local newText = seq..(i)
- -- r2.requestSetNode(activitySequences[i].InstanceId, "Name", newText)
- -- end
- --end
-
- local sequenceId = r2:getSelectedSequInstId(uiName)
- -- request erase node
- r2.requestEraseNode(sequenceId, "", -1)
-
- return sequenceId
-end
-
-function r2:removeElementsSequenceUI(tabIndex, uiName, elementsTable, sequName)
-
- local wndUI = getUI("ui:interface:"..uiName)
- assert(wndUI)
-
- local tab = wndUI:find("sequence_tabs")
- assert(tab)
-
- local activeLogicEntity = r2:getSelectedInstance()
- assert(activeLogicEntity)
- local activitySequences = activeLogicEntity:getBehavior()[elementsTable]
-
- for i=tabIndex+1,(tab.tabButtonNb-1) do
- local buttonTab = tab:find("tab"..i)
- assert(buttonTab)
-
- buttonTab.params_l = "r2:selectSequenceTab('"..uiName.."', "..tostring(i-1)..")"
-
- if buttonTab.hardtext == sequName..(i+1) then
- buttonTab.uc_hardtext = sequName..i
- end
- end
-
- -- recover name of the future "first sequence"
- local firstEltName
- local indexName
- if tab.tabButtonNb > 1 then
- if tabIndex==0 then
- indexName = 1
- else
- indexName = 0
- end
- --if activitySequences[indexName].Name==sequName..(indexName+1) then
- if r2:getSequenceName(activitySequences[indexName])==sequName..(indexName+1) then
- firstEltName = sequName.."1"
- else
- --firstEltName = activitySequences[indexName].Name
- firstEltName = r2:getSequenceName(activitySequences[indexName])
- end
- else
- firstEltName = tostring(i18n.get("uiR2EDSequences"))
- end
-
- local selectedElt = r2:getSelectedEltUI(uiName)
- if selectedElt and selectedElt.parent.parent.parent.id == r2:getSelectedSequ(uiName).id then
- r2:setSelectedEltUIId(uiName, nil)
- end
-
- tab:removeTab(tabIndex)
-
- if tab.tabButtonNb == 0 then
- r2:cleanSequenceEditor(wndUI)
- end
-
- return firstEltName
-end
-
-function r2:cleanSequenceEditor(eltSequenceUI)
-
- local sepTop = eltSequenceUI:find("sep_top")
- assert(sepTop)
-
- local sepBottom = eltSequenceUI:find("sep_bottom")
- assert(sepBottom)
-
- local sepLeft = eltSequenceUI:find("sep_left")
- assert(sepLeft)
-
- local sepRight = eltSequenceUI:find("sep_right")
- assert(sepRight)
-
- local removeSequence = eltSequenceUI:find("remove_sequence_button")
- assert(removeSequence)
-
- local editSequence = eltSequenceUI:find("edit_sequence")
- assert(editSequence)
-
- sepTop.active = false
- sepBottom.active = false
- sepLeft.active= false
- sepRight.active= false
- removeSequence.active = false
- editSequence.active = false
-
- local repeatButtonGr = eltSequenceUI:find("repeat_group")
- repeatButtonGr.active = false
-end
-
------------------- new elements sequence -------------------------------------------------------------
-function r2:newElementsSequence(uiName, templateParams, editorEltTemplate, instance, sequName)
-
- local eltSequenceUI = getUI("ui:interface:"..uiName)
- assert(eltSequenceUI)
-
- local menu = eltSequenceUI:find("sequence_menu")
- assert(menu)
-
- local tab = menu:find("sequence_tabs")
- assert(tab)
-
- local newTabNb = tab.tabButtonNb+1
- local posParent, posRef, id, hardText, group
- if newTabNb == 1 then
- posParent = "parent"
- posRef = "TL TL"
- else
- posParent = "tab"..(newTabNb-2)
- posRef = "TR TL"
- end
-
- id = "tab"..(newTabNb-1)
- local group = "sequence"..r2.sequencesNb
-
- r2.sequencesNb = r2.sequencesNb + 1
-
- local newTabGroup = createUIElement("sequence_elements_template", menu.id, {id=group,
- new_elt=templateParams.newElt, new_elt_text=templateParams.newEltText,
- elt_order_text=templateParams.eltOrderText, up_elt=templateParams.upElt,
- down_elt=templateParams.downElt, max_min_elts=templateParams.maxMinElts,
- down_up_color=templateParams.downUpColor})
- assert(newTabGroup)
-
- menu:addGroup(newTabGroup)
-
- newTabGroup.Env.sequenceId = instance.InstanceId
-
- local tabName
- if instance.Name~= "" then
- tabName = instance.Name
- else
- local comps = instance.Parent
- for i=0, comps.Size-1 do
- if comps[i].InstanceId == instance.InstanceId then
- tabName = sequName..(i+1)
- break
- end
- end
- end
-
- local newTab = createUIElement("sequence_tab_template", tab.id,
- {id=id, posparent=posParent, posref=posRef, hardtext=tabName, group=group,
- col_pushed =templateParams.colPushed, params_l=templateParams.paramsL})
- assert(newTab)
-
- tab:addTab(newTab)
-
- if r2.ownCreatedInstances[instance.InstanceId] == true then
- tab.selection = tab.tabButtonNb-1
- r2.ownCreatedInstances[instance.InstanceId] = nil
-
- --local repeatButton = eltSequenceUI:find("repeat_group"):find("repeat"):find("toggle_butt")
- --assert(repeatButton)
- --repeatButton.pushed = (instance.Repeating == 0)
-
- r2:selectElementsSequence(uiName, tab.tabButtonNb-1)
- end
-
- if tab.tabButtonNb == 1 then
- local sepTop = menu:find("sep_top")
- assert(sepTop)
-
- local sepBottom = menu:find("sep_bottom")
- assert(sepBottom)
-
- local sepLeft = menu:find("sep_left")
- assert(sepLeft)
-
- local sepRight = menu:find("sep_right")
- assert(sepRight)
-
- local removeSequence = eltSequenceUI:find("remove_sequence_button")
- assert(removeSequence)
-
- local editSequence = eltSequenceUI:find("edit_sequence")
- assert(editSequence)
-
- sepTop.active = true
- sepBottom.active = true
- sepLeft.active= true
- sepRight.active= true
- removeSequence.active = true
- editSequence.active = true
-
- if uiName == "r2ed_triggers" then --TEMP TEMP TEMP
- local repeatButtonGr = eltSequenceUI:find("repeat_group")
- repeatButtonGr.active = true
- end --TEMP TEMP TEMP
- end
-
- local listElements = newTabGroup:find("elements_list")
- assert(listElements)
- listElements.Env.elementsCount = nil
-
- -- add element editor in list
- local newEditorElt = createGroupInstance(editorEltTemplate, listElements.id, {id="edit_element", active="false"})
- assert(newEditorElt)
- listElements:addChild(newEditorElt)
- listElements.parent:updateCoords()
-
- newEditorElt.Env.isEditor = true
-
- newEditorElt.active = false
-
- return newTabGroup
-end
-
----------------------------- new element --------------------------------------------------------------
-function r2:newTriggerElement(uiName, elementName, templateParams, sequenceUI, instanceId)
-
- if sequenceUI == nil then
- eltSequenceUI = getUI("ui:interface:"..uiName)
- assert(eltSequenceUI)
-
- local tab = eltSequenceUI:find("sequence_tabs")
- assert(tab)
-
- local sequenceUI = eltSequenceUI:find(tab.associatedGroupSelection)
- end
- assert(sequenceUI)
-
- local newElement = r2:newElement(sequenceUI, elementName, templateParams, true)
-
- newElement.Env.elementId = instanceId
-
- if r2.ownCreatedInstances[instanceId] == true then
- newElement:find("select").pushed = true
- r2:selectTriggerElement(sequenceUI, uiName, newElement:find("select"))
- r2.ownCreatedInstances[instanceId] = nil
-
- if uiName == "r2ed_triggers" then
- r2:updateActivityEditor()
- elseif uiName == "r2ed_chat_sequence" then
- r2:updateChatEditor()
- end
- end
-
- r2:maximizeMinimizeElement(uiName, newElement)
-
- return newElement
-end
-
----------------------------- new base element --------------------------------------------------------------
-function r2:newElement(sequence, elementName, templateParams, eltOrder)
-
- local listElements = sequence:find("elements_list")
- assert(listElements)
-
- -- counter for element group id
- if listElements.Env.elementsCount == nil then
- listElements.Env.elementsCount = 0
- listElements.Env.elementsNb = 1
- else
- listElements.Env.elementsCount = listElements.Env.elementsCount+1
- listElements.Env.elementsNb = listElements.Env.elementsNb+1
- end
-
- local elementId = "elt"..listElements.Env.elementsCount
-
- local hardText = elementName.." "..listElements.Env.elementsNb.." : "
-
- -- create new element
- local newElement = createGroupInstance("element_template", listElements.id,
- {id=elementId, posref="TL TL", x="0", y="0", sizeref="w", hardtext=hardText,
- select_elt=templateParams.selectElt, open_elt_editor=templateParams.openEltEditor,
- max_min_elt=templateParams.maxMinElt, remove_elt=templateParams.removeElt, open_chat=templateParams.openChat,
- col_over=templateParams.colOver, col_pushed=templateParams.colPushed})
-
- -- add element to list
- listElements:addChild(newElement)
- listElements.parent:updateCoords()
-
- -- active global minimize / maximize button
- if listElements.childrenNb == 2 then
- local maxElts = sequence:find("maximize_elements")
- assert(maxElts)
- maxElts.active = true
-
- if eltOrder then
-
- local elementOrder = sequence:find("element_order")
- assert(elementOrder)
- elementOrder.active=true
- end
- end
-
- -- scroll goes down to new element
- local sequenceContent = newElement.parent.parent.parent
- assert(sequenceContent)
-
- local scrollBar = sequenceContent:find("scroll_objects")
- assert(scrollBar)
- scrollBar.trackPos = 0
-
- -- target sroll text
- local scroll = newElement:find("scroll_bar_text")
- assert(scroll)
-
- local scrollText = newElement:find("scroll_text_gr")
- assert(scrollText)
- scroll:setTarget(scrollText.id)
-
- return newElement
-end
-
------------------- OPEN SEQUENCE EDITOR --------------------------------------------------
-function r2:openSequenceEditor(uiName, editorName)
-
- local editor = getUI("ui:interface:"..editorName)
- assert(editor)
-
- local eltsUI = getUI("ui:interface:"..uiName)
- assert(eltsUI)
-
- editor.x = eltsUI.x
- editor.y = eltsUI.y
- editor.active = true
-
- -- update edit box text with current sequence name
- local editName = editor:find("sequence_name"):find("edit_box_group")
- assert(editName)
-
- local tab = eltsUI:find("sequence_tabs")
- assert(tab)
-
- local buttonTab = tab:find("tab"..tab.selection)
- assert(buttonTab)
-
- editName.uc_input_string = buttonTab.uc_hardtext
-end
-
------------------- SET SEQUENCE NAME -----------------------------------------------------
-function r2:setSequenceName(uiName, editorName)
-
- local editor = getUI("ui:interface:"..editorName)
- assert(editor)
-
- local editName = editor:find("sequence_name"):find("edit_box_group")
- assert(editName)
-
- local name = editName.input_string
-
- local sequenceInstId = r2:getSelectedSequInstId(uiName)
- r2.requestSetNode(sequenceInstId, "Name", name)
-end
-
-function r2:updateSequenceName(uiName, instance)
-
- --local name = instance.Name
- local name = r2:getSequenceName(instance)
- local sequInstId = instance.InstanceId
-
- local eltsUI = getUI("ui:interface:"..uiName)
- assert(eltsUI)
-
- local tab = eltsUI:find("sequence_tabs")
- assert(tab)
-
- local tabId
- for i=0, tab.tabButtonNb-1 do
- local sequenceUI = tab:getGroup(i)
- if sequenceUI.Env.sequenceId == sequInstId then
- tabId = i
- break
- end
- end
-
- local buttonTab = tab:find("tab"..tabId)
- assert(buttonTab)
-
- buttonTab.uc_hardtext = name
-
- if uiName == "r2ed_triggers" then
- r2:updateSequencesButtonBar(tabId, name)
- end
-end
-
-function r2:updateSequenceRepeatingOption(uiName, instance)
-
- local sequenceUI = r2:getSelectedSequ(uiName)
-
- if sequenceUI.Env.sequenceId == instance.InstanceId then
-
- local eltsUI = getUI("ui:interface:"..uiName)
- local repeatButton = eltsUI:find("repeat_group"):find("repeat"):find("toggle_butt")
- repeatButton.pushed = (instance.Repeating == 0)
- end
-end
-
-
---------------------------------------------------------------------------------------------------
--------------------------- ACTIVE LOGIC ENTITY DisplayerProperties -----------------------------------------
---------------------------------------------------------------------------------------------------
-
-local activeLogicEntityPropertySheetDisplayerTable = clone(r2:propertySheetDisplayer())
-
-------------------------------------------------
-function activeLogicEntityPropertySheetDisplayerTable:onPostCreate(instance)
-end
-------------------------------------------------
-function activeLogicEntityPropertySheetDisplayerTable:onErase(instance)
-end
-------------------------------------------------
-function activeLogicEntityPropertySheetDisplayerTable:onPreHrcMove(instance)
-end
-------------------------------------------------
-function activeLogicEntityPropertySheetDisplayerTable:onPostHrcMove(instance)
-end
-------------------------------------------------
-function activeLogicEntityPropertySheetDisplayerTable:onFocus(instance, hasFocus)
-end
-
-------------------------------------------------
-r2.activitiesAndChatsUIUpdate = false
-function activeLogicEntityPropertySheetDisplayerTable:onSelect(instance, isSelected)
-
- r2:logicEntityPropertySheetDisplayer():onSelect(instance, isSelected)
-
- local triggersUI = getUI("ui:interface:r2ed_triggers")
- assert(triggersUI)
-
- if not isSelected then
- triggersUI.active = false
- r2:closeMiniActivityView()
- r2:closeChatSequencesUI()
-
- r2:cleanActivitiesAndChatsUI()
- r2:cleanLogicEntityUI()
- else
- r2.activitiesAndChatsUIUpdate = false
- end
-end
-
-r2.callSetSaysWhat = true
-------------------------------------------------
-function r2:cleanActivitiesAndChatsUI()
-
- -- update chat sequence combo box
- local triggersUI = getUI("ui:interface:r2ed_triggers")
- assert(triggersUI)
- local chatSequencesUI = getUI("ui:interface:r2ed_chat_sequence")
- assert(chatSequencesUI)
-
- -- remove all tabs
- local sequenceMenu = triggersUI:find("sequence_menu")
- assert(sequenceMenu)
-
- local tabActivities = triggersUI:find("sequence_tabs")
- assert(tabActivities)
-
- for i=0, tabActivities.tabButtonNb-1 do
- local groupTab = tabActivities:getGroup(i)
- assert(groupTab)
- sequenceMenu:delGroup(groupTab)
- end
-
- tabActivities:removeAll()
- r2:setSelectedEltUIId("r2ed_triggers", nil)
- r2:cleanSequenceEditor(triggersUI)
-
- -- delete chat sequences
- sequenceMenu = chatSequencesUI:find("sequence_menu")
- assert(sequenceMenu)
-
- local tabChats = chatSequencesUI:find("sequence_tabs")
- assert(tabChats)
-
- for i=0, tabChats.tabButtonNb-1 do
- local groupTab = tabChats:getGroup(i)
- assert(groupTab)
- sequenceMenu:delGroup(groupTab)
- end
-
- tabChats:removeAll()
- r2:setSelectedEltUIId("r2ed_chat_sequence", nil)
- r2:cleanSequenceEditor(chatSequencesUI)
-end
-
-function r2:updateActivitiesAndChatsUI(instance)
-
- if r2.activitiesAndChatsUIUpdate==true then
- return
- end
-
- r2.activitiesAndChatsUIUpdate = true
-
- if r2.lastSelectedActivitySequence==nil then
-
- r2:cleanActivitiesAndChatsUI()
-
- -- update chat sequence combo box
- local triggersUI = getUI("ui:interface:r2ed_triggers")
- assert(triggersUI)
- local chatSequencesUI = getUI("ui:interface:r2ed_chat_sequence")
- assert(chatSequencesUI)
-
- -- remove all tabs
- local tabActivities = triggersUI:find("sequence_tabs")
- assert(tabActivities)
-
- -- delete chat sequences
- local tabChats = chatSequencesUI:find("sequence_tabs")
- assert(tabChats)
-
-
- local activitySequences = instance:getBehavior().Activities
- local chatSequences = instance:getBehavior().ChatSequences
-
- -- build sequences of selected NPC group
- local uiName = "r2ed_triggers"
-
- for s = 0, activitySequences.Size - 1 do
- local sequence = activitySequences[s]
- r2:newActivitiesSequence(false, sequence, true)
- end
-
- if tabActivities.tabButtonNb>1 then
- tabActivities.selection = 0
- r2:selectElementsSequence(uiName, 0)
- end
- for s=0, tabActivities.tabButtonNb-1 do
- local sequenceUI = tabActivities:getGroup(s)
- assert(sequenceUI)
-
- local eltsList = sequenceUI:find("elements_list")
- assert(eltsList)
- if eltsList.childrenNb > 1 then
- local firstElt = eltsList:getChild(1)
- local selectedButton = firstElt:find("select")
- selectedButton.pushed = true
-
- r2:selectElement(sequenceUI, uiName, true, selectedButton)
-
- r2:updateActivityEditor()
-
- break
- end
- end
-
- uiName = "r2ed_chat_sequence"
- r2.callSetSaysWhat = false
- for s = 0, chatSequences.Size - 1 do
- local sequence = chatSequences[s]
- r2:newChatsSequence(false, sequence, true)
- end
- r2.callSetSaysWhat = true
- if tabChats.tabButtonNb>1 then
- tabChats.selection = 0
- r2:selectElementsSequence(uiName, 0)
- end
- for s=0, tabChats.tabButtonNb-1 do
- local sequenceUI = tabChats:getGroup(s)
- assert(sequenceUI)
-
- local eltsList = sequenceUI:find("elements_list")
- assert(eltsList)
- if eltsList.childrenNb > 1 then
- local firstElt = eltsList:getChild(1)
- local selectedButton = firstElt:find("select")
- r2.callSetSaysWhat = false
- selectedButton.pushed = true
-
- r2:selectElement(sequenceUI, uiName, true, selectedButton)
-
- r2.callSetSaysWhat = true
-
- r2:updateChatEditor()
- end
- end
-
- triggersUI.uc_title = tostring(i18n.get("uiR2EDActivitySequenceEditor")) .. r2:getSelectedInstance().Name
- chatSequencesUI.uc_title = tostring(i18n.get("uiR2EDChatSequenceEditor")) .. r2:getSelectedInstance().Name
- end
-end
-
-------------------------------------------------
-function activeLogicEntityPropertySheetDisplayerTable:onAttrModified(instance, attributeName)
-
- r2:logicEntityPropertySheetDisplayer():onAttrModified(instance, attributeName)
-
- if not r2.activitiesAndChatsUIUpdate or instance ~= r2:getSelectedInstance() then
- return
- end
-
- if attributeName == "Name" then
-
- local triggersUI = getUI("ui:interface:r2ed_triggers")
- assert(triggersUI)
-
- local chatSequencesUI = getUI("ui:interface:r2ed_chat_sequence")
- assert(chatSequencesUI)
-
- triggersUI.uc_title = tostring(i18n.get("uiR2EDActivitySequenceEditor")) .. instance[attributeName]
- chatSequencesUI.uc_title = tostring(i18n.get("uiR2EDChatSequenceEditor")) .. instance[attributeName]
- end
-end
-
-------------------------------------------------
-function r2:activeLogicEntityPropertySheetDisplayer()
- return activeLogicEntityPropertySheetDisplayerTable -- returned shared displayer to avoid wasting memory
-end
-
-
---------------------------------------------------------------------------------------------------
--------------------------- NPC GROUP DisplayerProperties -----------------------------------------
---------------------------------------------------------------------------------------------------
-
-local npcGroupPropertySheetDisplayerTable = clone(r2:propertySheetDisplayer())
-
-------------------------------------------------
-function npcGroupPropertySheetDisplayerTable:onPostCreate(instance)
-end
-------------------------------------------------
-function npcGroupPropertySheetDisplayerTable:onErase(instance)
-end
-------------------------------------------------
-function npcGroupPropertySheetDisplayerTable:onPreHrcMove(instance)
-end
-------------------------------------------------
-function npcGroupPropertySheetDisplayerTable:onPostHrcMove(instance)
-end
-------------------------------------------------
-function npcGroupPropertySheetDisplayerTable:onFocus(instance, hasFocus)
-end
-
-------------------------------------------------
-function npcGroupPropertySheetDisplayerTable:onSelect(instance, isSelected)
- r2:activeLogicEntityPropertySheetDisplayer():onSelect(instance, isSelected)
-end
-
-------------------------------------------------
-function npcGroupPropertySheetDisplayerTable:onAttrModified(instance, attributeName)
- r2:activeLogicEntityPropertySheetDisplayer():onAttrModified(instance, attributeName)
-end
-
-------------------------------------------------
-function r2:npcGroupPropertySheetDisplayer()
- return npcGroupPropertySheetDisplayerTable -- returned shared displayer to avoid wasting memory
-end
-
-
-
-
-
-
---------------------------------------------------------------------------------------------------
--------------------------------- ACTIVITY SEQUENCE DisplayerProperties ---------------------------
---------------------------------------------------------------------------------------------------
-local activitySequencePropertySheetDisplayerTable = clone(r2:propertySheetDisplayer())
-
-------------------------------------------------
-function activitySequencePropertySheetDisplayerTable:onPostCreate(instance)
-
- local activeLogicEntity = r2:getSelectedInstance()
- local activeLogicEntityParent = instance.Parent.Parent.Parent
-
- if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
- return
- end
-
- r2:newActivitiesSequence(false, instance, false)
-end
-------------------------------------------------
-function activitySequencePropertySheetDisplayerTable:onErase(instance)
-
- local activeLogicEntity = r2:getSelectedInstance()
- local activeLogicEntityParent = instance.Parent.Parent.Parent
-
- if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
- return
- end
-
- local triggersUI = getUI("ui:interface:r2ed_triggers")
- assert(triggersUI)
-
- local sequenceTabs = triggersUI:find("sequence_tabs")
- assert(sequenceTabs)
-
- local sequIndex
- for i=0,sequenceTabs.tabButtonNb-1 do
- local sequence = sequenceTabs:getGroup(i)
- if sequence.Env.sequenceId == instance.InstanceId then
- sequIndex = i
- break
- end
- end
-
- if sequIndex~=nil then
- r2:removeActivitiesSequenceUI(sequIndex)
- end
-end
-------------------------------------------------
-function activitySequencePropertySheetDisplayerTable:onPreHrcMove(instance)
-end
-------------------------------------------------
-function activitySequencePropertySheetDisplayerTable:onPostHrcMove(instance)
-end
-------------------------------------------------
-function activitySequencePropertySheetDisplayerTable:onFocus(instance, hasFocus)
-end
-
-------------------------------------------------
-function activitySequencePropertySheetDisplayerTable:onSelect(instance, isSelected)
-end
-
-------------------------------------------------
-function activitySequencePropertySheetDisplayerTable:onAttrModified(instance, attributeName)
-
- local activeLogicEntity = r2:getSelectedInstance()
- local activeLogicEntityParent = instance.Parent.Parent.Parent
-
- if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
- return
- end
-
- if attributeName == "Name" then
- r2:updateSequenceName("r2ed_triggers", instance)
- elseif attributeName == "Repeating" then
- r2:updateSequenceRepeatingOption("r2ed_triggers", instance)
- end
-end
-
-------------------------------------------------
-function r2:activitySequencePropertySheetDisplayer()
- return activitySequencePropertySheetDisplayerTable -- returned shared displayer to avoid wasting memory
-end
-
-
---------------------------------------------------------------------------------------------------
--------------------------------- CHAT SEQUENCE DisplayerProperties ---------------------------
---------------------------------------------------------------------------------------------------
-local chatSequencePropertySheetDisplayerTable = clone(r2:propertySheetDisplayer())
-
-------------------------------------------------
-function chatSequencePropertySheetDisplayerTable:onPostCreate(instance)
-
- local activeLogicEntity = r2:getSelectedInstance()
- local activeLogicEntityParent = instance.Parent.Parent.Parent
-
- if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
- return
- end
-
- r2:newChatsSequence(false, instance)
-end
-------------------------------------------------
-function chatSequencePropertySheetDisplayerTable:onErase(instance)
-
- local activeLogicEntity = r2:getSelectedInstance()
- local activeLogicEntityParent = instance.Parent.Parent.Parent
-
- if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
- return
- end
-
- local chatsUI = getUI("ui:interface:r2ed_chat_sequence")
- assert(chatsUI)
-
- local sequenceTabs = chatsUI:find("sequence_tabs")
- assert(sequenceTabs)
-
- local sequIndex
- for i=0,sequenceTabs.tabButtonNb-1 do
- local sequence = sequenceTabs:getGroup(i)
- if sequence.Env.sequenceId == instance.InstanceId then
- sequIndex = i
- break
- end
- end
-
- if sequIndex~=nil then
- r2:removeChatsSequenceUI(sequIndex)
- end
-
- r2:updateMiniActivityView()
-end
-------------------------------------------------
-function chatSequencePropertySheetDisplayerTable:onPreHrcMove(instance)
-end
-------------------------------------------------
-function chatSequencePropertySheetDisplayerTable:onPostHrcMove(instance)
-end
-------------------------------------------------
-function chatSequencePropertySheetDisplayerTable:onFocus(instance, hasFocus)
-end
-
-------------------------------------------------
-function chatSequencePropertySheetDisplayerTable:onSelect(instance, isSelected)
-end
-
-------------------------------------------------
-function chatSequencePropertySheetDisplayerTable:onAttrModified(instance, attributeName)
-
- local activeLogicEntity = r2:getSelectedInstance()
- local activeLogicEntityParent = instance.Parent.Parent.Parent
-
- if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
- return
- end
-
- if attributeName == "Name" then
- r2:updateSequenceName("r2ed_chat_sequence", instance)
- elseif attributeName == "Repeating" then
- r2:updateSequenceRepeatingOption("r2ed_chat_sequence", instance)
- end
-end
-
-------------------------------------------------
-function r2:chatSequencePropertySheetDisplayer()
- return chatSequencePropertySheetDisplayerTable -- returned shared displayer to avoid wasting memory
-end
-
-
---------------------------------------------------------------------------------------------------
--------------------------------- ACTIVITY STEP DisplayerProperties--------------------------------
---------------------------------------------------------------------------------------------------
-local activityStepPropertySheetDisplayerTable = clone(r2:propertySheetDisplayer())
-
-------------------------------------------------
-function activityStepPropertySheetDisplayerTable:onPostCreate(instance)
-
- local activeLogicEntity = r2:getSelectedInstance()
- local activeLogicEntityParent = instance.Parent.Parent.Parent.Parent.Parent
-
- if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
- return
- end
-
- local activitySequInst = instance.Parent.Parent
-
- local triggersUI = getUI("ui:interface:r2ed_triggers")
- assert(triggersUI)
-
- local sequenceTabs = triggersUI:find("sequence_tabs")
- assert(sequenceTabs)
-
- local sequenceUI
- for i=0,sequenceTabs.tabButtonNb-1 do
- local sequence = sequenceTabs:getGroup(i)
- if sequence.Env.sequenceId == activitySequInst.InstanceId then
- sequenceUI = sequence
- break
- end
- end
-
- r2:newActivity(false, nil, instance, sequenceUI)
-end
-------------------------------------------------
-function activityStepPropertySheetDisplayerTable:onErase(instance)
-
- local activeLogicEntity = r2:getSelectedInstance()
- local activeLogicEntityParent = instance.Parent.Parent.Parent.Parent.Parent
-
- if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
- return
- end
-
- local sequenceUI, elementUI = r2:findSequenceAndElementUIFromInstance(instance, "r2ed_triggers")
-
- if elementUI ~= nil then
- r2:removeActivityUI(sequenceUI, elementUI)
- end
-end
-------------------------------------------------
-function activityStepPropertySheetDisplayerTable:onPreHrcMove(instance)
-end
-------------------------------------------------
-function activityStepPropertySheetDisplayerTable:onPostHrcMove(instance)
-
- local activeLogicEntity = r2:getSelectedInstance()
- local activeLogicEntityParent = instance.Parent.Parent.Parent.Parent.Parent
-
- if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
- return
- end
-
- local sequenceUI, activityStepUI = r2:findSequenceAndElementUIFromInstance(instance, "r2ed_triggers")
- if activityStepUI then
- r2:downUpElement(activityStepUI, "r2ed_triggers")
- end
-end
-------------------------------------------------
-function activityStepPropertySheetDisplayerTable:onFocus(instance, hasFocus)
-end
-
-------------------------------------------------
-function activityStepPropertySheetDisplayerTable:onSelect(instance, isSelected)
-end
-
-------------------------------------------------
-function activityStepPropertySheetDisplayerTable:onAttrModified(instance, attributeName)
-
- local activeLogicEntity = r2:getSelectedInstance()
- local activeLogicEntityParent = instance.Parent.Parent.Parent.Parent.Parent
-
- if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
- return
- end
-
- local sequenceUI, elementUI = r2:findSequenceAndElementUIFromInstance(instance, "r2ed_triggers")
- if elementUI then
- r2:updateActivityChatSequence(elementUI)
- end
-end
-
-------------------------------------------------
-function activityStepPropertySheetDisplayerTable:onTargetInstanceEraseRequested(instance, refIdName, refIdIndexInArray)
-
- if refIdName == "ActivityZoneId" then
- r2.requestSetNode(instance.InstanceId, "Activity", "Stand Still")
- r2.requestSetNode(instance.InstanceId, "ActivityZoneId", r2.RefId(""))
- r2.requestSetNode(instance.InstanceId, "TimeLimit", "No Limit")
- r2.requestSetNode(instance.InstanceId, "TimeLimitValue", "")
- elseif refIdName == "Chat" then
- r2.requestSetNode(instance.InstanceId, "Chat", r2.RefId(""))
- end
-end
-------------------------------------------------
-function activityStepPropertySheetDisplayerTable:onTargetInstanceAttrModified(instance, refIdName, refIdIndexInArray, targetAttrName, targetAttrIndexInArray)
-end
-
--------------------------------------------------
-function r2:activityStepPropertySheetDisplayer()
- return activityStepPropertySheetDisplayerTable -- returned shared displayer to avoid wasting memory
-end
-
-
-
---------------------------------------------------------------------------------------------------
--------------------------------- CHAT STEP DisplayerProperties------------------------------------
---------------------------------------------------------------------------------------------------
-local chatStepPropertySheetDisplayerTable = clone(r2:propertySheetDisplayer())
-
-------------------------------------------------
-function chatStepPropertySheetDisplayerTable:onPostCreate(instance)
-
- local activeLogicEntity = r2:getSelectedInstance()
- local activeLogicEntityParent = instance.Parent.Parent.Parent.Parent.Parent
-
- if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
- return
- end
-
- local chatSequInst = instance.Parent.Parent
-
- local chatsUI = getUI("ui:interface:r2ed_chat_sequence")
- assert(chatsUI)
-
- local sequenceTabs = chatsUI:find("sequence_tabs")
- assert(sequenceTabs)
-
- local sequenceUI
- for i=0,sequenceTabs.tabButtonNb-1 do
- local sequence = sequenceTabs:getGroup(i)
- if sequence.Env.sequenceId == chatSequInst.InstanceId then
- sequenceUI = sequence
- break
- end
- end
-
- r2:newChat(false, instance, sequenceUI)
-end
-------------------------------------------------
-function chatStepPropertySheetDisplayerTable:onErase(instance)
-
- local activeLogicEntity = r2:getSelectedInstance()
- local activeLogicEntityParent = instance.Parent.Parent.Parent.Parent.Parent
-
- if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
- return
- end
-
- local sequenceUI, elementUI = r2:findSequenceAndElementUIFromInstance(instance, "r2ed_chat_sequence")
-
- if elementUI ~= nil then
- local chatStepInst = r2:getInstanceFromId(elementUI.Env.elementId)
- assert(chatStepInst)
- r2:updateActivitiesWhithThisChatSequence(chatStepInst, true)
- r2:removeElementUI(sequenceUI, "r2ed_chat_sequence", elementUI)
- end
-end
-------------------------------------------------
-function chatStepPropertySheetDisplayerTable:onPreHrcMove(instance)
-end
-------------------------------------------------
-function chatStepPropertySheetDisplayerTable:onPostHrcMove(instance)
-
- local activeLogicEntity = r2:getSelectedInstance()
- local activeLogicEntityParent = instance.Parent.Parent.Parent.Parent.Parent
-
- if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
- return
- end
-
- r2:updateActivitiesWhithThisChatSequence(instance, false)
-
- local sequenceUI, chatStepUI = r2:findSequenceAndElementUIFromInstance(instance, "r2ed_chat_sequence")
- if chatStepUI then
- r2:downUpElement(chatStepUI, "r2ed_chat_sequence")
- end
-end
-------------------------------------------------
-function chatStepPropertySheetDisplayerTable:onFocus(instance, hasFocus)
-end
-
-------------------------------------------------
-function chatStepPropertySheetDisplayerTable:onSelect(instance, isSelected)
-end
-
-------------------------------------------------
-function chatStepPropertySheetDisplayerTable:onAttrModified(instance, attributeName)
-
- local activeLogicEntity = r2:getSelectedInstance()
- local activeLogicEntityParent = instance.Parent.Parent.Parent.Parent.Parent
-
- if not r2.activitiesAndChatsUIUpdate or activeLogicEntity==nil or activeLogicEntity ~= activeLogicEntityParent then
- return
- end
-
- local sequenceUI, chatStepUI = r2:findSequenceAndElementUIFromInstance(instance, "r2ed_chat_sequence")
- if chatStepUI then
- r2:updateChatText(chatStepUI)
- end
-end
-
-function r2:findSequenceAndElementUIFromInstance(instance, uiName)
-
- local sequenceInst = instance.Parent.Parent
-
- local wndUI = getUI("ui:interface:"..uiName)
- assert(wndUI)
-
- local sequenceTabs = wndUI:find("sequence_tabs")
- assert(sequenceTabs)
-
- local sequenceUI
- for i=0,sequenceTabs.tabButtonNb-1 do
- local sequence = sequenceTabs:getGroup(i)
- if sequence.Env.sequenceId == sequenceInst.InstanceId then
- sequenceUI = sequence
- break
- end
- end
-
- if sequenceUI ~= nil then
- local eltsList = sequenceUI:find("elements_list")
- assert(eltsList)
-
- for i=0,eltsList.childrenNb-1 do
- local element = eltsList:getChild(i)
- if element.Env.elementId == instance.InstanceId then
- return sequenceUI, element
- end
- end
- end
-end
-
---------------------------------------------------
-function r2:chatStepPropertySheetDisplayer()
- return chatStepPropertySheetDisplayerTable -- returned shared displayer to avoid wasting memory
-end
-
-
-
---------------------------------------------------------------------------------------------------
--------------------------------- CHAT ACTION DisplayerProperties -----------------------
---------------------------------------------------------------------------------------------------
-local chatActionPropertySheetDisplayerTable = clone(r2:propertySheetDisplayer())
-
-------------------------------------------------
-function chatActionPropertySheetDisplayerTable:onPostCreate(instance)
-end
-------------------------------------------------
-function chatActionPropertySheetDisplayerTable:onErase(instance)
-end
-------------------------------------------------
-function chatActionPropertySheetDisplayerTable:onPreHrcMove(instance)
-end
-------------------------------------------------
-function chatActionPropertySheetDisplayerTable:onPostHrcMove(instance)
-end
-------------------------------------------------
-function chatActionPropertySheetDisplayerTable:onFocus(instance, hasFocus)
-end
-
-------------------------------------------------
-function chatActionPropertySheetDisplayerTable:onSelect(instance, isSelected)
-end
-
-------------------------------------------------
-function chatActionPropertySheetDisplayerTable:onAttrModified(instance, attributeName)
-end
-
-------------------------------------------------
-function chatActionPropertySheetDisplayerTable:onTargetInstanceEraseRequested(instance, refIdName, refIdIndexInArray)
- if refIdName == "Who" then
- r2.requestSetNode(instance.InstanceId, "Who", r2.RefId(""))
- r2.requestSetNode(instance.InstanceId, "Says", "")
- r2.requestSetNode(instance.InstanceId, "Emote", "")
- r2.requestSetNode(instance.InstanceId, "Facing", r2.RefId(""))
- elseif refIdName == "Facing" then
- r2.requestSetNode(instance.InstanceId, "Facing", r2.RefId(""))
- end
-end
-------------------------------------------------
-function chatActionPropertySheetDisplayerTable:onTargetInstanceAttrModified(instance, refIdName, refIdIndexInArray, targetAttrName, targetAttrIndexInArray)
-end
-
-------------------------------------------------
-function r2:chatActionPropertySheetDisplayer()
- return chatActionPropertySheetDisplayerTable -- returned shared displayer to avoid wasting memory
-end
-
-
-
-
-
-
-
-
-
-
-
-r2.lastSelectedActivitySequence = nil
-
-r2.activityTexture = { ["Follow Route"] = "r2_mini_activity_follow_road.tga",
- ["Patrol"] = "r2_mini_activity_patrol_road.tga",
- ["Repeat Road"] = "r2_mini_activity_repeat_road.tga",
- ["Wander"] = "r2_mini_activity_wander_zone.tga",
- ["Stand Still"] = "r2_mini_activity_stand_still.tga",
--- ["Inactive"] = "r2_mini_activity_inactive.tga"
- }
-
----------------------------------------------------------------------------------------------------------
--- Show the mini activity view for this instance
-function r2:setupMiniActivityView(instance)
- if instance and instance:isKindOf("ActiveLogicEntity") then
- local selectedTab = 0
- if r2.lastSelectedActivitySequence then
- selectedTab = r2.lastSelectedActivitySequence
- end
- r2:selectActivitiesSequence(selectedTab)
- r2:updateSequencesButtonBar(selectedTab)
- end
-end
-
------------------- SELECT ACTIVITY SEQUENCE ---------------------------------------------------------
-function r2:selectActivitiesSequence(index)
- r2:selectElementsSequence("r2ed_triggers", index)
- r2:openAndUpdateMiniActivityView(index)
-end
-
------------------- UPDATE SEQUENCES BUTTON BAR ---------------------------------------------------------
-function r2:updateSequencesButtonBar(index, sequenceName)
-
- local selectBar = getUI("ui:interface:r2ed_select_bar")
- assert(selectBar)
-
- local sequencesButton = selectBar:find("sequences")
- assert(sequencesButton)
-
- local activeLogicEntity = r2:getSelectedInstance()
- if activeLogicEntity then
- if sequenceName==nil and (index >=0) and (index < activeLogicEntity:getBehavior().Activities.Size) then
- local activitySequence = activeLogicEntity:getBehavior().Activities[index]
- assert(activitySequence)
- --sequencesButton.uc_hardtext = activitySequence.Name
- sequencesButton.uc_hardtext = r2:getSequenceName(activitySequence)
- elseif sequenceName~= nil then
- sequencesButton.uc_hardtext = sequenceName
- else
- sequencesButton.uc_hardtext = i18n.get("uiR2EDSequences")
- end
- end
-end
-
-
-function r2:newMiniActivitySequence()
- return r2:newActivitiesSequence(true)
-end
-
-function r2:openAndUpdateMiniActivityView(index)
- r2:openMiniActivityView()
- -- update activities list
-
- r2:updateMiniActivityView(index)
-end
-
-function r2:openMiniActivityView()
- local triggersUI = getUI("ui:interface:r2ed_triggers")
- assert(triggersUI)
-
- local selectedInst = r2:getSelectedInstance()
-
- if selectedInst and not selectedInst:isBotObject() and not selectedInst:isPlant() and not triggersUI.active then
- local miniActivityView = getUI("ui:interface:r2ed_mini_activity_view")
- assert(miniActivityView)
- miniActivityView.active = true
- end
-end
-
-
-function r2:updateMiniActivityView(index)
-
- local miniActivityView = getUI("ui:interface:r2ed_mini_activity_view")
- assert(miniActivityView)
-
- local miniActivities = miniActivityView:find("mini_activities")
- assert(miniActivities)
-
- local noActivityLabel = miniActivityView:find("no_activity")
- assert(noActivityLabel)
-
- local startCount = 0
- local sequence
- if index~=nil then
- local activities = r2:getSelectedInstance():getBehavior().Activities
- if index < activities.Size then
- sequence = activities[index]
- end
- else
- sequence = r2:getSelectedSequInst("r2ed_triggers")
- end
-
- if sequence~=nil then
-
- --label "No activity"
- if sequence.Components.Size == 0 then
- noActivityLabel.active = true
- noActivityLabel.uc_hardtext = tostring(i18n.get("uiR2EdNoActivity"))
- else
- noActivityLabel.active = false
- end
-
- for i=0, sequence.Components.Size-1 do
-
- local activityInst = sequence.Components[i]
- assert(activityInst)
-
- if activityInst then
-
- local activityIndex = i
- if afterEltEditor==true then activityIndex = i-1 end
-
- local miniActivity = miniActivities[tostring(activityIndex)]
- assert(miniActivity)
-
- miniActivity.active = true
- miniActivity.Env.id = activityIndex
-
- -- chat button
- local chatButton = miniActivity:find("chat_sequence"):find("button")
- assert(chatButton)
- if tostring(activityInst.Chat) ~= "" then
- local chatTexture = "r2_mini_activity_chat.tga"
- chatButton.texture = chatTexture
- chatButton.texture_pushed = chatTexture
- chatButton.texture_over = chatTexture
- else
- local chatTexture = "r2_mini_activity_empty_chat.tga"
- chatButton.texture = chatTexture
- chatButton.texture_pushed = chatTexture
- chatButton.texture_over = chatTexture
- end
-
- -- activity type button
- local activityButton = miniActivity:find("activity"):find("button")
- assert(activityButton)
- local activityTexture = r2.activityTexture[activityInst.Activity]
- if activityTexture then
- activityButton.texture = activityTexture
- activityButton.texture_pushed = activityTexture
- activityButton.texture_over = activityTexture
- end
-
- -- activity type text
- local activityText = miniActivity:find("activity_name")
- assert(activityText)
- activityText.uc_hardtext = activityInst.Activity
- end
- end
- startCount = sequence.Components.Size
- else
- noActivityLabel.active = true
- noActivityLabel.uc_hardtext = tostring(i18n.get("uiR2EdNoSequence"))
- end
-
- -- hide remaining mini activity templates
- for i=startCount, r2.maxActivities-1 do
- local miniActivity = miniActivities[tostring(i)]
- assert(miniActivity)
- miniActivity.active = false
- end
-end
-
-
-function r2:closeMiniActivityView()
- local miniActivityView = getUI("ui:interface:r2ed_mini_activity_view")
- assert(miniActivityView)
- miniActivityView.active = false
-end
-
-function r2:openActivitiesSequence()
-
- r2:updateActivitiesAndChatsUI(r2:getSelectedInstance())
-
- local triggersUI = getUI("ui:interface:r2ed_triggers")
- assert(triggersUI)
-
- triggersUI.active = true
- triggersUI:updateCoords()
-
- if triggersUI.Env.openFirst == nil then
- triggersUI:center()
- triggersUI.Env.openFirst = true
- end
-
- r2:closeMiniActivityView()
-end
-
-
-function r2:chooseOrOpenSelectedChatSequence()
-
- r2:updateActivitiesAndChatsUI(r2:getSelectedInstance())
-
- -- init menu
- local menuName = "ui:interface:r2ed_chat_sequences_menu"
- launchContextMenuInGame(menuName)
- local menu = getUI(menuName)
-
- local rootMenu = menu:getRootMenu()
- assert(rootMenu)
- rootMenu:reset()
-
- -- update menu
- local miniActivity = getUICaller().parent.parent.parent
- assert(miniActivity)
-
- local miniActivityNb = tonumber(miniActivity.Env.id)
- local activitySequence = r2:getSelectedSequInst("r2ed_triggers")
- assert(activitySequence)
- local activityInst = activitySequence.Components[miniActivityNb]
-
- local chatSequenceId = tostring(activityInst.Chat)
-
- local newLine = 3
- --title "Chat sequence"
- local chatSequence
- if chatSequenceId ~= "" then
- chatSequence = r2:getInstanceFromId(chatSequenceId)
- assert(chatSequence)
- --rootMenu:addLine(ucstring(tostring(i18n.get("uiR2EDChatSequence")).." " .. chatSequence.Name .." : "), "lua", "", "Title")
- rootMenu:addLine(ucstring(tostring(i18n.get("uiR2EDChatSequence")).." " .. r2:getSequenceName(chatSequence) .." : "), "lua", "", "Title")
- else
- rootMenu:addLine(ucstring(tostring(i18n.get("uiR2EDChatSequence")).." : "), "lua", "", "Title")
- end
-
- rootMenu:addSeparator()
-
- -- "Open chat sequence"
- if chatSequenceId ~= "" then
- --rootMenu:addLine(ucstring(tostring(i18n.get("uiR2EDOpen")).." "..chatSequence.Name), "lua", "r2:openMiniActivityChatSequence("..tostring(miniActivityNb)..")", "Open")
- rootMenu:addLine(ucstring(tostring(i18n.get("uiR2EDOpen")).." "..r2:getSequenceName(chatSequence)), "lua", "r2:openMiniActivityChatSequence("..tostring(miniActivityNb)..")", "Open")
- newLine = newLine + 1
- end
-
- -- "Any chat sequence"
- rootMenu:addLine(ucstring(i18n.get("uiR2EdNoChat")), "lua", "r2:setSequenceChatToMiniActivity("..tostring(miniActivityNb)..")", "None")
-
-
- -- "new chat sequence"
- rootMenu:addLine(ucstring(tostring(i18n.get("uiR2EdNewChat")).."..."), "lua", "r2:newChatsSequenceAndSelect("..tostring(miniActivityNb)..")", "None")
- local menuButton = createGroupInstance("r2_menu_button", "", { bitmap = "r2_icon_create.tga", size="14" })
- rootMenu:setUserGroupLeft(newLine, menuButton)
-
- rootMenu:addSeparator()
-
- local activeLogicEntity = r2:getSelectedInstance()
- assert(activeLogicEntity)
-
- for i=0, activeLogicEntity:getBehavior().ChatSequences.Size-1 do
- local sequence = activeLogicEntity:getBehavior().ChatSequences[i]
- assert(sequence)
-
- --rootMenu:addLine(ucstring(sequence.Name), "lua", "r2:setSequenceChatToMiniActivity("..tostring(miniActivityNb)..", " .. tostring(i)..")", sequence.InstanceId)
- rootMenu:addLine(ucstring(r2:getSequenceName(sequence)), "lua", "r2:setSequenceChatToMiniActivity("..tostring(miniActivityNb)..", " .. tostring(i)..")", sequence.InstanceId)
- end
-
- -- display menu
- menu:updateCoords()
- local ref = getUICaller()
- menu.y = ref.y_real - (menu.h - ref.h_real)
- menu.x = ref.x_real
- menu:updateCoords()
-end
-
-function r2:openMiniActivityChatSequence(miniActivityNb, chatSequenceId)
-
- local activitySequence = r2:getSelectedSequInst("r2ed_triggers")
- assert(activitySequence)
- local activityInst = activitySequence.Components[miniActivityNb]
-
- if chatSequenceId == nil then
- chatSequenceId = tostring(activityInst.Chat)
- end
-
- r2:openChatSequence(chatSequenceId)
-end
-
-function r2:openChatSequence(chatSequenceId)
-
- if chatSequenceId == nil then
- chatSequenceId = r2:getSelectedEltInst("r2ed_triggers").Chat
- end
-
- local chatSequences = getUI("ui:interface:r2ed_chat_sequence")
- assert(chatSequences)
-
- local tab = chatSequences:find("sequence_tabs")
- assert(tab)
-
- local selectedTab
- local sequenceUI
- for i=0, tab.tabButtonNb-1 do
- sequence = tab:getGroup(i)
- assert(sequence)
- if sequence.Env.sequenceId == chatSequenceId then
- sequenceUI = sequence
- selectedTab = i
- break
- end
- end
-
- if selectedTab then
- tab.selection = selectedTab
-
- local repeatButton = chatSequences:find("repeat_group"):find("repeat"):find("toggle_butt")
- assert(repeatButton)
-
- local sequenceInstId = sequenceUI.Env.sequenceId
- local sequenceInst = r2:getInstanceFromId(sequenceInstId)
-
- repeatButton.pushed = (sequenceInst.Repeating == 0)
- end
-
- r2:openChatSequences()
-end
-
-function r2:newChatsSequenceAndSelect(miniActivityNb)
- local chatSequenceId = r2:newChatsSequence(true)
-
- if chatSequenceName ~= -1 then
- r2:setSequenceChatToMiniActivity(miniActivityNb, -1, chatSequenceId)
- r2:openMiniActivityChatSequence(miniActivityNb, chatSequenceId)
- end
-end
-
-function r2:setSequenceChatToMiniActivity(miniActivityNb, sequenceNb, chatSequenceId)
-
- local miniActivityView = getUI("ui:interface:r2ed_mini_activity_view")
- assert(miniActivityView)
-
- local miniActivities = miniActivityView:find("mini_activities")
- assert(miniActivities)
-
- local miniActivity = miniActivities[tostring(miniActivityNb)]
- assert(miniActivity)
-
- local activitySequence = r2:getSelectedSequInst("r2ed_triggers")
- assert(activitySequence)
- local activityInst = activitySequence.Components[miniActivityNb]
-
- local chatTexture
-
- if sequenceNb == nil then
- r2:selectChatSequence("None", activityInst.InstanceId)
- chatTexture = "r2_mini_activity_empty_chat.tga"
- else
- local activeLogicEntity = r2:getSelectedInstance()
- assert(activeLogicEntity)
-
- if chatSequenceId == nil then
- local chatSequence = activeLogicEntity:getBehavior().ChatSequences[tonumber(sequenceNb)]
- assert(chatSequence)
- chatSequenceId = chatSequence.InstanceId
- end
-
- r2:selectChatSequence(chatSequenceId, activityInst.InstanceId)
-
- chatTexture = "r2_mini_activity_chat.tga"
- end
-
- local chatButton = miniActivity:find("chat_sequence"):find("button")
- assert(chatButton)
- chatButton.texture = chatTexture
- chatButton.texture_pushed = chatTexture
- chatButton.texture_over = chatTexture
-end
-
-function r2:openActivity()
-
- r2:updateActivitiesAndChatsUI(r2:getSelectedInstance())
-
- local miniActivity = getUICaller().parent.parent.parent
- assert(miniActivity)
-
- local sequenceUI = r2:getSelectedSequ("r2ed_triggers")
- assert(sequenceUI)
-
- local activityList = sequenceUI:find("elements_list")
- assert(activityList)
-
- local eltEditor = activityList:find("edit_element")
- assert(eltEditor)
- local indexEltEditor = activityList:getElementIndex(eltEditor)
-
- local activityIndex = miniActivity.Env.id
- if indexEltEditor<=activityIndex then activityIndex=activityIndex+1 end
-
- local activityUI = activityList:getChild(activityIndex)
- assert(activityUI)
-
- local selectedButtonElt = activityUI:find("select")
- assert(selectedButtonElt)
-
- selectedButtonElt.pushed = true
- r2:selectTriggerElement(nil, "r2ed_triggers", selectedButtonElt)
-
- r2:updateActivityEditor()
- r2:openActivitiesSequence()
-end
-
-function r2:selectSequenceTab(uiName, index)
-
- if uiName == "r2ed_triggers" then
- r2:updateSequencesButtonBar(index)
- end
-
- local eltsUI = getUI("ui:interface:"..uiName)
- assert(eltsUI)
-
- local sequencesTab = eltsUI:find("sequence_tabs")
- assert(sequencesTab)
-
- local repeatButton = eltsUI:find("repeat_group"):find("repeat"):find("toggle_butt")
- assert(repeatButton)
-
- local sequenceUI = sequencesTab:getGroup(index)
- assert(sequenceUI)
- local sequenceInstId = sequenceUI.Env.sequenceId
-
- if sequenceInstId and r2:getInstanceFromId(sequenceInstId) then
- local sequenceInst = r2:getInstanceFromId(sequenceInstId)
- repeatButton.pushed = (sequenceInst.Repeating == 0)
- end
-end
-
-
-
-function r2:getSequenceName(sequenceInst)
-
- local name = sequenceInst.Name
- local index = -1
- if name == "" then
- local components = sequenceInst.Parent
- for i=0, components.Size-1 do
- if components[i].InstanceId == sequenceInst.InstanceId then
- index = i
- break
- end
- end
-
- if index >= 0 then
- local startName
- if sequenceInst:isKindOf("ChatSequence") then
- startName = tostring(i18n.get("uiR2EdSequChat"))
- elseif sequenceInst:isKindOf("ActivitySequence") then
- startName = tostring(i18n.get("uiR2EdSeq"))
- end
-
- name = startName..(index+1)
- end
- end
-
- return name
-end
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/code/ryzom/common/data_common/r2/r2_ui_windows.lua b/code/ryzom/common/data_common/r2/r2_ui_windows.lua
deleted file mode 100644
index 02e2b7893..000000000
--- a/code/ryzom/common/data_common/r2/r2_ui_windows.lua
+++ /dev/null
@@ -1,118 +0,0 @@
--- management of visible editor windows
-
----------------
--- FUNCTIONS --
----------------
-
--------------------------------------------------------------------------------------
--- refresh the button that allow to toggle a window on / off
-function r2:refreshWindowButtons()
- -- debugInfo("refreshWindowButtons")
-end
-
-
--------------------------------------------------------------------------------------
-function r2:switchWindow(name)
- local wnd = getUI(name)
- wnd.active = not wnd.active
-end
-
--------------------------------------------------------------------------------------
--- misc windows activation deactivation
-function r2:switchPaletteWindow()
- self:switchWindow("ui:interface:r2ed_palette")
-end
-
-function r2:switchScenarioWindow()
- self:switchWindow("ui:interface:r2ed_scenario")
-end
-
-function r2:switchDebugWindow()
- self:switchWindow("ui:interface:debug_info")
-end
-
-function r2:switchChatWindow()
- self:switchWindow("ui:interface:main_chat")
-end
-
-function r2:switchWebAdminWindow()
- self:switchWindow("ui:interface:r2ed_ring_window")
-end
-
-function r2:switchMailBoxWindow()
- self:switchWindow("ui:interface:mailbox")
-end
-
-function r2:switchGuildForumWindow()
- self:switchWindow("ui:interface:guild_forum")
-end
-
-function r2:switchMapWindow()
- self:switchWindow("ui:interface:map")
-end
-
-function r2:switchPlayerAdminWindow()
- self:switchWindow("ui:interface:ring_chars_tracking")
-end
-
-function r2:switchCustomBBoxWindow()
- self:switchWindow("ui:interface:r2ed_bbox_edit")
- if r2.CustomBBox.FirstDisplay == true then
- if r2.CustomBBox:getWindow().active then
- r2.CustomBBox:getWindow():center()
- end
- r2.CustomBBox.FirstDisplay = false
- end
- if r2.CustomBBox:getWindow().active then
- runCommand("showR2EntityBoxes")
- else
- runCommand("hideR2EntityBoxes")
- end
-end
-
-
-function r2:isPropertyWindowVisible()
- if r2.PropertyWindowVisible == true then
- if r2.CurrentPropertyWindow ~= nil then
- return true
- end
- end
- return false
-end
-
-function r2:switchPropertiesWindow()
- if r2:isPropertyWindowVisible() then
- if r2.CurrentPropertyWindow ~= nil then
- r2.CurrentPropertyWindow.active = false
- end
- r2.PropertyWindowVisible = false
- else
- r2:showProperties(r2:getSelectedInstance())
- end
-end
-
-------------------
--- STATIC DATAS --
-------------------
-
-r2.PropertyWindowVisible = false -- not stored in window because there are several "properties" windows (one per class)
-r2.CurrentPropertyWindow = nil -- current property window being displayed
-
-
------------------------------------------
--- INIT OF WINDOW POSITIONS AT STARTUP --
------------------------------------------
-
-
--- init default pos for a property window
-function r2:initDefaultPropertyWindowPosition(wnd)
- if wnd == nil then
- return
- end
- scrW, scrH = getWindowSize()
- wnd.x = 4
- wnd.y = scrH - 312
- wnd.w = 225
- wnd.h = 300
-end
-
diff --git a/code/ryzom/common/data_common/r2/r2_utils.lua b/code/ryzom/common/data_common/r2/r2_utils.lua
deleted file mode 100644
index 0c25ba64c..000000000
--- a/code/ryzom/common/data_common/r2/r2_utils.lua
+++ /dev/null
@@ -1,500 +0,0 @@
-if r2.Utils == nil
-then
- r2.Utils={}
-end
-
-
-r2.Utils.addReaction = function(this,event,action)
- local reactions = this.Reactions[event]
- if reactions == nil
- then
- reactions = {}
- this.Reactions[event]=reactions
- end
- table.insert(reactions,action)
-end
-
-------------------------------------------------------
---Create the states and groups to represent:
--- -A counter mission
--- -The counters used for this mission
-r2.Utils._obsolete_initCounterStates = function(counter,context)
-
- if counter.Class =="Counter"
- then
-
- local pGroup = r2.createPseudoGroup(context)
- context.RtCounters[counter.InstanceId]=pGroup
-
- for k,v in pairs(counter.Counters)
- do
- Translator.LogicEntityTranslator(v,context)
- end
- end
-end
-
-
-r2.Utils.createGroup = function(x,y,n,base,name,mode)
-
- if mode == nil
- then
- mode = "circle"
- end
-
- local isGeneric = false
-
- if string.find(base, "palette.entities.players.") ~= nil then
- isGeneric = true
- end
-
-
- local npcGroup = r2.newComponent("NpcGrpFeature")
- assert(npcGroup)
- npcGroup.Name = name
-
- if mode == "circle"
- then
-
- local pas = (2 * math.pi)/n
- local r = (n/(2*math.pi))+2
- for i=1,n do
- local npc = nil
- if ( isGeneric == true) then
- npc = r2.newComponent("NpcCustom")
- else
- npc = r2.newComponent("Npc")
- end
-
- npc.Name = name.."_".."Npc"..i
- npc.Base = base
- npc.Position.x = x + (r-1) * math.cos((i-1)*pas)
- npc.Position.y = y + (r-1) * math.sin((i-1)*pas)
- npc.Position.z = r2:snapZToGround(npc.Position.x, npc.Position.y)
- npc.Angle = (i-1)*pas + math.pi
- table.insert(npcGroup.Components,npc)
- end
- end
- if mode == "line"
- then
- local pas = 1
- for i=1,n do
- local npc = r2.newComponent("Npc")
- npc.Name = name.."_".."Npc"..i
- npc.Base = base
- npc.Position.x = x + i * pas
- npc.Position.y = y
- npc.Position.z = r2:snapZToGround(npc.Position.x, npc.Position.y)
- npc.Angle = 0
- table.insert(npcGroup.Components,npc)
- end
- end
- return npcGroup
-end
-
---region = region to fill
---x,y = region's center
---r = region's ray
---nbPoints = number of points to create the region
-r2.Utils.createRegion = function(region,x, y, r,nbPoints)
- region.Points = {}
- local tmpPositions = region.Points
- local pas = (2 * math.pi)/nbPoints
- local Angle = 0
- while nbPoints ~= 0
- do
- local tmpVertex = r2.newComponent("RegionVertex")
- local tmpPosition = r2.newComponent("Position")
- local sx, sy, sz
- sx = x + r * math.cos(Angle)
- sy = y + r * math.sin(Angle)
- sx, sy, sz = r2:snapPosToGround(sx, sy)
- tmpPosition.x = sx
- tmpPosition.y = sy
- tmpPosition.z = sz
- tmpVertex.Position = tmpPosition
- table.insert(tmpPositions, tmpVertex)
- Angle = Angle + pas
- nbPoints = nbPoints - 1
- end
-end
-
---region = region to fill
---x,y = region's center
---r = region's ray
---nbPoints = number of points to create the region
-r2.Utils.createNonDeleteableRegion = function(region,x, y, r,nbPoints)
- region.Deletable = 0
- region.Points = {}
- local tmpPositions = region.Points
- local pas = (2 * math.pi)/nbPoints
- local Angle = 0
- while nbPoints ~= 0
- do
- local tmpVertex = r2.newComponent("RegionVertex")
- tmpVertex.Deletable = 0
- local tmpPosition = r2.newComponent("Position")
- local sx, sy, sz
- sx = x + r * math.cos(Angle)
- sy = y + r * math.sin(Angle)
- sx, sy, sz = r2:snapPosToGround(sx, sy)
- tmpPosition.x = sx
- tmpPosition.y = sy
- tmpPosition.z = sz
- tmpVertex.Position = tmpPosition
- table.insert(tmpPositions, tmpVertex)
- Angle = Angle + pas
- nbPoints = nbPoints - 1
- end
-end
-
---region = trigger Zone
---x,y = region's center
---r = region's ray
---nbPoints = number of points to create the region
-r2.Utils.createTriggerRegion = function(region,x, y, r)
- return r2.Utils.createNonDeleteableRegion(region, x, y, r, 4)
-end
-
-
-
--- Create a Road
--- ex local road = createRoad("rout1", { {21570, -1363}, {21570, -1363}, {21570, -1363})
-r2.Utils.createRoute = function(name, positions)
- local road = r2.newComponent("Road")
- local function wp(x, y, z)
- local wayPoint = r2.newComponent("WayPoint")
- local pos = r2.newComponent("Position")
- pos.x = x
- pos.y = y
- pos.z = z
- wayPoint.Position = pos
- return wayPoint
- end
-
--- road.Base = "palette.geom.road"
- road.Name = name
- local tmpPositions = road.Points -- depart a arrivée
-
- for index, points in pairs(positions)
- do
- table.insert(tmpPositions, wp(points[1], points[2], 0))
- end
-
- return road
-end
-
-
---function to set an RtAiState with a npc's behavior
-r2.Utils.setState = function(context,behavior,rtAiState)
- local aiMovement = behavior.Type
- rtAiState.Name = rtAiState.Id .. "|" .. aiMovement
- rtAiState.AiMovement = aiMovement
- if (aiMovement == "wander" or aiMovement == "follow_route" or aiMovement == "patrol_route" or aiMovement == "repeat_road") then
- local id = behavior.ZoneId
- local zone = context.Components[id]
- assert( zone ~= nil)
- local points=zone.Points
- assert( points ~= nil)
- local size = table.getn(points)
- rtAiState.Pts = {}
- local k,v = next(points, nil)
- local i = 0
- while k ~= nil
- do
- if (k ~= "Keys")
- then
- -- replacement for getworldPos
- assert(v ~= nil)
- i = i +1
- rtAiState.Pts[i] = {}
- -- ??? v.Position.x ??
- rtAiState.Pts[i].x = r2.getWorldPos(v).x
- rtAiState.Pts[i].y = r2.getWorldPos(v).y
- rtAiState.Pts[i].z = r2.getWorldPos(v).z
- end
- k,v = next(points, k)
- end
- -- do reverse
- if (aiMovement == "patrol_route") then
- i = 0
- for i = 1, size -1 , 1
- do
- local first = size - i
- local last = size + i
-
- rtAiState.Pts[last] = {}
- rtAiState.Pts[last].x = rtAiState.Pts[first].x
- rtAiState.Pts[last].y = rtAiState.Pts[first].y
- rtAiState.Pts[last].z = rtAiState.Pts[first].z
- end
- end
- if (aiMovement == "patrol_route" or aiMovement == "repeat_road") then
- rtAiState.AiMovement = "follow_route"
- local eventHandler = Actions.createEvent("destination_reached", rtAiState.Id ,"")
- assert( eventHandler ~= nil)
- local eName = rtAiState.Id .. ":destination_reached"
- eventHandler.Name=eName
- table.insert(context.RtAct.Events,eventHandler)
-
- local action = Actions.createAction("begin_state", rtAiState.Id)
- action.Name="begin state " .. rtAiState.Id
- table.insert(context.RtAct.Actions,action)
- table.insert(eventHandler.ActionsId,action.Id)
- end
- end
-end
-
-
-r2.Utils.invertRoad = function(road)
- local road2 = r2.newComponent("Road")
- local function wp(x, y, z)
- local wayPoint = r2.newComponent("WayPoint")
- local pos = r2.newComponent("Position")
- pos.x = x
- pos.y = y
- pos.z = z
- wayPoint.Position = pos
- return wayPoint
- end
- local max = table.getn(road.Points)
-
- for i=1,max do
- local point = road.Points[max-i+1].Position
- table.insert(road2.Points,wp(point.x,point.y,point.z))
- end
- return road2
-end
-
-
-r2.Utils.createEntry = function(who,states,event,actions)
- local entry = r2.newComponent("EventHandlerEntry")
- entry.Who = who
- entry.States = states
- entry.Event = event
- entry.Actions = actions
- return entry
-end
-
-r2.Utils.createPlace = function(x,y,z,r)
- local place = r2.newComponent("Place")
- place.Position.x=x
- place.Position.y=y
- place.Position.z=z
- place.Radius = r
- return place
-end
-
-r2.Utils.searchEntry = function(activity,who,event,state)
- local max = table.getn(activity.Entries)
- for i=1, max do
- local entry = activity.Entries[i]
- if entry.Who==who and entry.Event == event and (entry.States == state or state=="")
- then
- return entry
- end
- end
- return nil
-end
-
-r2.Utils.groupActivities = function(activity1,activity2,event1,state1,event2,state2)
- local entry
- entry = r2.Utils.searchEntry(activity1,activity1.Entries[1].Who,event1,state1)
-
- if entry == nil
- then
- entry = r2.Utils.createEntry(activity1.Entries[1].Who,state1,event1,"begin_state\n"..state2)
- table.insert(activity1.Entries,entry)
- else
- entry.Actions = entry.Actions .. "\nbegin_state\n"..state2
- end
-
- entry = r2.Utils.searchEntry(activity2,activity2.Entries[1].Who,event2,state2)
- if entry == nil
- then
- entry = r2.Utils.createEntry(activity2.Entries[1].Who,state2,event2,"begin_state\n"..state1)
- table.insert(activity2.Entries,entry)
- else
- entry.Actions = entry.Actions .. "\nbegin_state\n"..state
- end
-end
-
-r2.Utils.evalCost = function(feature)
- --luaObject(feature)
- local components = feature.Components
- --luaObject(components)
- local cost = 0
- if components ~= nil
- then
- for key,comp in pairs(components)
- do
- if key~="Keys" and comp.Class == "Npc"
- then
- cost = cost + 1
- end
- end
- end
- return cost
-end
-
-r2.Utils.createChatAction = function(who,says,emote,face)
- local chatStep
-
- chatStep = r2.newComponent("ChatAction")
- chatStep.Who = who
-
- if says ~= ""
- then
- local entry=r2.registerText(says)
- chatStep.Says = entry.InstanceId
- else
- chatStep.Says = says
- end
-
- if face ~="" and face ~=nil
- then
- chatStep.Facing = face
- end
-
- chatStep.Emote = emote
- return chatStep
-end
-
-
-
---replace each instanceId in the table by the new one
-r2.Utils.replaceTab = function(this,ttable)
-for k,v in pairs(this)
-do
- if k ~="Keys"
- then
- this[k]=ttable[this[k]]
- end
-end
-end
---call the replace function for each object in the table
-r2.Utils.callReplace = function(this,ttable)
-for k,v in pairs(this)
-do
- if k ~="Keys"
- then
- v:replace(ttable)
- end
-end
-end
-
-
-r2.Utils.changeRepere = function(position,center)
- position.x=position.x - center.x
- position.y=position.y - center.y
- position.z = r2:snapZToGround(position.x,position.y)
-end
-
-r2.Utils.changeZoneRepere = function(zone,center)
- for i=1,table.getn(zone.Points)
- do
- r2.Utils.changeRepere(zone.Points[i])
- end
-end
-
-r2.Utils.changeRepereRt = function(npc,center)
- local x,y
- local position = npc.Position
- x = position.x - center.x
- y = position.y - center.y
- r2.requestSetNode(position.InstanceId,"x",x)
- r2.requestSetNode(position.InstanceId,"y",y)
- r2.requestSetNode(position.InstanceId,"z",r2:snapZToGround(x,y))
-end
-
-r2.Utils.setNewGroupCenter = function(group,x,y)
- local k,v = next(group.Components,nil)
- local center = r2.newComponent("Position")
- local first = true
- center.x = x
- center.y = y
-
- while k~=nil
- do
- if first == true
- then
- first = false
- local newCenter = {}
- newCenter.x = -(center.x - v.Position.x)
- newCenter.y = -(center.y - v.Position.y)
- center.z = r2:snapZToGround(center.x,center.y)
- r2.requestSetNode(v.Position.InstanceId,"x",center.x)
- r2.requestSetNode(v.Position.InstanceId,"y",center.y)
- r2.requestSetNode(v.Position.InstanceId,"z",r2:snapZToGround(center.x,center.y))
- center = newCenter
- else
- r2.Utils.changeRepereRt(v,center)
- end
- k,v = next(group.Components,k)
- end
-
-end
-
--- Obsolete
-r2.Utils.getRtGroup = function(context,instanceId)
- debugInfo("Call obsolete function: call r2.Translator.getRtGroup")
- -- use r2.Translator.getRtGroup instead
- return r2.Translator.getRtGroup(context, instanceId)
-end
-
-r2.Utils.concat = function(text,textSup)
- if text == ""
- then
- return textSup
- else
- return text.."\n"..textSup
- end
-end
-
-
------------------------------------------------------------
---return a string like: "group1:Npc1" for use with actions
-r2.Utils.getNpcParam = function(npcId, context)
-
- assert( type(npcId) == "string")
- local who = r2:getInstanceFromId(tostring(npcId))
--- local group = who:getParentGroup()
- local rtNpcGrp = context.RtGroups[tostring(npcId)]
- if rtNpcGrp == nil
- then
- debugInfo("Err: unable to know the npc's group name ("..npcId..")")
- return nil
- end
-
- return rtNpcGrp.Name..":"..tostring(who.Name)
-end
-
-
---
--- Returns the RtNpcGrp Id for a given instanceId
---
-r2.Utils.getRtIdFromInstanceId = function(context, instanceId)
- assert(instanceId ~= nil and type(instanceId) == "string")
- local instance = r2:getInstanceFromId(instanceId)
- assert(instance)
- return context.RtGroups[instanceId].Id
-end
-
-
--- vianney tests
-function r2.testVianney1()
- r2.requestStartAct(1)
-end
-
-function r2.testVianney2()
- r2.requestStartAct(2)
-end
-
-function r2.testVianney3()
- r2.requestStopAct()
-end
-
-function r2:lowerTranslate(uiR2EdStr)
- return string.lower(i18n.get(uiR2EdStr):toUtf8())
-end
-
-
diff --git a/code/ryzom/common/data_common/r2/r2_version.lua b/code/ryzom/common/data_common/r2/r2_version.lua
deleted file mode 100644
index 17e709df8..000000000
--- a/code/ryzom/common/data_common/r2/r2_version.lua
+++ /dev/null
@@ -1,496 +0,0 @@
-
-r2.Version = {}
-
-local version = r2.Version
-
-
-function r2.Version.checkVersion(scenarioVersionList, currentVersionList)
- local undef = {}
- local older = {}
- local newer = {}
- local ok = true
-
- local k,v = next(scenarioVersionList, nil)
- while k do
- if (v ~= currentVersionList[k]) then
- ok = false
- if currentVersionList[k] == nil then
- table.insert(undef, k)
- elseif v < currentVersionList[k] then
- table.insert(older, k)
- else
- table.insert(newer, k)
- end
- end
- k,v = next(scenarioVersionList, k)
- end
- return ok, undef, older, newer
-
-end
-
-function r2.Version.getUndefComponent(scenarioVersionList, currentVersionList)
- local undef = {}
- local k,v = next(scenarioVersionList, nil)
- while k do
- if (v ~= currentVersionList[k] and currentVersionList[k] == nil ) then
- table.insert(undef, k)
- end
- k,v = next(scenarioVersionList, k)
- end
- return true
-
-end
-
-local levelToString =
-{
- [0] = "20",
- [1] = "50",
- [2] = "100",
- [3] = "150",
- [4] = "200",
- [5] = "250"
-}
-
-function r2.Version.save(filename)
-
- local scenario = r2.Scenario
-
- if scenario then
- local scenarioList = r2.Version.getCurrentVersionList()
- local update = false
-
- local k,v = next(scenarioList, nil)
- while k do
- if (r2.Scenario.Versions[k] ~= v) then update = true end
- k,v = next(scenarioList, k)
- end
-
- k,v = next(r2.Scenario.Versions, nil)
- while k do
- if (scenarioList[k] ~= v) then update = true end
- k,v = next(r2.Scenario.Versions, k)
- end
-
- if update then
- r2.requestSetGhostNode(scenario.InstanceId, "Versions", scenarioList)
- end
- local accessList = {}
-
-
- local ok, level, err = r2.RingAccess.verifyScenario()
- if not r2.RingAccess.LoadAnimation and not r2.getIsAnimationSession() then
- r2.updateScenarioAck(ok, level, err.What)
- end
- accessList = r2.RingAccess.getAccessListAsString(level)
-
-
- local values = {}
-
-
-
- local date = os.date()
-
- local firstLocationName = ""
- local shortDescription = ""
- local title = ""
- local name = ""
- local userName = r2:getUserEntityName()
- local modifierMD5 = r2.getCharIdMd5()
- local creatorName = ""
- local rules = ""
- local level = ""
- local language = ""
- local type = ""
- local creatorMD5 =""
- local createUserName = userName
- local createDate = date
- local otherCharAccess = "Full"
- local nevraxScenario = "0"
- local trialAllowed = "0"
- local scenarioTag = ""
-
-
- if r2.Scenario and r2.Scenario.Locations
- and table.getn(r2.Scenario.Locations) > 0 and r2.Scenario.Locations[0].IslandName then
- firstLocationName = r2.Scenario.Locations[0].IslandName
- end
-
- if r2.Scenario and r2.Scenario.Description then
- --shortDescription =string.gsub(r2.Scenario.Description.ShortDescription, "\n", "\\n")
- shortDescription = r2.Scenario.Description.ShortDescription
- level = string.gsub(r2.Scenario.Description.LevelId, "\n", "\\n")
- level = levelToString[tonumber(level)]
- rules = string.gsub(r2.Scenario.AccessRules, "\n", "\\n")
- if rules=="liberal" then
- rules=i18n.get("uiR2EDliberal"):toUtf8()
- elseif rules == "strict" then
- rules=i18n.get("uiR2EDstrict"):toUtf8()
- end
- title = string.gsub(r2.Scenario.Description.Title, "\n", "\\n")
- language = r2.Scenario.Language
- type = r2.Scenario.Type
- name = r2.Scenario.Name
- if r2.Scenario.Ghost_Name then
- name = r2.Scenario.Ghost_Name
- end
- if r2.Scenario.Description.Creator then
- createUserName = r2.Scenario.Description.Creator
- end
- if r2.Scenario.Description.CreatorMD5 then
- creatorMD5 = r2.Scenario.Description.CreatorMD5
- end
- if r2.Scenario.Description.CreationDate then
- createDate = r2.Scenario.Description.CreationDate
- end
- if table.getn(r2.Scenario.Locations) > 0 then
- initialIslandLocation = r2.Scenario.Locations[0].IslandName
- initialEntryPoint = r2.Scenario.Locations[0].EntryPoint
- initialSeason = r2.Scenario.Locations[0].Season
- end
-
- if r2.Scenario.Description.OtherCharAccess then
- otherCharAccess = r2.Scenario.Description.OtherCharAccess
- if otherCharAccess == "RoSOnly" then
- if config.R2EDExtendedDebug ~= 1 then
- if filename == "data/r2_buffer.dat" then
- return false
- else
- r2.onSystemMessageReceived("BC_ML", "", "uiR2EDErrorRefuseToSaveRoS")
- r2.requestNewAction(i18n.get("uiR2EDUpdatingScenarioToDefaultAccess"))
- r2.requestSetNode(r2.Scenario.Description.InstanceId, "OtherCharAccess", "Full")
- r2.requestEndAction()
- return false
- end
- else
- r2.onSystemMessageReceived("BC_ML", "", "Updating the system of Trial limitation")
- r2.requestNewAction(i18n.get("uiR2EDUpdatingScenarioAccess"))
- r2.requestSetNode(r2.Scenario.Description.InstanceId, "OtherCharAccess", "Full")
- r2.requestSetNode(r2.Scenario.Description.InstanceId, "NevraxScenario", "1")
- r2.requestSetNode(r2.Scenario.Description.InstanceId, "TrialAllowed", "1")
- r2.requestSetNode(r2.Scenario.Description.InstanceId, "ScenarioTag", "")
- r2.requestEndAction()
- return false
- end
-
-
- end
- end
-
- if r2.Scenario.Description.NevraxScenario == tostring(1) then
- nevraxScenario = r2.Scenario.Description.NevraxScenario
- trialAllowed = r2.Scenario.Description.TrialAllowed
- scenarioTag = r2.Scenario.Description.ScenarioTag
- userName = "Ring(Nevrax)"
- createUserName = userName
-
- if config.R2EDExtendedDebug ~= 1 then
-
- if filename == "data/r2_buffer.dat" then
- return false
- else
- r2.onSystemMessageReceived("BC_ML", "", "uiR2EDErrorRefuseToSaveRoS")
- r2.requestNewAction(i18n.get("uiR2EDUpdatingScenarioAccess"))
- r2.requestSetNode(r2.Scenario.Description.InstanceId, "NevraxScenario", "0")
- r2.requestSetNode(r2.Scenario.Description.InstanceId, "TrialAllowed", "0")
- r2.requestSetNode(r2.Scenario.Description.InstanceId, "ScenarioTag", "")
- r2.requestEndAction()
-
- return false
- end
-
-
- end
- end
-
- end
-
- table.insert(values, {Title = title})
- table.insert(values, {Name = name})
- table.insert(values, {ShortDescription = shortDescription})
- table.insert(values, {FirstLocation = firstLocationName})
- table.insert(values, {RingPointLevel = accessList})
- table.insert(values, {CreateBy = createUserName})
- table.insert(values, {CreatorMD5 = creatorMD5})
- table.insert(values, {CreationDate = createDate})
- table.insert(values, {ModifiedBy = userName})
- table.insert(values, {ModifierMD5 = modifierMD5})
- table.insert(values, {OtherCharAccess = otherCharAccess})
-
- table.insert(values, {ModificationDate = date})
- table.insert(values, {Rules = rules})
- table.insert(values, {Level = level})
- table.insert(values, {Type = type})
- table.insert(values, {Language = language})
- table.insert(values, {InitialIsland = initialIslandLocation})
- table.insert(values, {InitialEntryPoint = initialEntryPoint})
- table.insert(values, {InitialSeason = initialSeason})
- if nevraxScenario == tostring(1) then
- table.insert(values, {NevraxScenario = nevraxScenario})
- table.insert(values, {TrialAllowed = trialAllowed})
- table.insert(values, {ScenarioTag = scenarioTag})
- end
-
-
- r2.save(filename, values)
- end
- return true
-end
-
-
-local function updateVersionImpl(nodeList, scenarioVersionList, currentVersionFullList)
- assert(nodeList)
- assert(scenarioVersionList)
- assert(currentVersionFullList)
-
- local k,v = next(nodeList, nil)
- while k do
-
-
- -- go up in the class hierarchy, calling each redefinition of 'onUpdate' function
- -- when a version change is detected
- local currClassName = v.Class
-
- -- look at a update function for this component or one of it's ancester
- while currClassName ~= "" and currClassName ~= nil do
- local currClass = r2.Classes[currClassName]
- if not currClass then
- debugInfo(colorTag(255, 0, 0) .. "Error can not update your scenario: the component"..currClassName.." seems to be obsolete")
- return false
- end
- local scenarioVersionNode = defaulting(scenarioVersionList[currClassName], 0)
- local currentVersionNode = defaulting(currentVersionFullList[currClassName], 0)
- if currentVersionNode ~= scenarioVersionNode then
- --
- if scenarioVersionNode == nil then
- debugInfo(colorTag(0, 255 ,255) .. "The component (".. v.Class .. ") does not exist anymore")
- return false
- elseif currentVersionNode == nil then
- debugInfo(colorTag(0, 255 ,255) .. "The component (".. v.Class .. ") does not exist anymore")
- return false
- else
- debugInfo(colorTag(0, 255 ,255) .. "Updating the component " .. v.InstanceId .. "(".. v.Class .. "/"..currClassName..") from ".. scenarioVersionNode .. " to " .. currentVersionNode ..".")
-
- local updateFunc = currClass.updateVersion
- if not updateFunc then
- debugInfo( "Your scenario can not be updated. Because the component " .. v.Class .. " can not be updated (no update Function?).\n")
- return false
- end
- local ok1, ok2 = pcall(updateFunc, v, scenarioVersionNode, currentVersionNode)
- if not ok1 or not ok2 then
- debugInfo( "Your scenario can not be updated. Because the component " .. v.Class .. " can not be updated.\n")
- if not ok1 then
- debugInfo(ok2)
- end
- return false
- end
-
- end
- end
- currClassName = currClass.BaseClass
- end
-
- k,v = next(nodeList, k)
- end
- return true
-
-end
-
-function r2.Version.updateVersion()
- if r2.Translator == nil then
- debugInfo("Syntax error")
- return false
- end
- local scenarioInstance = r2.Scenario
-
- if not scenarioInstance then return true end
-
- local currentVersionFullList = r2.Version.getCurrentVersionFullList()
- local scenarioVersionList = r2.Version.getScenarioVersionList()
-
- local versionOk, undef, older, newer = r2.Version.checkVersion(scenarioVersionList, currentVersionFullList)
-
- local modified = false
- if not versionOk then
-
- debugInfo(colorTag(0,255,25).."Begin Update")
-
- local scenarioVersionName = scenarioInstance.VersionName
- local currentVersionName = r2.Classes["Scenario"].VersionName
-
- if scenarioVersionName == nil then scenarioVersionName = "0.0.0" end
- if currentVersionName == nil then currentVersionName = "0.0.0" end
-
- local str = "Updating the scenario from '"..scenarioVersionName.."' to '".. currentVersionName .."'.\nThe obsolete scenario will be saved in 'old_scenario.r2'"
- printMsg(str)
- local nodeList = r2.Version.getScenarioNodes(scenarioInstance)
- assert(nodeList)
-
- do
- local k,v = next(undef, nil)
- while k do
- debugInfo(colorTag(0, 255 ,255) .. "The component ".. v .. " used in this scenario does not exist.")
- k,v = next(undef, k)
- end
- end
-
- do
- local k,v = next(older, nil)
- while k do
- debugInfo(colorTag(0, 255 ,255) .. "The component ".. v .. " is too old (we will try to update it)")
- k,v = next(older, k)
- end
- end
-
- do
- local k,v = next(newer, nil)
- while k do
- debugInfo(colorTag(0, 255 ,255) .. "The component ".. v .. " is too new (maybe wrong version?)")
- k,v = next(newer, k)
- end
- end
- if table.getn(undef) > 0 then
- debugInfo(colorTag(255, 0, 0) .. "Error can not update your scenario: the scenario containse components that are not defined")
- return true
- end
- local oldState = scenarioInstance.Ghost
- scenarioInstance.Ghost = false
- r2.save("old_scenario.r2")
- scenarioInstance = r2.Scenario
-
- scenarioInstance.Ghost = true
-
- local syntaxOk, ok = pcall(updateVersionImpl, nodeList, scenarioVersionList, currentVersionFullList)
- if not syntaxOk then
- r2.print(ok)
- ok = false
- end
- if ok then
- -- ok
- debugInfo(colorTag(0,255,25).."Update succced")
- local currentVersionList = r2.Version.getCurrentVersionList()
- r2.requestSetNode(scenarioInstance.InstanceId, "VersionName", currentVersionName)
- r2.requestSetNode(scenarioInstance.InstanceId, "Versions", currentVersionList)
- scenarioInstance.Ghost = oldState
- r2.requestUploadCurrentScenario()
- r2.clearActionHistoric() -- undo invalidated after a version update !!
- modified = true
- else
- debugInfo(colorTag(255, 0, 0) .. "Errors occurs while updateing your scenario")
-
- end
- scenarioInstance.Ghost = oldState
- debugInfo(colorTag(0,255,25).."End Update")
-
- end
- return not modified;
-end
-
-
-
-
--- return Scenario Nodes - leaf first
-function r2.Version.getScenarioNodes(node, nodeListParam)
- assert(node)
- if nodeListParam then nodeList = nodeListParam else nodeList = {} end
-
- if not r2.isTable(node) then return nodeList end
- local k,v = next(node, nil)
- while k do
- r2.Version.getScenarioNodes(v, nodeList)
- k,v = next(node, k)
- end
- if node.InstanceId then
- table.insert(nodeList, node)
- if not node.Class then assert(nil) end
- end
- return nodeList
-end
-
-
--- get the Current Version of sceanrio
-function r2.Version.getCurrentVersionList()
- local scenarionInstance = r2.Scenario
- local versionList = {}
- r2.Version._getCurrentVersionListImpl(scenarionInstance, versionList)
- return versionList;
-end
-
-function r2.Version.getCurrentVersionFullList()
- local versionList = {}
- local classes = r2.Classes
- local k, v = next(classes, nil)
- while k do
- if v.Version then
- versionList[k] = v.Version
- else
- versionList[k] = 0
- end
- k, v = next(classes, k)
- end
- return versionList
-end
-
-function r2.Version._getCurrentVersionListImpl(node, versionList)
- if ( type (node) == "string" or type(node) == "number") then return end
- local k,v = next(node, nil)
- if node.Class and not versionList[node.Class] then
- if r2.Classes[node.Class] and r2.Classes[node.Class].Version then
- versionList[node.Class] = r2.Classes[node.Class].Version
- else
- versionList[node.Class] = 0
- end
- end
- while k do
- r2.Version._getCurrentVersionListImpl(v, versionList);
- k,v = next(node, k)
- end
-end
-
-
-function r2.Version.getScenarioVersionList(scenarioNode)
- local scenario = scenarioNode
- if not scenario then scenario = r2.Scenario end
- assert(scenario)
- local versions = scenario.Versions
- local versionList = {}
- if versions == nil then
- return r2.Version._getScenarioVersionListImpl(scenario, versionList)
- else
- local k,v = next(versions, nil)
- while k do
- versionList[k] = v
- k,v = next(versions, k)
- end
- end
- return versionList
-
-end
-
-function r2.Version._getScenarioVersionListImpl(node, versionList)
- if ( type (node) == "string" or type(node) == "number") then return end
- local k,v = next(node, nil)
- if node.Class and not versionList[node.Class] then
- versionList[node.Class] = 0
- end
- while k do
- r2.Version._getScenarioVersionListImpl(v, versionList);
- k,v = next(node, k)
- end
- return versionList
-end
-
--- Version 0.0.0 -> prior to 7 dec 2005
-
--- version 0.0.1 prior to 7 dec 2005
--- Act.Version = 1
--- Act.ManualWeather
--- Act.WeatherValue
-
--- version 0.0.2 19 dec 2005
--- Act.Version = 2
--- Act.Behavior (Because Act changes type from BaseType to LogicAction
---
--- version 0.0.3 1 janv 2006
--- ActivityStep.Version=1
--- "Inactive" -> "Stand Still"
-
diff --git a/code/ryzom/common/data_common/r2/r2_world_object.lua b/code/ryzom/common/data_common/r2/r2_world_object.lua
deleted file mode 100644
index 5a5720fa7..000000000
--- a/code/ryzom/common/data_common/r2/r2_world_object.lua
+++ /dev/null
@@ -1,214 +0,0 @@
------------------------------------------------------------
--- Base class for objects that have a position in world --
------------------------------------------------------------
-
-local worldObject =
-{
- BaseClass = "BaseClass",
- Name="WorldObject",
- Version = 1, -- Version 1 : removed the 'DisplayMode' field
- Prop =
- {
- {Name="Position", Type="Position"},
- {Name="InheritPos", Type="Number", DefaultValue="1", Visible=false},
- -- DisplayMode : can have one of the following values :
- -- 0, Visible -> the object is visible, this is the default
- -- 1, Hidden -> the object is not visible (not in scene / not in the minimap)
- -- 2, Frozen -> the object can't be selected, but is visible
- -- 3, Locked -> the object can be selected, but not moved/rotated
-
- --
-
- --{Name="DisplayMode",
- -- Type="Number",
- -- DefaultValue="0",
- -- Visible=function(instance) return instance:isDisplayModeOptionAvailable() end,
- -- WidgetStyle="EnumDropDown",
- -- Enum={ "uiR2EDDisplayModeVisible", "uiR2EDDisplayModeHidden", "uiR2EDDisplayFrozen", "uiR2EDDisplayLocked" }
- -- }
- }
-}
-
-
-------------------------------------------------------------------
-function worldObject.updateVersion(this, scenarioValue, currentValue)
- local patchValue = scenarioValue
- if patchValue < 1 then
- -- display mode removed in version 1
- if this.DisplayMode then
- r2.requestEraseNode(this.InstanceId, "DisplayMode", -1)
- end
- patchValue = 1
- end
- if patchValue == currentValue then return true end
- return false
-end
-
-------------------------------------------------------------------
--- When this function returns 'true', the user is given the choice to change the display mode of the object
--- false by default
-function worldObject.canChangeDisplayMode(this)
- return false
-end
-
-------------------------------------------------------------------
--- get world position as a table { x = , y = , z = }
-function worldObject.getWorldPos(this)
- if this.InheritPos ~= 0 and this.ParentInstance then
- local parentPos = this.ParentInstance:getWorldPos()
- assert(parentPos and parentPos.x and parentPos.y and parentPos.z)
- return { x = this.Position.x + parentPos.x,
- y = this.Position.y + parentPos.y,
- z = this.Position.z + parentPos.z }
- end
- return { x = this.Position.x,
- y = this.Position.y,
- z = this.Position.z }
-end
-
-
-
--- tmp fix for translation to primitives
-function r2.getWorldPos(table)
- local instance = r2:getInstanceFromId(table.InstanceId)
- if instance == nil then
- dumpCallStack(1)
- debugInfo("getInstanceFromId de "..table.InstanceId .." renvoie NIL")
- inspect(r2:getCurrentAct())
- assert(false)
- end
- local result = instance:getWorldPos()
- return result
-end
-
-------------------------------------------------------------------
--- Make this object position relative to another position
--- & send appropriate network msg
--- If the object doesn't herit pos from parent, then its position remains unchanged
--- (example of use : grouping & ungrouping)
-function worldObject.requestMakePosRelativeTo(this, parent)
- if not this.InheritPos then return end
- --debugInfo('requestMakePosRelativeTo')
- --debugInfo(colorTag(255, 0, 255) .. 'old local pos = ')
- --luaObject(this.Position)
- --debugInfo(colorTag(255, 0, 255) .. 'old world pos = ')
- --luaObject(this:getWorldPos())
- assert(parent)
- local worldPos = this:getWorldPos()
- if parent.getWorldPos == nil then
- debugInfo(debug.traceback())
- inspect(parent)
- assert(nil)
- end
- local parentWorldPos = parent:getWorldPos()
- local newLocalPos = clone(this.Position)
- newLocalPos.x = worldPos.x - parentWorldPos.x
- newLocalPos.y = worldPos.y - parentWorldPos.y
- newLocalPos.z = worldPos.z - parentWorldPos.z
- --debugInfo(colorTag(255, 0, 255) .. 'parent world pos = ')
- --luaObject(parentWorldPos)
- --debugInfo(colorTag(255, 0, 255) .. 'new local pos = ')
- --luaObject(newLocalPos)
- if this.Position:equals(newLocalPos) then
- return -- same new pos, no need to send msg
- end
- r2.requestSetNode(newLocalPos.InstanceId, "", newLocalPos)
-end
-
-------------------------------------------------------------------
--- redefine base class copy : ensure that position is expressed in world coordinates after the copy
-function worldObject.copy(this)
- local result = r2.Classes.BaseClass.copy(this)
- local worldPos = this:getWorldPos()
- result.Position.x = worldPos.x
- result.Position.y = worldPos.y
- result.Position.z = worldPos.z
- return result
-end
-
-------------------------------------------------------------------
--- Test if display mode can currenlty be changed by the user (maybe not the case if inherited by parent)
-function worldObject.isDisplayModeOptionAvailable(this)
- if not this:canChangeDisplayMode() then return false end
- -- if inherited from parent and parent not visible then don't give any option
- local classDesc= this:getClass()
- if classDesc.DisplayerVisualParams and classDesc.DisplayerVisualParams.InheritDisplayMode then
- if this.ParentInstance and this.ParentInstance:isKindOf("WorldObject") and this.ParentInstance.DisplayerVisual.DisplayMode ~= 0 then
- return false
- end
- end
- return true
-end
-
-------------------------------------------------------------------
--- test if the given display mode toggle is supported for this entity
--- 0, -> always supported (can be visible ...)
--- 1, -> can this object be hidden ?
--- 2, -> can this object be frozen ?
--- 3, -> can this object be locked ?
-function worldObject.isDisplayModeToggleSupported(this, displayMode)
- return false
-end
-
-------------------------------------------------------------------
--- If this entity has option to change its display mode, add them
-function worldObject.getAvailableDisplayModeCommands(this, dest)
- if not this:isDisplayModeOptionAvailable() then return end
- if this.DisplayerVisual.DisplayMode == 0 then
- if this:isDisplayModeToggleSupported(1) then
- table.insert(dest, this:buildCommand(this.onSetDisplayModeHide, "hide", "uiR2EDDisplayModeHide", "r2ed_toolbar_hide.tga", true))
- end
- if this:isDisplayModeToggleSupported(2) then
- table.insert(dest, this:buildCommand(this.onSetDisplayModeFreeze, "freeze", "uiR2EDDisplayModeFreeze", "r2ed_toolbar_freeze.tga", false))
- end
- if this:isDisplayModeToggleSupported(3) then
- table.insert(dest, this:buildCommand(this.onSetDisplayModeLock, "lock", "uiR2EDDisplayModeLock", "r2ed_toolbar_lock.tga", false))
- end
- elseif this.DisplayerVisual.DisplayMode == 1 then
- if this:isDisplayModeToggleSupported(1) then
- table.insert(dest, this:buildCommand(this.onSetDisplayModeShow, "show", "uiR2EDDisplayModeShow", "r2ed_toolbar_show.tga", true))
- end
- elseif this.DisplayerVisual.DisplayMode == 2 then
- if this:isDisplayModeToggleSupported(2) then
- table.insert(dest, this:buildCommand(this.onSetDisplayModeShow, "unfreeze", "uiR2EDDisplayModeUnfreeze", "r2ed_toolbar_unfreeze.tga", false))
- end
- elseif this.DisplayerVisual.DisplayMode == 3 then
- if this:isDisplayModeToggleSupported(3) then
- table.insert(dest, this:buildCommand(this.onSetDisplayModeShow, "unlock", "uiR2EDDisplayModeUnlock", "r2ed_toolbar_unlock.tga", false))
- end
- end
-end
-
-------------------------------------------------------------------
--- display modes
-function worldObject.onSetDisplayModeShow(this)
- --r2.requestNewAction(i18n.get("uiR2EDChangeDisplayAction"))
- --r2.requestSetNode(this.InstanceId, "DisplayMode", 0)
- this.DisplayerVisual.DisplayMode = 0
- r2.ContextualCommands:update()
-end
-function worldObject.onSetDisplayModeHide(this)
- --r2.requestNewAction(i18n.get("uiR2EDChangeDisplayAction"))
- --r2.requestSetNode(this.InstanceId, "DisplayMode", 1)
- this.DisplayerVisual.DisplayMode = 1
- r2.ContextualCommands:update()
-end
-function worldObject.onSetDisplayModeFreeze(this)
- --r2.requestNewAction(i18n.get("uiR2EDChangeDisplayAction"))
- --r2.requestSetNode(this.InstanceId, "DisplayMode", 2)
- this.DisplayerVisual.DisplayMode = 2
- r2.ContextualCommands:update()
-end
-function worldObject.onSetDisplayModeLock(this)
- --r2.requestNewAction(i18n.get("uiR2EDChangeDisplayAction"))
- --r2.requestSetNode(this.InstanceId, "DisplayMode", 3)
- this.DisplayerVisual.DisplayMode = 3
- r2.ContextualCommands:update()
-end
-
-
-
-r2.registerComponent(worldObject)
-
-
-
diff --git a/code/ryzom/common/data_common/r2/unit_test/r2_client1.lua b/code/ryzom/common/data_common/r2/unit_test/r2_client1.lua
deleted file mode 100644
index 0efd768be..000000000
--- a/code/ryzom/common/data_common/r2/unit_test/r2_client1.lua
+++ /dev/null
@@ -1,4 +0,0 @@
-r2.doFile("r2_unit_test.lua")
-UnitTest.testCreateScenario()
-r2.show()
-
diff --git a/code/ryzom/common/data_common/r2/unit_test/r2_client2.lua b/code/ryzom/common/data_common/r2/unit_test/r2_client2.lua
deleted file mode 100644
index 4d3159c30..000000000
--- a/code/ryzom/common/data_common/r2/unit_test/r2_client2.lua
+++ /dev/null
@@ -1,6 +0,0 @@
-doFile("lua/unit_test/unit_test.lua")
-UnitTest.testAddDefaultFeature()
-UnitTest.testAddNpcGrpFeature()
-UnitTest.testAddFaunaFeature()
-r2.translateFeatures()
-r2.show()
diff --git a/code/ryzom/common/data_common/r2/unit_test/r2_client3.lua b/code/ryzom/common/data_common/r2/unit_test/r2_client3.lua
deleted file mode 100644
index 7eb1881b9..000000000
--- a/code/ryzom/common/data_common/r2/unit_test/r2_client3.lua
+++ /dev/null
@@ -1,5 +0,0 @@
-doFile("lua/unit_test/unit_test.lua")
-UnitTest.testAddFaunaFeature()
-UnitTest.testUpdateScenario()
-UnitTest.testTranslateFeatures()
-
diff --git a/code/ryzom/common/data_common/r2/unit_test/r2_unit_test.lua b/code/ryzom/common/data_common/r2/unit_test/r2_unit_test.lua
deleted file mode 100644
index b48e3da5a..000000000
--- a/code/ryzom/common/data_common/r2/unit_test/r2_unit_test.lua
+++ /dev/null
@@ -1,1509 +0,0 @@
---BaseY = -32594
-BaseX = 21570
-BaseY = -1363
-
-UnitTest = {}
-
-
-UnitTest.testAddSecondaryActUi = function()
- function Form_onOk(form)
- local act =r2.newComponent("Act")
- local features = act.Features
- local tmpDefault = r2.newComponent("DefaultFeature")
- table.insert(features, tmpDefault)
- r2.requestInsertNode(r2.ScenarioInstanceId, "Acts", -1, "", act)
- end
-
- function Form_onCancel(form)
-
- end
- r2:doForm("CreateNewAdventureActDescription", {}, Form_onOk, Form_onCancel)
-end
-
-
-UnitTest.testLoadAnimationScenarioUi = function()
-
- local function onOk(form)
- if (form.LoadScenario_Name ~= nil and type(form.LoadScenario_Name) == "string") then
- if form.LoadScenario_Name == "" then
- local ui = r2:getForm("LoadScenario")
- ui.active = true
- ui.Env.Choice = nil
- r2.CurrentForm = ui
-
- messageBox(i18n.get("uiR2EDInvalidName"))
- return
- end
-
- local filename = form.LoadScenario_Name
- if string.find(filename, '.r2', -3) == nil then
-
- local ui = r2:getForm("LoadScenario")
- ui.active = true
- ui.Env.Choice = nil
- r2.CurrentForm = ui
-
- messageBox(i18n.get("uiR2EDInvalidName"))
- return
- end
- filename = form.Path .. filename
-
-
-
- local header = r2.getFileHeader(filename)
- local mainland = not header or header.NevraxScenario ~= "1" or header.TrialAllowed ~= "1"
- local trial = isPlayerFreeTrial()
- if mainland and getDbProp("SERVER:USER:IS_NEWBIE") == 1 and trial then
- local ui = r2:getForm("LoadScenario")
- ui.active = true
- ui.Env.Choice = nil
- r2.CurrentForm = ui
- r2.onSystemMessageReceived("ERR", "", "uiRingLoadingNotARoSScenario")
- return
- end
-
-
- local ok, errStr = r2.RingAccess.loadAnimation(filename)
- if not ok then
- local ui = r2:getForm("LoadScenario")
- ui.active = true
- ui.Env.Choice = nil
- r2.CurrentForm = ui
-
- messageBox(i18n.get("uiR2EDInvalidScenario"))
-
- end
-
- end
- end
-
- local function onCancel(data, form)
- local ui = r2:getForm("LoadScenario")
- ui.active = true
- ui.Env.Choice = nil
- r2.CurrentForm = ui
-
- end
-
- local str = r2:getStartingAnimationFilename();
- local ok, errStr = r2.RingAccess.loadAnimation(str)
-
- if ok and string.len(str) ~= 0 then
- local header = r2.getFileHeader(str)
- local mainland = not header or header.NevraxScenario ~= "1" or header.TrialAllowed ~= "1"
- local newbie = getDbProp("SERVER:USER:IS_NEWBIE") == 1
- if mainland and isPlayerFreeTrial() and newbie then
- r2.onSystemMessageReceived("ERR", "", "uiRingLoadingNotARoSScenario")
- ok = false
- end
- end
-
- if not ok then
- r2:doForm("LoadScenario", {}, onOk, onCancel)
- if string.len(str) ~= 0 then
- messageBox(errStr)
- end
-
- end
-
-end
-
-
-UnitTest.testWaitAnimationScenarioLoadingUi = function()
-
--- local ui = getUI("ui:interface:r2ed_animation_waiting")
--- ui.active = true
---- setTopWindow(ui)
-
-end
-
-
-UnitTest.testLoadScenarioUi = function()
-
- local function onCancel(data, form)
- end
-
- local function onOk(form)
-
- if (form.LoadScenario_Name ~= nil and type(form.LoadScenario_Name) == "string") then
- if form.LoadScenario_Name == "" then
- messageBox(i18n.get("uiR2EDLoadScenario_InvalidFileName"))
- return
- end
-
- local ucName = ucstring()
- ucName:fromUtf8(form.LoadScenario_Name)
- local filename = tostring(ucName)
- if string.find(filename, '.r2', -3) == nil then
- messageBox(i18n.get("uiR2EDLoadScenario_InvalidFileName"))
- return
- end
-
--- if string.find(filename, '.r2', -3) == nil then
--- filename = form.Name .. ".r2"
--- end
-
- local path = form.Path
- local extendedFileName = filename
- if path and path ~= "" then
- extendedFileName = path..filename
- end
-
- if form.LoadScenario_Level == ""
- and form.LoadScenario_Rules == ""
- and config.R2EDExtendedDebug == 1 then
- messageBox(i18n.get("uiR2EDLoadScenario_LoadScenarioWithoutHeader"))
- elseif form.RingAccess and form.RingAccess == 0 then
- local ui = r2:getForm("LoadScenario")
- ui.active = true
- r2.CurrentForm = ui
- messageBox(i18n.get("uiR2EDLoadScenario_No"))
- return
- end
-
-
-
- local header = r2.getFileHeader(extendedFileName)
- if header then
- local locked = header and header.OtherCharAccess == "RunOnly"
-
- if locked and header.ModifierMD5 and string.len(header.ModifierMD5) > 0 then
- if not r2.hasCharacterSameCharacterIdMd5(header.ModifierMD5) then
- if config.R2EDExtendedDebug ~=1 then
- r2.onSystemMessageReceived("ERR", "", "uiR2EDLoadingLockedScenario")
- else
- local ui = r2:getForm("LoadScenario")
- ui.active = true
- r2.CurrentForm = ui
- r2.onSystemMessageReceived("ERR", "", "uiR2EDLoadingLockedScenarioOverride")
- return
- end
- else
-
- end
- end
- end
-
- local ok = r2.load(extendedFileName)
- if not ok then
- messageBox(i18n.get("uiR2EDInvalidScenario"))
- else
- r2.acts.deleteOldScenario = true
- end
- end
- end
-
-
-
- r2:doForm("LoadScenario", {}, onOk, onCancel)
-end
-
-function UnitTest.saveScenario(name, overwrite)
-
- if (name ~= nil and type(name) == "string")
- then
- if name == "" then
- messageBox(i18n.get("uiR2EDInvalidName"))
- return
- end
- if string.find(name, '.r2', -3) == nil then
- name = name .. ".r2"
- end
- -- update scenario name with the new name
- if name ~= r2.Scenario.Ghost_Name then
- r2.requestNewAction(i18n.get("uiR2EDChangeScenarioName"))
- r2.requestSetNode(r2.Scenario.InstanceId, "Ghost_Name", nlfile.getFilename(name))
- r2.requestEndAction() -- force a flush
- end
- local extendedFilename = r2.getScenarioSavePath()..name
-
- --
- if overwrite ~= true then
- local file = io.open(extendedFilename, "r")
- if file ~= nil then
- io.close(file)
- validMessageBox(concatUCString(ucstring(name), i18n.get("uiR2EDConfirmOverWrite")), "lua", "UnitTest.saveScenario('" .. name .. "', true )", "", "", "ui:interface")
- return
- end
- end
-
- local ok, ret = pcall(r2.Version.save, extendedFilename)
- local errorMsg = ret
- if ok and ret then
- displaySystemInfo(concatUCString(i18n.get("uiR2EDSaveSuccessFull"), ucstring(name)), "BC")
- else
- displaySystemInfo(concatUCString(i18n.get("uiR2EDSaveFailure"), ucstring(name)), "BC")
- end
- end
-end
-
-UnitTest.testSaveScenarioUi = function()
- local function onOk(form)
- local smallName = form.Name
- uc=ucstring()
- uc:fromUtf8(smallName)
- local str = uc:toString()
- UnitTest.saveScenario(str, false)
- end
-
- local function onCancel(form)
-
- end
- r2:doForm("SaveScenario", {}, onOk, onCancel)
-end
-
-
-UnitTest.tesConnectAdventure = function()
- local function onOk(form)
- if (form.AdventureId ~= nil and type(form.AdventureId) == "number")
- then
- r2.requestMapConnection(form.AdventureId)
- else
- debugInfo("R2Lua can't connect adventure")
-
- end
- end
-
- local function onCancel(form)
-
- end
- r2:doForm("ConnectAdventure", {}, onOk, onCancel)
-end
-
-
-UnitTest.createRoad = function(x,y,name)
- local road = r2.newComponent("Road")
-
- local function wp(x, y, z)
- local wayPoint = r2.newComponent("WayPoint")
- local pos = r2.newComponent("Position")
- pos.x = x
- pos.y = y
- pos.z = z
- wayPoint.Position = pos
- return wayPoint
- end
- road.Base = "palette.geom.road"
- road.Name = name
- local tmpPositions = road.Points
- table.insert(tmpPositions, wp(x - 5, y, 0))
- table.insert(tmpPositions, wp(x + 5, y, 0))
- table.insert(tmpPositions, wp(x, y - 5, 0))
-
-
- return road
-end
-
-
---- UserComponent
-
-
-r2.getUserComponentSourceExtension = function () return "lua" end
-r2.getUserComponentExtension = function () return "lua" end
-r2.getUserComponentExamplesDirectory= function () return "examples/user_components" end
-r2.getUserComponentBinairyDirectory = function () return "ring_features" end
-
-r2.UserComponentsManager = {}
-
-
-local UserComponentsManager = r2.UserComponentsManager
-
-
-
-
-function UserComponentsManager:newPackage(identifiant)
- local package = {}
- package.Name = "UnnamedPackage"
- package.Description = "Undescribed Package"
- package.Components = {}
-
- if (not identifiant) then
- package.GlobalNamespace = true
- else
- package.FileInfo = clone(UserComponentsManager.CurrentFileInfo)
-
- end
-
- function package:fullname(name)
- if package.GlobalNamespace then
- return name
- else
- return name .. "_" .. package.MD5
- end
- end
-
- function package:newComponent(name)
- if not package.GlobalNamespace then
- if r2.Scenario.UserComponents.UserComponents[self.FileInfo.Md5] then
- r2.requestInsertNode(r2.Scenario.InstanceId, "UserComponents", -1, self.Md5, self.FileInfo.Package)
- end
- end
- return r2.newComponent(fullname(name))
- end
-
- function package:getUniqId()
- return self:fullname(self.Name)
- end
-
- return clone(package)
-
-end
-
-function UserComponentsManager:newComponent()
- local component = {
- BaseClass="LogicEntity",
- Name = "Unknown",
- Menu="ui:interface:r2ed_feature_menu",
- DisplayerUI = "R2::CDisplayerLua",
- DisplayerUIParams = "defaultUIDisplayer",
- DisplayerVisual = "R2::CDisplayerVisualEntity",
- Text = "uiR2EDtooltipCreateUnkownComponent",
- Tooltip = "uiR2EDtooltipCreateUnkownComponent",
- Icon = "r2ed_feature_timer.tga",
- IconOver = "r2ed_feature_timer_over.tga",
- IconPushed= "r2ed_feature_timer_pushed.tga",
- Parameters = {},
- ApplicableActions = {},
- Events = {},
- Conditions = {},
- TextContexts = {},
- TextParameters = {},
- LiveParameters = {},
- Prop = { }
- }
- function component:registerMenu(logicEntityMenu)
- logicEntityMenu:addLine(ucstring(self.Name), "lua", "", self.Name)
- end
-
- function component:createImpl()
-
- if not r2:checkAiQuota() then return end
-
-
- component:create()
- end
-
- function component:create()
- end
-
- -----------------------------------------------------------------------------------------------
- -- from base class
- component.getParentTreeNode = function(this)
- return this:getFeatureParentTreeNode()
- end
- ---------------------------------------------------------------------------------------------------------
- -- from base class
- component.appendInstancesByType = function(this, destTable, kind)
- assert(type(kind) == "string")
- --this:delegate():appendInstancesByType(destTable, kind)
- r2.Classes.LogicEntity.appendInstancesByType(this, destTable, kind)
- for k, component in specPairs(this.Components) do
- component:appendInstancesByType(destTable, kind)
- end
- end
- ---------------------------------------------------------------------------------------------------------
- -- from base class
- component.getSelectBarSons = function(this)
- return Components
- end
- ---------------------------------------------------------------------------------------------------------
- -- from base class
- component.canHaveSelectBarSons = function(this)
- return false;
- end
-
- function component:onPostCreate() end
-
- function component:translator(context)
- r2.Translator.createAiGroup(self, context)
- end
-
- function component:pretranslate(context)
- r2.Translator.translateAiGroup(self, context)
- end
-
- return clone(component)
-end
-
-function UserComponentsManager:addUserComponentIntoPalette(componentId, package, component)
-
- local theText, theTooltip, theIcon, theIconOver, theIconPushed = component.Text, component.Tooltip, component.Icon, component.IconOver, component.IconPushed
- if not theText then theText = "uiR2EDtooltipCreateUnkownComponent" end
- if not theTooltip then theTooltip = "uiR2EDtooltipCreateUnkownComponent" end
- if not theIcon then theIcon = "r2ed_feature_timer.tga" end
- if not theIconOver then theIconOver = "r2ed_feature_timer_over.tga" end
- if not theIconPushed then theIconPushed = "r2ed_feature_timer_pushed.tga" end
-
- local palette = getUI("ui:interface:r2ed_palette")
- assert(palette)
- local menu = palette:find("sbtree_features")
- assert(menu)
- menu = menu:find("feature_list")
- assert(menu)
-
- local theParent = "parent"
-
- if componentId == 1 then
- theParent = "parent"
- else
- theParent = "r2_user_component" .. tostring(componentId - 1)
- end
-
- local instance = createGroupInstance("named_r2ed_tool", menu.id , {
- id="r2_user_component"..tostring(componentId),
- tooltip=theTooltip,
- onclick_l="lua",
- posparent="parent",
- posref="TL TL", x=tostring(componentId * 4),
- y=tostring(1 + componentId * -64),
- icon = theIcon,
- icon_over = theIconOver,
- icon_pushed = theIconPushed,
- text=theText,
- params_l="r2.UserComponentsManager.Packages['".. package:getUniqId() .. "'].Components['".. component.Name.."']:create()"
- })
- debugInfo("r2.UserComponentsManager.Packages['".. package:getUniqId() .. "'].Components['".. component.Name.."']:createImpl()")
- assert(instance)
- menu:addGroup(instance)
-
-end
-
-
-function UserComponentsManager:updateUserComponentsUi()
- local index = 0
-
- local k, package = next(self.Packages)
- while k do
- local kC, component = next(package.Components)
- while kC do
- UserComponentsManager:addUserComponentIntoPalette(index, package, component)
- index = index + 1
-
- kC, component = next(package.Components, kC)
- end
-
- k, package = next(self.Packages, k)
- end
-end
-
-
-function UserComponentsManager:updateUserComponents()
- local index = 0
- local k, package = next(self.Packages)
- while k do
-
- local kC, component = next(package.Components)
- while kC do
- r2.registerComponent(component, package)
- kC, component = next(package.Components, kC)
- end
-
- k, package = next(self.Packages, k)
- end
- self:updateUserComponentsUi();
-end
-
-
-function UserComponentsManager:registerPackageComponents(package)
- local kC, component = next(package.Components)
- while kC do
- r2.registerComponent(component, package)
- kC, component = next(package.Components, kC)
- end
-
-end
-
-
-function UserComponentsManager:addUserComponent(filename)
- local package = self:loadPackage(filename)
- assert(package)
- self.Packages[package:getUniqId()] = package
- self:registerPackageComponents(package)
- UserComponentsManager:updateUserComponentsUi()
-
-end
-
-function UserComponentsManager:registerFileInfo(fileinfo)
- self.CurrentFileInfo = fileinfo
-end
-
-
-function UserComponentsManager:loadPackage(filename)
-
- self.CurrentPackage = nil
- self.CurrentFileInfo = nil
-
-
-
-
- local str = r2.readUserComponentFile(filename)
- if not str then
- debugInfo("Error in package '" .. filename .. "'")
- return nil
- end
-
- local f, msg = loadstring(str)
- if not f then
- debugInfo("Syntax error in package '" .. filename .. "': '" .. msg .. "'")
- return nil
- end
-
- local ok, msg = pcall(f)
- if not ok then
- debugInfo("Loading error in package '" .. filename .. "': '" .. msg .. "'")
- return nil
- end
-
- if not self.CurrentPackage then
- debugInfo("No Package information in '"..filename.."'")
- return nil
- end
-
- r2.updateUserComponentsInfo(filename, self.CurrentPackage.Name, self.CurrentPackage.Description,
- self.CurrentFileInfo.TimeStamp, self.CurrentFileInfo.MD5)
- self.CurrentPackage.fileinfo = clone(self.CurrentFileInfo)
- return self.CurrentPackage
-
-end
-
-function UserComponentsManager:init()
- self.UserComponentDirectory = "./ring_features"
- self.Packages = {}
- self.CurrentPackage = nil
- -- r2.requestSetNode(r2.Scenario.InstanceId, "UserComponents", {}) -- TODO to remove
- self.Instanece = self
-end
-
-
-function UserComponentsManager:addUserComponentIntoScenario(filename)
- local package= self:loadPackage(filename)
- if not package then return end
- local uniqId = package:getUniqId()
--- TODO
- if r2.Scenario.UserComponents[ uniqId ] then
- debugInfo("The User defined Component '".. package.Name .. "' is already present in the current scenario.")
- return
- else
- r2.requestInsertNode(r2.Scenario.InstanceId, "UserComponents", -1, uniqId, uniqId)
- -- TODO: requestUpdateComponent
- -- UserComponentsManager:addUserComponent(filename)
- r2.registerUserComponent(filename)
- end
-end
-
-
-function UserComponentsManager:addUserComponentUi()
-end
-
-
-function UserComponentsManager:test()
--- UserComponentsManager:addUserComponent("./ring_features/r2_features_zone_triggers.lua.r2c")
-end
-
-
-function UserComponentsManager:registerPackage(package)
- assert(package)
- self.CurrentPackage = package
-end
-
-function UserComponentsManager:registerComponent(package, component)
- if not package then return end
- if not component then return end
- package.Components[package:fullname(component.Name)] = component
-end
-
-function UserComponentsManager:compileUserComponent(filename)
- local component = self:loadPackage(filename)
- if not component then
- debugInfo("Can not compile user component.")
- return
- end
- component = nil
- r2.saveUserComponentFile(filename, true)
-end
-
-
-
-
-UserComponentsManager:init()
-
-function UserComponentsManager:createUserComponentUi(otherDirectory)
- local directory = otherDirectory
- if (directory == nil) then directory= r2.getUserComponentExamplesDirectory() end
- local extension = r2.getUserComponentSourceExtension()
-
- local function onOk(form)
- local filename = directory .."/".. form.Name
- self:compileUserComponent(filename)
- end
- local function onCancel() end
-
- debugInfo(extension)
- r2:doForm("LoadUserComponent", {Directory=directory, Extension=extension}, onOk, onCancel)
-end
-
-
-function UserComponentsManager:importUserComponentUi(otherDirectory)
-
- local directory = otherDirectory
- if (directory == nil) then directory= r2.getUserComponentBinairyDirectory() end
- local extension = r2.getUserComponentExtension()
-
- local function onOk(form)
- local filename = directory.."/".. form.Name
- UserComponentsManager:addUserComponentIntoScenario(filename)
- end
- local function onCancel() end
- r2:doForm("LoadUserComponent", {Directory=self.UserComponentDirectory, Extension=extension}, onOk, onCancel)
-
-end
-
-
------------------------------------------------------------------------------------------------------------------------------------------
--- Ring Access
---
-r2.RingAccess = { }
-
-local RingAccess = r2.RingAccess
-
-
-
-function RingAccess.testAccess(access)
- -- always true in local mode
- if config.Local == 1 then
- return true
- end
- --
- local t = string.sub(access, 1, 1)
- local v = tonumber(string.sub(access, 2))
-
- local charAccessMap = r2.getRingAccessAsMap(r2.getCharacterRingAccess())
- if charAccessMap[t] == nil then return false end
- if charAccessMap[t] < v then return false end
- return true
-
-end
-
-function RingAccess.updateLevel(access, level, allowed)
- if string.len(access) == 0 then
- return true, level
- end
-
- local t = string.sub(access, 1, 1)
- local v = tonumber(string.sub(access, 2, string.len(access)))
- if level[t] == nil or level[t] < v then
- level[t] = v
- end
- if allowed[t] == nil or allowed[t] < v then
- return false, level
- end
- return true, level
-end
-
-function RingAccess.errorMessageIsland(islandName, accessWanted, accessCharacter)
- local accessWantedMap = r2.getRingAccessAsMap(accessWanted)
- local accessCharacterMap = accessCharacter
-
- local k, v = next(accessWantedMap, nil);
- assert( k)
- local charLevel = accessCharacterMap[k]
- if charLevel == nil then charLevel = 0 end
-
- return RingAccess.errorMessageImpl("InvalidIslandLevel", islandName, k, v, charLevel)
-
-end
-
-
-function RingAccess.errorMessageBot(entityName, accessWanted, accessCharacter)
- local accessWantedMap = r2.getRingAccessAsMap(accessWanted)
- local accessCharacterMap = accessCharacter
-
- local k, v = next(accessWantedMap, nil);
- assert( k)
- local charLevel = accessCharacterMap[k]
- if charLevel == nil then charLevel = 0 end
-
- return RingAccess.errorMessageImpl("InvalidBotLevel", entityName, k, v, charLevel)
-
-end
-
-
-function RingAccess.errorMessageGeneric( accessWanted, accessCharacter)
- local accessWantedMap = r2.getRingAccessAsMap(accessWanted)
- local accessCharacterMap = accessCharacter
-
- local k, v = next(accessWantedMap, nil);
- assert( k)
- local charLevel = accessCharacterMap[k]
- if charLevel == nil then charLevel = 0 end
-
- return RingAccess.errorMessageImpl("InvalidLevel", nil, k, v, charLevel)
-
-end
-
-
-function RingAccess.errorMessageImpl(errorType, name, package, entityLevel, charLevel)
-
- local trad
- local entityName
-
- if errorType == "InvalidIslandLevel" then
- trad = i18n.get("uiR2EDErrMessageNoEnoughRingPointFor".."Island")
- entityName = i18n.get(name):toUtf8()
- elseif errorType == "InvalidBotLevel" then
- trad = i18n.get("uiR2EDErrMessageNoEnoughRingPointFor".."Bot")
- entityName = name
- elseif errorType =="InvalidLevel" then
- trad = i18n.get("uiR2EDErrMessageNoEnoughRingPointFor".."Generic")
- else
- trad = i18n.get("uiR2EDErrMessageDataCorrupted")
- package = nil
- entityLevel = nil
- chatLevel = nil
- entityName = nil
- end
-
-
-
- local str = trad:toUtf8()
-
- if package and string.len(package) ~= 0 then
- local category = i18n.get(string.format("uiR2EDRingAccessCategory_%s", package))
- str=string.gsub (str, "", category:toUtf8())
- end
- if entityLevel then
- str=string.gsub (str, "", tostring(entityLevel))
- end
- if charLevel then
- str=string.gsub (str, "", tostring(charLevel))
- end
- if entityName then
- str=string.gsub (str, "", entityName)
- end
-
- local err = {}
- err.Type = errorType
- err.Name = name
- err.Package = package
- err.CharLevel = charLevel
- err.EntityLevel = entityLevel
- err.What = str
- return err
-
-end
-
-function RingAccess.dumpRingAccessLocations(level, allowed, ok)
- local k1, v1 = next(r2.Scenario.Locations, nil)
- while k1 do
-
- local access = r2.getIslandRingAccess(v1.IslandName)
- local map = r2.getRingAccessAsMap(access)
- r2.print(access)
-
- local k, v = next(map, nil)
- if k then
- if not level[k] then level[k] = {} end
- if not level[k][v] then level[k][v] = {} end
- table.insert(level[k][v], { Ok=test, Type="Island", Name=v1.IslandName} )
- end
-
-
- k1, v1 = next(r2.Scenario.Locations, k1)
- end
- return ok, level
-end
-
-
-function RingAccess.dumpRingAccessEntityRec(node, level, allowed, ok, err )
- local isTree = false
-
- if type(node) == "table" then
- isTree = true
- elseif type(node) == "userdata" then
- local mt = getmetatable(node)
- if mt~= nil and mt.__next ~= nil then
- isTree = true
- end
- end
-
- if isTree then
- if node.Class ~= nil then
- local access = ""
- local access2 = nil
- local type = "Unknown"
- if node.isKindOf and node:isKindOf("Npc") then
- access2 = node.RingAccess
- local sheet = ""
- if node.Sheet then sheet = node.Sheet end
- access = r2.getSheetRingAccess(node.SheetClient, sheet)
- type = "Bot"
-
-
- elseif node.RingAccess then
- local access = node.RingAccess
- type = "Component"
-
-
- end
-
- local map = r2.getRingAccessAsMap(access)
- local k, v = next(map, nil)
- if k then
- if not level[k] then level[k] = {} end
- if not level[k][v] then level[k][v] = {} end
- local obj = { Ok=test, Type=type, Name=node.Name, PaletteId=access2}
- table.insert(level[k][v], obj)
- end
- end
-
- local t = nil
-
- if node.Components then t = node.Components end
- if node.Acts then t = node.Acts end
- if node.Features then t = node.Features end
-
- if t then
- local k, v = next(t, nil)
- while k do
- ok, level, err = RingAccess.dumpRingAccessEntityRec(v, level, allowed, ok, err)
- k, v = next(t, k)
- end
- end
- end
- return ok, level, err
-end
-
-function RingAccess.dumpRingAccess()
- local level = {} -- will be filled
-
- local allowed = r2.getRingAccessAsMap(r2.getCharacterRingAccess())
-
- local ok = true
- local err= {}
- err.What = ""
- ok, level = RingAccess.dumpRingAccessLocations(level, allowed, ok, err)
- ok, level, err = RingAccess.dumpRingAccessEntityRec(r2.Scenario, level, allowed, ok, err)
-
- RingAccess.saveRingAccessLevel(level)
- return ok, level, err
-end
-
-function RingAccess.saveRingAccessLevel(data)
- local function dumpRec(item, f)
- local k,v = next(item)
- while k do
- f:write(k.."='"..v.."', ")
- k,v = next(item, k)
- end
- end
-
- local filename = "scenario_level.txt"
- local f = io.open(filename, "w")
- assert(f)
- f:write("-- "..filename.." ".. os.date() .."'\n\n")
- f:write("r2.ScenarioRingAccess = {\n\n")
-
-
- local catId, cat = next(data, nil)
- while catId do
- f:write("\t"..catId.."= {\n")
- local levelId, level = next(cat, nil)
- while levelId do
- f:write("\t\t"..levelId.."= {\n")
- local itemId, item = next(level, nil)
- while itemId do
- f:write("\t\t\t{");
- dumpRec(item,f)
- f:write("}\n");
- itemId, item = next(level, itemId)
- end
- f:write("\t\t}\n")
- levelId, level = next(cat, levelId)
- end
- f:write("\t}\n")
- catId, cat = next(data, catId)
- end
- f:write("}\n")
- f:flush()
- f:close()
-
- messageBox("Ring access has been saved in \""..filename.."\"")
-
-
-end
-
-function RingAccess.verifyLocations(level, allowed, ok, err)
- local k, v = next(r2.Scenario.Locations, nil)
- while k do
-
- local access = r2.getIslandRingAccess(v.IslandName)
- local test, level = RingAccess.updateLevel(access, level, allowed)
- if not test then
- if ok then
- ok = false
- err = RingAccess.errorMessageIsland(v.IslandName, access, allowed)
- end
- end
- k, v = next(r2.Scenario.Locations, k)
- end
- return ok, level, err
-end
-
-function RingAccess.verifyEntityRec(node, level, allowed, ok, err )
- local isTree = false
-
- if type(node) == "table" then
- isTree = true
- elseif type(node) == "userdata" then
- local mt = getmetatable(node)
- if mt~= nil and mt.__next ~= nil then
- isTree = true
- end
- end
-
- if isTree then
- if node.Class ~= nil then
- if node.isKindOf and node:isKindOf("Npc") then
- local access = node.RingAccess
- local test, level = RingAccess.updateLevel(access, level, allowed)
- local sheet = ""
- if node.Sheet then sheet = node.Sheet end
- local access2 = r2.getSheetRingAccess(node.SheetClient, sheet)
- local test2, level = RingAccess.updateLevel(access2, level, allowed)
- if not test2 then
- test = false
- access = access2
- end
-
- if not test and ok then
- ok = false
- err = RingAccess.errorMessageBot(node.Name, access, allowed)
- end
-
-
- elseif node.RingAccess then
- local test = RingAccess.updateLevel(node.RingAccess, level, allowed)
- if not test and ok then
- ok = false
- err = RingAccess.errorMessageGeneric(node.access, allowed)
- end
-
- end
- end
-
- local t = nil
-
- if node.Components then t = node.Components end
- if node.Acts then t = node.Acts end
- if node.Features then t = node.Features end
-
- if t then
- local k, v = next(t, nil)
- while k do
- ok, level, err = RingAccess.verifyEntityRec(v, level, allowed, ok, err)
- k, v = next(t, k)
- end
- end
- end
- return ok, level, err
-end
-
-function RingAccess.verifyScenario()
-
- local level = {} -- will be filled
-
- local allowed = r2.getRingAccessAsMap(r2.getCharacterRingAccess())
-
- local ok = true
- local err= {}
- err.What = ""
- ok, level, err = RingAccess.verifyLocations(level, allowed, ok, err)
- ok, level, err = RingAccess.verifyEntityRec(r2.Scenario, level, allowed, ok, err)
-
- return ok, level, err
-end
-
-function RingAccess.verifyRtScenario(rtScenario)
- local ok, err = r2.verifyRtScenario(rtScenario)
- if not ok then
- err = RingAccess.errorMessageImpl(err.Type, err.EntityName, err.Package, err.EntityLevel, err.CharLevel)
- end
- return ok, err
-end
-
-function RingAccess.getAccessListAsString(list)
- local ret = ''
- local k,v = next(list)
- while k do
- if string.len(ret) ~= 0 then ret = ret ..':' end
- ret = ret .. k .. tostring(v)
- k, v= next(list, k)
- end
- return ret
-end
-
-function RingAccess.createAccessList()
- assert( config.R2EDExtendedDebug == 1)
- function createAccessListRec(node, f)
- if r2.isTable(node) then
- -- each palette entry
- if node.Id ~= nil then
- local base = r2.getPaletteElement(node.Id)
- local access = r2.getPropertyValue(base, "RingAccess")
- local sheet = r2.getPropertyValue(base, "Sheet")
- local sheetClient = r2.getPropertyValue(base, "SheetClient")
- if not sheet then sheet = "" end
- if not sheetClient then sheetClient = "" end
-
- f:write(string.format(" \n", node.Id, access, sheetClient, sheet))
- else
- local k,v = next(node, nil)
- while k do
- createAccessListRec(v, f)
- k,v = next(node, k)
- end
- end
- end
- end
-
- local f = io.open("data_common/r2/r2_ring_access.xml", "w")
- assert(f)
- f:write("\n\n")
- f:write("\n\n")
- f:write("\n")
- createAccessListRec(r2.Palette, f)
- f:write("\n")
- f:flush()
- f:close()
-
-end
-
-function RingAccess.loadAnimation(str)
- RingAccess.LoadAnimation = true
- local ok, msg = r2.loadAnimation(str)
- RingAccess.LoadAnimation = false
- return ok, msg
-end
-
-
-
-function r()
- resetR2UICache()
- runCommand('resetEditorAndReloadUI')
--- UserComponentsManager:addUserComponentUi()
-end
-
-function t2()
--- UserComponentsManager:loadPackage('./ring_features/r2_features_zone_triggers.lua.r2c.gz')
-end
-
-function t3()
--- r2.registerUserComponent('./ring_features/r2_features_zone_triggers.lua.r2c.gz')
-end
-
-
-function t5()
- local toto = "&ezr_çà'_\\)d //:1' 2 éééà'..)à/:*?\"<>|à)@4 58ftgsfdg\"/:*?\"<>|"
- toto = string.gsub(toto, "[\\/:*?\"<>|]", "_")
-end
-
-
-r2.UserComponentManager = r2.UserComponentsManager
-
-
-function r2:dumpDialogsAsText(filename, noMessage)
-
- local function dumpRec(entity, f)
- if entity:isKindOf("ChatSequence") then
- f:write("{\n\tName=[["..entity.Name.."]], Texts={\n")
- local stepId, step = next(entity.Components)
- while stepId do
-
- local who =""
- if tostring(step.Actions[0].Who) == "" then
- who = step.Actions[0].WhoNoEntity
- else
- local whoInst = r2:getInstanceFromId(step.Actions[0].Who)
- if whoInst then
- who = whoInst.Name
- end
- end
- local what = ""
- if tostring(step.Actions[0].Says) ~= "" then
- local whatInst = r2:getInstanceFromId(step.Actions[0].Says)
- if whatInst then
- local tmp = ucstring()
- tmp:fromUtf8(whatInst.Text)
- what = tmp:toString()
- end
- end
- id = tostring(step.Actions[0].Says)
- if id ~= "" then
- f:write("\t\t{Id=[["..id.."]], Who=[["..who.."]], Text=[["..what.."]], },\n")
- end
- stepId, step = next(entity.Components, stepId)
- end
-
- f:write("\t}\n},\n")
- end
- if entity.Components then
- local componentId, comp = next(entity.Components, nil)
- while componentId do
- dumpRec(comp)
- componentId, comp = next(entity.Components, componentId)
- end
- end
- end
-
- local allNames = r2:getAllNames()
- local function dumpBotnameRec(entity, f)
- assert(f)
- if not entity:isKindOf("Act") and not entity:isKindOf("Scenario") and entity.Name and entity.Name~="" then
- local mustPrint = true
- -- do not print DefaultName eg "Growling Gingo"
- if entity:isKindOf("Npc") then
- local basename = entity.Base
- if basename then basename = r2.PaletteIdToTranslation[ basename ] end
- if basename ~= nil and basename == entity.Name then
- mustPrint = false
- end
- local found = false
- local types, names = next (allNames)
- while types and mustPrint do
- local index, name = next (names)
- while index and mustPrint do
- if entity.Name == name then mustPrint = false end
- index, name = next (names, index)
- end
- types, names = next (allNames, types)
- end
- local base = r2.getPaletteElement(entity.Base)
- if base and base.Name == entity.Name then mustPrint = false end
- end
- if mustPrint then
- f:write("\t{ Id=[["..entity.InstanceId.."]], Name=[["..entity.Name.."]], },\n");
- end
- end
- if entity.Components then
- local componentId, comp = next(entity.Components, nil)
- while componentId do
- dumpBotnameRec(comp, f)
- componentId, comp = next(entity.Components, componentId)
- end
- end
- end
-
- local previousEntity = nil
- local function dumpVariousPropertyRec(entity, f)
- assert(f)
-
- local function dumpProperty(property, entity, f)
- if entity[property] and string.len( entity[property] ) > 0 then
- if previousEntity ~= entity.InstanceId then f:write("\n") end
- previousEntity = entity.InstanceId
- f:write("\t{\tId=[["..entity.InstanceId.."]], Property=[[".. property .. "]], Text=[[".. entity[property] .. "]]},\n");
- end
- end
-
- if not r2.isTable(entity) then return end
-
- if entity.iKindOf and entity:isKindOf("Location") then
- dumpProperty("Name", entity, f)
- end
-
- if entity.iKindOf and entity:isKindOf("PlotItem") then
- dumpProperty("Name", entity, f)
- dumpProperty("Comment", entity, f)
- dumpProperty("Desc", entity, f)
- end
-
- -- Act or Scenenario description
- dumpProperty("Title", entity, f)
- dumpProperty("ShortDescription", entity, f)
- dumpProperty("PreActDescription", entity, f)
-
- -- Mission
- dumpProperty("BroadcastText", entity, f)
- dumpProperty("ContextualText", entity, f)
- dumpProperty("MissionSucceedText", entity, f)
- dumpProperty("MissionText", entity, f)
- dumpProperty("WaitValidationText", entity, f)
-
-
-
- local k,v = next(entity)
- while k do
- dumpVariousPropertyRec(v, f)
- k,v = next(entity, k)
- end
-
- end
-
-
- if not filename then filename = "scenario_texts.txt" end
- local f = io.open(filename, "w")
- do
-
- assert(f)
- f:write("-- scenario_texts.txt '".. os.date() .."'\n\n")
- f:write("-- Here are the content of differents the dialogs\n")
- f:write("-- You must only translate the \"Text\" field (not the \"Who\" or \"Name\")\n")
-
- f:write("r2.DialogsAsText = {\n")
-
-
- local actId, act = next(r2.Scenario.Acts, nil)
- while actId do
- local featureId, feature = next(act.Features, nil)
- while featureId do
- dumpRec(feature, f)
- featureId, feature = next(act.Features, featureId)
- end
- actId, act = next(r2.Scenario.Acts, actId)
- end
- f:write("}\n\n\n")
- end
-
- do
-
- assert(f)
- f:write("\n-- Here are the content of different component name of the scenario\n")
- f:write("-- Generic Fauana name and default botname are not present\n")
- f:write("-- You only have to translate the \"Name\" Field\n")
- f:write("r2.BotnameAsText = {\n\n")
-
-
- local actId, act = next(r2.Scenario.Acts, nil)
- while actId do
- local featureId, feature = next(act.Features, nil)
- while featureId do
- dumpBotnameRec(feature, f)
- featureId, feature = next(act.Features, featureId)
- end
- actId, act = next(r2.Scenario.Acts, actId)
- end
- f:write("}\n\n\n")
- end
-
- do
-
- assert(f)
- f:write("\n-- Here are the content of different field of the scenario like plot item/act description\n")
- f:write("-- or task description/task text\n")
- f:write("-- You only have to translate the \"Text\" Field\n")
- f:write("r2.DiversText = {\n\n")
-
-
-
- dumpVariousPropertyRec(r2.Scenario, f)
-
- f:write("}\n")
- f:flush()
- f:close()
- end
- if not noMessage then
- messageBox("Text content has been saved in \"scenario_text.txt\"")
- end
-end
-
-function r2:updateDialogsFromText(filename, noMessage)
- if not filename then filename = "dialog.txt" end
- local f = io.open(filename, "r")
- if not f then
- if not noMessage then
- messageBox("Can not open \""..filename.."\"")
- else
- ld.log("Can not open \""..filename.."\"")
- end
- return
- end
- assert(f)
- if f ~= nil then
- local content = f:read("*all")
-
- io.close(f)
-
- local fun, msg = loadstring(content)
- if not fun then
- local err = "Syntax error in \""..filename.."\":"..msg
- if not noMessage then
- messageBox(err)
- else
- ld.log(err)
- end
- return
- end
- r2.DialogsAsText = {}
- r2.BotnameAsText = {}
- r2.DiversText = {}
- fun()
-
- local dialogId, dialog = next(r2.DialogsAsText, nil)
- while dialogId do
- local textId, text = next(dialog.Texts, nil)
- while textId do
- local t = tostring(text.Text)
- local uc=ucstring(t)
- local utf8=uc:toUtf8()
- r2.requestSetNode(tostring(text.Id), "Text", utf8)
- textId, text = next(dialog.Texts, textId)
- end
- dialogId, dialog = next(r2.DialogsAsText, dialogId)
- end
-
- do
- local id, value = next(r2.BotnameAsText, nil)
- while id do
- local t = tostring(value.Name)
- local uc=ucstring(t)
- local utf8=uc:toUtf8()
- r2.requestSetNode(tostring(value.Id), "Name", utf8)
- id, value = next(r2.BotnameAsText, id)
- end
- end
-
- do
- local id, value = next(r2.DiversText, nil)
- while id do
- local t = tostring(value.Text)
- local uc=ucstring(t)
- local utf8=uc:toUtf8()
- r2.requestSetNode(tostring(value.Id), value.Property, utf8)
- id, value = next(r2.DiversText, id)
- end
- end
- end
- if not noMessage then
- messageBox("Dialogs content has been update with text from \""..filename.."\"")
- end
- return true
-end
-
-
-ld = {}
-
-ld.WaitingCommands = {}
-
-function ld.runScript(scriptName)
- table.insert(ld.WaitingCommands, {'runScript', scriptName})
-end
-function ld.translate(textFilename, fileToSave)
- table.insert(ld.WaitingCommands, {'translate', textFilename, fileToSave})
-end
-
-function ld.saveTexts(fileToSave)
- table.insert(ld.WaitingCommands, {'saveTexts', fileToSave})
-end
-
-function ld.loadScena(fileToLoad)
- table.insert(ld.WaitingCommands, {'loadScena', fileToLoad})
-end
-
-function ld.log(toto)
- debugInfo("ld: "..toto)
- local f = io.open("ld.log", "a")
- f:write(tostring(os.date()).." "..toto.."\n")
- f:flush()
- f:close()
-end
-function ld.update()
- local command = nil
- if ld.lock == 1 then return end
- if table.getn( ld.WaitingCommands ) > 0 then
- command=table.remove(ld.WaitingCommands, 1)
-
- else
- return
- end
-
- if command[1] == 'saveTexts' then
- ld.log("ld.saveTexts " .. command[2])
- r2:dumpDialogsAsText(command[2], true)
- elseif command[1] == 'loadScena' then
- ld.log("ld.loadScena " .. command[2])
- ld.lock = 1
- r2.load(command[2 ])
- elseif command[1] == 'translate' then
- ld.log("ld.translate " .. command[2] .. " " .. command[3])
- r2.requestNewAction("Update")
- r2:updateDialogsFromText(command[2], true)
- r2.requestEndAction()
- r2.requestNewAction("Save")
- r2.Version.save(command[3])
- r2.requestEndAction()
- elseif command[1] == 'runScript' then
- debugInfo("ld.runScript " .. command[2])
- dofile(command[2])
- else
- ld.log("Unknown command:" .. command[1])
-
- end
- ld.log( tostring(table.getn(ld.WaitingCommands)) .. " tasks restantes")
- if table.getn(ld.WaitingCommands) == 0 then
- ld.log("")
- end
-end
-
-function createVisitZone()
- r2.Features['VisitZone'].Components.VisitZone:create()
-end
-
-function createAmbush()
- r2.Features['Ambush'].Components.Ambush:createProtected()
-end
-
-function createManHunt()
- r2.Features['ManHuntFeature'].Components.ManHunt:create()
-end
-
-function createTimedSpawner()
- r2.Features['TimedSpawner'].Components.TimedSpawner:create()
-end
-
-function createRandomChest()
- r2.Features['RandomChest'].Components.RandomChest:create()
-end
-function createDelivery()
- r2.Features['DeliveryTask'].Components.DeliveryTask:create()
-end
-
-function createKillNpc()
- r2.Features['KillNpc'].Components.KillNpc:create()
-end
-
-function createTargetMob()
- r2.Features['TargetMob'].Components.TargetMob:create()
-end
-function testIsInPalette()
- if r2.isInPalette("palette.entities.creatures.ccegf4") then
- debugInfo("Machin is in palette")
- else
- debugInfo("Machin is NOT in palette bordel")
- end
-end
-
-function createHiddenChest()
- r2.Features['HiddenChest'].Components.HiddenChest:create()
-end
-
-function createHunt()
- r2.Features['HuntTask'].Components.HuntTask:create()
-end
-
-
-function testFiles()
- local files = {"r2_translator.lua", "r2_logic.lua", "r2_unit_test.lua", "r2_features.lua", "r2_components.lua", "r2_version.lua"}
- local k,v = next(files)
- while k do
- local f = fileLookup(v)
- local fun= loadfile(f)
- if not fun then
- if f == "" then
- debugInfo("Error: "..v.." is an unknown file.")
- else
- debugInfo("Error: "..f.." has syntax errors.")
- end
- end
- k,v = next(files, k)
- end
-end
diff --git a/code/ryzom/common/data_common/system_files.cfg b/code/ryzom/common/data_common/system_files.cfg
deleted file mode 100644
index cadf2c5e5..000000000
--- a/code/ryzom/common/data_common/system_files.cfg
+++ /dev/null
@@ -1,15 +0,0 @@
-
-// List of files to be kept up to date
-// This list can't contain more than 20 files approximately
-
-Files =
-{
- // DO NOT REMOVE THIS ENTRY
- // THIS MUST ALWAYS BE THE FIRST FILE !!
- "system_files.cfg",
- //
-
- "msg.xml",
- "database.xml",
- "chat_static.cdb"
-};
diff --git a/code/ryzom/common/data_common/visual_slot.tab b/code/ryzom/common/data_common/visual_slot.tab
deleted file mode 100644
index d0c4dacd9..000000000
Binary files a/code/ryzom/common/data_common/visual_slot.tab and /dev/null differ
diff --git a/code/ryzom/common/data_common/weather.cfg b/code/ryzom/common/data_common/weather.cfg
deleted file mode 100644
index 897e99e68..000000000
--- a/code/ryzom/common/data_common/weather.cfg
+++ /dev/null
@@ -1,14 +0,0 @@
-///////////////////////////
-///////////////////////////
-/// Weather CONFIG FILE ///
-///////////////////////////
-///////////////////////////
-
-
-RealDayLength = 3000.0; // real length of the day, in seconds (3000 = 50mn)
-NumHours = 24.0; // number of ryzom hours in a day
-NightTransitionStartHour = 19.0; // start of night transition
-NightTransitionEndHour = 21.0; // end of night transition
-DawnTransitionStartHour = 5.0; // start of dawn transition
-DawnTransitionEndHour = 7.0; // end of dawn transition
-MaxNumColorSteps = 25; // the max number of color steps