5 ------------------------------------------------------------------------------------------------------------
6 -- handle right click on palette item
7 function r2
:onPaletteRightClick(paletteNode
)
8 -- store palette path for futur display
9 self
.tmpPaletteNode
= paletteNode
12 ------------------------------------------------------------------------------------------------------------
13 function r2
:onShowPaletteLuaTable(maxDepth
)
14 if (self
.tmpPaletteNode
== nil) then return end
15 runCommand("luaObject", self
.tmpPaletteNode
, maxDepth
)
20 ------------------------------------------------------------------------------------------------------------
21 function r2
:buildPaletteUI()
23 --debugInfo(colorTag(0, 255, 127) .."Begin building palette UI")
24 local tree
= getUI(r2
.Palette
.UIPath
)
25 local botTree
= getUI(r2
.Palette
.BotObjectsUIPath
)
26 if tree
==nil or botTree
==nil then return end
28 local shortElementId
= 0
30 r2
.Palette
.ShortIdToElement
= {}
32 local function buildBranch(luaBranch
, branchStrId
, depth
, openDepth
)
33 local newNode
= SNode()
34 newNode
.Opened
= depth
< openDepth
36 newNode
.Text
= i18n
.get(branchStrId
)
37 for k
, v
in pairs(luaBranch
) do
38 if (k
~= "instances") then
40 if type(v
)=="table" and v
.Display
~=false then
42 -- this is a sub branch
43 newNode
:addChild(buildBranch(v
, "uiR2ED" .. k
, depth
+ 1, openDepth
))
46 for instKey
, instValue
in pairs(v
) do
47 -- the value is a table containing a list of instances
48 local subNode
= SNode()
49 if instValue
.DirectName
~= nil then
50 subNode
.Text
= instValue
.DirectName
52 subNode
.Text
= i18n
.get(instValue
.Translation
)
55 r2
.PaletteIdToTranslation
[instValue
.Id
] = subNode
.Text
:toUtf8()
56 r2
.PaletteIdToGroupTranslation
[instValue
.Id
] = newNode
.Text
:toUtf8()
57 r2
.PaletteIdToType
[instValue
.Id
] = v
59 subNode
.Id
= tostring(shortElementId
)
60 local paletteElement
= r2
.getPaletteElement(instValue
.Id
)
61 if (paletteElement
== nil)
63 debugInfo("invalid nil Palette: " .. instValue
.Id
)
65 r2
.Palette
.ShortIdToElement
[tostring(shortElementId
)] = paletteElement
66 shortElementId
= shortElementId
+ 1
67 subNode
.Opened
= false
68 subNode
.AHName
= "r2ed_create_entity"
69 subNode
.AHParams
= "PaletteId=" .. instValue
.Id
70 --subNode.AHNameRight = "lua"
71 --subNode.AHParamsRight = "r2ed:onPaletteRightClick(" .. instValue.Id .. ")"
72 local ringAccess
= r2
.getPropertyValue(paletteElement
, "RingAccess")
73 local insertNode
= true
75 insertNode
= r2
.RingAccess
.testAccess(ringAccess
)
78 newNode
:addChild(subNode
)
86 -- create root node & call function
87 local rootNode
= buildBranch(r2
.Palette
.Entries
, r2
.Palette
.StrId
, 0, 2)
89 tree
:setRootNode(rootNode
)
91 local botRootNode
= buildBranch(r2
.Palette
.BotEntries
, r2
.Palette
.StrId
, 0, 1)
93 botTree
:setRootNode(botRootNode
)
95 local paletteWindow
= tree
:getEnclosingContainer()
97 -- paletteWindow.active = true
98 -- paletteWindow:updateCoords()
99 local selection
= paletteWindow
:find("entity_selection")
100 local enclosing
= paletteWindow
:find("entity_enclosing")
102 enclosing
.h
= - selection
.h_real
- delta
103 enclosing
.y
= - selection
.h_real
- delta
104 paletteWindow
:invalidateCoords()
107 --debugInfo(colorTag(0, 255, 127) .. "Palette UI built")
108 r2
:setupPaletteAccessibleContent()
109 --r2:setupDefaultCustomBBoxes()
112 ---------------------------------------------------------------------------------------------------------
113 -- Setup the content that is visible in the palette depending on the chosen ecosystem and level
114 function r2
:setupPaletteAccessibleContent()
116 local levelMin
, levelMax
, ecosystem
= r2
:getPaletteAccessibilityFactors()
118 local function setupBranch(branch
)
120 if branch
.Id
== "branch" then
121 for index
= 0, branch
:getNumChildren() - 1 do
122 local showChild
= setupBranch(branch
:getChild(index
))
129 local paletteNode
= r2
.Palette
.ShortIdToElement
[branch
.Id
]
130 --assert(paletteNode)
132 local currLevel
= defaulting(paletteNode
.Level
, 1)
133 local currEcosystem
= defaulting(paletteNode
.Ecosystem
, "")
134 -- tmp : ignore level & ecosystem for objects
135 if string.match(paletteNode
.SheetClient
, "object.*") then
137 elseif currLevel
>= levelMin
and currLevel
<= levelMax
and (currEcosystem
== "" or string.match(currEcosystem
, ecosystem
)) then
140 --debugInfo(currEcosystem)
145 -- branch.Color = CRGBA(255, 255, 255)
147 -- branch.Color = CRGBA(255, 0, 0)
153 if ecosystem
and levelMin
and levelMax
then
154 local tree
= getUI(r2
.Palette
.UIPath
)
155 setupBranch(tree
:getRootNode())
160 function r2
:getPaletteAccessibilityFactors()
162 local tree
= getUI(r2
.Palette
.UIPath
)
163 if tree
== nil then return end
164 local levelRange
= tree
:getEnclosingContainer():find("level").selection
+ 1 -- TMP : tha 'all' field was removed ...
167 if levelRange
== 0 then
171 levelMin
= (levelRange
- 1) * 50 + 1
172 levelMax
= levelMin
+ 49
174 local ecosystemTable
=
176 ".*", "Desert", "Forest", "Jungle", "Lacustre", "PrimeRoots", "Goo"
178 local ecosystem
= ecosystemTable
[tree
:getEnclosingContainer():find("ecosystem").selection
+ 2] -- TMP : added 2 instead of 1 because the 'all' field has been removed
180 return levelMin
, levelMax
, ecosystem
183 function r2
:createRoad()
185 r2
:setCurrentTool('R2::CToolDrawPrim', { Look
= r2
.PrimRender
.RoadCreateLook
,
186 InvalidLook
= r2
.PrimRender
.RoadCreateInvalidLook
,
187 Type
="Road", ForceShowPrims
=true })
190 function r2
:createRegion()
192 r2
:setCurrentTool('R2::CToolDrawPrim',
194 Look
= r2
.PrimRender
.RegionCreateLook
,
195 InvalidLook
= r2
.PrimRender
.RegionCreateInvalidLook
,
196 CanCloseLook
= r2
.PrimRender
.RegionCreateCanCloseLook
,
198 SelectInstance
= true,
204 ---------------------------------------------------------------------------------------------------------
205 -- TMP for demo : assign default custom bbox to mobs
206 --function r2:setupDefaultCustomBBoxes()
207 -- for id, node in pairs(r2.Palette.ShortIdToElement) do
208 -- if string.match(node.Base, "palette.entities.creatures.*") then
219 -- r2:setEntityCustomSelectBox(node.SheetClient, box)