shiplcdbox.lua

--- Gauges that sit at the bottom and do gauge things related to things to do on a ship.
--@classmod ShipLCDBox

ShipLCDBox = {}

ShipLCDBox.update = function()

end
--_updateHandler





-------------------------------------------------------
--- Initialisation
-- @section initialisation

--- Creates a new instance of the ShipLCDBox class.
-- @tparam string _instanceName Instance name, should be identical to variable instance is assigned to.
-- @tparam int _elementX X position of
-- @tparam int _elementY
-- @tparam string _inputText Text to display.
-- @tparam test _backingText Dark backing text to mimic unlit LCD segments.
-- @tparam int[opt=30] _fontSize Font size of the attached text.
-- @tparam string[opt="HotPink"] _fontColour Font colour in a QtCSS compatible string.
-- @treturn table A new instance of the ShipLCDBox class.
-- @usage lcds = ShipLCDBox:new("lcds")
function ShipLCDBox:new(_instanceName, _elementX, _elementY, _inputText, _backingText, _fontSize, _fontColour)

    cloudDir = cloudDir or [[D:\Achaea\]]
    self.__index = ShipLCDBox
    local self = setmetatable({}, ShipLCDBox)

    --===============================
    -- BASIC ATTRIBUTES

    self._instanceName = _instanceName
    self._fontSize = _fontSize or 30
    self._fontName = "DSEG7 Classic Mini-Bold Italic"
    self._padding = 4
    self._fontColour = _fontColour or "HotPink"

    registerAnonymousEventHandler( "ship prompt processed", self._instanceName..":update")

    self._LCD_CSS = CSSMan.new([[
        background-color: #00000000;
        border-style: solid;
        border-color: white;
        border-width: 0px;
        border-radius: 0px;
        margin: 0px;
        qproperty-alignment: 'AlignHCenter | AlignVCenter';
        font-family: "]]..self._fontName..[[", sans-serif;
    ]])

    self._LCD_off_CSS = CSSMan.new([[
        background-color: #00000000;
        border-style: solid;
        border-color: white;
        border-width: 0px;
        border-radius: 0px;
        margin: 0px;
        qproperty-alignment: 'AlignHCenter | AlignVCenter';
        font-family: "]]..self._fontName..[[", sans-serif;
        color: #333333;
    ]])

    self._updateHandler = self._updateHandler or registerAnonymousEventHandler("svo done with prompt", self._instanceName..":update")

    --===============================
    -- MAIN CONTAINER
    _charW,_charH   = calcFontSize(self._fontSize, self._fontName)
    _elementWidth   = (math.max( string.len(_inputText), string.len(_backingText) )*_charW) + (self._padding*2)
    _elementHeight  = _charH + (self._padding*2)

    self._container = Geyser.Label:new({ name = self._instanceName.."._container", x = _elementX, y = _elementY, width = _elementWidth, height = _elementHeight })

    --========================================================================--
    -- LABELS

    --self._labelBackground  = Geyser.Label:new({ name = self._instanceName.."._labelBackground",  x = 0,   y = 0, width  = 980, height = 26 }, self._container )
    self._labelForegroundText = Geyser.Label:new({ name = self._instanceName.."._labelForegroundText", x = 0, y = 0, width  = "100%",  height = "100%", color = "#007700" }, self._container )
    self._labelBackgroundText = Geyser.Label:new({ name = self._instanceName.."._labelBackgroundText", x = 0, y = 0, width  = "100%",  height = "100%", color = "#007700" }, self._container )

    --===============================
    -- LABEL STYLESHEETS AND IMAGES

    self._container:setStyleSheet( [[background-color: #00000000;]] )

    self._labelForegroundText:setStyleSheet(self._LCD_CSS:getCSS())
    self._labelBackgroundText:setStyleSheet(self._LCD_off_CSS:getCSS())

    --===============================
    -- LABEL ECHOES

    self._labelForegroundText:echo( tostring( _inputText ), self._fontColour, "r"..tostring(self._fontSize) )
    self._labelBackgroundText:echo( tostring(_backingText), "#333333", "r"..tostring(self._fontSize) )

    self._container:raiseAll()
    self._labelBackgroundText:raise()
    self._labelForegroundText:raise()

    return self

end





--------------------------------------------------------------------------------
--- Misc methods
-- @section misc
--------------------------------------------------------------------------------

--- Shows or hides the whole object on the screen.
-- Just a shortcut for things like getting into my ship UI.
-- @tparam bool _visible True to show object, false to hide.
-- @usage ShipLCDBox:setVisible(true)
function ShipLCDBox:setVisible(_visible)
    if _visible then
        self._container:show()
    else
        self._container:hide()
    end
end

--- Shows or hides the whole object on the screen.
-- Just a shortcut for things like getting into my ship UI.
-- @tparam table _positionTable Key/value table, with key being
-- @tparam string _type Type of display to instantiate. Valid options are hull, sails, speed, 'wind`
-- @usage ShipLCDBox:setVisible(true)
function ShipLCDBox:build(_positionTable, _type)
    self.hull  = ShipLCDBox:new(self._instanceName..".hull",  846, 808, "42", "88", 36, "green")
    self.sails = ShipLCDBox:new(self._instanceName..".sails", 846, 923, "42", "88", 36, "green")
    self.speed = ShipLCDBox:new(self._instanceName..".speed", 330, 941, "42", "88", 28, "cyan" )
    self.wind  = ShipLCDBox:new(self._instanceName..".wind",  24,  941, "42", "88", 28, "cyan" )
end
generated by LDoc 1.4.3 Last updated 2021-01-24 20:08:44