Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: Kaz on June 01, 2011, 06:41:32 PM

Title: Still struggling with keyboard input to Editor field
Post by: Kaz on June 01, 2011, 06:41:32 PM
This one still foxes me every time - I include an editor in a window and sometimes can put text in it, and then on the next occasion I use it, the editor will not accept keyboard input.

I have read that it's to do with the Window being exclusive, but the window calling the offending NewPlayer window has "NewPlayer = Game.LoadWindow("newplayer.window"); NewPlayer.Exclusive; = true, along with newplayer.script containing the line this.GoExclusive(); - but still the editor ignores the keyboard.

Any ideas?

Thanks
Title: Re: Still struggling with keyboard input to Editor field
Post by: Mnemonic on June 02, 2011, 06:57:13 AM
It sounds needlessly complicated. The usual workflow is...

In the calling script:

Code: WME Script
  1. var someWindow = Game.LoadWindow("path\some.window");
  2. someWindow.GoExclusive();
  3.  
  4. // now the script waits until the window is closed
  5.  
  6. Game.UnloadObject(someWindow);
  7.  


In the editor window script:

Code: WME Script
  1. <nothing relevant to window exclusivity>
  2.  

That should display the window in exclusive mode, so it will have keyboard focus.
You can also try using someWindow.GoSystemExclusive(); instead. That will freeze everything else and your window will get total exclusivity (but that shouldn't be necessary, as far as I can tell).
Title: Re: Still struggling with keyboard input to Editor field
Post by: Kaz on June 02, 2011, 08:16:06 AM
Thanks for the suggestion. Over-complications were due to me trying Everything I Could Think Of. :(
I implemented your suggestion as I understood it, and it made no difference. So I must be doing something else wrong?

Herewith the relevant part of one of the calling scripts:
Quote
on "New"
  {
  this.PlaySound("ui_elements\GenMoveClick.ogg");
  var fn = this.GetControl("New");
  NewPlayer = Game.LoadWindow("interface\IntroMenu\NewPlayer.window");
  NewPlayer.GoExclusive();
  while(NewPlayer != null)
    {
   Sleep(20);
   }
  InitButtons();
  NoDelete();
  NoNew();
  fn.Pressed = false;   
  }

And here is the other calling script:
Quote
on "Play"
  {
  // If we don't have any players, create one
  this.PlaySound("ui_elements\GenMoveClick.ogg");
  if(Player.Num == 0)
    {
   NewPlayer = Game.LoadWindow("interface\IntroMenu\NewPlayer.window");
   NewPlayer.GoExclusive();
   while(NewPlayer != null)
     {
     Sleep(20);
     }
   DoPlayer();
   }
  else
    {
   Game.LoadGame(Player.Current);
   }
  }


In the New Player window where the Editor is, all components are set to Parent Notify TRUE and the relevant part of the script says:
Quote
on "OK"
  {
  Game.Interactive = false;
  var ed = this.GetControl("NameEditor");
  var pn = ed.Text;
  Game.Msg("Player is "+pn);
  Player.Num = Player.Num+1;
  Game.Msg("Player.Num is "+Player.Num);
  var px = Player.Num;
  Player[px] = pn;
  Player.Current = px;
  Player.Changed = true;
  Game.RegWriteNumber("PlayerNum", Player.Num);
  Game.RegWriteNumber("PlayerCurrent", Player.Current);
  for(var a = 1; a < Player.Num +1; a = a +1)
    {
   var RegKeyName = "Player" + a;
   Game.RegWriteString(RegKeyName, Player[a]);
   }
  Game.Interactive = true;
  NewPlayer = null;
  this.Close();
  Game.UnloadObject(this);
  }

Still no keyboard input on the window. So what am I doing wrong? Thanks for your help on this.

(BTW, this 'Post Reply' box is very difficult to write in - it bounces what I'm typing out of sight and any corrections cause its window to scroll)
Title: Re: Still struggling with keyboard input to Editor field
Post by: metamorphium on June 02, 2011, 08:44:31 AM
Can you post the window declaration?
Title: Re: Still struggling with keyboard input to Editor field
Post by: Kaz on June 02, 2011, 10:16:30 AM
Thanks Jan - herewith.

; generated by WindowEdit

; $EDITOR_PROJECT_ROOT_DIR$ ..\..\..\

WINDOW
{
  NAME="NewPlayer"
  CAPTION=""
 
 
  TITLE_ALIGN="left"
 
  X=1024
  Y=234
  WIDTH=400
  HEIGHT=300
  DISABLED=FALSE
  VISIBLE=TRUE
  PARENT_NOTIFY=FALSE
  TRANSPARENT=FALSE
  PAUSE_MUSIC=TRUE
  MENU=FALSE
  IN_GAME=FALSE
  CLIP_CONTENTS=FALSE
 
  ALPHA_COLOR { 0, 0, 0 }
  ALPHA=0
 
  SCRIPT="interface\IntroMenu\NewPlayer.script"
 
  EDITOR_PROPERTY
  {
    NAME="Selected"
    VALUE="False"
  }

  STATIC
  {
    NAME="Background"
    CAPTION=""
   
    IMAGE="ui_elements\BackgroundSuper400x300.JPG"
    TEXT=""
    TEXT_ALIGN="left"
    VERTICAL_ALIGN="center"
   
    X=0
    Y=0
    WIDTH=400
    HEIGHT=300
    DISABLED=FALSE
    VISIBLE=TRUE
    PARENT_NOTIFY=TRUE
   
   
    EDITOR_PROPERTY
    {
      NAME="Selected"
      VALUE="False"
    }

  }
  STATIC
  {
    NAME="Title"
    CAPTION=""
   
    FONT="fonts\Arial20BoldRed.font"
    TEXT="/IM_NewPlayer/"
    TEXT_ALIGN="center"
    VERTICAL_ALIGN="center"
   
    X=30
    Y=20
    WIDTH=335
    HEIGHT=65
    DISABLED=FALSE
    VISIBLE=TRUE
    PARENT_NOTIFY=TRUE
   
   
    EDITOR_PROPERTY
    {
      NAME="Selected"
      VALUE="False"
    }

  }
  BUTTON
  {
    NAME="OK"
    CAPTION=""
   
    FONT="fonts\arial20.font"
    FONT_PRESS="fonts\Arial20BoldRed.font"
   
    TEXT="/IM_ButtonOK/"
    TEXT_ALIGN="center"
   
    X=80
    Y=180
    WIDTH=90
    HEIGHT=96
    DISABLED=FALSE
    VISIBLE=TRUE
    PARENT_NOTIFY=TRUE
    FOCUSABLE=FALSE
    CENTER_IMAGE=FALSE
    PRESSED=FALSE
    PIXEL_PERFECT=FALSE
   
   
    EDITOR_PROPERTY
    {
      NAME="Selected"
      VALUE="False"
    }

  }
  BUTTON
  {
    NAME="Cancel"
    CAPTION=""
   
    FONT="fonts\arial20.font"
    FONT_PRESS="fonts\Arial20BoldRed.font"
   
    TEXT="/IM_Cancel/"
    TEXT_ALIGN="center"
   
    X=260
    Y=180
    WIDTH=90
    HEIGHT=90
    DISABLED=FALSE
    VISIBLE=TRUE
    PARENT_NOTIFY=TRUE
    FOCUSABLE=FALSE
    CENTER_IMAGE=FALSE
    PRESSED=FALSE
    PIXEL_PERFECT=FALSE
   
   
    EDITOR_PROPERTY
    {
      NAME="Selected"
      VALUE="False"
    }

  }
  EDIT
  {
    NAME="NameEditor"
    CAPTION=""
   
    FONT="fonts\arial20.font"
   
    TEXT=""
   
    X=56
    Y=96
    WIDTH=275
    HEIGHT=60
    MAX_LENGTH=20
    CURSOR_BLINK_RATE=530
    FRAME_WIDTH=0
    DISABLED=FALSE
    VISIBLE=TRUE
    PARENT_NOTIFY=TRUE
   
    EDITOR_PROPERTY
    {
      NAME="Selected"
      VALUE="True"
    }

  }
}

Title: Re: Still struggling with keyboard input to Editor field
Post by: metamorphium on June 02, 2011, 01:06:18 PM
ok, and the code excerpts are from "interface\IntroMenu\NewPlayer.script" right?

As I don't see anything substantionally wrong, I will need to see the propper script files, not just excerpts. Also you did check a wme.log for script errors, right?

Because in your original post you state: "NewPlayer.Exclusive; = true" which is obviously a syntax error (misplaced semicolon).

Title: Re: Still struggling with keyboard input to Editor field
Post by: Kaz on June 02, 2011, 01:22:24 PM
Hi

Sorry about the NewPlayer.Exclusive - but I've since tried it the way Mnemonic suggested, which incidentally was the way it was originally, when it worked :(

Thanks for doing this.

Three scripts involved. IntroMenu is the game's introductory menu, and if no players are registered, pressing "Play" will call the NewPlayer window with the Editor in question. PlayerList allows for registering and deleting additional players, so also calls the NewPlayer window. Then there's the NewPlayer itself

Quote

#include "scripts\base.inc"
#include "scripts\keys.inc"

// I AM INTROMENU

this.xResult = false;
var BeenHere = Game.IsSaveSlotUsed(0);
if(BeenHere != true)
  {
  // Initialize system
  var RegKeyName;
  Game.RegWriteNumber("PlayerNum", null);
  Game.RegWriteNumber("PlayerCurrent", null);
  for(var t = 1; t<7; t = t+1);
    {
   RegKeyName = "Player"+t;
   Game.RegWriteString(RegKeyName, null);
   }
  Game.SaveGame(0, "SystemSave");
  }
var PlayerName = this.GetControl("PlayerName");
// Find out who's playing and update this menu for current and player list for profile changes
Player.Num = Game.RegReadNumber("PlayerNum");
if(Player.Num == null)
  {
  Player.Num = 0;
  Game.RegWriteNumber("PlayerNum", Player.Num);
  }
else
  {
  Player.Num = Game.RegReadNumber("PlayerNum");
  }
 
if(Player.Num > 0)
  {
  // Get already registered players
  Player.Current = Game.RegReadNumber("PlayerCurrent");
  // Initialise list
  for(var a = 1; a <7; a = a+1)
    {
    Player[a] = null;
    }
  // Repopulate list   
  for(a = 1; a < Player.Num +1; a = a + 1)
   {
   RegKeyName = "Player" + a;
   Player[a] = Game.RegReadString(RegKeyName);
   }
  DoPlayer();
  }

function DoPlayer()
  {
  var dp = Player.Current;
  PlayerName.Text = Game.ExpandString("/IM_PlayerName/")+" "+Player[dp];
  PlayerName.Visible = true;
  var ChangeProfile = this.GetControl("ChangeProfile");
  ChangeProfile.Visible = true;
  ChangeProfile.Disabled = false;
  }

on "Play"
  {
  // If we don't have any players, create one
  this.PlaySound("ui_elements\GenMoveClick.ogg");
  if(Player.Num == 0)
    {
   NewPlayer = Game.LoadWindow("interface\IntroMenu\NewPlayer.window");
   NewPlayer.GoExclusive();
   while(NewPlayer != null)
     {
     Sleep(20);
     }
   DoPlayer();
   }
  else
    {
   Game.LoadGame(Player.Current);
   }
  }
 
on "Options"
  {
  this.PlaySound("ui_elements\GenMoveClick.ogg");
  Game.Msg("No options yet");
  }

on "Credits"
  {
  this.PlaySound("ui_elements\GenMoveClick.ogg");
  Game.Msg("No credits yet");
  }
 
on "Exit"
  {
  // ARE YOU SURE?
  this.PlaySound("ui_elements\GenMoveClick.ogg");
  var qg = Game.LoadWindow("interface\IntroMenu\QuitSure.window");
  }

on "ChangeProfile"
  {
  this.PlaySound("ui_elements\GenMoveClick.ogg");
  var PlayerList = Game.LoadWindow("interface\IntroMenu\PlayerList.window");
  if(Player.Changed == true)
    {
   Player.Changed = null;
   DoPlayer();
   }
  }


////////////////////////////////////////////////////////////////////////////////
on "close"
  {
  this.Close();
  }


////////////////////////////////////////////////////////////////////////////////
on "yes"
  {
  this.xResult = true;
  this.Close();
  }


////////////////////////////////////////////////////////////////////////////////
on "Keypress"
  {
  var button;

  if(Keyboard.KeyCode==VK_ESCAPE)
    {
    button = this.GetControl("close");
    button.Press();
   }
  else if(Keyboard.KeyCode==VK_RETURN)
    {
    // button = this.GetControl("yes");
    // button.Press();
    }
  }


Quote
#include "scripts\base.inc"
#include "scripts\keys.inc"

// I AM PLAYERLIST

this.xResult = false;
for(var w = 1024; w > 512; w = w - 32)
  {
  this.X = w;
  Sleep(20);
  }


Player.Was = Player.Current;
InitButtons();
NoDelete();
NoNew();
this.GoExclusive();

function InitButtons()
  {
  Game.Interactive = false;
  for(var ib = 1; ib < 7; ib = ib + 1)
    {
   //Initialize buttons
   var ic = this.GetControl(ib);
   Game.Msg("ic is "+ic);
   ic.Text = "";
   ic.Disabled = true;
   ic.Visible = false;
   }
   
  for(ib = 1; ib < Player.Num+1; ib = ib+1)
    {
   ic = this.GetControl(ib);
   ic.Text = Player[ib];
   ic.Disabled = false;
   ic.Visible = true;
   if(Player.Current == ib)
     {
     ic.SetFont("fonts\Arial20BoldRed.font");
     }
   else
     {
     ic.SetFont("fonts\arial20.font");
     }
   }
  Game.Interactive = true;
  }

function NoDelete()
  {
  Game.Interactive = false;
  var d = this.GetControl("Delete");
  if(Player.Current == 1)
    {
   d.Disabled = true;
   d.Visible = true;
   d.SetFont=("fonts\arial20greyed.font");;
   }
  else
    {
   d.Disabled = false;
   d.Visible = true;
    d.SetFont("fonts\arial20.font");   
   }
  Game.Interactive = true;
  }

function NoNew()
  {
  Game.Interactive = false;
  var n = this.GetControl("New");
  if(Player.Num > 5)
    {
   n.Disabled = true;
   n.Visible = true;
   n.SetFont("fonts\arial20greyed.font");
   }
  else
    {
   n.Disabled = false;
   n.Visible = true;
   n.SetFont("fonts\arial20.font");
   }
  Game.Interactive = true;
  }

function CloseThis()
  {
  Player.Was = null;
  this.Close();
  Game.UnloadObject(this);
  }
////////////////////////////////////////////////////////////////////////////////
on "1"
  {
  this.PlaySound("ui_elements\GenMoveClick.ogg");
  Player.Current = 1; 
  InitButtons();
  }
 
on "2"
  {
  this.PlaySound("ui_elements\GenMoveClick.ogg");
  Player.Current = 2; 
  InitButtons();
  }
 
on "3"
  {
  this.PlaySound("ui_elements\GenMoveClick.ogg");
  Player.Current = 3; 
  InitButtons();
  }
 
on "4"
  {
  this.PlaySound("ui_elements\GenMoveClick.ogg");
  Player.Current = 4; 
  InitButtons();
  }
 
on "5"
  {
  this.PlaySound("ui_elements\GenMoveClick.ogg");
  Player.Current = 5; 
  InitButtons();
  }
 
on "6"
  {
  this.PlaySound("ui_elements\GenMoveClick.ogg");
  Player.Current = 6; 
  InitButtons();
  }
 
on "New"
  {
  this.PlaySound("ui_elements\GenMoveClick.ogg");
  var fn = this.GetControl("New");
  NewPlayer = Game.LoadWindow("interface\IntroMenu\NewPlayer.window");
  NewPlayer.GoExclusive();
  while(NewPlayer != null)
    {
   Sleep(20);
   }
  InitButtons();
  NoDelete();
  NoNew();
  fn.Pressed = false;   
  }
 
on "Delete"
  {
  this.PlaySound("ui_elements\GenMoveClick.ogg");
  var fd = this.GetControl("Delete");
  var dw = Game.LoadWindow(""); // ARE YOU SURE?
  if(dw == true)
    {
   Player.Changed = true;
    for(var pd = Player.Current; pd < Player.Num; pd = pd + 1)
      {
     Player[pd] = Player[pd + 1];
     var RegKeyName = "Player" + pd;
      Game.RegWriteString(RegKeyName, Player[pd]);
     }
   var px = Player.Num;
   RegKeyName = "Player"+Player.Num;
   Player[px] = null;
   Game.RegWriteString(RegKeyName, null);
   Player.Num = Player.Num - 1;
   Game.RegWriteNumber("PlayerNum", Player.Num);
   InitButtons();
   NoDelete();
   NoNew();
   }
  dw.Pressed = false;
  }

on "Continue"
  {
  this.PlaySound("ui_elements\GenMoveClick.ogg");
  this.xResult = true;
  CloseThis();     
  }

on "Cancel"
  {
  this.PlaySound("ui_elements\GenMoveClick.ogg");
  if(Player.Current != Player.Was)
    {
   Player.Current = Player.Was;
   InitButtons();
   }
  this.xResult = false;
  CloseThis();
  }


////////////////////////////////////////////////////////////////////////////////
on "Keypress"
  {
  var button;

  if(Keyboard.KeyCode==VK_ESCAPE)
    {
    button = this.GetControl("close");
    button.Press();
   }
  else if(Keyboard.KeyCode==VK_RETURN)
    {
    // button = this.GetControl("yes");
    // button.Press();
    }
  }




Quote
#include "scripts\base.inc"
#include "scripts\keys.inc"

// I AM NEWPLAYER

this.xResult = false;
for(var w = 1024; w > 312; w = w - 64)
  {
  this.X = w;
  Sleep(20);
  }
///////////////////////////////////////////////////////////////////////////////
on "Cancel"
  {
  NewPlayer = null;
  this.Close();
  Game.UnloadObject(this);
  }


////////////////////////////////////////////////////////////////////////////////
on "OK"
  {
  Game.Interactive = false;
  var ed = this.GetControl("NameEditor");
  var pn = ed.Text;
  Game.Msg("Player is "+pn);
  Player.Num = Player.Num+1;
  Game.Msg("Player.Num is "+Player.Num);
  var px = Player.Num;
  Player[px] = pn;
  Player.Current = px;
  Player.Changed = true;
  Game.RegWriteNumber("PlayerNum", Player.Num);
  Game.RegWriteNumber("PlayerCurrent", Player.Current);
  for(var a = 1; a < Player.Num +1; a = a +1)
    {
   var RegKeyName = "Player" + a;
   Game.RegWriteString(RegKeyName, Player[a]);
   }
  Game.Interactive = true;
  NewPlayer = null;
  this.Close();
  Game.UnloadObject(this);
  }


////////////////////////////////////////////////////////////////////////////////
on "Keypress"
  {
  var button;

  if(Keyboard.KeyCode==VK_ESCAPE)
    {
    button = this.GetControl("close");
    button.Press();
   }
  else if(Keyboard.KeyCode==VK_RETURN)
    {
    // button = this.GetControl("yes");
    // button.Press();
    }
  }

Title: Re: Still struggling with keyboard input to Editor field
Post by: metamorphium on June 02, 2011, 01:55:36 PM
ok. before I dig into the code, there are a lot of really shady lines.

try putting away this.GoExclusive(); from the middle script - you already are in exclusive mode!

Also put away the sleeps from the inital loops, they are useless and delay the script (if they're not meant as a weird visual effect). Sleep in a loop is necessary only for endless loops where the computer would get stuck.


Title: Re: Still struggling with keyboard input to Editor field
Post by: Kaz on June 02, 2011, 05:40:39 PM
Thank you. As you suggested, I have removed the extra Exclusive and sleeps. Some of them are actually meant as a weird visual effect, and those I've left in :)

The Editor still does not accept keyboard input.

Thanks again for looking at this. It has me foxed. I've read everything I can find about it. But I cannot find what's wrong with my code.
 
Title: Re: Still struggling with keyboard input to Editor field
Post by: Mnemonic on June 02, 2011, 05:51:45 PM
The best thing (and easiest for all of us) would be if you could make a project that reproduces the issue, so that we can take a look at it.

Quote
(BTW, this 'Post Reply' box is very difficult to write in - it bounces what I'm typing out of sight and any corrections cause its window to scroll)
If you are using Internet Explorer, click the "compatibility view" icon next to address bar.
Title: Re: Still struggling with keyboard input to Editor field
Post by: Kaz on June 02, 2011, 06:24:13 PM
The one I'm working on now isn't big - just a proof of concept of a player management screen.

How should I get it to you?

Title: Re: Still struggling with keyboard input to Editor field
Post by: Kaz on June 03, 2011, 10:30:46 AM
Project zipped and sent to forum at dead code email.

Cheers
Title: Re: Still struggling with keyboard input to Editor field
Post by: Mnemonic on June 03, 2011, 04:19:07 PM
I tested your project and I can enter text without any problems. And I tried MANY times. Are you able to reproduce the problem on several different computers?
There was this old thread (http://forum.dead-code.org/index.php?topic=3758.0) where you seemed to be having troubles with application losing focus. Could that be something similar?
Title: Re: Still struggling with keyboard input to Editor field
Post by: Kaz on June 04, 2011, 01:51:28 PM
I've now made sure nothing else is on the Windows desktop. Still get the same fault.

What's more confusing is that it still fails to work for me in the runtime, every time - but the compiled version of the same code works fine, every time. Can you suggest why that difference might be between the runtime and the compiled?

I also added the following lines to the 'Newplayer' window that contains the editor:
this.Focus();
var e=this.GetControl("NameEditor");
e.Focus();
but still no keyboard input in the runtime.

 ??? ??? ???
 
Title: Re: Still struggling with keyboard input to Editor field
Post by: Mnemonic on June 09, 2011, 08:36:25 AM
I'm convinced it's an application focus problem on a particular machine. Were you ever able to reproduce the issue on other computer? What about windowed / fullscreen mode, any difference? At least in windowed mode you can clearly see if the window is focused.