1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
| #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Scrolling de la map, avec la molette de la souris
# berka 0.1 Rgss1
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# http://www.rpgmakervx-fr.com
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# adaptation du script ruby de ˜aŠ� un grand merci !
#
# molette pour les ordonn�es
# Ctrl+molette pour les abcisses
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
module Berka
module Souris
ID_Int=1 #id de l'interrupteur a activer pour autoriser le scrolling
Vitesse=8 #vitesse du scrolling de la map
end
end
class Souris
Get_Message=Win32API.new('User32','GetMessage','plll','l') # reception d'un message
GetAsyncKeyState=Win32API.new("user32","GetAsyncKeyState",'i','i') # test d'une touche
GetKeyState=Win32API.new("user32","GetKeyState",'i','i') # etat d'une touche
SetCursorPos=Win32API.new('user32','SetCursorPos','nn','n') # positionnement du curseur
GetCursorPo=Win32API.new('user32','GetCursorPos','p','i') # position du curseur
ScreenToClient=Win32API.new('user32','ScreenToClient','lp','i') # coordonn�es du handle
GetPrivateProfileStringA=Win32API.new('kernel32','GetPrivateProfileStringA','pppplp','l') # lecture fichier
FindWindowA=Win32API.new('user32','FindWindowA','pp','l') # recuperation handle d'une fenetre
GetClientRect=Win32API.new('user32','GetClientRect','lp','i') # recuperations dimensions ecran
GetWindowRect=Win32API.new('user32','GetWindowRect','lp','i') #recuperation dimensions fenetre (handle)
Point=Struct.new(:x,:y) # cr�ation d'une structure de symboles: coord molette
Message=Struct.new(:message,:wparam,:lparam,:pt) # struct de symboles: message renvoy� par la molette
Param=Struct.new(:x,:y,:scroll) # parametres de la molette
Scroll=0x0000020A # pointeur de la molette
def handle # recuperation du handle du rgss player
game_name="\0"*256
GetPrivateProfileStringA.call('Game','Title','',game_name,255,".\\Game.ini")
game_name.delete!("\0")
return handle=FindWindowA.call('RGSS Player',game_name)
end
def unpack_dword(buffer,offset=0) # d�compactage d'integer 32bits
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) # d�compactage du message de la molette
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 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 click?(button);@keys.include?(button)?(return true):(return false);end #si clic
def press?(button);@press.include?(button)?(return true):(return false);end # si appui
def pressed?(key);return true unless GetKeyState.call(key).between?(0,1);return false;end # test appui
def global_pos;pos=[0,0].pack('ll');GetCursorPo.call(pos)!=0 ? (return pos.unpack('ll')):(return nil);end # pos a l'ecran
def set_pos(x_pos=0,y_pos=0) # positionnement
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 # maj des entrees
@pos,@keys,@press=pos,[],[]
@keys << 1 if GetAsyncKeyState.call(1)&0x01==1
@keys << 2 if GetAsyncKeyState.call(2)&0x01==1
@keys << 3 if GetAsyncKeyState.call(4)&0x01==1
@press << 1 if pressed?(1)
@press << 2 if pressed?(2)
@press << 3 if pressed?(4)
end
def pos # recuperation position dans player
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 dans_player? # teste si curseur est dans player
return true if global_pos[0].between?(client_pos[0],client_pos[0]+client_size[0])&&
global_pos[1].between?(client_pos[1],client_pos[1]+client_size[1])
return false
end
def screen_to_client(x,y) #pos player dans ecran
return nil unless x&&y
pos=[x,y].pack('ll')
ScreenToClient.call(handle,pos)!=0?(return pos.unpack('ll')):(return nil)
end
def client_size # dimensions player
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 # position player
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 # convertit position en position carreaux
return nil if @pos.nil?
return [(@pos[0]+$game_map.display_x/8)/32,(@pos[1]+$game_map.display_y/8)/32]
end
def scroll # retourne l'etat de la molette
msg="\0"*32;Get_Message.call(msg,0,0,0);r=wmcallback(unpack_msg(msg))
return r if !r.nil?
end
end
$souris=Souris.new # lancement de la classe souris
module Input
class << self
alias :update_souris :update unless Input.methods.include?("update_souris")
def update
update_souris
$souris.update # maj souris
end
end
end
class Scene_Map
alias :souris_update :update
def update
souris_update
update_scroll if $souris.dans_player?&&$game_switches[Berka::Souris::ID_Int]
end
def update_scroll
s=$souris.scroll;return if s.nil?
s[2]<0 ? (Input.press?(Input::CTRL) ? d=6 : d=2) : (Input.press?(Input::CTRL) ? d=4 : d=8)
$game_map.start_scroll(d,1,Berka::Souris::Vitesse) # lance le scroll dans la direction d
end
end |