Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: TheDerman on December 09, 2005, 02:31:28 AM

Title: Fading in/out the inventory window
Post by: TheDerman on December 09, 2005, 02:31:28 AM
Hi,

Just wondering how I can fade the inventory window in and out. I have it at the bottom of the screen, and when the player moves the mouse down there I want the window to fade in (I'm assuming all the items will fade in aswell if the actual window is set to fade). Then when they leave that area, the window fades out.

Where can I put the necessary code?

Thanks.
Title: Re: Fading in/out the inventory window
Post by: Mnemonic on December 09, 2005, 09:17:26 AM
It's mostly a matter of convenience. Personally, I'd create two methods, FadeIn() and FadeOut() and place them to the script attached to your inventory window. Something like:

Code: [Select]
method FadeIn()
{
  // some fade in code similar to what you're using to fade in the actor
  // http://forum.dead-code.org/index.php?topic=936.msg6969#msg6969
}


Then you'd have to modify the game_daemon.script, which handles the inventory display/hide.
Right now it does something like: Game.InventoryVisible = true;
You'd have to replace this line by something like:

Code: [Select]
var InvWindow = Game.GetInventoryWindow();
InvWindow.FadeIn();


I hope that makes sense. If not, feel free to ask for further details :)
Title: Re: Fading in/out the inventory window
Post by: TheDerman on December 09, 2005, 09:21:49 AM
Was I really fading in the actor? How crazy of me - I'm not doing that anymore.  ;D Actually, it's a different game.

Thanks for the help - I'll give it a try.

EDIT - had another question here, but I sorted it out.  8)
Title: Re: Fading in/out the inventory window
Post by: TheDerman on December 10, 2005, 05:49:35 PM
Ok, I'm afraid I don't really understand how to do this inventory fading thing.

I put the method code in my inventory.script? But then after I put all the fading stuff, what do I actually tell it to fade?

This is how I'm fading stuff:

  for(var i=1; i<=10; i=i+1)

etc...

But don't I need to actually state what is I'm fading after that code?  ???

I need mucho more help. Cheers.
Title: Re: Fading in/out the inventory window
Post by: Mnemonic on December 12, 2005, 10:39:58 AM
You put the two methods to the script attached to the inventory window. In your inventory box defintion there's something like:

