(SOLVED) Modifying the Sierra template

Started by Haruspex, Sun 10/11/2024 23:58:35

Previous topic - Next topic

Haruspex

I'm diving into AGS again, and at the moment I'm working on UI. I thought I would keep it simple and base everything around the Sierra template. My plan is to create a sort of SCUMM/Sierra hybrid thing. Here's what I have so far:

Screenshot

I haven't modified it much. I moved the icon bar to the bottom of the screen and set it to always show. The status bar now only displays the current hotspot and it's directly above the icon bar. On the icon bar itself, I've removed the inventory button, save, load, and quit. This required me to go into the global script and ensure that the save and load buttons in the panel properly brought up the save and load GUIs.

Next, I modified the inventory GUI by removing all the buttons but the scroll buttons. Then I resized it and made it always show on top of the icon bar.

Of course the graphics have been changed, and everything's been resized.

In the global script, I had to remove some references to buttons that no longer exist.

It works... kinda. I can toggle between walk, interact, look, and talk just fine, and those work as expected. I can also scroll through the inventory and select an inventory item. My mouse cursor and mouse mode change correctly, and the inventory item shows up in the button next to it correctly as the currently active inventory item.

Where I'm running into an issue is selecting an inventory item seems to hijack my mouse cursor. Once an inventory item is chosen, walk and interact become the inventory item cursor, even though they work correctly as walk and interact. Strangely it doesn't seem to affect the talk and examine cursors.

I'm sure I'm missing something, as there's functionality the script probably expects that no longer exists, but I'm really struggling to identify what that is and replace it with something that works.

Edit:
The problem turned out to be the new mouse-cursor graphics I had made. Switching to the new 16x16 cursor graphics broke something, with no rhyme or reason as to why. The solution was to stick those same cursor graphics into the corner of a larger 28x27 pixel image and use those instead. It works, but it's a head-scratcher as to why just swapping the graphics broke it.

Crimson Wizard

Quote from: BeardFacePixelHead on Sun 10/11/2024 23:58:35Where I'm running into an issue is selecting an inventory item seems to hijack my mouse cursor. Once an inventory item is chosen, walk and interact become the inventory item cursor, even though they work correctly as walk and interact. Strangely it doesn't seem to affect the talk and examine cursors.

That's ... not expected. Do you use "Mouse.ChangeModeGraphic" or "Mouse.UseModeGraphic" anywhere in your code?

I think it would be easier to tell if you'd show all the script relevant to mouse controls in your game.

Haruspex

#2
Here's a Pastebin link of the entire modified global script.

In case you don't want to dig through that mess, here's are bits of it that may be relevant:

Code: ags
//=============================================================================
// INVENTORY WINDOW
//=============================================================================

function btnInvUp_Click(GUIControl *control, MouseButton button)
{
  invCustom.ScrollUp();
}

function btnInvDown_Click(GUIControl *control, MouseButton button)
{
  invCustom.ScrollDown();
}

function btnIconCurInv_Click(GUIControl *control, MouseButton button)
{
  if (player.ActiveInventory != null)
  {
    mouse.Mode = eModeUseinv;
  }
}

Code: ags
function handle_room_click(MouseButton button)
{
  if (button == eMouseLeft)
  {
    // left-click, so try using the current mouse cursor mode at this position
    Room.ProcessClick(mouse.x, mouse.y, mouse.Mode );
  }
  else if (button == eMouseRight || button == eMouseWheelSouth){
    // right-click or mouse wheel down will cycle the mouse cursor mode forwards
    mouse.SelectNextMode();
  }
  else if (button == eMouseMiddle)
  {
    // middle-click makes the character walk to clicked area, regardless of cursor mode
    Room.ProcessClick(mouse.x, mouse.y, eModeWalkto);
  }
  else if (button == eMouseWheelNorth)
  {
    // mouse wheel up will cycle the cursor mode backwards
    mouse.SelectPreviousMode();
  }
}

Code: ags
function handle_inventory_click(MouseButton button)
{
  // InventoryItem.GetAtScreenXY could return null here
  // so using game.inv_activated instead is a safer option
  InventoryItem* item = inventory[game.inv_activated];
  
  if (button == eMouseLeftInv)
  {
    if (mouse.Mode == eModeInteract)
    {
      // interact mode selects an inventory item
      player.ActiveInventory = item;
    }
    else if (mouse.Mode == eModeUseinv)
    {
      if (item.ID != player.ActiveInventory.ID)
      {
        // use one item on another
        item.RunInteraction(eModeUseinv);
      }
    }
    else
    {
      // otherwise run corresponding interaction (LookAt, etc)
      item.RunInteraction(mouse.Mode);
    }
  }
}

