Guest User

Unknown Error Amaranth's Mouse Script

a guest
Sep 4th, 2016
61
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #============================================================================
  2. # SUPER SIMPLE MOUSE SCRIPT
  3. # v1.10 by Shaz
  4. #----------------------------------------------------------------------------
  5. # This is a conversion of the XP Mouse script by Near Fantastica and
  6. # SephirothSpawn modified by Amaranth Games, to run under VX Ace.
  7. #----------------------------------------------------------------------------
  8. # To Install:
  9. # Copy and paste into a new slot in materials, below all other scripts
  10. #----------------------------------------------------------------------------
  11. # To Customize:
  12. # Add keyword icon index pairs to the ICON hash (below this documentation).
  13. # Each of the keywords can be used in an event comment to make the mouse
  14. # cursor change into that icon when hovering over the event.
  15. #----------------------------------------------------------------------------
  16. # To Use:
  17. # Add the following comment to an event page:
  18. # <mouse icon [x y] [name]>
  19. # where icon is the keyword from the ICON hash below
  20. # x and y are the offsets to override player movement (optional)
  21. # name is the text to display next to the icon when hovering over the event (optional)
  22. #
  23. # Examples:
  24. # <mouse fight>
  25. # will change the cursor into the 'fight' icon when over the event
  26. # <mouse touch 0 1>
  27. # will change the cursor into the 'touch' icon when over the event, and
  28. # make the player walk to the tile below the event when the mouse button is
  29. # clicked
  30. # <mouse talk Gloria>
  31. # will change the cursor into the 'talk' icon and display the name Gloria
  32. # <mouse talk 0 2 Henry Smith>
  33. # will change the cursor into the 'talk' icon and display the name Henry Smith,
  34. # and when the mouse button is clicked, the player will walk to the tile
  35. # two below the event (good to use for shops where there's a counter in between)
  36. #
  37. # To force pathfinding on the player or an event, simply add a move route with
  38. # the player or event as the subject, with a Script command, and call
  39. # find_path(x, y) where x and y are the coordinates of the tile you want to move to
  40. # Examples:
  41. # Set Move Route (Player): Script: find_path(5, 8)
  42. # will make the player find a path to tile 5, 8
  43. # Set Move Route (This Event): Script: find_path(10, 5)
  44. # will make the event find a path to tile 10, 5
  45. #
  46. # NOTE: The path will be ATTEMPTED. If there is no path TO that exact tile,
  47. # a path to an adjacent tile will be attempted. If no path is found there
  48. # either, no movement will occur.
  49. # If a route is found, the player or event will begin moving towards it. But
  50. # if their path is blocked while they are moving, movement will be cancelled.
  51. #----------------------------------------------------------------------------
  52. # Author's Notes:
  53. # This script should work with any RTP script.
  54. # I do not guarantee that it will work with ANY other script (especially anything
  55. # that overrides player or event movement, such as pixel movement scripts, or
  56. # custom window scripts).
  57. #
  58. # Script OVERWRITES the following methods:
  59. # Game_Map.setup_starting_map_event
  60. # Game_Map.setup_autorun_common_event
  61. #
  62. # If you have other scripts that ALIAS these methods, this mouse script should
  63. # be placed above them.
  64. #----------------------------------------------------------------------------
  65. # Terms:
  66. # Use in free and commercial games
  67. # Credit: Near Fantastica, SephirothSpawn, Amaranth Games, Shaz
  68. #----------------------------------------------------------------------------
  69. # Versions:
  70. # 1.0 - 6 Sept 2013 - initial release
  71. # 1.02 - 7 Sept 2013 - fixed crash when loading games saved prior to adding script
  72. # - fixed player gets stuck on impassable area on world map
  73. # when clicking while leaving air ship
  74. # 1.03 - 8 Sept 2013 - fixed actor moving to diagonal tile instead of adjacent
  75. # 1.04 - 10 Sept 2013 - fixed vehicle pathfinding on world map
  76. # - fixed event trigger when no path found
  77. # 1.05 - 14 Sept 2013 - tweaked accessing of tilemap offset
  78. # 1.06 - 3 Nov 2013 - disabled mouse movement when waiting for NPC move route
  79. # - fixed events not triggering after player finishes walking
  80. # 1.07 - 6 Nov 2013 - slow down mouse scrolling, and don't loop save files
  81. # 1.08 - 24 Nov 2013 - cater for YEA Core large resolution with too-small maps
  82. # - fixed early event activation bug introduced in 1.06
  83. # - replaced calc of Windows_Selectable boundaries with item_rect
  84. # - added ability to completely disable mouse
  85. # 1.09 - 21 Dec 2013 - fixed mouse re-enable when calling common events
  86. # 1.10 - 6 Apr 2014 - add interaction for top part of > 32pixel high event
  87. # - activate an event without walking up to it
  88. # (add <autoactivate> comment at top of event page)
  89. # - arrow keys override mouse movement when pathfinding
  90. # - ignore mouse in menus when using keyboard
  91. # - make player walk to counter opposite shopkeepers
  92. #============================================================================
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. #============================================================================
  100. # SUPER SIMPLE MOUSE SCRIPT
  101. # Mouse Sprite
  102. #============================================================================
  103.  
  104.  
  105. # Add/remove/change icon names here. The icon name is what will be used in the
  106. # event <mouse ...> command to show a different mouse icon when hovering over
  107. # the event. These MUST be in lower case here!
  108. ICON = {'arrow' => 528, 'talk' => 530, 'look' => 529, 'fight' => 116,
  109. 'touch' => 531, 'exitu' => 532, 'exitd' => 533, 'exitl' => 534,
  110. 'exitr' => 535, 'mouse' => 536, 'game' => 537, 'book' => 236,
  111. 'sleep' => 6, 'clothes' => 168}
  112. DEFAULT_ICON = 'arrow'
  113.  
  114. class Sprite_Mouse < Sprite
  115. #--------------------------------------------------------------------------
  116. # * Initialization
  117. #--------------------------------------------------------------------------
  118. def initialize
  119. super
  120. self.z = 10100
  121. self.ox = 4
  122. update
  123. @dummy = Bitmap.new(32, 32)
  124. self.bitmap = Bitmap.new(32, 32)
  125. @enabled = true
  126. @ignored = false
  127. end
  128. #--------------------------------------------------------------------------
  129. # * Frame Update
  130. #--------------------------------------------------------------------------
  131. def update
  132. return if !@enabled
  133. super
  134. if !SceneManager.scene.nil?
  135. if !Mouse.position.nil?
  136. mx, my = *Mouse.position
  137. if @cursor == DEFAULT_ICON
  138. self.x = mx unless mx.nil?
  139. else
  140. self.x = [mx, Graphics.width - self.bitmap.width].min unless mx.nil?
  141. end
  142. self.y = my unless my.nil?
  143. end
  144. if @scene != SceneManager.scene.class || Mouse.trigger?
  145. @scene = SceneManager.scene.class
  146. set_bitmap
  147. end
  148. end
  149. end
  150. #--------------------------------------------------------------------------
  151. # * Set Bitmap
  152. #--------------------------------------------------------------------------
  153. def set_bitmap(cursor = DEFAULT_ICON, text = nil)
  154. if @ignored
  155. cursor = DEFAULT_ICON
  156. text = nil
  157. end
  158.  
  159. if @cursor != cursor || @text != text
  160. @cursor = cursor
  161. @text = text
  162. item_cursor = ICON[cursor]
  163. rect = Rect.new(item_cursor % 16 * 24, item_cursor / 16 * 24, 24, 24)
  164. if @text.nil?
  165. self.bitmap = Bitmap.new(24, 32)
  166. self.bitmap.blt(0, 0, Cache.system('Iconset'), rect)
  167. else
  168. w = @dummy.text_size(@text).width
  169. h = @dummy.font.size
  170. bitmap = Bitmap.new(26 + w, [32, h+2].max)
  171. bitmap.font.size = @dummy.font.size
  172. bitmap.font.shadow = true
  173. if self.x + 26 + w > Graphics.width
  174. bitmap.draw_text(0, 0, w, h, @text)
  175. bitmap.blt(w, 0, Cache.system('Iconset'), rect)
  176. else
  177. bitmap.blt(0, 0, Cache.system('Iconset'), rect)
  178. bitmap.draw_text(26, 0, w, h, @text)
  179. end
  180. self.bitmap = bitmap
  181. end
  182. end
  183. end
  184. #--------------------------------------------------------------------------
  185. # * Update Event Cursors
  186. #--------------------------------------------------------------------------
  187. def update_event_cursors
  188. # Remove mouse icon and text if we're off the grid
  189. if Mouse.grid.nil?
  190. set_bitmap
  191. return
  192. end
  193. # Set cursor and text according to event
  194. x, y = *Mouse.grid
  195. event = $game_map.lowest_mouse_event_xy(x, y)
  196. unless event.nil? && y < 410
  197. if !event.mouse_icon.nil? || !event.mouse_text.nil?
  198. set_bitmap(event.mouse_icon, event.mouse_text)
  199. return
  200. end
  201. end
  202. # default bitmap if not over an event
  203. set_bitmap
  204. end
  205. #--------------------------------------------------------------------------
  206. # * Enable Mouse
  207. #--------------------------------------------------------------------------
  208. def enabled=(value)
  209. @enabled = value
  210. self.visible = value
  211. end
  212. #--------------------------------------------------------------------------
  213. # * Mouse Enabled?
  214. #--------------------------------------------------------------------------
  215. def enabled?
  216. @enabled
  217. end
  218. #--------------------------------------------------------------------------
  219. # * Ignore Mouse
  220. #--------------------------------------------------------------------------
  221. def ignored=(value)
  222. @ignored = value
  223. end
  224. #--------------------------------------------------------------------------
  225. # * Mouse Ignored?
  226. #--------------------------------------------------------------------------
  227. def ignored?
  228. @ignored
  229. end
  230. end
  231.  
  232. $mouse = Sprite_Mouse.new
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239. #============================================================================
  240. # SUPER SIMPLE MOUSE SCRIPT
  241. # Mouse Module
  242. #============================================================================
  243.  
  244.  
  245. #==============================================================================
  246. # ** Mouse Module
  247. #------------------------------------------------------------------------------
  248. # by Near Fantastica and SephirothSpawn
  249. # adapted and converted to VX Ace by Shaz
  250. #==============================================================================
  251. module Mouse
  252. #--------------------------------------------------------------------------
  253. # * Mouse to Input Triggers
  254. # key => Input::KeyCONSTANT (key: 0 - left, 1 - middle, 2 - right)
  255. #--------------------------------------------------------------------------
  256. Mouse_to_Input_Triggers = {0 => Input::C, 1 => Input::B, 2 => Input::A}
  257. #--------------------------------------------------------------------------
  258. # * API Declarations
  259. #--------------------------------------------------------------------------
  260. GAKS = Win32API.new('user32', 'GetAsyncKeyState', 'i', 'i')
  261. GSM = Win32API.new('user32', 'GetSystemMetrics', 'i', 'i')
  262. Cursor_Pos = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
  263. Scr2cli = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')
  264. Client_rect = Win32API.new('user32', 'GetClientRect', %w(l p), 'i')
  265. Findwindow = Win32API.new('user32', 'FindWindowA', %w(p p), 'l')
  266. Readini = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')
  267. ShowCursor = Win32API.new('user32', 'ShowCursor', 'i', 'l')
  268. #--------------------------------------------------------------------------
  269. # * Module Variables
  270. #--------------------------------------------------------------------------
  271. @triggers = [[0, 1], [0, 2], [0, 4]]
  272. @old_pos = 0
  273. @pos_i = 0
  274. @sys_cursor_visible = false
  275. #--------------------------------------------------------------------------
  276. # * Mouse Grid Position
  277. #--------------------------------------------------------------------------
  278. def self.grid
  279. return nil if @pos.nil?
  280. mx, my = SceneManager.scene.instance_variable_get(:@spriteset).tilemap_offset
  281. x = (@pos[0] + mx) / 32
  282. y = (@pos[1] + my) / 32
  283. return [x, y]
  284. end
  285. #--------------------------------------------------------------------------
  286. # * Mouse Position
  287. #--------------------------------------------------------------------------
  288. def self.position
  289. return @pos.nil? ? [0, 0] : @pos
  290. end
  291. #--------------------------------------------------------------------------
  292. # * Mouse Global Position
  293. #--------------------------------------------------------------------------
  294. def self.global_pos
  295. pos = [0, 0].pack('ll')
  296. return Cursor_Pos.call(pos) == 0 ? nil : pos.unpack('ll')
  297. end
  298. #--------------------------------------------------------------------------
  299. # * Screen to Client
  300. #--------------------------------------------------------------------------
  301. def self.screen_to_client(x=0, y=0)
  302. pos = [x, y].pack('ll')
  303. return Scr2cli.call(self.hwnd, pos) == 0 ? nil : pos.unpack('ll')
  304. end
  305. #--------------------------------------------------------------------------
  306. # * Mouse Position
  307. #--------------------------------------------------------------------------
  308. def self.pos
  309. gx, gy = global_pos
  310. x, y = screen_to_client(gx, gy)
  311.  
  312. # Test boundaries
  313. begin
  314. if (x >= 0 && y >= 0 && x <= Graphics.width && y <= Graphics.height)
  315. return x, y
  316. else
  317. return -20, -20
  318. end
  319. rescue
  320. return 0, 0
  321. end
  322. end
  323. #--------------------------------------------------------------------------
  324. # * Update Mouse Position
  325. #--------------------------------------------------------------------------
  326. def self.update
  327. old_pos = @pos
  328. @pos = self.pos
  329.  
  330. # Has mouse been moved?
  331. if old_pos != @pos
  332. Input.method = :mouse
  333. end
  334.  
  335. # Which mouse to show - custom, or system?
  336. if $mouse.enabled? == @sys_cursor_visible
  337. @sys_cursor_visible = !@sys_cursor_visible
  338. ShowCursor.call(@sys_cursor_visible ? 1 : 0)
  339. end
  340.  
  341. return if !$mouse.enabled?
  342.  
  343. # Leaving / Entering Range?
  344. if old_pos != [-20, -20] && @pos == [-20, -20] # leaving range
  345. ShowCursor.call(1)
  346. elsif old_pos == [-20, -20] && @pos != [-20, -20] # entering range
  347. ShowCursor.call(0)
  348. end
  349.  
  350. # Update Triggers
  351. for i in @triggers
  352. n = GAKS.call(i[1])
  353. if [0, 1].include?(n)
  354. i[0] = (i[0] > 0 ? i[0] * -1 : 0)
  355. else
  356. i[0] = (i[0] > 0 ? i[0] + 1 : 1)
  357. end
  358. end
  359. end
  360. #--------------------------------------------------------------------------
  361. # * Trigger?
  362. # id : 0:Left, 1:Right, 2:Center
  363. #--------------------------------------------------------------------------
  364. def self.trigger?(id = 0)
  365. if pos != [-20, -20]
  366. return @triggers[id][0] == 1
  367. end
  368. return false
  369. end
  370. #--------------------------------------------------------------------------
  371. # * Repeat?
  372. # id : 0:Left, 1:Right, 2:Center
  373. #--------------------------------------------------------------------------
  374. def self.repeat?(id = 0)
  375. return @triggers[id][0] > 0 && @triggers[id][0] % 5 == 1
  376. end
  377. #--------------------------------------------------------------------------
  378. # * Hwnd
  379. #--------------------------------------------------------------------------
  380. def self.hwnd
  381. if @hwnd.nil?
  382. title = "\0" * 256
  383. Readini.call('Game', 'Title', '', title, 255, '.\\Game.ini')
  384. title.delete!("\0")
  385. @hwnd = Findwindow.call('RGSS Player', title)
  386. ShowCursor.call(0)
  387. end
  388. return @hwnd
  389. end
  390. #--------------------------------------------------------------------------
  391. # * Client Size
  392. #--------------------------------------------------------------------------
  393. def self.client_size
  394. rect = [0, 0, 0, 0].pack('l4')
  395. Client_rect.call(self.hwnd, rect)
  396. return rect.unpack('l4')[2..3]
  397. end
  398. end
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405. #============================================================================
  406. # SUPER SIMPLE MOUSE SCRIPT
  407. # Input
  408. #============================================================================
  409.  
  410.  
  411. class << Input
  412. #--------------------------------------------------------------------------
  413. # * Public Instance Variables
  414. #--------------------------------------------------------------------------
  415. attr_accessor :method
  416. #--------------------------------------------------------------------------
  417. # * Alias Listings
  418. #--------------------------------------------------------------------------
  419. alias :seph_mouse_input_update :update
  420. alias :seph_mouse_input_trigger? :trigger?
  421. alias :seph_mouse_input_repeat? :repeat?
  422. #--------------------------------------------------------------------------
  423. # * Frame Update
  424. #--------------------------------------------------------------------------
  425. def update
  426. $mouse.update
  427. Mouse.update
  428. seph_mouse_input_update
  429. # Are we using the mouse or the keyboard?
  430. @method = :keyboard if dir4 != 0 || dir8 != 0
  431. end
  432. #--------------------------------------------------------------------------
  433. # * Trigger? Test
  434. #--------------------------------------------------------------------------
  435. def trigger?(constant)
  436. return true if seph_mouse_input_trigger?(constant)
  437. if $mouse.enabled? && !Mouse.pos.nil?
  438. if Mouse::Mouse_to_Input_Triggers.has_value?(constant)
  439. return true if Mouse.trigger?(Mouse::Mouse_to_Input_Triggers.index(constant))
  440. end
  441. end
  442. return false
  443. end
  444. #--------------------------------------------------------------------------
  445. # * Repeat? Test
  446. #--------------------------------------------------------------------------
  447. def repeat?(constant)
  448. return true if seph_mouse_input_repeat?(constant)
  449. if $mouse.enabled? && !Mouse.pos.nil?
  450. if Mouse::Mouse_to_Input_Triggers.has_value?(constant)
  451. return true if Mouse.repeat?(Mouse::Mouse_to_Input_Triggers.index(constant))
  452. end
  453. end
  454. return false
  455. end
  456. end
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463. #============================================================================
  464. # SUPER SIMPLE MOUSE SCRIPT
  465. # Map
  466. #============================================================================
  467.  
  468.  
  469. class Spriteset_Map
  470. #--------------------------------------------------------------------------
  471. # * Tilemap Offset
  472. #--------------------------------------------------------------------------
  473. def tilemap_offset
  474. if $imported && $imported["YEA-CoreEngine"]
  475. [@tilemap.ox - @viewport1.rect.x, @tilemap.oy - @viewport1.rect.y]
  476. else
  477. [@tilemap.ox, @tilemap.oy]
  478. end
  479. end
  480. end
  481.  
  482. class Game_Map
  483. #--------------------------------------------------------------------------
  484. # * Detect/Set Up Starting Map Event
  485. #--------------------------------------------------------------------------
  486. def setup_starting_map_event
  487. event = @events.values.find {|event| event.starting }
  488. event.clear_starting_flag if event
  489. @interpreter.setup(event.list, event.id, event.trigger_in?([0,1,2,3])) if event
  490. event
  491. end
  492. #--------------------------------------------------------------------------
  493. # * Detect/Set Up Autorun Common Event
  494. #--------------------------------------------------------------------------
  495. def setup_autorun_common_event
  496. event = $data_common_events.find do |event|
  497. event && event.autorun? && $game_switches[event.switch_id]
  498. end
  499. @interpreter.setup(event.list, 0, true) if event
  500. event
  501. end
  502. #--------------------------------------------------------------------------
  503. # * Get ID of Lowest Mouse-enabled Event at Designated Coordinates
  504. #--------------------------------------------------------------------------
  505. def lowest_mouse_event_xy(x, y)
  506. list = events_xy(x, y) + events_xy(x, y+1)
  507. list.sort! {|a, b| b.y - a.y}
  508. evt = nil
  509. list.each do |event|
  510. if (event.pos?(x, y) || (event.pos?(x, y+1) && event.height > 32)) &&
  511. (evt.nil? || event.y > evt.y)
  512. evt = event
  513. break
  514. end
  515. end
  516. return evt
  517. end
  518. end
  519.  
  520. class Scene_Map
  521. #--------------------------------------------------------------------------
  522. # * Frame Update
  523. #--------------------------------------------------------------------------
  524. alias shaz_mouse_scene_map_update update
  525. def update
  526. $mouse.update_event_cursors
  527. shaz_mouse_scene_map_update
  528. end
  529. end
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536. #============================================================================
  537. # SUPER SIMPLE MOUSE SCRIPT
  538. # Event
  539. #============================================================================
  540.  
  541.  
  542. module RPG
  543. class Event
  544. class Page
  545. #--------------------------------------------------------------------
  546. # * Public Instance Variables
  547. #--------------------------------------------------------------------
  548. attr_reader :mouse_icon
  549. attr_reader :mouse_text
  550. attr_reader :mouse_position
  551. attr_reader :mouse_autoactivate
  552. #--------------------------------------------------------------------
  553. # * Build Stats
  554. #--------------------------------------------------------------------
  555. def build_stats
  556. # Mouse icons (icon mandatory, others optional)
  557. # <mouse icon destx desty name>
  558. @mouse_icon = nil
  559. @mouse_text = nil
  560. @mouse_position = [0, 0]
  561. @mouse_autoactivate = false
  562. # look for mouse instructions
  563. list.each do |command|
  564. if [108, 408].include?(command.code)
  565. comment = command.parameters[0]
  566. case comment
  567. when /<mouse/i
  568. params = /<mouse (.*)>/i.match(comment)[1].split(' ')
  569. @mouse_icon = params.shift
  570. if params.size > 1 && params[0] =~ /\d+/ && params[1] =~ /\d+/
  571. @mouse_position = [params.shift.to_i, params.shift.to_i]
  572. end
  573. if params.size > 0
  574. @mouse_text = params.join(' ')
  575. end
  576. when /<autoactivate>/
  577. @mouse_autoactivate = true
  578. end
  579. end #if
  580. end #do
  581. end #def
  582. end
  583. end
  584. end
  585.  
  586. class Game_Event < Game_Character
  587. #--------------------------------------------------------------------------
  588. # * Public Instance Variables
  589. #--------------------------------------------------------------------------
  590. attr_reader :mouse_icon
  591. attr_reader :mouse_text
  592. attr_reader :mouse_position
  593. attr_reader :mouse_autoactivate
  594. #--------------------------------------------------------------------------
  595. # * Start Event
  596. #--------------------------------------------------------------------------
  597. alias shaz_mouse_game_event_start start
  598. def start
  599. $game_player.start_event(@id) if !empty?
  600. shaz_mouse_game_event_start
  601. end
  602. #--------------------------------------------------------------------------
  603. # * Clear Event Page Settings
  604. #--------------------------------------------------------------------------
  605. alias shaz_mouse_game_event_clear_page_settings clear_page_settings
  606. def clear_page_settings
  607. shaz_mouse_game_event_clear_page_settings
  608. @mouse_icon = nil
  609. @mouse_text = nil
  610. @mouse_position = [0, 0]
  611. @mouse_autoactivate = false
  612. @height = 0
  613. end
  614. #--------------------------------------------------------------------------
  615. # * Set Up Event Page Settings
  616. #--------------------------------------------------------------------------
  617. alias shaz_mouse_game_event_setup_page_settings setup_page_settings
  618. def setup_page_settings
  619. shaz_mouse_game_event_setup_page_settings
  620. @page.build_stats
  621. @mouse_icon = @page.mouse_icon
  622. @mouse_text = @page.mouse_text
  623. @mouse_position = @page.mouse_position
  624. @mouse_autoactivate = @page.mouse_autoactivate
  625. set_size
  626. end
  627. end
  628.  
  629.  
  630.  
  631.  
  632.  
  633.  
  634. #============================================================================
  635. # SUPER SIMPLE MOUSE SCRIPT
  636. # Character
  637. #============================================================================
  638.  
  639.  
  640. class Game_CharacterBase
  641. attr_reader :height # Height of character bitmap
  642. #--------------------------------------------------------------------------
  643. # * Initialize Public Member Variables
  644. #--------------------------------------------------------------------------
  645. alias shaz_mouse_game_characterbase_init_public_members init_public_members
  646. def init_public_members
  647. shaz_mouse_game_characterbase_init_public_members
  648. @height = 0
  649. end
  650. #--------------------------------------------------------------------------
  651. # * Change Graphics
  652. # character_name : new character graphic filename
  653. # character_index : new character graphic index
  654. #--------------------------------------------------------------------------
  655. alias shaz_mouse_game_characterbase_set_graphic set_graphic
  656. def set_graphic(character_name, character_index)
  657. shaz_mouse_game_characterbase_set_graphic(character_name, character_index)
  658. set_size
  659. end
  660. #--------------------------------------------------------------------------
  661. # * Set character width/height size
  662. #--------------------------------------------------------------------------
  663. def set_size
  664. bw = Cache.character(@character_name).width
  665. bh = Cache.character(@character_name).height
  666. sign = @character_name[/^[\!\$]./]
  667. if sign && sign.include?('$')
  668. @width = bw / 3
  669. @height = bh / 4
  670. else
  671. @width = bw / 12
  672. @height = bh / 8
  673. end
  674. end
  675. #--------------------------------------------------------------------------
  676. # * Detect Collision with Event
  677. #--------------------------------------------------------------------------
  678. def collide_with_events?(x, y)
  679. $game_map.events_xy_nt(x, y).any? do |event|
  680. self != event && (event.normal_priority? || self.is_a?(Game_Event))
  681. end
  682. end
  683. #--------------------------------------------------------------------------
  684. # * Detect Collision with Vehicle
  685. #--------------------------------------------------------------------------
  686. def collide_with_vehicles?(x, y)
  687. !self.is_a?(Game_Player) && ($game_map.boat.pos_nt?(x, y) || $game_map.ship.pos_nt?(x, y))
  688. end
  689. #--------------------------------------------------------------------------
  690. # * Frame Update
  691. #--------------------------------------------------------------------------
  692. alias shaz_mouse_game_characterbase_update update
  693. def update
  694. run_path if @runpath
  695. shaz_mouse_game_characterbase_update
  696. end
  697. #--------------------------------------------------------------------------
  698. # * Run Path
  699. #--------------------------------------------------------------------------
  700. def run_path
  701. return if moving?
  702. @step = @map.nil? || @map[@x, @y].nil? ? 0 : @map[@x, @y] - 1
  703. if @step < 1
  704. clear_path
  705. else
  706. x, y = @x, @y
  707. dirs = []
  708. dirs.push(6) if @map[@x+1, @y] == @step && passable?(@x, @y, 6)
  709. dirs.push(2) if @map[@x, @y+1] == @step && passable?(@x, @y, 2)
  710. dirs.push(4) if @map[@x-1, @y] == @step && passable?(@x, @y, 4)
  711. dirs.push(8) if @map[@x, @y-1] == @step && passable?(@x, @y, 8)
  712. while dirs.size > 0
  713. dir = dirs.delete_at(rand(dirs.size))
  714. move_straight(dir)
  715. break if x != @x || y != @y
  716. end
  717. # clear the path if we couldn't move
  718. clear_path if x == @x && y == @y
  719. end
  720. end
  721. #--------------------------------------------------------------------------
  722. # * Find Path
  723. #--------------------------------------------------------------------------
  724. def find_path(x, y)
  725. sx, sy = @x, @y
  726. @tx, @ty = x, y
  727. result = setup_map(sx, sy)
  728. @runpath = result[0]
  729. @map = result[1]
  730. @map[sx, sy] = result[2] if result[2] != nil
  731. end
  732. #--------------------------------------------------------------------------
  733. # * Clear Path
  734. #--------------------------------------------------------------------------
  735. def clear_path
  736. @map = nil
  737. @runpath = false
  738. end
  739. #--------------------------------------------------------------------------
  740. # * Setup Map
  741. #--------------------------------------------------------------------------
  742. def setup_map(sx, sy)
  743. map = Table.new($game_map.width, $game_map.height)
  744. update_counter = 0
  745. map[@tx, @ty] = 1
  746. old_positions = [[@tx, @ty]]
  747. new_positions = []
  748.  
  749. # if tile is impassable, but CAN move to adjacent tiles, use the adjacent tiles instead
  750. if (!passable?(@tx, @ty, 2) && !passable?(@tx, @ty, 4) &&
  751. !passable?(@tx, @ty, 6) && !passable?(@tx, @ty, 8)) ||
  752. $game_map.events_xy_nt(@tx, @ty).any? { |evt| evt.normal_priority? && evt != self }
  753. old_positions = []
  754.  
  755. # Can we move from the destination tile in any direction?
  756. if map_passable?(@tx, @ty, 2)
  757. map[@tx, @ty+1] = 1
  758. old_positions.push([@tx, @ty+1])
  759. end
  760. if map_passable?(@tx, @ty, 8)
  761. map[@tx, @ty-1] = 1
  762. old_positions.push([@tx, @ty-1])
  763. end
  764. if map_passable?(@tx, @ty, 4)
  765. map[@tx-1, @ty] = 1
  766. old_positions.push([@tx-1, @ty])
  767. end
  768. if map_passable?(@tx, @ty, 6)
  769. map[@tx+1, @ty] = 1
  770. old_positions.push([@tx+1, @ty])
  771. end
  772.  
  773. # If not, can we at least move up to the destination tile?
  774. if old_positions.size == 0
  775. if map_passable?(@tx-1,@ty,6)
  776. map[@tx-1,@ty] = 1
  777. old_positions.push([@tx-1,@ty])
  778. end
  779. if map_passable?(@tx+1,@ty,4)
  780. map[@tx+1,@ty] = 1
  781. old_positions.push([@tx+1,@ty])
  782. end
  783. if map_passable?(@tx,@ty-1,2)
  784. map[@tx,@ty-1] = 1
  785. old_positions.push([@tx,@ty-1])
  786. end
  787. if map_passable?(@tx,@ty+1,8)
  788. map[@tx,@ty+1] = 1
  789. old_positions.push([@tx,@ty+1])
  790. end
  791. end
  792. end
  793.  
  794. # If there are any counters, can we move to the tile on the other side?
  795. if map_passable?(@tx-2,@ty,6) && $game_map.counter?(@tx-1,@ty)
  796. map[@tx-2,@ty] = 1
  797. old_positions.push([@tx-2,@ty])
  798. end
  799. if map_passable?(@tx+2,@ty,4) && $game_map.counter?(@tx+1,@ty)
  800. map[@tx+2,@ty] = 1
  801. old_positions.push([@tx+2,@ty])
  802. end
  803. if map_passable?(@tx,@ty-2,2) && $game_map.counter?(@tx,@ty-1)
  804. map[@tx,@ty-2] = 1
  805. old_positions.push([@tx,@ty-2])
  806. end
  807. if map_passable?(@tx,@ty+2,2) && $game_map.counter?(@tx,@ty+1)
  808. map[@tx,@ty+2] = 1
  809. old_positions.push([@tx,@ty+2])
  810. end
  811.  
  812.  
  813. depth = 2
  814. depth.upto(100) { |step|
  815. break if old_positions[0].nil?
  816. @step = step
  817. loop do
  818. break if old_positions[0].nil?
  819. x, y = old_positions.shift
  820. return [true, map, @step-1] if x == sx && y == sy
  821. if map[x, y + 1] == 0 && passable?(x, y, 2)
  822. map[x, y + 1] = @step
  823. new_positions.push([x, y + 1])
  824. end
  825. if map[x - 1, y] == 0 && passable?(x, y, 4)
  826. map[x - 1, y] = @step
  827. new_positions.push([x - 1, y])
  828. end
  829. if map[x + 1, y] == 0 && passable?(x, y, 6)
  830. map[x + 1, y] = @step
  831. new_positions.push([x + 1, y])
  832. end
  833. if map[x, y - 1] == 0 && passable?(x, y, 8)
  834. map[x, y - 1] = @step
  835. new_positions.push([x, y - 1])
  836. end
  837. # Update graphics? (to reduce lag)
  838. update_counter += 1
  839. if update_counter > 50
  840. Graphics.update
  841. update_counter = 0
  842. end
  843. end
  844. old_positions = new_positions
  845. new_positions = []
  846. }
  847. return [false, nil, nil]
  848. end
  849. end
  850.  
  851. class Game_Character < Game_CharacterBase
  852. #--------------------------------------------------------------------------
  853. # * Force Move Route
  854. #--------------------------------------------------------------------------
  855. alias shaz_mouse_game_character_force_move_route force_move_route
  856. def force_move_route(move_route)
  857. clear_path
  858. shaz_mouse_game_character_force_move_route(move_route)
  859. end
  860. end
  861.  
  862.  
  863.  
  864.  
  865.  
  866.  
  867. #============================================================================
  868. # SUPER SIMPLE MOUSE SCRIPT
  869. # Player
  870. #============================================================================
  871.  
  872.  
  873. class Game_Player < Game_Character
  874. #--------------------------------------------------------------------------
  875. # * Trigger Map Event
  876. # triggers : Trigger array
  877. # normal : Is priority set to [Same as Characters] ?
  878. #--------------------------------------------------------------------------
  879. alias shaz_mouse_game_player_start_map_event start_map_event
  880. def start_map_event(x, y, triggers, normal)
  881. @started_events = []
  882. shaz_mouse_game_player_start_map_event(x, y, triggers, normal)
  883. end
  884. #--------------------------------------------------------------------------
  885. # * Start Event
  886. #--------------------------------------------------------------------------
  887. def start_event(event_id)
  888. @started_events = [] if @started_events.nil?
  889. @started_events.push(event_id)
  890. end
  891. #--------------------------------------------------------------------------
  892. # * Processing of Movement via Input from Directional Buttons
  893. #--------------------------------------------------------------------------
  894. alias shaz_mouse_game_player_move_by_input move_by_input
  895. def move_by_input
  896. if Input.dir4 > 0
  897. clear_path
  898. shaz_mouse_game_player_move_by_input
  899. else
  900. # Move by mouse input
  901. if !$game_message.busy? && !$game_message.visible && !@move_route_forcing &&
  902. !@vehicle_getting_on && !@vehicle_getting_off &&
  903. Mouse.trigger?(0) && !Mouse.grid.nil? && !$mouse.ignored?
  904. mx, my = *Mouse.grid
  905. # turn in direction
  906. if (@x - mx).abs >= (@y - my).abs
  907. set_direction(@x > mx ? 4 : 6)
  908. else
  909. set_direction(@y > my ? 8 : 2)
  910. end
  911. # find path
  912. @event = $game_map.lowest_mouse_event_xy(mx, my)
  913. if @event.nil?
  914. find_path(mx, my)
  915. elsif @event.mouse_autoactivate
  916. @event.start
  917. @started_events = []
  918. clear_path
  919. else
  920. find_path(@event.x + @event.mouse_position[0],
  921. @event.y + @event.mouse_position[1])
  922. end
  923. end
  924. end
  925. end
  926. #--------------------------------------------------------------------------
  927. # * Frame Update
  928. #--------------------------------------------------------------------------
  929. alias shaz_mouse_game_player_update update
  930. def update
  931. shaz_mouse_game_player_update
  932. update_pathfinding if !@event.nil? && !moving?
  933. end
  934. #--------------------------------------------------------------------------
  935. # * Check event after pathfinding
  936. #--------------------------------------------------------------------------
  937. def update_pathfinding
  938. if @map.nil? || @map[@x, @y] <= 1
  939. dir = @x < @event.x ? 6 : @x > @event.x ? 4 : @y < @event.y ? 2 : @y > @event.y ? 8 : 0
  940. # Face event and trigger it (only if not triggered by start_map_event)
  941. turn_toward_character(@event) if !@event.pos?(@x, @y)
  942. if !@started_events.include?(@event.id) && !@map.nil? && !in_airship?
  943. @event.start
  944. @started_events = []
  945. end
  946. clear_path
  947. end
  948. end
  949. #--------------------------------------------------------------------------
  950. # * Clear Path
  951. #--------------------------------------------------------------------------
  952. def clear_path
  953. @event = nil
  954. super
  955. end
  956. end
  957.  
  958.  
  959.  
  960.  
  961.  
  962.  
  963. #============================================================================
  964. # SUPER SIMPLE MOUSE SCRIPT
  965. # Interpreter
  966. #============================================================================
  967.  
  968.  
  969. class Game_Interpreter
  970. #--------------------------------------------------------------------------
  971. # * Event Setup
  972. #--------------------------------------------------------------------------
  973. alias shaz_mouse_game_interpreter_setup setup
  974. def setup(list, event_id = 0, lock_player = false)
  975. shaz_mouse_game_interpreter_setup(list, event_id)
  976. @lock_player = lock_player
  977. end
  978. #--------------------------------------------------------------------------
  979. # * Execute
  980. #--------------------------------------------------------------------------
  981. alias shaz_mouse_game_interpreter_run run
  982. def run
  983. $mouse.ignored = true if @lock_player
  984. shaz_mouse_game_interpreter_run
  985. $mouse.ignored = false if @lock_player
  986. end
  987. end
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994. #============================================================================
  995. # SUPER SIMPLE MOUSE SCRIPT
  996. # Windows
  997. #============================================================================
  998.  
  999.  
  1000. class Window_Selectable < Window_Base
  1001. #--------------------------------------------------------------------------
  1002. # * Frame Update
  1003. #--------------------------------------------------------------------------
  1004. alias shaz_mouse_window_selectable_update update
  1005. def update
  1006. shaz_mouse_window_selectable_update
  1007. process_mouse_handling if Input.method == :mouse
  1008. end
  1009. #--------------------------------------------------------------------------
  1010. # * Mouse Movement Processing
  1011. #--------------------------------------------------------------------------
  1012. def process_mouse_handling
  1013. return unless $mouse.enabled? && cursor_movable?
  1014. # Add a delay to prevent too-fast scrolling
  1015. @delay = @delay ? @delay + 1 : 0
  1016. return if @delay % 3 > 0
  1017.  
  1018. mx, my = *Mouse.position
  1019. vx = self.viewport ? self.x - self.viewport.ox + self.viewport.rect.x : self.x
  1020. vy = self.viewport ? self.y - self.viewport.oy + self.viewport.rect.y : self.y
  1021. if mx.between?(vx, vx + self.width) &&
  1022. my.between?(vy, vy + self.height)
  1023. mx -= vx
  1024. mx -= padding
  1025. my -= vy
  1026. my -= padding
  1027. my += oy
  1028. for i in 0 ... item_max
  1029. rect = item_rect(i)
  1030. if mx.between?(rect.x, rect.x + rect.width) &&
  1031. my.between?(rect.y, rect.y + rect.height)
  1032. last_index = @index
  1033. select(i)
  1034. if @index != last_index
  1035. Sound.play_cursor
  1036. end
  1037. break
  1038. end
  1039. end
  1040. end
  1041. end
  1042. end
  1043.  
  1044. class Window_NameInput < Window_Selectable
  1045. #--------------------------------------------------------------------------
  1046. # * Mouse Movement Processing
  1047. #--------------------------------------------------------------------------
  1048. def process_mouse_handling
  1049. return unless $mouse.enabled?
  1050. # Add a delay to prevent too-fast scrolling
  1051. @delay = @delay ? @delay + 1 : 0
  1052. return if @delay % 3 > 0
  1053.  
  1054. mx, my = *Mouse.position
  1055. vx = (self.viewport ? self.x - self.viewport.ox + self.viewport.rect.x : self.x) + padding
  1056. vy = (self.viewport ? self.y - self.viewport.oy + self.viewport.rect.y : self.y) + padding
  1057. if mx.between?(vx, vx + self.width - padding * 2) &&
  1058. my.between?(vy, vy + self.height - padding * 2)
  1059. mx -= vx
  1060. my -= vy
  1061. x = (mx > 5*32+16 ? mx-16 : mx) / 32
  1062. y = my / line_height
  1063. last_index = @index
  1064. @index = y * 10 + x
  1065. Sound.play_cursor if @index != last_index
  1066. end
  1067. end
  1068. end
  1069.  
  1070. class Scene_File < Scene_MenuBase
  1071. #--------------------------------------------------------------------------
  1072. # * Update Cursor
  1073. #--------------------------------------------------------------------------
  1074. alias shaz_mouse_scene_file_update_cursor update_cursor
  1075. def update_cursor
  1076. shaz_mouse_scene_file_update_cursor
  1077. process_mouse_handling if Input.method == :mouse
  1078. end
  1079. #--------------------------------------------------------------------------
  1080. # * Mouse Movement Processing
  1081. #--------------------------------------------------------------------------
  1082. def process_mouse_handling
  1083. return unless $mouse.enabled?
  1084. # Add a delay to prevent too-fast scrolling
  1085. @delay = @delay ? @delay + 1 : 0
  1086. return if @delay % 3 > 0
  1087.  
  1088. mx, my = *Mouse.position
  1089. vx = @savefile_viewport.ox + mx
  1090. vy = @savefile_viewport.oy + my
  1091. last_index = @index
  1092. new_index = vy / savefile_height
  1093. if @index != new_index
  1094. if new_index > @index
  1095. cursor_down(false)
  1096. else
  1097. cursor_up(false)
  1098. end
  1099. Sound.play_cursor
  1100. @savefile_windows[last_index].selected = false
  1101. @savefile_windows[@index].selected = true
  1102. end
  1103. end
  1104. end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×