Chaos Project

RPG Maker => RPG Maker Scripts => RMXP Script Database => Topic started by: Fantasist on January 08, 2008, 02:31:29 pm

Title: [XP] Moving Windows v1.0
Post by: Fantasist on January 08, 2008, 02:31:29 pm
Moving Windows
Authors: Fantasist
Version: 1.0
Type: Graphical Enhancement
Key Term: Misc System



Introduction

Moves a window with a 'decelerating' effect (think STCMS)


Features




Screenshots

N/A


Demo

Paste this in a new slot just below Scene_Menu and you have your demo (after installing the script of course)

class Scene_Menu

  def main
    s1 = $data_system.words.item
    s2 = $data_system.words.skill
    s3 = $data_system.words.equip
    s4 = 'Status'
    s5 = 'Save'
    s6 = 'End Game'
    @command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6])
    @command_window.index = @menu_index
    @command_window.y = -224
    if $game_party.actors.size == 0
      (0..3).each {|i| @command_window.disable_item(i)}
    end
    @command_window.disable_item(4) if $game_system.save_disabled
    # Make play time window
    @playtime_window = Window_PlayTime.new
    @playtime_window.x = -160
    @playtime_window.y = 224
    # Make steps window
    @steps_window = Window_Steps.new
    @steps_window.x = -160
    @steps_window.y = 320
    # Make gold window
    @gold_window = Window_Gold.new
    @gold_window.x = -160
    @gold_window.y = 416
    # Make status window
    @status_window = Window_MenuStatus.new
    @status_window.x = 640
    @status_window.y = 0
    # Move the windows
    @command_window.move(0, 0)
    @playtime_window.move(0, 224)
    @steps_window.move(0, 320)
    @gold_window.move(0, 416)
    @status_window.move(160, 0)
   
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      break if $scene != self
    end
    Graphics.freeze
    @command_window.dispose
    @playtime_window.dispose
    @steps_window.dispose
    @gold_window.dispose
    @status_window.dispose
  end
 
  alias moving_wins_test_menu_upd update
  def update
    @command_window.move(0, 0)
    @playtime_window.move(0, 224)
    @steps_window.move(0, 320)
    @gold_window.move(0, 416)
    @status_window.move(160, 0)
    moving_wins_test_menu_upd
  end
 
end




Script

Paste in a new script slot above main.

#==============================================================================
# ** Moving Windows
#------------------------------------------------------------------------------
# by Fantasist
# Version: 1.0
# Date: 14-Sep-2009
#------------------------------------------------------------------------------
# Version History:
#
#   1.0 - First version
#------------------------------------------------------------------------------
# Description:
#
#     This script adds moving functionality to windows.
#------------------------------------------------------------------------------
# Compatibility:
#
#     Might not be compatible with other similar scripts.
#------------------------------------------------------------------------------
# Instructions:
#
#     Paste this script below "Window_Base" and above "Main".
#
#     The syntax for moving a window is:
#
#           my_window.move(dest_x, dest_y[, move_speed])
#
#     where
#           dest_x: Destination X coordinate
#           dest_y: Destination Y coordinate
#           move_speed (optional): Speed divider. Larger numbers means faster.
#
#     The attributes "dest_x", "dest_y" and "move_speed" can be used directly
#     without using the "move" function all the time.
#
#     The "moving?" function returns "true" if the windows are in motion. This
#     can be used as an event in exotic systems of all sorts :)
#------------------------------------------------------------------------------
# Issues:
#
#     None known.
#------------------------------------------------------------------------------
# Credits and Thanks:
#
#   Fantasist - For making this.
#------------------------------------------------------------------------------
# Notes:
#
#   If you have any questions, suggestions or comments, you can find me at:
#
#    - www.chaos-project.com
#    - www.quantumcore.forumotion.com
#
#   Enjoy ^_^
#==============================================================================

