Window_Advanced
Authors: Ryex
Version: 2.05
Type: Graphical Enhancement
Key Term: Scripting Tool
IntroductionThis is a base class like Window_Base, it contains methods for opening/closing windows with animation, as well as animated movement and resizing.
Features
- Opening/Closing window animations
- Two different movement algorithms
- Two different resizing algorithms
- Very easy to use
- Animated cursor movement
Screenshotshttp://www.youtube.com/watch?v=4sGvUk6uxL8
DemoNA
Script
#==============================================================================
# ** Window_Advanced_Base
#------------------------------------------------------------------------------
# V1.05
# By Ryex
#------------------------------------------------------------------------------
# Contains basic animtion methods to make things easier
#==============================================================================
class Window_AdvBase < Window
def initialize(x, y, w, h, open = true, dir = 0, mode = 0, speed = 2, pin = false)
super()
self.z = 100
if open
unless pin
case dir
when 0
open_x = x
open_y = (h / 2) - 16 + y
when 1
open_x = (w / 2) - 16 + x
open_y = y
when 2
open_x = (w / 2) - 16 + x
open_y = (h / 2) - 16 + y
end
else
open_x = x
open_y = y
end
self.x = open_x
self.y = open_y
case dir
when 0
self.height = 32
self.width = w
when 1
self.width = 32
self.height = h
when 2
self.height = 32
self.width = 32
end
@dest_x = open_x
@dest_y = open_y
else
self.x = x
self.y = y
self.width = w
self.height = h
@dest_x = x
@dest_y = y
end
@opening = open
@closing = false
@open_dir = dir
@size_mode = mode
@move_mode = 0
@size_s = speed
@move_s = 16
@dest_h = h
@dest_w = w
@tot_h = (@dest_h - self.height).abs
@tot_w = (@dest_w - self.width).abs
@tot_x = (@dest_x - self.x).abs
@tot_y = (@dest_y - self.y).abs
@pin = pin
@resize = false
@x_counter = 0
@y_counter = 0
@f_resize_y = self.y + ((@dest_h - self.height) / 2.0).floor
@f_resize_x = self.x + ((@dest_w - self.width) / 2.0).floor
end
def update_size
if self.height != @dest_h || self.width != @dest_w
case @size_mode
when 0
h = self.height
w = self.width
dist_h = (@dest_h - h).abs > @size_s ? @size_s : (@dest_h - h).abs
dist_w = (@dest_w - w).abs > @size_s ? @size_s : (@dest_w - w).abs
@dest_h > h ? self.height += dist_h : self.height -= dist_h
@dest_w > w ? self.width += dist_w : self.width -= dist_w
unless @pin
if dist_h <= 1
@y_counter +=1
if (@y_counter % 2) == 0
@dest_h > h ? self.y -= 1 : self.y += 1
end
else
@dest_h > h ? self.y -= (dist_h / 2.0).floor : self.y += (dist_h / 2.0).floor
end
if dist_w <= 1
@x_counter +=1
if (@x_counter % 2) == 0
@dest_w > w ? self.x -= 1 : self.x += 1
end
else
@dest_w > w ? self.x -= (dist_w / 2.0).floor : self.x += (dist_w / 2.0).floor
end
@dest_x = self.x
@dest_y = self.y
end
when 1
h = self.height
w = self.width
dist_h = [((@dest_h - h).abs / @size_s.to_f).ceil, (@tot_h / @size_s.to_f).ceil].min
dist_w = [((@dest_w - w).abs / @size_s.to_f).ceil, (@tot_w / @size_s.to_f).ceil].min
@dest_h > h ? self.height += dist_h : self.height -= dist_h
@dest_w > w ? self.width += dist_w : self.width -= dist_w
unless @pin
if dist_h <= 1
@y_counter +=1
if (@y_counter % 2) == 0
@dest_h > h ? self.y -= 1 : self.y += 1
end
else
@dest_h > h ? self.y -= (dist_h / 2.0).floor : self.y += (dist_h / 2.0).floor
end
if dist_w <= 1
@x_counter +=1
if (@x_counter % 2) == 0
@dest_w > w ? self.x -= 1 : self.x += 1
end
else
@dest_w > w ? self.x -= (dist_w / 2.0).floor : self.x += (dist_w / 2.0).floor
end
@dest_x = self.x
@dest_y = self.y
end
end
end
end
def update_position
if self.x != @dest_x || self.y != @dest_y
case @move_mode
when 0
x = self.x
y = self.y
dist_x = (@dest_x - x).abs > @move_s ? @move_s : (@dest_x - x).abs
dist_y = (@dest_y - y).abs > @move_s ? @move_s : (@dest_y - y).abs
@dest_x > x ? self.x += dist_x : self.x -= dist_x
@dest_y > y ? self.y += dist_y : self.y -= dist_y
when 1
x = self.x
y = self.y
dist_x = [((@dest_x - x).abs / @move_s.to_f).ceil, (@tot_x / @move_s.to_f).ceil].min
dist_y = [((@dest_y - y).abs / @move_s.to_f).ceil, (@tot_y / @move_s.to_f).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
end
end
def moving?
return self.x != @dest_x || self.y != @dest_y
end
def resizing?
return self.height != @dest_h || self.width != @dest_w
end
def at_dest?
return self.height == @dest_h && self.width == @dest_w &&
self.x == @dest_x && self.y == @dest_y
end
def move(x, y, mode = 0, speed = 16)
@move_mode = mode
@move_s = speed
@dest_x = x
@dest_y = y
@tot_x = (x - self.x).abs
@tot_y = (y - self.y).abs
end
def resize(w, h, mode = 0, speed = 2, pin = false)
@resize = true
@size_mode = mode
@size_s = speed
@dest_h = h
@dest_w = w
@tot_h = (h - self.height).abs
@tot_w = (w - self.width).abs
@pin = pin
end
def close(dir, mode = 0, speed = 2, pin = false)
@closing = true
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@size_mode = mode
@size_s = speed
@pin = pin
case dir
when 0
@dest_h = 32
@tot_h = (32 - self.height).abs
@dest_w = self.width
@tot_w = (self.width - self.width).abs
when 1
@dest_w = 32
@tot_w = (32 - self.width).abs
@dest_h = self.height
@tot_h = (self.height- self.height).abs
when 2
@dest_w = 32
@tot_w = (32 - self.width).abs
@dest_h = 32
@tot_h = (32 - self.height).abs
end
end
def update_open
if at_dest?
@opening = false
finalize
end
end
def update_close
if at_dest?
@closing = false
dispose
end
end
def update_resize
if at_dest?
@resize = false
@x_counter = 0
@y_counter = 0
refresh
end
end
def normal_update
if @resize
update_resize
end
end
def update
super
# Reset if windowskin was changed
if $game_system.windowskin_name != @windowskin_name
@windowskin_name = $game_system.windowskin_name
self.windowskin = RPG::Cache.windowskin(@windowskin_name)
end
update_size if resizing?
update_position if moving?
if @opening
update_open
elsif @closing
update_close
else
normal_update
end
end
def dispose
if self.contents != nil
self.contents.dispose
self.contents = nil
end
super
end
end
#==============================================================================
# ** Window_Advanced_Selectable
#------------------------------------------------------------------------------
# V1.00
# By Ryex
#------------------------------------------------------------------------------
# Contains basic animtion methods to make tings easier
#==============================================================================
class Window_AdvSelectable < Window_AdvBase
attr_reader :index, :help_window, :column_max, :item_max, :row_size, :column_size, :offset
def initialize(x, y, w, h, column_size, row_size = 32, offset = 32, open = true, dir = 0, mode = 0, speed = 2, pin = false)
super(x, y, w, h, open, dir, mode, speed, pin)
@item_max = 1
@column_max = 1
@index = -1
@column_size = column_size
@offset = offset
@row_size = row_size
@cursor_dest_x = @cursor_dest_y = 0
@cursor_dest_h, @cursor_dest_w = row_size, column_size
@cursor_move_mode = 1
@cursor_move_s = 4
@cursor_tot_h = (@cursor_dest_h - self.height).abs
@cursor_tot_w = (@cursor_dest_w - self.width).abs
@cursor_tot_x = (@cursor_dest_x - self.x).abs
@cursor_tot_y = (@cursor_dest_y - self.y).abs
@contents_dest_x = @contents_dest_y = 0
@contents_move_mode = 1
@contents_move_s = 16
@contents_tot_x = @contents_tot_y = 0
@cursor_open = true
end
def index=(index)
@index = index
# Update Help Text (update_help is defined by the subclasses)
if self.active and @help_window != nil
update_help
end
# Update cursor rectangle
update_cursor_rect
end
def column_size=(size)
@column_size = size
refresh
update_cursor_rect
end
def offset=(space)
@offset = space
refresh
update_cursor_rect
end
def row_size=(size)
@row_size = size
refresh
update_cursor_rect
end
def column_max=(max)
@column_max = max
refresh
update_cursor_rect
end
def item_max=(max)
@item_max = max
refresh
update_cursor_rect
end
#--------------------------------------------------------------------------
# * Get Row Count
#--------------------------------------------------------------------------
def row_max
# Compute rows from number of items and columns
return (@item_max + @column_max - 1) / @column_max
end
def left_column
return self.ox / @column_size
end
def left_column=(column)
if column < 0
column = 0
self.ox = column * (@column_size + @offset)
end
if column > @column_max
column = @column_max - 1
self.ox = column * (@column_size + @offset)
end
move_window_contents(column * (@column_size + @offset), self.oy)
end
#--------------------------------------------------------------------------
# * Get Top Row
#--------------------------------------------------------------------------
def top_row
# Divide y-coordinate of window contents transfer origin by 1 row
# height of 32
return self.oy / @row_size
end
#--------------------------------------------------------------------------
# * Set Top Row
# row : row shown on top
#--------------------------------------------------------------------------
def top_row=(row)
# If row is less than 0, change it to 0
if row < 0
row = 0
self.oy = row * @row_size
end
# If row exceeds row_max - 1, change it to row_max - 1
if row > row_max - 1
row = row_max - 1
self.oy = row * @row_size
end
# transfer origin
move_window_contents(self.ox, row * @row_size)
end
def page_column_max
return (self.width - 32) / @column_size
end
#--------------------------------------------------------------------------
# * Get Number of Rows Displayable on 1 Page
#--------------------------------------------------------------------------
def page_row_max
# Subtract a frame height of 32 from the window height, and divide it by
# 1 row height of 32
return (self.height - 32) / @row_size
end
#--------------------------------------------------------------------------
# * Get Number of Items Displayable on 1 Page
#--------------------------------------------------------------------------
def page_item_max
# Multiply row count (page_row_max) times column count (@column_max)
return page_row_max * @column_max
end
#--------------------------------------------------------------------------
# * Set Help Window
# help_window : new help window
#--------------------------------------------------------------------------
def help_window=(help_window)
@help_window = help_window
# Update help text (update_help is defined by the subclasses)
if self.active and @help_window != nil
update_help
end
end
#--------------------------------------------------------------------------
# * Update Cursor Rectangle
#--------------------------------------------------------------------------
def update_cursor_rect
# If cursor position is less than 0
if @index < 0
self.cursor_rect.empty
return
end
# Get current row
row = @index / @column_max
column = @index - (row * @column_max)
# If current row is before top row
if row < self.top_row
# Scroll so that current row becomes top row
self.top_row = row
end
if column < self.left_column
self.left_column = column
end
if column > self.left_column + (self.page_column_max - 1)
self.left_column = column - (self.page_column_max - 1)
end
# If current row is more to back than back row
if row > self.top_row + (self.page_row_max - 1)
# Scroll so that current row becomes back row
self.top_row = row - (self.page_row_max - 1)
end
# Calculate cursor width
cursor_width = @column_size
# Calculate cursor coordinates
x = column * (@column_size + @offset) - self.ox
y = row * @row_size - self.oy
# Update cursor rectangle
if @cursor_open
self.cursor_rect.set(x, y, cursor_width, @row_size)
@cursor_open = false
end
move_cursor_rect(x, y, cursor_width, @row_size)
end
def cursor_moving?
return self.cursor_rect.x != @cursor_dest_x || self.cursor_rect.y != @cursor_dest_y || self.cursor_rect.width != @cursor_dest_w || self.cursor_rect.height != @cursor_dest_h
end
def contents_moving?
return self.ox != @contents_dest_x || self.oy != @contents_dest_y
end
def move_window_contents(x, y, mode = 1, speed = 16)
@contents_dest_x = x
@contents_dest_y = y
@contents_move_mode = mode
@contents_move_s = speed
@contents_tot_x = (@contents_dest_x - self.ox).abs
@contents_tot_y = (@contents_dest_y - self.oy).abs
end
def move_cursor_rect(x, y, width, height, mode = 1, speed = 4)
@cursor_dest_x = x
@cursor_dest_y = y
@cursor_dest_w = width
@cursor_dest_h = height
@cursor_move_mode = mode
@cursor_move_s = speed
@cursor_tot_h = (height - self.height).abs
@cursor_tot_w = (width - self.width).abs
@cursor_tot_x = (x - self.cursor_rect.x).abs
@cursor_tot_y = (y - self.cursor_rect.y).abs
end
def update_contents_position
if self.ox != @contents_dest_x || self.oy != @contents_dest_y
case @contents_move_mode
when 0
x = self.ox
y = self.oy
dist_x = (@contents_dest_x - x).abs > @contents_move_s ? @contents_move_s : (@contents_dest_x - x).abs
dist_y = (@contents_dest_y - y).abs > @contents_move_s ? @contents_move_s : (@contents_dest_y - y).abs
@contents_dest_x > x ? self.ox += dist_x : self.ox -= dist_x
@contents_dest_y > y ? self.oy += dist_y : self.oy -= dist_y
when 1
x = self.ox
y = self.oy
dist_x = [((@contents_dest_x - x).abs / @contents_move_s.to_f).ceil, (@contents_tot_x / @contents_move_s.to_f).ceil].min
dist_y = [((@contents_dest_y - y).abs / @contents_move_s.to_f).ceil, (@contents_tot_y / @contents_move_s.to_f).ceil].min
@contents_dest_x > x ? self.ox += dist_x : self.ox -= dist_x
@contents_dest_y > y ? self.oy += dist_y : self.oy -= dist_y
end
end
end
def update_move_cursor_rect
x = self.cursor_rect.x
y = self.cursor_rect.y
h = self.cursor_rect.height
w = self.cursor_rect.width
if self.cursor_rect.height != @cursor_dest_h || self.cursor_rect.width != @cursor_dest_w
case @cursor_move_mode
when 0
dist_h = (@cursor_dest_h - h).abs > @cursor_move_s ? @cursor_move_s : (@cursor_dest_h - h).abs
dist_w = (@cursor_dest_w - w).abs > @cursor_move_s ? @cursor_move_s : (@cursor_dest_w - w).abs
@cursor_dest_h > h ? h += dist_h : h -= dist_h
@cursor_dest_w > w ? w += dist_w : w -= dist_w
when 1
dist_h = [((@cursor_dest_h - h).abs / @cursor_move_s.to_f).ceil, (@cursor_tot_h / @size_s.to_f).ceil].min
dist_w = [((@cursor_dest_w - w).abs / @cursor_move_s.to_f).ceil, (@cursor_tot_w / @size_s.to_f).ceil].min
@cursor_dest_h > h ? h += dist_h : h -= dist_h
@cursor_dest_w > w ? w += dist_w : w -= dist_w
end
end
if self.cursor_rect.x != @cursor_dest_x || self.cursor_rect.y != @cursor_dest_y
case @cursor_move_mode
when 0
dist_x = (@cursor_dest_x - x).abs > @cursor_move_s ? @cursor_move_s : (@cursor_dest_x - x).abs
dist_y = (@cursor_dest_y - y).abs > @cursor_move_s ? @cursor_move_s : (@cursor_dest_y - y).abs
@cursor_dest_y > x ? x += dist_x : x -= dist_x
@cursor_dest_y > y ? y += dist_y : y -= dist_y
when 1
dist_x = [((@cursor_dest_x - x).abs / @cursor_move_s.to_f).ceil, (@cursor_tot_x / @cursor_move_s.to_f).ceil].min
dist_y = [((@cursor_dest_y - y).abs / @cursor_move_s.to_f).ceil, (@cursor_tot_y / @cursor_move_s.to_f).ceil].min
@cursor_dest_x > x ? x += dist_x : x -= dist_x
@cursor_dest_y > y ? y += dist_y : y -= dist_y
end
end
self.cursor_rect.set(x, y, w, h)
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def normal_update
super
# If cursor is movable
if self.active and @item_max > 0 and @index >= 0
# If pressing down on the directional buttons
if Input.repeat?(Input::DOWN)
# If column count is 1 and directional button was pressed down with no
# repeat, or if cursor position is more to the front than
# (item count - column count)
if (@column_max == 1 and Input.trigger?(Input::DOWN)) or
@index < @item_max - @column_max
# Move cursor down
$game_system.se_play($data_system.cursor_se)
@index = (@index + @column_max) % @item_max
end
end
# If the up directional button was pressed
if Input.repeat?(Input::UP)
# If column count is 1 and directional button was pressed up with no
# repeat, or if cursor position is more to the back than column count
if (@column_max == 1 and Input.trigger?(Input::UP)) or
@index >= @column_max
# Move cursor up
$game_system.se_play($data_system.cursor_se)
@index = (@index - @column_max + @item_max) % @item_max
end
end
# If the right directional button was pressed
if Input.repeat?(Input::RIGHT)
# If column count is 2 or more, and cursor position is closer to front
# than (item count -1)
if @column_max >= 2 and @index < @item_max - 1
# Move cursor right
$game_system.se_play($data_system.cursor_se)
@index += 1
end
end
# If the left directional button was pressed
if Input.repeat?(Input::LEFT)
# If column count is 2 or more, and cursor position is more back than 0
if @column_max >= 2 and @index > 0
# Move cursor left
$game_system.se_play($data_system.cursor_se)
@index -= 1
end
end
# If R button was pressed
if Input.repeat?(Input::R)
# If bottom row being displayed is more to front than bottom data row
if self.top_row + (self.page_row_max - 1) < (self.row_max - 1)
# Move cursor 1 page back
$game_system.se_play($data_system.cursor_se)
@index = [@index + self.page_item_max, @item_max - 1].min
self.top_row += self.page_row_max
end
end
# If L button was pressed
if Input.repeat?(Input::L)
# If top row being displayed is more to back than 0
if self.top_row > 0
# Move cursor 1 page forward
$game_system.se_play($data_system.cursor_se)
@index = [@index - self.page_item_max, 0].max
self.top_row -= self.page_row_max
end
end
end
# Update help text (update_help is defined by the subclasses)
if self.active and @help_window != nil
update_help
end
# Update cursor rectangle
update_cursor_rect
update_move_cursor_rect if cursor_moving?
update_contents_position if contents_moving?
end
end
InstructionsInstructions for both AdvBase and AdvSelectable: ShowHide to use simply subclass and add a finalize method and refresh method, use finalize to create the self.contents bitmap and call refresh to draw the content of the window, you can use it just like you would a normal window exsept you should NEVER create self.contents in def initialize the class has a special handling for this in def finalize.
moving? returns true if the window need moving
resizing? returns true if the window needs resizing
at_dest? returns true if the window needs neither moving nor resizing
move(x, y, mode, speed)
x > the x you want to move the window too
y > the y you want to move the window too
mode > 0 or 1 refers to the two different algorithms used for movement, default is 0
speed > the pixels the window will grow or shrink each frame should never be lower than 2, default is 2.
when mode is 1 speed works differently; when speed is 1 the window open instantly, when speed is 2 it open half the distance in the first frame half the remaining distance in the second and so on, when speed is 3 it open 30% of the remaining distance fist frame, 33.333% of the remaining distance the second and so on, when speed is 4 it moves 25% of the raining distence each frame, 5 it moves 20%, 6 > 16.666%, 7 > 14.2857%, ECT.
resize(w, h, mode, speed, pin)
w > new width
h > new height
mode > 0 or 1 refers to the two different algorithms used for resizing, default is 0
speed > the pixels the window will grow or shrink each frame should never be lower than 2, default is 2.
when mode is 1 speed works differently; when speed is 1 the window open instantly, when speed is 2 it open half the distance in the first frame half the remaining distance in the second and so on, when speed is 3 it open 30% of the remaining distance fist frame, 33.333% of the remaining distance the second and so on, when speed is 4 it moves 25% of the raining distence each frame, 5 it moves 20%, 6 > 16.666%, 7 > 14.2857%, ECT.
pin > should the top left corner be kept in the same place? true or false, default is false
NOTE: the resize method will call refresh when the window is done resizing
close(dir, mode, speed, pin)
dir > direction the window should close. o is top to bottom, 1 is left to right, 2 is both at the same time
mode > 0 or 1 refers to the two different algorithms used for resizing, default is 0
speed > the pixels the window will grow or shrink each frame should never be lower than 2, default is 2.
when mode is 1 speed works differently; when speed is 1 the window open instantly, when speed is 2 it open half the distance in the first frame half the remaining distance in the second and so on, when speed is 3 it open 30% of the remaining distance fist frame, 33.333% of the remaining distance the second and so on, when speed is 4 it moves 25% of the raining distence each frame, 5 it moves 20%, 6 > 16.666%, 7 > 14.2857%, ECT.
pin > should the top left corner be kept in the same place? true or false, default is false
NOTE: the close command disposes the contents of the window immediately and will automatically disposes of the window when the animation is complete. make sure you are aware of this when calling the update method.
NOTE: NO animation will take place unless the update method is called.
AdvSelectable only instructions: ShowHide
to use simple make a subclass and do what you would normal do for a selectable window but follow the instruction for AdvBase too. be sure to set the item and column maxes in the finalize method.
this class not only adds animation but it makes it easier to set up selectable windows correctly all around, the instance variable @offset controls the horizontal off set between each menu item changing it will automatically refresh the window and if you use it in you drawing methods every thing will come out right automatically. the same can be said for @row_size and @column_size these control the height of each row and the width of each column respectively and changing them will refresh the window and update the cursor.
Compatibilityshould work with anything
Credits and Thanks
Author's Notesthis class contain none of Window_Base's drawing methods so if you want them include them in you sub class
I made this... well... because I wanted to. it will make making any animated system easier
O_O
Will DEFINITELY look into this. Looks VERY promising. Thanks, Ryex, and congrats on another great job!
*powers up*
now i just need to make Window_Advanced_Selectable
it will be a sub class of Window_Advanced_Base but it will have both vertical and horizontal ANIMATED scrolling and looping.
Very nice I will most likely end up using this *lv's up*
Wouldn't it be better if you included those methods in Window_Base instead of making a new class?
I tried but the opening stuff would not work and window select had problems, this was just easier
maybe you could at least change the name of the class to
Window_ABase so its faster to type...
GG has a point, helps the lazy folk :rolleyes:
Oh, and very good job on this one Ryex, you kinda beat me to it. I'm gonna try this soon. *powers up*
fantasist its now levels
Quote from: game_guy on July 05, 2009, 11:59:50 am
maybe you could at least change the name of the class to
Window_ABase so its faster to type...
"What is ABase supposed to be mean? Is that a typing mistake or what?!" is the first thing I would think if I saw "ABase". Window_Advanced would have probably been enough, but Window_AdvancedBase is fine, too.
A = advanced
thats why ABase would be fine for me
"Oh, my bad. Of course. It's 'Advanced' and not any of the other 10000 english words starting with A. How dumb of me."
Seriously, man.
fine well I'll just be lazy and keep it ABase for my lazyness >_> maybe AdvBase? I dunno
AdvBase would be a lot better. Remember, if somebody would have to read your code like this, he would get confused very quickly.
Laziness has nothing to do with it. It's not like you're going to type it every 20th line. You're gonna probably never type it except when creating a new class that is derivated from it. :P
Quote from: Fantasist on July 05, 2009, 02:42:40 pm
GG has a point, helps the lazy folk :rolleyes:
Oh, and very good job on this one Ryex, you kinda beat me to it. I'm gonna try this soon. *powers up*
Thank you Fant, this was really fairly easy once I discovered that you CAN NOT re-size a window unless self.contents is nil (disposing is not enough, you must set it to nil) if you try RGSS crashes with out an error.
Quote from: Ryexander on July 05, 2009, 12:16:18 am
now i just need to make Window_Advanced_Selectable
it will be a sub class of Window_Advanced_Base but it will have both vertical and horizontal ANIMATED scrolling and looping.
that's the main reason for both making a new class and naming it as I did though your right AdvBase and AdvSelectabl IS a lot shorter
O_o I never had problems resizing it. Worst thing that would happen is that the arrows would appear because the window is smaller than the bitmap.
ok that is just weird, if self.contents is disposed but not set to nil RGSS crashes but if you just leave it alone your good. this discovery is annoying because it took half an hour to figure out why RGSS was crashing but it dose make Window_AdvSlectabul easyer.
Oh that. Yeah, if you dispose it, better set it to nil as well. I just meant that don't even have to dispose it.
Update to v1.02 resize will no longer depose of the windows contents but will call refresh once animation is complete, close however WILL dispose of the contents immediately
EDIT: Update to 1.03 speed now works with mode 0 AND mode 1 but in mode 1 it works differently, read the instruction to find out how
EDIT another update, the finalize is no longer defined in Window_AdvBase and must be created by the user. read the instructions to find out what you should put there. this is in an effort to help me creat Window_AdvSelectable, which by the way is in the works as I type.
Curses, I was going to suggest something about the ABase too, but Blizzard and I seem to be on the same wavelength. :P Yes, Advanced's abbreviation is usually Adv. . Having something like ABase can denote a lot of things. One thing I can easily think of a variable of a Base, like A-Base, B-Base, C-Base (Of course it's more commonly done as Base-A and etc.) or the simple indefinite article (A base was found at...). Definitely not Advanced though. ): But screw convenience if you have a high enough WPM. :V:
Anyway...I have thoughts that something like this can really make the Window effects much greater than before, but I really have no idea where to start. I suppose I would have to sit down and focus.
well I have Window Adv selectable
almost finished. I'm
oh so close I just need to get it looping verticly when there is more than one column and improve cursor movement and we're good. right now... it looks... AWESOME!
Window_AdvBase is now 1.04 and it has the shortened class name now so. enjoy.
UPDATE: Window_AdvSelectable v1.0 is out the only glitch I know of is that you can't loop vertically when there is more than one column, I will fix this eventually.
to use this new class make sure you have v 1.04 of the base class installed too
here is a demo class of the slectable window just make a new instance with a bunch of commands and test it out.
class Window_Test < Window_AdvSelectable
def initialize(w, commands)
@commands = commands
super(0, 0, w, 160, 160, 32, 32, true, 0, 0, 4, false)
end
def finalize
@column_max = 7
@item_max = @commands.size
self.contents = Bitmap.new (self.width - 32, self.height - 32)
self.active = true
self.index = 0
refresh
end
def refresh
self.contents.clear
self.contents = Bitmap.new(160 * (@column_max + @offset), row_max * 32)
for i in 0...@item_max
draw_item(i)
end
end
def draw_item(index)
row = index / @column_max
column = index - (row * @column_max)
x = column * (@column_size + @offset)
y = row * @row_size
rect = Rect.new(x, y, @column_size, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands[index], 1)
end
end
feel free to mess with the column max to see the effect
also I've been using this to test it it use the window in the spoiler above so just call this scene and you will be able to test it
class Scene_Test
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Load database
$data_actors = load_data("Data/Actors.rxdata")
$data_classes = load_data("Data/Classes.rxdata")
$data_skills = load_data("Data/Skills.rxdata")
$data_items = load_data("Data/Items.rxdata")
$data_weapons = load_data("Data/Weapons.rxdata")
$data_armors = load_data("Data/Armors.rxdata")
$data_enemies = load_data("Data/Enemies.rxdata")
$data_troops = load_data("Data/Troops.rxdata")
$data_states = load_data("Data/States.rxdata")
$data_animations = load_data("Data/Animations.rxdata")
$data_tilesets = load_data("Data/Tilesets.rxdata")
$data_common_events = load_data("Data/CommonEvents.rxdata")
$data_system = load_data("Data/System.rxdata")
# Make system object
$game_system = Game_System.new
@sprite = Sprite.new
@sprite.bitmap = RPG::Cache.title($data_system.title_name)
s1 = 'test'
commands = []
100.times {|n| commands.push(s1)}
@test_window = Window_Test.new(384, commands)
Graphics.transition
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
Graphics.freeze
@test_window.dispose
end
def update
if @test_window.disposed?
@test_window = Window_Test.new(0, 0, 200, 200)
end
@test_window.update
update_input
return
end
def update_input
if Input.trigger?(Input::B)
end
if Input.trigger?(Input::C)
end
if Input.trigger?(Input::R)
end
if Input.trigger?(Input::L)
end
return
end
end
UPDATE: fixed a small movement bug when doing resizing with pin off
Quote from: Blizzard on July 05, 2009, 03:11:45 pm
AdvBase would be a lot better. Remember, if somebody would have to read your code like this, he would get confused very quickly.
Laziness has nothing to do with it. It's not like you're going to type it every 20th line. You're gonna probably never type it except when creating a new class that is derivated from it. :P
Minor English lesson: Is "derived." "Derivated" is not a word.
@Script: GJ, but I'm not sure I would call it an "algorithm." Kinda pretentious
is only using word to quote DW: The Shakespeare Code
Ok, after having used this on a major project and comparing it to the performance alongside that of the standard window, coupled with Ryex's prompt and friendly support, (which few scripters seem to offer >.>) I can honestly say that this script kicks ass. It might not have 9000000 features, but hey, if Ryex updates, it will. For NOW, however, it operates with EASE, and VERY smoothly, if you know how to use it. (Possibly put the test script and scene in your original post, Ryex? That's what helped me the most. Besides the "mode 10" problem, LMAO.)
Point being, this is a very nice scripting tool. It makes a VERY noticeable graphical improvement.