Advertisement
Zeriab

[RGSS3] Switch toggable map variable icon display

Jun 10th, 2017
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.44 KB | None | 0 0
  1. class Scene_Map < Scene_Base
  2.   # Switch for opening/closing the gold window
  3.   VARIABLE_DISPLAY_SWITCH = 15
  4.   VARIABLE_ID = 42
  5.   VARIABLE_ICON_INDEX = 20
  6.   VARIABLE_X = 424
  7.   VARIABLE_Y = 48
  8.   VARIABLE_WIDTH = 120
  9.   VARIABLE_HEIGHT = 48
  10.   VARIABLE_ICON_OFFSET = 48
  11.   VARIABLE_TEXT_OFFSET = 50
  12.  
  13.   ##
  14.   # Aliases
  15.   #
  16.   alias_method :zeriab_variable_create_all_windows, :create_all_windows
  17.   def create_all_windows
  18.     zeriab_variable_create_all_windows
  19.     create_variable_display
  20.   end
  21.  
  22.   alias_method :zeriab_variable_update_scene, :update_scene
  23.   def update_scene
  24.     zeriab_variable_update_scene
  25.     update_variable_display
  26.   end
  27.  
  28.   ##
  29.   # Creation
  30.   #
  31.   def create_variable_display
  32.     @variable_display = Window_VariableDisplay.new(
  33.       VARIABLE_ID,
  34.       VARIABLE_ICON_INDEX,
  35.       VARIABLE_X,
  36.       VARIABLE_Y,
  37.       VARIABLE_WIDTH,
  38.       VARIABLE_HEIGHT)
  39.     @variable_display.icon_offset = VARIABLE_ICON_OFFSET
  40.     @variable_display.text_offset = VARIABLE_TEXT_OFFSET
  41.     @variable_display.openness = 0
  42.    
  43.     @show_variable_display = $game_switches[VARIABLE_DISPLAY_SWITCH]
  44.     @variable_display.open if @show_variable_display
  45.   end
  46.  
  47.   ##
  48.   # Update open state
  49.   #
  50.   def update_variable_display
  51.     if @show_variable_display != $game_switches[VARIABLE_DISPLAY_SWITCH]
  52.       @show_variable_display = $game_switches[VARIABLE_DISPLAY_SWITCH]
  53.       if @show_variable_display
  54.         @variable_display.open
  55.       else
  56.         @variable_display.close
  57.       end
  58.       @variable_display.update
  59.     end
  60.   end  
  61. end
  62.  
  63. ##
  64. # Variable display with icon
  65. #
  66. class Window_VariableDisplay < Window_Base
  67.   attr_reader :variable_id
  68.   attr_reader :icon_index
  69.   attr_accessor :icon_offset
  70.   attr_accessor :text_offset
  71.  
  72.   def value; $game_variables[@variable_id]; end
  73.    
  74.   ##
  75.   # Init
  76.   #
  77.   def initialize(variable_id, icon_index, x, y, width, height)
  78.     #super(0, 0, window_width, fitting_height(1))
  79.     super(x, y, width, height)
  80.     @variable_id = variable_id
  81.     @icon_index = icon_index
  82.     self.icon_offset = 48
  83.     self.text_offset = 50
  84.     refresh
  85.   end
  86.  
  87.   ##
  88.   # Refresh
  89.   #
  90.   def refresh
  91.     contents.clear
  92.     draw_icon(icon_index, width - icon_offset, 0)
  93.     draw_text(0, 0, width - text_offset, line_height, value, 2)
  94.   end
  95.  
  96.   ##
  97.   # Update
  98.   #
  99.   def update
  100.     super
  101.     @old_value ||= value
  102.     if @old_value != value
  103.       @old_value = value
  104.       refresh
  105.     end
  106.   end
  107. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement