3 -- Category : uiR2EdEmptyFeature --
4 -- CreationFrom : uiR2EdEmptyParameters
7 r2
.Features
.EmptyFeature
= {}
9 local feature
= r2
.Features
.EmptyFeature
11 feature
.Name
="EmptyFeature"
13 feature
.Description
="An empty feature"
15 feature
.Components
= {}
18 -- #########################
19 -- # FEATURE FUNCTIONS #
20 -- #########################
23 -- Registers the feature creation form used as a creation menu in the editor
25 function feature
.registerForms()
26 r2
.Forms
.EmptyFeatureForm
=
28 Caption
= "uiR2EdEmptyParameters",
31 -- The creation form's fields are defined here
32 {Name
="Property1", Type
="String", Category
="UI Subsection"}
40 feature
.Components
.EmptyFeature
=
42 BaseClass
="LogicEntity",
44 Menu
="ui:interface:r2ed_feature_menu",
46 DisplayerUI
= "R2::CDisplayerLua",
47 DisplayerUIParams
= "defaultUIDisplayer",
48 DisplayerVisual
= "R2::CDisplayerVisualEntity",
53 -- The different actions that can be performed by the feature ("activate", "wander", "spawn" etc.)
55 ApplicableActions
= {},
58 -- Events are the feature's states that may trigger actions on the feature. (ex: "on activation",
59 -- "on arrive at camp" etc.)
64 -- Conditions can be tested on the feature, giving information about its state (ex: "is wandering", "is active" etc.)
69 -- TextContexts is what the feature might say upon events (2 different kinds: spontaneous & interrogation texts)
79 -- Feature's parameters which can be modified by the GM at runtime.
84 -- Properties define the attributes of the feature.
85 -- They're all displayed in the properties window of the feature.
87 -- -Name: define the name of the property
89 -- -Type: define the type of the property and can be "String", "Number", "Table", "RefId" etc.
91 -- -Category: Define a subsection of the property window displayed within the editor, so that different properties
92 -- refering to the same feature's aspect can be grouped, and not added randomly in the window
94 -- WidgetStyle: define the type of UI widget that will be used to display the property. If not specified,
95 -- the property is displayed in a textBox.
99 {Name
="InstanceId", Type
="String", Category
="uiR2EDRollout_UISubsection", WidgetStyle
="StaticText"}
105 getParentTreeNode
= function(this
)
106 return this
:getFeatureParentTreeNode()
112 appendInstancesByType
= function(this
, destTable
, kind
)
113 assert(type(kind
) == "string")
114 --this:delegate():appendInstancesByType(destTable, kind)
115 r2
.Classes
.LogicEntity
.appendInstancesByType(this
, destTable
, kind
)
116 for k
, component
in specPairs(this
.Components
) do
117 component
:appendInstancesByType(destTable
, kind
)
124 getSelectBarSons
= function(this
)
131 canHaveSelectBarSons
= function(this
)
136 -- Called when running EditMode to create the feature locally without sending anything into the act (speed purpose).
138 onPostCreate
= function(this
)
141 pretranslate
= function(this
, context
)
142 r2
.Translator
.createAiGroup(this
, context
)
145 translate
= function(this
, context
)
146 r2
.Translator
.translateAiGroup(this
, context
)
149 getAvailableCommands
= function(this
, dest
)
150 r2
.Classes
.LogicEntity
.getAvailableCommands(this
, dest
) -- fill by ancestor
151 this
:getAvailableDisplayModeCommands(dest
)
155 -- ###########################
156 -- # COMPONENT FUNCTIONS #
157 -- ###########################
159 local component
= feature
.Components
.EmptyFeature
162 -- Called when running test mode to create the feature and insert it into the current act.
164 component
.createGhostComponents
= function(act
, comp
)
168 -- Creates an instance of the feature with attributes retrieved from the creation form
169 component
.createComponent
= function(x
, y
)
171 local comp
= r2
.newComponent("EmptyFeature")
174 comp
.Base
= "palette.entities.botobjects.milestone"
175 comp
.Name
= r2
:genInstanceName(i18n
.get("uiR2EdEmptyFeature")):toUtf8()
179 comp
.Position
.z
= r2
:snapZToGround(x
, y
)
186 -- Displays the creation form of the feature and calls CreateComponent with the user input values
188 component
.create
= function()
190 if not r2
:checkAiQuota() then return end
192 local function paramsOk(resultTable
)
193 r2
.requestNewAction(i18n
.get("uiR2EDNewEmptyFeatureAction"))
194 local x
= tonumber( resultTable
["X"] )
195 local y
= tonumber( resultTable
["Y"] )
199 debugInfo("Can't create Component")
202 local component
= feature
.Components
.EmptyFeature
.createComponent( x
, y
)
203 r2
.requestInsertNode(r2
:getCurrentAct().InstanceId
, "Features", -1, "", component
)
206 local function paramsCancel()
207 debugInfo("Cancel form for 'EmptyFeature' creation")
209 local function posOk(x
, y
, z
)
210 debugInfo(string.format("Validate creation of 'EmptyFeature' at pos (%d, %d, %d)", x
, y
, z
))
211 r2
:doForm("EmptyFeatureForm", {X
=x
, Y
=y
}, paramsOk
, paramsCancel
)
213 local function posCancel()
214 debugInfo("Cancel choice 'EmptyFeature' position")
216 r2
:choosePos("object_milestone.creature", posOk
, posCancel
, "createFeatureBanditCamp")
221 function feature
.registerForms()
222 r2
.Forms
.EmptyFeatureForm
=
224 Caption
= "uiR2EdEmptyParameters",
227 -- The creation form's fields are defined here
228 {Name
="Property1", Type
="String", Category
="uiR2EDRollout_UISubsection"}
234 -- The following functions are specific to the Feature
236 local component
= feature
.Components
.EmptyFeature
238 component
.getLogicAction
= function(entity
, context
, action
)
239 local firstAction
, lastAction
= nil,nil
240 return firstAction
, lastAction
243 component
.getLogicCondition
= function(this
, context
, condition
)
247 component
.getLogicEvent
= function(this
, context
, event
)
248 local eventHandler
, firsCondition
, lastCondition
= nil, nil, nil
249 return eventHandler
, firsCondition
, lastCondition
253 function component
:registerMenu(logicEntityMenu
)
254 local name
= i18n
.get("uiR2EdEmptyFeature")
255 logicEntityMenu
:addLine(ucstring(name
), "lua", "", "EmptyFeature")
258 function component
:getLogicTranslations()
260 local logicTranslations
= {
261 ["ApplicableActions"] = {},
264 return logicTranslations
267 r2
.Features
["EmptyFeature"] = feature