shipcompass.lua
ShipCompass = {}
function ShipCompass:new(_instanceName, _x, _y)
ShipCompass.__index = ShipCompass
local self = setmetatable({}, ShipCompass)
self._instanceName = tostring(_instanceName)
self.container = Geyser.Label:new({
name = self._instanceName..".container",
x = _x, y = _y,
width = 483, height = 456,
})
self.courseNeedle = Geyser.Label:new({
name = self._instanceName..".courseNeedle",
x = 42, y = 22,
width = 310, height = 310,
}, self.container)
self.windNeedle = Geyser.Label:new({
name = self._instanceName..".windNeedle",
x = 42, y = 22,
width = 310, height = 310,
}, self.container)
self.bearingNeedle = Geyser.Label:new({
name = self._instanceName..".bearingNeedle",
x = 35, y = 20,
width = 324, height = 324,
}, self.container)
self.container:setStyleSheet([[background-color: #00000000;]])
self.bearingNeedle:raise()
self.windNeedle:raise()
self.courseNeedle:raise()
self:setCourseNeedle("n")
self:setWindNeedle("n")
self:setBearingNeedle(0)
self._updateHandler = self._updateHandler or registerAnonymousEventHandler("ship done with prompt", self._instanceName..":update")
return self
end
function ShipCompass:setCourseNeedle(_direction)
_direction = string.lower(_direction)
self.courseNeedle:setStyleSheet([[
background-color: #00000000;
border-image: url(]]..cloudDir:gsub("\\","/")..[[GUI/images/needles/big16/]].._direction..[[.png);
]])
self.courseNeedle._displayed = _direction
end
----------------------------------------
--- Sets the orientation of the wind needle.
-- @tparam string _direction Direction in short format.
-- @usage compass:setWindNeedle("ne")
function ShipCompass:setWindNeedle(_direction)
_direction = string.lower(_direction)
self.windNeedle:setStyleSheet([[
background-color: #00000000;
border-image: url(]]..cloudDir:gsub("\\","/")..[[GUI/images/needles/bigred16/]].._direction..[[.png);
]])
self.windNeedle._displayed = _direction
end
----------------------------------------
--- Sets the orientation of the bearing needle.
-- @tparam int _direction Direction in rounded degrees.
-- @usage compass:setBearingNeedle(270)
function ShipCompass:setBearingNeedle(_direction)
_direction = string.lower(_direction)
self.bearingNeedle:setStyleSheet([[
background-color: #00000000;
border-image: url(]]..cloudDir:gsub("\\","/")..[[GUI/images/needles/outer360/]].._direction..[[.png);
]])
self.bearingNeedle._displayed = _direction
end
function ShipCompass:move(to_X,to_Y)
self.container:move(to_X,to_Y)
end
function ShipCompass:update(...)
local promptTable = arg[2]
self:setCourseNeedle (promptTable._course)
self:setWindNeedle (promptTable._windDirection)
end