#===============================================================================
# Windows Features
# By Trebor777
# Edit by Shocks
# Version 3.0
#-------------------------------------------------------------------------------
# Permits the drag & drop, the resizing, close and click features.
# Added the widgets handling.
# Only one window or icon(see icon class) can be drag at the same time
#===============================================================================
SDK.log("win_features", "Trebor777", "2.0", "27-11-06")
#-------------------------------------------------------------------------------
# Begin SDK Enabled Check
#-------------------------------------------------------------------------------
if SDK.state('win_features')
#===============================================================================
# Class window Base
#===============================================================================
class Window_Base
attr_accessor :dragable
attr_accessor :scalable
attr_accessor :clickable
attr_accessor :closable
attr_accessor :widgets
#--------------------------------------------------------------------------
alias old_initialize initialize
#--------------------------------------------------------------------------
def initialize(x, y, width, height)
@dragable = false
@scalable = false
@clickable = false
@closable = false
@widgets = []
old_initialize(x, y, width, height)
self.margin = 16 # 16 is the default margin size
end
#--------------------------------------------------------------------------
# Dispose the windows and the widgets it has.
#--------------------------------------------------------------------------
def dispose
super
for w in @widgets
w.dispose
end
end
#--------------------------------------------------------------------------
# Change the normal color to black instead of white
#--------------------------------------------------------------------------
def normal_color
return Color.new(0, 0, 0, 255)
end
#--------------------------------------------------------------------------
# Frame Update, Check the different status to execute the different features
#--------------------------------------------------------------------------
def update
super
if $game_system.windowskin_name != @windowskin_name
@windowskin_name = $game_system.windowskin_name
self.windowskin = RPG::Cache.windowskin(@windowskin_name)
end
@old_opacity = self.back_opacity if @old_opacity == nil
@old_opacity2 = self.contents_opacity if @old_opacity2 == nil
# Check for close
if @closable and in_area?([self.width-15, 3, 10, 10]) and $click_esquerdo and $dragging == false
for w in @widgets
w.visible = false
w.active = false
end
self.active = false
self.visible = false
on_close
end
# Check for click
if @clickable and (self.visible or self.opacity > 0)
if $click_esquerdo and in_area?
on_click_left
elsif $click_esquerdo and !in_area? and self.active
out_click
end
if $click_direito and in_area?
on_click_right
end
if Input.trigger(Input::Mouse_Middle) and in_area?
on_click_middle
end
end
# Check for Drag and resizing.
if (@dragging and !Input.pressed(Input::Mouse_Left))
@dragging = nil
$dragging = false
end
if (@scaling and !Input.pressed(Input::Mouse_Left))
@scaling = nil
end
if Input.pressed(Input::mouse_Left)) and self.visible and !$item_drag
if @dragable and (in_area?([0, 0, self.width, 10]) or @dragging)
drag if (!$dragging or @dragging) and !$scrolling
end
if @scalable and (in_area?([self.width-10,self.height-10,10,10]) or @scaling)
scale if @scaling or !$scrolling
end
end
# Retornar opacidade (fade-in)
for i in 1...4
if !$dragging and self.back_opacity != @old_opacity
self.back_opacity += i if @old_opacity + i > self.back_opacity
self.back_opacity -= i if @old_opacity - i < self.back_opacity
end
end
for i in 1...4
if !$dragging and self.contents_opacity != @old_opacity2
self.contents_opacity += i if @old_opacity2 + i > self.contents_opacity
self.contents_opacity -= i if @old_opacity2 - i < self.contents_opacity
end
end
# Update all the linked widgets
for w in @widgets
w.update
end
end
#--------------------------------------------------------------------------
# Check if the mouse cursor is in the given area of the window
# args = [x,y,w,h], by default represent the entire window.
#--------------------------------------------------------------------------
def in_area?(args=[0,0,self.width,self.height])
if $mouse.x.between?(self.x+args[0],self.x + args[2]+args[0]) and
$mouse.y.between?(self.y+args[1],self.y + args[3]+args[1])
return true
end
return false
end
#--------------------------------------------------------------------------
# Drag & Drop method
#--------------------------------------------------------------------------
def drag
if @dragging == nil
@dif_x = $mouse.x - self.x
@dif_y = $mouse.y - self.y
@dragging = true
$dragging = true
end
if @dragging
self.contents_opacity = 160
self.back_opacity = 160
self.x = $mouse.x - @dif_x
self.y = $mouse.y - @dif_y
end
end
#--------------------------------------------------------------------------
# Resizing method
#--------------------------------------------------------------------------
def scale
if @scaling==nil
self.ox=0
self.oy=0
@scaling=true
end
if @scaling
self.width = $mouse.x- self.x if $mouse.x- self.x>self.margin*2
self.height = $mouse.y- self.y if $mouse.y- self.y>self.margin*2
end
end
#--------------------------------------------------------------------------
# On event methods
# Usually called in the update method.
#--------------------------------------------------------------------------
def on_click_left
end
#--------------------------------------------------------------------------
def on_click_right
end
#--------------------------------------------------------------------------
def on_click_middle
end
#--------------------------------------------------------------------------
def on_close
end
#--------------------------------------------------------------------------
def out_click
end
#--------------------------------------------------------------------------
# Set the visibility for the window, and for the widgets.
#--------------------------------------------------------------------------
def visible=(t)
@visible=t
for w in @widgets
w.visible=t
end
update_visible
update_arrows
end
end
#===============================================================================
# Add the mouse support for Window_Command, to allow option selection with the
# mouse.
#===============================================================================
class Window_Command
alias cursor_mouse_update update
alias cursor_mouse_initialize initialize
#--------------------------------------------------------------------------
def initialize(width, commands)
@ind_box = []
cursor_mouse_initialize(width, commands)
end
#--------------------------------------------------------------------------
def update
# Fill @ind_box only one time.
if @ind_box == []
cursor_width = self.width / @column_max - 32
for i in 0...@item_max
x = i % @column_max * (cursor_width + 32)
y = i / @column_max * 32 - self.oy+self.margin
@ind_box.push([[x,y,cursor_width,32],i])
end
end
# Original update
cursor_mouse_update
# Check mouse State and update the index
return if @ind_box == nil
for b in @ind_box
if in_area?(b[0])and self.active and Input.trigger(Input::Mouse_Left)
@index = b[1]
update_cursor_rect
end
end
end
#--------------------------------------------------------------------------
end
end