Advertisement
Holy87

Game Extra Options

Feb 8th, 2017
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 20.02 KB | None | 0 0
  1. =begin
  2.  ==============================================================================
  3.   ■ Add-on Opzioni di Holy87
  4.       versione 1.0.01
  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.     Questo script aggiunge nuovi comandi alle opzioni di gioco, tra cui:
  11.     ● Opzioni volume (musica, sottofondo ed effetti sonori)
  12.     ● Opzione dimensione della finestra (per ingrandirla senza andare in full-screen)
  13.     ● Opzione corsa automatica
  14.     ● Opzione comparsa testo rapida
  15.     ● Opzione per disattivare le animazioni di battaglia
  16.  ==============================================================================
  17.   ■ Compatibilità
  18.     DataManager -> alias create_game_objects
  19.  ==============================================================================
  20.   ■ Installazione e istruzioni
  21.     Installare questo script sotto Materials e prima del Main.
  22.     RICHIEDE IL MODULO DI SUPPORTO UNIVERSALE DI HOLY87 E LO SCRIPT DELLE
  23.     OPZIONI (ovviamente).
  24.     Lo script è Plug&Play. Puoi modificare alcuni settaggi in basso, nella
  25.     sezione CONFIGURAZIONE.
  26.  ==============================================================================
  27. =end
  28.  
  29. #==============================================================================
  30. # ** CONFIGURAZIONE
  31. #------------------------------------------------------------------------------
  32. #  Configura i testi e le opzioni
  33. #==============================================================================
  34. module Gameplay_Settings
  35.   #--------------------------------------------------------------------------
  36.   # * Impostazioni di base. Cancella o cambia l'ordine degli elementi per
  37.   #   rimuovere o spostare le opzioni.
  38.   #--------------------------------------------------------------------------
  39.   COMMANDS = [:autodash, :fastmsg, :battle_anim, :bgm, :bgs, :se, :screen_size]
  40.   #--------------------------------------------------------------------------
  41.   # * Switch e variabili
  42.   #--------------------------------------------------------------------------
  43.   AUTODASH_SW = 101           # switch per l'auto corsa
  44.   FASTMSG_SW = 102            # switch per i messaggi rapidi
  45.   BATTLE_ANIM_SW = 103        # switch per le animazioni di battaglia
  46.   BGM_VOLUME_VAR = 101        # variabile volume musica
  47.   BGS_VOLUME_VAR = 102        # variabile volume sottofondo
  48.   SE_VOLUME_VAR = 103         # variabile volume effetti
  49.   BGM_MUTE_SW = 104           # switch musica OFF
  50.   BGS_MUTE_SW = 105           # switch musica ON
  51.   SE_MUTE_SW = 106            # switch effetti OFF
  52.   #--------------------------------------------------------------------------
  53.   # * Vocaboli
  54.   #--------------------------------------------------------------------------
  55.   AUTODASH_HELP = 'Scegli se attivare la corsa automatica.'
  56.   AUTODASH_CMD = 'Auto corsa'
  57.   AUTODASH_ON = 'Sì'
  58.   AUTODASH_OFF = 'No'
  59.   FASTMSG_HELP = 'Scegli se mostrare i messaggi istantaneamente.'
  60.   FASTMSG_CMD = 'Comparsa testo'
  61.   FASTMSG_ON = 'Istantaneo'
  62.   FASTMSG_OFF = 'Normale'
  63.   BATTLE_ANIM_HELP = 'Scegli se nascondere le animazioni di battaglia.'
  64.   BATTLE_ANIM_CMD = 'Anim. battaglia'
  65.   BATTLE_ANIM_ON = 'Nascondi'
  66.   BATTLE_ANIM_OFF = 'Mostra'
  67.   BGM_CMD = 'Volume Musica'
  68.   BGM_HELP = 'Regola il volume della musica.'
  69.   BGS_CMD = 'Volume ambiente'
  70.   BGS_HELP = 'Regola il volume dell\'ambiente.'
  71.   SE_CMD = 'Volume effetti'
  72.   SE_HELP = 'Regola il volume degli effetti sonori.'
  73.   SCREEN_CMD = 'Grandezza Finestra'
  74.   SCREEN_HELP = 'Regola le dimensioni della finestra di gioco.'
  75.   #--------------------------------------------------------------------------
  76.   # * Altri settaggi
  77.   #--------------------------------------------------------------------------
  78.   SCREEN_SIZES = [1, 1.5, 2, 4] # proporzioni dello schermo
  79. end
  80.  
  81. #==============================================================================
  82. # ** FINE CONFIGURAZIONE
  83. #------------------------------------------------------------------------------
  84. #                 - ATTENZIONE: NON MODIFICARE OLTRE! -
  85. #==============================================================================
  86.  
  87.  
  88.  
  89. $imported = {} if $imported == nil
  90. $imported['H87_GameOptions'] = 1.0
  91. #==============================================================================
  92. # ** Screen_Size
  93. #==============================================================================
  94. class Screen_Size
  95.   attr_accessor :width
  96.   attr_accessor :height
  97.   #--------------------------------------------------------------------------
  98.   # * Object initialization
  99.   # @param [Integer] width
  100.   # @param [Integer] height
  101.   #--------------------------------------------------------------------------
  102.   def initialize(width, height)
  103.     @width = width.to_i
  104.     @height = height.to_i
  105.   end
  106.   #--------------------------------------------------------------------------
  107.   # *
  108.   # @param [String] text
  109.   # @return [Screen_Size]
  110.   # @raise [Error]
  111.   #--------------------------------------------------------------------------
  112.   def self.from_s(text)
  113.     if text =~ /(.+)x(.+)/
  114.       Screen_Size.new($1.to_i, $2.to_i)
  115.     else
  116.       raise('Errore: Proporzioni non valide')
  117.     end
  118.   end
  119.   #--------------------------------------------------------------------------
  120.   # * Make a printable string format (ex. '640x480')
  121.   # @return [String]
  122.   #--------------------------------------------------------------------------
  123.   def to_s; sprintf('%dx%d', self.width, self.height); end
  124. end
  125.  
  126. #==============================================================================
  127. # ** Gameplay_Settings
  128. #------------------------------------------------------------------------------
  129. # Core methods for this script
  130. #==============================================================================
  131. module Gameplay_Settings
  132.   SECTIONS = { # this hash handles sections. Really, it is too complicated!
  133.       :autodash => :game, :fastmsg => :game, :battle_anim => :game,
  134.       :bgm => :audio, :bgs => :audio, :se => :audio, :screen_size => :graphic
  135.   }
  136.   #--------------------------------------------------------------------------
  137.   # * Add the options to the settings menu
  138.   #--------------------------------------------------------------------------
  139.   def self.add_options
  140.     (0..COMMANDS.size-1).each { |i|
  141.       command = COMMANDS[i]
  142.       hash = HASHES[command]
  143.       case SECTIONS[command]
  144.         when :game
  145.           H87Options.push_game_option(hash)
  146.         when :audio
  147.           H87Options.push_sound_option(hash)
  148.         when :graphic
  149.           H87Options.push_graphic_option(hash)
  150.         else
  151.           H87Options.push_generic_option(hash)
  152.       end
  153.     }
  154.   end
  155.   #--------------------------------------------------------------------------
  156.   # * Returns a Screen_Size object from the current resolution * rate
  157.   # @param [Number] rate
  158.   # @return [Screen_Size]
  159.   #--------------------------------------------------------------------------
  160.   def self.screen_size(rate)
  161.     Screen_Size.new(Graphics.width * rate, Graphics.height * rate)
  162.   end
  163.   #--------------------------------------------------------------------------
  164.   # * Gets avaiable screen sizes for your display
  165.   # @return [Array]
  166.   #--------------------------------------------------------------------------
  167.   def self.get_screen_sizes
  168.     sizes = []
  169.     SCREEN_SIZES.each {|size|
  170.       sizes.push(screen_size(size)) if size_possible?(screen_size(size))
  171.     }
  172.     sizes
  173.   end
  174.   #--------------------------------------------------------------------------
  175.   # * Returns an array of sizes
  176.   # @param [Array] screen_sizes
  177.   #--------------------------------------------------------------------------
  178.   def self.screen_value_array(screen_sizes)
  179.     values = []
  180.     screen_sizes.each{|size|
  181.       values.push(size.to_s)
  182.     }
  183.     values
  184.   end
  185.   #--------------------------------------------------------------------------
  186.   # * Returns an array of strings showing all sizes possible
  187.   # ex. [544x420, 640x480, ..] from all rates
  188.   # @param [Screen_Size] screen
  189.   #--------------------------------------------------------------------------
  190.   def self.size_possible?(screen)
  191.     resolution = Win.screen_resolution
  192.     screen.width <= resolution[0] && screen.height <= resolution[1]
  193.   end
  194.   #--------------------------------------------------------------------------
  195.   # * Returns the variable ID for the specified volume
  196.   #--------------------------------------------------------------------------
  197.   def self.volume_var_id(type)
  198.     vols = {:bgm => BGM_VOLUME_VAR, :bgs => BGS_VOLUME_VAR, :se => SE_VOLUME_VAR}
  199.     vols[type]
  200.   end
  201.   #--------------------------------------------------------------------------
  202.   # * Returns the mute switch ID for the specified volume
  203.   #--------------------------------------------------------------------------
  204.   def self.volume_sw_id(type)
  205.     vols = {:bgm => BGM_MUTE_SW, :bgs => BGS_MUTE_SW, :se => SE_MUTE_SW}
  206.     vols[type]
  207.   end
  208.   #--------------------------------------------------------------------------
  209.   # * Command hashes
  210.   #--------------------------------------------------------------------------
  211.   HASHES = {
  212.       :autodash => { :type => :switch,
  213.                      :text => AUTODASH_CMD,
  214.                      :help => AUTODASH_HELP,
  215.                      :sw   => AUTODASH_SW,
  216.                      :on   => AUTODASH_ON,
  217.                      :off  => AUTODASH_OFF,
  218.                      :default => false, },
  219.       :fastmsg => { :type => :switch,
  220.                     :text => FASTMSG_CMD,
  221.                     :help => FASTMSG_HELP,
  222.                     :sw   => FASTMSG_SW,
  223.                     :on   => FASTMSG_ON,
  224.                     :off  => FASTMSG_OFF,
  225.                     :default => false, },
  226.       :battle_anim => { :type => :switch,
  227.                         :text => BATTLE_ANIM_CMD,
  228.                         :help => BATTLE_ANIM_HELP,
  229.                         :sw   => BATTLE_ANIM_SW,
  230.                         :on   => BATTLE_ANIM_ON,
  231.                         :off  => BATTLE_ANIM_OFF,
  232.                         :default => false, },
  233.       :bgm => {
  234.           :type => :bar,
  235.           :text => BGM_CMD,
  236.           :help => BGM_HELP,
  237.           :max => 100,
  238.           :var => BGM_VOLUME_VAR,
  239.           :sw => BGM_MUTE_SW,
  240.           :default => 100,
  241.           :method => :update_bgm},
  242.       :bgs => {
  243.           :type => :bar,
  244.           :text => BGS_CMD,
  245.           :help => BGS_HELP,
  246.           :max => 100,
  247.           :var => BGS_VOLUME_VAR,
  248.           :sw => BGS_MUTE_SW,
  249.           :default => 100,
  250.           :method => :update_bgs},
  251.       :se => {
  252.           :type => :bar,
  253.           :text => SE_CMD,
  254.           :help => SE_HELP,
  255.           :max => 100,
  256.           :var => SE_VOLUME_VAR,
  257.           :sw => SE_MUTE_SW,
  258.           :default => 100},
  259.       :screen_size => {
  260.           :type => :variable,
  261.           :text => SCREEN_CMD,
  262.           :help => SCREEN_HELP,
  263.           :values => screen_value_array(get_screen_sizes),
  264.           :var => 'screen_size',
  265.           :method => :update_screen,
  266.           :open_popup => get_screen_sizes.size > 3,
  267.           :default => 0}
  268.   }
  269. end
  270. # finally adds the options to the menu
  271. Gameplay_Settings.add_options
  272.  
  273. class Option
  274.   #--------------------------------------------------------------------------
  275.   # * Screen update method
  276.   #--------------------------------------------------------------------------
  277.   def update_screen(value)
  278.     Graphics.update_screen_resolution
  279.   end
  280.   #--------------------------------------------------------------------------
  281.   # * BGM update method
  282.   #--------------------------------------------------------------------------
  283.   def update_bgm(value)
  284.     RPG::BGM::last.play
  285.   end
  286.   #--------------------------------------------------------------------------
  287.   # * BGS update method
  288.   #--------------------------------------------------------------------------
  289.   def update_bgs(value)
  290.     RPG::BGS::last.play
  291.   end
  292. end
  293.  
  294. module Graphics
  295.   #--------------------------------------------------------------------------
  296.   # * Updates the window width
  297.   #--------------------------------------------------------------------------
  298.   def self.update_screen_resolution
  299.     return unless $game_settings
  300.     return unless $game_settings['screen_size']
  301.     value = $game_settings['screen_size']
  302.     rate = Gameplay_Settings::SCREEN_SIZES[value]
  303.     if rate.nil?
  304.       $game_settings['screen_size'] = 0
  305.       rate = 1
  306.     end
  307.     screen = Gameplay_Settings.screen_size(rate)
  308.     if Gameplay_Settings.size_possible?(screen)
  309.       Screen.resize(screen.width, screen.height)
  310.     end
  311.   end
  312. end
  313.  
  314. #==============================================================================
  315. # ** Game_Player
  316. #==============================================================================
  317. class Game_Player < Game_Character
  318.   #--------------------------------------------------------------------------
  319.   # * Determine if Dashing
  320.   #--------------------------------------------------------------------------
  321.   def dash?
  322.     return false if @move_route_forcing
  323.     return false if $game_map.disable_dash?
  324.     return false if vehicle
  325.     player_run?
  326.   end
  327.   #--------------------------------------------------------------------------
  328.   # * Determine if player is running
  329.   #--------------------------------------------------------------------------
  330.   def player_run?
  331.     if $game_system.autodash_on?
  332.       !Input.press?(:A)
  333.     else
  334.       Input.press?(:A)
  335.     end
  336.   end
  337. end
  338.  
  339. #==============================================================================
  340. # ** Game_System
  341. #==============================================================================
  342. class Game_System
  343.   #--------------------------------------------------------------------------
  344.   # * Checks if autodash is setted ON
  345.   #--------------------------------------------------------------------------
  346.   def autodash_on?
  347.     $game_switches[Gameplay_Settings::AUTODASH_SW]
  348.   end
  349.   #--------------------------------------------------------------------------
  350.   # * Checks if fast message is setted ON
  351.   #--------------------------------------------------------------------------
  352.   def fast_message_on?
  353.     $game_switches[Gameplay_Settings::FASTMSG_SW]
  354.   end
  355.   #--------------------------------------------------------------------------
  356.   # * Checks if the battle animation is disabled
  357.   #--------------------------------------------------------------------------
  358.   def hide_battle_animation?
  359.     $game_switches[Gameplay_Settings::BATTLE_ANIM_SW]
  360.   end
  361. end
  362.  
  363. #==============================================================================
  364. # ** Window_Message
  365. #==============================================================================
  366. class Window_Message < Window_Base
  367.   alias classic_show_fast update_show_fast unless $@
  368.   #--------------------------------------------------------------------------
  369.   # * Alias method update show fast
  370.   #--------------------------------------------------------------------------
  371.   def update_show_fast
  372.     @show_fast = true if $game_system.fast_message_on?
  373.     classic_show_fast
  374.   end
  375. end
  376.  
  377. #==============================================================================
  378. # ** Window_Message
  379. #==============================================================================
  380. class Scene_Battle < Scene_Base
  381.   alias classic_show_anim_h87 show_animation unless $@
  382.   #--------------------------------------------------------------------------
  383.   # * Alias method show battle animation
  384.   #--------------------------------------------------------------------------
  385.   def show_animation(targets, animation_id)
  386.     return if $game_system.hide_battle_animation?
  387.     classic_show_anim_h87(targets, animation_id)
  388.   end
  389. end
  390.  
  391. #==============================================================================
  392. # ** Audio
  393. #==============================================================================
  394. module Audio
  395.   # noinspection RubyResolve
  396.   class << self
  397.     alias opt_old_bgm_play bgm_play
  398.     alias opt_old_bgs_play bgs_play
  399.     alias opt_old_me_play me_play
  400.     alias opt_old_se_play se_play
  401.   end
  402.   #--------------------------------------------------------------------------
  403.   # * Returns the BGM and ME volume (value from 0 to 100)
  404.   #--------------------------------------------------------------------------
  405.   def self.music_volume
  406.     return 100 unless $game_variables
  407.     return 0 unless $game_switches[Gameplay_Settings.volume_sw_id(:bgm)]
  408.     [[$game_variables[Gameplay_Settings.volume_var_id(:bgm)], 0].max, 100].min
  409.   end
  410.   #--------------------------------------------------------------------------
  411.   # * Returns the BGS volume (value from 0 to 100)
  412.   #--------------------------------------------------------------------------
  413.   def self.environment_volume
  414.     return 100 unless $game_variables
  415.     return 0 unless $game_switches[Gameplay_Settings.volume_sw_id(:bgs)]
  416.     [[$game_variables[Gameplay_Settings.volume_var_id(:bgs)], 0].max, 100].min
  417.   end
  418.   #--------------------------------------------------------------------------
  419.   # * Returns the SE volume (value from 0 to 100)
  420.   #--------------------------------------------------------------------------
  421.   def self.sound_volume
  422.     return 100 unless $game_variables
  423.     return 0 unless $game_switches[Gameplay_Settings.volume_sw_id(:se)]
  424.     [[$game_variables[Gameplay_Settings.volume_var_id(:se)], 0].max, 100].min
  425.   end
  426.   #--------------------------------------------------------------------------
  427.   # * Alias method: bgm_play
  428.   #--------------------------------------------------------------------------
  429.   def self.bgm_play(filename, volume = 100, pitch = 100, pos = 0)
  430.     volume = volume * music_volume / 100
  431.     opt_old_bgm_play(filename, volume, pitch, pos)
  432.   end
  433.   #--------------------------------------------------------------------------
  434.   # * Alias method: bgs_play
  435.   #--------------------------------------------------------------------------
  436.   def self.bgs_play(filename, volume = 100, pitch = 100, pos = 0)
  437.     volume = volume * environment_volume / 100
  438.     opt_old_bgs_play(filename, volume, pitch, pos)
  439.   end
  440.   #--------------------------------------------------------------------------
  441.   # * Alias method: me_play
  442.   #--------------------------------------------------------------------------
  443.   def self.me_play(filename, volume = 100, pitch = 100)
  444.     volume = volume * music_volume / 100
  445.     opt_old_me_play(filename, volume, pitch)
  446.   end
  447.   #--------------------------------------------------------------------------
  448.   # * Alias method: se_play
  449.   #--------------------------------------------------------------------------
  450.   def self.se_play(filename, volume = 100, pitch = 100)
  451.     volume = volume * sound_volume / 100
  452.     opt_old_se_play(filename, volume, pitch)
  453.   end
  454. end
  455.  
  456. #==============================================================================
  457. # ** DataManager
  458. #==============================================================================
  459. module DataManager
  460.   class << self
  461.     alias h87gameopt_create_game_objects create_game_objects
  462.   end
  463.   #--------------------------------------------------------------------------
  464.   # * Game objects creation
  465.   #--------------------------------------------------------------------------
  466.   def self.create_game_objects
  467.     h87gameopt_create_game_objects
  468.     adjust_sound_variables
  469.   end
  470.   #--------------------------------------------------------------------------
  471.   # * Initialize sound variables and switches
  472.   #--------------------------------------------------------------------------
  473.   def self.adjust_sound_variables
  474.     $game_variables[Gameplay_Settings.volume_var_id(:bgm)] = 100
  475.     $game_variables[Gameplay_Settings.volume_var_id(:bgs)] = 100
  476.     $game_variables[Gameplay_Settings.volume_var_id(:se)] = 100
  477.     $game_switches[Gameplay_Settings.volume_sw_id(:bgm)] = true
  478.     $game_switches[Gameplay_Settings.volume_sw_id(:bgs)] = true
  479.     $game_switches[Gameplay_Settings.volume_sw_id(:se)] = true
  480.     Graphics.update_screen_resolution
  481.   end
  482. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement