Please login or register.

Login with username, password and session length
Advanced search  

News:

For WME related articles and tutorials visit WME Resource Center.

Author Topic: Trying to get a popup window to close.  (Read 5216 times)

0 Members and 1 Guest are viewing this topic.

Uhfgood

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 117
  • No pain, no game!
    • View Profile
    • Indie Flux
Trying to get a popup window to close.
« on: February 21, 2008, 09:40:52 PM »

Essentially I have a window that pops up when you hold down the mouse button for a small period of time.  It's actually just the code off of the 3d actors demo, that I trimmed down a little.  I can't get the window to close after clicking.  I figured the "on "Characters"" line would do what was in there, but apparently not.  I'm doing something wrong somewhere.  Also an odd thing is at first in the debugging console it would show my menu script, and now it doesn't do that at all, for no reason I can think of.

Any help is appreciated.

Here's the game.script:
Code: [Select]
#include "scripts\base.inc"
#include "scripts\keys.inc"

global ClickStarted;
global ClickStartTime;
global ClickObject;

// store some of the game's attributes in global variables for convenience
Keyboard = Game.Keyboard;
Scene = Game.Scene;


// load the right-click menu
global WinMenu = Game.LoadWindow("interface\menu\InGameMenu.window");
WinMenu.Visible = false;

// load the "caption" window
var win = Game.LoadWindow("interface\system\caption.window");
global WinCaption = win.GetWidget("caption");


global MenuObject = null;


// load our main actor
actor = Game.LoadActor("actors\John\John.actor");
Game.MainObject = actor;

// run the "game loop" script
Game.AttachScript("scripts\game_loop.script");


// which scene to load?
Game.ChangeScene(Game.StartupScene);

on "LeftClick"
{
if( !ClickStarted )
{
  // perform click start
  ClickObject = Game.ActiveObject;

  // mark click start and remember the time
  ClickStarted = true;
  ClickStartTime = Game.CurrentTime;
}
else
  WinMenu.ApplyEvent("Characters");
}
////////////////////////////////////////////////////////////////////////////////
on "LeftRelease"
{
if( !ClickStarted )
Scene.ApplyEvent("LeftRelease");
}



////////////////////////////////////////////////////////////////////////////////
on "Keypress"
{
  // on Esc or F1 key
  if(Keyboard.KeyCode==VK_ESCAPE || Keyboard.KeyCode==VK_F1)
  {
    // load and display the main menu window
    WinCaption.Visible = false;
    var WinMainMenu = Game.LoadWindow("interface\system\mainmenu.window");
    WinMainMenu.Center();
    WinMainMenu.GoSystemExclusive();
    Game.UnloadObject(WinMainMenu);
  }
}


////////////////////////////////////////////////////////////////////////////////
on "QuitGame"
{
  // on Alt+F4 (window close)
  // load and display the quit confirmation window
  WinCaption.Visible = false;
  var WinQuit = Game.LoadWindow("interface\system\quit.window");
  WinQuit.Center();
  WinQuit.GoSystemExclusive();

  // and if the user selected Yes
  if(WinQuit.xResult)
  {
    // quit the game
    Game.QuitGame();
  }
  // otherwise just unload the quit window from memory
  else Game.UnloadObject(WinQuit);
}

Now here's game_loop.script:
Code: [Select]
#include "scripts\base.inc"

// this script runs in an endless loop and does all the user-interface work
// that needs to be periodically updated
// such as the floating items captions display and positioning
// and the sliding inventory window handling

global WinCaption;
global WinMenu;

global ClickStarted;
global ClickStartTime;
global ClickObject;

var VerbHoldTime = 200; // in milliseconds

// infinite loop
while(true){

  // handle verb coin if the the required time has passed
  if(ClickStarted && !WinMenu.Visible && Game.CurrentTime - ClickStartTime >= VerbHoldTime)
  {
    // position the verbs window
    WinMenu.X = Game.MouseX - WinMenu.Width/2;
    if(WinMenu.X < 0) WinMenu.X = 0;
    if(WinMenu.X + WinMenu.Width>Game.ScreenWidth) WinMenu.X = Game.ScreenWidth - WinMenu.Width;

    WinMenu.Y = Game.MouseY - WinMenu.Height/2 + 10;
    if(WinMenu.Y < 0) WinMenu.Y = 0;
    if(WinMenu.Y + WinMenu.Height>Game.ScreenHeight) WinMenu.Y = Game.ScreenHeight - WinMenu.Height;
   
    // and display it
    WinMenu.Visible = true;
   
    var Caption = WinMenu.GetWidget("caption");
    Caption.Text = ClickObject.Caption;


    // if we are about to show the verbs, we tell the actor to cancel
    // whatever he was going to do
    actor.Reset();
  }
 
  // save the active object for later
  var ActObj = Game.ActiveObject;

  // go to sleep for 20 miliseconds to allow the engine to perform other tasks
  // it is important for the "endless" scripts to call the Sleep command, otherwise the game will get stuck
  Sleep(1);
}

And finally here's the code for my menu:
Code: [Select]
#include "scripts\base.inc"
global WinMenu;
global ClickStarted;

////////////////////////////////////////////////////////////////////////////////
on "Characters"
{
ClickStarted = false;
WinMenu.Visible = false;
self.Close();
}

