[Solved] Hide the menu in game

Level 5
Joined
Feb 23, 2019
Messages
16
Hi, I've been trying to hide the menu bar in game for my map, and I can hide it visually by calling BlzHideOriginFrames but there is one big problem. The mouse coordinates become (0,0) when you hover over that area. In the map, the cursor is like a joystick and moves in quick bursts, it usually ends up sticking to the extremities of the screen, NESW. But when it's at the top in the rectangular area where the menu bar should be, the coordinates are always (0,0). This of course makes the map unplayable.

I was wondering if there's a way to fix the "mouse deadzone" where the menubar is/should be? Either in GUI or in JASS is fine. Thank you
 
One simple way is to define a frame that "cages" the mouse so that the mouse can't move beyond that safe-zone:
1758445857462.png


To create it, you can just make a frame on game start and set the alpha to 0. When your mouse coordinate trigger fires, you can call BlzFrameCageMouse(cageFrame, true) to keep the mouse within the frame:
JASS:
library MouseXY initializer Init
    globals
        private framehandle cageFrame = null
        private boolean DEBUG_SHOW_CAGE = true
    endglobals

    private function OnMouseMove takes nothing returns nothing
        call ClearTextMessages()
        call BJDebugMsg("X: " + R2S(BlzGetTriggerPlayerMouseX()) + ", Y: " + R2S(BlzGetTriggerPlayerMouseY()))
        if cageFrame != null then
            call BlzFrameCageMouse(cageFrame, true)
        endif
    endfunction

    private function OnGameStart takes nothing returns nothing
        set cageFrame = BlzCreateFrameByType("BACKDROP", "CageFrame", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
        call BlzFrameSetAbsPoint(cageFrame, FRAMEPOINT_BOTTOMLEFT, 0, 0)
        call BlzFrameSetAbsPoint(cageFrame, FRAMEPOINT_BOTTOMRIGHT, 0.8, 0)
        call BlzFrameSetAbsPoint(cageFrame, FRAMEPOINT_TOPLEFT, 0, 0.575)
        call BlzFrameSetAbsPoint(cageFrame, FRAMEPOINT_TOPRIGHT, 0.8, 0.575)

        if DEBUG_SHOW_CAGE then
            call BlzFrameSetAlpha(cageFrame, 50)
        else
            call BlzFrameSetAlpha(cageFrame, 0)
        endif

        call DestroyTimer(GetExpiredTimer())        
    endfunction

    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterPlayerEvent(t, Player(0), EVENT_PLAYER_MOUSE_MOVE)
        call TriggerAddAction(t, function OnMouseMove)
        call TimerStart(CreateTimer(), 0, false, function OnGameStart)
        call BlzHideOriginFrames(true)
    endfunction
endlibrary

I'll attach a sample map in case you want to play around with it. It'll prevent you from panning upwards though (but I'm not sure if that is an issue for you since it sounds like your map is using the mouse for other things).

The other ways are a bit more complicated--you'd instead have to monitor the mouse screen coordinates (again via frames, similar to this system: Perfect Async Mouse Screen XY v1.1) and then you'd have to convert the screen coordinates to world coordinates yourself.

Or perhaps there is some cool trick I don't know about that lets you get around this issue. :)
 

Attachments

Back
Top