Forged Alliance Forever Forged Alliance Forever Forums 2016-11-14T11:43:38+02:00 /feed.php?f=3&t=13487 2016-11-14T11:43:38+02:00 2016-11-14T11:43:38+02:00 /viewtopic.php?t=13487&p=139047#p139047 <![CDATA[Re: PrintText location values]]> Statistics: Posted by EntropyWins — 14 Nov 2016, 11:43


]]>
2016-11-14T10:39:38+02:00 2016-11-14T10:39:38+02:00 /viewtopic.php?t=13487&p=139045#p139045 <![CDATA[Re: PrintText location values]]> https://github.com/FAForever/fa

If you know how sync betweek sim and ui works, this should answer your question https://github.com/FAForever/fa/search?utf8=%E2%9C%93&q=printtext if not, let me know.

Statistics: Posted by speed2 — 14 Nov 2016, 10:39


]]>
2016-11-14T09:49:16+02:00 2016-11-14T09:49:16+02:00 /viewtopic.php?t=13487&p=139040#p139040 <![CDATA[Re: PrintText location values]]>
I've actually created a little wrapper around PrintText in my code to have dependency injection, hide often not needed details, and have named parameters. Funnily enough the named parameters I came up with are exactly the same as those PrintToScreen has :D

Code:
newInstance = function()
    return {
        print = function(str, options)
            options = options or {}
            options.size = options.size or 20
            options.color = options.color or "ffffffff"
            options.duration = options.duration or 5
            options.location = options.location or "center"

            PrintText(str, options.size, options.color, options.duration, options.location);
        end
    }
end

Statistics: Posted by EntropyWins — 14 Nov 2016, 09:49


]]>
2016-11-14T09:43:12+02:00 2016-11-14T09:43:12+02:00 /viewtopic.php?t=13487&p=139038#p139038 <![CDATA[Re: PrintText location values]]>
Apparently I missed something when collecting the FAF lua files from all those archives, cause I don't have that file. Perhaps it's possible to set up some automated thing (integrated with the FAF build process maybe) that stuffs all those files into some public repo/place? That'd make things a lot easier to look up for modders and map makers. Alternatively a script that collects all those things from your local machine and stuffs it into a directory... does that already exist maybe?

Statistics: Posted by EntropyWins — 14 Nov 2016, 09:43


]]>
2016-11-14T09:32:50+02:00 2016-11-14T09:32:50+02:00 /viewtopic.php?t=13487&p=139037#p139037 <![CDATA[Re: PrintText location values]]>
Code:
local UIUtil = import('/lua/ui/uiutil.lua')
local LayoutHelpers = import('/lua/maui/layouthelpers.lua')

local locations = {
    lefttop = {'AtLeftIn', 'AtTopIn'},
    leftcenter = {'AtLeftIn', 'AtVerticalCenterIn'},
    leftbottom = {'AtLeftIn', 'AtBottomIn'},
    righttop = {'AtRightIn', 'AtTopIn'},
    rightcenter = {'AtRightIn', 'AtVerticalCenterIn'},
    rightbottom = {'AtRightIn', 'AtBottomIn'},
    centertop = {'AtHorizontalCenterIn', 'AtTopIn'},
    center = {'AtHorizontalCenterIn', 'AtVerticalCenterIn'},
    centerbottom = {'AtHorizontalCenterIn', 'AtBottomIn'},
}

local controls = {}
local worldView = import('/lua/ui/game/borders.lua').GetMapGroup()

function PrintToScreen(textData)
    if not locations[textData.location] then
        WARN('Trying to print text \"'..textData.text..'\" to an invalid location!')
        return false
    else
        local control = false
        local newControl = false
        if not controls[textData.location] then
            controls[textData.location] = {}
            newControl = true
        else   
            for index, textControl in controls[textData.location] do
                if not textControl.active then
                    control = textControl
                    break
                end
            end
        end
        if not control then
            control = UIUtil.CreateText(worldView, '', 12, UIUtil.bodyFont)
            control:DisableHitTest()
            control.Depth:Set(GetFrame(0):GetTopmostDepth() + 1)
            table.insert(controls[textData.location], control)
            if newControl then
                LayoutHelpers[locations[textData.location][1]](control, worldView)
                LayoutHelpers[locations[textData.location][2]](control, worldView)
            else
                LayoutHelpers.Below(control, controls[textData.location][table.getn(controls[textData.location])-1])
            end
        end
        control:SetText(textData.text)
        local color = 'ffffffff'
        if textData.color and type(textData.color) == 'string' and string.len(textData.color) == 8 then
            color = textData.color
        end
        control:SetColor(color)
        control:SetFont(UIUtil.bodyFont, textData.size)
        control.active = true
        control:Show()
        control:SetAlpha(1)
        if textData.duration then
            control.time = 0
            control:SetNeedsFrameUpdate(true)
            control.OnFrame = function(self, time)
                self.time = time + self.time
                if self.time > textData.duration then
                    local newAlpha = self:GetAlpha() - time
                    if newAlpha < 0 then
                        self:Hide()
                        self.active = false
                        self:SetNeedsFrameUpdate(false)
                    else
                        self:SetAlpha(newAlpha)
                    end
                end
            end
        end
    end
end

Statistics: Posted by speed2 — 14 Nov 2016, 09:32


]]>
2016-11-14T06:50:33+02:00 2016-11-14T06:50:33+02:00 /viewtopic.php?t=13487&p=139032#p139032 <![CDATA[PrintText location values]]> Statistics: Posted by EntropyWins — 14 Nov 2016, 06:50


]]>