Advertisement
Scinaya

Variable Map Window by Shanghai

Apr 28th, 2011
794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.23 KB | None | 0 0
  1. #===============================================================================
  2. #
  3. # Shanghai Simple Script - Variable Map Window
  4. # Last Date Updated: 2010.05.17
  5. # Level: Normal
  6. #
  7. # This script allows for multiple variables and automatically updates itself
  8. # when the variables themselves change.
  9. #===============================================================================
  10. # Instructions
  11. # -----------------------------------------------------------------------------
  12. # To install this script, open up your script editor and copy/paste this script
  13. # to an open slot below ▼ Materials but above ▼ Main. Remember to save.
  14. #
  15. # To use this variable window, use these event calls. Works on map only.
  16. #
  17. # variable_window_clear
  18. # - Clears all of the variable window and closes it.
  19. #
  20. # variable_window_open
  21. # - Opens the variable window, but only if it has variables.
  22. #
  23. # variable_window_close
  24. # - Closes the variable window.
  25. #
  26. # variable_window_add(variable_id)
  27. # - Adds the variable_id to the variable window.
  28. #
  29. # variable_window_remove(variable_id)
  30. # - Removes the variable_id from the variable window.
  31. #
  32. # variable_window_upper_left
  33. # variable_window_upper_right
  34. # variable_window_lower_left
  35. # variable_window_lower_right
  36. # - Moves the variable window to that location.
  37. #
  38. # variable_window_width(x)
  39. # - Changes the variable window's width to x.
  40. #===============================================================================
  41.  
  42. $imported = {} if $imported == nil
  43. $imported["VariableMapWindow"] = true
  44.  
  45. #==============================================================================
  46. # ** Game_System
  47. #==============================================================================
  48.  
  49. class Game_System
  50.   #--------------------------------------------------------------------------
  51.   # * Public Instance Variables
  52.   #--------------------------------------------------------------------------
  53.   attr_accessor :shown_variables
  54.   attr_accessor :variable_window_open
  55.   attr_accessor :variable_corner
  56.   attr_accessor :variable_width
  57. end
  58.  
  59. #==============================================================================
  60. # ** Game_Interpreter
  61. #==============================================================================
  62.  
  63. class Game_Interpreter
  64.   #--------------------------------------------------------------------------
  65.   # * Variable Window Clear
  66.   #--------------------------------------------------------------------------
  67.   def variable_window_clear
  68.     return unless $scene.is_a?(Scene_Map)
  69.     $scene.variable_window.data = []
  70.     $scene.variable_window.refresh
  71.     $scene.variable_window.close
  72.   end
  73.   #--------------------------------------------------------------------------
  74.   # * Variable Window Open
  75.   #--------------------------------------------------------------------------
  76.   def variable_window_open
  77.     return unless $scene.is_a?(Scene_Map)
  78.     $scene.variable_window.open if $scene.variable_window.data != []
  79.     $game_system.variable_window_open = true
  80.   end
  81.   #--------------------------------------------------------------------------
  82.   # * Variable Window Close
  83.   #--------------------------------------------------------------------------
  84.   def variable_window_close
  85.     return unless $scene.is_a?(Scene_Map)
  86.     $scene.variable_window.close
  87.     $game_system.variable_window_open = false
  88.   end
  89.   #--------------------------------------------------------------------------
  90.   # * Variable Window Add
  91.   #--------------------------------------------------------------------------
  92.   def variable_window_add(variable_id)
  93.     return unless $scene.is_a?(Scene_Map)
  94.     return unless variable_id.is_a?(Integer)
  95.     return if $game_variables[variable_id].nil?
  96.     return if $game_system.shown_variables.include?(variable_id)
  97.     $game_system.shown_variables.push(variable_id)
  98.     $scene.variable_window.refresh
  99.   end
  100.   #--------------------------------------------------------------------------
  101.   # * Variable Window Remove
  102.   #--------------------------------------------------------------------------
  103.   def variable_window_remove(variable_id)
  104.     return unless $scene.is_a?(Scene_Map)
  105.     return unless $game_system.shown_variables.include?(variable_id)
  106.     $game_system.shown_variables.delete(variable_id)
  107.     $scene.variable_window.refresh
  108.   end
  109.   #--------------------------------------------------------------------------
  110.   # * Variable Window Upper Left
  111.   #--------------------------------------------------------------------------
  112.   def variable_window_upper_left
  113.     return unless $scene.is_a?(Scene_Map)
  114.     $game_system.variable_corner = 0
  115.   end
  116.   #--------------------------------------------------------------------------
  117.   # * Variable Window Upper Right
  118.   #--------------------------------------------------------------------------
  119.   def variable_window_upper_right
  120.     return unless $scene.is_a?(Scene_Map)
  121.     $game_system.variable_corner = 1
  122.   end
  123.   #--------------------------------------------------------------------------
  124.   # * Variable Window Lower Left
  125.   #--------------------------------------------------------------------------
  126.   def variable_window_lower_left
  127.     return unless $scene.is_a?(Scene_Map)
  128.     $game_system.variable_corner = 2
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   # * Variable Window Lower Right
  132.   #--------------------------------------------------------------------------
  133.   def variable_window_lower_right
  134.     return unless $scene.is_a?(Scene_Map)
  135.     $game_system.variable_corner = 3
  136.   end
  137.   #--------------------------------------------------------------------------
  138.   # * Variable Window Width
  139.   #--------------------------------------------------------------------------
  140.   def variable_window_width(value)
  141.     return unless $scene.is_a?(Scene_Map)
  142.     $game_system.variable_width = [160, value].max
  143.     $scene.variable_window.refresh
  144.   end
  145. end
  146.  
  147. #==============================================================================
  148. # ** Window_Variable
  149. #==============================================================================
  150.  
  151. class Window_Variable < Window_Selectable
  152.   #--------------------------------------------------------------------------
  153.   # * Public Instance Variables
  154.   #--------------------------------------------------------------------------
  155.   attr_accessor :data
  156.   #--------------------------------------------------------------------------
  157.   # * Object Initialization
  158.   #--------------------------------------------------------------------------
  159.   def initialize
  160.     $game_system.shown_variables = [] if $game_system.shown_variables.nil?
  161.     super(0, 0, 160, 56)
  162.     self.openness = 0 if $game_system.shown_variables.empty?
  163.     self.openness = 0 unless $game_system.variable_window_open
  164.     refresh
  165.     update_corner
  166.   end
  167.   #--------------------------------------------------------------------------
  168.   # * Refresh
  169.   #--------------------------------------------------------------------------
  170.   def refresh
  171.     $game_system.variable_width = 160 if $game_system.variable_width.nil?
  172.     self.width = $game_system.variable_width
  173.     @data = $game_system.shown_variables
  174.     @value = [] if @value.nil?
  175.     for variable in @data
  176.       next if $game_variables[variable].nil?
  177.       @value[variable] = $game_variables[variable]
  178.     end
  179.     @item_max = @data.size
  180.     self.height = [@item_max, 1].max * 24 + 32
  181.     create_contents
  182.     for i in 0...@item_max
  183.       draw_item(i)
  184.     end
  185.     update_corner
  186.   end
  187.   #--------------------------------------------------------------------------
  188.   # * Update
  189.   #--------------------------------------------------------------------------
  190.   def update
  191.     super
  192.     refresh if @data != $game_system.shown_variables
  193.     for variable in @data.compact
  194.       next if variable == nil
  195.       next if $game_variables[variable].nil?
  196.       next if @value[variable] == $game_variables[variable]
  197.       draw_item(@data.index(variable))
  198.     end
  199.     update_corner
  200.   end
  201.   #--------------------------------------------------------------------------
  202.   # * Update Corner
  203.   #--------------------------------------------------------------------------
  204.   def update_corner
  205.     $game_system.variable_corner = 0 if $game_system.variable_corner.nil?
  206.     case $game_system.variable_corner
  207.     when 0
  208.       self.x = 0
  209.       self.y = 0
  210.     when 1
  211.       self.x = Graphics.width - self.width
  212.       self.y = 0
  213.     when 2
  214.       self.x = 0
  215.       self.y = Graphics.height - self.height
  216.     when 3
  217.       self.x = Graphics.width - self.width
  218.       self.y = Graphics.height - self.height
  219.     end
  220.   end
  221.   #--------------------------------------------------------------------------
  222.   # * Draw Item
  223.   #--------------------------------------------------------------------------
  224.   def draw_item(index)
  225.     rect = item_rect(index)
  226.     self.contents.clear_rect(rect)
  227.     current_id = @data[index]
  228.     return if $game_variables[current_id].nil?
  229.     name = sprintf("%s:", $data_system.variables[current_id])
  230.     amount = $game_variables[current_id]
  231.     self.contents.font.color = system_color
  232.     self.contents.draw_text(rect, name, 0)
  233.     self.contents.font.color = normal_color
  234.     self.contents.draw_text(rect, amount, 2)
  235.   end
  236. end
  237.  
  238. #==============================================================================
  239. # ** Scene_Map
  240. #==============================================================================
  241.  
  242. class Scene_Map < Scene_Base
  243.   #--------------------------------------------------------------------------
  244.   # * Public Instance Variables
  245.   #--------------------------------------------------------------------------
  246.   attr_accessor :variable_window
  247.   #--------------------------------------------------------------------------
  248.   # * Start processing
  249.   #--------------------------------------------------------------------------
  250.   alias start_sss_variable_map_window start unless $@
  251.   def start
  252.     start_sss_variable_map_window
  253.     @variable_window = Window_Variable.new
  254.   end
  255.   #--------------------------------------------------------------------------
  256.   # * Termination Processing
  257.   #--------------------------------------------------------------------------
  258.   alias terminate_sss_variable_map_window terminate unless $@
  259.   def terminate
  260.     @variable_window.dispose unless @variable_window.nil?
  261.     @variable_window = nil
  262.     terminate_sss_variable_map_window
  263.   end
  264.   #--------------------------------------------------------------------------
  265.   # * Basic Update Processing
  266.   #--------------------------------------------------------------------------
  267.   alias update_basic_sss_variable_map_window update_basic unless $@
  268.   def update_basic
  269.     update_basic_sss_variable_map_window
  270.     @variable_window.update unless @variable_window.nil?
  271.   end
  272.   #--------------------------------------------------------------------------
  273.   # * Frame Update
  274.   #--------------------------------------------------------------------------
  275.   alias update_sss_variable_map_window update unless $@
  276.   def update
  277.     update_sss_variable_map_window
  278.     @variable_window.update unless @variable_window.nil?
  279.   end
  280. end
  281.  
  282. #===============================================================================
  283. #
  284. # END OF FILE
  285. #
  286. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement