System myszki - Pan Cube - 12-06-13 08:16
~ Mouse System - System myszki ~
Krótki opis:
Skrypt ten pozwala na używanie myszki podczas gry.
Autor:
Jet10985(Jet)
Tłumaczenie:
GmenGul
Skrypt:
Kod:
#===============================================================================
# Mouse System (RGSS3 - VX Ace)
# By Jet10985(Jet)
# Tłumaczył: GmenGul
# Some Code by: Woratana, Berka
# Uses: ListRA-92's Path Finding
# Super Heavy Testing/Debug Help/Requested By: Nathanial(Beleren)
#===============================================================================
# Skrypt ten pozwoli ci w pełni korzystać z myszy w grze stworzonej w RMVX Ace
# dla różnych Celów.
# Ten skrypt zawiera: 7 dostosowywań opcji.
#===============================================================================
# Overwritten Methods:
# Game_Player: move_by_input
#-------------------------------------------------------------------------------
# Aliased methods:
# Scene_Map: update, terminate, update_transfer_player
# Input: update, trigger?, press?, repeat?, dir4, dir8
# Window_Selectable: update, top_row=
# Scene_File: update
# Window_NameInput: update
# Game_Temp: initialize
# Game_Event: initialize, update
#===============================================================================
#Tego poniżej nie tłumaczę, bo myślę że to nie potrzebne :)
#===============================================================================
=begin
Showing text above event when mouse hovers:
If you want a message to appear over an event's head if the mouse is hovering
over the event, put this comment in the event:
MOUSE TEXT MESSAGE HERE
everything after TEXT will be the hovering display.
--------------------------------------------------------------------------------
Change mouse picture above event when mouse hovers:
If you want the mouse's picture to temporarily change whne over an event, put
this comment in the event
MOUSE PIC NAME/NUMBER
if you put a name, the mouse will become that picture, but if you put a number
then the mouse will become the icon that is the id number
--------------------------------------------------------------------------------
Specific mouse click movement routes:
If you want the player to land specifically in a square around an event when
they click to move on the event, put one of these comments in the event:
MOUSE MOVE UP/LEFT/RIGHT/DOWN
only put the direction that you want the player to land on.
--------------------------------------------------------------------------------
Click to activate:
If you want an event to automatically start when it is clicked on, place
this in an event comment:
MOUSE CLICK
--------------------------------------------------------------------------------
Don't stop the player when walking over a touch event:
By default, this script will stop a mouse-caused movement if the player walks
over/under a player touch/event touch event. If you want the event to activate,
but for the player to keep walking to their destination, put this comment in the
event:
MOUSE NOSTOP
--------------------------------------------------------------------------------
Ignore Events:
To have an event be ignored when the mouse makes it's movement path(as if the
event isn't there), put this comment in the event:
MOUSE THROUGH
--------------------------------------------------------------------------------
Dodatkowe Uwagi:
Z wyboru okna np. przedmioty, które mają więcej rzeczy niż to, co pokazano,
gracze mogą:
-albo umieścić kursor pod oknem, aby przewinąć w dół ,lub
-użyć kółka od myszy, bądź (tego co jest między LPM a PPM)
do przewijania w górę / w dół.
Możesz włączyć zdarzenia przyciskiem akcji przez stojące obok zdarzenie i
kliknięcie na nie myszką.
=end
module JetMouse
# Jeśli chcesz użyć grafiki z folderu (nie wiem za bardzo jaki, ale chyba)
# pictures, wpisz nazwę tego pliku.
CURSOR_PICTURE = "cursor-mouse"
# Jeśli nie użyjesz grafiki z folderu, użyta będzie ikona która jest wpisana
# niżej. Jeśli nie chcesz użyć grafiki, tylko jako zwykły kursor systemu,
# pozostaw pole powyżej i poniżej jako puste.
# Wpisz poniżej id danego itemu(grafiki), by zmienić wygląd kursora.
ICON_INDEX = 387 # <---- Domyślnie jest to 387
# Czy chcesz żeby gracz mógł się poruszać za pomocą myszki?
# Wpisz "true" bez cudzysłowia jeśli tak, albo "false", jeśli nie.
ALLOW_MOUSE_MOVEMENT = true
# Czy chcesz mieć 8-kierunkowe chodzenie za pomocą myszy?
# True = Tak, False = Nie. Wymagany skrypt na chodzenie w
# ośmiu kierunkach, stworzonego przez tego samego twórcę,
# co tego skryptu.
DO_8DIR_WALKING = true
#=========================================#
# Dalej już nie tłumaczę, za mało czasu :)#
#=========================================#
# Turning this switch on will make the mouse invisible and unusuable until
# the switch is turned off
TURN_MOUSE_OFF_SWITCH = 20
# Do you want the mouse to check for mouse wheel scrolling in selectbale
# windows? Not using this may reduce some rare cases of lag.
USE_WHEEL_DETECTION = false
# Do you want to use the Dijkstra formula for pathfinding?
# This is more accurate, but slower.
USE_DIJKSTRA = true
end
#================================================#
# Nie edytuj poniżej, chyba że wiesz co robisz!!.#
#================================================#
module Mouse
Get_Message = Win32API.new('user32', 'GetMessage', 'plll', 'l')
GetAsyncKeyState = Win32API.new("user32", "GetAsyncKeyState", 'i', 'i')
GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
SetCursorPos = Win32API.new('user32', 'SetCursorPos', 'nn', 'n')
GetCursorPo = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
ScreenToClient = Win32API.new('user32', 'ScreenToClient', 'lp', 'i')
FindWindowA = Win32API.new('user32', 'FindWindowA', 'pp', 'l')
GetClientRect = Win32API.new('user32', 'GetClientRect', 'lp', 'i')
GetWindowRect = Win32API.new('user32', 'GetWindowRect', 'lp', 'i')
contents = File.open('Game.ini', 'r') { |f| f.read }
q = contents[/Title=(.+)/].nil? ? "cccc" : $1
@handle = FindWindowA.call('RGSS Player', q)
module_function
Point = Struct.new(:x, :y)
Message = Struct.new(:message, :wparam, :lparam, :pt)
Param = Struct.new(:x, :y, :scroll)
Scroll = 0x0000020A
def hiword(dword); return((dword&0xffff0000) >> 16)&0x0000ffff; end
def loword(dword); return dword&0x0000ffff; end
def word2signed_short(value)
return value if (value&0x8000) == 0
return -1 *((~value&0x7fff) + 1)
end
def unpack_dword(buffer, offset = 0)
ret = buffer[offset + 0]&0x000000ff
ret |=(buffer[offset + 1] <<(8 * 1))&0x0000ff00
ret |=(buffer[offset + 2] <<(8 * 2))&0x00ff0000
ret |=(buffer[offset + 3] <<(8 * 3))&0xff000000
return ret
end
def unpack_msg(buffer)
msg = Message.new; msg.pt = Point.new
msg.message=unpack_dword(buffer,4*1)
msg.wparam = unpack_dword(buffer, 4 * 2)
msg.lparam = unpack_dword(buffer,4*3)
msg.pt.x = unpack_dword(buffer, 4 * 5)
msg.pt.y = unpack_dword(buffer, 4 * 6)
return msg
end
def wmcallback(msg)
return unless msg.message == Scroll
param = Param.new
param.x = word2signed_short(loword(msg.lparam))
param.y = word2signed_short(hiword(msg.lparam))
param.scroll = word2signed_short(hiword(msg.wparam))
return [param.x, param.y, param.scroll]
end
def click?(button)
return false if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
return true if @keys.include?(button)
return false
end
def press?(button)
return false if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
return true if @press.include?(button)
return false
end
def set_pos(x_pos = 0, y_pos = 0)
width,height = client_size
if (x_pos.between?(0, width) && y_pos.between?(0, height))
SetCursorPos.call(client_pos[0] + x_pos,client_pos[1] + y_pos)
end
end
def update
return if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
@pos = Mouse.pos
@keys, @press = [], []
@keys.push(1) if GetAsyncKeyState.call(1)&0x01==1
@keys.push(2) if GetAsyncKeyState.call(2)&0x01==1
@keys.push(3) if GetAsyncKeyState.call(4)&0x01==1
@press.push(1) if pressed?(1)
@press.push(2) if pressed?(2)
@press.push(3) if pressed?(4)
end
def pressed?(key)
return true unless GetKeyState.call(key).between?(0, 1)
return false
end
def global_pos
pos = [0, 0].pack('ll')
GetCursorPo.call(pos) != 0 ?(return pos.unpack('ll')):(return [0, 0])
end
def pos
return 0, 0 if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
x, y = screen_to_client(*global_pos)
width, height = client_size
begin
x = 0 if x <= 0; y = 0 if y <= 0
x = width if x >= width; y = height if y >= height
return x, y
end
end
def screen_to_client(x, y)
return nil unless x && y
pos = [x, y].pack('ll')
ScreenToClient.call(@handle, pos) != 0 ?(return pos.unpack('ll')):(return [0, 0])
end
def client_size
rect = [0, 0, 0, 0].pack('l4')
GetClientRect.call(@handle, rect)
right,bottom = rect.unpack('l4')[2..3]
return right, bottom
end
def client_pos
rect=[0, 0, 0, 0].pack('l4')
GetWindowRect.call(@handle, rect)
left, upper = rect.unpack('l4')[0..1]
return left + 4, upper + 30
end
def grid
return [-1, -1] if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
return [-1, -1] if @pos.nil?
return [(@pos[0]/32),(@pos[1]/32)]
end
def true_grid
return [grid[0] + $game_map.display_x / 256, grid[1] + $game_map.display_y / 256]
end
def area?(x, y, width, height)
return false if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
return false if @pos.nil?
return @pos[0].between?(x, width + x) && @pos[1].between?(y, height + y)
end
def scroll
msg="\0"*32;Get_Message.call(msg,0,0,0);r=wmcallback(unpack_msg(msg))
return r if !r.nil?
end
end
class Sprite_Cursor < Sprite_Base
attr_accessor :current_cursor, :not_default
include JetMouse
def initialize
super
@current_cursor = ""
@not_default = false
Win32API.new('user32', 'ShowCursor', 'i', 'i').call(0)
self.z = 5004
create_cursor(CURSOR_PICTURE)
$game_switches = []
update
end
def create_cursor(cursor = "")
self.bitmap.dispose unless self.bitmap.nil?
self.bitmap = nil
begin
self.bitmap = Cache.system(cursor)
@current_cursor = cursor
rescue
self.bitmap = Bitmap.new(24, 24)
bitmap = Cache.system("Iconset")
rect = Rect.new(ICON_INDEX % 16 * 24, ICON_INDEX / 16 * 24, 24, 24)
self.bitmap.blt(0, 0, bitmap, rect)
@current_cursor = ICON_INDEX
end
@not_default = false
end
def change_cursor(cursor)
self.bitmap.dispose unless self.bitmap.nil?
self.bitmap = nil
begin
self.bitmap = Cache.system(cursor)
@current_cursor = cursor
@not_default = true
rescue
begin
self.bitmap = Bitmap.new(24, 24)
bitmap = Cache.system("Iconset")
rect = Rect.new(cursor % 16 * 24, cursor / 16 * 24, 24, 24)
self.bitmap.blt(0, 0, bitmap, rect)
@current_cursor = cursor
@not_default = true
rescue
create_cursor(CURSOR_PICTURE)
end
end
end
def update
return if self.disposed?
if $game_switches[TURN_MOUSE_OFF_SWITCH]
self.opacity = 0 unless self.opacity == 0
end
self.opacity = 255 unless self.opacity == 255
super
x = self.x
y = self.y
self.x, self.y = Mouse.pos
self.x -= 8 if @not_default
self.y -= 8 if @not_default
end
end
$cursor = Sprite_Cursor.new
module Input
class << self
alias jet5888_press? press? unless $@
def press?(arg)
if arg == Input::C
return true if Mouse.press?(1)
elsif arg == Input::B
return true if Mouse.press?(2)
end
jet5888_press?(arg)
end
alias jet5888_repeat? repeat? unless $@
def repeat?(arg)
if arg == Input::C
return true if Mouse.click?(1)
elsif arg == Input::B
return true if Mouse.click?(2)
end
jet5888_repeat?(arg)
end
alias jet5888_trigger? trigger? unless $@
def trigger?(arg)
if arg == Input::C
return true if Mouse.click?(1)
elsif arg == Input::B
return true if Mouse.click?(2)
end
jet5888_trigger?(arg)
end
alias jet8432_update update unless $@
def update(*args, &block)
jet8432_update(*args, &block)
if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH] && $cursor.opacity != 0
$cursor.opacity = 0
end
$cursor.update unless $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
Mouse.update unless $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
end
alias jet1626_dir4 dir4 unless $@
def dir4(*args, &block)
if !$game_temp.nil?
if $game_temp.move_because_of_mouse
if !$game_temp.mouse_path.empty? && $game_player.movable? &&
!$game_map.interpreter.running? && SceneManager.scene_is?(Scene_Map) &&
jet1626_dir4(*args, &block) == 0
f = $game_temp.mouse_path.reverse!.pop
$game_temp.mouse_path.reverse!
return f * 2
else
$game_temp.move_because_of_mouse = false
$game_temp.mouse_path = []
end
end
end
jet1626_dir4(*args, &block)
end
alias jet1626_dir8 dir8 unless $@
def dir8(*args, &block)
if !$game_temp.nil?
if $game_temp.move_because_of_mouse
if !$game_temp.mouse_path.empty? && $game_player.movable? &&
!$game_map.interpreter.running? && SceneManager.scene_is?(Scene_Map) &&
jet1626_dir8(*args, &block) == 0
f = $game_temp.mouse_path.reverse!.pop
$game_temp.mouse_path.reverse!
if [1, 2, 3, 4].include?(f)
return f * 2
else
case f
when 5
return 1
when 6
return 3
when 7
return 7
when 8
return 9
end
end
else
$game_temp.move_because_of_mouse = false
$game_temp.mouse_path = []
end
end
end
jet1626_dir8(*args, &block)
end
end
end
class Game_Player
def move_by_input
return if !movable? || $game_map.interpreter.running?
move = Input.dir4
move_straight(move) if move > 0
end
end
class Game_Character
def find_mouse_path(trgt_x, trgt_y)
fake_char = Game_Character.new
fake_char.moveto(self.x, self.y)
fake_char.set_direction(self.direction)
path = []
g = MGraph.new(JetMouse::DO_8DIR_WALKING ? 8 : 4)
until fake_char.x == trgt_x && fake_char.y == trgt_y
if JetMouse::USE_DIJKSTRA
path.push(g.Dijkstra(fake_char.x, fake_char.y, trgt_x, trgt_y))
else
path.push(g.AStar(fake_char.x, fake_char.y, trgt_x, trgt_y))
end
if path[-1] != 0
fake_char.move_straight(path[-1] * 2)
else
path = []
break
end
end
Graphics.frame_reset
return path.reverse
end
end
class PQueue < Array
def addEl(ii)
iii = 0
while iii < self.length && self[iii] < ii
iii += 1
end
self.insert(iii,ii)
end
def remEl(ii)
iii = 0
while iii < self.length && self[iii] < ii
iii += 1
end
self.delete_at(iii)
end
def found?(ii)
i = 0
j = self.length-1
ff = false
while (not ff) && i <= j
mid = (i+j)/2
if self[mid] == ii
ff = true
else
if self[mid] < ii
i = mid+1
else
j = mid-1
end
end
end
return ff
end
end
class MGraph
attr_accessor :w, :h
attr_accessor :neighbors
attr_accessor :passage_table
def initialize(nh, char = $game_player)
@w = $game_map.width
@h = $game_map.height
@neighbors = nh
@passage_table = Table.new(@w,@h,nh)
for i in 0..@w
for j in 0..@h
for k in 1..nh
@passage_table[i,j,k-1] = char.passable?(i, j, k * 2) ? 1 : 0
if not neighborExist?(nodeOf(i, j), k)
@passage_table[i, j, k - 1] = 0
end
end
end
end
end
def nodeOf(x,y)
return y*@w+x+1
end
def xNode(idxNode)
return (idxNode-1) % @w
end
def yNode(idxNode)
return (idxNode-1)/@w
end
def neighborOf(idxNode,dir)
case dir
when 1
return (idxNode+@w)
when 2
return (idxNode-1)
when 3
return (idxNode+1)
when 4
return (idxNode-@w)
end
end
def neighborExist?(idxNode,dir)
case dir
when 1
return (yNode(idxNode)<@h-1)
when 2
return (xNode(idxNode)>0)
when 3
return (xNode(idxNode)<@w-1)
when 4
return (yNode(idxNode)>0)
end
end
def reconstruct_path(s,t,vertices_prev)
u=t
while vertices_prev[u] != s && vertices_prev[u] != 0
u = vertices_prev[u]
end
case u
when s+@w
return 1
when s-1
return 2
when s+1
return 3
when s-@w
return 4
end
return 0
end
def heuristic_dist(u,v)
dx = xNode(v)-xNode(u)
dy = yNode(v)-yNode(u)
return (dx.abs+dy.abs)
end
def Dijkstra(x1, y1, x2, y2)
s = nodeOf(x1, y1)
t = nodeOf(x2, y2)
q = PQueue.new(1, 0)
q.addEl(s)
vertices_dist = Array.new(@w * @h + 1, 9999)
vertices_prev = Array.new(@w * @h + 1, 0)
vertices_dist[s] = 0
while q.length > 1
d = vertices_dist[q[1]]
u = q[1]
if q.length > 2
for ii in 2..q.length-1
if vertices_dist[q[ii]] < d
d = vertices_dist[q[ii]]
u = q[ii]
end
end
end
if u == t
return reconstruct_path(s,t,vertices_prev)
end
q.remEl(u)
for i in 1..@neighbors
if @passage_table[xNode(u), yNode(u), i - 1] == 1
v = neighborOf(u, i)
alt = vertices_dist[u] + 1
if alt < vertices_dist[v]
q.addEl(v)
vertices_dist[v] = alt
vertices_prev[v] = u
end
end
end
end
return 0
end
def AStar(x1, y1, x2, y2)
s = nodeOf(x1, y1)
t = nodeOf(x2, y2)
q = PQueue.new(1, 0)
q.addEl(s)
q1 = Array.new(@w * @h + 1, false)
vertices_prev = Array.new(@w * @h + 1, 0)
vertices_dist = Array.new(@w * @h + 1, 9999)
h_score = Array.new(@w * @h + 1, 0)
f_score = Array.new(@w * @h + 1, 9999)
vertices_dist[s] = 0
h_score[s] = heuristic_dist(s, t)
f_score[s] = h_score[s]
while q.length > 1
d = f_score[q[1]]
u = q[1]
if q.length > 2
for ii in 2..q.length-1
if f_score[q[ii]] < d
d = f_score[q[ii]]
u = q[ii]
end
end
end
if u == t
return reconstruct_path(s, t, vertices_prev)
end
q.remEl(u)
q1[u] = true
for i in 1..@neighbors
if @passage_table[xNode(u), yNode(u), i - 1] == 1
v = neighborOf(u, i)
if !q1[v]
tentative_g_score = vertices_dist[u] + 1
if !q.found?(v)
q.addEl(v)
tentative_is_better = true
elsif tentative_g_score < vertices_dist[v]
tentative_is_better = true
else
tentative_is_better = false
end
if tentative_is_better
if vertices_prev[v] != 0
if f_score[u] < f_score[vertices_prev[v]]
vertices_prev[v] = u
end
else
vertices_prev[v] = u
end
vertices_dist[v] = tentative_g_score
h_score[v] = heuristic_dist(v, t)
f_score[v] = vertices_dist[v] + h_score[v]
end
end
end
end
end
return 0
end
end
class Game_Temp
attr_accessor :move_because_of_mouse
attr_accessor :mouse_controlled_object
attr_accessor :making_path
attr_accessor :mouse_path
attr_accessor :did_mouse_change
alias jet6742_initialize initialize unless $@
def initialize(*args, &block)
jet6742_initialize(*args, &block)
@move_because_of_mouse = false
@making_path = false
@mouse_path = []
end
end
class Window_Selectable
alias jet6742_update update unless $@
def update(*args, &block)
jet6742_update(*args, &block)
update_mouse if self.active && self.visible
end
alias jet7222_top_row top_row= unless $@
def top_row=(*args, &block)
@last_cursor_move = 0 if @last_cursor_move.nil?
@last_cursor_move -= 1
return if @in_rect_loop || @last_cursor_move > 0
jet7222_top_row(*args, &block)
@last_cursor_move = 10
end
def update_mouse
if JetMouse::USE_WHEEL_DETECTION
f = Mouse.scroll
if !f.nil?
if f[2] < 0
if contents.height > self.height && self.oy - contents.height < -self.height + 32
self.top_row = self.top_row + 1
end
else
self.top_row = self.top_row - 1 if contents.height > self.height
end
end
end
original_index = @index
fake_index = -2
add_x = self.viewport.nil? ? 0 : self.viewport.ox
add_y = self.viewport.nil? ? 0 : self.viewport.oy
self.item_max.times {|i|
rect = item_rect(i)
if Mouse.area?(self.x - self.ox + rect.x + 16 + add_x, self.y - self.oy + rect.y + 16 + add_y, rect.width, rect.height)
fake_index = i
end
}
@index = fake_index == -2 ? original_index : fake_index
update_cursor
end
end
class Scene_File
alias wor_scefil_upd_mouse update unless $@
def update(*args, &block)
(0..self.item_max - 1).each do |i|
ix = @savefile_windows[i].x
iy = @savefile_windows[i].y + 48
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(*args, &block)
end
end
class Window_NameInput
alias wor_winnam_upd_mouse update unless $@
def update(*args, &block)
wor_winnam_upd_mouse(*args, &block)
if self.active and self.visible
(0..self.table[@page].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
class Window_PartyCommand
def update_mouse
(0..self.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 + 64
self.index = i if Mouse.area?(irx, iry, irect.width, irect.height)
end
end
end
class Window_ActorCommand
def update_mouse
(0..self.item_max - 1).each do |i|
irect = item_rect(i)
irx = self.viewport.ox + 288 + 16 + irect.x + 96
iry = 288 + 16 + irect.y + 64
self.index = i if Mouse.area?(irx, iry, irect.width, irect.height)
end
end
end
class Window_EventPopUp < Window_Base
def initialize(x, y, width, height, text)
super(x, y, width, height)
self.opacity = 0
@text = text
refresh
end
def refresh
self.contents.clear
self.contents.draw_text(0, 0, self.width, 24, @text)
end
end
class Game_Event
attr_accessor :popup_window, :page
def check_for_comment(regexp)
return false if @list.nil?
for item in @list
if item.code == 108 or item.code == 408
if !item.parameters[0][regexp].nil?
return $1.nil? ? true : $1
end
end
end
return false
end
def through
return true if check_for_comment(/MOUSE THROUGH/i) && $game_temp.making_path
return @through
end
alias jet2734_update update unless $@
def update(*args, &block)
jet2734_update(*args, &block)
update_mouse_popup
update_mouse_change
end
def update_mouse_popup
switch = $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
if Mouse.true_grid == [self.x, self.y] && !switch && !@erased
f = self.check_for_comment(/MOUSE TEXT(.+)/i)
if f != false
q = Bitmap.new(1, 1)
size = q.text_size(f)
x = self.screen_x - 16 - size.width / 2
y = self.screen_y - 52 - size.height / 2
if self.popup_window != nil
self.popup_window.dispose
self.popup_window = nil
end
self.popup_window = Window_EventPopUp.new(x, y,
size.width + 34, size.height + 34, f)
q.dispose
q = nil
end
else
if self.popup_window != nil
self.popup_window.dispose
self.popup_window = nil
end
end
end
def update_mouse_change
if Mouse.true_grid == [self.x, self.y]
f =(self.check_for_comment(/MOUSE PIC(.+)/i) rescue false)
if f != false
if f.to_i != 0
$cursor.change_cursor(f.to_i) unless $cursor.current_cursor == f.to_i
else
$cursor.change_cursor(f) unless $cursor.current_cursor == f
end
$game_temp.did_mouse_change = true
end
end
end
end
class Scene_Map
alias jet6742_update update unless $@
def update(*args, &block)
if !$game_message.visible
update_mouse_left_click
end
jet6742_update(*args, &block)
check_mouse_change
end
alias jet7811_terminate terminate unless $@
def terminate(*args, &block)
for event in $game_map.events.values
next if event.popup_window.nil?
event.popup_window.dispose unless event.popup_window.disposed?
event.popup_window = nil
end
$cursor.create_cursor(JetMouse::CURSOR_PICTURE) if ![JetMouse::CURSOR_PICTURE,
JetMouse::ICON_INDEX].include?($cursor.current_cursor)
$cursor.opacity = 0
jet7811_terminate(*args, &block)
$cursor.opacity = 255 unless $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
end
alias jet8887_update_transfer_player update_transfer_player unless $@
def update_transfer_player(*args, &block)
if $game_player.transfer?
$cursor.create_cursor(JetMouse::CURSOR_PICTURE) if ![JetMouse::CURSOR_PICTURE,
JetMouse::ICON_INDEX].include?($cursor.current_cursor)
end
jet8887_update_transfer_player(*args, &block)
end
def check_mouse_change
return if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
if $game_message.visible || $game_player.transfer?
$cursor.create_cursor(JetMouse::CURSOR_PICTURE) if ![JetMouse::CURSOR_PICTURE,
JetMouse::ICON_INDEX].include?($cursor.current_cursor)
return
end
$cursor.create_cursor(JetMouse::CURSOR_PICTURE) if $game_temp.did_mouse_change.nil? &&
![JetMouse::CURSOR_PICTURE, JetMouse::ICON_INDEX].include?($cursor.current_cursor)
$game_temp.did_mouse_change = nil
end
def update_mouse_left_click
return if $game_map.interpreter.running? || $game_player.transfer?
if Mouse.click?(1)
event_activated = false
for event in $game_map.events_xy(*Mouse.true_grid)
if event.check_for_comment(/MOUSE CLICK/i)
event.start
event_activated = true
elsif (event.x - $game_player.x).abs + (event.y - $game_player.y).abs == 1
if ![3, 4].include?(event.trigger) &&
(![0, 2].include?(event.priority_type) || event.trigger == 0) &&
![0, 1].include?(event.page.list.size)
if (event.y - $game_player.y).abs >
(event.x - $game_player.x).abs
if event.y - $game_player.y > 0
$game_player.set_direction(2)
else
$game_player.set_direction(8)
end
else
if event.x - $game_player.x > 0
$game_player.set_direction(6)
else
$game_player.set_direction(4)
end
end
event.start
event_activated = true
break
end
end
if !event_activated
for i in ["UP", "DOWN", "RIGHT", "LEFT"]
if event.check_for_comment(/MOUSE MOVE #{i}/i)
event_activated = true
case i
when "UP"
x, y = event.x, event.y - 1
when "DOWN"
x, y = event.x, event.y + 1
when "LEFT"
x, y = event.x - 1, event.y
when "RIGHT"
x, y = event.x + 1, event.y
end
break
end
end
end
end
if !event_activated
x, y = *Mouse.true_grid
end
if !x.nil?
$game_temp.move_because_of_mouse = true
g = $game_player.find_mouse_path(x, y)
$game_temp.mouse_path = g
end
end
end
end
Screeny:
Dodatkowe informacje:
Demo nie potrzebne :P
Instalacja:
Skrypt wrzucamy nad main i testujemy.
RE: System myszki - Spazmatic - 22-07-13 17:35
Świetnie, właśnie go szukałem.Dzięki!
RE: System myszki - krakoman - 22-07-13 18:09
Skrypcik bardzo polecam!
RE: System myszki - Mateix - 23-07-13 13:43
Nowsza wersja skryptu a w niej m.in. więcej opcji konfiguracji:
Kod:
#===============================================================================
# Mouse System
# By Jet10985(Jet)
# Some code by Daniel Martin
#===============================================================================
# This script will allow full use of the mouse inside of Ace for various
# purposes.
# This script has: 11 customization options.
#===============================================================================
# Overwritten Methods:
# Game_Player: move_by_input
# Window_NameInput: item_max
#-------------------------------------------------------------------------------
# Aliased methods:
# Scene_Map: update, terminate, update_transfer_player
# Input: update, trigger?, press?, repeat?, dir8/dir4
# Window_Selectable: update
# Scene_File: update, top_index=
# Game_Event: update, setup_page
# Game_Player: check_action_event, get_on_off_vehicle
# Game_System: initialize
#===============================================================================
=begin
Showing text above event when mouse hovers:
If you want a message to appear over an event's head if the mouse is hovering
over the event, put this comment in the event:
MOUSE TEXT MESSAGE HERE
everything after TEXT will be the hovering display.
--------------------------------------------------------------------------------
Change mouse picture above event when mouse hovers:
If you want the mouse's picture to temporarily change whne over an event, put
this comment in the event
MOUSE PIC NAME/NUMBER
if you put a name, the mouse will become that picture, but if you put a number
then the mouse will become the icon that is the id number
--------------------------------------------------------------------------------
Specific mouse click movement routes:
If you want the player to land specifically in a square around an event when
they click to move on the event, put one of these comments in the event:
MOUSE MOVE UP/LEFT/RIGHT/DOWN
only put the direction that you want the player to land on.
--------------------------------------------------------------------------------
Click to activate:
If you want an event to automatically start when it is clicked on, place
this in an event comment:
MOUSE CLICK
--------------------------------------------------------------------------------
Ignore Events:
To have an event be ignored when the mouse makes it's movement path(as if the
event isn't there), put this comment in the event:
MOUSE THROUGH
--------------------------------------------------------------------------------
You can do some extra things with the mouse using event "Script..." commands:
Mouse.set_pos(x, y) will set the mouse's position to the x and y specified.
Mouse.area?(x, y, width, height) will check if the mouse is inside the given
rectangle, on-screen. This does not account for a scrolled map.
Mouse.grid will return where on the screen the mouse is, not accounting for
a scrolled map. Returns an array: [x, y]
Mouse.true_grid will return where on the map the mouse is, accounting for a
scrolled map. Returns an array: [x, y]
Mouse.click?(1 or 2) will return true/false depending on if a mouse button was
clicked, in only the current frame. Use 1 for left-click, 2 for right-click.
Mouse.press?(1 or 2) will return true/false depending on if a mouse button is
currently being pressed. Use 1 for left-click, 2 for right-click.
--------------------------------------------------------------------------------
Extra Notes:
You can activate action button events by standing next to the event and clicking
on it with the mouse.
=end
module Jet
module MouseSystem
# This is the image used to display the cursor in-game.
CURSOR_IMAGE = "cursor-picture"
# If the above image does not exist, the icon at this index will be used.
CURSOR_ICON = 147
# turning ths switch on will completely disable the mouse.
TURN_MOUSE_OFF_SWITCH = 99
# Do you want the player to be able to move using the mouse?
# This can be changed in-game using toggle_mouse_movement(true/false)
ALLOW_MOUSE_MOVEMENT = true
# Do you want to check for diagonal movement as well? Please note this
# enables regular diagonal movement with the keyboard as well.
DO_DIAGONAL_MOVEMENT = false
# If the tile they click on for movement is not passable, do you want
# to check the surround tiles for a movable area?
CHECK_FOR_MOVES = true
# Would you like a black box to outline the exact tile the mouse is over?
DEV_OUTLINE = true
end
module HoverText
# This is the font for the hovering mouse text.
FONT = "Verdana"
# This is the font color for hovering mouse text.
COLOR = Color.new(255, 255, 255, 255)
# This is the font size for hovering mouse text.
SIZE = 20
end
module Pathfinder
# While mainly for coders, you may change this value to allow the
# pathfinder more time to find a path. 1000 is default, as it is enough for
# a 100x100 maze.
MAXIMUM_ITERATIONS = 1000
end
end
#===============================================================================
# DON'T EDIT FURTHER UNLESS YOU KNOW WHAT TO DO.
#===============================================================================
module Mouse
Get_Message = Win32API.new('user32', 'GetMessage', 'plll', 'l')
GetAsyncKeyState = Win32API.new("user32", "GetAsyncKeyState", 'i', 'i')
GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
GetCursorPo = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
SetCursorPos = Win32API.new('user32', 'SetCursorPos', 'nn', 'n')
ScreenToClient = Win32API.new('user32', 'ScreenToClient', 'lp', 'i')
GetClientRect = Win32API.new('user32', 'GetClientRect', 'lp', 'i')
GetWindowRect = Win32API.new('user32', 'GetWindowRect', 'lp', 'i')
a = Win32API.new('kernel32', 'GetPrivateProfileString', 'pppplp', 'l')
b = Win32API.new('user32', 'FindWindow', 'pp', 'i')
a.call("Game", "Title", "", title = "\0" * 256, 256, ".//Game.ini")
@handle = b.call("RGSS Player", title.unpack("C*").collect {|a| a.chr }.join.delete!("\0"))
Win32API.new('user32', 'ShowCursor', 'i', 'i').call(0)
module_function
def click?(button)
return true if @keys.include?(button)
return false
end
def press?(button)
return true if @press.include?(button)
return false
end
def set_pos(x_pos = 0, y_pos = 0)
width,height = client_size
if (x_pos.between?(0, width) && y_pos.between?(0, height))
SetCursorPos.call(client_pos[0] + x_pos,client_pos[1] + y_pos)
end
end
def moved?
@pos != @old_pos
end
def set_cursor(image)
(@cursor ||= Sprite_Cursor.new).set_cursor(image)
end
def revert_cursor
(@cursor ||= Sprite_Cursor.new).revert
end
def update
if !$game_switches.nil?
if $game_switches[Jet::MouseSystem::TURN_MOUSE_OFF_SWITCH]
@keys, @press = [], []
@pos = [-1, -1]
@cursor.update
return
end
end
@old_pos = @pos.dup
@pos = Mouse.pos
@keys.clear
@press.clear
@keys.push(1) if GetAsyncKeyState.call(1)&0x01 == 1
@keys.push(2) if GetAsyncKeyState.call(2)&0x01 == 1
@keys.push(3) if GetAsyncKeyState.call(4)&0x01 == 1
@press.push(1) if pressed?(1)
@press.push(2) if pressed?(2)
@press.push(3) if pressed?(4)
@cursor.update rescue @cursor = Sprite_Cursor.new
end
def init
@keys = []
@press = []
@pos = Mouse.pos
@cursor = Sprite_Cursor.new
end
def pressed?(key)
return true unless GetKeyState.call(key).between?(0, 1)
return false
end
def global_pos
pos = [0, 0].pack('ll')
GetCursorPo.call(pos) != 0 ? (return pos.unpack('ll')) : (return [0, 0])
end
def pos
x, y = screen_to_client(*global_pos)
width, height = client_size
begin
x = 0 if x <= 0; y = 0 if y <= 0
x = width if x >= width; y = height if y >= height
return x, y
end
end
def screen_to_client(x, y)
return nil unless x && y
pos = [x, y].pack('ll')
if ScreenToClient.call(@handle, pos) != 0
return pos.unpack('ll')
else
return [0, 0]
end
end
def client_size
rect = [0, 0, 0, 0].pack('l4')
GetClientRect.call(@handle, rect)
right,bottom = rect.unpack('l4')[2..3]
return right, bottom
end
def client_pos
rect = [0, 0, 0, 0].pack('l4')
GetWindowRect.call(@handle, rect)
left, upper = rect.unpack('l4')[0..1]
return left + 4, upper + 30
end
def grid
[(@pos[0]/32),(@pos[1]/32)]
end
def true_grid
[grid[0] + $game_map.display_x, grid[1] + $game_map.display_y]
end
def grid_by_pos
asd = pos
[pos[0] / 32, pos[1] / 32]
end
def true_grid_by_pos
[grid_by_pos[0] + $game_map.display_x, grid_by_pos[1] + $game_map.display_y]
end
def area?(x, y, width, height)
@pos[0].between?(x, width + x) && @pos[1].between?(y, height + y)
end
class Sprite_Cursor < Sprite
def initialize
super(nil)
self.z = 50000
@bitmap_cache = initial_bitmap
if Jet::MouseSystem::DEV_OUTLINE
@outline = Sprite.new(nil)
@outline.bitmap = Bitmap.new(32, 32)
@outline.bitmap.fill_rect(0, 0, 32, 32, Color.new(0, 0, 0, 190))
@outline.bitmap.fill_rect(1, 1, 30, 30, Color.new(0, 0, 0, 0))
end
end
def initial_bitmap
begin
self.bitmap = Cache.picture(Jet::MouseSystem::CURSOR_IMAGE)
rescue
self.bitmap = Bitmap.new(24, 24)
icon_index = Jet::MouseSystem::CURSOR_ICON
rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
self.bitmap.blt(0, 0, Cache.system("Iconset"), rect, 255)
end
self.bitmap.dup
end
def set_cursor(image)
if image.is_a?(Integer)
self.bitmap = Bitmap.new(24, 24)
icon_index = image
rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
self.bitmap.blt(0, 0, Cache.system("Iconset"), rect, 255)
else
self.bitmap = Cache.picture(image)
end
end
def revert
self.bitmap = @bitmap_cache.dup
end
def update
super
self.x, self.y = *Mouse.pos
self.visible = !$game_switches[Jet::MouseSystem::TURN_MOUSE_OFF_SWITCH]
if !@outline.nil?
@outline.visible = SceneManager.scene_is?(Scene_Map)
@outline.x = Mouse.grid[0] * 32
@outline.y = [Mouse.grid[1] * 32, 1].max
end
end
end
end
Mouse.init
class << Input
alias jet5888_press? press?
def press?(arg)
if arg == Input::C
return true if Mouse.press?(1)
elsif arg == Input::B
return true if Mouse.press?(2)
end
jet5888_press?(arg)
end
alias jet5888_repeat? repeat?
def repeat?(arg)
if arg == Input::C
return true if Mouse.click?(1)
elsif arg == Input::B
return true if Mouse.click?(2)
end
jet5888_repeat?(arg)
end
alias jet5888_trigger? trigger?
def trigger?(arg)
if arg == Input::C
return true if Mouse.click?(1)
elsif arg == Input::B
return true if Mouse.click?(2)
end
jet5888_trigger?(arg)
end
if Jet::MouseSystem::DO_DIAGONAL_MOVEMENT
alias jet3845_dir8 dir8
def dir8(*args, &block)
if (orig = jet3845_dir8(*args, &block)) == 0
if !$game_temp.nil? && SceneManager.scene_is?(Scene_Map)
if !(a = $game_temp.mouse_character).nil? && a.movable?
if !$game_temp.mouse_path.nil? && !$game_temp.mouse_path.empty?
return $game_temp.mouse_path.shift
end
end
end
end
$game_temp.mouse_path = nil if !$game_temp.nil?
return orig
end
else
alias jet3845_dir4 dir4
def dir4(*args, &block)
if (orig = jet3845_dir4(*args, &block)) == 0
if !$game_temp.nil? && SceneManager.scene_is?(Scene_Map)
if !(a = $game_temp.mouse_character).nil? && a.movable?
if !$game_temp.mouse_path.nil? && !$game_temp.mouse_path.empty?
return $game_temp.mouse_path.shift
end
end
end
end
$game_temp.mouse_path = nil if !$game_temp.nil?
return orig
end
end
alias jet8432_update update
def update(*args, &block)
jet8432_update(*args, &block)
Mouse.update
end
end
class Window_Selectable
alias jet1084_update update
def update(*args, &block)
jet1084_update(*args, &block)
update_mouse if self.active && self.visible && Mouse.moved?
end
def update_mouse
return if $game_switches[Jet::MouseSystem::TURN_MOUSE_OFF_SWITCH]
orig_index = @index
rects = []
add_x = self.x + 16 - self.ox
add_y = self.y + 16 - self.oy
if !self.viewport.nil?
add_x += self.viewport.rect.x - self.viewport.ox
add_y += self.viewport.rect.y - self.viewport.oy
end
self.item_max.times {|i|
@index = i
mouse_update_cursor
rects << cursor_rect.dup
}
@index = orig_index
rects.each_with_index {|rect, i|
if Mouse.area?(rect.x + add_x, rect.y + add_y, rect.width, rect.height)
@index = i
end
}
update_cursor
call_update_help
end
def mouse_update_cursor
if @cursor_all
cursor_rect.set(0, 0, contents.width, row_max * item_height)
elsif @index < 0
cursor_rect.empty
else
cursor_rect.set(item_rect(@index))
end
end
end
class Window_NameInput
def item_max
90
end
end
class Scene_File
alias jet3467_update update
def update(*args, &block)
update_mouse
jet3467_update(*args, &block)
end
alias jet7222_top_index top_index=
def top_index=(*args, &block)
@last_cursor_move = 0 if @last_cursor_move.nil?
@last_cursor_move -= 1
return if @last_cursor_move > 0
jet7222_top_index(*args, &block)
@last_cursor_move = 10
end
def update_mouse
self.item_max.times {|i|
ix = @savefile_windows[i].x
iy = @savefile_windows[i].y + 48 - @savefile_viewport.oy
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
}
ensure_cursor_visible
end
end
class Game_Temp
attr_accessor :mouse_character, :mouse_movement, :mouse_path
end
class Game_CharacterBase
def mouse_path(target_x, target_y, did_dir = false)
return if target_x == self.x && target_y == self.y
f = $game_map.find_path(target_x.to_i, target_y.to_i, @x.to_i, @y.to_i, self)
if f.empty? && !did_dir && Jet::MouseSystem::CHECK_FOR_MOVES
[[0, 1], [0, -1], [1, 0], [-1, 0]].each {|a|
next if !f.empty?
f = $game_map.find_path(target_x.to_i + a[0], target_y.to_i + a[1],
@x.to_i, @y.to_i, self)
}
end
$game_temp.mouse_path = f
end
end
class Game_Player
def move_by_input
return if !movable? || $game_map.interpreter.running?
dir = (Jet::MouseSystem::DO_DIAGONAL_MOVEMENT ? Input.dir8 : Input.dir4)
if dir % 2 == 0 || !Jet::MouseSystem::DO_DIAGONAL_MOVEMENT
move_straight(dir) if dir > 0 && dir % 2 == 0
else
horz = case dir; when 1,7; 4; when 3,9; 6; end
vert = case dir; when 7,9; 8; when 1,3; 2; end
move_diagonal(horz, vert)
end
end
alias jet3745_check_action_event check_action_event
def check_action_event(*args, &block)
return false unless Input.jet5888_trigger?(:C)
jet3745_check_action_event(*args, &block)
end
alias jet3745_get_on_off_vehicle get_on_off_vehicle
def get_on_off_vehicle(*args, &block)
if !Input.jet5888_trigger?(:C)
[:boat, :ship, :airship].each {|a|
if $game_map.send(a).pos?(*Mouse.true_grid)
jet3745_get_on_off_vehicle(*args, &block)
return
end
}
elsif Input.jet5888_trigger?(:C)
jet3745_get_on_off_vehicle(*args, &block)
end
end
def get_on_vehicle_mouse(veh)
return if vehicle
@vehicle_type = veh.type
if vehicle
turn_toward_character(veh)
@vehicle_getting_on = true
force_move_forward unless in_airship?
@followers.gather
end
@vehicle_getting_on
end
end
class Window_MousePopUp < Window_Base
def initialize(event, text)
rect = Bitmap.new(1, 1).text_size(text)
width = rect.width
height = rect.height
super(event.screen_x - width / 2, event.screen_y - 48, width + 32, height + 32)
self.opacity = 0
self.contents.font.name = Jet::HoverText::FONT
self.contents.font.color = Jet::HoverText::COLOR
self.contents.font.size = Jet::HoverText::SIZE
@text = text
@event = event
refresh
end
def refresh
contents.clear
draw_text(0, 0, contents.width, contents.height, @text)
end
def update
super
self.visible = !@event.erased? && Mouse.true_grid_by_pos == [@event.x, @event.y]
self.x = @event.screen_x - contents.width / 2 - 8
self.y = @event.screen_y - 64
end
end
class Game_Event
attr_accessor :text_box
def check_for_comment(regexp)
return false if empty?
for item in @list
if item.code == 108 or item.code == 408
if !item.parameters[0][regexp].nil?
return $1.nil? ? true : $1
end
end
end
return false
end
def mouse_empty?
return true if empty?
return @list.reject {|a| [108, 408].include?(a.code) }.size <= 1
end
alias jet3745_setup_page setup_page
def setup_page(*args, &block)
jet3745_setup_page(*args, &block)
@text_box = nil
@mouse_activated = nil
@mouse_cursor = nil
end
def mouse_activated?
@mouse_activated ||= check_for_comment(/MOUSE[ ]*CLICK/i)
end
def text_box
@text_box ||= (
if (a = check_for_comment(/MOUSE[ ]*TEXT[ ]*(.+)/i))
Window_MousePopUp.new(self, a)
else
false
end
)
end
def through
if $game_temp.mouse_movement && check_for_comment(/MOUSE[ ]*THROUGH/i)
true
else
super
end
end
def mouse_cursor
@mouse_cursor ||= (
if (a = check_for_comment(/MOUSE[ ]*PIC[ ]*(\d+)/i))
a.to_i
elsif (a = check_for_comment(/MOUSE[ ]*PIC[ ]*(.+)/i))
a
else
false
end
)
end
def erased?
@erased
end
def movable?
return false if moving?
return false if $game_message.busy? || $game_message.visible
return true
end
def check_mouse_change
if mouse_cursor
Mouse.set_cursor(@mouse_cursor)
return true
end
return false
end
alias jet3845_update update
def update(*args, &block)
jet3845_update(*args, &block)
@text_box.update if text_box
end
end
class Game_Vehicle
attr_reader :type
end
class Game_System
attr_accessor :mouse_movement
alias jet2735_initialize initialize
def initialize(*args, &block)
jet2735_initialize(*args, &block)
@mouse_movement = Jet::MouseSystem::ALLOW_MOUSE_MOVEMENT
end
end
class Game_Interpreter
def toggle_mouse_movement(bool)
$game_system.mouse_movement = bool
end
end
class Scene_Map
alias jet3745_update update
def update(*args, &block)
jet3745_update
check_mouse_movement
check_mouse_icon_change
end
alias jet5687_terminate terminate
def terminate(*args, &block)
$game_map.events.values.each {|a|
a.text_box.dispose if a.text_box
a.text_box = nil
}
Mouse.update
jet5687_terminate(*args, &block)
end
def mouse_char
$game_temp.mouse_character
end
def check_mouse_icon_change
changed_mouse = false
$game_map.events_xy(*Mouse.true_grid_by_pos).each {|event|
changed_mouse = changed_mouse || event.check_mouse_change
}
Mouse.revert_cursor unless changed_mouse
end
def check_mouse_movement
$game_temp.mouse_character ||= $game_player
if Mouse.click?(1)
dont_move = false
x, y = *Mouse.true_grid_by_pos
evs = $game_map.events_xy(x, y)
(evs + $game_map.vehicles).each {|event|
if event.is_a?(Game_Vehicle)
if (event.x - mouse_char.x).abs + (event.y - mouse_char.y).abs == 1
mouse_char.get_on_vehicle_mouse(event)
dont_move = true
end
elsif !!!mouse_char.vehicle
if event.mouse_activated?
event.start
dont_move = true
elsif (event.x - mouse_char.x).abs + (event.y - mouse_char.y).abs == 1
if !event.mouse_empty? && [0, 1, 2].include?(event.trigger)
mouse_char.turn_toward_character(event)
event.start
dont_move = true
end
else
{UP: [0, -1], DOWN: [0, 1], LEFT: [-1, 0], RIGHT: [1, 0]}.each {|d, a|
if event.check_for_comment(/MOUSE[ ]*MOVE[ ]*#{d.to_s}/i)
x += a[0]; y += a[1]
did_dir = true
end
}
end
end
} if $game_system.mouse_movement
if $game_system.mouse_movement
mouse_char.mouse_path(x, y, did_dir ||= false) unless dont_move
else
evs.each {|event|
if event.mouse_activated?
event.start
end
}
end
end
end
end
class Game_Map
class Astar
class PriorityQueue
def initialize
@list = []
end
def add(priority, item)
@list << [priority, @list.length, item]
@list.sort!
self
end
def <<(pritem)
add(*pritem)
end
def next
@list.shift[2]
end
def empty?
@list.empty?
end
end
def initialize(map)
@map = map
end
def do_find_path(goal, start, char)
been_there = {}
pqueue = PriorityQueue.new
pqueue << [1, [start, [], 1]]
iters = 0
while !pqueue.empty?
iters += 1
return [] if iters > Jet::Pathfinder::MAXIMUM_ITERATIONS
spot, path_so_far, cost_so_far = pqueue.next
next if been_there[spot]
newpath = [path_so_far, spot]
if (spot == goal)
path = []
newpath.flatten.each_slice(2) {|i,j| path << [i,j]}
return recreate_path(path)
end
been_there[spot] = 1
spotsfrom(spot, char).each {|newspot|
next if been_there[newspot]
newcost = cost_so_far + 1
pqueue << [newcost + estimate(newspot, goal), [newspot,newpath,newcost]]
}
end
return []
end
def estimate(spot, goal)
[(spot[0] - goal[0]).abs, (spot[1] - goal[1]).abs].max
end
def spotsfrom(spot, char)
neighbors = []
4.times {|i|
i += 1
new_x = @map.round_x_with_direction(spot[0], i * 2)
new_y = @map.round_y_with_direction(spot[1], i * 2)
next unless char.passable?(spot[0], spot[1], i * 2)
neighbors << [new_x, new_y]
}
if Jet::MouseSystem::DO_DIAGONAL_MOVEMENT
[2, 8].each {|a|
[4, 6].each {|b|
new_x = @map.round_x_with_direction(spot[0], b)
new_y = @map.round_y_with_direction(spot[1], a)
next unless char.diagonal_passable?(spot[0], spot[1], b, a)
neighbors << [new_x, new_y]
}
}
end
neighbors
end
def recreate_path(path)
rec_path = []
hash = {[1, 0] => 6, [-1, 0] => 4, [0, 1] => 2, [0, -1] => 8,
[-1, 1] => 1, [-1, -1] => 7, [1, 1] => 3, [1, -1] => 9}
until path.empty?
pos = path.shift
nex = path[0]
next if path.empty?
ar = [nex[0] <=> pos[0], nex[1] <=> pos[1]]
rec_path << hash[ar]
end
return rec_path
end
end
def find_path(t_x, t_y, x, y, char = $game_player)
@astar ||= Astar.new(self)
@astar.do_find_path([t_x, t_y], [x, y], char)
end
end
RE: System myszki - Mateix - 23-07-13 19:23
Możesz wolić starszą wersję ale pewnie wiele osób woli tą najnowszą, bardziej dopracowaną mimo braku tłumaczenia. Zawsze można używać do patrzenia co znaczy jakaś opcja Google Tłumacza lub starszej, spolszczonej wersji.
RE: System myszki - SuperRafi - 11-01-14 11:46
Fajny skrypt przyda się do zrobienia zdarzenia z kopaniem rud
RE: System myszki - Diero - 07-02-14 09:44
A da się ustawić, żeby była możliwość chodzenia myszką? Bo bardzo by mi się to przydało.
RE: System myszki - Avara - 07-02-14 11:04
Diero, zanim zaczniesz pytać o takie rzeczy, przeczytaj najpierw konfigurację w skrypcie -.- Tam znajdziesz odpowiedź.
RE: System myszki - Nokachi - 17-06-14 16:22
Nowsza wersja jest o niebo lepsza, w starszej, podczas walki musiałem używać klawiszy ponieważ myszka się dziwnie zachowywała, nie dało się wybrać niektórych opcji.
RE: System myszki - helio108 - 17-08-15 11:52
Czy można ustawić skrypt tak aby gracz po kliknięciu na miejsce na którym nie może stanąć podchodził jak najbliżej tego miejsca?
|