39_CrowdNavigation.lua 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. -- CrowdNavigation example.
  2. -- This sample demonstrates:
  3. -- - Generating a dynamic navigation mesh into the scene
  4. -- - Performing path queries to the navigation mesh
  5. -- - Adding and removing obstacles/agents at runtime
  6. -- - Raycasting drawable components
  7. -- - Crowd movement management
  8. -- - Accessing crowd agents with the crowd manager
  9. -- - Using off-mesh connections to make boxes climbable
  10. -- - Using agents to simulate moving obstacles
  11. require "LuaScripts/Utilities/Sample"
  12. local INSTRUCTION = "instructionText"
  13. function Start()
  14. -- Execute the common startup for samples
  15. SampleStart()
  16. -- Create the scene content
  17. CreateScene()
  18. -- Create the UI content
  19. CreateUI()
  20. -- Setup the viewport for displaying the scene
  21. SetupViewport()
  22. -- Hook up to the frame update and render post-update events
  23. SubscribeToEvents()
  24. end
  25. function CreateScene()
  26. scene_ = Scene()
  27. -- Create octree, use default volume (-1000, -1000, -1000) to (1000, 1000, 1000)
  28. -- Also create a DebugRenderer component so that we can draw debug geometry
  29. scene_:CreateComponent("Octree")
  30. scene_:CreateComponent("DebugRenderer")
  31. -- Create scene node & StaticModel component for showing a static plane
  32. local planeNode = scene_:CreateChild("Plane")
  33. planeNode.scale = Vector3(100.0, 1.0, 100.0)
  34. local planeObject = planeNode:CreateComponent("StaticModel")
  35. planeObject.model = cache:GetResource("Model", "Models/Plane.mdl")
  36. planeObject.material = cache:GetResource("Material", "Materials/StoneTiled.xml")
  37. -- Create a Zone component for ambient lighting & fog control
  38. local zoneNode = scene_:CreateChild("Zone")
  39. local zone = zoneNode:CreateComponent("Zone")
  40. zone.boundingBox = BoundingBox(-1000.0, 1000.0)
  41. zone.ambientColor = Color(0.15, 0.15, 0.15)
  42. zone.fogColor = Color(0.5, 0.5, 0.7)
  43. zone.fogStart = 100.0
  44. zone.fogEnd = 300.0
  45. -- Create a directional light to the world. Enable cascaded shadows on it
  46. local lightNode = scene_:CreateChild("DirectionalLight")
  47. lightNode.direction = Vector3(0.6, -1.0, 0.8)
  48. local light = lightNode:CreateComponent("Light")
  49. light.lightType = LIGHT_DIRECTIONAL
  50. light.castShadows = true
  51. light.shadowBias = BiasParameters(0.00025, 0.5)
  52. -- Set cascade splits at 10, 50 and 200 world units, fade shadows out at 80% of maximum shadow distance
  53. light.shadowCascade = CascadeParameters(10.0, 50.0, 200.0, 0.0, 0.8)
  54. -- Create randomly sized boxes. If boxes are big enough, make them occluders. Occluders will be software rasterized before
  55. -- rendering to a low-resolution depth-only buffer to test the objects in the view frustum for visibility
  56. local boxGroup = scene_:CreateChild("Boxes")
  57. for i = 1, 20 do
  58. local boxNode = boxGroup:CreateChild("Box")
  59. local size = 1.0 + Random(10.0)
  60. boxNode.position = Vector3(Random(80.0) - 40.0, size * 0.5, Random(80.0) - 40.0)
  61. boxNode:SetScale(size)
  62. local boxObject = boxNode:CreateComponent("StaticModel")
  63. boxObject.model = cache:GetResource("Model", "Models/Box.mdl")
  64. boxObject.material = cache:GetResource("Material", "Materials/Stone.xml")
  65. boxObject.castShadows = true
  66. if size >= 3.0 then
  67. boxObject.occluder = true
  68. end
  69. end
  70. -- Create a DynamicNavigationMesh component to the scene root
  71. local navMesh = scene_:CreateComponent("DynamicNavigationMesh")
  72. -- Enable drawing debug geometry for obstacles and off-mesh connections
  73. navMesh.drawObstacles = true
  74. navMesh.drawOffMeshConnections = true
  75. -- Set the agent height large enough to exclude the layers under boxes
  76. navMesh.agentHeight = 10
  77. -- Set nav mesh cell height to minimum (allows agents to be grounded)
  78. navMesh.cellHeight = 0.05
  79. -- Create a Navigable component to the scene root. This tags all of the geometry in the scene as being part of the
  80. -- navigation mesh. By default this is recursive, but the recursion could be turned off from Navigable
  81. scene_:CreateComponent("Navigable")
  82. -- Add padding to the navigation mesh in Y-direction so that we can add objects on top of the tallest boxes
  83. -- in the scene and still update the mesh correctly
  84. navMesh.padding = Vector3(0.0, 10.0, 0.0)
  85. -- Now build the navigation geometry. This will take some time. Note that the navigation mesh will prefer to use
  86. -- physics geometry from the scene nodes, as it often is simpler, but if it can not find any (like in this example)
  87. -- it will use renderable geometry instead
  88. navMesh:Build()
  89. -- Create an off-mesh connection for each box to make it climbable (tiny boxes are skipped).
  90. -- Note that OffMeshConnections must be added before building the navMesh, but as we are adding Obstacles next, tiles will be automatically rebuilt.
  91. -- Creating connections post-build here allows us to use FindNearestPoint() to procedurally set accurate positions for the connection
  92. CreateBoxOffMeshConnections(navMesh, boxGroup)
  93. -- Create some mushrooms as obstacles. Note that obstacles are non-walkable areas
  94. for i = 1, 100 do
  95. CreateMushroom(Vector3(Random(90.0) - 45.0, 0.0, Random(90.0) - 45.0))
  96. end
  97. -- Create a DetourCrowdManager component to the scene root (mandatory for crowd agents)
  98. scene_:CreateComponent("DetourCrowdManager")
  99. -- Create some movable barrels. We create them as crowd agents, as for moving entities it is less expensive and more convenient than using obstacles
  100. CreateMovingBarrels(navMesh)
  101. -- Create Jack node as crowd agent
  102. SpawnJack(Vector3(-5, 0, 20))
  103. -- Create the camera. Limit far clip distance to match the fog. Note: now we actually create the camera node outside
  104. -- the scene, because we want it to be unaffected by scene load / save
  105. cameraNode = Node()
  106. local camera = cameraNode:CreateComponent("Camera")
  107. camera.farClip = 300.0
  108. -- Set an initial position for the camera scene node above the plane and looking down
  109. cameraNode.position = Vector3(0.0, 50.0, 0.0)
  110. pitch = 80.0
  111. cameraNode.rotation = Quaternion(pitch, yaw, 0.0)
  112. end
  113. function CreateUI()
  114. -- Create a Cursor UI element because we want to be able to hide and show it at will. When hidden, the mouse cursor will
  115. -- control the camera, and when visible, it will point the raycast target
  116. local style = cache:GetResource("XMLFile", "UI/DefaultStyle.xml")
  117. local cursor = Cursor:new()
  118. cursor:SetStyleAuto(style)
  119. ui.cursor = cursor
  120. -- Set starting position of the cursor at the rendering window center
  121. cursor:SetPosition(graphics.width / 2, graphics.height / 2)
  122. -- Construct new Text object, set string to display and font to use
  123. local instructionText = ui.root:CreateChild("Text", INSTRUCTION)
  124. instructionText.text = "Use WASD keys to move, RMB to rotate view\n"..
  125. "LMB to set destination, SHIFT+LMB to spawn a Jack\n"..
  126. "CTRL+LMB to teleport main agent\n"..
  127. "MMB to add obstacles or remove obstacles/agents\n"..
  128. "F5 to save scene, F7 to load\n"..
  129. "Space to toggle debug geometry\n"..
  130. "F12 to toggle this instruction text"
  131. instructionText:SetFont(cache:GetResource("Font", "Fonts/Anonymous Pro.ttf"), 15)
  132. -- The text has multiple rows. Center them in relation to each other
  133. instructionText.textAlignment = HA_CENTER
  134. -- Position the text relative to the screen center
  135. instructionText.horizontalAlignment = HA_CENTER
  136. instructionText.verticalAlignment = VA_CENTER
  137. instructionText:SetPosition(0, ui.root.height / 4)
  138. end
  139. function SetupViewport()
  140. -- Set up a viewport to the Renderer subsystem so that the 3D scene can be seen
  141. local viewport = Viewport:new(scene_, cameraNode:GetComponent("Camera"))
  142. renderer:SetViewport(0, viewport)
  143. end
  144. function SubscribeToEvents()
  145. -- Subscribe HandleUpdate() function for processing update events
  146. SubscribeToEvent("Update", "HandleUpdate")
  147. -- Subscribe HandlePostRenderUpdate() function for processing the post-render update event, during which we request debug geometry
  148. SubscribeToEvent("PostRenderUpdate", "HandlePostRenderUpdate")
  149. -- Subscribe HandleCrowdAgentFailure() function for resolving invalidation issues with agents, during which we
  150. -- use a larger extents for finding a point on the navmesh to fix the agent's position
  151. SubscribeToEvent("CrowdAgentFailure", "HandleCrowdAgentFailure")
  152. -- Subscribe HandleCrowdAgentReposition() function for controlling the animation
  153. SubscribeToEvent("CrowdAgentReposition", "HandleCrowdAgentReposition")
  154. end
  155. function SpawnJack(pos)
  156. local jackNode = scene_:CreateChild("Jack")
  157. jackNode.position = pos
  158. local modelObject = jackNode:CreateComponent("AnimatedModel")
  159. modelObject.model = cache:GetResource("Model", "Models/Jack.mdl")
  160. modelObject.material = cache:GetResource("Material", "Materials/Jack.xml")
  161. modelObject.castShadows = true
  162. jackNode:CreateComponent("AnimationController")
  163. -- Create a CrowdAgent component and set its height and realistic max speed/acceleration. Use default radius
  164. local agent = jackNode:CreateComponent("CrowdAgent")
  165. agent.height = 2.0
  166. agent.maxSpeed = 3.0
  167. agent.maxAccel = 3.0
  168. end
  169. function CreateMushroom(pos)
  170. local mushroomNode = scene_:CreateChild("Mushroom")
  171. mushroomNode.position = pos
  172. mushroomNode.rotation = Quaternion(0.0, Random(360.0), 0.0)
  173. mushroomNode:SetScale(2.0 + Random(0.5))
  174. local mushroomObject = mushroomNode:CreateComponent("StaticModel")
  175. mushroomObject.model = cache:GetResource("Model", "Models/Mushroom.mdl")
  176. mushroomObject.material = cache:GetResource("Material", "Materials/Mushroom.xml")
  177. mushroomObject.castShadows = true
  178. -- Create the navigation Obstacle component and set its height & radius proportional to scale
  179. local obstacle = mushroomNode:CreateComponent("Obstacle")
  180. obstacle.radius = mushroomNode.scale.x
  181. obstacle.height = mushroomNode.scale.y
  182. end
  183. function CreateBoxOffMeshConnections(navMesh, boxGroup)
  184. boxes = boxGroup:GetChildren()
  185. for i, box in ipairs(boxes) do
  186. local boxPos = box.position
  187. local boxHalfSize = box.scale.x / 2
  188. -- Create 2 empty nodes for the start & end points of the connection. Note that order matters only when using one-way/unidirectional connection.
  189. local connectionStart = box:CreateChild("ConnectionStart")
  190. connectionStart.worldPosition = navMesh:FindNearestPoint(boxPos + Vector3(boxHalfSize, -boxHalfSize, 0)) -- Base of box
  191. local connectionEnd = connectionStart:CreateChild("ConnectionEnd")
  192. connectionEnd.worldPosition = navMesh:FindNearestPoint(boxPos + Vector3(boxHalfSize, boxHalfSize, 0)) -- Top of box
  193. -- Create the OffMeshConnection component to one node and link the other node
  194. local connection = connectionStart:CreateComponent("OffMeshConnection")
  195. connection.endPoint = connectionEnd
  196. end
  197. end
  198. function CreateMovingBarrels(navMesh)
  199. local barrel = scene_:CreateChild("Barrel")
  200. local model = barrel:CreateComponent("StaticModel")
  201. model.model = cache:GetResource("Model", "Models/Cylinder.mdl")
  202. model.material = cache:GetResource("Material", "Materials/StoneTiled.xml")
  203. model.material:SetTexture(TU_DIFFUSE, cache:GetResource("Texture2D", "Textures/TerrainDetail2.dds"))
  204. model.castShadows = true
  205. for i = 1, 20 do
  206. local clone = barrel:Clone()
  207. local size = 0.5 + Random(1)
  208. clone.scale = Vector3(size / 1.5, size * 2, size / 1.5)
  209. clone.position = navMesh:FindNearestPoint(Vector3(Random(80.0) - 40.0, size * 0.5 , Random(80.0) - 40.0))
  210. local agent = clone:CreateComponent("CrowdAgent")
  211. agent.radius = clone.scale.x * 0.5
  212. agent.height = size
  213. end
  214. barrel:Remove()
  215. end
  216. function SetPathPoint(spawning)
  217. local hitPos, hitDrawable = Raycast(250.0)
  218. if hitDrawable then
  219. local navMesh = scene_:GetComponent("DynamicNavigationMesh")
  220. local pathPos = navMesh:FindNearestPoint(hitPos, Vector3.ONE)
  221. if spawning then
  222. -- Spawn a jack at the target position
  223. SpawnJack(pathPos)
  224. else
  225. -- Set crowd agents target position
  226. scene_:GetComponent("DetourCrowdManager"):SetCrowdTarget(pathPos)
  227. end
  228. end
  229. end
  230. function AddOrRemoveObject()
  231. -- Raycast and check if we hit a mushroom node. If yes, remove it, if no, create a new one
  232. local hitPos, hitDrawable = Raycast(250.0)
  233. if hitDrawable then
  234. local hitNode = hitDrawable.node
  235. if hitNode.name == "Mushroom" then
  236. hitNode:Remove()
  237. elseif hitNode.name == "Jack" then
  238. hitNode:Remove()
  239. else
  240. CreateMushroom(hitPos)
  241. end
  242. end
  243. end
  244. function Raycast(maxDistance)
  245. local pos = ui.cursorPosition
  246. -- Check the cursor is visible and there is no UI element in front of the cursor
  247. if (not ui.cursor.visible) or (ui:GetElementAt(pos, true) ~= nil) then
  248. return nil, nil
  249. end
  250. local camera = cameraNode:GetComponent("Camera")
  251. local cameraRay = camera:GetScreenRay(pos.x / graphics.width, pos.y / graphics.height)
  252. -- Pick only geometry objects, not eg. zones or lights, only get the first (closest) hit
  253. local octree = scene_:GetComponent("Octree")
  254. local result = octree:RaycastSingle(cameraRay, RAY_TRIANGLE, maxDistance, DRAWABLE_GEOMETRY)
  255. if result.drawable ~= nil then
  256. return result.position, result.drawable
  257. end
  258. return nil, nil
  259. end
  260. function MoveCamera(timeStep)
  261. -- Right mouse button controls mouse cursor visibility: hide when pressed
  262. ui.cursor.visible = not input:GetMouseButtonDown(MOUSEB_RIGHT)
  263. -- Do not move if the UI has a focused element (the console)
  264. if ui.focusElement ~= nil then
  265. return
  266. end
  267. -- Movement speed as world units per second
  268. local MOVE_SPEED = 20.0
  269. -- Mouse sensitivity as degrees per pixel
  270. local MOUSE_SENSITIVITY = 0.1
  271. -- Use this frame's mouse motion to adjust camera node yaw and pitch. Clamp the pitch between -90 and 90 degrees
  272. -- Only move the camera when the cursor is hidden
  273. if not ui.cursor.visible then
  274. local mouseMove = input.mouseMove
  275. yaw = yaw + MOUSE_SENSITIVITY * mouseMove.x
  276. pitch = pitch + MOUSE_SENSITIVITY * mouseMove.y
  277. pitch = Clamp(pitch, -90.0, 90.0)
  278. -- Construct new orientation for the camera scene node from yaw and pitch. Roll is fixed to zero
  279. cameraNode.rotation = Quaternion(pitch, yaw, 0.0)
  280. end
  281. -- Read WASD keys and move the camera scene node to the corresponding direction if they are pressed
  282. if input:GetKeyDown(KEY_W) then
  283. cameraNode:Translate(Vector3(0.0, 0.0, 1.0) * MOVE_SPEED * timeStep)
  284. end
  285. if input:GetKeyDown(KEY_S) then
  286. cameraNode:Translate(Vector3(0.0, 0.0, -1.0) * MOVE_SPEED * timeStep)
  287. end
  288. if input:GetKeyDown(KEY_A) then
  289. cameraNode:Translate(Vector3(-1.0, 0.0, 0.0) * MOVE_SPEED * timeStep)
  290. end
  291. if input:GetKeyDown(KEY_D) then
  292. cameraNode:Translate(Vector3(1.0, 0.0, 0.0) * MOVE_SPEED * timeStep)
  293. end
  294. -- Set destination or spawn a jack with left mouse button
  295. if input:GetMouseButtonPress(MOUSEB_LEFT) then
  296. SetPathPoint(input:GetQualifierDown(QUAL_SHIFT))
  297. -- Add new obstacle or remove existing obstacle/agent with middle mouse button
  298. elseif input:GetMouseButtonPress(MOUSEB_MIDDLE) then
  299. AddOrRemoveObject()
  300. end
  301. -- Check for loading/saving the scene from/to the file Data/Scenes/CrowdNavigation.xml relative to the executable directory
  302. if input:GetKeyPress(KEY_F5) then
  303. scene_:SaveXML(fileSystem:GetProgramDir().."Data/Scenes/CrowdNavigation.xml")
  304. elseif input:GetKeyPress(KEY_F7) then
  305. scene_:LoadXML(fileSystem:GetProgramDir().."Data/Scenes/CrowdNavigation.xml")
  306. -- Toggle debug geometry with space
  307. elseif input:GetKeyPress(KEY_SPACE) then
  308. drawDebug = not drawDebug
  309. -- Toggle instruction text with F12
  310. elseif input:GetKeyPress(KEY_F12) then
  311. instruction = ui.root:GetChild(INSTRUCTION)
  312. instruction.visible = not instruction.visible
  313. end
  314. end
  315. function HandleUpdate(eventType, eventData)
  316. -- Take the frame time step, which is stored as a float
  317. local timeStep = eventData:GetFloat("TimeStep")
  318. -- Move the camera, scale movement with time step
  319. MoveCamera(timeStep)
  320. end
  321. function HandlePostRenderUpdate(eventType, eventData)
  322. if drawDebug then
  323. -- Visualize navigation mesh, obstacles and off-mesh connections
  324. scene_:GetComponent("DynamicNavigationMesh"):DrawDebugGeometry(true)
  325. -- Visualize agents' path and position to reach
  326. scene_:GetComponent("DetourCrowdManager"):DrawDebugGeometry(true)
  327. end
  328. end
  329. function HandleCrowdAgentFailure(eventType, eventData)
  330. local node = eventData:GetPtr("Node", "Node")
  331. local agentState = eventData:GetInt("CrowdAgentState")
  332. -- If the agent's state is invalid, likely from spawning on the side of a box, find a point in a larger area
  333. if agentState == CROWD_AGENT_INVALID then
  334. -- Get a point on the navmesh using more generous extents
  335. local newPos = scene_:GetComponent("DynamicNavigationMesh"):FindNearestPoint(node.position, Vector3(5, 5, 5))
  336. -- Set the new node position, CrowdAgent component will automatically reset the state of the agent
  337. node.position = newPos
  338. end
  339. end
  340. function HandleCrowdAgentReposition(eventType, eventData)
  341. local WALKING_ANI = "Models/Jack_Walk.ani"
  342. local node = eventData:GetPtr("Node", "Node")
  343. local agent = eventData:GetPtr("CrowdAgent", "CrowdAgent")
  344. local velocity = eventData:GetVector3("Velocity")
  345. -- Only Jack agent has animation controller
  346. local animCtrl = node:GetComponent("AnimationController")
  347. if animCtrl ~= nil then
  348. local speed = velocity:Length()
  349. if animCtrl:IsPlaying(WALKING_ANI) then
  350. local speedRatio = speed / agent.maxSpeed
  351. -- Face the direction of its velocity but moderate the turning speed based on the speed ratio as we do not have timeStep here
  352. node.rotation = node.rotation:Slerp(Quaternion(Vector3.FORWARD, velocity), 0.1 * speedRatio)
  353. -- Throttle the animation speed based on agent speed ratio (ratio = 1 is full throttle)
  354. animCtrl:SetSpeed(WALKING_ANI, speedRatio)
  355. else
  356. animCtrl:Play(WALKING_ANI, 0, true, 0.1)
  357. end
  358. -- If speed is too low then stopping the animation
  359. if speed < agent.radius then
  360. animCtrl:Stop(WALKING_ANI, 0.8)
  361. end
  362. end
  363. end
  364. -- Create XML patch instructions for screen joystick layout specific to this sample app
  365. function GetScreenJoystickPatchString()
  366. return
  367. "<patch>" ..
  368. " <add sel=\"/element\">" ..
  369. " <element type=\"Button\">" ..
  370. " <attribute name=\"Name\" value=\"Button3\" />" ..
  371. " <attribute name=\"Position\" value=\"-120 -120\" />" ..
  372. " <attribute name=\"Size\" value=\"96 96\" />" ..
  373. " <attribute name=\"Horiz Alignment\" value=\"Right\" />" ..
  374. " <attribute name=\"Vert Alignment\" value=\"Bottom\" />" ..
  375. " <attribute name=\"Texture\" value=\"Texture2D;Textures/TouchInput.png\" />" ..
  376. " <attribute name=\"Image Rect\" value=\"96 0 192 96\" />" ..
  377. " <attribute name=\"Hover Image Offset\" value=\"0 0\" />" ..
  378. " <attribute name=\"Pressed Image Offset\" value=\"0 0\" />" ..
  379. " <element type=\"Text\">" ..
  380. " <attribute name=\"Name\" value=\"Label\" />" ..
  381. " <attribute name=\"Horiz Alignment\" value=\"Center\" />" ..
  382. " <attribute name=\"Vert Alignment\" value=\"Center\" />" ..
  383. " <attribute name=\"Color\" value=\"0 0 0 1\" />" ..
  384. " <attribute name=\"Text\" value=\"Spawn Jack\" />" ..
  385. " </element>" ..
  386. " <element type=\"Text\">" ..
  387. " <attribute name=\"Name\" value=\"KeyBinding\" />" ..
  388. " <attribute name=\"Text\" value=\"LSHIFT\" />" ..
  389. " </element>" ..
  390. " <element type=\"Text\">" ..
  391. " <attribute name=\"Name\" value=\"MouseButtonBinding\" />" ..
  392. " <attribute name=\"Text\" value=\"LEFT\" />" ..
  393. " </element>" ..
  394. " </element>" ..
  395. " <element type=\"Button\">" ..
  396. " <attribute name=\"Name\" value=\"Button4\" />" ..
  397. " <attribute name=\"Position\" value=\"-120 -12\" />" ..
  398. " <attribute name=\"Size\" value=\"96 96\" />" ..
  399. " <attribute name=\"Horiz Alignment\" value=\"Right\" />" ..
  400. " <attribute name=\"Vert Alignment\" value=\"Bottom\" />" ..
  401. " <attribute name=\"Texture\" value=\"Texture2D;Textures/TouchInput.png\" />" ..
  402. " <attribute name=\"Image Rect\" value=\"96 0 192 96\" />" ..
  403. " <attribute name=\"Hover Image Offset\" value=\"0 0\" />" ..
  404. " <attribute name=\"Pressed Image Offset\" value=\"0 0\" />" ..
  405. " <element type=\"Text\">" ..
  406. " <attribute name=\"Name\" value=\"Label\" />" ..
  407. " <attribute name=\"Horiz Alignment\" value=\"Center\" />" ..
  408. " <attribute name=\"Vert Alignment\" value=\"Center\" />" ..
  409. " <attribute name=\"Color\" value=\"0 0 0 1\" />" ..
  410. " <attribute name=\"Text\" value=\"Obstacles\" />" ..
  411. " </element>" ..
  412. " <element type=\"Text\">" ..
  413. " <attribute name=\"Name\" value=\"MouseButtonBinding\" />" ..
  414. " <attribute name=\"Text\" value=\"MIDDLE\" />" ..
  415. " </element>" ..
  416. " </element>" ..
  417. " </add>" ..
  418. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/attribute[@name='Is Visible']\" />" ..
  419. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Set</replace>" ..
  420. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]\">" ..
  421. " <element type=\"Text\">" ..
  422. " <attribute name=\"Name\" value=\"MouseButtonBinding\" />" ..
  423. " <attribute name=\"Text\" value=\"LEFT\" />" ..
  424. " </element>" ..
  425. " </add>" ..
  426. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/attribute[@name='Is Visible']\" />" ..
  427. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Debug</replace>" ..
  428. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]\">" ..
  429. " <element type=\"Text\">" ..
  430. " <attribute name=\"Name\" value=\"KeyBinding\" />" ..
  431. " <attribute name=\"Text\" value=\"SPACE\" />" ..
  432. " </element>" ..
  433. " </add>" ..
  434. "</patch>"
  435. end