[SOLVED][LUA][STILL A BUG] GameScrollPosition for menus?

  • #1, z sebastianSunday, 09. October 2016, 01:18 hodinky 8 years ago
    Hello there,

    I hope i can get some hints.

    Im a bit stuck here with a debug window I am creating to instant teleport my char to each scene. Because I don't want to add every scene manually to a list I created a value which gets filled with all available scene names to its string and display it.
    So far so good. Working.

    When clicking on a specific position of the screen I want to execute a script which gets the Y-Position of my cursor to proceed further. (depending on Y position getting the id of the scene which gets displayed around the position)

    Because the debug screen (type:menu) is longer than a whole screen resolution (scrolls down) I have to determine the exact position of the cursor on the menu itself.

    For scenes it seems to work with game.ScrollPosition.y + cursorpos.y to get the Y-position.
    In menus though it seems that game.ScrollPosition.y is always "0" . Any ideas how i get the exact Position on the whole menu here?


    kind regards
    Sebastian


    Kapitán

    2346 Posts


  • #2, z afrlmeSunday, 09. October 2016, 01:44 hodinky 8 years ago
    Hmm... it seems using the scroll scene if cursor near edge of screen option doesn't update the actual scroll position value. If I manually type "exec game.ScrollPosition = {x=400, y=0}" then it updates the scroll position to the coordinates I just specified & when then query "exec print(game.ScrollPosition.x, game.ScrollPosition.y)" it prints the correct scroll position values to the log. Maybe you could setup the bounding box manually with Lua script maybe?
    local pos
    local w = 1920 -- total width of scene
    local h = 2160 -- total height of scene
    
    function scrollmenu()
     pos = game.ScrollPosition
     -- + --
     if getCursorPos().y < 10 then
      game.ScrollPosition = { x = pos.x, y = pos.y - 1 }
     elseif getCursorPos().y > (game.WindowResolution.y - 10) and game.ScrollPosition.y < (h - game.WindowResolution.y) then
      game.ScrollPosition = { x = pos.x, y = pos.y + 1 }
     end
    end
    
    registerEventHandler("mainLoop", "scrollmenu")
    

    ... no idea how far I am off the mark. Kind of late & written off the top of my head.

    Imperátor

    7285 Posts

  • #3, z sebastianSunday, 09. October 2016, 01:55 hodinky 8 years ago
    hm yeah may i have to do it this way. But it seems that i discovered a bug if it doesnt get updated, right?

    Kapitán

    2346 Posts

  • #4, z afrlmeSunday, 09. October 2016, 01:56 hodinky 8 years ago
    Yeah, must be a bug.

    Anyway... script I posted wasn't exactly right. This one isn't exactly right either as it's for x-axis, but I'm sure you'll have no trouble modifying it to your needs. wink
    local pos
    local w = 2880 -- total width of scene
    local h = 1080 -- total height of scene
    
    function scrollmenu()
     pos = game.ScrollPosition
     -- + --
     if getCursorPos().x < 10 and game.ScrollPosition.x > 0 then
      game.ScrollPosition = { x = (pos.x - 5), y = pos.y}
     elseif getCursorPos().x > (game.WindowResolution.x - 10) and game.ScrollPosition.x < (w - game.WindowResolution.x) then
      game.ScrollPosition = { x = (pos.x + 5), y = pos.y}
     end
    end
    
    registerEventHandler("mainLoop", "scrollmenu")
    

    Imperátor

    7285 Posts

  • #5, z sebastianSunday, 09. October 2016, 14:41 hodinky 8 years ago
    Thanks smile
    I'll try now to continue my debug screen.

    Kapitán

    2346 Posts