Need help from players that are playing at high resolution

Discussion in 'Lua Discussions' started by CatweazleX, Nov 30, 2019.

Thread Status:
Not open for further replies.
  1. CatweazleX

    CatweazleX Avatar

    Messages:
    653
    Likes Received:
    777
    Trophy Points:
    93
    Location:
    Veritas Sanctuary
    Hi,

    i want to find out how to deal with the font size in a way that it is roughly the same on all monitors/resolution.
    Currently there is a problem with font sizes when a high resolution is set, the text is to small under high resolution conditions.

    You can type \info monitor <monitorsize> on the console. (Eg: \info monitor 24 - to say it is a 24 zoll monitor (zoll = inches?))

    Here are two simple mods to test. They need libsota.0.4.6-dev and libsota.util. Found here incl. the examples. (the libsota.lua there is the libsota.0.4.6-dev)

    Example to pin infos to the paperdoll (shows your virtues)
    Code:
    -- paperdoll by Catweazle Waldschrath
    -- depends on libsota.0.4.6
    
    
    function ShroudOnStart()
        ui.onInit(function()
         
            paperdoll = {}
            function paperdoll.refresh()
                local c = string.style(player.stat(317).value, { color = "#ef2929"})
                local l = string.style(player.stat(318).value, { color = "#ad7fa8"})
                local t = string.style(player.stat(319).value, { color = "#729fcf"})
                local f = string.style("Courage: %s Love: %s Truth: %s", { size=14 })
                setLabelCaption(paperdoll.label, string.format(f, c, l, t))
            end
            paperdoll.label = createLabelWithShadow()
            paperdoll.timer = setInterval(10, paperdoll.refresh)
            paperdoll.refresh()     
    
        end)
     
        ui.onClientWindow(function(which, what, window)
            if what == "moved" then
                moveLabelTo(paperdoll.label, window.left+3, window.top + window.height)
            elseif window.open then
                moveLabelTo(paperdoll.label, window.left+3, window.top + window.height)
                showLabel(paperdoll.label)
                resumeTimer(paperdoll.timer)
            else
                hideLabel(paperdoll.label)
                pauseTimer(paperdoll.timer)
            end
        end)
    end
    
    
    -- not needed
    function ShroudOnConsoleInput() end
    function ShroudOnGUI() end
    function ShroudOnUpdate() end
    
    
    A simple loctracker. (Does not vanish when you stand)
    Code:
    -- locTracker by Catweazle Waldschrath
    -- depends on libsota.0.4.6
    
    
    function ShroudOnStart()
    
    -- apis are ready, time to compose our mod. (initialize)
    ui.onInit(function()
        local styleStillness = { size=14, color="#c4a000", bold=true }
        local styleMoving = { size=14, color="yellow", bold=true }
        local styleStanding = { size=14, color="#edd400", bold=true }
    
        loctrack = {
            enabled = true,
            label = createLabelWithShadow(),
            timer = setInterval(0.25, function()
                local loc = player.location
                local caption = string.format("%s (x: %.2f, y: %.2f, z: %.2f)", loc.scene.name, loc.x, loc.y, loc.z)
             
                if player.isMoving then
                    caption = caption:style(styleMoving)
                elseif player.isStill then
                    caption = caption:style(styleStillness)
                else
                    caption = caption:style(styleStanding)
                end
    
                local r = caption:rect():moveTo(nil, 90)
                setLabelRect(loctrack.label, r)
                setLabelCaption(loctrack.label, caption)
            end),
        }
         
        ui.command.add("loctrack", function()
            loctrack.enabled = not loctrack.enabled
    
            setTimerEnabled(loctrack.timer, loctrack.enabled)
            setLabelVisible(loctrack.label, loctrack.enabled)
         
            local msg = createLabel(nil, nil, 200, 120)
            if isTimerEnabled(loctrack.timer) then
                setLabelCaption(msg, "<size=18><color=white>locTracker activated</color></size>")
            else
                setLabelCaption(msg, "<size=18><color=white>locTracker deactivated</color></size>")
            end
            showLabel(msg)
            setTimeout(3, function() ui.label.remove(msg) end)
        end)
        ui.shortcut.add("pressed", "RightAlt", "L", "loctrack")
    
    
        -- all mods are initialized, time to start/run
        ui.onStart(function()
            showLabel(loctrack.label)
        end)
     
    end)
    
    
    
    
    end -- ShroudOnStart
    
    -- implement other ShroudOn... to allow other scripts
    function ShroudOnConsoleInput() end
    function ShroudOnGUI() end
    function ShroudOnUpdate() end
    
    

    Would like to hear if this work, by setting the monitor size. Or that it does not work.

    Greetings
    Catweazle

    Edit:
    Updated libsota.0.4.6-dev. It should now display the text with the intended size without the need to enter \info monitor <monitorsize> first. But this command can still be used.
    If it is working, or not, please leave a post here. I would like to remove the \info monitor.
     
    Last edited: Nov 30, 2019
    Aeryk likes this.
  2. Toular

    Toular Avatar

    Messages:
    661
    Likes Received:
    631
    Trophy Points:
    93
    One thing I'm doing for that in my Lua scripts is to base the font size on ShroudGetScreenY. 1 / 90th seems to work pretty well. I then derive the linespace (intra-line spacing) on that font size.
    fontSize = ShroudGetScreenY() / 90
    linespace = fontSize * 1.2

    That should result in a more-or-less consistent font size across a variety of resolutions.
     
    CatweazleX likes this.
  3. CatweazleX

    CatweazleX Avatar

    Messages:
    653
    Likes Received:
    777
    Trophy Points:
    93
    Location:
    Veritas Sanctuary
    So to say you can display 90 lines on your screen. And want to have a line-spacing of 1.2. So, i only have to find out how many X i can display on my screen at a reference font size, to find out the raster. (Chars x and y). Sounds like a plan, and saves that one has to enter the monitor size to get the dpi. I'll try that. Thx

    Edit:
    I take your aproach. Screen.height / 90 is 12. That seems to be the default font size on my screen. 90 * 12 is 1080, that is my vertical resolution. So i do screen.height / 1080 now, to get a font size multiplier. That means the font size is now relative to 1080 screen resolution.
    That should also work for modders with different resolution.
     
    Last edited: Nov 30, 2019
  4. Drake Aedus

    Drake Aedus Avatar

    Messages:
    536
    Likes Received:
    886
    Trophy Points:
    75
    Gender:
    Male
    @Toular
    What is linespace in reference to for your example? Total height per row of text?

    Does anyone have a quick way to calculate text width?
     
  5. Toular

    Toular Avatar

    Messages:
    661
    Likes Received:
    631
    Trophy Points:
    93
    It's the distance I offset labels vertically for calculating row position. It also works out to be pretty close the the height of the label when rendered.

    Determining width of a text string is one thing we really need so we can line-up tables. I don't even try, except to pad with spaces using string.format "%40s"...
     
Thread Status:
Not open for further replies.