Need Help with Gemini Rue-esque Verbcoin Gui

Started by Vault15, Mon 07/05/2012 23:10:20

Previous topic - Next topic

Vault15

I've been working at this for over a week and have searched all over to try and have the gui/inventory just like in Gemini Rue (on steam, made with AGS). If you play the demo you'll see exactly what I want for my game. 100% the same type of gui (obviously modified graphics and "move" instead of "kick")

I have the latest version of AGS and managed to modify the original verbcoin gui enough so that left click walks and right clicking brings up the Verbcoin Gui. The problem is that it's very glitchy and seems to crash far too often, so I suppose I can't read the scripting well enough yet (putting 100% effort into it though).

I need the Gui to do the following:

1. Left click makes the character walk and displays the hotspot name above and to the right of the cursor (not the middle of the screen!)
2. Right click brings up a hybrid verbcoin inventory where you can click "look, use, talk, move" and you can see items you've picked up right below those icons.

In other words, when you right click you'll be able to see the verbcoin gui and inventory. I only want right click to work on hotspots and not just anywhere on the screen. So if you right click on a blank spot/non-hotspot area then it won't do anything.

Does anyone have a nice template that they'd be willing to share so that I can get to this point? Once I have the gui set I can actually work on my storyline, scenes, rooms, characters, dialogue (the whole game) so I can't tell you how much this will help me.

Here is what I have right now as my VerbCoin Gui:
http://www.mediafire.com/?axd9ctg5udee3ha


Thanks so much in advance for any help!  :)

monkey0506

#1
Without taking the time to download your code, some basic thoughts:

Quote from: Vault15 on Mon 07/05/2012 23:10:201. Left click makes the character walk

Code: ags
// GlobalScript.asc

function on_mouse_click(MouseButton button)
{
  if (button == eMouseLeft)
  {
    ProcessClick(mouse.x, mouse.y, eModeWalkto);
  }
}


Quote from: Vault15 on Mon 07/05/2012 23:10:20and displays the hotspot name above and to the right of the cursor (not the middle of the screen!)

Code: ags
// GlobalScript.asc
String oldLocationText;

function repeatedly_execute()
{
  if (!gVerbcoin.Visible)
  {
    String text = Game.GetLocationName(mouse.x, mouse.y);
    if (text == null) text = "";
    int width = GetTextWidth(text, lblStatusline.Font);
    int height = GetTextHeight(text, lblStatusline.Font, width);
    gStatusline.X = mouse.x; // text position begins at mouse.x
    gStatusline.Y = (mouse.y - height - 5); // position text 5px above mouse.y
    lblStatusline.Text = text;
    oldLocationText = text;
  }
  else
  {
    // reposition gStatusline as needed
    GUIControl *control = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
    Button *button = null;
    if (control != null) button = control.AsButton;
    if (button == null) return; // end the function if there mouse isn't over a button
    lblStatusline.Text = "";
    if (button == btnLook) lblStatusline.Text = "Look at ";
    else if (button == btnUse) lblStatusLine.Text = "Use ";
    lblStatusline.Text = lblStatusline.Text.Append(oldLocationText);
  }
}


Quote from: Vault15 on Mon 07/05/2012 23:10:202. Right click brings up a hybrid verbcoin inventory

Code: ags
// GlobalScript.asc

function on_mouse_click(MouseButton button)
{
  if (button == eMouseLeft) // including the code from above...
  {
    ProcessClick(mouse.x, mouse.y, eModeWalkto);
  }
  else if (button == eMouseRight)
  {
    if (GetLocationType(mouse.x, mouse.y) != eLocationNothing)
    {
      gVerbcoin.Visible = true;
      gVerbcoin.X = mouse.x;
      gVerbcoin.Y = mouse.y;
    }
  }
}


Quote from: Vault15 on Mon 07/05/2012 23:10:20where you can click "look, use, talk, move"

Code: ags
// GlobalScript.asc

function btnLook_OnClick(GUIControl *control, MouseButton button)
{
  gVerbcoin.Visible = false; // remove this if you want the GUI to stay on
  ProcessClick(gVerbcoin.X, gVerbcoin.Y, eModeLookat);
}

