Have a GUI stay on screen for some seconds then tween away

Started by AndreasBlack, Mon 02/10/2023 15:38:59

« previous - next »

AndreasBlack

So i'm doing this general function for a Gui Popup "controller connected" or "instructions" or "Achievements" sign in the corner. I've noticed some games, no big titles named. They have controller support, however it never says "controller is connected" and it was confusing at first, eventually i realised "omg it's got controller support. That's why the mouse is acting all weird!".

So i'd figured in my game i want a popup for when it's connected, or if it accidently get's disconnected, just in case that happens! Everything is fine apart from i can't manage to get it to stay on screen for some seconds without having it blocking the game. Optimal would be to start the timer after i've pushed the mousebutton or random gamepad button.

When i try tween it with a Timer, that doesn't work for me. It complains about it being a blocking action since i'm obviously using repeatedly execute to check for when the timer has expired. What do i do?

This is the code i have so far..

Code: ags
function Which_Controller_Is_Connected_Gui()

{
    gamepad = Controller.Open(0);
    String inputName = gamepad.GetName();
  
    if (inputName == "PS4 Controller")
  
  
    if (gamepad.Plugged()==true)

{

    if (gPlaystation_4.Visible==true)
{
    if (!gamepad.PressAnyKey() || mouse.IsButtonDown(eMouseLeft))
{
  
  Wait(25); //I don't like. Blocks the player. But i also don't want it to get of the screen immediately
            //I want the player to be able to see it first "Oh, hey a controller or hey a information box"!
            //however if you click the mouse button or the gamepad it flys away fast.
            //so a timer would be neccessary
  aSwoosh_Items.Play();
  gPlaystation_4.TweenPosition(0.7, 220, 250,eNoBlockTween); //I want this to delay or wait a second or two
  gPlaystation_4.Visible=false;
  gPlaystation_4.Transparency=100;
  
} 
}
  
  else if (gamepad.Plugged()==false)

{
  gPlaystation_4.SetPosition(221, 161); //Just in case it's unplugged by mistake it get's noticed..
  gPlaystation_4.Transparency=0; 
  gPlaystation_4.Visible=true;
}
  
}
}




Khris

Sorry, the indentation is a mess. And if (inputName == "PS4 Controller") is not followed by a {} block, which works fine but is confusing to read.

First of all you need to decouple the controller code from your notice GUI.

1. write a function that will display a message, then add rep_exe code that removes it after some time has passed (use a timer that starts when the GUI is shown and remove it when it expires)

2. call the function and pass along your gamepad message, whatever it may be

abstauber


AndreasBlack

#3
Ha
Quote from: abstauber on Wed 04/10/2023 09:31:32Is it a coincidence? @eri0o just released his Toaster Module, doing more or less what you might need:
https://www.adventuregamestudio.co.uk/forums/modules-plugins-tools/module-toaster-0-1-0/msg636658069


(laugh) i don't think it is! I just saw it  :-D  I hope it works as easily as it looks (nod) I still trouble with trying to reference the actual input of the controller. The only way i've gotten that to work is to have the GUI and the controller in the same function. Even tho it's really messy i agree on that. I'm not a "coder" i'm a messer.

If i write a different function for just the GUI how can i get the GUI to recognise that a specific controller is plugged. Cause i can't understand how to do a "Get Controller input* if statement and if controller is x-box = show that gui graphic. If controller is playstation show another bakgroundgraphic on the gui, etc!

Code: ags
  gamepad = Controller.Open(0);
    String inputName = gamepad.GetName();
  
    if (inputName == "PS4 Controller"  //this one i would like the GUI code to "look" for. But i can't)
  
  
    if (gamepad.Plugged()==true 

 

Khris

You can add parameters to the function to pass along arbitrary additional info, like the GUI background.

Code: ags
  ShowNotification("PS4 controller detected!", 123); // 123 is slot of the PS4 background sprite 

Your function now looks like this:

Code: ags
function ShowNotification(String message, int bg_slot) {
  // setup
  gMessage.BackgroundGraphic = bg_slot;
  lblMessage.Text = message;
  // etc.
  // start tween and timer
}

You can also use an enum instead:
Code: ags
enum NotificationBG {
  eNotificationPS4 = 123,
  eNotificationXBox = 135,
};

If you add this to the header, you can replace int bg_slot with NotificationBG bg_slot and call the function like this:
Code: ags
  ShowNotification("PS4 controller detected!", eNotificationPS4);

AndreasBlack

Thanks a lot, i will try the function soon! However where do you check for which controller is connected so the GUI knows? Should the gui function be called inside of the various controller code blocks?

Since most people i guess either have a Xbox or PS controller type. And doing a tutorial which ends up being "another button" if you have a xbox instead of a ps connected wouldn't be so nice, hence why you need to make sure to check for a specific controller so future "small tutorials" like "this is how you run",  will be customized

Khris

Not sure if AGS can detect which type of controller is connected. Maybe you can determine it by axis/button count?
Anyway, you can also simply let the player select their controller type.

As for the GUI knowing which controller is connected: you simply pass along any required information when you call the function that displays the message. Like I said in my previous post, you can add arbitrary information to the ShowNotification call.
Maybe I don't really understand what you're asking?

Quote from: AndreasBlack on Wed 04/10/2023 12:17:03Should the gui function be called inside of the various controller code blocks?
Yes, you call the function whenever you want to show the notification GUI. If you want to show a notification that confirms a controller was detected, you have to call the notification function inside the code that detects the controller.
Just to clarify: the GUI function is essentially just a more sophisticated Display() command. But instead of Display("Controller detected"); you're calling your own function. It wouldn't be necessary for the Display function to "know" your game state, so why would this be an issue with your own notification function?

eri0o

Quote from: abstauber on Wed 04/10/2023 09:31:32Is it a coincidence? @eri0o just released his Toaster Module, doing more or less what you might need:
https://www.adventuregamestudio.co.uk/forums/modules-plugins-tools/module-toaster-0-1-0/msg636658069


Erh, this thread was a good idea to put something from my head as a module. :)

SMF spam blocked by CleanTalk