Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #==============================================================================
  2. # ** TDS Quick Travel
  3. #    Ver: 1.4
  4. #------------------------------------------------------------------------------
  5. #  * Description:
  6. #  This script allows you to quickly travel to pre determined locations on a
  7. #  map.
  8. #------------------------------------------------------------------------------
  9. #  * Features:
  10. #  Quickly change locations on a map.
  11. #------------------------------------------------------------------------------
  12. #  * Instructions:
  13. #
  14. #  To add a quick travel location to a map use this in a script call:
  15. #
  16. #  add_map_quick_travel(id, name, map, map_id, x, y, dir)
  17. #
  18. #   id     = ID of the quick travel point. (It's order in the list)
  19. #   name   = name of the quick travel location.
  20. #   map    = map id to add quick travel location to.
  21. #   map_id = map ID to quick travel to.
  22. #   x      = X coordinate of the quick travel location on the map
  23. #   y      = Y coordinate of the quick travel location on the map
  24. #   dir    = facing direction after quick traveling (2: Down , 4: Left, 6: Right, 8: Up)  
  25. #
  26. #  To disable quick travel use this on a script call:
  27. #
  28. #    disable_map_quick_travel
  29. #  
  30. #  To enable quick travel use this on a script call:
  31. #
  32. #    disable_map_quick_travel
  33. #
  34. #  To call the quick travel selection menu press the "X" (A) key.
  35. #
  36. #  To call the quick travel menu from an event, use this on a script call:
  37. #
  38. #    call_map_quick_travel_menu
  39. #
  40. #------------------------------------------------------------------------------
  41. #  * Notes:
  42. #  None.
  43. #------------------------------------------------------------------------------
  44. # WARNING:
  45. #
  46. # Do not release, distribute or change my work without my expressed written
  47. # consent, doing so violates the terms of use of this work.
  48. #
  49. # If you really want to share my work please just post a link to the original
  50. # site.
  51. #
  52. # * Not Knowing English or understanding these terms will not excuse you in any
  53. #   way from the consequenses.
  54. #==============================================================================
  55. # * Import to Global Hash *
  56. #==============================================================================
  57. ($imported ||= {})[:TDS_Quick_Travel] = true
  58.  
  59. #==============================================================================
  60. # ** Game_System
  61. #------------------------------------------------------------------------------
  62. #  This class handles system-related data. Also manages vehicles and BGM, etc.
  63. # The instance of this class is referenced by $game_system.
  64. #==============================================================================
  65.  
  66. class Game_System
  67.   #--------------------------------------------------------------------------
  68.   # * Public Instance Variables
  69.   #--------------------------------------------------------------------------
  70.   attr_accessor :map_quick_travel
  71.   attr_accessor :disable_quick_travel
  72.   #--------------------------------------------------------------------------
  73.   # * Alias Listings
  74.   #--------------------------------------------------------------------------
  75.   alias tds_quick_travel_game_system_initialize                    initialize  
  76.   #--------------------------------------------------------------------------
  77.   # * Object Initialization
  78.   #--------------------------------------------------------------------------
  79.   def initialize
  80.     # Run Original Method
  81.     tds_quick_travel_game_system_initialize    
  82.     # Initialize Quick Travel Values
  83.     init_quick_travel        
  84.   end
  85.   #--------------------------------------------------------------------------
  86.   # * Initialize Map Quick Travel
  87.   #--------------------------------------------------------------------------
  88.   def init_quick_travel  
  89.     # Disable Quick Travel Flag
  90.     @disable_quick_travel = false
  91.     # Make Map Quick Travel Hash
  92.     @map_quick_travel = {}
  93.   end  
  94.   #--------------------------------------------------------------------------
  95.   # * Determine if Map Quick Travel is possible
  96.   #--------------------------------------------------------------------------
  97.   def can_quick_travel?
  98.     # Return false if map quick travel is disabled
  99.     return false if @disable_quick_travel
  100.     # Return false if Map has no quick travel points
  101.     return false if !has_quick_travel?
  102.     # Return true by default
  103.     return true
  104.   end
  105.   #--------------------------------------------------------------------------
  106.   # * Determine if Map has Quick Travel points
  107.   #--------------------------------------------------------------------------
  108.   def has_quick_travel?
  109.     # Return false if Map Quick Travel List is nil or empty
  110.     return false if @map_quick_travel[$game_map.map_id].nil?
  111.     # Return true by default
  112.     return true
  113.   end  
  114.   #--------------------------------------------------------------------------
  115.   # * Get Quick Travel Map List
  116.   #--------------------------------------------------------------------------
  117.   def quick_travel_map_list
  118.     # Get Map Quick Travel Points
  119.     return @map_quick_travel[$game_map.map_id].keys.sort.collect {|id| @map_quick_travel[$game_map.map_id][id]}
  120.   end
  121. end
  122.  
  123.  
  124. #==============================================================================
  125. # ** Game_Interpreter
  126. #------------------------------------------------------------------------------
  127. #  An interpreter for executing event commands. This class is used within the
  128. # Game_Map, Game_Troop, and Game_Event classes.
  129. #==============================================================================
  130.  
  131. class Game_Interpreter
  132.   #--------------------------------------------------------------------------
  133.   # * Constants (Structs)
  134.   #--------------------------------------------------------------------------
  135.   # Battle Action Base
  136.   Quick_Travel_Settings = Struct.new(:name, :map_id, :x, :y, :direction)        
  137.   #--------------------------------------------------------------------------
  138.   # * Enable or Disable Map Quick Travel
  139.   #--------------------------------------------------------------------------
  140.   def enable_map_quick_travel  ; $game_system.disable_quick_travel = false end  
  141.   def disable_map_quick_travel ; $game_system.disable_quick_travel = true end
  142.   #--------------------------------------------------------------------------
  143.   # * Call Map Quick Travel Menu
  144.   #--------------------------------------------------------------------------
  145.   def call_map_quick_travel_menu
  146.     # If on Scene Map and there are quick travel points
  147.     if SceneManager.scene_is?(Scene_Map) and $game_system.has_quick_travel?
  148.       # Call Quick Travel Menu Process
  149.       SceneManager.scene.start_quick_travel_selection
  150.     end
  151.   end      
  152.   #--------------------------------------------------------------------------
  153.   # * Add Map Quick Travel
  154.   #--------------------------------------------------------------------------
  155.   def add_map_quick_travel(id, name, map, map_id, x, y, dir = 2)
  156.     # Make Empty hash if necessary
  157.     $game_system.map_quick_travel[map] ||= {}
  158.     # Set Map Quick Travel Point
  159.     $game_system.map_quick_travel[map][id] = Quick_Travel_Settings.new(name, map_id, x, y, dir)
  160.   end  
  161.   #--------------------------------------------------------------------------
  162.   # * Remove Map Quick Travel
  163.   #--------------------------------------------------------------------------
  164.   def remove_map_quick_travel(map_id, id)
  165.     # Return if there are quick travel points in the map
  166.     return if $game_system.map_quick_travel[map_id].nil?
  167.     # Delete Map Quick Travel Point
  168.     $game_system.map_quick_travel[map_id].delete(id)
  169.   end
  170. end
  171.  
  172.  
  173. #==============================================================================
  174. # ** Scene_Map
  175. #------------------------------------------------------------------------------
  176. #  This class performs the map screen processing.
  177. #==============================================================================
  178.  
  179. class Scene_Map < Scene_Base
  180.   #--------------------------------------------------------------------------
  181.   # * Alias Listings
  182.   #--------------------------------------------------------------------------
  183.   alias tds_quick_travel_scene_map_update                              update
  184.   #--------------------------------------------------------------------------
  185.   # * Frame Update
  186.   #--------------------------------------------------------------------------
  187.   def update
  188.     # Update Quick Travel Input
  189.     update_quick_travel_input  
  190.     # Run Original Method
  191.     tds_quick_travel_scene_map_update
  192.   end
  193.   #--------------------------------------------------------------------------
  194.   # * Start Quick Travel SElection
  195.   #--------------------------------------------------------------------------
  196.   def start_quick_travel_selection
  197.     # Make Scene Cover Sprite
  198.     @scene_cover = Sprite.new
  199.     @scene_cover.bitmap = Graphics.snap_to_bitmap
  200.     @scene_cover.bitmap.blur      
  201.     @scene_cover.opacity = 0      
  202.     @scene_cover.tone.set(-30, -30, -30)
  203.     @scene_cover.z = 5000
  204.     # Make Quick Travel Window
  205.     @quick_travel_list_window = Window_Quick_Travel_List.new
  206.     @quick_travel_list_window.x = (Graphics.width - @quick_travel_list_window.width) / 2
  207.     @quick_travel_list_window.y = (Graphics.height - @quick_travel_list_window.height) / 2      
  208.     @quick_travel_list_window.z = 5100
  209.     @quick_travel_list_window.openness = 0
  210.     @quick_travel_list_window.open.activate.select(0)
  211.     # Set Quick Travel Window Handlers
  212.     @quick_travel_list_window.set_handler(:ok,     method(:on_quick_travel_selection_ok))
  213.     @quick_travel_list_window.set_handler(:cancel, method(:on_quick_travel_selection_cancel))
  214.     # Fade In Scene Cover
  215.     15.times { Graphics.update ; @scene_cover.opacity += 17}
  216.     # Quick Travel Selection Update Loop
  217.     loop {
  218.       # Update Graphics, Input and Quick Travel Window
  219.       Graphics.update ; Input.update ; @quick_travel_list_window.update
  220.       # Break if Quick Travelis nil
  221.       break if @quick_travel_list_window.nil?
  222.     }
  223.   end
  224.   #--------------------------------------------------------------------------
  225.   # * [OK] Quick Travel Selection
  226.   #--------------------------------------------------------------------------
  227.   def on_quick_travel_selection_ok
  228.     # Get Transfer Information
  229.     transfer = @quick_travel_list_window.selected_transfer
  230.     # Deactivate and Close Quick Travel List window
  231.     @quick_travel_list_window.deactivate ; @quick_travel_list_window.close
  232.     # Update Graphics and Fadeout Scene Cover
  233.     10.times { Graphics.update ; @scene_cover.opacity -= 17 ; @quick_travel_list_window.update }
  234.     # Dispose of Scene Cover
  235.     @scene_cover.bitmap.dispose ; @scene_cover.dispose ; @scene_cover = nil
  236.     # Dispose of Quick Travel List Window
  237.     @quick_travel_list_window.dispose ; @quick_travel_list_window = nil
  238.     # Start Transfer
  239.     $game_player.reserve_transfer(transfer.map_id, transfer.x, transfer.y, transfer.direction)
  240.     $game_temp.fade_type = 0
  241.     # Update Input
  242.     Input.update
  243.   end
  244.   #--------------------------------------------------------------------------
  245.   # * [Cancel] Quick Travel Selection
  246.   #--------------------------------------------------------------------------
  247.   def on_quick_travel_selection_cancel
  248.     # Deactivate and Close Quick Travel List window
  249.     @quick_travel_list_window.deactivate ; @quick_travel_list_window.close
  250.     # Update Graphics and Fadeout Scene Cover
  251.     10.times { Graphics.update ; @scene_cover.opacity -= 17 ; @quick_travel_list_window.update }
  252.     # Dispose of Scene Cover
  253.     @scene_cover.bitmap.dispose ; @scene_cover.dispose ; @scene_cover = nil
  254.     # Dispose of Quick Travel List Window
  255.     @quick_travel_list_window.dispose ; @quick_travel_list_window = nil
  256.     # Update Input
  257.     Input.update
  258.   end
  259.   #--------------------------------------------------------------------------
  260.   # * Update Quick Travel Input
  261.   #--------------------------------------------------------------------------
  262.   def update_quick_travel_input
  263.     # Return if Interpreter is running or messages
  264.     return if !$game_system.can_quick_travel? or $game_map.interpreter.running? or ($game_message.busy? or $game_message.visible)    
  265.     # If Input Trigger A
  266.     if Input.trigger?(:X)
  267.       # Play Ok Sound
  268.       Sound.play_ok
  269.       # Start Quick Travel Selection
  270.       start_quick_travel_selection
  271.     end
  272.   end
  273. end
  274.  
  275.  
  276. #==============================================================================
  277. # ** Window_Quick_Travel_List
  278. #------------------------------------------------------------------------------
  279. #  This window handles Quick Travel List selection.
  280. #==============================================================================
  281.  
  282. class Window_Quick_Travel_List < Window_Selectable
  283.   #--------------------------------------------------------------------------
  284.   # * Public Instance Variables
  285.   #--------------------------------------------------------------------------
  286.   attr_reader :quick_travel_list  
  287.   #--------------------------------------------------------------------------
  288.   # * Object Initialization
  289.   #--------------------------------------------------------------------------
  290.   def initialize
  291.     # Get Quick Travel List
  292.     @quick_travel_list =  $game_system.quick_travel_map_list      
  293.     # Get Max Text Width of Commands
  294.     @max_text_width = max_text_width
  295.     # Create Window Contents
  296.     super(0, 0, window_width, window_height)
  297.     # Draw Window Contents
  298.     refresh
  299.   end
  300.   #--------------------------------------------------------------------------
  301.   # * Get Selected Transfer Information
  302.   #--------------------------------------------------------------------------
  303.   def selected_transfer ; @quick_travel_list[@index] end  
  304.   #--------------------------------------------------------------------------
  305.   # * Window Width and Height
  306.   #--------------------------------------------------------------------------
  307.   def window_width  ; [12 + max_text_width + (standard_padding * 2), Graphics.width].min end
  308.   def window_height ; fitting_height(visible_line_number) end
  309.   #--------------------------------------------------------------------------
  310.   # * Max Columns
  311.   #--------------------------------------------------------------------------
  312.   def col_max ; 1 end
  313.   #--------------------------------------------------------------------------
  314.   # * Get Number of Items
  315.   #--------------------------------------------------------------------------
  316.   def item_max ; @quick_travel_list.size end
  317.   #--------------------------------------------------------------------------
  318.   # * Get Number of Lines to Show
  319.   #--------------------------------------------------------------------------
  320.   def visible_line_number ; [[item_max + 1, 16].min, 2].max end
  321.   #--------------------------------------------------------------------------
  322.   # * Get Number of Rows Displayable on 1 Page
  323.   #--------------------------------------------------------------------------
  324.   def page_row_max ; super - 1 end
  325.   #--------------------------------------------------------------------------
  326.   # * Get Row Count
  327.   #--------------------------------------------------------------------------
  328.   def row_max ; super + 1 end
  329.   #--------------------------------------------------------------------------
  330.   # * Item Rect
  331.   #--------------------------------------------------------------------------
  332.   def item_rect(index) ; rect = super ; rect.y += line_height ; rect end  
  333.   #--------------------------------------------------------------------------
  334.   # * Find Max Text Width
  335.   #--------------------------------------------------------------------------
  336.   def max_text_width
  337.     # Create Temporary Contents
  338.     contents = Bitmap.new(1, 1)
  339.     contents.font.size = Font.default_size
  340.     contents.font.bold = Font.default_bold
  341.     contents.font.italic = Font.default_italic    
  342.     # Get Starting Width
  343.     width = 0
  344.     # Go Through Quick Travel List
  345.     @quick_travel_list.each {|t|
  346.     # Set Max Width
  347.     w = contents.text_size(t.name).width ; width += w if w > width
  348.     }
  349.     # Dispose of Contents
  350.     contents.dispose ; contents = nil
  351.     # Return Max Text Width
  352.     return [width, 230].max
  353.   end
  354.   #--------------------------------------------------------------------------
  355.   # * Refresh
  356.   #--------------------------------------------------------------------------
  357.   def refresh
  358.     super
  359.     contents.font.color = system_color
  360.     # Draw Quick Travel Header
  361.     draw_text(0, 0, contents_width, line_height, "Tuỳ Chọn Dịch Chuyển", 1)
  362.   end
  363.   #--------------------------------------------------------------------------
  364.   # * Draw Item
  365.   #--------------------------------------------------------------------------
  366.   def draw_item(index)
  367.     # Draw Quick Travel Point Name
  368.     draw_text(item_rect_for_text(index), @quick_travel_list.at(index).name)
  369.   end
  370. end