SHARE
TWEET

Menu Variables - ENG

Holy87 Aug 3rd, 2015 231 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. =begin
  2.  ==============================================================================
  3.   ■ Holy87's Menu Variables
  4.       version 1.0
  5.       User difficulty: ★
  6.       License: CC-BY. Everyone can distribute this script and use in their free
  7.       and commercial games. Credit required.
  8.  ==============================================================================
  9.     This script adds so many variables you like in the main menu, inside the
  10.     gold window, to add more currencies
  11.  ==============================================================================
  12.   ■ Compatibility
  13.     Window_Gold -> alias refresh
  14.  ==============================================================================
  15.   ■ Installation and instructions
  16.     Place this script under Materials and above Main.
  17.     Configure how many variables you want int the VARIABLES array below.
  18.  ==============================================================================
  19. =end
  20.  
  21. #==============================================================================
  22. # ** CONFIGURATION
  23. #------------------------------------------------------------------------------
  24. #  Script configuration
  25. #==============================================================================
  26. module MenuVariablesConfig
  27.   VARIABLES = [
  28.   #--------------------------------------------------------------------------
  29.   # * Add so many lines as the variables you want to shoq, like the example:
  30.   #--------------------------------------------------------------------------
  31.   #Name         Variable ID   icon (0 to none)
  32.   ["Crystals",  1,            343   ],
  33.   ["Emblems",   2,            245   ],
  34.   ["Stardusts", 3,            348   ],
  35.   ]#do not remove the parenthesys!
  36. end
  37.  
  38.  
  39. #==============================================================================
  40. # ** Variable_Description
  41. #------------------------------------------------------------------------------
  42. #  Contains informations of the variable to show
  43. #==============================================================================
  44. class Variable_Description
  45.   attr_reader :name         #name
  46.   attr_reader :id           #variable ID
  47.   attr_reader :icon_index   #icon index
  48.   #--------------------------------------------------------------------------
  49.   # * Initialization
  50.   #   var_array: array for variable informations [name, id, icon]
  51.   #--------------------------------------------------------------------------
  52.   def initialize(var_array)
  53.     @name = var_array[0]
  54.     @id = var_array[1]
  55.     @icon_index = var_array[2]
  56.   end
  57.   #--------------------------------------------------------------------------
  58.   # * Returns the variable value
  59.   #--------------------------------------------------------------------------
  60.   def value; $game_variables[@id]; end
  61.   #--------------------------------------------------------------------------
  62.   # * Returns true if it hasn't the icon
  63.   #--------------------------------------------------------------------------
  64.   def no_icon?; @icon_index == 0 || @icon_index.nil?; end
  65. end
  66.  
  67. #==============================================================================
  68. # ** Window_Gold
  69. #------------------------------------------------------------------------------
  70. #  Edit the window to include the variables
  71. #==============================================================================
  72. class Window_Gold < Window_Base
  73.   include MenuVariablesConfig #module inclusion
  74.   alias h87_menuvariable_refresh refresh unless $@
  75.   #--------------------------------------------------------------------------
  76.   # * Method for height
  77.   #--------------------------------------------------------------------------
  78.   def fitting_height(number)
  79.     number += VARIABLES.size if SceneManager.scene.is_a?(Scene_Menu)
  80.     super(number)
  81.   end
  82.   #--------------------------------------------------------------------------
  83.   # * Refresh
  84.   #--------------------------------------------------------------------------
  85.   def refresh
  86.     if SceneManager.scene.is_a?(Scene_Menu)
  87.       contents.clear
  88.       draw_variables
  89.       draw_currency_value(value, currency_unit, 4, line_height*@variables.size, contents.width - 8)
  90.     else
  91.       h87_menuvariable_refresh
  92.     end
  93.   end
  94.   #--------------------------------------------------------------------------
  95.   # * Obtains the variable informations
  96.   #--------------------------------------------------------------------------
  97.   def get_variables
  98.     @variables = []
  99.     for i in 0.. VARIABLES.size-1
  100.       @variables.push(Variable_Description.new(VARIABLES[i]))
  101.     end
  102.   end
  103.   #--------------------------------------------------------------------------
  104.   # * Draw the variables
  105.   #--------------------------------------------------------------------------
  106.   def draw_variables
  107.     get_variables
  108.     for i in 0..@variables.size-1
  109.       var = @variables[i]
  110.       twidth = contents_width - text_size(var.value).width
  111.       twidth -= 24 unless var.no_icon?
  112.       change_color(system_color)
  113.       draw_text(0, line_height*i, twidth, line_height, var.name)
  114.       change_color(normal_color)
  115.       twidth = contents_width - (var.no_icon? ? 0 : 24)
  116.       draw_text(0, line_height*i, twidth, line_height, var.value, 2)
  117.       unless var.no_icon?
  118.         draw_icon(var.icon_index, contents_width-24, line_height*i)
  119.       end
  120.     end
  121.   end
  122. end  #end of the script.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top