Advertisement
Guest User

Untitled

a guest
Aug 8th, 2013
853
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.90 KB | None | 0 0
  1. #===========================================================================#
  2. # #*****************# #
  3. # #*** By Falcao ***# Mouse System Buttons 2.5 #
  4. # #*****************# This is a button based mouse script, allow #
  5. # create as many buttons you want to the map #
  6. # screen or map ground, also provide you full #
  7. # RMVXACE mouse interaction within the game play #
  8. # #
  9. # #
  10. # Falcao RGSS site: http://falcaorgss.wordpress.com #
  11. # Falcao Forum site: http://makerpalace.com #
  12. # #
  13. #===========================================================================#
  14.  
  15. #----------------------------------------------------------------------------
  16. # * Version 2.5 change log (Date: June 9 2013)
  17. #
  18. # Fixed non-refreshing item description bug
  19. # Fixed Save file selection issue
  20. # Added ability to start events even if the player is no facing the event
  21. # Removed option to display arrow selector on save file
  22. # Added compatibility for multiples game resolutions
  23. # Item selection with mouse is now more occurate
  24. # Fixed issue with pearl skillbar (when clicking any tool perform path finding)
  25. # Cleaned up some code
  26. #
  27. #----------------------------------------------------------------------------
  28. # * Version 2.0 change log (Date: January 13 2013)
  29. #
  30. # - Added path finding, now the game player is able to move using the mouse
  31. # - Now you are able to change the mouse cursor icon in game
  32. # - Two new notetags added to change the mouse cursor by event comment tags
  33. # - Fixed crash when pointing a notetagged event with a valid condition
  34. #----------------------------------------------------------------------------
  35. # * Version 1.6 change log (Date: November 21 2012)
  36. #
  37. # - Added compatibility for any game screen resolution
  38. # - System optimized to consume less cpu than before
  39. # - Added extra compatibility for Pearl ABS Liquid
  40. # - Removed the font fix
  41. # - Added the imported bolean
  42. #----------------------------------------------------------------------------
  43. # * Version 1.5 change log
  44. #
  45. # - Fixed cursor sound over loading on selectable windows
  46. # - Fixed bug when selecting event graphic tileset that have mouse comment tag
  47. # - FIxed minor bug when transfering (event name now erase completely)
  48. # - Added option to turn on / off arrow selector on save file
  49. # - Important! changes on mouse comment tags!
  50. # ~ CLICK START change to MOUSE START
  51. # ~ ANIMATION change to MOUSE ANIMATION
  52. # ~ NAME change to MOUSE NAME
  53. #
  54. #---------------------------------------------------------------------------
  55. # * installation
  56. #
  57. # Copy and paste this script above main done!
  58. #
  59. # * Mouse triggers
  60. # - Left click: Action button
  61. # - Right click: Cancel button, close windows
  62. # - Mouse wheel middle button: DASH
  63. #
  64. #---------------------------------------------------------------------------
  65. # * Main features
  66. #
  67. # - Allow you create buttons and configure them to do something
  68. # - Events can be buttons too, map ground buttons! for some puzzles etc.
  69. # - Allow you display event name
  70. # - Full mouse interaction
  71. # - WASD movement optional
  72. # - Path finding feature, player is able to move using the mouse
  73. # - Mouse cursor changing in-game enabled
  74. #---------------------------------------------------------------------------
  75. # * Event buttons commands
  76. #
  77. # Write this lines on event comments tags
  78. #
  79. # MOUSE START - Event start when you click the event
  80. # MOUSE ANIMATION x - Show animation when mouse is over event,
  81. # ex: MOUSE ANIMATION 1
  82. # MOUSE NAME x - Display event name when mouse is over event,
  83. # ex: MOUSE NAME Falcao
  84. # MOUSE ICON x - change the mouse cursor icon when it is over the event
  85. # change x for the icon index to display
  86. # MOUSE PIC X - Change the mouse cursor when is over an event but in this
  87. # case it display a picture graphic name, change x for the
  88. # picture name
  89. #------------------------------------------------------------------------------
  90. # * Script calls
  91. #
  92. # Call this line to turn off/on the mouse cursor within the game true/false
  93. # Mouse.show_cursor(false)
  94. #
  95. # If you want to change the mouse cursor manually use the following script calls
  96. # Mouse.set_cursor(:iconset, x) - change x for any icon index
  97. #
  98. # if you want to show a picture instead iconset use the next script call
  99. # Mouse.set_cursor(:picture, name) - change name for picture name
  100. #-----------------------------------------------------------------------------
  101.  
  102. module Map_Buttons
  103.  
  104. # You can easily insert as many buttons you want to the map screen
  105. # define here below your buttons parameters
  106.  
  107. Insert = {
  108. #-----------------------------------------------------------------------------
  109. # A => [B, C, D, E, F]
  110. #
  111. # A = Button number
  112. #
  113. # B = Name
  114. # C = X position in screen tile
  115. # D = Y position in screen tile
  116. # E = Icon, if you want a picture write picture 'name' otherwise icon index
  117. # F = What this button gonna do?, you have two options, call scene or call
  118. # common event, if you want scene put scene name, if you want common event
  119. # put common event ID
  120.  
  121. # This button call the menu screen
  122. 1=> ["Menu", 16, 11, 117, Scene_Menu],
  123.  
  124. # This button call a common event ID 1
  125. 2=> ["Bestiary", 16, 12, 121, 1],
  126.  
  127.  
  128.  
  129. }
  130.  
  131. # * General configutration
  132.  
  133. # Mouse cursor icon, if you want a picture write pic 'name' otherwise icon index
  134. CursorIcon = 386
  135.  
  136. # Switch ID to turn off/on the icons on the screen
  137. Switch = 100
  138.  
  139. # Allow movement with W A S D keys true/false
  140. WASD_Movement = true
  141.  
  142. # When you click on event, do you want the player to ignore the self movement?
  143. IgnoreEventPath = true
  144.  
  145. # Switch id to enable or disable the path finding feature
  146. PathFinderSwitch = 500
  147. #
  148. #----------------------------------------------------------------------------
  149. #
  150. # * License
  151. #
  152. # You can use this script in non comercial games, in you need it for comercial
  153. # games let me know. falmc99@gmail.com
  154. #-----------------------------------------------------------------------------
  155.  
  156. def self.check_value(value)
  157. return 'numeric' if value.is_a? Fixnum
  158. return 'string'
  159. end
  160. end
  161.  
  162. ($imported ||= {})[:Mouse_System_Buttons] = 2.0
  163.  
  164. # This class create all screen and event buttons on game screen
  165. class Interactive_Buttoms
  166. attr_reader :cursoring
  167. def initialize
  168. create_screen_buttoms
  169. @ani_delay = 0
  170. @pearl_abs = $imported["Falcao Pearl ABS Liquid"]
  171. end
  172.  
  173. def create_screen_buttoms
  174. @buttons_sprites = []
  175. for i in Map_Buttons::Insert.values
  176. @buttons_sprites.push(Sprite_Buttons.new(i[0], i[1], i[2], i[3], i[4]))
  177. end
  178. end
  179.  
  180. def create_button_text
  181. if @button_text.nil?
  182. @button_text = Sprite.new
  183. @button_text.bitmap = Bitmap.new(100, 32)
  184. @button_text.z = 50
  185. @button_text.bitmap.font.size = 16
  186. end
  187. end
  188.  
  189. def dispose_screen_buttons
  190. for button in @buttons_sprites
  191. button.dispose
  192. end
  193. @buttons_sprites = []
  194. end
  195.  
  196. def dispose_button_text
  197. if not @button_text.nil?
  198. @button_text.dispose
  199. @button_text.bitmap.dispose
  200. @button_text = nil
  201. end
  202. end
  203.  
  204. def dispose
  205. dispose_screen_buttons
  206. dispose_button_text
  207. end
  208.  
  209. def update
  210. if $game_switches[Map_Buttons::Switch] and not @buttons_sprites.empty?
  211. dispose_screen_buttons
  212. elsif not $game_switches[Map_Buttons::Switch] and @buttons_sprites.empty?
  213. create_screen_buttoms
  214. end
  215. update_buttons
  216. update_event_selection
  217. end
  218.  
  219. # path update
  220. def update_path
  221. return if $game_switches[Map_Buttons::PathFinderSwitch]
  222. return if $game_message.busy?
  223. return unless $game_player.normal_walk?
  224. @mxx, @myy = Mouse.map_grid[0], Mouse.map_grid[1]
  225. if Map_Buttons::IgnoreEventPath
  226. $game_map.events.values.each do |event|
  227. return if event.x == @mxx and event.y == @myy
  228. end
  229. end
  230. $game_player.find_path(@mxx, @myy) unless on_toolbar?
  231. end
  232.  
  233.  
  234. def on_toolbar?
  235. return false unless @pearl_abs
  236. 9.times.each {|x| return true if @mxx == PearlSkillBar::Tile_X + x and
  237. @myy == PearlSkillBar::Tile_Y}
  238. return false
  239. end
  240.  
  241.  
  242. def update_buttons
  243. for button in @buttons_sprites
  244. button.update
  245. if button.zooming
  246. @screen_b = true
  247. create_button_text
  248. if button.x > 272
  249. x, y = button.px * 32 - 98, button.py * 32
  250. draw_button_text(x, y, button.name, 2)
  251. elsif button.x < 272
  252. x, y = button.px * 32 + 31, button.py * 32
  253. draw_button_text(x, y, button.name, 0)
  254. end
  255. end
  256. end
  257.  
  258. if @screen_b != nil
  259. unless mouse_over_button?
  260. dispose_button_text
  261. @screen_b = nil
  262. end
  263. end
  264. end
  265.  
  266. def reset_cursor
  267. if Map_Buttons::check_value(@cursoring[1]) == 'numeric'
  268. Mouse.set_cursor(:iconset, @cursoring[1], true)
  269. else
  270. Mouse.set_cursor(:picture, @cursoring[1], true)
  271. end
  272. @cursoring = nil
  273. end
  274.  
  275. def apply_iconchanging(sym, operand, event)
  276. cursor = $game_system.cursorr
  277. cursor = Map_Buttons::CursorIcon if cursor.nil?
  278. @cursoring = [event, cursor]
  279. Mouse.set_cursor(sym, operand, true)
  280. end
  281.  
  282. def update_event_selection
  283. return if @screen_b #disable event buttom if mouse over screen buttom
  284. update_path if Mouse.trigger?(0)
  285. for event in $game_map.events.values
  286. next if event.page.nil?
  287. if event.x == Mouse.map_grid[0] and event.y == Mouse.map_grid[1]
  288. if event.mouse_start
  289. if Mouse.trigger?(0) and !$game_map.interpreter.running?
  290. event.start
  291. end
  292. end
  293.  
  294. if event.square_size?($game_player, 2)
  295. if Mouse.trigger?(0) and !$game_map.interpreter.running?
  296. event.start
  297. end
  298. end
  299.  
  300. anime = event.mouse_animation
  301. if anime != 0
  302. @ani_delay += 1
  303. event.animation_id = anime if @ani_delay == 1
  304. @ani_delay = 0 if @ani_delay > 16
  305. end
  306. name = event.mouse_name
  307. if name != ""
  308. @eve = [event.x, event.y, event, name]
  309. create_button_text
  310. end
  311. icon = event.mouse_iconset
  312. picture = event.mouse_picture
  313. if !icon.nil? and icon != 0 and @cursoring.nil?
  314. apply_iconchanging(:iconset, icon, event)
  315. elsif !picture.nil? and picture != "" and @cursoring.nil?
  316. apply_iconchanging(:picture, picture, event)
  317. end
  318. end
  319. end
  320.  
  321. if @cursoring != nil
  322. reset_cursor if not mouse_over_event?(@cursoring[0].x, @cursoring[0].y)
  323. end
  324.  
  325. if @eve != nil
  326. @eve[2].ch_oy.nil? ? event_oy = 32 : event_oy = @eve[2].ch_oy
  327. if event_oy > 32
  328. draw_button_text(@eve[2].screen_x - 49,
  329. @eve[2].screen_y - event_oy / 2 - 50, @eve[3], 1)
  330. else
  331. draw_button_text(@eve[2].screen_x - 49,
  332. @eve[2].screen_y - event_oy / 2 - 36, @eve[3], 1)
  333. end
  334. if not mouse_over_event?(@eve[0], @eve[1])
  335. dispose_button_text
  336. @eve = nil
  337. end
  338. end
  339. end
  340.  
  341. def draw_button_text(x, y, text, a=0)
  342. return if @button_text.nil?
  343. @button_text.x = x
  344. @button_text.y = y
  345. return if @old_name == text
  346. @button_text.bitmap.clear
  347. @button_text.bitmap.draw_text(2, 0, @button_text.bitmap.width, 32, text, a)
  348. @old_name = text
  349. end
  350.  
  351. def mouse_over_button?
  352. for button in @buttons_sprites
  353. if Mouse.object_area?(button.x, button.y - 6, button.width, button.height)
  354. return true
  355. end
  356. end
  357. @old_name = nil
  358. return false
  359. end
  360.  
  361. def mouse_over_event?(event_x, event_y)
  362. if Mouse.map_grid[0] == event_x and Mouse.map_grid[1] == event_y
  363. return true
  364. end
  365. @old_name = nil
  366. return false
  367. end
  368. end
  369.  
  370. # Set buttons sprites
  371. class Spriteset_Map
  372. alias falcao_insert_buttuns_view create_viewports
  373. def create_viewports
  374. @interact_buttoms = Interactive_Buttoms.new
  375. falcao_insert_buttuns_view
  376. end
  377.  
  378. alias falcao_insert_buttuns_dis dispose
  379. def dispose
  380. @interact_buttoms.reset_cursor if @interact_buttoms.cursoring != nil
  381. @interact_buttoms.dispose
  382. falcao_insert_buttuns_dis
  383. end
  384.  
  385. alias falcao_insert_buttuns_up update
  386. def update
  387. if $game_player.clear_mousepointers
  388. @interact_buttoms.dispose
  389. $game_player.clear_mousepointers = nil
  390. end
  391. @interact_buttoms.update
  392. falcao_insert_buttuns_up
  393. end
  394. end
  395.  
  396. # comments definition
  397. class Game_Event < Game_Character
  398. attr_reader :mouse_start, :mouse_animation, :mouse_name, :mouse_iconset
  399. attr_reader :mouse_picture, :page
  400. alias falcaomouse_setup setup_page_settings
  401. def setup_page_settings
  402. falcaomouse_setup
  403. @mouse_start = check_comment("MOUSE START")
  404. @mouse_animation = check_value("MOUSE ANIMATION")
  405. @mouse_name = check_name("MOUSE NAME")
  406. @mouse_iconset = check_value("MOUSE ICON")
  407. @mouse_picture = check_name("MOUSE PIC")
  408. end
  409.  
  410. def check_comment(comment)
  411. return false if @list.nil? or @list.size <= 0
  412. for item in @list
  413. if item.code == 108 or item.code == 408
  414. if item.parameters[0].include?(comment)
  415. return true
  416. end
  417. end
  418. end
  419. return false
  420. end
  421.  
  422. def check_value(comment)
  423. return 0 if @list.nil? or @list.size <= 0
  424. for item in @list
  425. if item.code == 108 or item.code == 408
  426. if item.parameters[0] =~ /#{comment}[ ]?(\d+)?/
  427. return $1.to_i
  428. end
  429. end
  430. end
  431. return 0
  432. end
  433.  
  434. def check_name(comment)
  435. return "" if @list.nil? or @list.size <= 0
  436. for item in @list
  437. next unless item.code == 108 or item.code == 408
  438. if item.parameters[0] =~ /#{comment} (.*)/
  439. return $1.to_s
  440. end
  441. end
  442. return ""
  443. end
  444.  
  445. def square_size?(target, size)
  446. distance = (@x - target.x).abs + (@y - target.y).abs
  447. enable = (distance <= size-1)
  448. return true if enable
  449. return false
  450. end
  451.  
  452. end
  453.  
  454. # Create screen buttons sprites
  455. class Sprite_Buttons < Sprite
  456. attr_reader :px
  457. attr_reader :py
  458. attr_reader :name
  459. attr_reader :zooming
  460. def initialize(name, px, py, icon_index, action=nil)
  461. super()
  462. self.z = 50
  463. @icon_index = icon_index
  464. @px = px
  465. @py = py
  466. @action = action
  467. @object_zooming = 0
  468. @zooming = false
  469. @name = name
  470. set_bitmap
  471. update
  472. end
  473.  
  474. def update
  475. super
  476. if Mouse.object_area?(self.x, self.y - 4, self.bitmap.width,
  477. self.bitmap.height)
  478. @zooming = true
  479. @object_zooming += 1
  480. case @object_zooming
  481. when 1..10 ; self.zoom_x -= 0.02 ; self.zoom_y -= 0.02
  482. when 11..20 ; self.zoom_x += 0.02 ; self.zoom_y += 0.02
  483. when 21..30 ; self.zoom_x = 1.0 ; self.zoom_y = 1.0
  484. @object_zooming = 0
  485. end
  486. if Mouse.trigger?(0) and @action != nil
  487. unless $game_map.interpreter.running?
  488. Sound.play_ok
  489. if @action == Scene_Menu and not $game_system.menu_disabled
  490. SceneManager.call(@action)
  491. Window_MenuCommand::init_command_position
  492. return
  493. end
  494. if Map_Buttons::check_value(@action) == 'numeric'
  495. $game_temp.reserve_common_event(@action)
  496. else
  497. SceneManager.call(@action)
  498. end
  499. end
  500. end
  501. elsif @object_zooming > 0
  502. self.zoom_x = 1.0
  503. self.zoom_y = 1.0
  504. @object_zooming = 0
  505. else
  506. @zooming = false
  507. end
  508. end
  509.  
  510. def set_bitmap
  511. if Map_Buttons::check_value(@icon_index) == 'numeric'
  512. self.bitmap = Bitmap.new(24, 24)
  513. bitmap = Cache.system("Iconset")
  514. rect = Rect.new(@icon_index % 16 * 24, @icon_index / 16 * 24, 24, 24)
  515. self.bitmap.blt(0, 0, bitmap, rect)
  516. else
  517. self.bitmap = Cache.picture(@icon_index)
  518. end
  519. self.x = @px * 32 + 4
  520. self.y = @py * 32 + 4
  521. end
  522. end
  523.  
  524. # Game_character new variable
  525. class Game_CharacterBase
  526. attr_accessor :ch_oy
  527. end
  528.  
  529. # Sprite character
  530. class Sprite_Character < Sprite_Base
  531. alias falcaoadd_oxy_set_character_bitmap set_character_bitmap
  532. def set_character_bitmap
  533. falcaoadd_oxy_set_character_bitmap
  534. @character.ch_oy = self.oy
  535. end
  536. end
  537.  
  538. class Game_System
  539. attr_accessor :current_cursor
  540. def cursorr
  541. return Map_Buttons::CursorIcon if @current_cursor.nil?
  542. return @current_cursor
  543. end
  544. end
  545.  
  546. # Mouse module
  547. module Mouse
  548.  
  549. GetKeyState = Win32API.new('user32', 'GetAsyncKeyState', 'i', 'i')
  550. GetCursorPos = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
  551. GetClientRect = Win32API.new('user32', 'GetClientRect', %w(l p), 'i')
  552. ShowCursor = Win32API.new('user32', 'ShowCursor', 'i', 'l')
  553. ScreenToClient = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')
  554. Findwindow = Win32API.new('user32', 'FindWindowA', %w(p p), 'l')
  555. GetPrivatePro = Win32API.new('kernel32', 'GetPrivateProfileStringA',
  556. %w(p p p p l p), 'l')
  557.  
  558. ShowCursor.call(0)
  559.  
  560. @triggers = [[0, 1], [0, 2], [0, 4]]
  561. @old_pos = 0
  562.  
  563. # Mouse Sprite
  564.  
  565. def self.set_cursor(sym, operand, write=false)
  566. case sym
  567. when :iconset
  568. $mouse_cursor.bitmap = Bitmap.new(24, 24)
  569. bitmap = Cache.system("Iconset")
  570. rect = Rect.new(operand % 16 * 24, operand / 16 * 24, 24, 24)
  571. $mouse_cursor.bitmap.blt(0, 0, bitmap, rect)
  572. when :picture then $mouse_cursor.bitmap = Cache.picture(operand)
  573. end
  574. $game_system.current_cursor = operand if write
  575. end
  576.  
  577. $mouse_cursor = Sprite.new
  578. icon = Map_Buttons::CursorIcon
  579. if Map_Buttons::check_value(icon) == 'numeric'
  580. set_cursor(:iconset, icon)
  581. else
  582. set_cursor(:picture, icon)
  583. end
  584. $mouse_cursor.z = 10001
  585. $mouse_cursor.x = $mouse_cursor.y = 1000
  586. $mouse_cursor.ox = 4
  587.  
  588. def self.show_cursor(value)
  589. unless value
  590. @pos[0] = @pos[1] = 600
  591. end
  592. $mouse_cursor.visible = value
  593. end
  594.  
  595. def self.map_grid
  596. return nil if @pos == nil
  597. x = ($game_map.display_x).to_i + (@pos[0] / 32)
  598. y = ($game_map.display_y).to_i + (@pos[1] / 32)
  599. return [x, y]
  600. end
  601.  
  602. def self.standing?
  603. return false if @old_px != @pos[0]
  604. return false if @old_py != @pos[1]
  605. return true
  606. end
  607.  
  608. def self.input_keys
  609. $game_arrows.mode_on ? type = $game_arrows.in_type : type = Input::C
  610. keys = {0 => type, 1 => Input::B, 2 => Input::A}
  611. return keys
  612. end
  613.  
  614. def self.object_area?(x, y, width, height)
  615. return false if @pos.nil?
  616. return @pos[0].between?(x, width + x) && @pos[1].between?(y, height + y)
  617. end
  618.  
  619. def self.position
  620. return @pos == nil ? [0, 0] : @pos
  621. end
  622.  
  623. def self.global_pos
  624. pos = [0, 0].pack('ll')
  625. return GetCursorPos.call(pos) == 0 ? nil : pos.unpack('ll')
  626. end
  627.  
  628. def self.screen_to_client(x=0, y=0)
  629. pos = [x, y].pack('ll')
  630. return ScreenToClient.call(self.hwnd, pos) == 0 ? nil : pos.unpack('ll')
  631. end
  632.  
  633. def self.pos
  634. global_pos = [0, 0].pack('ll')
  635. gx, gy = GetCursorPos.call(global_pos) == 0 ? nil : global_pos.unpack('ll')
  636. local_pos = [gx, gy].pack('ll')
  637. x, y = ScreenToClient.call(self.hwnd,
  638. local_pos) == 0 ? nil : local_pos.unpack('ll')
  639. begin
  640. if (x >= 0 && y >= 0 && x <= Graphics.width && y <= Graphics.height)
  641. @old_px, @old_py = x, y
  642. return x, y
  643. else
  644. return -20, -20
  645. end
  646. rescue
  647. return 0, 0
  648. end
  649. end
  650.  
  651. def self.update
  652. old_pos = @pos
  653. @pos = self.pos
  654. self.input_keys
  655. if !$mouse_cursor.visible && old_pos != @pos
  656. $mouse_cursor.visible = true
  657. end
  658. if old_pos != [-20, -20] && @pos == [-20, -20]
  659. ShowCursor.call(1)
  660. elsif old_pos == [-20, -20] && @pos != [-20, -20]
  661. ShowCursor.call(0)
  662. end
  663. for i in @triggers
  664. n = GetKeyState.call(i[1])
  665. if [0, 1].include?(n)
  666. i[0] = (i[0] > 0 ? i[0] * -1 : 0)
  667. else
  668. i[0] = (i[0] > 0 ? i[0] + 1 : 1)
  669. end
  670. end
  671. end
  672.  
  673. # trigger definition
  674. def self.trigger?(id = 0)
  675. pos = self.pos
  676. if pos != [-20,-20]
  677. case id
  678. when 0
  679. return @triggers[id][0] == 1
  680. when 1
  681. if @triggers[1][0] == 1 && !$game_system.menu_disabled
  682. return @triggers[id][0] == 1
  683. end
  684. when 2
  685. return @triggers[id][0] == 1
  686. end
  687. end
  688. end
  689.  
  690. # repeat definition
  691. def self.repeat?(id = 0)
  692. if @triggers[id][0] <= 0
  693. return false
  694. else
  695. return @triggers[id][0] % 5 == 1 && @triggers[id][0] % 5 != 2
  696. end
  697. end
  698.  
  699. #press definition
  700. def self.press?(id = 0)
  701. if @triggers[id][0] <= 0
  702. return false
  703. else
  704. return true
  705. end
  706. end
  707.  
  708. def self.screen_to_client(x=0, y=0)
  709. pos = [x, y].pack('ll')
  710. return ScreenToClient.call(self.hwnd, pos) == 0 ? nil : pos.unpack('ll')
  711. end
  712.  
  713. def self.hwnd
  714. if @hwnd.nil?
  715. game_name = "\0" * 256
  716. GetPrivatePro.call('Game', 'Title', '', game_name, 255, ".\\Game.ini")
  717. game_name.delete!("\0")
  718. @hwnd = Findwindow.call('RGSS Player', game_name)
  719. end
  720. return @hwnd
  721. end
  722.  
  723. def self.client_size
  724. rect = [0, 0, 0, 0].pack('l4')
  725. GetClientRect.call(self.hwnd, rect)
  726. right, bottom = rect.unpack('l4')[2..3]
  727. return right, bottom
  728. end
  729. end
  730.  
  731. # Input module aliased
  732. class << Input
  733. unless self.method_defined?(:falcao21_mouse_update)
  734. alias_method :falcao21_mouse_update, :update
  735. alias_method :falcao21_mouse_trigger?, :trigger?
  736. alias_method :falcao21_mouse_repeat?, :repeat?
  737. alias_method :fal_mouse_input_press?, :press?
  738. end
  739.  
  740. def update
  741. if $mouse_cursor.visible
  742. Mouse.update
  743. $game_arrows.update
  744. mx, my = *Mouse.position
  745. $mouse_cursor.x = mx unless mx.nil?
  746. $mouse_cursor.y = my unless my.nil?
  747. end
  748. falcao21_mouse_update
  749. end
  750.  
  751. # trigger
  752. def trigger?(constant)
  753. return true if falcao21_mouse_trigger?(constant)
  754. unless Mouse.pos.nil?
  755. if Mouse.input_keys.has_value?(constant)
  756. mouse_trigger = Mouse.input_keys.index(constant)
  757. return true if Mouse.trigger?(mouse_trigger)
  758. end
  759. end
  760. return false
  761. end
  762.  
  763. # press
  764. def press?(constant)
  765. return true if fal_mouse_input_press?(constant)
  766. unless Mouse.pos.nil?
  767. if Mouse.input_keys.has_value?(constant)
  768. mouse_trigger = Mouse.input_keys.index(constant)
  769. return true if Mouse.press?(mouse_trigger)
  770. end
  771. end
  772. return false
  773. end
  774.  
  775. # repeat
  776. def repeat?(constant)
  777. return true if falcao21_mouse_repeat?(constant)
  778. unless Mouse.pos.nil?
  779. if Mouse.input_keys.has_value?(constant)
  780. mouse_trigger = Mouse.input_keys.index(constant)
  781. return true if Mouse.repeat?(mouse_trigger)
  782. end
  783. end
  784. return false
  785. end
  786. end
  787.  
  788. # Here your best friend, you can call this script within the game, scene etc.
  789. # $game_arrows.create_arrows(x, y), create it, $game_arrows.dispose, delete it
  790. class Game_Arrow_Selector
  791. attr_accessor :mode_on
  792. attr_accessor :in_type
  793. def initialize
  794. @mode_on = false
  795. end
  796.  
  797. def create_arrows(x, y)
  798. return unless @arrows_sprites.nil?
  799. buttons = {1=> 'UP', 2=> 'RIGHT', 3=> 'DOWN',
  800. 4=> 'LEFT', 5=> 'OK', 6=> 'Cancel'}
  801. @arrows_sprites = []
  802. for i in buttons.values
  803. @arrows_sprites.push(Garrows_Sprites.new(i, x, y))
  804. end
  805. end
  806.  
  807. def dispose
  808. return if @arrows_sprites.nil?
  809. for arrow in @arrows_sprites
  810. arrow.dispose
  811. end
  812. @arrows_sprites = nil
  813. @mode_on = false
  814. end
  815.  
  816. def update
  817. return if @arrows_sprites.nil?
  818. for arrow in @arrows_sprites
  819. arrow.update
  820. end
  821. end
  822. end
  823.  
  824. class Garrows_Sprites < Sprite
  825. def initialize(name, x, y)
  826. super()
  827. self.z = 1000
  828. @px, @py = x, y
  829. @name = name
  830. @object_zooming = 0
  831. @zooming = false
  832. set_bitmap
  833. update
  834. end
  835.  
  836. def update
  837. super
  838. if Mouse.object_area?(self.x + @fix[0], self.y + @fix[1],
  839. self.bitmap.width + @fix[2], self.bitmap.height + @fix[3])
  840. $game_arrows.mode_on = true
  841. $game_arrows.in_type = Input::UP if @name == 'UP'
  842. $game_arrows.in_type = Input::DOWN if @name == 'DOWN'
  843. $game_arrows.in_type = Input::LEFT if @name == 'LEFT'
  844. $game_arrows.in_type = Input::RIGHT if @name == 'RIGHT'
  845. $game_arrows.in_type = Input::C if @name == 'OK'
  846. $game_arrows.in_type = Input::B if @name == 'Cancel'
  847. @object_zooming += 1
  848. @zooming = true
  849. case @object_zooming
  850. when 1..10 ; self.zoom_x -= 0.01 ; self.zoom_y -= 0.01
  851. when 11..20 ; self.zoom_x += 0.01 ; self.zoom_y += 0.01
  852. when 21..30 ; self.zoom_x = 1.0 ; self.zoom_y = 1.0
  853. @object_zooming = 0
  854. end
  855. elsif @object_zooming > 0
  856. self.zoom_x = 1.0
  857. self.zoom_y = 1.0
  858. @object_zooming = 0
  859. elsif @zooming
  860. @zooming = false
  861. $game_arrows.mode_on = false
  862. end
  863. end
  864.  
  865. def set_bitmap
  866. self.bitmap = Bitmap.new(24, 15) if @name != 'Cancel'
  867. case @name
  868. when 'UP'
  869. self.x = @px + 25 ; self.y = @py - 2
  870. self.angle = 182 ; @fix = [-23, -18, 0, 0]
  871. when 'DOWN'
  872. self.x = @px + 1 ; self.y = @py + 26
  873. @fix = [0, -4, 0, 0]
  874. when 'LEFT'
  875. self.x = @px ; self.y = @py + 1
  876. self.angle = - 92 ; @fix = [-14, -4, - 9, 9]
  877. when 'RIGHT'
  878. self.x = @px + 26 ; self.y = @py + 26
  879. self.angle = + 92 ; @fix = [0, - 26, - 9, 9]
  880. when 'OK'
  881. self.x = @px + 1 ; self.y = @py + 6
  882. @fix = [0, -4, 0, 0]
  883. self.bitmap.font.size = 20
  884. self.bitmap.draw_text(4, -7, self.bitmap.width, 32, @name)
  885. return
  886. when 'Cancel'
  887. self.x = @px - 11 ; self.y = @py + 42
  888. @fix = [0, -4, 0, 0]
  889. self.bitmap = Bitmap.new(50, 15)
  890. self.bitmap.font.size = 20
  891. self.bitmap.draw_text(2, -7, self.bitmap.width, 32, @name)
  892. return
  893. end
  894. draw_crappy_triangle(0, 0)
  895. end
  896.  
  897. # This method create a crappy triangle pointing down
  898. def draw_crappy_triangle(px, py)
  899. color = Color.new(192, 224, 255, 255)
  900. x, y, w, = 0, 4, 24
  901. self.bitmap.fill_rect(px + 1, py, 22, 1, color)
  902. self.bitmap.fill_rect(px, py + 1, 24, 4, color)
  903. for i in 1..10
  904. x += 1; y += 1; w -= 2
  905. self.bitmap.fill_rect(px + x, py + y, w, 1, color)
  906. end
  907. end
  908. end
  909.  
  910. $game_arrows = Game_Arrow_Selector.new
  911.  
  912. # Arrow selector is displayed when Input number is on
  913. class Game_Interpreter
  914. alias falcao_setup_num_input setup_num_input
  915. def setup_num_input(params)
  916. falcao_setup_num_input(params)
  917. $game_arrows.create_arrows(256, 194) if $game_message.position == 0
  918. $game_arrows.create_arrows(256, 340) if $game_message.position == 1
  919. $game_arrows.create_arrows(256, 180) if $game_message.position == 2
  920. end
  921. end
  922.  
  923. # Arrow selector is disposed when press ok
  924. class Window_NumberInput < Window_Base
  925. alias falcao_process_ok process_ok
  926. def process_ok
  927. falcao_process_ok
  928. $game_arrows.dispose
  929. end
  930. end
  931.  
  932. # WASD Movements
  933. module Input
  934. class << self
  935. if !method_defined?('vxe_dir4')
  936. alias vxace_dir4 dir4
  937. end
  938. def dir4
  939. if Map_Buttons::WASD_Movement
  940. return 2 if (Input.press?(Input::Y))
  941. return 4 if (Input.press?(Input::X))
  942. return 6 if (Input.press?(Input::Z))
  943. return 8 if (Input.press?(Input::R))
  944. end
  945. return vxace_dir4
  946. end
  947. end
  948. end
  949.  
  950. # If event start with mouse
  951. class Game_Player < Game_Character
  952. alias falcao_start_map_event start_map_event
  953. def start_map_event(x, y, triggers, normal)
  954. $game_map.events_xy(x, y).each do |event_click|
  955. return if event_click.check_comment("MOUSE START")
  956. end
  957. falcao_start_map_event(x, y, triggers, normal)
  958. end
  959. end
  960.  
  961. # clear pointers when tranfering
  962. class Game_Player < Game_Character
  963. attr_accessor :clear_mousepointers
  964. alias falcaomouse_perform_transfer perform_transfer
  965. def perform_transfer
  966. @clear_mousepointers = true if $game_map.map_id != @new_map_id
  967. falcaomouse_perform_transfer
  968. end
  969. end
  970.  
  971. # Path find
  972. class Game_Character < Game_CharacterBase
  973. attr_accessor :map, :runpath
  974. alias pathfind1_ini initialize
  975. def initialize
  976. pathfind1_ini
  977. @map = nil
  978. @runpath = false
  979. end
  980.  
  981. alias pathfind1_up update
  982. def update
  983. run_path if @runpath == true
  984. pathfind1_up
  985. end
  986.  
  987. def run_path
  988. return if moving?
  989. step = @map[@x,@y]
  990. if step == 1
  991. @map = nil
  992. @runpath = false
  993. return
  994. end
  995. dir = rand(2)
  996. case dir
  997. when 0
  998. move_straight(6) if @map[@x+1,@y] == step - 1 && step != 0
  999. move_straight(2) if @map[@x,@y+1] == step - 1 && step != 0
  1000. move_straight(4) if @map[@x-1,@y] == step - 1 && step != 0
  1001. move_straight(8) if @map[@x,@y-1] == step - 1 && step != 0
  1002. when 1
  1003. move_straight(8) if @map[@x,@y-1] == step - 1 && step != 0
  1004. move_straight(4) if @map[@x-1,@y] == step - 1 && step != 0
  1005. move_straight(2) if @map[@x,@y+1] == step - 1 && step != 0
  1006. move_straight(6) if @map[@x+1,@y] == step - 1 && step != 0
  1007. end
  1008. end
  1009.  
  1010. def find_path(x,y)
  1011. sx, sy = @x, @y
  1012. result = setup_map(sx,sy,x,y)
  1013. @runpath = result[0]
  1014. @map = result[1]
  1015. @map[sx,sy] = result[2] if result[2] != nil
  1016. end
  1017.  
  1018. def clear_path
  1019. @map = nil
  1020. @runpath = false
  1021. end
  1022.  
  1023. def setup_map(sx,sy,ex,ey)
  1024. map = Table.new($game_map.width, $game_map.height)
  1025. map[ex,ey] = 1
  1026. old_positions = []
  1027. new_positions = []
  1028. old_positions.push([ex, ey])
  1029. depth = 2
  1030. depth.upto(100){|step|
  1031. loop do
  1032. break if old_positions[0] == nil
  1033. x,y = old_positions.shift
  1034. return [true, map, step] if x == sx and y+1 == sy
  1035. if $game_player.passable?(x, y, 2) and map[x,y + 1] == 0
  1036. map[x,y + 1] = step
  1037. new_positions.push([x,y + 1])
  1038. end
  1039. return [true, map, step] if x-1 == sx and y == sy
  1040. if $game_player.passable?(x, y, 4) and map[x - 1,y] == 0
  1041. map[x - 1,y] = step
  1042. new_positions.push([x - 1,y])
  1043. end
  1044. return [true, map, step] if x+1 == sx and y == sy
  1045. if $game_player.passable?(x, y, 6) and map[x + 1,y] == 0
  1046. map[x + 1,y] = step
  1047. new_positions.push([x + 1,y])
  1048. end
  1049. return [true, map, step] if x == sx and y-1 == sy
  1050. if $game_player.passable?(x, y, 8) and map[x,y - 1] == 0
  1051. map[x,y - 1] = step
  1052. new_positions.push([x,y - 1])
  1053. end
  1054. end
  1055. old_positions = new_positions
  1056. new_positions = []
  1057. }
  1058. return [false, nil, nil]
  1059. end
  1060. end
  1061.  
  1062. class Game_Player
  1063. alias pathfind_player_update update
  1064. def update
  1065. clear_path if Input.dir4 != 0
  1066. pathfind_player_update
  1067. end
  1068.  
  1069. alias findpath_perform_transfer perform_transfer
  1070. def perform_transfer
  1071. clear_path if $game_map.map_id != @new_map_id
  1072. findpath_perform_transfer
  1073. end
  1074. end
  1075.  
  1076. # Window selectable (Thanks wora for some lines here)
  1077. class Window_Selectable < Window_Base
  1078. alias mouse_selection_ini initialize
  1079. def initialize(*args)
  1080. mouse_selection_ini(*args)
  1081. @scroll_wait = 0
  1082. @cursor_wait = 0
  1083. @sdelay = 0
  1084. end
  1085.  
  1086. alias mouse_selection_update update
  1087. def update
  1088. update_mouse_selection if self.active and self.visible
  1089. @sdelay -= 1 if @sdelay > 0
  1090. mouse_selection_update
  1091. end
  1092.  
  1093. def update_mouse_selection
  1094. @cursor_wait -= 1 if @cursor_wait > 0
  1095. plus_x = self.x + 16 - self.ox
  1096. plus_y = self.y + 8 - self.oy
  1097. unless self.viewport.nil?
  1098. plus_x += self.viewport.rect.x - self.viewport.ox
  1099. plus_y += self.viewport.rect.y - self.viewport.oy
  1100. end
  1101. (0..self.item_max - 1).each do |i|
  1102. irect = item_rect(i)
  1103. move_cursor(i) if Mouse.object_area?(
  1104. irect.x + plus_x, irect.y + plus_y, irect.width, irect.height)
  1105. update_cursor
  1106. end
  1107. end
  1108.  
  1109. def move_cursor(index)
  1110. return if @index == index
  1111. @scroll_wait -= 1 if @scroll_wait > 0
  1112. row1 = @index / self.col_max
  1113. row2 = index / self.col_max
  1114. bottom = self.top_row + (self.page_row_max - 1)
  1115. if index != @index and @sdelay == 0
  1116. Sound.play_cursor
  1117. @sdelay = 5
  1118. end
  1119. if row1 == self.top_row and row2 < self.top_row
  1120. return if @scroll_wait > 0
  1121. @index = [@index - self.col_max, 0].max
  1122. @scroll_wait = 30
  1123. elsif row1 == bottom and row2 > bottom
  1124. return if @scroll_wait > 0
  1125. @index = [@index + self.col_max, self.item_max - 1].min
  1126. @scroll_wait = 30
  1127. else
  1128. @index = index
  1129. end
  1130. select(@index)
  1131. return if @cursor_wait > 0
  1132. @cursor_wait += 2
  1133. end
  1134. end
  1135.  
  1136.  
  1137. class Window_NameInput
  1138. def item_max
  1139. return 90
  1140. end
  1141. end
  1142.  
  1143. class Scene_File < Scene_MenuBase
  1144.  
  1145. alias mouse_top_index top_index=
  1146. def top_index=(index)
  1147. @scroll_timer = 0 if @scroll_timer.nil? ; @scroll_timer -= 1
  1148. return if @scroll_timer > 0
  1149. mouse_top_index(index) ; @scroll_timer = 35
  1150. end
  1151.  
  1152. alias mouse_sb_update update
  1153. def update
  1154. (0..self.item_max - 1).each do |i|
  1155. ix = @savefile_windows[i].x
  1156. iy = @savefile_windows[i].y + 40 - @savefile_viewport.oy
  1157. iw = @savefile_windows[i].width
  1158. ih = @savefile_windows[i].height
  1159. if Mouse.object_area?(ix, iy, iw, ih)
  1160. @savefile_windows[@index].selected = false
  1161. @savefile_windows[i].selected = true
  1162. @index = i
  1163. end
  1164. ensure_cursor_visible
  1165. end
  1166. mouse_sb_update
  1167. end
  1168. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement