Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================#
- # IRS (Icy Requested Script) - Variable Menu
- # Created By : IceDragon
- # Date Created : 05/07/2011
- # Date Modified: 05/07/2011
- #==============================================================================#
- # To call the variable scene use:
- # call_varscene("NAME", columns)
- # In an event script command.
- # // ------------------------------------------------------------------- //#
- # For a quick test
- # Set the following variables to the value on the right
- # 1 - 90
- # 17 - 5
- # 18 - 100
- # 19 - 120
- # 20 - 24
- # Then call call_varscene("BASIC", 2)
- #==============================================================================#
- # IRS::VariableWindowSystem - (IRS001 - Primary)
- #==============================================================================#
- module IRS
- module VariableWindowSystem
- #==============================================================================#
- # Start Primary Customization
- #------------------------------------------------------------------------------#
- #==============================================================================#
- DEFAULT_WINDOWSETS = { }
- DEFAULT_WINDOWSETS["BASIC"] = []
- # // [ "TYPE", [general_info], [type_parameters] ]
- # // ------------------------------------------------------------------- //#
- # // [ "VALUE", ["Name", icon_index, "Description"], [sprintf_format, var] ]
- # // [ "MINMAX",["Name", icon_index, "Description"], [sprintf_format, var1, var2] ]
- # // [ "BAR", ["Name", icon_index, "Description"], [var1, var2] ]
- # // ------------------------------------------------------------------- //#
- # // Icon_index of -1 will use no icon
- # // "<<" works like ".push" on an array "[]"
- DEFAULT_WINDOWSETS["BASIC"] << ["VALUE", # // Type
- ["TeMP(5)", 130, "5"], # // General Info
- [": %s", 17], # // Parameters
- ] # // "TeMP(5)"
- DEFAULT_WINDOWSETS["BASIC"] << ["MINMAX", # // Type
- ["Material", 128, "Used as the building blocks"], # // General Info
- [": %s/%s", 20, 19], # // Parameters
- ] # // "Material"
- DEFAULT_WINDOWSETS["BASIC"] << ["BAR", # // Type
- ["Volume", 129, "System Volume"], # // General Info
- [1, 18], # // Parameters
- ] # // "Volume"
- # // ------------------------------------------------------------------- //#
- DEFAULT_WINDOWSETS["OTHER"] = []
- #==============================================================================#
- # End Primary Customization
- #------------------------------------------------------------------------------#
- #==============================================================================#
- module_function
- # // Get Variable Set
- def get_varset(name)
- return DEFAULT_WINDOWSETS[name]
- end
- #==============================================================================#
- # End Script Functions
- #------------------------------------------------------------------------------#
- #==============================================================================#
- end
- end
- #==============================================================================#
- # Game_Interpreter
- #==============================================================================#
- class Game_Interpreter
- #--------------------------------------------------------------------------#
- # * new method :call_varscene
- #--------------------------------------------------------------------------#
- def call_varscene( varset_name, columns = 1, from=:map, return_index=0 )
- varset = IRS::VariableWindowSystem.get_varset( varset_name )
- $scene = Scene_VariableMenu.new( varset, columns, from, return_index )
- end
- end
- #==============================================================================#
- # Window_VariableBase
- #==============================================================================#
- class Window_VariableBase < Window_Selectable
- #--------------------------------------------------------------------------#
- # * method :initialize
- #--------------------------------------------------------------------------#
- def initialize( varset, columns, x, y, w, h )
- super( x, y, w, h )
- @column_max = columns
- @data = varset
- self.index = 0
- self.active = true
- refresh
- end
- #--------------------------------------------------------------------------#
- # * method :obj
- #--------------------------------------------------------------------------#
- def obj ; return @data[self.index] end
- #--------------------------------------------------------------------------#
- # * method :refresh
- #--------------------------------------------------------------------------#
- def refresh
- @item_max = @data.size
- create_contents
- for i in 0...@data.size
- draw_item( i, true )
- end
- end
- #--------------------------------------------------------------------------#
- # * method :item_rect
- #--------------------------------------------------------------------------#
- def item_rect( index )
- rect = Rect.new( 0, 0, 0, 0 )
- rect.width = ( contents.width + @spacing ) / @column_max - @spacing
- rect.height = WLH
- rect.x = index % @column_max * ( rect.width + @spacing )
- rect.y = index / @column_max * WLH
- return rect
- end
- #--------------------------------------------------------------------------#
- # * method :draw_item
- #--------------------------------------------------------------------------#
- def draw_item( index, enabled=true )
- vars = $game_variables
- varset = @data[index]
- case varset[0].upcase
- # // "VALUE" A single value is draw beside the name
- when "VALUE"
- rect = get_varset_rect( index, varset )
- if varset[1][1] >= 0
- draw_icon(varset[1][1], rect.x, rect.y, enabled)
- rect.x += 24 ; rect.width -= 24
- end
- self.contents.font.color.alpha = enabled ? 255 : 128
- self.contents.draw_text( rect, varset[1][0] )
- valtext = sprintf( varset[2][0], vars[varset[2][1]] )
- self.contents.draw_text( rect, valtext, 2 )
- # // "MINMAX"
- when "MINMAX"
- rect = get_varset_rect( index, varset )
- if varset[1][1] >= 0
- draw_icon( varset[1][1], rect.x, rect.y, enabled )
- rect.x += 24 ; rect.width -= 24
- end
- self.contents.font.color.alpha = enabled ? 255 : 128
- self.contents.draw_text( rect, varset[1][0] )
- valtext = sprintf( varset[2][0], vars[varset[2][1]], vars[varset[2][2]] )
- self.contents.draw_text( rect, valtext, 2 )
- # // "BAR"
- when "BAR"
- rect = get_varset_rect( index, varset )
- val, max = vars[varset[2][0]], vars[varset[2][1]]
- if varset[1][1] >= 0
- draw_icon( varset[1][1], rect.x, rect.y, enabled )
- rect.x += 24 ; rect.width -= 24
- end
- # // Draw Bar
- rect2 = rect.clone ; rect2.width -= 4 ; rect2.height = 8 ; rect2.y += 12
- self.contents.fill_rect( rect2, gauge_back_color )
- rect3 = rect2.clone
- rect3.x += 1 ; rect3.width -= 2 ; rect3.y += 1 ; rect3.height -= 2
- rlwidth = rect3.width
- rect3.width = rlwidth * val / max
- self.contents.gradient_fill_rect( rect3, hp_gauge_color1, hp_gauge_color2 )
- self.contents.font.color.alpha = enabled ? 255 : 128
- self.contents.draw_text( rect, varset[1][0] )
- end
- end
- #--------------------------------------------------------------------------#
- # * method :get_varset_rect
- #--------------------------------------------------------------------------#
- def get_varset_rect( index, varset )
- unless varset[3].nil?
- case varset[3]
- when Rect ; rect = varset[3][0].clone
- when Array ; rect = Rect.new( *varset[3] )
- else ; return nil ; end
- else ; rect = item_rect(index) ; end
- return rect
- end
- #--------------------------------------------------------------------------#
- # * method :update_help
- #--------------------------------------------------------------------------#
- def update_help
- @help_window.set_text( obj.nil?() ? "" : obj[1][2] )
- end
- end
- #==============================================================================#
- # Scene_VariableMenu
- #==============================================================================#
- class Scene_VariableMenu < Scene_Base
- #--------------------------------------------------------------------------#
- # * method :initialize
- #--------------------------------------------------------------------------#
- def initialize( varset, columns, called = :map, return_index=0 )
- super()
- # ---------------------------------------------------- #
- @columns = columns
- @calledfrom = called
- @return_index = return_index
- # ---------------------------------------------------- #
- @varset = varset
- # ---------------------------------------------------- #
- end
- #--------------------------------------------------------------------------#
- # * method :start
- #--------------------------------------------------------------------------#
- def start()
- # ---------------------------------------------------- #
- create_menu_background()
- # ---------------------------------------------------- #
- winrect = Rect.new( 0, 0, Graphics.width(), Graphics.height() )
- @windows = { }
- # ---------------------------------------------------- #
- @windows["Varset"] = Window_VariableBase.new( @varset, @columns, 0, 56, winrect.width, winrect.height - 56)
- @windows["Help"] = Window_Help.new()
- # ---------------------------------------------------- #
- @windows["Varset"].help_window = @windows["Help"]
- end
- #--------------------------------------------------------------------------#
- # * method :terminate
- #--------------------------------------------------------------------------#
- def terminate()
- # ---------------------------------------------------- #
- super()
- # ---------------------------------------------------- #
- dispose_menu_background()
- # ---------------------------------------------------- #
- @windows.values.compact.each { |w| w.dispose }
- # ---------------------------------------------------- #
- end
- #--------------------------------------------------------------------------#
- # * method :return_scene
- #--------------------------------------------------------------------------#
- def return_scene()
- # ---------------------------------------------------- #
- case @calledfrom
- when :map
- $scene = Scene_Map.new()
- when :menu
- $scene = Scene_Menu.new( @return_index )
- end
- end
- #--------------------------------------------------------------------------#
- # * method :update
- #--------------------------------------------------------------------------#
- def update()
- # ---------------------------------------------------- #
- super()
- # ---------------------------------------------------- #
- @windows.values.each { |w| next if w.nil?() ; w.update() if w.active }
- update_user_input()
- end
- #--------------------------------------------------------------------------#
- # * method :update_user_input
- #--------------------------------------------------------------------------#
- def update_user_input()
- if Input.trigger?( Input::B ) ; Sound.play_cancel ; return_scene end
- end
- end
- #=*==========================================================================*=#
- # ** END OF FILE
- #=*==========================================================================*=#
Advertisement
Add Comment
Please, Sign In to add comment