Advertisement
Holy87

Settings Menu - EN

Aug 6th, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 56.09 KB | None | 0 0
  1. =begin
  2.  ==============================================================================
  3.   ■ Holy87 GAME OPTIONS
  4.       version 1.1
  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 add a settings menu to configure maker's and other script's
  10.     custom options (if they can support). Give to the player the options due
  11.     to him!
  12.  ==============================================================================
  13.   ■ Compatibility
  14.     Scene_Title -> alias create_command_window
  15.     Scene_Menu -> alias create_command_window
  16.     DataManager -> alias load_normal_database
  17.  ==============================================================================
  18.   ■ Installation and instructions
  19.     Install this script under Materials and above the Main
  20.     REQUIRES THE UNVIERSAL SUPPORT MODULE OF HOLY87.
  21.    
  22.   ■ Instruction for making game options
  23.  
  24.       You can easly add options adding them at the ELEMENTS array (below).
  25.       It's possible to add options that change switches, variables, bars
  26.       and other elements. Let's see how.
  27.      
  28.     ● To add separators
  29.       {:type => :separator, :text => "This is a separator"}
  30.       The separator is used to make more organized the settings menu separating
  31.       many categories. It's important to set type as :separator, while the :text
  32.       attribute shows the section title.
  33.      
  34.     ● To add switches
  35.       {:type => :switch, :text => "Option name", :sw => 10, :on => "ON",
  36.        :off => "OGFF", :help => "Activates the option"}
  37.       With this command you can setup a switch option. The :sw parameter indicates
  38.       the game switch ID to set true or false. The parameters :on and :off are the
  39.       text showed in the options.
  40.       You can also add the value :default => true if you want that the switch will
  41.       be active as new game starts.
  42.      
  43.     ● To add Variables
  44.       {:type => :variable, :text => "Option name", :var => 2, :max => 5,
  45.        :help => "Change the option value"}
  46.       This command set up an options with a game variable. With :var we can set
  47.       the variable ID and :max the maximum value. In this case, we set up that
  48.       option of the variable 2 can have the values 0, 1, 2, 3, 4 and 5.
  49.       You can also customize value names, for example
  50.      
  51.       {:type => :variable, :text => "Difficulty", :var => 5,
  52.        :help => "Set up the game difficulty.",
  53.        :values => ["Easy", "Normal", "Hard", "Extreme"] }
  54.       Are there so many values to show in a single line? No problem!
  55.       Add the parameter :open_popup => true to show the option selection in a
  56.       popup window with unlimited values.
  57.       In this case, you can omit the :max parameter because the values are already
  58.       defined.
  59.      
  60.     ● To add bars
  61.       Another way to control variables is using bars. This will show a bar
  62.       that fills up or empties as the user preferences. The configuration is similiar
  63.       to the variables, but you mai define also the bar color. Example:
  64.       {:type => :bar, :text => "Volume", :var => 5, :max => 100, :color => 5,
  65.        :help => "Set up the game volume."}
  66.       The color refers to the color number in the windowskin (for example, 0 is
  67.       the text color).
  68.       The bars have also the benefit of being coupled with a switch, if the user
  69.       press Enter the option can be disabled (for example, to make audio mute).
  70.       Just add the :sw attribute like a switch option!
  71.      
  72.   ■ Advanced options for geeks
  73.    
  74.       SET UP GLOBAL OPTIONS (THAT NON DEPEND FROM THE SAVEGAME)
  75.       If you set a switch ID or variable not like an integer number, but like
  76.       a string or a symbol, the option is seen like global and will be saved
  77.       in $game_settings.
  78.      
  79.       ENABLING OR DISABLING SOME OPTIONS
  80.       You can enable or disable the options in 2 ways:
  81.       ● $game_system.option_enable(tag, true/false) enables or disables the
  82.         game option, using this code in a call script or other scripts.
  83.         The <tag> parameter is the option tag defined in the option configuration
  84.         (:tag => :option_name)
  85.       ● using :condition => "condition" in the option configuration.
  86.         For example, :condition => "$game_switches[55] == true" will allow the option
  87.         only if the switch 55 is true
  88.      
  89.       ADVANCED ENTRIES FOR CUSTOM RUBY CODE EXECUTION
  90.       Setting the type as :advanced, it will be executed a code when the player press
  91.       enter on him. Example:
  92.       {:type => :advanced, method => :change_scene}
  93.       Then you may define the change_scene method in the Option class:
  94.  
  95.       class Option
  96.         def change_scene
  97.           SceneManager.call(Mia_Scena)
  98.         end
  99.       end
  100.      
  101.       Also, if you want to customize the walue showed in the options, you may alias
  102.       the method draw_advanced in Window_GameOptions.
  103.      
  104.       If you set the value :method => :method_name in a bar, switch or variable, it
  105.       will be executed the method method_name before the value is setted. You can set
  106.       :var or :sw to 0 if you don't want to use definitely a variable or a switch.
  107.       The method in this case must receive a INNER PARAMETER that refers to the setted
  108.       value.
  109.  
  110.       If you set the value :val_mt => :method_name, the value that will be showed in
  111.       the options will be taken from the method method_name, defined in the Option class.
  112.      
  113.   ■ Instruction for other scripters
  114.  
  115.       It is useful to scripters to add game options to proper scripts directly in this
  116.       settings menu, instead of creating apart.
  117.       For the scripters, the options ae divided by 8 categories:
  118.       - Generic, same defined by the user
  119.       - Appearance, like themes and wallpapers
  120.       - Audio, for music and sounds
  121.       - Game, for game options like battle speed and difficulty level
  122.       - Graphic, like screen resolution and special effects
  123.       - Commands, for game controls
  124.       - System, for techincal configurations
  125.       - Internet, for the online functionalities
  126.       The categories will have a dedicated separator automatically inserted (all but the
  127.       generic category).
  128.       To add an option in those categories, for every option you may pass the hash (defined
  129.       like the previous options) in the respective methods:
  130.       if $imported["H87_Options"]
  131.       H87Options.push_system_option(hash)
  132.       H87Options.push_generic_option(hash)
  133.       H87Options.push_game_option(hash)
  134.       H87Options.push_graphic_option(hash)
  135.       H87Options.push_sound_option(hash)
  136.       H87Options.push_appearance_option(hash)
  137.       H87Options.push_keys_option(hash)
  138.       H87Options.push_internet_option(hash)
  139.      
  140.     ● Custom popup windows
  141.       You can create custom popup windows with an option creating a subclass of
  142.       Window_OptionPopup (see below) or Generic_PopupWindow, and setting this
  143.       attribute to the option: :popup => ClassName
  144.  ==============================================================================
  145. =end
  146. $imported = {} if $imported == nil
  147. $imported["H87_Options"] = true
  148. #==============================================================================
  149. # ** CONFIGURATION
  150. #------------------------------------------------------------------------------
  151. #  Configure texts and options
  152. #==============================================================================
  153. module H87Options
  154.   #--------------------------------------------------------------------------
  155.   # * Vocab
  156.   #--------------------------------------------------------------------------
  157.   #Settings command
  158.   OPTION_COMMAND = "Settings"
  159.   #Disabled bar value:
  160.   OFF_BAR = "OFF"  
  161.   #Options ordered for category:
  162.   SYSTEM_OPTIONS =      "System"
  163.   GAME_OPTIONS =        "Game"
  164.   SOUND_OPTIONS =       "Audio"
  165.   APPEARANCE_OPTIONS =  "appearance"
  166.   GRAPHIC_OPTIONS =     "Graphic"
  167.   INTERNET_OPTIONS =    "Internet"
  168.   KEYS_OPTIONS =        "Commands"
  169.   USER_OPTIONS =        "General"
  170.   #--------------------------------------------------------------------------
  171.   # * Sound used when switch is toggled
  172.   #--------------------------------------------------------------------------
  173.   TOGGLE_SOUND = "Switch2"
  174.   #--------------------------------------------------------------------------
  175.   # * Do you want to show the settings menu in the title? There will be
  176.   #   showed only the GLOBAL options (stored in Game_Settings)
  177.   #--------------------------------------------------------------------------
  178.   SHOW_ON_TITLE = false
  179.   #--------------------------------------------------------------------------
  180.   # * Show settings menu in main menu?
  181.   #--------------------------------------------------------------------------
  182.   SHOW_ON_MENU = true
  183.   #--------------------------------------------------------------------------
  184.   # * Set here the options. See the examples to understand how create the
  185.   #   options
  186.   #--------------------------------------------------------------------------
  187.   ELEMENTS = [
  188.   #normal switch
  189.     { :type => :switch, #switch type
  190.       :text => "Switcher", #option name
  191.       :help => "This is a switch try",#showed in help
  192.       :sw   => 3, #switch ID
  193.       :on   => "ON",  #ON text
  194.       :off  => "OFF", #OFF text
  195.       :default => true, #default value (optional)
  196.     },
  197.   #separator
  198.     { :type => :separator,  #separator type
  199.       :text => "Separator",#showed text
  200.     },
  201.   #variable
  202.     { :type => :variable,   #variable type
  203.       :text => "Alarm",   #showed text
  204.       :help => "Set the alarm value", #description
  205.       :var  => 10,          #variable ID
  206.       :max  => 11,          #max value
  207.       :default => 6,        #default value
  208.     },
  209.   #another variable
  210.     { :type => :variable,   #variable type
  211.       :text => "Difficolty",#showed text
  212.       :help => "Set the game difficulty", #description
  213.       :var  => 11,          #variable
  214.       :values => ["Easy","Normal","Hard"],#values 0, 1 and 2
  215.     },
  216.   #another variable, there are so many values, so it will show a popup
  217.     { :type => :variable,   #variable type
  218.       :text => "Month",#showed text
  219.       :help => "Set the month", #description
  220.       :var  => 12,          #variable
  221.       :open_popup => true,  #use a popup instead of the line
  222.       :values => ["January", "February", "March", "April", "May",
  223.       "June", "July", "August", "September", "October", "November",
  224.       "December"],# months of the year
  225.     },
  226.   #Variable showed as a bar
  227.     { :type   => :bar, #bar type
  228.       :text   => "Filler", #showed text
  229.       :sw     => 5, #switch ON/OFF
  230.       :var    => 13,#variable ID
  231.       :color  => 10, #bar color (10 is red in the default windowskin)
  232.       :max    => 50, #max value
  233.     },
  234.   #Another bar
  235.     { :type   => :bar, #bar type
  236.       :text   => "Prowess", #showed text
  237.       :var    => 14,#variable ID
  238.       :color  => 4, #bar color (4 is blue)
  239.       :max    => 100, #max value
  240.       :default => 44,
  241.       :condition => "$game_switches[5] == false", #this option is avaiable only
  242.       # if the switch 5 is false (so if you deactivate the previous bar)
  243.     },
  244.   #Advanced option
  245.     { :type => :advanced, #special option
  246.       :method => :call_debug, #activation method, see below
  247.       :text => "Go to debug", #showed text
  248.       :condition => "$TEST", #Active only if it's a game test
  249.       :help => "Shows the debug window if it is a play test.",
  250.     },      
  251.   ] #DO NOT DELETE THIS PARENTHESIS!
  252.  
  253.   #--------------------------------------------------------------------------
  254.   # * Custom menu title configuration
  255.   # => ONLY IF YOU USE MY CUSTOM MENU TITLE!
  256.   #--------------------------------------------------------------------------
  257.   TITLE_ICON = "Icon"  #command icon
  258.   TITLE_BALOON = "Baloon" # baloon picture
  259. end
  260.  
  261. class Option
  262.   #there will be defined all the custom methods
  263.  
  264.   #for the previous example
  265.   def call_debug
  266.     SceneManager.call(Scene_Debug)
  267.   end
  268. end
  269.  
  270. #==============================================================================
  271. # ** END OF CONFIGURATION
  272. #------------------------------------------------------------------------------
  273. #                 - WARNING: DO NOT EDIT BELOW! -
  274. #==============================================================================
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281. #==============================================================================
  282. # ** Modulo H87Options
  283. #------------------------------------------------------------------------------
  284. #  Modulo di gestione delle opzioni
  285. #==============================================================================
  286. module H87Options
  287.   #--------------------------------------------------------------------------
  288.   # * Restituisce le opzioni di gioco
  289.   #--------------------------------------------------------------------------
  290.   def self.game_options
  291.     return @game.nil? ? [] : @game
  292.   end
  293.   #--------------------------------------------------------------------------
  294.   # * Restituisce le opzioni definite dall'utente
  295.   #--------------------------------------------------------------------------
  296.   def self.user_options
  297.     return ELEMENTS + generic_options
  298.   end
  299.   #--------------------------------------------------------------------------
  300.   # * Restituisce le opzioni generali
  301.   #--------------------------------------------------------------------------
  302.   def self.generic_options
  303.     return @generic.nil? ? [] : @generic
  304.   end
  305.   #--------------------------------------------------------------------------
  306.   # * Restituisce le opzioni grafiche
  307.   #--------------------------------------------------------------------------
  308.   def self.graphic_options
  309.     return @graphic.nil? ? [] : @graphic
  310.   end
  311.   #--------------------------------------------------------------------------
  312.   # * Restituisce le opzioni di sistema
  313.   #--------------------------------------------------------------------------
  314.   def self.system_options
  315.     return @system.nil? ? [] : @system
  316.   end
  317.   #--------------------------------------------------------------------------
  318.   # * Restituisce le opzioni audio
  319.   #--------------------------------------------------------------------------
  320.   def self.sound_options
  321.     return @sound.nil? ? [] : @sound
  322.   end
  323.   #--------------------------------------------------------------------------
  324.   # * Restituisce le opzioni dei comandi
  325.   #--------------------------------------------------------------------------
  326.   def self.keys_options
  327.     return @keys.nil? ? [] : @keys
  328.   end
  329.   #--------------------------------------------------------------------------
  330.   # * Restituisce le opzioni internet
  331.   #--------------------------------------------------------------------------
  332.   def self.internet_options
  333.     return @internet.nil? ? [] : @internet
  334.   end
  335.   #--------------------------------------------------------------------------
  336.   # * Restituisce le opzioni d'aspetto
  337.   #--------------------------------------------------------------------------
  338.   def self.appearance_options
  339.     return @appearance.nil? ? [] : @appearance
  340.   end
  341.   #--------------------------------------------------------------------------
  342.   # * Restituisce tutte le opzioni
  343.   #--------------------------------------------------------------------------
  344.   def self.all_options
  345.     return user_options + game_options + appearance_options + graphic_options +
  346.     sound_options + keys_options + system_options + internet_options
  347.   end
  348.   #--------------------------------------------------------------------------
  349.   # * Aggiunge le opzioni di sistema
  350.   #--------------------------------------------------------------------------
  351.   def self.push_system_option(hash)
  352.     if @system.nil?
  353.       @system = [{:type=> :separator, :text=> SYSTEM_OPTIONS}]
  354.     end
  355.     @system.push(hash)
  356.   end
  357.   #--------------------------------------------------------------------------
  358.   # * Aggiunge le opzioni dei comandi
  359.   #--------------------------------------------------------------------------
  360.   def self.push_keys_option(hash)
  361.     if @keys.nil?
  362.       @keys = [{:type=> :separator, :text=> KEYS_OPTIONS}]
  363.     end
  364.     @keys.push(hash)
  365.   end
  366.   #--------------------------------------------------------------------------
  367.   # * Aggiunge le opzioni generiche
  368.   #--------------------------------------------------------------------------
  369.   def self.push_generic_option(hash)
  370.     @generic = [] if @generic.nil?
  371.     @generic.push(hash)
  372.   end
  373.   #--------------------------------------------------------------------------
  374.   # * Aggiunge le opzioni d'aspetto
  375.   #--------------------------------------------------------------------------
  376.   def self.push_appearance_option(hash)
  377.     if @appearance.nil?
  378.       @appearance = [{ :type=> :separator,:text=> APPEARANCE_OPTIONS}]
  379.     end
  380.     @appearance.push(hash)
  381.   end
  382.   #--------------------------------------------------------------------------
  383.   # * Aggiunge le opzioni di gioco
  384.   #--------------------------------------------------------------------------
  385.   def self.push_game_option(hash)
  386.     if @game.nil?
  387.       @game = [{:type=> :separator, :text=> GAME_OPTIONS}]
  388.     end
  389.     @game.push(hash)
  390.   end
  391.   #--------------------------------------------------------------------------
  392.   # * Aggiunge le opzioni audio
  393.   #--------------------------------------------------------------------------
  394.   def self.push_sound_option(hash)
  395.     if @sound.nil?
  396.       @sound = [{ :type=> :separator, :text=> SOUND_OPTIONS}]
  397.     end
  398.     @sound.push(hash)
  399.   end
  400.   #--------------------------------------------------------------------------
  401.   # * Aggiunge le opzioni grafiche
  402.   #--------------------------------------------------------------------------
  403.   def self.push_graphic_option(hash)
  404.     if @graphic.nil?
  405.       @graphic = [{ :type=> :separator, :text=> GRAPHIC_OPTIONS}]
  406.     end
  407.     @graphic.push(hash)
  408.   end
  409.   #--------------------------------------------------------------------------
  410.   # * Aggiunge le opzioni internet
  411.   #--------------------------------------------------------------------------
  412.   def self.push_internet_option(hash)
  413.     if @internet.nil?
  414.       @internet = [{ :type=> :separator, :text=> INTERNET_OPTIONS}]
  415.     end
  416.     @internet.push(hash)
  417.   end
  418.   #--------------------------------------------------------------------------
  419.   # * Restituisce la lista delle opzioni
  420.   #--------------------------------------------------------------------------
  421.   def self.option_list
  422.     options = []
  423.     for option in all_options
  424.       opt = Option.new(option)
  425.       next if opt.for_game? and $game_temp.nil? || $game_temp.in_game == false
  426.       options.push(opt)
  427.     end
  428.     return options
  429.   end
  430. end
  431.  
  432. #==============================================================================
  433. # ** classe Scene_Menu
  434. #------------------------------------------------------------------------------
  435. #  Aggiunta del comando Opzioni
  436. #==============================================================================
  437. class Scene_Menu < Scene_MenuBase
  438.   alias h87options_create_command_window create_command_window unless $@
  439.   #--------------------------------------------------------------------------
  440.   # * Finestra comandi
  441.   #--------------------------------------------------------------------------
  442.   def create_command_window
  443.     h87options_create_command_window
  444.     @command_window.set_handler(:options, method(:command_options))
  445.   end
  446.   #--------------------------------------------------------------------------
  447.   # * Vai alle opzioni
  448.   #--------------------------------------------------------------------------
  449.   def command_options
  450.     $game_temp.in_game = true
  451.     SceneManager.call(Scene_Options)
  452.   end
  453. end
  454.  
  455. #==============================================================================
  456. # ** Classe Window_MenuCommand
  457. #------------------------------------------------------------------------------
  458. #  Aggiunta del comando Opzioni
  459. #==============================================================================
  460. class Window_MenuCommand < Window_Command
  461.   alias h87options_aoc add_original_commands unless $@
  462.   #--------------------------------------------------------------------------
  463.   # * Aggiunta del comando
  464.   #--------------------------------------------------------------------------
  465.   def add_original_commands
  466.     h87options_aoc
  467.     if H87Options::SHOW_ON_MENU
  468.       add_command(H87Options::OPTION_COMMAND, :options, true)
  469.     end
  470.   end
  471. end
  472.  
  473. #==============================================================================
  474. # ** classe Scene_Title
  475. #------------------------------------------------------------------------------
  476. #  Aggiunta del comando per andare alle opzioni
  477. #==============================================================================
  478. class Scene_Title < Scene_Base
  479.   alias h87options_create_command_window create_command_window unless $@
  480.   #--------------------------------------------------------------------------
  481.   # * Aggiunta dell'evento
  482.   #--------------------------------------------------------------------------
  483.   def create_command_window
  484.     h87options_create_command_window
  485.     @command_window.set_handler(:options, method(:command_options))
  486.   end
  487.   #--------------------------------------------------------------------------
  488.   # * Comando per le opzioni
  489.   #--------------------------------------------------------------------------
  490.   def command_options
  491.     $game_temp.in_game = false
  492.     SceneManager.call(Scene_Options)
  493.   end
  494.   #--------------------------------------------------------------------------
  495.   # * Aggiunta del comando del menu titolo personalizzato
  496.   #--------------------------------------------------------------------------
  497.   if $imported["H87_TitleMenu"]
  498.   alias h87options_ccp crea_contenuti_personalizzati
  499.   def crea_contenuti_personalizzati
  500.     h87options_ccp
  501.     if H87Options::SHOW_ON_TITLE
  502.       add_cursor(:options,:command_options,H87Options::TITLE_ICON,H87Options::TITLE_BALOON)
  503.     end
  504.   end;end
  505. end
  506.  
  507. #==============================================================================
  508. # ** Classe Window_TitleCommand
  509. #------------------------------------------------------------------------------
  510. #  Aggiunta del comando Opzioni
  511. #==============================================================================
  512. class Window_TitleCommand < Window_Command
  513.   alias h87options_aoc make_command_list unless $@
  514.   #--------------------------------------------------------------------------
  515.   # * Aggiunta del comando
  516.   #--------------------------------------------------------------------------
  517.   def make_command_list
  518.     h87options_aoc
  519.     if H87Options::SHOW_ON_TITLE
  520.       add_command(H87Options::OPTION_COMMAND, :options, true)
  521.     end
  522.   end
  523. end
  524.  
  525. #==============================================================================
  526. # ** DataManager
  527. #------------------------------------------------------------------------------
  528. #  Modifica del caricamento iniziale
  529. #==============================================================================
  530. module DataManager
  531.   class << self
  532.     alias h87options_lnd load_normal_database
  533.   end
  534.   #--------------------------------------------------------------------------
  535.   # * Alias caricamento DB
  536.   #--------------------------------------------------------------------------
  537.   def self.load_normal_database
  538.     h87options_lnd
  539.     initialize_options
  540.   end
  541.   #--------------------------------------------------------------------------
  542.   # * Inizializza le variabili globali
  543.   #--------------------------------------------------------------------------
  544.   def self.initialize_options
  545.     for option in H87Options.option_list
  546.       next if $game_settings[option.id] != nil
  547.       next if option.value != nil
  548.       option.value = option.default if option.default != nil
  549.       option.toggle if option.type == :bar
  550.     end
  551.   end
  552. end
  553.  
  554. #==============================================================================
  555. # ** Classe Option
  556. #------------------------------------------------------------------------------
  557. #  Contiene le impostazioni della singola opzione di gioco
  558. #==============================================================================
  559. class Option
  560.   #--------------------------------------------------------------------------
  561.   # * Variabili d'istanza pubblici
  562.   #--------------------------------------------------------------------------
  563.   attr_reader :type         #tipo
  564.   attr_reader :description  #descrizione
  565.   attr_reader :name         #nome
  566.   attr_reader :values       #elenco valori
  567.   attr_reader :max          #massimo della variabile
  568.   attr_reader :default      #valore predefinito
  569.   attr_reader :value_method #metodo che restituisce il valore
  570.   attr_reader :bar_color    #colore della barra
  571.   attr_reader :tag          #etichetta (per salvataggio in game_settings)
  572.   #--------------------------------------------------------------------------
  573.   # * Inizializzazione
  574.   #--------------------------------------------------------------------------
  575.   def initialize(hash)
  576.     @type = hash[:type]
  577.     @description = hash[:help]
  578.     @name = hash[:text]
  579.     @for_game = hash[:in_game]
  580.     @tag = hash[:tag]
  581.     @default = hash[:default]
  582.     case @type
  583.     when :switch; init_switch(hash)
  584.     when :variable; init_variable(hash)
  585.     when :separator; init_separator(hash)
  586.     when :advanced; init_advanced(hash)
  587.     when :bar; init_bar(hash)
  588.     end
  589.     @method = hash[:method]
  590.     @value_method = hash[:val_mt] unless hash[:val_mt].nil?
  591.     @special_draw = hash[:special] unless hash[:special].nil?
  592.     @enabled_condition = hash[:condition] unless hash[:condition].nil?
  593.   end
  594.   #--------------------------------------------------------------------------
  595.   # * Inizializza gli attributi dello switch
  596.   #--------------------------------------------------------------------------
  597.   def init_switch(hash)
  598.     @default = false if @default.nil?
  599.     @switch = hash[:sw]
  600.     @values = [hash[:off], hash[:on]]
  601.   end
  602.   #--------------------------------------------------------------------------
  603.   # * Inizializza gli attributi della variabile
  604.   #--------------------------------------------------------------------------
  605.   def init_variable(hash)
  606.     @distance = hash[:distance].nil? ? 1 : hash[:distance]
  607.     @variable = hash[:var]
  608.     @need_popup = hash[:open_popup]
  609.     @popup = eval(hash[:popup]) if hash[:popup]
  610.     @default = 0 if @default.nil?
  611.     if hash[:values].nil?
  612.       @values = []
  613.       @max = hash[:max]
  614.       for i in 0..@max
  615.         @values.push(i)
  616.       end
  617.     else
  618.       @values = hash[:values]
  619.       @max = @values.size
  620.     end
  621.   end
  622.   #--------------------------------------------------------------------------
  623.   # * Inizializza gli attributi del separatore
  624.   #--------------------------------------------------------------------------
  625.   def init_separator(hash)
  626.   end
  627.   #--------------------------------------------------------------------------
  628.   # * Inizializza gli attributi dell'oggetto avanzato
  629.   #--------------------------------------------------------------------------
  630.   def init_advanced(hash)
  631.     @popup = eval(hash[:popup]) if hash[:popup]
  632.   end
  633.   #--------------------------------------------------------------------------
  634.   # * Inizializza gli attributi della barra
  635.   #--------------------------------------------------------------------------
  636.   def init_bar(hash)
  637.     @max = hash[:max]
  638.     @variable = hash[:var]
  639.     @default = 0 if @default.nil?
  640.     @switch = hash[:sw] if hash[:sw] != nil
  641.     @distance = hash[:distance].nil? ? 1 : hash[:distance]
  642.     @bar_color = hash[:color]
  643.   end
  644.   #--------------------------------------------------------------------------
  645.   # * Restituisce il valore dell'opzione
  646.   #--------------------------------------------------------------------------
  647.   def value
  648.     return method(@value_method).call if @value_method != nil
  649.     case @type
  650.     when :switch
  651.       return switch
  652.     when :variable, :bar
  653.       return variable
  654.     end
  655.   end
  656.   #--------------------------------------------------------------------------
  657.   # * Imposta il valore dell'opzione
  658.   #--------------------------------------------------------------------------
  659.   def value=(new_value)
  660.     method(@method).call(new_value) if @method
  661.     case @type
  662.     when :switch
  663.       set_switch(new_value)
  664.     when :variable, :bar
  665.       set_variable(new_value)
  666.     end
  667.   end
  668.   #--------------------------------------------------------------------------
  669.   # * Cambia lo stato della switch
  670.   #--------------------------------------------------------------------------
  671.   def toggle
  672.     set_switch(!self.switch) if @switch
  673.   end
  674.   #--------------------------------------------------------------------------
  675.   # * Incrementa il valore dell'opzione
  676.   #--------------------------------------------------------------------------
  677.   def increment
  678.     if @type == :switch
  679.       toggle
  680.     else
  681.       set_switch(true)
  682.       self.value += @distance
  683.       if :variable
  684.         self.value = 0 if self.value > @max
  685.       else
  686.         self.value = @max if self.value > @max
  687.       end
  688.     end
  689.   end
  690.   #--------------------------------------------------------------------------
  691.   # * Decrementa il valore dell'opzione
  692.   #--------------------------------------------------------------------------
  693.   def decrement
  694.     if @type == :switch
  695.       toggle
  696.     else
  697.       set_switch(true)
  698.       self.value -= @distance
  699.       if :variable
  700.         self.value = @max if self.value < 0
  701.       else
  702.         self.value = 0 if self.value < 0
  703.       end
  704.     end
  705.   end
  706.   #--------------------------------------------------------------------------
  707.   # * Restituisce la classe della finestra di popup
  708.   #--------------------------------------------------------------------------
  709.   def popup
  710.     return @popup if @popup
  711.     return Generic_PopupWindow if @need_popup
  712.     return nil
  713.   end
  714.   #--------------------------------------------------------------------------
  715.   # * Restituisce l'ID dello switch o variabile assegnato
  716.   #--------------------------------------------------------------------------
  717.   def id
  718.     return @variable if @variable != nil
  719.     return @switch if @switch != nil
  720.     return @tag
  721.   end
  722.   #--------------------------------------------------------------------------
  723.   # * Restituisce lo stato della switch
  724.   #--------------------------------------------------------------------------
  725.   def switch
  726.     return true if @switch.nil?
  727.     return true if @switch == 0
  728.     if @switch.is_a?(Integer)
  729.       return $game_switches[@switch]
  730.     else
  731.       return $game_settings[@switch]
  732.     end
  733.   end
  734.   #--------------------------------------------------------------------------
  735.   # * Imposta lo stato della switch
  736.   #--------------------------------------------------------------------------
  737.   def set_switch(value)
  738.     return if @switch.nil?
  739.     return if @switch == 0
  740.     if @switch.is_a?(Integer)
  741.       $game_switches[@switch] = value
  742.     else
  743.       $game_settings[@switch] = value
  744.     end
  745.   end
  746.   #--------------------------------------------------------------------------
  747.   # * Restituisce lo stato della variabile
  748.   #--------------------------------------------------------------------------
  749.   def variable
  750.     return 0 if @variable == 0
  751.     if @variable.is_a?(Integer)
  752.       return $game_variables[@variable]
  753.     else
  754.       return $game_settings[@variable]
  755.     end
  756.   end
  757.   #--------------------------------------------------------------------------
  758.   # * Imposta lo stato della variabile
  759.   #--------------------------------------------------------------------------
  760.   def set_variable(value)
  761.     return if @variable == 0
  762.     if @variable.is_a?(Integer)
  763.       $game_variables[@variable] = value
  764.     else
  765.       $game_settings[@variable] = value
  766.     end
  767.   end
  768.   #--------------------------------------------------------------------------
  769.   # * Restituisce true se l'opzione ha una switch
  770.   #--------------------------------------------------------------------------
  771.   def toggable?
  772.     return @switch != nil
  773.   end
  774.   #--------------------------------------------------------------------------
  775.   # * Restituisce le condizioni di abilitazione dell'opzione
  776.   #--------------------------------------------------------------------------
  777.   def enabled?
  778.     if $game_system != nil && self.tag != nil &&
  779.       $game_system.enabling_options[self.tag] == false
  780.       return false
  781.     end
  782.     return true if @enabled_condition.nil?
  783.     return eval(@enabled_condition)
  784.   end
  785.   #--------------------------------------------------------------------------
  786.   # * Restituisce true se è un separatore
  787.   #--------------------------------------------------------------------------
  788.   def separator?
  789.     return @type == :separator
  790.   end
  791.   #--------------------------------------------------------------------------
  792.   # * Restituisce true se è un'opzione disponibile solo nella partita
  793.   #   (ossia, non visibile nella schermata del titolo)
  794.   #--------------------------------------------------------------------------
  795.   def for_game?
  796.     return true if @variable.is_a?(Integer)
  797.     return true if @switch.is_a?(Integer)
  798.     return true if @for_game
  799.     return false
  800.   end
  801.   #--------------------------------------------------------------------------
  802.   # * Restituisce true se l'opzione apre un popup
  803.   #--------------------------------------------------------------------------
  804.   def open_popup?
  805.     return self.popup != nil
  806.   end
  807.   #--------------------------------------------------------------------------
  808.   # * Restituisce true se l'opzione è disponibile e configurabile
  809.   #--------------------------------------------------------------------------
  810.   def value_active?(value_index)
  811.     if @type == :switch
  812.       return value_index == 1 && value ? true : false
  813.     elsif @type == :variable
  814.       return value == value_index * @distance
  815.     else
  816.       return true
  817.     end
  818.   end
  819.   #--------------------------------------------------------------------------
  820.   # * Restituisce true se l'opzione è attiva
  821.   #--------------------------------------------------------------------------
  822.   def is_on?
  823.     return self.switch
  824.   end
  825.   #--------------------------------------------------------------------------
  826.   # * Restituisc true se l'opzione può essere decrementata
  827.   #--------------------------------------------------------------------------
  828.   def can_decrement?
  829.     return false if @type == :bar && self.value <= 0
  830.     return false if @need_popup
  831.     return true
  832.   end
  833.   #--------------------------------------------------------------------------
  834.   # * Restituisce true se l'opzione può essere incrementata
  835.   #--------------------------------------------------------------------------
  836.   def can_increment?
  837.     return false if @type == :bar && self.value >= self.max
  838.     return false if @need_popup
  839.     return true
  840.   end
  841.   #--------------------------------------------------------------------------
  842.   # * Esegue il metodo personalizzato dell'opzione
  843.   #--------------------------------------------------------------------------
  844.   def execute_method
  845.     return unless @method
  846.     method(@method).call
  847.   end
  848. end
  849.  
  850. #==============================================================================
  851. # ** Scene_Options
  852. #------------------------------------------------------------------------------
  853. #  Schermata delle opzioni
  854. #==============================================================================
  855. class Scene_Options < Scene_MenuBase
  856.   #--------------------------------------------------------------------------
  857.   # * Inizio
  858.   #--------------------------------------------------------------------------
  859.   def start
  860.     super
  861.     create_help_window
  862.     create_option_window
  863.     create_popup_windows
  864.   end
  865.   #--------------------------------------------------------------------------
  866.   # * Aggiornamento
  867.   #--------------------------------------------------------------------------
  868.   def update
  869.     super
  870.     update_popups
  871.   end
  872.   #--------------------------------------------------------------------------
  873.   # * Fine
  874.   #--------------------------------------------------------------------------
  875.   def terminate
  876.     super
  877.     dispose_popups
  878.   end
  879.   #--------------------------------------------------------------------------
  880.   # * Aggiorna le finestre di popup
  881.   #--------------------------------------------------------------------------
  882.   def update_popups
  883.     @popups.each_value{|p| p.update}
  884.   end
  885.   #--------------------------------------------------------------------------
  886.   # * Elimina le finestre di popup
  887.   #--------------------------------------------------------------------------
  888.   def dispose_popups
  889.     @popups.each_value{|p| p.dispose}
  890.   end
  891.   #--------------------------------------------------------------------------
  892.   # * Creazione della finestra d'aiuto
  893.   #--------------------------------------------------------------------------
  894.   def create_help_window
  895.     @help_window = Window_Help.new
  896.   end
  897.   #--------------------------------------------------------------------------
  898.   # * Creazione della finestra delle opzioni
  899.   #--------------------------------------------------------------------------
  900.   def create_option_window
  901.     @option_window = Window_GameOptions.new(@help_window.y + @help_window.height)
  902.     @option_window.help_window = @help_window
  903.     @option_window.set_handler(:cancel, method(:return_scene))
  904.     @option_window.activate
  905.   end
  906.   #--------------------------------------------------------------------------
  907.   # * Crea le finestre di popup
  908.   #--------------------------------------------------------------------------
  909.   def create_popup_windows
  910.     @popups = {}
  911.     opt = H87Options.option_list
  912.     y = @help_window.height
  913.     for i in 0..opt.size-1
  914.       if opt[i].popup
  915.         popup = opt[i].popup.new(y, opt[i])
  916.         popup.visible = false
  917.         popup.set_handler(:cancel, method(:close_popup))
  918.         popup.set_handler(:ok, method(:item_selected))
  919.         @popups[i] = popup
  920.       end
  921.     end
  922.   end  
  923.   #--------------------------------------------------------------------------
  924.   # * Restituisce la finestra di popup attualmente aperta
  925.   #--------------------------------------------------------------------------
  926.   def popup
  927.     return @popups[@popup_index]
  928.   end
  929.   #--------------------------------------------------------------------------
  930.   # * Mostra la finestra di popup
  931.   #   index: indice dell'opzione
  932.   #--------------------------------------------------------------------------
  933.   def show_popup(index)
  934.     @last_frame = Graphics.frame_count
  935.     @popup_index = index
  936.     x = Graphics.width - popup.width
  937.     y = @help_window.height
  938.     popup.x = Graphics.width
  939.     popup.visible = true
  940.     if $imported["H87_SmoothMovements"]
  941.       @option_window.smooth_move(0 - popup.width, y)
  942.       popup.smooth_move(x, y)
  943.     else
  944.       @option_window.x = 0 - popup.width
  945.       popup.x = x
  946.     end
  947.     popup.activate
  948.   end
  949.   #--------------------------------------------------------------------------
  950.   # * Viene eseguito quando l'utente seleziona un'opzione dal popup
  951.   #--------------------------------------------------------------------------
  952.   def item_selected
  953.     if @last_frame < Graphics.frame_count
  954.       @option_window.item.value = popup.selected_value
  955.       @option_window.refresh
  956.       close_popup
  957.     else
  958.       popup.activate
  959.     end
  960.   end
  961.   #--------------------------------------------------------------------------
  962.   # * Chiude la finestra di popup
  963.   #--------------------------------------------------------------------------
  964.   def close_popup
  965.     popup.deactivate
  966.     x = Graphics.width
  967.     y = @help_window.height
  968.     if $imported["H87_SmoothMovements"]
  969.       @option_window.smooth_move(0, y)
  970.       popup.smooth_move(x, y)
  971.     else
  972.       @option_window.x = 0
  973.       popup.x = x
  974.     end
  975.     @option_window.activate
  976.     @popup_index = nil
  977.   end
  978. end
  979.  
  980. #==============================================================================
  981. # ** Window_GameOptions
  982. #------------------------------------------------------------------------------
  983. #  Finestra che contiene l'elenco delle opzioni
  984. #==============================================================================
  985. class Window_GameOptions < Window_Selectable
  986.   #--------------------------------------------------------------------------
  987.   # * Inizializzazione
  988.   #   y: coordinata Y iniziale
  989.   #--------------------------------------------------------------------------
  990.   def initialize(y)
  991.     super(0, y, Graphics.width, Graphics.height - y)
  992.     @data = []
  993.     make_option_list
  994.     create_contents
  995.     refresh
  996.     self.index = 0
  997.     cursor_down if item && item.separator?
  998.   end
  999.   #--------------------------------------------------------------------------
  1000.   # * draw_item
  1001.   #   index: indice dell
  1002.   #--------------------------------------------------------------------------
  1003.   def draw_item(index)
  1004.     item = @data[index]
  1005.     if item
  1006.       rect = item_rect(index)
  1007.       rect.width -= 4
  1008.       draw_item_name(item, rect.x, rect.y, enable?(item))
  1009.       draw_item_state(rect, item)
  1010.     end
  1011.   end
  1012.   #--------------------------------------------------------------------------
  1013.   # * Draw Item Name
  1014.   #     enabled : Enabled flag. When false, draw semi-transparently.
  1015.   #--------------------------------------------------------------------------
  1016.   def draw_item_name(item, x, y, enabled = true, width = 172)
  1017.     return unless item
  1018.     change_color(normal_color, enabled)
  1019.     draw_text(x, y, width, line_height, item.name) unless item.separator?
  1020.   end
  1021.   #--------------------------------------------------------------------------
  1022.   # * Mostra lo stato dell'opzione a seconda del tipo
  1023.   #--------------------------------------------------------------------------
  1024.   def draw_item_state(rect, item)
  1025.     case item.type
  1026.     when :separator
  1027.       draw_separator(rect, item)
  1028.     when :switch
  1029.       draw_switch(rect, item)
  1030.     when :variable
  1031.       draw_variable(rect, item)
  1032.     when :bar
  1033.       draw_bar(rect, item)
  1034.     when :advanced
  1035.       draw_advanced(rect, item)
  1036.     end
  1037.   end
  1038.   #--------------------------------------------------------------------------
  1039.   # * Disegna il separatore
  1040.   #--------------------------------------------------------------------------
  1041.   def draw_separator(rect, item)
  1042.     color = gauge_back_color
  1043.     color.alpha = 128
  1044.     contents.fill_rect(rect.x, rect.y+2, rect.width, rect.height-4, color)
  1045.     draw_text(rect.x, rect.y, rect.width, line_height, item.name, 1)
  1046.   end
  1047.   #--------------------------------------------------------------------------
  1048.   # * Move Cursor Down
  1049.   #--------------------------------------------------------------------------
  1050.   def cursor_down(wrap = false)
  1051.     super
  1052.     super if item.separator?
  1053.   end
  1054.   #--------------------------------------------------------------------------
  1055.   # * Move Cursor Up
  1056.   #--------------------------------------------------------------------------
  1057.   def cursor_up(wrap = false)
  1058.     super
  1059.     super if item.separator?
  1060.   end
  1061.   #--------------------------------------------------------------------------
  1062.   # * Disegna lo switch
  1063.   #--------------------------------------------------------------------------
  1064.   def draw_switch(rect, item)
  1065.     x = get_state_x(rect)
  1066.     width = get_state_width(x, rect, item)
  1067.     change_color(normal_color, enable?(item) && !item.value)
  1068.     contents.draw_text(x, rect.y, width, line_height, item.values[0], 1)
  1069.     x += width
  1070.     change_color(normal_color, enable?(item) && item.value)
  1071.     contents.draw_text(x, rect.y, width, line_height, item.values[1], 1)
  1072.   end
  1073.   #--------------------------------------------------------------------------
  1074.   # * Disegna la variabile
  1075.   #--------------------------------------------------------------------------
  1076.   def draw_variable(rect, item)
  1077.     unless item.open_popup?
  1078.       draw_values_variable(rect, item)
  1079.     else
  1080.       draw_popup_variable(rect, item)
  1081.     end
  1082.   end
  1083.   #--------------------------------------------------------------------------
  1084.   # * Disegna la variabile se apre un popup
  1085.   #--------------------------------------------------------------------------
  1086.   def draw_popup_variable(rect, item)
  1087.     x = get_state_x(rect)
  1088.     width = rect.width - x
  1089.     change_color(normal_color, enable?(item))
  1090.     draw_text(x, rect.y, width, line_height, item.values[item.value], 1)
  1091.   end
  1092.   #--------------------------------------------------------------------------
  1093.   # * Disegna i valori della variabile
  1094.   #--------------------------------------------------------------------------
  1095.   def draw_values_variable(rect, item)
  1096.     x = get_state_x(rect)
  1097.     width = get_state_width(x, rect, item)
  1098.     for i in 0..item.max
  1099.       next if item.values[i].nil?
  1100.       change_color(normal_color, enable?(item) && item.value_active?(i))
  1101.       draw_text(x+(width*i), rect.y, width, line_height, item.values[i], 1)
  1102.     end
  1103.   end
  1104.   #--------------------------------------------------------------------------
  1105.   # * Disegna la barra
  1106.   #--------------------------------------------------------------------------
  1107.   def draw_bar(rect, item)
  1108.     x = get_state_x(rect)
  1109.     width = rect.width - x
  1110.     color = text_color(item.bar_color)
  1111.     color.alpha = enable?(item) ? 255 : 128
  1112.     contents.fill_rect(x, rect.y+5, width, line_height-10, color)
  1113.     contents.clear_rect(x+1, rect.y+6, width-2, line_height-12)
  1114.     rate = item.value/item.max.to_f
  1115.     contents.fill_rect(x, rect.y+5, width*rate, line_height-10, color)
  1116.     if item.is_on?
  1117.       change_color(normal_color, enable?(item))
  1118.       text = sprintf("%2d%%",rate*100)
  1119.     else
  1120.       change_color(power_down_color, enable?(item))
  1121.       text = H87Options::OFF_BAR
  1122.     end
  1123.     draw_text(x, rect.y, width, line_height, text, 1)
  1124.   end
  1125.   #--------------------------------------------------------------------------
  1126.   # * Disegna il valore del metodo avanzato
  1127.   #--------------------------------------------------------------------------
  1128.   def draw_advanced(rect, item)
  1129.   end
  1130.   #--------------------------------------------------------------------------
  1131.   # * Update Help Text
  1132.   #--------------------------------------------------------------------------
  1133.   def update_help
  1134.     @help_window.set_item(item)
  1135.   end
  1136.   #--------------------------------------------------------------------------
  1137.   # * Creazione della lista delle opzioni
  1138.   #--------------------------------------------------------------------------
  1139.   def make_option_list
  1140.     @data = H87Options.option_list
  1141.   end
  1142.   #--------------------------------------------------------------------------
  1143.   # * Get Number of Items
  1144.   #--------------------------------------------------------------------------
  1145.   def item_max
  1146.     @data ? @data.size : 0
  1147.   end
  1148.   #--------------------------------------------------------------------------
  1149.   # * Display in Enabled State?
  1150.   #--------------------------------------------------------------------------
  1151.   def enable?(item)
  1152.     item.enabled?
  1153.   end
  1154.   #--------------------------------------------------------------------------
  1155.   # * Restituisce l'opzione selezionata
  1156.   #--------------------------------------------------------------------------
  1157.   def item
  1158.     return @data[index]
  1159.   end
  1160.   #--------------------------------------------------------------------------
  1161.   # * Restituisce la coordinata X dove disegnare lo stato
  1162.   #--------------------------------------------------------------------------
  1163.   def get_state_x(rect)
  1164.     return rect.x + rect.width / 2
  1165.   end
  1166.   #--------------------------------------------------------------------------
  1167.   # * Restituisce la larghezza del valore in caso di più valori
  1168.   #--------------------------------------------------------------------------
  1169.   def get_state_width(x, rect, item)
  1170.     return (rect.width - x) / item.values.size
  1171.   end
  1172.   #--------------------------------------------------------------------------
  1173.   # * Esecuzione dell'azione di selezione (INVIO)
  1174.   #--------------------------------------------------------------------------
  1175.   def action
  1176.     case item.type
  1177.     when :switch, :bar
  1178.       toggle_item
  1179.     when :advanced
  1180.       process_method
  1181.     when :variable
  1182.       open_popup
  1183.     end
  1184.   end
  1185.   #--------------------------------------------------------------------------
  1186.   # * Cambia lo stato della switch dell'opzione
  1187.   #--------------------------------------------------------------------------
  1188.   def toggle_item
  1189.     return unless item.toggable?
  1190.     item.toggle
  1191.     RPG::SE.new(H87Options::TOGGLE_SOUND).play
  1192.     refresh
  1193.     activate
  1194.   end
  1195.   #--------------------------------------------------------------------------
  1196.   # * Chiama il metodo
  1197.   #--------------------------------------------------------------------------
  1198.   def process_method
  1199.     item.execute_method
  1200.     open_popup
  1201.   end
  1202.   #--------------------------------------------------------------------------
  1203.   # * Apre il popup
  1204.   #--------------------------------------------------------------------------
  1205.   def open_popup
  1206.     return unless item.popup
  1207.     Sound.play_ok
  1208.     SceneManager.scene.show_popup(self.index)
  1209.     deactivate
  1210.   end
  1211.   #--------------------------------------------------------------------------
  1212.   # * Aggiornamento
  1213.   #--------------------------------------------------------------------------
  1214.   def update
  1215.     return if disposed?
  1216.     super
  1217.     update_other_commands
  1218.   end
  1219.   #--------------------------------------------------------------------------
  1220.   # * Aggiorna gli altri comandi
  1221.   #--------------------------------------------------------------------------
  1222.   def update_other_commands
  1223.     return unless active && cursor_movable?
  1224.     shift_left if Input.repeat?(:LEFT) && item.can_decrement? && enable?(item)
  1225.     shift_right if Input.repeat?(:RIGHT) && item.can_increment? && enable?(item)
  1226.     action if Input.trigger?(:C) && enable?(item)
  1227.   end
  1228.   #--------------------------------------------------------------------------
  1229.   # * Scorri a sinistra se è una variabile o una barra
  1230.   #--------------------------------------------------------------------------
  1231.   def shift_left
  1232.     item.decrement
  1233.     Sound.play_cursor
  1234.     refresh
  1235.   end
  1236.   #--------------------------------------------------------------------------
  1237.   # * Scorri a destra se è una variabile o una barra
  1238.   #--------------------------------------------------------------------------
  1239.   def shift_right
  1240.     item.increment
  1241.     Sound.play_cursor
  1242.     refresh
  1243.   end
  1244. end
  1245.  
  1246. #==============================================================================
  1247. # ** Window_OptionPopup
  1248. #------------------------------------------------------------------------------
  1249. #  Classe d'appoggio per le finestre di popup
  1250. #==============================================================================
  1251. class Window_OptionPopup < Window_Selectable
  1252.   #--------------------------------------------------------------------------
  1253.   # * Inizializzazione
  1254.   #--------------------------------------------------------------------------
  1255.   def initialize(y, option, width = 200)
  1256.     super(Graphics.width, y, width, Graphics.height - y)
  1257.     @option = option
  1258.     @data = []
  1259.     refresh
  1260.     select_last
  1261.   end
  1262.   #--------------------------------------------------------------------------
  1263.   # * Refresh
  1264.   #--------------------------------------------------------------------------
  1265.   def refresh
  1266.     make_option_list
  1267.     create_contents
  1268.     draw_all_items
  1269.   end
  1270.   #--------------------------------------------------------------------------
  1271.   # * Ottiene la lista delle opzioni dei valori
  1272.   #--------------------------------------------------------------------------
  1273.   def make_option_list
  1274.   end  
  1275.   #--------------------------------------------------------------------------
  1276.   # * Restituisce il numero di oggetti
  1277.   #--------------------------------------------------------------------------
  1278.   def item_max
  1279.     return @data.nil? ? 0 : @data.size
  1280.   end
  1281.   #--------------------------------------------------------------------------
  1282.   # * Restituisce l'opzione selezionata
  1283.   #--------------------------------------------------------------------------
  1284.   def select_last
  1285.   end
  1286.   #--------------------------------------------------------------------------
  1287.   # * Restituisce la nuova opzione selezionata dall'utente
  1288.   #--------------------------------------------------------------------------
  1289.   def selected_value
  1290.     return @keys ? @keys[self.index] : self.index
  1291.   end
  1292. end
  1293.  
  1294. #==============================================================================
  1295. # ** Generic_PopupWindow
  1296. #------------------------------------------------------------------------------
  1297. #  Finestra dei popup generici delle opzioni
  1298. #==============================================================================
  1299. class Generic_PopupWindow < Window_OptionPopup
  1300.   #--------------------------------------------------------------------------
  1301.   # * Inizializzazione
  1302.   #   y: coordinata Y
  1303.   #   option: opzione del popup
  1304.   #--------------------------------------------------------------------------
  1305.   def initialize(y, option)
  1306.     super(y, option, 200)
  1307.   end
  1308.   #--------------------------------------------------------------------------
  1309.   # * disegna l'oggetto
  1310.   #--------------------------------------------------------------------------
  1311.   def draw_item(index)
  1312.     rect = item_rect(index)
  1313.     draw_text(rect, item(index))
  1314.   end
  1315.   #--------------------------------------------------------------------------
  1316.   # * Ottiene l'elenco dei valori dell'opzione
  1317.   #--------------------------------------------------------------------------
  1318.   def make_option_list
  1319.     @data = @option.values
  1320.     if @data.is_a?(Hash)
  1321.       @keys = @data.keys
  1322.       @data = @data.values
  1323.     end
  1324.   end
  1325.   #--------------------------------------------------------------------------
  1326.   # * Restituisce il valore selezionato
  1327.   #--------------------------------------------------------------------------
  1328.   def item(index = self.index)
  1329.     return @data[index]
  1330.   end
  1331.  
  1332.   def key(index = self.index)
  1333.     return @keys[index]
  1334.   end
  1335.   #--------------------------------------------------------------------------
  1336.   # * Restituisce l'opzione selezionata
  1337.   #--------------------------------------------------------------------------
  1338.   def select_last
  1339.     if @option.values.is_a?(Array)
  1340.       self.index = [[@option.value, 0].max, @option.values.size-1].min
  1341.     else
  1342.       self.index = keys_from_hash
  1343.     end
  1344.   end
  1345.   #--------------------------------------------------------------------------
  1346.   # * Restituisce l'opzione selezionata dall'hash dei valori
  1347.   #--------------------------------------------------------------------------
  1348.   def keys_from_hash
  1349.     if @keys.find_index(@option.value)
  1350.       return @keys.find_index(@option.value)
  1351.     else
  1352.       return @keys.first
  1353.     end
  1354.   end
  1355. end
  1356.  
  1357. #==============================================================================
  1358. # ** Game_Temp
  1359. #------------------------------------------------------------------------------
  1360. #  Aggiunta dei parametri
  1361. #==============================================================================
  1362. class Game_Temp
  1363.   attr_accessor :in_game
  1364. end
  1365.  
  1366. #==============================================================================
  1367. # ** Game_System
  1368. #------------------------------------------------------------------------------
  1369. #  Aggiunta dei parametri
  1370. #==============================================================================
  1371. class Game_System
  1372.   attr_accessor :options_initialized
  1373.   attr_accessor :enabling_options
  1374.   def option_enable(tag, state)
  1375.     @enabling_options = {} if @enabling_options.nil?
  1376.     @enabling_options[tag] = state
  1377.   end
  1378. end
  1379.  
  1380. #==============================================================================
  1381. # ** Scene_Map
  1382. #------------------------------------------------------------------------------
  1383. #  Inizializzazione delle opzioni
  1384. #==============================================================================
  1385. class Scene_Map < Scene_Base
  1386.   alias h87options_start start unless $@
  1387.   def start
  1388.     h87options_start
  1389.     initialize_options
  1390.   end
  1391.   #--------------------------------------------------------------------------
  1392.   # * Inizializza le opzioni, se non ancora inizializzate
  1393.   #--------------------------------------------------------------------------
  1394.   def initialize_options
  1395.     return if $game_system.options_initialized
  1396.     $game_system.options_initialized = true
  1397.     for option in H87Options.option_list
  1398.       next unless option.for_game?
  1399.       option.value = option.default if option.default != nil
  1400.       option.toggle if option.type == :bar
  1401.     end
  1402.   end
  1403. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement