9
updateFrameCountDown = -1, --this is used for triggering delayed render updates. If it's more than zero, it's decreased each frame until it's zero, and a render is then carried out. If it's below zero nothing is done.
14
function Compass.Refresh_Clicked(args)
15
Compass.helper:refresh()
16
Compass.helper:getMap():render()
20
function Compass.ZoomIn_Clicked(args)
21
local newResolution = Compass.helper:getMap():getResolution() - 0.2
22
--prevent the user from zooming in to much (at which point only one pixel from the head of the avatar will be seen
23
if newResolution > 0.2 then
24
Compass.helper:getMap():setResolution(newResolution)
25
Compass.helper:getMap():render()
26
Compass.helper:refresh()
30
function Compass.ZoomOut_Clicked(args)
31
local newResolution = Compass.helper:getMap():getResolution() + 0.2
32
--we'll use the arbitrary resolution of 5 as the max
33
if newResolution < 5 then
34
Compass.helper:getMap():setResolution(Compass.helper:getMap():getResolution() + 0.2)
35
Compass.helper:getMap():render()
36
Compass.helper:refresh()
43
function Compass.repositionAtAvatar()
44
local pos = emberOgre:getAvatar():getAvatarSceneNode():getPosition()
45
Compass.helper:reposition(pos.x, pos.z)
48
function Compass.framestarted(frameEvent)
49
if Compass.updateFrameCountDown > 0 then
50
Compass.updateFrameCountDown = Compass.updateFrameCountDown - 1
51
if Compass.updateFrameCountDown == 0 then
52
--if we haven't created any anchor yet, it means that the whole compass is uninitialized and needs to be shown, else we can just rerender the map
53
if Compass.anchor == nil then
56
Compass.helper:getMap():render()
57
Compass.helper:refresh()
59
Compass.updateFrameCountDown = -1
64
function Compass.TerrainPageGeometryUpdated(page)
65
--wait six frames until we rerender the map. This is a hack because apparently the event this listens for doesn't actually guarantee that the page will be rendered next frame. We need to add another event which is emitted when a page actually is rendered the first time.
66
Compass.updateFrameCountDown = 6
69
function Compass.initialize()
70
Compass.anchor = EmberOgre.Gui.CompassThirdPersonCameraAnchor:new_local(Compass.helper, emberOgre:getMainCamera():getCamera(), emberOgre:getMainCamera():getRootNode())
71
if Compass.widget ~= nil then
76
function Compass.CreatedAvatarEntity(avatarEntity)
77
connect(Compass.connectors, guiManager.EventFrameStarted, "Compass.framestarted")
80
function Compass.buildWidget()
81
Compass.helperImpl = EmberOgre.Gui.RenderedCompassImpl:new_local()
83
Compass.helper = EmberOgre.Gui.Compass:new_local(Compass.helperImpl)
84
Compass.map = Compass.helper:getMap()
87
Compass.buildCEGUIWidget()
89
--don't show the compass here, instead wait until we've gotten some terrain (by listening
90
connect(Compass.connectors, emberOgre.EventCreatedAvatarEntity, "Compass.CreatedAvatarEntity")
91
connect(Compass.connectors, emberOgre:getTerrainGenerator().EventTerrainPageGeometryUpdated, "Compass.TerrainPageGeometryUpdated")
95
-- Call this method to build the cegui widget.
96
function Compass.buildCEGUIWidget()
97
Compass.widget = guiManager:createWidget()
98
Compass.widget:loadMainSheet("Compass.layout", "Compass/")
99
Compass.widget:setIsActiveWindowOpaque(false)
100
Compass.renderImage = Compass.widget:getWindow("RenderImage")
101
Compass.pointerImage = Compass.widget:getWindow("Pointer")
103
local assetManager = EmberOgre.Gui.AssetsManager:new_local()
105
--set up the main background image
106
local texturePair = assetManager:createTextureImage(Compass.helperImpl:getTexture(), "CompassMap")
107
if texturePair:hasData() then
108
Compass.renderImage:setProperty("Image", CEGUI.PropertyHelper:imageToString(texturePair:getTextureImage()))
111
--also set up the pointer image
112
texturePair = assetManager:createTextureImage(Compass.helperImpl:getPointerTexture(), "CompassPointer")
113
if texturePair:hasData() then
114
Compass.pointerImage:setProperty("Image", CEGUI.PropertyHelper:imageToString(texturePair:getTextureImage()))
117
Compass.widget:hide()
122
Compass.buildWidget()
b'\\ No newline at end of file'