PrintText location values [SOLVED]

This is for troubleshooting of problems with the FAF client and Forged Alliance game.

Moderator: PhilipJFry

PrintText location values

Postby EntropyWins » 14 Nov 2016, 06:50

I'm looking for the contract of the PrintText function. In particular, which values it accepts for its 5th parameter "location".I know it accepts "center", but it does not accept either "left" or "top". What is allowed besides center?
EntropyWins
Avatar-of-War
 
Posts: 113
Joined: 02 Oct 2016, 20:26
Has liked: 18 times
Been liked: 4 times
FAF User Name: EntropyWins

Re: PrintText location values  [SOLVED]

Postby speed2 » 14 Nov 2016, 09:32

From /lua/ui/game/textdisplay.lua

Code: Select all
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
User avatar
speed2
Contributor
 
Posts: 3189
Joined: 05 Jan 2013, 15:11
Has liked: 636 times
Been liked: 1119 times
FAF User Name: speed2

Re: PrintText location values

Postby EntropyWins » 14 Nov 2016, 09:43

Thanks! That definitely answers my question.

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?
EntropyWins
Avatar-of-War
 
Posts: 113
Joined: 02 Oct 2016, 20:26
Has liked: 18 times
Been liked: 4 times
FAF User Name: EntropyWins

Re: PrintText location values

Postby EntropyWins » 14 Nov 2016, 09:49

On PrintText itself... what is its relationship to PrintToScreen? Does it call PrintToScreen? And if so, is there a reason to use PrintText rather than PrintToScreen directly?

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: Select all
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
EntropyWins
Avatar-of-War
 
Posts: 113
Joined: 02 Oct 2016, 20:26
Has liked: 18 times
Been liked: 4 times
FAF User Name: EntropyWins

Re: PrintText location values

Postby speed2 » 14 Nov 2016, 10:39

Well we have in our git repo only files we've changed 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.
User avatar
speed2
Contributor
 
Posts: 3189
Joined: 05 Jan 2013, 15:11
Has liked: 636 times
Been liked: 1119 times
FAF User Name: speed2

Re: PrintText location values

Postby EntropyWins » 14 Nov 2016, 11:43

So PrintText is sim and PrintToScreen is UI? I read some stuff about those two components on the wiki and get the basic gist.
EntropyWins
Avatar-of-War
 
Posts: 113
Joined: 02 Oct 2016, 20:26
Has liked: 18 times
Been liked: 4 times
FAF User Name: EntropyWins


Return to Tech Support

Who is online

Users browsing this forum: No registered users and 1 guest