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: Menu Akce na levé tlačítko  (Read 2818 times)

0 Members and 1 Guest are viewing this topic.

janCZek

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 4
    • View Profile
Menu Akce na levé tlačítko
« on: July 22, 2005, 12:27:17 AM »

Tak si tady jen tak zkouším různě upravovat scripty z dema a chtěl bych předělat game.script tak, aby se menu akce (Talk/Take/LookAt) zobrazilo při klepnutí levého tlačítka myši na objekt. Pravé by pak fungovalo jen na odkládání zvednutých předmětů z inventáře. Bohužel to nějak nemaká. Žádnou chybu mi to sice neukazuje, ale při zobrazeném menu a klepnutím na nějaké z tlačítek se vůbec nic nestane - jen zmizí menu. Takhle jsem to změnil...možná to je blbě, nevím:

Code: [Select]
#include "scripts\base.inc"
#include "scripts\keys.inc"

// 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\menu.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.LoadActor3D("actors\pes\pes.act3d");
Game.MainObject = actor;

// run the "daemon" script
Game.AttachScript("scripts\game_daemon.script");


// which scene to load?
Game.ChangeScene("scenes\scene_1\scene_1.scene");



////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
  var ActObj = Game.ActiveObject;
  if(ActObj!=null)
  {   
    if(Game.SelectedItem != null && Game.SelectedItem != ActObj)
    {
      var Item = Game.SelectedItem;
      if(ActObj.CanHandleEvent(Item.Name)) ActObj.ApplyEvent(Item.Name);
      else if(Item.CanHandleEvent("default-use")) Item.ApplyEvent("default-use");
      else if(ActObj.CanHandleEvent("default-use")) ActObj.ApplyEvent("default-use");
      else {
        var id = Random(1,2);
        switch(id)
      {
      case 1: actor.Talk("To je blbost"); break;
      case 2: actor.Talk("Něco jiného"); break;
      }
      }
    }
   
    if(WinMenu.Visible == true) WinMenu.Visible = false;
    else if(ActObj.CanHandleEvent("Take") || ActObj.CanHandleEvent("Talk") || ActObj.CanHandleEvent("LookAt"))
      {
        MenuObject = Game.ActiveObject;
        var Caption = WinMenu.GetWidget("Caption");
        Caption.Text = MenuObject.Caption;
     
        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;
        if(WinMenu.Y<0) WinMenu.Y = 0;
        if(WinMenu.Y+WinMenu.Height>Game.ScreenHeight) WinMenu.Y = Game.ScreenHeight-WinMenu.Height;

        WinMenu.Visible = true;
        actor.Reset();
       
    }  else ActObj.ApplyEvent("LeftClick");
  } else Scene.ApplyEvent("LeftClick");
}

////////////////////////////////////////////////////////////////////////////////
on "RightClick"
{
  var ActObj = Game.ActiveObject;
  // if inventory item selected? deselect it
  if (Game.SelectedItem != null){
    Game.SelectedItem = null;
    return;
  }
  if(ActObj!=null) ActObj.ApplyEvent("RightClick"); 
}

////////////////////////////////////////////////////////////////////////////////
on "Keypress"
{
  // on Esc or F1 key
  if(Keyboard.KeyCode==VK_ESCAPE)
  {
    // 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);
  }
  else if(Keyboard.KeyCode==VK_F1)
  {
  Scene.ShowGeometry = !Scene.ShowGeometry;
  }
}

////////////////////////////////////////////////////////////////////////////////
on "QuitGame"
{
  // on Alt+F4 (window close)
  // load and display the quit confirmation window
  if(QuestionBox(Game.ExpandString("/IGMENU0009/"))) Game.QuitGame();
}

////////////////////////////////////////////////////////////////////////////////
method QuestionBox(Message, SystemExclusive)
{
if(SystemExclusive==null) SystemExclusive = true;

var Window = Game.LoadWindow("interface\system\quit.window");
Window.Center();
Window.xMessage = Game.ExpandString(Message);

if(SystemExclusive) Window.GoSystemExclusive();
else Window.GoExclusive();

var Result = Window.xResult;
Game.UnloadObject(Window);

return Result;
}


Jiné soubory jsem neupravoval. Proč to tedy nejde?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Menu Akce na levé tlačítko
« Reply #1 on: July 22, 2005, 06:19:30 PM »

Po zbeznem prozkoumani bych rekl, ze tam prebyva ten radek

if(WinMenu.Visible == true) WinMenu.Visible = false;

Ten zpusobuje, ze se po kliknuti menu zavre a jinak tam je IMHO k nicemu.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave
 

Page created in 0.041 seconds with 23 queries.