Code: ags
function on_mouse_click(MouseButton button)
{
  if (button == eMouseLeftInv || button == eMouseRightInv || button == eMouseMiddleInv)
  {
    handle_inventory_click(button);
  }
  // game is paused, then don't process mouse clicks inside the room
  else if (!IsGamePaused())
  {
    handle_room_click(button);
  }
}

Oh, and "Mouse.UseModeGraphic" is present here:
Code: ags
// hide the HUD and show a GUI
function open_gui(GUI* gui_to_open)
{
  lblOverHotspot.Visible = false;
  gIconbar.Visible = false;
  gInventory.Visible = false;
  gStatusline.Visible = false;
  mouse.UseModeGraphic(eModePointer);
  gui_to_open.Visible = true;
}

Thanks for looking at this for me...

Crimson Wizard

Hmm, I don't see anything wrong...
maybe somebody else will have ideas.

Khris

Can you upload the source files so we can take a look?

Haruspex

Okay, absolutely bizarre...

I was determined to figure it out last night, so I started over. The issue is not in the script at all. I diligently tested the game with each change made, and I was absolutely baffled that even with every single modification implemented, it worked perfectly.

So I started swapping out the UI graphics, and with all the UI bits changed, it STILL worked perfectly, that is until I swapped out the mouse cursors themselves. POW, now I have the same problem.

For some reason, simply swapping out the default mouse cursors causes the game to get all confused about them for absolutely no reason. It's baffling. I re-imported the old mouse cursors back in, and now it works perfectly fine again. It's a head-scratcher for sure.

I tried importing the new cursors as new sprites, then switching the cursors to the new sprites while leaving the defaults alone, the problem re-emerges.

So I deleted the new sprites. Switched the cursors back to the defaults. That fixed it. I then re-made the new cursor sprites but with a bigger image. I used the size of the default "walk" cursor sprite as a base. The new cursors are much smaller, so I just stuck those graphics in the corner of the larger image. I imported the new sprites, switched the cursor images, and NOW it all works perfectly again...

I am extremely confused why that worked though. The new cursors were 16x16 images. I have them in the corner of 28x27 images now, and everything is fine. Nothing else changed.

Just a quirk of the engine maybe?

eri0o

The sprite shouldn't matter, can't you share the project?

Haruspex

Quote from: eri0o on Mon 11/11/2024 14:59:04The sprite shouldn't matter, can't you share the project?
You're absolutely right, which is why it's so weird.
If you want to mess with it, here are the files. This is the working version with the new, larger sized cursor sprites. The cursor sprites that didn't work properly were sized 16x16.

Crimson Wizard

Quote from: BeardFacePixelHead on Mon 11/11/2024 15:12:22If you want to mess with it, here are the files. This is the working version with the new, larger sized cursor sprites. The cursor sprites that didn't work properly were sized 16x16.

Well, we meant the project that does not work, as even if we try to replicate the problem, we might do something different from what you did.

I tried, importing a 16x16 sprite, and set it as a walk cursor. Nothing bad happened so far as I can see. I can still select items, and then switch to "walk" cursor, and it displays a "walk" image.

Haruspex

Quote from: Crimson Wizard on Mon 11/11/2024 16:09:59Well, we meant the project that does not work, as even if we try to replicate the problem, we might do something different from what you did.
Oh, sure thing. Here's the broken version. The only difference is the 4 cursor sprites.

Crimson Wizard

#10
Yes, I can confirm this happening, and also if I export a single cursor sprite from the "broken" version and import to the "working" version, and set as "interact" cursor, then that cursor gets broken too.

At this point I begin to suspect a engine's bug...

EDIT: another thing I noticed is that this bug happens after you cycle cursors with the right mouse button. And it only seems to happen to cursor modes adjancent to "use inv".

EDIT2: Indeed , this happens only in Direct3D/OpenGL graphic drivers, but not Software driver. Which means this is related to the texture cache again.

I still do not understand how is this related to the sprite's size though.
Okay, I think i found the mistake.

Crimson Wizard

So, what was happening, because of a mistake in the engine, when switching cursors the engine was copying item cursor image over other cursor images so long as they have matching format (size and color depth).

Here's a temporary build with a fix, may be downloaded and used:
https://cirrus-ci.com/task/4569629144645632

This fix will be included into the next 3.6.1 patch.

Haruspex

Spectacular!  :-D

Thanks a ton for everything you do with maintaining my favorite game engine.

SMF spam blocked by CleanTalk