Code: [Select]
INVENTORY_BOX
{
  ITEM_WIDTH = 65
  ITEM_HEIGHT = 65
  blah blah
  ...

  WINDOW
  {
    blah blah
    ...
   

You need to attach the script to the embedded window like this:


Code: [Select]
INVENTORY_BOX
{
  ITEM_WIDTH = 65
  ITEM_HEIGHT = 65
  blah blah

  WINDOW
  {
    SCRIPT = "path\window_fading.script"
    blah blah
    ...
   

And those two methods will look exactly like the actor fading code in the other thread linked above, but you'll replace "actor" with "this". Since the script is attached to the inventory window, the "this" variable points to the window itself.
I hope that helps.
Title: Re: Fading in/out the inventory window
Post by: TheDerman on December 12, 2005, 11:08:07 AM
I tried all that you suggest but it still won't fade in - I just get nothing, no inventory.

This is my inventory.script attached to the inventory.def

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

method FadeIn()
{
  for(var i=1; i<=10; i=i+1)
   {
    this.AlphaColor = MakeRGBA(255, 255, 255, 25*i);
    Sleep(100);
   }
  this.AlphaColor = MakeRGBA(255, 255, 255, 255);
}

method FadeOut()
{
  for(var i=10; i>=10; i=i-1)
   {
    this.AlphaColor = MakeRGBA(255, 255, 255, 25*i);
    Sleep(100);
   }
  this.AlphaColor = MakeRGBA(255, 255, 255, 0);
}

This is my game_daemon.script

Code: [Select]
  // display the inventory window
  var InvWindow = Game.GetInventoryWindow();

  if(Game.Interactive && Game.MouseY > 704 && !Game.ResponsesVisible && !WinMenu.Visible)
    {
      InvWindow.FadeIn();
    }

  else if(Game.MouseY < 704 || Game.ResponsesVisible || !Game.Interactive)
    {
      InvWindow.FadeOut();
    }


But it doesn't work.  ???
Title: Re: Fading in/out the inventory window
Post by: Mnemonic on December 12, 2005, 11:20:15 AM
Ok, one more thing you'll probably have to do, this.Visible = true; at the beginning of FadeIn, and this.Visible = false; at the end of FadeOut. That should do the trick, I hope...?
Title: Re: Fading in/out the inventory window
Post by: TheDerman on December 12, 2005, 11:36:59 AM
Nope. I'm afraid that didn't work either.   ;D

Tough one eh?
Title: Re: Fading in/out the inventory window
Post by: TheDerman on December 12, 2005, 11:43:53 AM
Ok, I replaced your this.Visible = true; with  Game.InventoryVisible = true; at the start of FadeIn and  Game.InventoryVisible = false; at the end of FadeOut.

Now the inventory continuously fades in and in and in and in forever. And just disappears when I move the mouse out of the area, so I guess the fade in is working somewhat but the fadeout not at all...???

 ;D

EDIT - could this be due to the game_daemon.script looping? So everytime that script loops around, and the conditions for fading in the inventory are TRUE (i.e. my mouse is at the bottom of the screen), it's fading in the inventory again and again...???
Title: Re: Fading in/out the inventory window
Post by: metamorphium on December 12, 2005, 11:57:35 AM
yes, you should put there condition to fadein or out only  if it's not been faded already.
 
Title: Re: Fading in/out the inventory window
Post by: TheDerman on December 12, 2005, 12:17:46 PM
Thanks Metamorphium, I guessed that -  took me a bit to figue it out how to put that condition in there though.   ;D

But I now have a perfectly fading inventory - yay!!! Just need to adjust the speed now.

Here's the code I ended up with in case anyone else comes looking.

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

global Faded;

method FadeIn()
{
 Game.InventoryVisible = true;
 for(var i=1; i<=10; i=i+1)
   {
    this.AlphaColor = MakeRGBA(255, 255, 255, 25*i);
    Sleep(100);
   }
 this.AlphaColor = MakeRGBA(255, 255, 255, 255);
 Faded = true;
}

method FadeOut()
{
  for(var i=10; i>=1; i=i-1)
   {
    this.AlphaColor = MakeRGBA(255, 255, 255, 25*i);
    Sleep(100);
   }
  this.AlphaColor = MakeRGBA(255, 255, 255, 0);
 Game.InventoryVisible = false;
 Faded = false;
}

and the game_daemon.script
Code: [Select]
  // display the inventory window
  var InvWindow = Game.GetInventoryWindow();
  if(Game.Interactive && Game.MouseY > 704 && !Game.ResponsesVisible && !WinMenu.Visible && Faded ==false)
   {
     InvWindow.FadeIn();
   }

  else if(Game.MouseY < 704 || Game.ResponsesVisible || !Game.Interactive)
   {
     InvWindow.FadeOut();
   }

And I had to put global Faded = false; at the top of the game_daemon.script (I think - well I did anyway and it works  ;D).

Thanks guys - I'm very happy now.  ::rock
Title: Re: Fading in/out the inventory window
Post by: metamorphium on December 12, 2005, 04:44:57 PM
This can't work IMO properly. Try to fade it out and then quickly move your cursor up and down. You will probably see another fadeout.
I would recommend trying something like this:

Code: [Select]
method FadeIn()
{
  ... // the code from your function as-is
  Faded = true;
}

method FadeOut()
{
  ... // the code from your function as-is
  Faded = false;
}

// the conditions should be something like
if (!Faded)  InvWindow.FadeIn();
//And
if (Faded)  InvWindow.FadeOut();


It's of course untested, but should work anyway. ;)
Title: Re: Fading in/out the inventory window
Post by: TheDerman on December 12, 2005, 06:12:43 PM
It works perfectly with the code I stated as far as the fade in and out goes.

Only problem was that it was continuously running the fadeout code when the inventory was not visible. That didn't affect the fade in or out, but it did slow down my caption window a little, but I fixed that with another condition so no problems here.  8)

Thanks again.
Title: Re: Fading in/out the inventory window
Post by: SBOVIS on January 12, 2006, 08:42:57 PM
Hi there,
            Is there any chance oyu could put the full scripts for this and how to achieve this somewhere on the forum.


I would like to have a go at fading in/out my inventory box and maybe other windows??

If not then maybe you can send me the scripts via email and how to achieve this.

(Been trying to do this for ages!! hahahahahahahahahahaha)
Title: Re: Fading in/out the inventory window
Post by: PoselSmrti on January 12, 2006, 10:03:09 PM
I have found this thread and it is great  :)!!! Very thx to all! :)
Title: Re: Fading in/out the inventory window
Post by: SBOVIS on January 13, 2006, 10:22:29 AM
I am having trouble with this, I have used the scripts listed but the inventory does not show at all now.


I have connected it to my INVENTORY window script.

Updated Game Deamon but still nothing.


Any help or full scripts would be good, save my hair being pulled out. hahahahahahaha


Title: Re: Fading in/out the inventory window
Post by: TheDerman on January 13, 2006, 02:37:17 PM
These are the scripts I have:


inventory.script:

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

global Faded;

method FadeIn()
{
 Game.InventoryVisible = true;
 for(var i=1; i<=10; i=i+1)
   {
    this.AlphaColor = MakeRGBA(255, 255, 255, 25*i);
    Sleep(40);
   }
 this.AlphaColor = MakeRGBA(255, 255, 255, 255);
 Faded = true;
}

method FadeOut()
{
  for(var i=10; i>=1; i=i-1)
   {
    this.AlphaColor = MakeRGBA(255, 255, 255, 25*i);
    Sleep(40);
   }
 this.AlphaColor = MakeRGBA(255, 255, 255, 0);
 Game.InventoryVisible = false;
 Faded = false;
}


And the relevant section of the game_daemon.script:

Code: [Select]
  // display the inventory window
  var InvWindow = Game.GetInventoryWindow();
  if(Game.Interactive && Game.MouseY > 704 && !Game.ResponsesVisible && !WinMenu.Visible && Faded==false)
   {
     InvWindow.FadeIn();
   }

  else if(Game.MouseY < 704 && Faded==true)
   {
     InvWindow.FadeOut();
   }

Hope that helps.
Title: Re: Fading in/out the inventory window
Post by: SBOVIS on January 13, 2006, 03:41:30 PM
Many thanks TheDerman.

In the game deamon scripts does this new code replace the old (unchanged demo script) or does it need to be added with the old code??


Cheers
Title: Re: Fading in/out the inventory window
Post by: TheDerman on January 13, 2006, 03:49:02 PM
It replaces only the part of the daemon script which deals with the inventory (down at the bottom) - everything else should be left as it is.

You will have to change certain things specific to your game, like the Y value - my inventory is at the bottom of the screen - you may have yours at the top or somewhere else.
Title: Re: Fading in/out the inventory window
Post by: SBOVIS on January 13, 2006, 03:51:26 PM
ok many thanks, will give it a bash and let you know.


Title: Re: Fading in/out the inventory window
Post by: SBOVIS on January 14, 2006, 01:46:52 PM
Hi,
     I have tried to implement these scripts but my inventory does not show.

I have attached the inventory fade script to my inventory window and changed Game Deamon script but still no inventory is showing.

TheDerman can you show me your full Game Deamon script on this thread as I think that is the issue here.


Cheers
Title: Re: Fading in/out the inventory window
Post by: PoselSmrti on January 14, 2006, 04:32:46 PM
Hi SBOVIS :)!

Did you create a global Faded = false; in your game_daemon.script?
Title: Re: Fading in/out the inventory window
Post by: SBOVIS on January 15, 2006, 12:35:39 AM
Certainly did, still no show on my inventory though, If I take the fade code out and reset it back the way it was, I get the inventory no problem. (just not fadeing)




Title: Re: Fading in/out the inventory window
Post by: TheDerman on January 15, 2006, 09:32:29 AM
Maybe if you post your inventory script and daemon script, we could spot the problem?

Did you insert SCRIPT = "interface\inventory.script" into your inventory.def in the WINDOW section of the file?
Title: Re: Fading in/out the inventory window
Post by: metamorphium on January 15, 2006, 10:15:25 AM
Also please check your wme.log for error messages. You'll usually find some clues as why it doesn't work there. If there is something written what looks like an error, post it together with requested files too. ;)
Title: Re: Fading in/out the inventory window
Post by: SBOVIS on January 15, 2006, 03:04:50 PM
ok will check and post files if needed.


many thanks



cheers
Title: Re: Fading in/out the inventory window
Post by: SBOVIS on January 16, 2006, 01:43:20 PM
Got this to work now, many thanks, looks great,

It was the Game.Deamon script as I have other code that conflicted with it.


By the way can this fade method be used for any windows??

I have several that would work well when faded, I have defined windows so do I do a similar script and attach it and call that within other scripts when I want it to fade??


Seems feasible??

Title: Re: Fading in/out the inventory window
Post by: metamorphium on January 16, 2006, 01:44:55 PM
yes, you can definitely use it for any window you like.

Glad it works for you now.
Title: Re: Fading in/out the inventory window
Post by: djb on January 16, 2006, 03:57:00 PM
i think, that you can optimize it and skip needlessly tests in game_daemon.script...

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

global Faded;

method FadeIn()
{
 if(!Faded) {
  Game.InventoryVisible = true;
  for(var i = 0; i <= 255; i = i + 25) {
    this.AlphaColor = MakeRGBA(255, 255, 255, i);
    Sleep(40);
   }
   this.AlphaColor = MakeRGBA(255, 255, 255, 255);
   Faded = true;
 }
}

method FadeOut()
{
 if(Faded) {
  for(var i = 255; i >= 0; i = i - 25) {
   this.AlphaColor = MakeRGBA(255, 255, 255, i);
   Sleep(40);
  }
  this.AlphaColor = MakeRGBA(255, 255, 255, 0);
  Game.InventoryVisible = false;
  Faded = false;
 }
}
Title: Re: Fading in/out the inventory window
Post by: SBOVIS on January 16, 2006, 04:32:33 PM
This is cool, I now have an inventory and other windows fadeing in and out, many thanks.