Keith
« Last Edit: February 23, 2008, 01:07:05 AM by Uhfgood »
Logged
--------------------------------------------
Keith Weatherby II
uhfgood -AT- frontier -DOT- com
Games Afoot Software
Indie Flux - Previews, Reviews, News and more!
--------------------------------------------

Uhfgood

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 117
  • No pain, no game!
    • View Profile
    • Indie Flux
Re: Trying to get a popup window to close.
« Reply #1 on: February 21, 2008, 10:47:10 PM »

A little closer to the problem.  Regardless of whether the menu is up or not, a left-click event always gets issued.  So in a sense each time I click on the button, it pops the menu back up, instead of going to the menu script and closing the window.

Not sure what to do about it though.
Logged
--------------------------------------------
Keith Weatherby II
uhfgood -AT- frontier -DOT- com
Games Afoot Software
Indie Flux - Previews, Reviews, News and more!
--------------------------------------------

goldenTouch

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 26
    • View Profile
    • Spare Time Gaming
Re: Trying to get a popup window to close.
« Reply #2 on: February 21, 2008, 11:04:09 PM »

If it's a verb coin you're making, I'll be happy to provide you with my own code for it.
It's working, and you can copy it right into your game.
You could look at it and modify it as you wish.

I didn't read through all your code, but it seems to me that you're not handling the button event from the menu (I assume you have buttons there?).
Logged

Uhfgood

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 117
  • No pain, no game!
    • View Profile
    • Indie Flux
Re: Trying to get a popup window to close.
« Reply #3 on: February 21, 2008, 11:18:44 PM »

Yeah.  At the moment I've reduced it from 4 to one, that one on the top (the Characters one).  How do I handle the button event from the menu?  I have a menu script that's attached, that checks the On "Characters" event.
Logged
--------------------------------------------
Keith Weatherby II
uhfgood -AT- frontier -DOT- com
Games Afoot Software
Indie Flux - Previews, Reviews, News and more!
--------------------------------------------

Uhfgood

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 117
  • No pain, no game!
    • View Profile
    • Indie Flux
Re: Trying to get a popup window to close.
« Reply #4 on: February 23, 2008, 12:51:46 AM »

I'm to understand nobody knows why the menu or button isn't getting control?

Mnemonic suggested I go back and reuse the whole demo code, and then take out just what I don't need.  Only problem is it's slightly different than what the demo has.  The demo's verb coin only works on interactive objects.  In my case I want it to work any time the user holds down the left mouse button.

Here's how I want my interface to work.  The user holds down the mouse button for a period of time until the menu pops up.  If the person holds and drags the menu also pops up.  If the person clicks on an interactive object or hotspot the menu pops up.

Secondly each button is going to open into another menu.  Center will be used to close the menu to the previous one.

Any help I can get is appreciated.

Keith
Logged
--------------------------------------------
Keith Weatherby II
uhfgood -AT- frontier -DOT- com
Games Afoot Software
Indie Flux - Previews, Reviews, News and more!
--------------------------------------------

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Trying to get a popup window to close.
« Reply #5 on: February 23, 2008, 01:03:43 AM »

Mnemonic answered very well. You're just not going to listen, are you?  ::) post your LeftClick handler from game.script here and I'm sure you just don't propagate mouse clicks to the window or something like that. I recommend reading some of the articles (either in wme book or in wiki) dealing with handlers, game.script and game_daemon.script. It would help you down the road and you'll find out why your code is not working. Your problem could be caused by thousands of things so don't blame anyone that he doesn't see a right solution with a tiny (and usually unrelated) code fragments.  C:-) ::wave
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Uhfgood

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 117
  • No pain, no game!
    • View Profile
    • Indie Flux
Re: Trying to get a popup window to close.
« Reply #6 on: February 23, 2008, 01:09:56 AM »

I posted all the scripts up in my first post, including the left click handler.

now... I will repost just that part again.

Code: [Select]
on "LeftClick"
{
if( !ClickStarted )
{
  // perform click start
  ClickObject = Game.ActiveObject;

  // mark click start and remember the time
  ClickStarted = true;
  ClickStartTime = Game.CurrentTime;
}
else
  WinMenu.ApplyEvent("Characters");
}

Note Mnemonic said to take the demo again and take stuff out until it worked.  However the demos work DIFFERENTLY than what I am trying to achieve.

And yes he did mention that somehow I'm not propagating the events down to the menu, however, this code I just posted should have applied it, and thus should have went in and On "Characters" did the required code.  I still don't know what I'm doing, and I have read through your articles, very informative yes, but I'm still not very quick when it comes to all these confusing script things.  I've even done programming in C/C++ and I still don't get it.

Logged
--------------------------------------------
Keith Weatherby II
uhfgood -AT- frontier -DOT- com
Games Afoot Software
Indie Flux - Previews, Reviews, News and more!
--------------------------------------------

Uhfgood

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 117
  • No pain, no game!
    • View Profile
    • Indie Flux
Re: Trying to get a popup window to close.
« Reply #7 on: February 23, 2008, 05:44:18 AM »

Meta - after reading your book again, as I have already a couple of times, I figured out how to do it.  I had to get the active object, rather than using WinMenu directly. 

And now it works

Thanks for the help.
Logged
--------------------------------------------
Keith Weatherby II
uhfgood -AT- frontier -DOT- com
Games Afoot Software
Indie Flux - Previews, Reviews, News and more!
--------------------------------------------
 

Page created in 0.044 seconds with 19 queries.