#==============================================================================
# ** Window_Base
#==============================================================================
class Window_Base < Window
  #--------------------------------------------------------------------------
  # * Attributes
  #--------------------------------------------------------------------------
  attr_accessor :dest_x
  attr_accessor :dest_y
  attr_accessor :move_speed
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias move_wins_winbase_init initialize
  def initialize(x, y, width, height)
    move_wins_winbase_init(x, y, width, height)
    self.dest_x = x
    self.dest_y = y
    self.move_speed = 3
  end
  #--------------------------------------------------------------------------
  # * Moving?
  #--------------------------------------------------------------------------
  def moving?
    return (self.x != self.dest_x || self.y != self.dest_y)
  end
  #--------------------------------------------------------------------------
  # * Move
  #--------------------------------------------------------------------------
  def move(dest_x, dest_y, move_speed = nil)
    self.dest_x = dest_x
    self.dest_y = dest_y
    self.move_speed = move_speed unless move_speed.nil?
  end
  #--------------------------------------------------------------------------
  # * Move Wins
  #--------------------------------------------------------------------------
  def move_wins
    dx = (self.dest_x - self.x).to_f / self.move_speed
    dy = (self.dest_y - self.y).to_f / self.move_speed
    # Decimal correction
    dx = self.dest_x > self.x ? dx.ceil : dx.floor
    dy = self.dest_y > self.y ? dy.ceil : dy.floor
    # Moving
    self.x += dx
    self.y += dy
  end
  #--------------------------------------------------------------------------
  # * x=
  #--------------------------------------------------------------------------
  def x=(val)
    self.dest_x = val unless moving?
    super(val)
  end
  #--------------------------------------------------------------------------
  # * y=
  #--------------------------------------------------------------------------
  def y=(val)
    self.dest_y = val unless moving?
    super(val)
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  alias move_wins_winbase_update update
  def update
    move_wins_winbase_update
    move_wins if moving?
  end
end


Alpha 1 version (for reference): ShowHide


#==============================================================================
# Moving windows (Alpha 2)
# by Fantasist
#------------------------------------------------------------------------------
#  This adds the 'move' function to windows. Syntax is
#    @window.move(dest_x, dest_y)
#  where
#       @window :The window you want to move
#       dest_x    :Destination x coordinate
#       dest_y    :Destination y coordinate
#==============================================================================

class Window_Base < Window
#--------------------------------------------------------------------------
# * Initialize
#--------------------------------------------------------------------------
alias moving_win_base_init initialize
def initialize(x, y, w, h)
  moving_win_base_init(x, y, w, h)
  @dest_x, @dest_y = x, y
  @tot_x = @tot_y = 0
 end
#--------------------------------------------------------------------------
# * moving? - checks if the window needs moving
#--------------------------------------------------------------------------
def moving?
  return self.x != @dest_x || self.y != @dest_y
end
#--------------------------------------------------------------------------
# * Move - prepares variables and sets off the moving process
#--------------------------------------------------------------------------  
def move(dest_x, dest_y)
  @dest_x = dest_x
  @dest_y = dest_y
  @tot_x = (dest_x - self.x).abs
  @tot_y = (dest_y - self.y).abs
end
#--------------------------------------------------------------------------
# Move Windows - the actual processing of movement
#--------------------------------------------------------------------------  
def move_wins
  x = self.x
  y = self.y
  dist_x = [((@dest_x-x).abs/3.0).ceil, (@tot_x/3.0).ceil].min
  dist_y = [((@dest_y-y).abs/3.0).ceil, (@tot_y/3.0).ceil].min
  @dest_x > x ? self.x += dist_x : self.x -= dist_x
  @dest_y > y ? self.y += dist_y : self.y -= dist_y
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias upd_win_base_move update
def update
  upd_win_base_move
  move_wins if moving?
end
end



Instructions

Paste this script below "Window_Base" and above "Main".

