Advertisement
Holy87

Game Options

May 26th, 2015
728
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 59.62 KB | None | 0 0
  1. =begin
  2.  ==============================================================================
  3.   ■ Opzioni di gioco di Holy87
  4.       versione 1.2.1
  5.       Difficoltà utente: ★★
  6.       Licenza: CC. Chiunque può scaricare, modificare, distribuire e utilizzare
  7.       lo script nei propri progetti, sia amatoriali che commerciali. Vietata
  8.       l'attribuzione impropria.
  9.  
  10.       Changelog
  11.       v1.2.1 -> risoluzione di bug critici e miglioramenti vari
  12.       v1.2.0 -> possibilità di impostare un valore minimo per le variabili
  13.                 possibilità di visualizzare il valore anziché percentuale
  14.                   nelle barre
  15.                 possibilità di impostare un colore RGB piuttosto che uno della
  16.                   windowskin per le barre
  17.                 possibilità di incrementare e decrementare più velocemente le
  18.                   barre tenendo premuto SHIFT o premento L e R
  19.                 possibilità di forzare la non-inizializzazione di una opzione
  20.                 correzioni bugfix generali
  21.       v1.1.3 -> correzione bug incremento barra
  22.       v1.1.2 -> correzione bug entrata nel menu
  23.       v1.1.1 -> correzione di bug
  24.  ==============================================================================
  25.     Questo script aggiunge il menu opzioni di gioco per configurare opzioni
  26.     del maker o degli script installati (se lo supportano). Dai al giocatore
  27.     le opzioni che gli spettano!
  28.  ==============================================================================
  29.   ■ Compatibilità
  30.     Scene_Title -> alias create_command_window
  31.     Scene_Menu -> alias create_command_window
  32.     DataManager -> alias load_normal_database
  33.  ==============================================================================
  34.   ■ Installazione e istruzioni
  35.     Installare questo script sotto Materials e prima del Main.
  36.     RICHIEDE IL MODULO DI SUPPORTO UNIVERSALE DI HOLY87.
  37.  
  38.   ■ Istruzioni per l'utilizzatore per creare opzioni di gioco
  39.  
  40.       Si possono aggiungere facilmente le opzioni aggiungendole nell'array
  41.       ELEMENTS (più in basso). È possibile aggiungere opzioni che cambiano
  42.       switch, variabili, barre ed altri elementi. Vediamo come.
  43.  
  44.     ● Per aggiungere separatori
  45.       {:type => :separator, :text => "Questo è un separatore}
  46.       Il separatore serve a tenere più organizzato il menu delle opzioni,
  47.       separando le categorie di opzioni. Importante impostare il tipo come
  48.       separatore, mentre l'attributo :text mostra il titolo della sezione.
  49.  
  50.     ● Per aggiungere switch
  51.       {:type => :switch, :text => "Nome opzione", :sw => 10, :on => "Acceso",
  52.        :off => "Spento", :help => "Attiva l'opzione"}
  53.       Con questo comando si configura l'opzione di uno switch. Il parametro
  54.       :sw indica l'ID della switch del gioco da impostare ON o OFF. I parametri
  55.       :on e :off sono il testo mostrato nelle opzioni.
  56.       Puoi anche aggiungere il valore :default => true se vuoi che lo switch
  57.       sia attivo all'inizio del gioco.
  58.  
  59.     ● Per aggiungere variabili
  60.       {:type => :variable, :text => "Nome opzione", :var => 2, :max => 5,
  61.        :help => "Cambia il valore dell'opzione"}
  62.       Questo comando invece configura un'opzione tramite variabile di gioco.
  63.       Con :var indica l'ID della variabile di gioco, :max il valore massimo che
  64.       può raggiungere l'opzione nella variabile. In questo caso l'opzione della
  65.       variabile 2 può avere come valori 0, 1, 2, 3, 4 e 5.
  66.       Puoi anche aggiungere :min => x se vuoi impostare un valore minimo che
  67.       non sia zero (anche minore di zero) dove x è il valore minimo.
  68.       Verranno mostrati in fila e il giocatore potrà scegliere il valore.
  69.       Puoi anche personalizzare i nomi dei valori, ad esempio
  70.  
  71.       {:type => :variable, :text => "Difficoltà", :var => 5,
  72.        :help => "Regola la difficoltà di gioco.",
  73.        :values => ["Facile", "Normale", "Difficile, "Estremo"] }
  74.       Ci sono troppe opzioni da mostrare in un solo rigo? Nessun problema!
  75.       Aggiungi il parametro :open_popup => true per mostrare la selezione
  76.       dell'opzione in un popup, per avere più opzioni insieme senza che stiano
  77.       troppo strette.
  78.       Anche con le variabili, puoi impostare il valore :default => x per
  79.       un valore predefinito all'inizio del gioco.
  80.       :max non serve, dato che i valori vengono definiti.
  81.  
  82.     ● Per aggiungere delle barre
  83.       Un altro modo per controllare le variabili è quello di usare le barre.
  84.       Viene mostrata una barra che si riempie o si svuota a preferenza dell'utente.
  85.       La configurazione è simile alle variabili, solo che si deve anche decidere
  86.       il colore della barra. Esempio:
  87.       {:type => :bar, :text => "Volume", :var => 5, :max => 100, :color => 5,
  88.        :help => "Regola il volume del gioco."}
  89.       Il colore si riferisce al numero del colore del testo della windowskin
  90.       (ad esempio, 0 per il colore del testo)
  91.       Le barre hanno anche il vantaggio di poter essere accoppiate ad uno
  92.       switch, nel caso si prema Invio l'opzione può essere disattivata (ad
  93.       esempio, rendendo muto l'audio). Basta aggiungere l'attributo :sw come
  94.       negli switch.
  95.       se non vuoi mostrare il valore come percentuale, usa :show_perc => false.
  96.       Al posto del colore del tema, puoi anche impostare un colore ben definito
  97.       come :color => Color.new(R, G, B) dove R, G e B sono i valori del colore.
  98.  
  99.   ■ Opzioni avanzate per gli smanettoni
  100.  
  101.       IMPOSTARE DELLE OPZIONI GLOBALI (CHE NON DIPENDONO DAL SALVATAGGIO)
  102.       Se imposti l'ID di una switch o una variabile non come numero, ma come
  103.       stringa o un simbolo, l'opzione viene vista come globale e verrà salvata
  104.       in $game_settings.
  105.  
  106.       ABILITARE O DISABILITARE LE OPZIONI
  107.       Puoi abilitare o disabilitare delle opzioni in due modi.
  108.       ● $game_system.option_enable(tag, true/false) abilita o disabilita
  109.         un'opzione di gioco. Il parametro tag è il nome dell'opzione definito
  110.         nella configurazione dell'opzione (:tag => "nome tag")
  111.       ● usando :condition => "condizione" nella configurazione dell'opzione.
  112.         Ad esempio, :condition => "$game_switches[55] == true" abiliterà l'opzione
  113.         solo se lo switch 55 è attivato.
  114.  
  115.       VOCI AVANZATE PER LE OPZIONI PER ESEGUIRE CODICE RUBY
  116.       Impostando il tipo come :advanced, viene eseguito del codice preconfigurato
  117.       quando il giocatore preme invio su di esso. Esempio:
  118.       {:type => :advanced, method => :change_scene}
  119.       class Option
  120.         def change_scene
  121.           SceneManager.call(Mia_Scena)
  122.         end
  123.       end
  124.  
  125.       FORZARE LA NON INIZIALIZZAZIONE DELLE VARIABILI
  126.       Se non vuoi che un'opzione venga automaticamente inizializzata a 0,
  127.       imposta il parametro :not_initialize => true
  128.  
  129.       Se vuoi assegnare anche un valore visualizzato come nelle altre opzioni,
  130.       devi fare l'alias del metodo draw_advanced in Window_GameOptions.
  131.  
  132.       Se imposti il valore :method => :nome_metodo in una barra, switch o
  133.       variabile, viene eseguito il metodo nome_metodo prima di impostare il
  134.       valore. Puoi mettere :var o :sw a 0 se non vuoi usare una variabile o uno
  135.       switch.
  136.       Il metodo in questo caso deve ricevere un PARAMETRO IN INGRESSO dato dal
  137.       valore inserito.
  138.  
  139.       Se imposti il valore :val_mt => nome_metodo, il valore che viene mostrato
  140.       nelle opzioni viene preso dal metodo impostato come nome_metodo, sempre
  141.       definito nella classe Option.
  142.  
  143.   ■ Istruzioni per gli scripter
  144.  
  145.       È molto utile per chi fa script aggiungere delle opzioni ai propri script
  146.       direttamente in questo menu opzioni, invece che crearlo a parte.
  147.       Per gli scripter, le opzioni vengono divise in 8 categorie:
  148.       - Generiche, nella stessa categoria di quelle definite dall'utente
  149.       - Aspetto, come temi e sfondi
  150.       - Audio, per musica e suoni
  151.       - Gioco, per opzioni di gioco come la velocità battaglia e la difficoltà
  152.       - Grafica, come la risoluzione e gli effetti speciali
  153.       - Comandi, per i controlli di gioco
  154.       - Sistema, per configurazioni tecniche
  155.       - Internet, per l'aspetto online.
  156.       Le categorie avranno il separatore dedicato già inserito (a parte quelle
  157.       generiche, ove puoi crearne una tu se il tuo script non ricade in una
  158.       delle categorie prefissate).
  159.       Per aggiungere le opzioni in queste categorie, per ogni opzione devi
  160.       passare l'hash (configurato come da istruzioni precedenti) nei rispettivi
  161.       metodi:
  162.       H87Options.push_system_option(hash)
  163.       H87Options.push_generic_option(hash)
  164.       H87Options.push_game_option(hash)
  165.       H87Options.push_graphic_option(hash)
  166.       H87Options.push_sound_option(hash)
  167.       H87Options.push_appearance_option(hash)
  168.       H87Options.push_keys_option(hash)
  169.       H87Options.push_internet_option(hash)
  170.  
  171.     ● Finestre di popup personalizzate
  172.       Puoi creare finestre di popup personalizzate alla selezione di un'opzione
  173.       creando una sottoclasse di Window_OptionPopup (vedi in basso), e impostando
  174.       l'attributo all'opzione :popup => "NomeClasse".
  175.  ==============================================================================
  176. =end
  177. $imported = {} if $imported == nil
  178. $imported['H87_Options'] = 1.2
  179. #==============================================================================
  180. # ** CONFIGURAZIONE
  181. #------------------------------------------------------------------------------
  182. #  Configura i testi e le opzioni
  183. #==============================================================================
  184. module H87Options
  185.   #--------------------------------------------------------------------------
  186.   # * Vocaboli
  187.   #--------------------------------------------------------------------------
  188.   #Comando Opzioni
  189.   OPTION_COMMAND = "Opzioni"
  190.   #Valore della barra disattivata
  191.   OFF_BAR = "OFF"
  192.   #Opzioni ordinate per categoria
  193.   SYSTEM_OPTIONS =      "Sistema"
  194.   GAME_OPTIONS =        "Gioco"
  195.   SOUND_OPTIONS =       "Audio"
  196.   APPEARANCE_OPTIONS =  "Aspetto"
  197.   GRAPHIC_OPTIONS =     "Grafica"
  198.   INTERNET_OPTIONS =    "Internet"
  199.   KEYS_OPTIONS =        "Comandi"
  200.   USER_OPTIONS =        "Generale"
  201.   #--------------------------------------------------------------------------
  202.   # * Suono al cambio di switch
  203.   #--------------------------------------------------------------------------
  204.   TOGGLE_SOUND = "Switch2"
  205.   #--------------------------------------------------------------------------
  206.   # * Mostra il menu opzioni nel titolo? Alla schermata del titolo vengono
  207.   #   mostrate solo le opzioni GLOBALI (vedi nelle istruzioni per smanettoni)
  208.   #--------------------------------------------------------------------------
  209.   SHOW_ON_TITLE = false
  210.   #--------------------------------------------------------------------------
  211.   # * Mostra le opzioni nella schermata del Menu?
  212.   #--------------------------------------------------------------------------
  213.   SHOW_ON_MENU = true
  214.   #--------------------------------------------------------------------------
  215.   # * Configura qui le varie opzioni. Vedi gli esempi per capire come
  216.   #   creare le opzioni.
  217.   #--------------------------------------------------------------------------
  218.   ELEMENTS = [
  219.       #normale switch
  220.       { :type => :switch, #tipo switch
  221.         :text => "Interruttore", #nome dell'opzione
  222.         :help => "Questa è una prova dell'interruttore.",#mostrato nella descr.
  223.         :sw   => 3, #ID della switch
  224.         :on   => "ON",  #testo ON
  225.         :off  => "OFF", #testo OFF
  226.         :default => true, #valore predefinito (facoltativo)
  227.       },
  228.       #separatore
  229.       { :type => :separator,  #tipo separatore
  230.         :text => "Separatore",#testo mostrato
  231.       },
  232.       #variabile
  233.       { :type => :variable,   #tipo variabile
  234.         :text => "Sveglia",   #testo mostrato
  235.         :help => "Imposta l'ora della sveglia", #descrizione
  236.         :var  => 110,          #ID della variabile
  237.         :max  => 11,          #valore massimo
  238.         :default => 6,        #valore predefinito
  239.       },
  240.       #altra variabile
  241.       { :type => :variable,   #tipo variabile
  242.         :text => "Animale",#testo mostrato
  243.         :help => "Imposta il tuo animale preferito", #descrizione
  244.         :var  => 111,          #variabile
  245.         :values => ["Cane", "Gatto", "Elefante"],#valori 0, 1 e 2
  246.       },
  247.       #altra variabile, tanti valori quindi mostro un popup
  248.       { :type => :variable,   #tipo variabile
  249.         :text => "Mese",#testo mostrato
  250.         :help => "Imposta il mese del gioco", #descrizione
  251.         :var  => 112,          #variabile
  252.         :open_popup => true,  #troppi valori, usa un popup
  253.         :values => ["Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno",
  254.                     "Luglio","Agosto","Settembre","Ottobre","Novembre",
  255.                     "Dicembre"],# i mesi dell'anno
  256.       },
  257.       #Variabile mostrata come barra
  258.       { :type   => :bar, #tipo barra
  259.         :text   => "Riempimento", #testo mostrato
  260.         :sw     => 5, #switch ON/OFF
  261.         :var    => 113,#ID della variabile
  262.         :color  => 10, #colore della variabile (10 è rosso nella skin default)
  263.         :max    => 50, #valore massimo
  264.         :perc => false,
  265.         :min => -50,
  266.       },
  267.       #Altra barra
  268.       { :type   => :bar, #tipo barra
  269.         :text   => "Prodezza", #testo mostrato
  270.         :var    => 14,#ID della variabile
  271.         :color  => 4, #colore della variabile (4 è celeste)
  272.         :max    => 100, #valore massimo
  273.         :default => 44,
  274.         :condition => "$game_switches[5] == false", #l'opzione è disponibile solo
  275.       }, #se lo switch 5 è false (in pratica se disattivi la barra precedente)
  276.       #Opzione avanzata
  277.       { :type => :advanced, #opzione speciale
  278.         :method => :apri_nome, #metodo alla pressione, vedi sotto per la definiz.
  279.         :text => "Cambia nome eroe", #testo mostrato
  280.         :condition => "$TEST", #attivo solo se è un test di gioco
  281.         :help => "Cambia il nome eroe durante il gioco.",
  282.       },
  283.   ] #NON CANCELLARE QUESTA PARENTESI!
  284.  
  285.   #--------------------------------------------------------------------------
  286.   # * Configurazione per Menu Titolo personalizzato
  287.   #--------------------------------------------------------------------------
  288.   TITLE_ICON = "Icona"  #icona del comando
  289.   TITLE_BALOON = "Fumetto" #immagine del fumetto
  290. end
  291.  
  292. class Option
  293.   #qui vanno definiti gli eventuali metodi da aggiungere
  294.  
  295.   #esempio precedente
  296.   def apri_nome
  297.     SceneManager.call(Scene_Name)
  298.     SceneManager.scene.prepare($game_party.members[0].id, 10)
  299.   end
  300. end
  301.  
  302. #==============================================================================
  303. # ** FINE CONFIGURAZIONE
  304. #------------------------------------------------------------------------------
  305. #                 - ATTENZIONE: NON MODIFICARE OLTRE! -
  306. #==============================================================================
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313. #==============================================================================
  314. # ** Modulo H87Options
  315. #------------------------------------------------------------------------------
  316. #  Modulo di gestione delle opzioni
  317. #==============================================================================
  318. module H87Options
  319.   #--------------------------------------------------------------------------
  320.   # * Restituisce le opzioni di gioco
  321.   #--------------------------------------------------------------------------
  322.   def self.game_options
  323.     return @game.nil? ? [] : @game
  324.   end
  325.   #--------------------------------------------------------------------------
  326.   # * Restituisce le opzioni definite dall'utente
  327.   #--------------------------------------------------------------------------
  328.   def self.user_options
  329.     return ELEMENTS + generic_options
  330.   end
  331.   #--------------------------------------------------------------------------
  332.   # * Restituisce le opzioni generali
  333.   #--------------------------------------------------------------------------
  334.   def self.generic_options
  335.     return @generic.nil? ? [] : @generic
  336.   end
  337.   #--------------------------------------------------------------------------
  338.   # * Restituisce le opzioni grafiche
  339.   #--------------------------------------------------------------------------
  340.   def self.graphic_options
  341.     return @graphic.nil? ? [] : @graphic
  342.   end
  343.   #--------------------------------------------------------------------------
  344.   # * Restituisce le opzioni di sistema
  345.   #--------------------------------------------------------------------------
  346.   def self.system_options
  347.     return @system.nil? ? [] : @system
  348.   end
  349.   #--------------------------------------------------------------------------
  350.   # * Restituisce le opzioni audio
  351.   #--------------------------------------------------------------------------
  352.   def self.sound_options
  353.     return @sound.nil? ? [] : @sound
  354.   end
  355.   #--------------------------------------------------------------------------
  356.   # * Restituisce le opzioni dei comandi
  357.   #--------------------------------------------------------------------------
  358.   def self.keys_options
  359.     return @keys.nil? ? [] : @keys
  360.   end
  361.   #--------------------------------------------------------------------------
  362.   # * Restituisce le opzioni internet
  363.   #--------------------------------------------------------------------------
  364.   def self.internet_options
  365.     return @internet.nil? ? [] : @internet
  366.   end
  367.   #--------------------------------------------------------------------------
  368.   # * Restituisce le opzioni d'aspetto
  369.   #--------------------------------------------------------------------------
  370.   def self.appearance_options
  371.     return @appearance.nil? ? [] : @appearance
  372.   end
  373.   #--------------------------------------------------------------------------
  374.   # * Restituisce tutte le opzioni
  375.   #--------------------------------------------------------------------------
  376.   def self.all_options
  377.     return user_options + game_options + appearance_options + graphic_options +
  378.         sound_options + keys_options + system_options + internet_options
  379.   end
  380.   #--------------------------------------------------------------------------
  381.   # * Aggiunge le opzioni di sistema
  382.   #--------------------------------------------------------------------------
  383.   def self.push_system_option(hash)
  384.     if @system.nil?
  385.       @system = [{:type=> :separator, :text=> SYSTEM_OPTIONS}]
  386.     end
  387.     @system.push(hash)
  388.   end
  389.   #--------------------------------------------------------------------------
  390.   # * Aggiunge le opzioni dei comandi
  391.   #--------------------------------------------------------------------------
  392.   def self.push_keys_option(hash)
  393.     if @keys.nil?
  394.       @keys = [{:type=> :separator, :text=> KEYS_OPTIONS}]
  395.     end
  396.     @keys.push(hash)
  397.   end
  398.   #--------------------------------------------------------------------------
  399.   # * Aggiunge le opzioni generiche
  400.   #--------------------------------------------------------------------------
  401.   def self.push_generic_option(hash)
  402.     @generic = [] if @generic.nil?
  403.     @generic.push(hash)
  404.   end
  405.   #--------------------------------------------------------------------------
  406.   # * Aggiunge le opzioni d'aspetto
  407.   #--------------------------------------------------------------------------
  408.   def self.push_appearance_option(hash)
  409.     if @appearance.nil?
  410.       @appearance = [{ :type=> :separator,:text=> APPEARANCE_OPTIONS}]
  411.     end
  412.     @appearance.push(hash)
  413.   end
  414.   #--------------------------------------------------------------------------
  415.   # * Aggiunge le opzioni di gioco
  416.   #--------------------------------------------------------------------------
  417.   def self.push_game_option(hash)
  418.     if @game.nil?
  419.       @game = [{:type=> :separator, :text=> GAME_OPTIONS}]
  420.     end
  421.     @game.push(hash)
  422.   end
  423.   #--------------------------------------------------------------------------
  424.   # * Aggiunge le opzioni audio
  425.   #--------------------------------------------------------------------------
  426.   def self.push_sound_option(hash)
  427.     if @sound.nil?
  428.       @sound = [{ :type=> :separator, :text=> SOUND_OPTIONS}]
  429.     end
  430.     @sound.push(hash)
  431.   end
  432.   #--------------------------------------------------------------------------
  433.   # * Aggiunge le opzioni grafiche
  434.   #--------------------------------------------------------------------------
  435.   def self.push_graphic_option(hash)
  436.     if @graphic.nil?
  437.       @graphic = [{ :type=> :separator, :text=> GRAPHIC_OPTIONS}]
  438.     end
  439.     @graphic.push(hash)
  440.   end
  441.   #--------------------------------------------------------------------------
  442.   # * Aggiunge le opzioni internet
  443.   #--------------------------------------------------------------------------
  444.   def self.push_internet_option(hash)
  445.     if @internet.nil?
  446.       @internet = [{ :type=> :separator, :text=> INTERNET_OPTIONS}]
  447.     end
  448.     @internet.push(hash)
  449.   end
  450.   #--------------------------------------------------------------------------
  451.   # * Restituisce la lista delle opzioni
  452.   #--------------------------------------------------------------------------
  453.   def self.option_list
  454.     options = []
  455.     for option in all_options
  456.       opt = Option.new(option)
  457.       next if opt.for_game? and $game_temp.nil? || $game_temp.in_game == false
  458.       options.push(opt)
  459.     end
  460.     return options
  461.   end
  462. end
  463.  
  464. #==============================================================================
  465. # ** classe Scene_Menu
  466. #------------------------------------------------------------------------------
  467. #  Aggiunta del comando Opzioni
  468. #==============================================================================
  469. class Scene_Menu < Scene_MenuBase
  470.   alias h87options_create_command_window create_command_window unless $@
  471.   #--------------------------------------------------------------------------
  472.   # * Finestra comandi
  473.   #--------------------------------------------------------------------------
  474.   def create_command_window
  475.     h87options_create_command_window
  476.     @command_window.set_handler(:options, method(:command_options))
  477.   end
  478.   #--------------------------------------------------------------------------
  479.   # * Vai alle opzioni
  480.   #--------------------------------------------------------------------------
  481.   def command_options
  482.     $game_temp.in_game = true
  483.     SceneManager.call(Scene_Options)
  484.   end
  485. end
  486.  
  487. #==============================================================================
  488. # ** Classe Window_MenuCommand
  489. #------------------------------------------------------------------------------
  490. #  Aggiunta del comando Opzioni
  491. #==============================================================================
  492. class Window_MenuCommand < Window_Command
  493.   alias h87options_aoc add_original_commands unless $@
  494.   #--------------------------------------------------------------------------
  495.   # * Aggiunta del comando
  496.   #--------------------------------------------------------------------------
  497.   def add_original_commands
  498.     h87options_aoc
  499.     if H87Options::SHOW_ON_MENU
  500.       add_command(H87Options::OPTION_COMMAND, :options, true)
  501.     end
  502.   end
  503. end
  504.  
  505. #==============================================================================
  506. # ** classe Scene_Title
  507. #------------------------------------------------------------------------------
  508. #  Aggiunta del comando per andare alle opzioni
  509. #==============================================================================
  510. class Scene_Title < Scene_Base
  511.   alias h87options_create_command_window create_command_window unless $@
  512.   #--------------------------------------------------------------------------
  513.   # * Aggiunta dell'evento
  514.   #--------------------------------------------------------------------------
  515.   def create_command_window
  516.     h87options_create_command_window
  517.     @command_window.set_handler(:options, method(:command_options))
  518.   end
  519.   #--------------------------------------------------------------------------
  520.   # * Comando per le opzioni
  521.   #--------------------------------------------------------------------------
  522.   def command_options
  523.     $game_temp.in_game = false
  524.     SceneManager.call(Scene_Options)
  525.   end
  526.   #--------------------------------------------------------------------------
  527.   # * Aggiunta del comando del menu titolo personalizzato
  528.   #--------------------------------------------------------------------------
  529.   if $imported["H87_TitleMenu"]
  530.     alias h87options_ccp crea_contenuti_personalizzati
  531.     def crea_contenuti_personalizzati
  532.       h87options_ccp
  533.       if H87Options::SHOW_ON_TITLE
  534.         add_cursor(:options,"command_options",H87Options::TITLE_ICON,H87Options::TITLE_BALOON)
  535.       end
  536.     end;end
  537. end
  538.  
  539. #==============================================================================
  540. # ** Classe Window_TitleCommand
  541. #------------------------------------------------------------------------------
  542. #  Aggiunta del comando Opzioni
  543. #==============================================================================
  544. class Window_TitleCommand < Window_Command
  545.   alias h87options_aoc make_command_list unless $@
  546.   #--------------------------------------------------------------------------
  547.   # * Aggiunta del comando
  548.   #--------------------------------------------------------------------------
  549.   def make_command_list
  550.     h87options_aoc
  551.     if H87Options::SHOW_ON_TITLE
  552.       add_command(H87Options::OPTION_COMMAND, :options, true)
  553.     end
  554.   end
  555. end
  556.  
  557. #==============================================================================
  558. # ** DataManager
  559. #------------------------------------------------------------------------------
  560. #  Modifica del caricamento iniziale
  561. #==============================================================================
  562. module DataManager
  563.   class << self
  564.     alias h87options_cgo create_game_objects
  565.   end
  566.   #--------------------------------------------------------------------------
  567.   # * Alias caricamento DB
  568.   #--------------------------------------------------------------------------
  569.   def self.create_game_objects
  570.     h87options_cgo
  571.     initialize_options
  572.   end
  573.   #--------------------------------------------------------------------------
  574.   # * Inizializza le variabili globali
  575.   #--------------------------------------------------------------------------
  576.   def self.initialize_options
  577.     for option in H87Options.option_list
  578.       next if $game_settings[option.id] != nil
  579.       next if option.value != nil
  580.       option.value = option.default if option.default != nil
  581.       option.set_switch(true) if option.type == :bar
  582.     end
  583.   end
  584. end
  585.  
  586. #==============================================================================
  587. # ** Classe Option
  588. #------------------------------------------------------------------------------
  589. #  Contiene le impostazioni della singola opzione di gioco
  590. #==============================================================================
  591. class Option
  592.   #--------------------------------------------------------------------------
  593.   # * Variabili d'istanza pubblici
  594.   #--------------------------------------------------------------------------
  595.   attr_reader :type         #tipo
  596.   attr_reader :description  #descrizione
  597.   attr_reader :name         #nome
  598.   attr_reader :values       #elenco valori
  599.   attr_reader :max          #massimo della variabile
  600.   attr_reader :min          #minimo della variabile
  601.   attr_reader :default      #valore predefinito
  602.   attr_reader :value_method #metodo che restituisce il valore
  603.   attr_reader :bar_color    #colore della barra
  604.   attr_reader :tag          #etichetta (per salvataggio in game_settings)
  605.   #--------------------------------------------------------------------------
  606.   # * Inizializzazione
  607.   #--------------------------------------------------------------------------
  608.   def initialize(hash)
  609.     @type = hash[:type]
  610.     @description = hash[:help]
  611.     @name = hash[:text]
  612.     @for_game = hash[:in_game]
  613.     @tag = hash[:tag]
  614.     @default = hash[:default]
  615.     @min = 0
  616.     case @type
  617.       when :switch; init_switch(hash)
  618.       when :variable; init_variable(hash)
  619.       when :separator; init_separator(hash)
  620.       when :advanced; init_advanced(hash)
  621.       when :bar; init_bar(hash)
  622.     end
  623.     @method = hash[:method]
  624.     @value_method = hash[:val_mt] unless hash[:val_mt].nil?
  625.     @special_draw = hash[:special] unless hash[:special].nil?
  626.     @enabled_condition = hash[:condition] unless hash[:condition].nil?
  627.   end
  628.   #--------------------------------------------------------------------------
  629.   # * Inizializza gli attributi dello switch
  630.   #--------------------------------------------------------------------------
  631.   def init_switch(hash)
  632.     @default = false if @default.nil? && !hash[:not_initialize]
  633.     @switch = hash[:sw]
  634.     @values = [hash[:off], hash[:on]]
  635.   end
  636.   #--------------------------------------------------------------------------
  637.   # * Inizializza gli attributi della variabile
  638.   #--------------------------------------------------------------------------
  639.   def init_variable(hash)
  640.     @distance = hash[:distance].nil? ? 1 : hash[:distance]
  641.     @variable = hash[:var]
  642.     @need_popup = hash[:open_popup]
  643.     @popup = eval(hash[:popup]) if hash[:popup]
  644.     @default = 0 if @default.nil? && !hash[:not_initialize]
  645.     if hash[:values].nil?
  646.       @values = []
  647.       @max = hash[:max]
  648.       @min = hash[:min] if hash[:min]
  649.       for i in @min..@max
  650.         @values.push(i)
  651.       end
  652.     else
  653.       @values = hash[:values]
  654.       @max = @values.size - 1
  655.     end
  656.   end
  657.   #--------------------------------------------------------------------------
  658.   # * Restituisce il valore minimo
  659.   #--------------------------------------------------------------------------
  660.   def min
  661.     return 0 if @min.nil?
  662.     return @min
  663.   end
  664.   #--------------------------------------------------------------------------
  665.   # * Inizializza gli attributi del separatore
  666.   #--------------------------------------------------------------------------
  667.   def init_separator(hash)
  668.   end
  669.   #--------------------------------------------------------------------------
  670.   # * Inizializza gli attributi dell'oggetto avanzato
  671.   #--------------------------------------------------------------------------
  672.   def init_advanced(hash)
  673.     @popup = eval(hash[:popup]) if hash[:popup]
  674.   end
  675.   #--------------------------------------------------------------------------
  676.   # * Inizializza gli attributi della barra
  677.   #--------------------------------------------------------------------------
  678.   def init_bar(hash)
  679.     @max = hash[:max]
  680.     @min = hash[:min] if hash[:min]
  681.     @perc = hash[:perc] == false ? false : true
  682.     @variable = hash[:var]
  683.     @default = 0 if @default.nil? && !hash[:not_initialize]
  684.     @switch = hash[:sw] if hash[:sw] != nil
  685.     @distance = hash[:distance].nil? ? 1 : hash[:distance]
  686.     @bar_color = 1
  687.     @bar_color = hash[:color] if hash[:color]
  688.   end
  689.   #--------------------------------------------------------------------------
  690.   # * Restituisce il valore dell'opzione
  691.   #--------------------------------------------------------------------------
  692.   def value
  693.     return method(@value_method).call if @value_method != nil
  694.     case @type
  695.       when :switch
  696.         return switch
  697.       when :variable, :bar
  698.         return variable
  699.     end
  700.   end
  701.   #--------------------------------------------------------------------------
  702.   # * Imposta il valore dell'opzione
  703.   #--------------------------------------------------------------------------
  704.   def value=(new_value)
  705.     case @type
  706.       when :switch
  707.         set_switch(new_value)
  708.       when :variable, :bar
  709.         set_variable(new_value)
  710.     end
  711.     method(@method).call(new_value) if @method
  712.   end
  713.   #--------------------------------------------------------------------------
  714.   # * Cambia lo stato della switch
  715.   #--------------------------------------------------------------------------
  716.   def toggle
  717.     set_switch(!self.switch) if @switch
  718.     method(@method).call(self.switch) if @method
  719.   end
  720.   #--------------------------------------------------------------------------
  721.   # * Incrementa il valore dell'opzione
  722.   #--------------------------------------------------------------------------
  723.   def increment(fast = false)
  724.     if @type == :switch
  725.       toggle
  726.     else
  727.       set_switch(true)
  728.       self.value += calc_distance(fast)
  729.       if :variable
  730.         self.value = self.min if self.value > @max
  731.       else #barra
  732.         self.value = @max if self.value > @max
  733.       end
  734.     end
  735.   end
  736.   #--------------------------------------------------------------------------
  737.   # * Decrementa il valore dell'opzione
  738.   #--------------------------------------------------------------------------
  739.   def decrement(fast = false)
  740.     if @type == :switch
  741.       toggle
  742.     else
  743.       set_switch(true)
  744.       self.value -= calc_distance(fast)
  745.       if :variable
  746.         self.value = @max if self.value < self.min
  747.       else #barra
  748.         self.value = self.min if self.value < self.min
  749.       end
  750.     end
  751.   end
  752.   #--------------------------------------------------------------------------
  753.   # * Restituisce l'incremento o decremento
  754.   #--------------------------------------------------------------------------
  755.   def calc_distance(fast)
  756.     return @distance unless @type == :bar
  757.     return @distance unless fast
  758.     return @distance * 10
  759.   end
  760.   #--------------------------------------------------------------------------
  761.   # * Restituisce la classe della finestra di popup
  762.   #--------------------------------------------------------------------------
  763.   def popup
  764.     return @popup if @popup
  765.     return Generic_PopupWindow if @need_popup
  766.     return nil
  767.   end
  768.   #--------------------------------------------------------------------------
  769.   # * Restituisce l'ID dello switch o variabile assegnato
  770.   #--------------------------------------------------------------------------
  771.   def id
  772.     return @variable if @variable != nil
  773.     return @switch if @switch != nil
  774.     return @tag
  775.   end
  776.   #--------------------------------------------------------------------------
  777.   # * Restituisce lo stato della switch
  778.   #--------------------------------------------------------------------------
  779.   def switch
  780.     return true if @switch.nil?
  781.     return true if @switch == 0
  782.     if @switch.is_a?(Integer)
  783.       return $game_switches[@switch]
  784.     else
  785.       return $game_settings[@switch]
  786.     end
  787.   end
  788.   #--------------------------------------------------------------------------
  789.   # * Imposta lo stato della switch
  790.   #--------------------------------------------------------------------------
  791.   def set_switch(value)
  792.     return if @switch.nil?
  793.     return if @switch == 0
  794.     if @switch.is_a?(Integer)
  795.       $game_switches[@switch] = value
  796.     else
  797.       $game_settings[@switch] = value
  798.     end
  799.   end
  800.   #--------------------------------------------------------------------------
  801.   # * Restituisce lo stato della variabile
  802.   #--------------------------------------------------------------------------
  803.   def variable
  804.     return 0 if @variable == 0
  805.     if @variable.is_a?(Integer)
  806.       return $game_variables[@variable]
  807.     else
  808.       return $game_settings[@variable]
  809.     end
  810.   end
  811.   #--------------------------------------------------------------------------
  812.   # * Imposta lo stato della variabile
  813.   #--------------------------------------------------------------------------
  814.   def set_variable(value)
  815.     return if @variable == 0
  816.     if @variable.is_a?(Integer)
  817.       $game_variables[@variable] = value
  818.     else
  819.       $game_settings[@variable] = value
  820.     end
  821.   end
  822.   #--------------------------------------------------------------------------
  823.   # * Restituisce true se l'opzione ha una switch
  824.   #--------------------------------------------------------------------------
  825.   def toggable?
  826.     return @switch != nil
  827.   end
  828.   #--------------------------------------------------------------------------
  829.   # * Restituisce le condizioni di abilitazione dell'opzione
  830.   #--------------------------------------------------------------------------
  831.   def enabled?
  832.     if $game_system != nil && self.tag != nil &&
  833.         $game_system.enabling_options[self.tag] == false
  834.       return false
  835.     end
  836.     return true if @enabled_condition.nil?
  837.     return eval(@enabled_condition)
  838.   end
  839.   #--------------------------------------------------------------------------
  840.   # * Restituisce true se mostra la percentuale (la barra)
  841.   #--------------------------------------------------------------------------
  842.   def show_perc?; @perc; end
  843.   #--------------------------------------------------------------------------
  844.   # * Restituisce true se è un separatore
  845.   #--------------------------------------------------------------------------
  846.   def separator?
  847.     return @type == :separator
  848.   end
  849.   #--------------------------------------------------------------------------
  850.   # * Restituisce true se è un'opzione disponibile solo nella partita
  851.   #   (ossia, non visibile nella schermata del titolo)
  852.   #--------------------------------------------------------------------------
  853.   def for_game?
  854.     return true if @variable.is_a?(Integer)
  855.     return true if @switch.is_a?(Integer)
  856.     return true if @for_game
  857.     return false
  858.   end
  859.   #--------------------------------------------------------------------------
  860.   # * Restituisce true se l'opzione apre un popup
  861.   #--------------------------------------------------------------------------
  862.   def open_popup?
  863.     return self.popup != nil
  864.   end
  865.   #--------------------------------------------------------------------------
  866.   # * Restituisce true se l'opzione è disponibile e configurabile
  867.   #--------------------------------------------------------------------------
  868.   def value_active?(value_index)
  869.     if @type == :switch
  870.       return value_index == 1 && value ? true : false
  871.     elsif @type == :variable
  872.       return value == value_index * @distance
  873.     else
  874.       return true
  875.     end
  876.   end
  877.   #--------------------------------------------------------------------------
  878.   # * Restituisce true se l'opzione è attiva
  879.   #--------------------------------------------------------------------------
  880.   def is_on?
  881.     return self.switch
  882.   end
  883.   #--------------------------------------------------------------------------
  884.   # * Restituisc true se l'opzione può essere decrementata
  885.   #--------------------------------------------------------------------------
  886.   def can_decrement?
  887.     return false if @type == :advanced
  888.     return false if @type == :bar && self.value <= self.min
  889.     return false if @need_popup
  890.     return true
  891.   end
  892.   #--------------------------------------------------------------------------
  893.   # * Restituisce true se l'opzione può essere incrementata
  894.   #--------------------------------------------------------------------------
  895.   def can_increment?
  896.     return false if @type == :advanced
  897.     return false if @type == :bar && self.value >= self.max
  898.     return false if @need_popup
  899.     return true
  900.   end
  901.   #--------------------------------------------------------------------------
  902.   # * Esegue il metodo personalizzato dell'opzione
  903.   #--------------------------------------------------------------------------
  904.   def execute_method
  905.     return unless @method
  906.     method(@method).call
  907.   end
  908. end
  909.  
  910. #==============================================================================
  911. # ** Scene_Options
  912. #------------------------------------------------------------------------------
  913. #  Schermata delle opzioni
  914. #==============================================================================
  915. class Scene_Options < Scene_MenuBase
  916.   #--------------------------------------------------------------------------
  917.   # * Inizio
  918.   #--------------------------------------------------------------------------
  919.   def start
  920.     super
  921.     create_help_window
  922.     create_option_window
  923.     create_popup_windows
  924.   end
  925.   #--------------------------------------------------------------------------
  926.   # * Aggiornamento
  927.   #--------------------------------------------------------------------------
  928.   def update
  929.     super
  930.     update_popups
  931.   end
  932.   #--------------------------------------------------------------------------
  933.   # * Fine
  934.   #--------------------------------------------------------------------------
  935.   def terminate
  936.     super
  937.     dispose_popups
  938.   end
  939.   #--------------------------------------------------------------------------
  940.   # * Aggiorna le finestre di popup
  941.   #--------------------------------------------------------------------------
  942.   def update_popups
  943.     @popups.each_value{|p| p.update}
  944.   end
  945.   #--------------------------------------------------------------------------
  946.   # * Elimina le finestre di popup
  947.   #--------------------------------------------------------------------------
  948.   def dispose_popups
  949.     @popups.each_value{|p| p.dispose}
  950.   end
  951.   #--------------------------------------------------------------------------
  952.   # * Creazione della finestra d'aiuto
  953.   #--------------------------------------------------------------------------
  954.   def create_help_window
  955.     @help_window = Window_Help.new
  956.   end
  957.   #--------------------------------------------------------------------------
  958.   # * Creazione della finestra delle opzioni
  959.   #--------------------------------------------------------------------------
  960.   def create_option_window
  961.     @option_window = Window_GameOptions.new(@help_window.y + @help_window.height)
  962.     @option_window.help_window = @help_window
  963.     @option_window.set_handler(:cancel, method(:return_scene))
  964.     @option_window.activate
  965.   end
  966.   #--------------------------------------------------------------------------
  967.   # * Crea le finestre di popup
  968.   #--------------------------------------------------------------------------
  969.   def create_popup_windows
  970.     @popups = {}
  971.     opt = H87Options.option_list
  972.     y = @help_window.height
  973.     for i in 0..opt.size-1
  974.       if opt[i].popup
  975.         popup = opt[i].popup.new(y, opt[i])
  976.         popup.visible = false
  977.         popup.set_handler(:cancel, method(:close_popup))
  978.         popup.set_handler(:ok, method(:item_selected))
  979.         @popups[i] = popup
  980.       end
  981.     end
  982.   end
  983.   #--------------------------------------------------------------------------
  984.   # * Restituisce la finestra di popup attualmente aperta
  985.   #--------------------------------------------------------------------------
  986.   def popup
  987.     return @popups[@popup_index]
  988.   end
  989.   #--------------------------------------------------------------------------
  990.   # * Mostra la finestra di popup
  991.   #   index: indice dell'opzione
  992.   #--------------------------------------------------------------------------
  993.   def show_popup(index)
  994.     @last_frame = Graphics.frame_count
  995.     @popup_index = index
  996.     x = Graphics.width - popup.width
  997.     y = @help_window.height
  998.     popup.x = Graphics.width
  999.     popup.visible = true
  1000.     if $imported["H87_SmoothMovements"]
  1001.       @option_window.smooth_move(0 - popup.width, y)
  1002.       popup.smooth_move(x, y)
  1003.     else
  1004.       @option_window.x = 0 - popup.width
  1005.       popup.x = x
  1006.     end
  1007.     popup.activate
  1008.   end
  1009.   #--------------------------------------------------------------------------
  1010.   # * Viene eseguito quando l'utente seleziona un'opzione dal popup
  1011.   #--------------------------------------------------------------------------
  1012.   def item_selected
  1013.     if @last_frame < Graphics.frame_count
  1014.       @option_window.item.value = popup.selected_value
  1015.       @option_window.refresh
  1016.       @help_window.refresh
  1017.       close_popup
  1018.     else
  1019.       popup.activate
  1020.     end
  1021.   end
  1022.   #--------------------------------------------------------------------------
  1023.   # * Chiude la finestra di popup
  1024.   #--------------------------------------------------------------------------
  1025.   def close_popup
  1026.     popup.deactivate
  1027.     x = Graphics.width
  1028.     y = @help_window.height
  1029.     if $imported["H87_SmoothMovements"]
  1030.       @option_window.smooth_move(0, y)
  1031.       popup.smooth_move(x, y)
  1032.     else
  1033.       @option_window.x = 0
  1034.       popup.x = x
  1035.     end
  1036.     @option_window.activate
  1037.     @popup_index = nil
  1038.   end
  1039. end
  1040.  
  1041. #==============================================================================
  1042. # ** Window_GameOptions
  1043. #------------------------------------------------------------------------------
  1044. #  Finestra che contiene l'elenco delle opzioni
  1045. #==============================================================================
  1046. class Window_GameOptions < Window_Selectable
  1047.   #--------------------------------------------------------------------------
  1048.   # * Inizializzazione
  1049.   #   y: coordinata Y iniziale
  1050.   #--------------------------------------------------------------------------
  1051.   def initialize(y)
  1052.     super(0, y, Graphics.width, Graphics.height - y)
  1053.     @data = []
  1054.     make_option_list
  1055.     create_contents
  1056.     refresh
  1057.     self.index = 0
  1058.     cursor_down if item && item.separator?
  1059.   end
  1060.   #--------------------------------------------------------------------------
  1061.   # * draw_item
  1062.   #   index: indice dell
  1063.   #--------------------------------------------------------------------------
  1064.   def draw_item(index)
  1065.     item = @data[index]
  1066.     if item
  1067.       rect = item_rect(index)
  1068.       rect.width -= 4
  1069.       draw_item_name(item, rect.x, rect.y, enable?(item))
  1070.       draw_item_state(rect, item)
  1071.     end
  1072.   end
  1073.   #--------------------------------------------------------------------------
  1074.   # * Draw Item Name
  1075.   #     enabled : Enabled flag. When false, draw semi-transparently.
  1076.   #--------------------------------------------------------------------------
  1077.   def draw_item_name(item, x, y, enabled = true, width = 172)
  1078.     return unless item
  1079.     change_color(normal_color, enabled)
  1080.     draw_text(x, y, width, line_height, item.name) unless item.separator?
  1081.   end
  1082.   #--------------------------------------------------------------------------
  1083.   # * Mostra lo stato dell'opzione a seconda del tipo
  1084.   #--------------------------------------------------------------------------
  1085.   def draw_item_state(rect, item)
  1086.     case item.type
  1087.       when :separator
  1088.         draw_separator(rect, item)
  1089.       when :switch
  1090.         draw_switch(rect, item)
  1091.       when :variable
  1092.         draw_variable(rect, item)
  1093.       when :bar
  1094.         draw_bar(rect, item)
  1095.       when :advanced
  1096.         draw_advanced(rect, item)
  1097.     end
  1098.   end
  1099.   #--------------------------------------------------------------------------
  1100.   # * Disegna il separatore
  1101.   #--------------------------------------------------------------------------
  1102.   def draw_separator(rect, item)
  1103.     color = gauge_back_color
  1104.     color.alpha = 128
  1105.     contents.fill_rect(rect.x, rect.y+2, rect.width, rect.height-4, color)
  1106.     draw_text(rect.x, rect.y, rect.width, line_height, item.name, 1)
  1107.   end
  1108.   #--------------------------------------------------------------------------
  1109.   # * Move Cursor Down
  1110.   #--------------------------------------------------------------------------
  1111.   def cursor_down(wrap = false)
  1112.     super
  1113.     super if item.separator?
  1114.   end
  1115.   #--------------------------------------------------------------------------
  1116.   # * Move Cursor Up
  1117.   #--------------------------------------------------------------------------
  1118.   def cursor_up(wrap = false)
  1119.     super
  1120.     super if item.separator?
  1121.   end
  1122.   #--------------------------------------------------------------------------
  1123.   # * Disegna lo switch
  1124.   #--------------------------------------------------------------------------
  1125.   def draw_switch(rect, item)
  1126.     x = get_state_x(rect)
  1127.     width = get_state_width(x, rect, item)
  1128.     change_color(normal_color, enable?(item) && !item.value)
  1129.     contents.draw_text(x, rect.y, width, line_height, item.values[0], 1)
  1130.     x += width
  1131.     change_color(normal_color, enable?(item) && item.value)
  1132.     contents.draw_text(x, rect.y, width, line_height, item.values[1], 1)
  1133.   end
  1134.   #--------------------------------------------------------------------------
  1135.   # * Disegna la variabile
  1136.   #--------------------------------------------------------------------------
  1137.   def draw_variable(rect, item)
  1138.     unless item.open_popup?
  1139.       draw_values_variable(rect, item)
  1140.     else
  1141.       draw_popup_variable(rect, item)
  1142.     end
  1143.   end
  1144.   #--------------------------------------------------------------------------
  1145.   # * Disegna la variabile se apre un popup
  1146.   #--------------------------------------------------------------------------
  1147.   def draw_popup_variable(rect, item)
  1148.     x = get_state_x(rect)
  1149.     width = rect.width - x
  1150.     change_color(normal_color, enable?(item))
  1151.     draw_text(x, rect.y, width, line_height, item.values[item.value], 1)
  1152.   end
  1153.   #--------------------------------------------------------------------------
  1154.   # * Disegna i valori della variabile
  1155.   #--------------------------------------------------------------------------
  1156.   def draw_values_variable(rect, item)
  1157.     x = get_state_x(rect)
  1158.     width = get_state_width(x, rect, item)
  1159.     for i in 0..item.max
  1160.       next if item.values[i].nil?
  1161.       change_color(normal_color, enable?(item) && item.value_active?(i))
  1162.       draw_text(x+(width*i), rect.y, width, line_height, item.values[i], 1)
  1163.     end
  1164.   end
  1165.   #--------------------------------------------------------------------------
  1166.   # * Disegna la barra
  1167.   #--------------------------------------------------------------------------
  1168.   def draw_bar(rect, item)
  1169.     x = get_state_x(rect)
  1170.     width = rect.width - x
  1171.     if item.bar_color.is_a?(Color)
  1172.       color = item.bar_color
  1173.     else
  1174.       color = text_color(item.bar_color)
  1175.     end
  1176.     color.alpha = enable?(item) ? 255 : 128
  1177.     contents.fill_rect(x, rect.y+5, width, line_height-10, color)
  1178.     contents.clear_rect(x+1, rect.y+6, width-2, line_height-12)
  1179.     rate = (item.value - item.min)/(item.max.to_f - item.min.to_f)
  1180.     contents.fill_rect(x, rect.y+5, width*rate, line_height-10, color)
  1181.     if item.is_on?
  1182.       change_color(normal_color, enable?(item))
  1183.       if item.show_perc?
  1184.         text = sprintf("%2d%%",rate*100)
  1185.       else
  1186.         text = item.value.to_i
  1187.       end
  1188.     else
  1189.       change_color(power_down_color, enable?(item))
  1190.       text = H87Options::OFF_BAR
  1191.     end
  1192.     draw_text(x, rect.y, width, line_height, text, 1)
  1193.   end
  1194.   #--------------------------------------------------------------------------
  1195.   # * Disegna il valore del metodo avanzato
  1196.   #--------------------------------------------------------------------------
  1197.   def draw_advanced(rect, item)
  1198.   end
  1199.   #--------------------------------------------------------------------------
  1200.   # * Update Help Text
  1201.   #--------------------------------------------------------------------------
  1202.   def update_help
  1203.     @help_window.set_item(item)
  1204.   end
  1205.   #--------------------------------------------------------------------------
  1206.   # * Creazione della lista delle opzioni
  1207.   #--------------------------------------------------------------------------
  1208.   def make_option_list
  1209.     @data = H87Options.option_list
  1210.   end
  1211.   #--------------------------------------------------------------------------
  1212.   # * Get Number of Items
  1213.   #--------------------------------------------------------------------------
  1214.   def item_max
  1215.     @data ? @data.size : 0
  1216.   end
  1217.   #--------------------------------------------------------------------------
  1218.   # * Display in Enabled State?
  1219.   #--------------------------------------------------------------------------
  1220.   def enable?(item)
  1221.     item.enabled?
  1222.   end
  1223.   #--------------------------------------------------------------------------
  1224.   # * Restituisce l'opzione selezionata
  1225.   #--------------------------------------------------------------------------
  1226.   def item
  1227.     return @data[index]
  1228.   end
  1229.   #--------------------------------------------------------------------------
  1230.   # * Restituisce la coordinata X dove disegnare lo stato
  1231.   #--------------------------------------------------------------------------
  1232.   def get_state_x(rect)
  1233.     return rect.x + rect.width / 2
  1234.   end
  1235.   #--------------------------------------------------------------------------
  1236.   # * Restituisce la larghezza del valore in caso di più valori
  1237.   #--------------------------------------------------------------------------
  1238.   def get_state_width(x, rect, item)
  1239.     return (rect.width - x) / item.values.size
  1240.   end
  1241.   #--------------------------------------------------------------------------
  1242.   # * Esecuzione dell'azione di selezione (INVIO)
  1243.   #--------------------------------------------------------------------------
  1244.   def action
  1245.     case item.type
  1246.       when :switch, :bar
  1247.         toggle_item
  1248.       when :advanced
  1249.         process_method
  1250.       when :variable
  1251.         open_popup
  1252.     end
  1253.   end
  1254.   #--------------------------------------------------------------------------
  1255.   # * Cambia lo stato della switch dell'opzione
  1256.   #--------------------------------------------------------------------------
  1257.   def toggle_item
  1258.     return unless item.toggable?
  1259.     item.toggle
  1260.     RPG::SE.new(H87Options::TOGGLE_SOUND).play
  1261.     refresh
  1262.     activate
  1263.   end
  1264.   #--------------------------------------------------------------------------
  1265.   # * Chiama il metodo
  1266.   #--------------------------------------------------------------------------
  1267.   def process_method
  1268.     item.execute_method
  1269.     open_popup
  1270.   end
  1271.   #--------------------------------------------------------------------------
  1272.   # * Apre il popup
  1273.   #--------------------------------------------------------------------------
  1274.   def open_popup
  1275.     return unless item.popup
  1276.     Sound.play_ok
  1277.     SceneManager.scene.show_popup(self.index)
  1278.     deactivate
  1279.   end
  1280.   #--------------------------------------------------------------------------
  1281.   # * Aggiornamento
  1282.   #--------------------------------------------------------------------------
  1283.   def update
  1284.     return if disposed?
  1285.     super
  1286.     update_other_commands
  1287.   end
  1288.   #--------------------------------------------------------------------------
  1289.   # * Aggiorna gli altri comandi
  1290.   #--------------------------------------------------------------------------
  1291.   def update_other_commands
  1292.     return unless active && cursor_movable?
  1293.     shift_left if Input.repeat?(:LEFT)
  1294.     shift_right if Input.repeat?(:RIGHT)
  1295.     shift_left(true) if Input.repeat?(:L)
  1296.     shift_right(true) if Input.repeat?(:R)
  1297.     action if Input.trigger?(:C) && enable?(item)
  1298.   end
  1299.   #--------------------------------------------------------------------------
  1300.   # * Scorri a sinistra se è una variabile o una barra
  1301.   #--------------------------------------------------------------------------
  1302.   def shift_left(fast = false)
  1303.     return unless item.can_decrement?
  1304.     return unless enable?(item)
  1305.     item.decrement(fast || Input.press?(:A))
  1306.     Sound.play_cursor
  1307.     refresh
  1308.   end
  1309.   #--------------------------------------------------------------------------
  1310.   # * Scorri a destra se è una variabile o una barra
  1311.   #--------------------------------------------------------------------------
  1312.   def shift_right(fast = false)
  1313.     return unless item.can_increment?
  1314.     return unless enable?(item)
  1315.     item.increment(fast || Input.press?(:A))
  1316.     Sound.play_cursor
  1317.     refresh
  1318.   end
  1319. end
  1320.  
  1321. #==============================================================================
  1322. # ** Window_OptionPopup
  1323. #------------------------------------------------------------------------------
  1324. #  Classe d'appoggio per le finestre di popup
  1325. #==============================================================================
  1326. class Window_OptionPopup < Window_Selectable
  1327.   #--------------------------------------------------------------------------
  1328.   # * Inizializzazione
  1329.   #--------------------------------------------------------------------------
  1330.   def initialize(y, option, width = 200)
  1331.     super(Graphics.width, y, width, Graphics.height - y)
  1332.     @option = option
  1333.     @data = []
  1334.     refresh
  1335.     select_last
  1336.   end
  1337.   #--------------------------------------------------------------------------
  1338.   # * Refresh
  1339.   #--------------------------------------------------------------------------
  1340.   def refresh
  1341.     make_option_list
  1342.     create_contents
  1343.     draw_all_items
  1344.   end
  1345.   #--------------------------------------------------------------------------
  1346.   # * Ottiene la lista delle opzioni dei valori
  1347.   #--------------------------------------------------------------------------
  1348.   def make_option_list
  1349.   end
  1350.   #--------------------------------------------------------------------------
  1351.   # * Restituisce il numero di oggetti
  1352.   #--------------------------------------------------------------------------
  1353.   def item_max
  1354.     return @data.nil? ? 0 : @data.size
  1355.   end
  1356.   #--------------------------------------------------------------------------
  1357.   # * Restituisce l'opzione selezionata
  1358.   #--------------------------------------------------------------------------
  1359.   def select_last
  1360.   end
  1361.   #--------------------------------------------------------------------------
  1362.   # * Restituisce la nuova opzione selezionata dall'utente
  1363.   #--------------------------------------------------------------------------
  1364.   def selected_value
  1365.     return @keys ? @keys[self.index] : self.index
  1366.   end
  1367. end
  1368.  
  1369. #==============================================================================
  1370. # ** Generic_PopupWindow
  1371. #------------------------------------------------------------------------------
  1372. #  Finestra dei popup generici delle opzioni
  1373. #==============================================================================
  1374. class Generic_PopupWindow < Window_OptionPopup
  1375.   #--------------------------------------------------------------------------
  1376.   # * Inizializzazione
  1377.   #   y: coordinata Y
  1378.   #   option: opzione del popup
  1379.   #--------------------------------------------------------------------------
  1380.   def initialize(y, option)
  1381.     super(y, option, 200)
  1382.   end
  1383.   #--------------------------------------------------------------------------
  1384.   # * disegna l'oggetto
  1385.   #--------------------------------------------------------------------------
  1386.   def draw_item(index)
  1387.     rect = item_rect(index)
  1388.     draw_text(rect, item(index))
  1389.   end
  1390.   #--------------------------------------------------------------------------
  1391.   # * Ottiene l'elenco dei valori dell'opzione
  1392.   #--------------------------------------------------------------------------
  1393.   def make_option_list
  1394.     @data = @option.values
  1395.     if @data.is_a?(Hash)
  1396.       @keys = @data.keys
  1397.       @data = @data.values
  1398.     end
  1399.   end
  1400.   #--------------------------------------------------------------------------
  1401.   # * Restituisce il valore selezionato
  1402.   #--------------------------------------------------------------------------
  1403.   def item(index = self.index)
  1404.     return @data[index]
  1405.   end
  1406.   #--------------------------------------------------------------------------
  1407.   # * Restituisce la chiave
  1408.   #--------------------------------------------------------------------------
  1409.   def key(index = self.index)
  1410.     return @keys[index]
  1411.   end
  1412.   #--------------------------------------------------------------------------
  1413.   # * Restituisce l'opzione selezionata
  1414.   #--------------------------------------------------------------------------
  1415.   def select_last
  1416.     if @option.values.is_a?(Array)
  1417.       self.index = [[@option.value, 0].max, @option.values.size-1].min
  1418.     else
  1419.       self.index = keys_from_hash
  1420.     end
  1421.   end
  1422.   #--------------------------------------------------------------------------
  1423.   # * Restituisce l'opzione selezionata dall'hash dei valori
  1424.   #--------------------------------------------------------------------------
  1425.   def keys_from_hash
  1426.     if @keys.find_index(@option.value)
  1427.       return @keys.find_index(@option.value)
  1428.     else
  1429.       return @keys.first
  1430.     end
  1431.   end
  1432. end
  1433.  
  1434. #==============================================================================
  1435. # ** Game_Temp
  1436. #------------------------------------------------------------------------------
  1437. #  Aggiunta dei parametri
  1438. #==============================================================================
  1439. class Game_Temp
  1440.   attr_accessor :in_game
  1441. end
  1442.  
  1443. #==============================================================================
  1444. # ** Game_System
  1445. #------------------------------------------------------------------------------
  1446. #  Aggiunta dei parametri
  1447. #==============================================================================
  1448. class Game_System
  1449.   attr_accessor :enabling_options
  1450.   def option_enable(tag, state)
  1451.     @enabling_options = {} if @enabling_options.nil?
  1452.     @enabling_options[tag] = state
  1453.   end
  1454. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement