issue with tpt.drawLine

  • Alchnoious
    3rd Jun 2023 Member 0 Permalink

    I am having some issues while writing my script. When I use APIs like tpt.drawLine to draw on the screen, their layer priority seems to be lower than the window provided by the API, causing me unable to draw on the window. Can someone provide me with a solution? Thank you.

    Here's an example to demonstrate my problem:

     

    local newWindow = Window:new(250, 150, 200, 200)
    function Cdraw()
        tpt.drawline(152, 170, 205, 334, 0, 255, 0, 255)
        tpt.drawline(205, 334, 378, 334, 0, 255, 0, 255)
        tpt.drawline(378, 334, 430, 170, 0, 255, 0, 255)
        tpt.drawline(430, 170, 291, 68, 0, 255, 0, 255)
        tpt.drawline(291, 68, 152, 170, 0, 255, 0, 255)
    end

    tpt.register_step(Cdraw)
    interface.showWindow(newWindow)

     

    I also have a question about how to delay execution. Whenever I use tpt.screenshot, it always takes the screenshot before the window is closed, which causes the screenshot to be obscured by the window.

    For example:

     

    local T_Button = Button:new(100, 30, 80, 15, "Screenshot")
    T_Button:action(
        function()
            interface.closeWindow(Mainwindow)
            tpt.screenshot(1,0)
        end
    )

     

    Finally, I hope my machine translation doesn't make it difficult for you to understand it.

     

  • LBPHacker
    3rd Jun 2023 Developer 0 Permalink
    To solve the priority problem, use newWindow:onDraw(...) instead of tpt.register_step(...). The tpt.screenshot delay you can't change, the best you can do is call it, and close your window in the next frame. Interface API windows also have an onTick callback, that would be the good place to do this.

    Edit: I've looked at the source and it turns out that tpt.screenshot can only capture the main window.
    Edited once by LBPHacker. Last: 3rd Jun 2023
  • Alchnoious
    3rd Jun 2023 Member 0 Permalink

    Thanks for the method, I'll go and use it.

    So you mean that using tpt.screenshot like this has no way to screenshot the game interface, right?

  • LBPHacker
    3rd Jun 2023 Developer 0 Permalink
    Yes. Furthermore, if you pass 1 as its first argument, it still won't capture the entire window, only the part where the simulation is, so it will exclude for example the element buttons and the category buttons.
  • Alchnoious
    3rd Jun 2023 Member 0 Permalink

    I used your advice but still encountered problems. Here is the code used in my test script and the results when run on Android tpt

     

    local Mainwindow = Window:new(50, 50, 525, 300)


    function draw()
        tpt.drawline(152, 170, 205, 334, 0, 255, 0, 255)
        tpt.drawline(205, 334, 378, 334, 0, 255, 0, 255)
        tpt.drawline(378, 334, 430, 170, 0, 255, 0, 255)
        tpt.drawline(430, 170, 291, 68, 0, 255, 0, 255)
        tpt.drawline(291, 68, 152, 170, 0, 255, 0, 255)
    end

     

    Mainwindow:onDraw(draw)

    interface.showWindow(Mainwindow)

     

  • LBPHacker
    3rd Jun 2023 Developer 0 Permalink
    Okay yeah android TPT is different, we'll have to ask @jacob1
  • Alchnoious
    4th Jun 2023 Member 0 Permalink

    Cracker1000:

     

    Cracker1000 PC control mod

     

    As the big title suggests, this script (or lua mod) allows you to use some of the most widely used features and modes from the PC version of the game on android. Below is the list of stuff it offers.

     

    *Ability to change brush shape and size

    *Tools: Line tool (also supports changing fan wall strength), Flood fill and box draw tool.

    *Toggles for debug mode, performance, cross hair, resetting spark and pressure.

    *Simulation tools: Allows you to use options like redo, undo and advance simulation frame by frame.

    *Other features not listed here.

     

    Link to the script

    Latest version: v3.0

     

    Steps to install/ update the script:

    Recommended way:

    In order to install the script you will have to open the console (second button from top on right corner) and just type this "tpt.getscript(214,"autorun.lua",1)" the bold text without quotes and then enter it.

    You will see a new button on the right hand side. Click it to open the script menu.

     

    Installing using script manager:

    If you have script manager installed on your android port, you can search for PC controls in the manager and install the script from there too.

     

    Do give suggestions or feedback, there'sa dedicated feedback button provided in the script too. Thanks to @jacob1 for helping with fan tool.

     

     

    Yes, Android tpt is a bit different. But when I was looking through this script I noticed that it also uses this drawing API

    Here are some snippets of what I found

     

    local function selectedbrush()
    brushheight:value(tpt.brushx)
    brushwidth:value(tpt.brushy)
    if ren.debugHUD() == 1 then
    gfx.drawText(315,261,"ON",35,255,35,255)
    else
    gfx.drawText(315,261,"OFF",255,35,35,255)
    end

     

    Omitted .....

     

    --Draws graphics when menu is open
    brushmenu:onDraw(selectedbrush)
    --End of script

  • jacob1
    6th Jun 2023 Developer 0 Permalink
    I was on vacation so couldn't check.

    But the answer seems to be that the tpt drawing api doesn't work in Lua windows. You have to use the graphics api instead. Everything you need is there.

    In my mod, the tpt api calls the legacy methods for drawing to the screen, but gfx uses the newer VideoBuffer stuff.