仙剑之十里坡

标题: 重量级!鼠标! [打印本页]

作者: BlackFeather    时间: 2010-3-27 18:34
标题: 重量级!鼠标!
  1. #
  2. # 本脚本来自www.66RPG.com,使用和转载请保留此信息
  3. #
  4. #=以下两个用来调整战斗时的手感问题,可以自己试试。
  5. $敌人选框扩大 = 20
  6. $角色选框扩大 = 30

  7. #==============================================================================
  8. # API调用
  9. #==============================================================================
  10. $ShowCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
  11. $GetCursorPos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
  12. $ScreenToClient = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
  13. $GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')
  14. $Window_HWND = $GetActiveWindow.call
  15. $GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
  16. #$FindWindow = Win32API.new("user32", "FindWindow", 'pp', 'i')
  17. #$HookStart = Win32API.new("mouse_hook.dll", "HookStart", 'i', nil)
  18. #$HookEnd = Win32API.new("mouse_hook.dll", "HookEnd", nil, nil)
  19. #$GetMouseStatus = Win32API.new("mouse_hook.dll", "GetMouseStatus", 'i', 'i')
  20. #$Window_HWND = $FindWindow.call(nil, 'mousetry')
  21. module Mouse
  22. LEFT = 0x01
  23. RIGHT = 0x02
  24. def self.init(sprite = nil)
  25. # $HookStart.call($Window_HWND)
  26. $ShowCursor.call(0)

  27. @show_cursor = false

  28. @mouse_sprite = Sprite.new
  29. @mouse_sprite.z = 99999
  30. @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/鼠标光标.png')
  31. #@mouse_sprite.bitmap.fill_rect(Rect.new(0, 0, 32, 32), Color.new(0, 0, 0))
  32. @left_press = false
  33. @right_press = false
  34. @left_trigger = false
  35. @right_trigger = false
  36. @left_repeat = false
  37. @right_repeat = false
  38. @click_lock = false

  39. update
  40. end
  41. def self.exit
  42. @mouse_sprite.bitmap.dispose
  43. @mouse_sprite.dispose
  44. @show_cursor = true
  45. # $HookEnd.call
  46. $ShowCursor.call(1)
  47. end
  48. def self.mouse_debug
  49. return @mouse_debug.bitmap
  50. end
  51. def self.update
  52. left_down = $GetKeyState.call(0x01)
  53. right_down = $GetKeyState.call(0x02)

  54. @click_lock = false
  55. mouse_x, mouse_y = self.get_mouse_pos
  56. if @mouse_sprite != nil
  57. @mouse_sprite.x = mouse_x
  58. @mouse_sprite.y = mouse_y
  59. end
  60. if left_down[7] == 1
  61. @left_repeat = (not @left_repeat)
  62. @left_trigger = (not @left_press)
  63. @left_press = true
  64. else
  65. @left_press = false
  66. @left_trigger = false
  67. @left_repeat = false
  68. end
  69. if right_down[7] == 1
  70. @right_repeat = (not @right_repeat)
  71. @right_trigger = (not @right_press)
  72. @right_press = true
  73. else
  74. @right_press = false
  75. @right_trigger = false
  76. @right_repeat = false
  77. end
  78. end
  79. def self.get_mouse_pos
  80. point_var = [0, 0].pack('ll')
  81. if $GetCursorPos.call(point_var) != 0
  82. if $ScreenToClient.call($Window_HWND, point_var) != 0
  83. x, y = point_var.unpack('ll')
  84. if (x < 0) or (x > 10000) then x = 0 end
  85. if (y < 0) or (y > 10000) then y = 0 end
  86. if x > 640 then x = 640 end
  87. if y > 480 then y = 480 end
  88. return x, y
  89. else
  90. return 0, 0
  91. end
  92. else
  93. return 0, 0
  94. end
  95. end
  96. def self.press?(mouse_code)
  97. if mouse_code == LEFT
  98. if @click_lock
  99. return false
  100. else
  101. return @left_press
  102. end
  103. elsif mouse_code == RIGHT
  104. return @right_press
  105. else
  106. return false
  107. end
  108. end
  109. def self.trigger?(mouse_code)
  110. if mouse_code == LEFT
  111. if @click_lock
  112. return false
  113. else
  114. return @left_trigger
  115. end
  116. elsif mouse_code == RIGHT
  117. return @right_trigger
  118. else
  119. return false
  120. end
  121. end
  122. def self.repeat?(mouse_code)
  123. if mouse_code == LEFT
  124. if @click_lock
  125. return false
  126. else
  127. return @left_repeat
  128. end
  129. elsif mouse_code == RIGHT
  130. return @right_repeat
  131. else
  132. return false
  133. end
  134. end
  135. def self.click_lock?
  136. return @click_lock
  137. end
  138. def self.click_lock
  139. @click_lock = true
  140. end
  141. def self.click_unlock
  142. @click_lock = false
  143. end
  144. end
  145. module Input
  146. if @self_update == nil
  147. @self_update = method('update')
  148. @self_press = method('press?')
  149. @self_trigger = method('trigger?')
  150. @self_repeat = method('repeat?')
  151. end
  152. def self.update
  153. @self_update.call
  154. Mouse.update
  155. end
  156. def self.press?(key_code)
  157. if @self_press.call(key_code)
  158. return true
  159. end
  160. if key_code == C
  161. return Mouse.press?(Mouse::LEFT)
  162. elsif key_code == B
  163. return Mouse.press?(Mouse::RIGHT)
  164. else
  165. return @self_press.call(key_code)
  166. end
  167. end
  168. def self.trigger?(key_code)
  169. if @self_trigger.call(key_code)
  170. return true
  171. end
  172. if key_code == C
  173. return Mouse.trigger?(Mouse::LEFT)
  174. elsif key_code == B
  175. return Mouse.trigger?(Mouse::RIGHT)
  176. else
  177. return @self_trigger.call(key_code)
  178. end
  179. end
  180. def self.repeat?(key_code)
  181. if @self_repeat.call(key_code)
  182. return true
  183. end
  184. if key_code == C
  185. return Mouse.repeat?(Mouse::LEFT)
  186. elsif key_code == B
  187. return Mouse.repeat?(Mouse::RIGHT)
  188. else
  189. return @self_repeat.call(key_code)
  190. end
  191. end
  192. end
  193. class Window_Selectable
  194. if @self_alias == nil
  195. alias self_update update
  196. @self_alias = true
  197. end
  198. def update
  199. #self.cursor_rect.empty
  200. self_update
  201. if self.active and @item_max > 0
  202. index_var = @index
  203. tp_index = @index
  204. mouse_x, mouse_y = Mouse.get_mouse_pos
  205. mouse_not_in_rect = true
  206. for i in 0...@item_max
  207. @index = i
  208. update_cursor_rect
  209. top_x = self.cursor_rect.x + self.x + 16
  210. top_y = self.cursor_rect.y + self.y + 16
  211. bottom_x = top_x + self.cursor_rect.width
  212. bottom_y = top_y + self.cursor_rect.height
  213. if (mouse_x > top_x) and (mouse_y > top_y) and
  214. (mouse_x < bottom_x) and (mouse_y < bottom_y)
  215. mouse_not_in_rect = false
  216. if tp_index != @index
  217. tp_index = @index
  218. $game_system.se_play($data_system.cursor_se)
  219. end
  220. break
  221. end
  222. end
  223. if mouse_not_in_rect
  224. @index = index_var
  225. update_cursor_rect
  226. Mouse.click_lock
  227. else
  228. Mouse.click_unlock
  229. end
  230. end
  231. end
  232. end
  233. class Window_NameInput
  234. if @self_alias == nil
  235. alias self_update update
  236. @self_alias = true
  237. end
  238. def update
  239. #self.cursor_rect.empty
  240. self_update
  241. if self.active
  242. index_var = @index
  243. mouse_x, mouse_y = Mouse.get_mouse_pos
  244. mouse_not_in_rect = true
  245. for i in (0...CHARACTER_TABLE.size).to_a.push(180)
  246. @index = i
  247. update_cursor_rect
  248. top_x = self.cursor_rect.x + self.x + 16
  249. top_y = self.cursor_rect.y + self.y + 16
  250. bottom_x = top_x + self.cursor_rect.width
  251. bottom_y = top_y + self.cursor_rect.height
  252. #
  253. if (mouse_x > top_x) and (mouse_y > top_y) and
  254. (mouse_x < bottom_x) and (mouse_y < bottom_y)
  255. mouse_not_in_rect = false
  256. break
  257. end
  258. end
  259. if mouse_not_in_rect
  260. @index = index_var
  261. update_cursor_rect
  262. Mouse.click_lock
  263. else
  264. Mouse.click_unlock
  265. end
  266. end
  267. end
  268. end
  269. class Window_InputNumber
  270. if @self_alias == nil
  271. alias self_update update
  272. @self_alias = true
  273. end
  274. def update
  275. #self.cursor_rect.empty
  276. self_update
  277. mouse_x, mouse_y = Mouse.get_mouse_pos
  278. if self.active and @digits_max > 0
  279. index_var = @index
  280. mouse_not_in_rect = true
  281. for i in 0...@digits_max
  282. @index = i
  283. update_cursor_rect
  284. top_x = self.cursor_rect.x + self.x + 16
  285. bottom_x = top_x + self.cursor_rect.width
  286. #
  287. if (mouse_x > top_x) and (mouse_x < bottom_x)
  288. mouse_not_in_rect = false
  289. break
  290. end
  291. end
  292. if mouse_not_in_rect
  293. @index = index_var
  294. update_cursor_rect
  295. Mouse.click_lock
  296. else
  297. Mouse.click_unlock
  298. end
  299. end
  300. if @last_mouse_y == nil
  301. @last_mouse_y = mouse_y
  302. end
  303. check_pos = (@last_mouse_y - mouse_y).abs
  304. if check_pos > 10
  305. $game_system.se_play($data_system.cursor_se)
  306. place = 10 ** (@digits_max - 1 - @index)
  307. n = @number / place % 10
  308. @number -= n * place
  309. n = (n + 1) % 10 if mouse_y < @last_mouse_y
  310. n = (n + 9) % 10 if mouse_y > @last_mouse_y
  311. @number += n * place
  312. refresh
  313. @last_mouse_y = mouse_y
  314. end
  315. end
  316. end
  317. class Scene_File
  318. if @self_alias == nil
  319. alias self_update update
  320. @self_alias = true
  321. end
  322. def update
  323. mouse_x, mouse_y = Mouse.get_mouse_pos
  324. Mouse.click_lock
  325. idx = 0
  326. for i in @savefile_windows
  327. top_x = i.x + 16
  328. top_y = i.y + 16
  329. bottom_x = top_x + i.width
  330. bottom_y = top_y + i.height
  331. if (mouse_x > top_x) and (mouse_y > top_y) and
  332. (mouse_x < bottom_x) and (mouse_y < bottom_y)
  333. i.selected = true
  334. if @file_index != idx
  335. @file_index = idx
  336. $game_system.se_play($data_system.cursor_se)
  337. end
  338. Mouse.click_unlock
  339. else
  340. i.selected = false
  341. end
  342. idx += 1
  343. end
  344. self_update
  345. end
  346. end
  347. class Arrow_Enemy
  348. if @self_alias == nil
  349. alias self_update update
  350. @self_alias = true
  351. end
  352. def update
  353. mouse_x, mouse_y = Mouse.get_mouse_pos
  354. idx = 0
  355. for i in $game_troop.enemies do
  356. if i.exist?
  357. top_x = i.screen_x - self.ox
  358. top_y = i.screen_y - self.oy
  359. bottom_x = top_x + self.src_rect.width
  360. bottom_y = top_y + self.src_rect.height
  361. if (mouse_x > top_x - $敌人选框扩大) and (mouse_y > top_y - $敌人选框扩大) and
  362. (mouse_x < bottom_x + $敌人选框扩大) and (mouse_y < bottom_y + $敌人选框扩大)
  363. if @index != idx
  364. $game_system.se_play($data_system.cursor_se)
  365. @index = idx
  366. end
  367. end
  368. end
  369. idx += 1
  370. end
  371. self_update
  372. end
  373. end
  374. class Arrow_Actor
  375. if @self_alias == nil
  376. alias self_update update
  377. @self_alias = true
  378. end
  379. def update
  380. mouse_x, mouse_y = Mouse.get_mouse_pos
  381. idx = 0
  382. for i in $game_party.actors do
  383. if i.exist?
  384. top_x = i.screen_x - self.ox
  385. top_y = i.screen_y - self.oy
  386. bottom_x = top_x + self.src_rect.width
  387. bottom_y = top_y + self.src_rect.height
  388. if (mouse_x > top_x - $角色选框扩大) and (mouse_y > top_y - $角色选框扩大) and
  389. (mouse_x < bottom_x + $角色选框扩大) and (mouse_y < bottom_y + $角色选框扩大)
  390. if @index != idx
  391. $game_system.se_play($data_system.cursor_se)
  392. @index = idx
  393. end
  394. end
  395. end
  396. idx += 1
  397. end
  398. self_update
  399. end
  400. end
  401. class Game_Player
  402. if @self_alias == nil
  403. alias self_update update
  404. @self_alias = true
  405. end
  406. def update
  407. mouse_x, mouse_y = Mouse.get_mouse_pos
  408. if @last_move_x == nil
  409. @last_move_x = false
  410. end
  411. if Mouse.press?(Mouse::LEFT)
  412. last_moving = moving?
  413. last_direction = @direction
  414. unless moving? or $game_system.map_interpreter.running? or
  415. @move_route_forcing or $game_temp.message_window_showing
  416. last_x = @x
  417. if @last_move_x
  418. @last_move_x = false
  419. elsif mouse_x > screen_x + 16
  420. move_right
  421. elsif mouse_x < screen_x - 16
  422. move_left
  423. end
  424. last_y = @y
  425. if last_x != @x
  426. @last_move_x = true
  427. elsif mouse_y > screen_y
  428. move_down
  429. elsif mouse_y < screen_y - 32
  430. move_up
  431. end
  432. if last_y != @y
  433. @last_move_x = false
  434. elsif not @last_move_x
  435. case last_direction
  436. when 2
  437. turn_down
  438. when 4
  439. turn_left
  440. when 6
  441. turn_right
  442. when 8
  443. turn_up
  444. end
  445. end
  446. end
  447. end
  448. self_update
  449. end
  450. end
  451. Mouse.init
  452. END { Mouse.exit }
复制代码

作者: BlackFeather    时间: 2010-3-27 18:35
只能发10000字节
使用方法:在ICON里放个“鼠标光标”就行了
作者: 李xx    时间: 2011-9-21 21:40
提示: 作者被禁止或删除 内容自动屏蔽




欢迎光临 仙剑之十里坡 (http://palslp.com/BBS/) Powered by Discuz! X2.5