function btnUse_OnClick(GUIControl *control, MouseButton button)
{
  gVerbcoin.Visible = false;
  ProcessClick(gVerbcoin.X, gVerbcoin.Y, eModeInteract);
}

// etc.


Quote from: Vault15 on Mon 07/05/2012 23:10:20and you can see items you've picked up right below those icons.

Presuming you want something like left-click select inventory item, right-click look at (make sure that in General Settings you are handling inventory clicks in the script):

Code: ags
// GlobalScript.asc

function on_mouse_click(MouseButton button)
{
  if (button == eMouseLeft)
  {
    ProcessClick(mouse.x, mouse.y, eModeWalkto);
  }
  else if (button == eMouseRight)
  {
    if (GetLocationType(mouse.x, mouse.y) != eLocationNothing)
    {
      gVerbcoin.Visible = true;
      gVerbcoin.X = mouse.x;
      gVerbcoin.Y = mouse.y;
    }
  }
  else if (button == eMouseLeftInv)
  {
    player.ActiveInventory = inventory[game.inv_activated];
    gVerbcoin.Visible = false;
  }
  else if (button == eMouseRightInv)
  {
    inventory[game.inv_activated].RunInteraction(eModeLookat);
  }
}


Should be enough to give you an idea of what's going on.

Vault15

Thanks so much for your help! I like how you answered every single thing I had needed to figure out. I'll go through what you posted and let you know when I have everything as I need.

If this works I'm definitely giving you a place in the ending credits. I really respect those who give such detailed, helpful responses.


Kudos

monkey0506

It's actually a relatively simple interface to set up. You'll notice that I posted the on_mouse_click function multiple times, just wanted you to be able to see what code was being added for which bit.

I also have a habit of typing out code for people without testing it, so I made a couple of minor corrections revisions. ;)

Let us know if any of that code doesn't make sense or for any reason doesn't work properly.

Vault15

#4
What should I do with the VerbCoin gui script I have already? I'm not sure what all I need to keep or what will conflict with your code exactly. I can still tell that this is a tremendous help, so I was just checking since I'm sure my code conflicts somehow (is your code meant to work with the default verbcoin gui in ags?).

For some reason I get a compile error with "int width = GetTextWidth(text, lblStatusline.Font);"  - The error was in lblStatusline



Edit 2: Alright, here's exactly what I modified now. Is this correct?:

Code: ags

String oldLocationText;

function repeatedly_execute()
{
  if (!gVerbCoin.Visible)
  {
    String text = Game.GetLocationName(mouse.x, mouse.y);
    if (text == null) text = "";
    int width = GetTextWidth(text, Game.NormalFont);
    int height = GetTextHeight(text, Game.NormalFont, width);
    gOverhotspot.X = mouse.x; // text position begins at mouse.x
    gOverhotspot.Y = (mouse.y - height - 5); // position text 5px above mouse.y
    overhotspot.Text = text;
    oldLocationText = text;
  }
  else
  {
    // reposition gStatusline as needed
    GUIControl *control = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
    Button *button = null;
    if (control != null) button = control.AsButton;
    if (button == null) return; // end the function if there mouse isn't over a button
    overhotspot.Text = "";
    if (button == look_button) overhotspot.Text = "Look at ";
    else if (button == interact_button) overhotspot.Text = "Use ";
    overhotspot.Text = overhotspot.Text.Append(oldLocationText);
  }
}




The default Guis mine came with were:

0: gOverhotspot
1: gVerbcoin
2: gInventory
3: gInvUnderlay


Thanks for your continued help.


Also if you do happen to look at the code I have, ignore the comments since they are unedited from the default gui script. Some comments won't make any sense (text saying right mouse when it's left, etc)

monkey0506

I suppose I could take a look at your code. ;)

The issue with lblStatusline wasn't a font issue, I thought you would pick up on the fact that it was just a made up script name for your status line label.

The issue with gStatusline is that you didn't get that it would be the script name for the GUI holding the status line label control. :P

Vault15

#6
(erased) - I can't seem to delete posts. Originally I had my entire code but it bloated the discussion far too much so I'm going to zip them all instead into 1 file. It's much better for everyone that way.

If a mod sees the (erased) posts, please delete them.

SMF spam blocked by CleanTalk