The syntax for moving a window is:
my_window.move(dest_x, dest_y[, move_speed])


where
     dest_x: Destination X coordinate
     dest_y: Destination Y coordinate
     move_speed (optional): Speed divider. Larger numbers means faster.

   The attributes "dest_x", "dest_y" and "move_speed" can be used directly without using the "move" function all the time.

   The "moving?" function returns "true" if the windows are in motion. This can be used as an event in exotic systems of all sorts :)


Compatibility

Might not be compatible with other similar scripts.


Credits and Thanks

Credit Fantasist (me) for making it.


Author's Notes

If you have any questions, suggestions or comments, you can find me at:

- www.chaos-project.com
- www.quantumcore.forumotion.com

Enjoy ^_^
Title: Re: Basic Moving Windows
Post by: Nortos on January 08, 2008, 05:59:22 pm
was this ur first script you made when you started scripting?
Title: Re: Basic Moving Windows
Post by: Fantasist on January 10, 2008, 12:10:09 am
My first complete script is my Battle Cursor (now integrated into Tons). My first scripting was mods to the CMS. Changed the window positions and things like that.
Title: Re: Basic Moving Windows
Post by: Calintz on January 10, 2008, 03:35:22 pm
Could you maybe post an example of when this script would be good to use?
Title: Re: Basic Moving Windows
Post by: Nortos on January 10, 2008, 07:47:19 pm
it animates windows if I'm correct? Makes them slide into place like Blizz's cms I think with all windows u want it to
Title: Re: Basic Moving Windows
Post by: Calintz on January 10, 2008, 10:15:33 pm
Interesting...I'll tinker with it, and see for myself  ;D
Title: Re: Basic Moving Windows
Post by: Fantasist on January 11, 2008, 05:54:20 pm
A quick edit eh? I'll edit the main post in a bit.
Title: Re: Basic Moving Windows
Post by: Juan on January 12, 2008, 01:53:31 am
@Fantasist Great work and could be useful for people who might want to animate menus.
Title: Re: Basic Moving Windows
Post by: Sally on January 12, 2008, 02:09:48 am
i wish i could script...
Title: Re: Basic Moving Windows
Post by: Fantasist on January 12, 2008, 08:59:21 am
Then why not learn? :D

@Juan, thanks :) You might be wondering what what all that ceils and rounds are for. Well, the code could be smaller but for some reason, the windows don't end up exactly in their destination and leave a pixel or two. I had to hard code the correction, hence why this version is alpha. I planned more glorious things. This is one feature of my Windows Plus pack, which has many enter-exit effects and lots of stuff.
Title: Re: Basic Moving Windows
Post by: Juan on January 13, 2008, 01:09:56 am
@Fantasist Sounds like some intersting features.
Title: Re: Basic Moving Windows
Post by: Calintz on January 13, 2008, 01:11:21 am
I've been reading some Tutorials myself. The beginner stuff is really easy to learn, but then agaian, I haven't gotten into the muck of it yet, so... ;D
Title: Re: Basic Moving Windows
Post by: Fantasist on January 13, 2008, 04:55:20 am
The muck of it is the best part in scripting Calintz ;)
Title: Re: Basic Moving Windows
Post by: Nortos on January 13, 2008, 05:02:43 am
so true I'm still all confuzzled in the muck but it's fun :P more than the first couple tuts but I still refer back every now and than
Title: Re: [XP] Basic Moving Windows
Post by: Fantasist on February 22, 2008, 09:47:34 am
ftw! stupid git! *deletes post*

That post, posted by stodophidwits as a Guest, had about 60 lines of links to porn, all in html. (<a href=http:.....)Was that a sick joke or was it a response to my last post?
QuoteThe muck of it is the best part in scripting Calintz


