[ZScript]Toggle-able Mouse Control

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
Nash
 
 
Posts: 17465
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: [ZScript]Toggle-able Mouse Control

Post by Nash »

I know I don't have any answers for you and I know this will probably be a looooong way off... but I do hope that some day, Z-Windows will be native to ZScript.

Recently I have started work on doing game UI and currently I am drawing things on the screen manually (picture below). It's such a pain to work with. As I was coding the thing, I was wishing there was some kind of "Qt library for GZDoom" or something, haha.

I can imagine Z-Windows drawn and running natively/directly within the ZScript VM to perform much better and also from your programming perspective, much more convenient due to object oriented programming, direct access to pointers and low-level screen drawing stuff, and overall not having to hack around and fight ACS' technical limitations would be so much more beneficial in the long run.

Heck, I'm willing to pay for a GUI solution/add-on for ZScript! XD

Best of luck to you, and it's great to see you continue working on it.
Spoiler: censored nudity
Last edited by Nash on Sun Oct 08, 2017 11:03 pm, edited 1 time in total.
User avatar
Sarah
Posts: 551
Joined: Wed Sep 06, 2006 12:36 pm
Preferred Pronouns: She/Her
Operating System Version (Optional): Debian 11 (bullseye), Windows 10
Location: Middle of Nowheresville Il.

Re: [ZScript]Toggle-able Mouse Control

Post by Sarah »

Haha, nice to hear from you Nash! Put some pants on that guy :lol:

Anyway, the long term goal is to completely port Z-Windows to ZScript, but things will be significantly different from GDCC. The only truly hacky stuff in Z-Windows is GetPlayerInput and HudMessage spamming; one early goal was a universal HudMessage ID system so users never need to mess with an ID. GDCC, as you know, gave us a C compiler with all the perks, structs, enums, pointers, etc. Z-Windows describes a "window" through a struct that even contains pointers to functions, creating a "C-Class". There's also structs for buttons, text, and graphics, which get connected to the window through linked lists. I'm not lying when I compare it to the Win32 API, which probably makes it just as difficult to begin using as ZScript.

What I'm currently imagining is another generic series of classes that allow for a window abstraction; what you put in it doesn't matter but creates the benefit of a uniform system to create interactive displays onscreen. I still have yet to even begin messing with drawing things onscreen, mouse control has taken priority. Right now ZScript and Z-Windows do not play together at all, the systems are that different, which has me considering skipping the intermediary step of making them play together and just going for the full ZScript version. What I need to do is get Z-Windows mouse control disabled, but continue to use the mouse struct and feed coordinates from ZScript to it. Z-Windows Universal Mouse Control is a large part of the system that touches many things. Lack of ZScript documentation and time to work on it are big hindrances to progress; I work 10hr days during the week with optional Saturdays and I'm working every other.


Question:
Some minor background: Z-Windows uses what I call "Quikclose" (yes no C in the word) to cancel mouse control and return movement control to the player. Z-Windows monitors the movement keys via GetPlayerInput, Forward, Back, Strafe Left/Right, and Turn Left/Right, and upon receiving one of these commands returns control to the player. This is because the game does not pause while the player is interacting with an interface, ala System Shock. That is both a limitation and feature.

My question is, how do I monitor the movement keys via ZScript? From "constants.txt" I can see there is an EButtons enum, but how do I go about using it?
User avatar
Sarah
Posts: 551
Joined: Wed Sep 06, 2006 12:36 pm
Preferred Pronouns: She/Her
Operating System Version (Optional): Debian 11 (bullseye), Windows 10
Location: Middle of Nowheresville Il.

Re: [ZScript]Toggle-able Mouse Control

Post by Sarah »

Been a week so I'm bumping this because I still have two unanswered questions:
  1. What is the best way to get the player's number within an actor? In this case I'm trying to get the player's number from within the player.

    To quote myself:
    I wrote:To clarify, the event handlers store the mouse coordinates in a global variable class. There should be a unique instance of this class for each player. When sending the coordinates to Z-Windows (the ACS part), the player has to locate their "Mouse Coordinate Storage" instance and call a script, supplying the coordinates as arguments. This all works good an well, and I've even set up a quick and dirty script to supply the player their number, which is where the question comes in. How do I do this via ZScript so I can drop that little dirty script?

    Code: Select all

    /*
    *   Z-Windows ZScript DoomPlayer
    *
    */
    
    
    // =========== class ZSWinPlayer : DoomPlayer ===========
    // - This is an actor class inheriting from the DoomPlayer and replacing the Spawn state
    class ZSWinPlayer : DoomPlayer
    {   
       zWinGlobalMousePosition mcs;
       int playNum;
       bool bNumSet;
       
       States
       {
          Spawn:
             PLAY A 1;
             TNT1 A 0
             {
                // Setup variables
                let zDefs = zWinDefs.Get();
                CVar cvZDebug = CVar.FindCVar(zDefs.zcv_Debug);
                if (!bNumSet)
                {
                   // Is there a way to do this via ZScript?
                   playNum = ACS_NamedExecuteWithResult("getPlayerNumber", 0);
                   bNumSet = true;
                }
                
                if (mcs == null)
                {
                   if (cvZDebug.GetInt() == true)
                      Console.Printf("Player %i: Mouse coordinate storage is null, searching.", playNum);
                   mcs = zWinGlobalMousePosition.Find(playNum);
                }
                
                // Check for working MCS and mouse is toggled, then send coordinates to zWin
                if (mcs && mcs.bmseToggle == true)
                   ACS_NamedExecute("thisIsATestScriptCall", 0, mcs.zmse_CoordX, mcs.zmse_CoordY);
                // MCS doesn't exist so make a new one.
                else if (mcs == null)
                {
                   if (cvZDebug.GetInt() == true)
                      Console.Printf("Player %i: No mouse coordinate storage class found, making new.", playNum);
                   mcs = new("zWinGlobalMousePosition").Init(playNum);
                }
             }
             Loop;
       }
    }
  2. How do I monitor the movement keys via ZScript?

    Quoting myself again:
    Nero wrote:Some minor background: Z-Windows uses what I call "Quikclose" (yes no C in the word) to cancel mouse control and return movement control to the player. Z-Windows monitors the movement keys via GetPlayerInput, Forward, Back, Strafe Left/Right, and Turn Left/Right, and upon receiving one of these commands returns control to the player. This is because the game does not pause while the player is interacting with an interface, ala System Shock. That is both a limitation and feature.

    My question is, how do I monitor the movement keys via ZScript? From "constants.txt" I can see there is an EButtons enum, but how do I go about using it?
Thanks for all the help thus far everyone!
ZzZombo
Posts: 317
Joined: Mon Jul 16, 2012 2:02 am

Re: [ZScript]Toggle-able Mouse Control

Post by ZzZombo »

Player actors should have a non-null `player` field. And that have the corresponding player number.

Return to “Scripting”