# [VX] SMS - Simple Mouse System
#------------------------------------------------------------------------------
# ◦ by Woratana [[email][email protected][/email]]
# ◦ Released on: 14/04/2008 (D-M-Y)
# ◦ Version: 1.5
#
# ◦ Credit: DerVVulfman, Near Fantastica, and Freak Boy [Mouse Input Module]
# lambchop, shun, Cybersam, Astro_mech, and Mr.Mo [Super Simple Mouse System]
# - Modern Algebra, Zeriab, Patrick Lester [Path Finding]
# - Near Fantastica, Fuso [Path Finding]
#
# - I will not be able to script this without those people and scripts above
#-----------------------------------------------------------------------------
#====[REQUIRE]=====
# - DerVVulfman's Mouse Input Module
# ([url]http://rmxp.org/forums/index.php?topic=26993[/url])
# It's XP script, but also works in VX!
#
# - Near Fantastica's Path Finding [version 1.0]
# ([url]http://www.rmxp.org/forums/index.php?topic=26661.0[/url])
# with a little fix to make it works in VX.
# (get fixed version from Simple Mouse System demo)
#
#====[FEATURE]=====
# - Support to use mouse in many scenes / windows
# - Click on map to move player with Path Finding
# - Mouse Pointer
#
#====[PLAN in next version]=====
# - Cursor change when put on other event
# - Better event trigger check by click mouse
#
#------------------------------------------------------------------------------
alias wor_mouse_upd_mouse update unless $@
def Mouse.update
wor_mouse_upd_mouse
if $mouse_old_icon.nil? or $mouse_old_icon != $mouse_icon
$mouse_old_icon = $mouse_icon
$mousec.bitmap = Cache.system($mouse_old_icon)
end
if @pos.nil?
$mousec.x = 1000 if $mousec.x != 1000
$mousec.y = 1000 if $mousec.y != 1000
else
$mousec.x = @pos[0] if $mousec.x != @pos[0]
$mousec.y = @pos[1] if $mousec.y != @pos[1]
end
end
def Mouse.map_pos
return nil if @pos == nil
x = ($game_map.display_x / 256) + (@pos[0] / 32)
y = ($game_map.display_y / 256) + (@pos[1] / 32)
return [x, y]
end
end
#==============================================================================
# ** 输出
#==============================================================================
class << Input
alias wor_input_upd_mouse update unless $@
alias wor_input_trig_mouse trigger? unless $@
alias wor_input_rep_mouse repeat? unless $@
def Input.update
wor_input_upd_mouse
Mouse.update
end
def Input.trigger?(input)
return wor_input_trig_mouse(input) if Mouse.pos.nil?
case input
when Input::B
return (wor_input_trig_mouse(input) or Mouse.click?(2))
when Input::C
if $scene.is_a?(Scene_Map) and !$game_message.visible
return wor_input_trig_mouse(input)
else
return (wor_input_trig_mouse(input) or Mouse.click?(1))
end
else
return wor_input_trig_mouse(input)
end
end
def Input.repeat?(input)
if input == Input::B
return (wor_input_rep_mouse(input) or Mouse.click?(2))
else
return wor_input_rep_mouse(input)
end
end
end
#==============================================================================
# ** 图形
#==============================================================================
class << Graphics
alias wor_graph_fadeout_mouse fadeout unless $@
def Graphics.fadeout(frames = 1)
$mousec.visible = false if !$mousec.nil?
wor_graph_fadeout_mouse(frames)
end
end
#==============================================================================
# ** Window_Selectable
#==============================================================================
class Window_Selectable < Window_Base
alias wor_winsel_ini_mouse initialize
alias wor_winsel_upd_mouse update
def initialize(*args)
wor_winsel_ini_mouse(*args)
@scroll_wait = 0
@cursor_wait = 0
end
def update
wor_winsel_upd_mouse
update_mouse if self.active and self.visible
end
def update_mouse
@cursor_wait -= 1 if @cursor_wait > 0
(0..@item_max - 1).each do |i|
irect = item_rect(i)
irx = self.x + 16 + irect.x - self.ox
iry = self.y + 16 + irect.y - self.oy
move_cursor(i) if Mouse.area?(irx, iry, irect.width, irect.height)
end
end
def move_cursor(index)
return if @index == index
@scroll_wait -= 1 if @scroll_wait > 0
row1 = @index / @column_max
row2 = index / @column_max
bottom = self.top_row + (self.page_row_max - 1)
if row1 == self.top_row and row2 < self.top_row
return if @scroll_wait > 0
@index = [@index - @column_max, 0].max
@scroll_wait = 4
elsif row1 == bottom and row2 > bottom
return if @scroll_wait > 0
@index = [@index + @column_max, @item_max - 1].min
@scroll_wait = 4
else
@index = index
end
return if @cursor_wait > 0
Sound.play_cursor
@cursor_wait += 2
end
end
#==============================================================================
# ** Window_MenuStatus
#==============================================================================
class Window_MenuStatus < Window_Selectable
def item_rect(index)
return Rect.new(0, index * 96, contents.width, 96)
end
end
#==============================================================================
# ** Window_NameInput
#==============================================================================
class Window_NameInput < Window_Base
alias wor_winnam_upd_mouse update
def update
wor_winnam_upd_mouse
if self.active and self.visible
(0..TABLE[@mode].size - 1).each do |i|
irect = item_rect(i)
irx = self.x + 16 + irect.x - self.ox
iry = self.y + 16 + irect.y - self.oy
@index = i if Mouse.area?(irx, iry, irect.width, irect.height)
end
end
end
end
#==============================================================================
# ** Window_PartyCommand
#==============================================================================
class Window_PartyCommand < Window_Command
def update_mouse
(0..@item_max - 1).each do |i|
irect = item_rect(i)
irx = self.viewport.ox + 16 + irect.x - self.ox
iry = 288 + 16 + irect.y - self.oy
self.index = i if Mouse.area?(irx, iry, irect.width, irect.height)
end
end
end
#==============================================================================
# ** Window_ActorCommand
#==============================================================================
class Window_ActorCommand < Window_Command
def update_mouse
(0..@item_max - 1).each do |i|
irect = item_rect(i)
irx = self.viewport.ox + 288 + 16 + irect.x
iry = 288 + 16 + irect.y
self.index = i if Mouse.area?(irx, iry, irect.width, irect.height)
end
end
end
#==============================================================================
# ** Window_Message
#==============================================================================
class Window_Message < Window_Selectable
def update_mouse
(0..@item_max - 1).each do |i|
irect = item_rect(i)
irx = self.x + 16 + irect.x - self.ox
iry = self.y + 16 + irect.y - self.oy + ($game_message.choice_start * WLH)
self.index = i if Mouse.area?(irx, iry, irect.width, irect.height)
end
end
end
#==============================================================================
# ** Scene_Base
#==============================================================================
class Scene_Base
alias wor_scebase_posstr_mouse post_start
alias wor_scebase_preter_mouse pre_terminate
def post_start
$mousec.visible = true if !$mousec.nil?
wor_scebase_posstr_mouse
end
def pre_terminate
$mousec.visible = false if !$mousec.nil?
wor_scebase_preter_mouse
end
end
#==============================================================================
# ** Scene_File
#==============================================================================
class Scene_File < Scene_Base
alias wor_scefil_upd_mouse update
def update
(0..@item_max - 1).each do |i|
ix = @savefile_windows[i].x
iy = @savefile_windows[i].y
iw = @savefile_windows[i].width
ih = @savefile_windows[i].height
if Mouse.area?(ix, iy, iw, ih)
@savefile_windows[@index].selected = false
@savefile_windows[i].selected = true
@index = i
end
end
wor_scefil_upd_mouse
end
end
#==============================================================================
# ** Scene_Map
#==============================================================================
class Scene_Map < Scene_Base
alias wor_scemap_ini_mouse initialize
alias wor_scemap_upd_mouse update
def initialize
@last_click = [nil, nil]
wor_scemap_ini_mouse
end
def update
wor_scemap_upd_mouse
mouse_xy = Mouse.map_pos
if Mouse.click?(1) and !mouse_xy.nil? and !$game_message.visible and
!$game_map.interpreter.running?
$game_player.turn_toward_pos(mouse_xy[0], mouse_xy[1])
if $game_player.close?(mouse_xy[0],mouse_xy[1]) and
$game_player.check_action_event
$game_player.clear_path
return
end
if $game_map.passable?(mouse_xy[0], mouse_xy[1])
$game_player.find_path(mouse_xy[0], mouse_xy[1])
end
@last_click = mouse_xy
end
if Mouse.click?(3) and !mouse_xy.nil? and !$game_message.visible and
!$game_map.interpreter.running?
$game_player.clear_path
$game_player.turn_toward_pos(mouse_xy[0], mouse_xy[1])
end
end
end
#==============================================================================
# ** Game_Character
#==============================================================================
class Game_Character
def turn_toward_pos(x,y)
sx = distance_x_from_pos(x)
sy = distance_y_from_pos(y)
if sx.abs > sy.abs
sx > 0 ? turn_left : turn_right
elsif sx.abs < sy.abs
sy > 0 ? turn_up : turn_down
end
end
def distance_x_from_pos(x)
sx = @x - x
if $game_map.loop_horizontal?
if sx.abs > $game_map.width / 2
sx -= $game_map.width
end
end
return sx
end
def distance_y_from_pos(y)
sy = @y - y
if $game_map.loop_vertical?
if sy.abs > $game_map.height / 2
sy -= $game_map.height
end
end
return sy
end
def close?(x,y)
sx = (@x - x).abs
sy = (@y - y).abs
if sx + sy == 1
return true
end
return false
end
end
#==============================================================================
# □ INI
#==============================================================================
module FSL
module ComicStyle_Window_message
module_function
#--------------------------------------------------------------------------
# ○ 常量
#--------------------------------------------------------------------------
RdINI = Win32API.new("kernel32","GetPrivateProfileStringA","pppplp","l")
WtINI = Win32API.new("kernel32","WritePrivateProfileStringA","pppp","l")
M2W = Win32API.new("kernel32","MultiByteToWideChar","ilpipi","l")
W2M = Win32API.new("kernel32","WideCharToMultiByte","ilpipipp","l")
#--------------------------------------------------------------------------
# ○ 读取配置
#--------------------------------------------------------------------------
def readini(app_name, key_name)
buff = "\0" * 256
RdINI.call(app_name,key_name,"",buff,buff.size,"./Skin.ini")
buff.delete!("\0")
return a2u(buff)
end
#--------------------------------------------------------------------------
# ○ 保存配置
#--------------------------------------------------------------------------
def writeini(app_name, key_name, value)
WtINI.call(app_name,key_name,u2a(value),"./Skin.ini")
end
#--------------------------------------------------------------------------
# ○ ASCII转UTF8
#--------------------------------------------------------------------------
def a2u(str)
len = M2W.call(0,0,str,-1,nil,0)
buf = "\0" * (len*2)
M2W.call(0,0,str,-1,buf,buf.size/2)
len = W2M.call(0xFDE9,0,buf,-1,nil,0,nil,nil)
ret = "\0" * len
W2M.call(0xFDE9,0,buf,-1,ret,ret.size,nil,nil)
return ret.delete!("\0")
end
#--------------------------------------------------------------------------
# ○ UTF8转ASCII
#--------------------------------------------------------------------------
def u2a(str)
len = M2W.call(0xFDE9,0,str,-1,nil,0)
buf = "\0" * (len*2)
M2W.call(0xFDE9,0,str,-1,buf,buf.size/2)
len = W2M.call(0,0,buf,-1,nil,0,nil,nil)
ret = "\0" * len
W2M.call(0,0,buf,-1,ret,ret.size,nil,nil)
return ret.delete!("\0")
end
end
end
#==============================================================================
# ■ Bitmap
#==============================================================================
class Bitmap
#--------------------------------------------------------------------------
# ○ 平铺
#--------------------------------------------------------------------------
def tile(dest_rect, src_bitmap, src_rect, opacity = 255)
m = dest_rect.width / src_rect.width
n = dest_rect.height / src_rect.height
m += 1 if dest_rect.width % src_rect.width > 0
n += 1 if dest_rect.height % src_rect.height > 0
buf = Bitmap.new(dest_rect.width, dest_rect.height)
for i in 0...m
x = src_rect.width * i
for j in 0...n
y = src_rect.height * j
buf.blt(x, y, src_bitmap, src_rect)
end
end
src_rect = Rect.new(0, 0, dest_rect.width, dest_rect.height)
self.blt(dest_rect.x, dest_rect.y, buf, src_rect, opacity)
buf.dispose
end
end