Either way, sorry if I souldn't have done it Bliz, but check the recycle topic and decide... or hey, should I post it in the mod f... oops, said too much!
Title: Re: [XP] Basic Moving Windows
Post by: Vell on February 22, 2008, 11:16:22 am
he posted another one, so i deleted it again...
Title: Re: [XP] Basic Moving Windows
Post by: Nortos on February 22, 2008, 07:50:53 pm
I know about the mod ... thingy anyway :P I saw it once when Blizz forgot to lock it to the usergroup I was in but I never went in, you all probably rave on about how good looking I'm anyway :P
Title: Re: [XP] Basic Moving Windows
Post by: Blizzard on February 23, 2008, 09:05:46 am
It's full of porn. #_# The others filled it completely up within just one week. #_#
Title: Re: [XP] Basic Moving Windows
Post by: Nortos on February 24, 2008, 02:45:44 am
lol *looks at Ulta*
Title: Re: [XP] Moving Windows v1.0
Post by: Fantasist on September 14, 2009, 09:25:22 am
Updated. I've FINALLY got the decimal correction right! :D
Title: Re: [XP] Moving Windows v1.0
Post by: Blizzard on September 14, 2009, 09:38:12 am
I think this is the most massive gravedig so far at the forum.
Title: Re: [XP] Moving Windows v1.0
Post by: Fantasist on September 14, 2009, 11:14:02 pm
Sorry ._.
Title: Re: [XP] Moving Windows v1.0
Post by: Blizzard on September 15, 2009, 04:34:03 am
Don't worry about it, I'm just saying. xD
Title: Re: [XP] Moving Windows v1.0
Post by: Ryex on September 15, 2009, 07:09:02 pm
THAT'S THE ERROR I FIXED IN YOUR MOVE METHOD WHEN I MADE WINDOW ADVANCED! lol until now I couldn't remember what the error I had to fix was.
you did the same thing as me just went about it in a different way.
Title: Re: [XP] Moving Windows v1.0
Post by: Fantasist on September 15, 2009, 11:48:39 pm
Do you mean the decimal correction or this:

  #--------------------------------------------------------------------------
  # * y=
  #--------------------------------------------------------------------------
  def y=(val)
    self.dest_y = val unless moving?
    super(val)
  end

@Blizz: I've been acting pretty weird lately. I should think before I do or say something. I used to do that, but these days...
Title: Re: [XP] Moving Windows v1.0
Post by: Ryex on September 17, 2009, 09:12:52 pm
the decimal correction thing, I did it differently but the same effect. when It would move almost to the spot you wanted it to but like a few pixels off? that.
it was really noticeable in opening and closing windows, even more so with "pin" off.
Title: Re: [XP] Moving Windows v1.0
Post by: samsonite789 on November 11, 2009, 12:49:51 pm
So I've been trying to figure this out for a while, but it's just not computing...

I understand how to make windows fly when you enter the menu from looking at your demo script, but how do you make them fly out again when you exit the menu?  I figured that it would be as simple as just moving them out before the menu scene ends, but that doesn't seem to work...
Title: Re: [XP] Moving Windows v1.0
Post by: Fantasist on November 13, 2009, 01:46:59 pm
That's what the "moving?" method is for (well, not entirely). You will need to mod the the "def main" method of the scene. Find these lines:


if $scene != self
   break
end


and add a condition for the window which last exits the screen. For example, let's say we are animating the default menu scene and all the windows move out of the screen one by one, the steps window being the last. The code will look like this:


if $scene != self && !@window_steps.moving?
   break
end


I hope that clears things up.
Title: Re: [XP] Moving Windows v1.0
Post by: samsonite789 on November 13, 2009, 08:14:57 pm
THAT'S IT!  It's like a big fist with the letters "DUH" written on the knuckles just punched me in the face.

Quote from: Fantasist on November 13, 2009, 01:46:59 pm
I hope that clears things up.


It did.  Thank you very much.  Unfortunately, there's a compatability issue with another script, so moving windows might have to wait...*le sigh*...