IceDragon200

IRS001-VariableMenu

May 7th, 2011
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.92 KB | None | 0 0
  1. #==============================================================================#
  2. # IRS (Icy Requested Script) - Variable Menu
  3. # Created By   : IceDragon
  4. # Date Created : 05/07/2011
  5. # Date Modified: 05/07/2011
  6. #==============================================================================#
  7. # To call the variable scene use:
  8. # call_varscene("NAME", columns)
  9. # In an event script command.
  10. # // ------------------------------------------------------------------- //#
  11. # For a quick test
  12. # Set the following variables to the value on the right
  13. # 1  - 90
  14. # 17 - 5
  15. # 18 - 100
  16. # 19 - 120
  17. # 20 - 24
  18. # Then call call_varscene("BASIC", 2)
  19. #==============================================================================#
  20. # IRS::VariableWindowSystem - (IRS001 - Primary)
  21. #==============================================================================#
  22. module IRS
  23.   module VariableWindowSystem
  24. #==============================================================================#
  25. #                      Start Primary Customization
  26. #------------------------------------------------------------------------------#
  27. #==============================================================================#
  28.     DEFAULT_WINDOWSETS = { }
  29.     DEFAULT_WINDOWSETS["BASIC"] = []
  30.     # // [ "TYPE",  [general_info], [type_parameters] ]
  31.     # // ------------------------------------------------------------------- //#
  32.     # // [ "VALUE", ["Name", icon_index, "Description"], [sprintf_format, var] ]
  33.     # // [ "MINMAX",["Name", icon_index, "Description"], [sprintf_format, var1, var2] ]    
  34.     # // [ "BAR",   ["Name", icon_index, "Description"], [var1, var2] ]  
  35.     # // ------------------------------------------------------------------- //#
  36.     # // Icon_index of -1 will use no icon
  37.     # // "<<" works like ".push" on an array "[]"
  38.     DEFAULT_WINDOWSETS["BASIC"] << ["VALUE",                  # // Type
  39.             ["TeMP(5)", 130, "5"],                            # // General Info
  40.             [": %s", 17],                                     # // Parameters
  41.            ] # // "TeMP(5)"
  42.     DEFAULT_WINDOWSETS["BASIC"] << ["MINMAX",                 # // Type
  43.             ["Material", 128, "Used as the building blocks"], # // General Info
  44.             [": %s/%s", 20, 19],                              # // Parameters
  45.            ] # // "Material"
  46.     DEFAULT_WINDOWSETS["BASIC"] << ["BAR",                    # // Type
  47.             ["Volume", 129, "System Volume"],                 # // General Info
  48.             [1, 18],                                          # // Parameters
  49.            ] # // "Volume"
  50.     # // ------------------------------------------------------------------- //#
  51.     DEFAULT_WINDOWSETS["OTHER"] = []      
  52. #==============================================================================#
  53. #                        End Primary Customization
  54. #------------------------------------------------------------------------------#
  55. #==============================================================================#    
  56.     module_function
  57.    
  58.     # // Get Variable Set
  59.     def get_varset(name)
  60.       return DEFAULT_WINDOWSETS[name]
  61.     end
  62. #==============================================================================#
  63. #                          End Script Functions
  64. #------------------------------------------------------------------------------#
  65. #==============================================================================#        
  66.   end
  67. end
  68.  
  69. #==============================================================================#
  70. # Game_Interpreter
  71. #==============================================================================#
  72. class Game_Interpreter
  73.  
  74.   #--------------------------------------------------------------------------#
  75.   # * new method :call_varscene
  76.   #--------------------------------------------------------------------------#  
  77.   def call_varscene( varset_name, columns = 1, from=:map, return_index=0 )
  78.     varset = IRS::VariableWindowSystem.get_varset( varset_name )
  79.     $scene = Scene_VariableMenu.new( varset, columns, from, return_index )
  80.   end
  81.  
  82. end
  83.  
  84. #==============================================================================#
  85. # Window_VariableBase
  86. #==============================================================================#
  87. class Window_VariableBase < Window_Selectable
  88.  
  89.   #--------------------------------------------------------------------------#
  90.   # * method :initialize
  91.   #--------------------------------------------------------------------------#  
  92.   def initialize( varset, columns, x, y, w, h )
  93.     super( x, y, w, h )
  94.     @column_max = columns
  95.     @data       = varset
  96.     self.index  = 0
  97.     self.active = true
  98.     refresh
  99.   end
  100.  
  101.   #--------------------------------------------------------------------------#
  102.   # * method :obj
  103.   #--------------------------------------------------------------------------#    
  104.   def obj ; return @data[self.index] end
  105.    
  106.   #--------------------------------------------------------------------------#
  107.   # * method :refresh
  108.   #--------------------------------------------------------------------------#    
  109.   def refresh
  110.     @item_max = @data.size
  111.     create_contents
  112.     for i in 0...@data.size
  113.       draw_item( i, true )
  114.     end  
  115.   end
  116.  
  117.   #--------------------------------------------------------------------------#
  118.   # * method :item_rect
  119.   #--------------------------------------------------------------------------#
  120.   def item_rect( index )
  121.     rect = Rect.new( 0, 0, 0, 0 )
  122.     rect.width = ( contents.width + @spacing ) / @column_max - @spacing
  123.     rect.height = WLH
  124.     rect.x = index % @column_max * ( rect.width + @spacing )
  125.     rect.y = index / @column_max * WLH
  126.     return rect
  127.   end
  128.  
  129.   #--------------------------------------------------------------------------#
  130.   # * method :draw_item
  131.   #--------------------------------------------------------------------------#  
  132.   def draw_item( index, enabled=true )
  133.     vars = $game_variables
  134.     varset = @data[index]
  135.     case varset[0].upcase
  136.     # // "VALUE" A single value is draw beside the name
  137.     when "VALUE"
  138.       rect = get_varset_rect( index, varset )
  139.       if varset[1][1] >= 0
  140.         draw_icon(varset[1][1], rect.x, rect.y, enabled)
  141.         rect.x += 24 ; rect.width -= 24
  142.       end  
  143.       self.contents.font.color.alpha = enabled ? 255 : 128
  144.       self.contents.draw_text( rect, varset[1][0] )
  145.       valtext = sprintf( varset[2][0], vars[varset[2][1]] )
  146.       self.contents.draw_text( rect, valtext, 2 )
  147.     # // "MINMAX"
  148.     when "MINMAX"  
  149.       rect = get_varset_rect( index, varset )
  150.       if varset[1][1] >= 0
  151.         draw_icon( varset[1][1], rect.x, rect.y, enabled )
  152.         rect.x += 24 ; rect.width -= 24
  153.       end  
  154.       self.contents.font.color.alpha = enabled ? 255 : 128
  155.       self.contents.draw_text( rect, varset[1][0] )
  156.       valtext = sprintf( varset[2][0], vars[varset[2][1]], vars[varset[2][2]] )
  157.       self.contents.draw_text( rect, valtext, 2 )
  158.     # // "BAR"
  159.     when "BAR"  
  160.       rect = get_varset_rect( index, varset )  
  161.       val, max = vars[varset[2][0]], vars[varset[2][1]]
  162.       if varset[1][1] >= 0
  163.         draw_icon( varset[1][1], rect.x, rect.y, enabled )
  164.         rect.x += 24 ; rect.width -= 24
  165.       end
  166.       # // Draw Bar
  167.       rect2 = rect.clone ; rect2.width -= 4 ; rect2.height = 8 ; rect2.y += 12
  168.       self.contents.fill_rect( rect2, gauge_back_color )
  169.       rect3 = rect2.clone
  170.       rect3.x += 1 ; rect3.width -= 2 ; rect3.y += 1 ; rect3.height -= 2
  171.       rlwidth = rect3.width
  172.       rect3.width = rlwidth * val / max
  173.       self.contents.gradient_fill_rect( rect3, hp_gauge_color1, hp_gauge_color2 )
  174.       self.contents.font.color.alpha = enabled ? 255 : 128
  175.       self.contents.draw_text( rect, varset[1][0] )
  176.     end  
  177.   end
  178.  
  179.   #--------------------------------------------------------------------------#
  180.   # * method :get_varset_rect
  181.   #--------------------------------------------------------------------------#  
  182.   def get_varset_rect( index, varset )
  183.     unless varset[3].nil?
  184.       case varset[3]
  185.       when Rect  ; rect = varset[3][0].clone
  186.       when Array ; rect = Rect.new( *varset[3] )
  187.       else       ; return nil ; end
  188.     else ; rect = item_rect(index) ; end
  189.     return rect
  190.   end
  191.  
  192.   #--------------------------------------------------------------------------#
  193.   # * method :update_help
  194.   #--------------------------------------------------------------------------#
  195.   def update_help
  196.     @help_window.set_text( obj.nil?() ? "" : obj[1][2] )
  197.   end
  198.  
  199. end
  200.  
  201. #==============================================================================#
  202. # Scene_VariableMenu
  203. #==============================================================================#
  204. class Scene_VariableMenu < Scene_Base
  205.  
  206.   #--------------------------------------------------------------------------#
  207.   # * method :initialize
  208.   #--------------------------------------------------------------------------#  
  209.   def initialize( varset, columns, called = :map, return_index=0 )
  210.     super()
  211.     # ---------------------------------------------------- #
  212.     @columns      = columns
  213.     @calledfrom   = called
  214.     @return_index = return_index
  215.     # ---------------------------------------------------- #
  216.     @varset = varset
  217.     # ---------------------------------------------------- #
  218.   end
  219.  
  220.   #--------------------------------------------------------------------------#
  221.   # * method :start
  222.   #--------------------------------------------------------------------------#  
  223.   def start()
  224.     # ---------------------------------------------------- #
  225.     create_menu_background()
  226.     # ---------------------------------------------------- #
  227.     winrect = Rect.new( 0, 0, Graphics.width(), Graphics.height() )
  228.     @windows = { }
  229.     # ---------------------------------------------------- #
  230.     @windows["Varset"] = Window_VariableBase.new( @varset, @columns, 0, 56, winrect.width, winrect.height - 56)
  231.     @windows["Help"]   = Window_Help.new()
  232.     # ---------------------------------------------------- #
  233.     @windows["Varset"].help_window = @windows["Help"]
  234.   end
  235.  
  236.   #--------------------------------------------------------------------------#
  237.   # * method :terminate
  238.   #--------------------------------------------------------------------------#
  239.   def terminate()
  240.     # ---------------------------------------------------- #
  241.     super()
  242.     # ---------------------------------------------------- #
  243.     dispose_menu_background()
  244.     # ---------------------------------------------------- #
  245.     @windows.values.compact.each { |w| w.dispose }
  246.     # ---------------------------------------------------- #
  247.   end  
  248.  
  249.   #--------------------------------------------------------------------------#
  250.   # * method :return_scene
  251.   #--------------------------------------------------------------------------#
  252.   def return_scene()
  253.     # ---------------------------------------------------- #
  254.     case @calledfrom
  255.     when :map
  256.       $scene = Scene_Map.new()
  257.     when :menu
  258.       $scene = Scene_Menu.new( @return_index )
  259.     end  
  260.   end
  261.  
  262.   #--------------------------------------------------------------------------#
  263.   # * method :update
  264.   #--------------------------------------------------------------------------#  
  265.   def update()
  266.     # ---------------------------------------------------- #
  267.     super()
  268.     # ---------------------------------------------------- #
  269.     @windows.values.each { |w| next if w.nil?() ; w.update() if w.active }
  270.     update_user_input()
  271.   end
  272.  
  273.   #--------------------------------------------------------------------------#
  274.   # * method :update_user_input
  275.   #--------------------------------------------------------------------------#  
  276.   def update_user_input()
  277.     if Input.trigger?( Input::B ) ; Sound.play_cancel ; return_scene end
  278.   end
  279.  
  280. end
  281.  
  282. #=*==========================================================================*=#
  283. # ** END OF FILE
  284. #=*==========================================================================*=#
Advertisement
Add Comment
Please, Sign In to add comment