Advertisement
Archeia

Basic Options Menu v1.3d High Res Edit

Jan 15th, 2015
823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 18.15 KB | None | 0 0
  1. #Basic Options Menu v1.3d
  2. #----------#
  3. #Features: Provides a simple option menu for the player to do optiony stuff...
  4. #           Like volume effects for all, bgm, and se's. Fancy!
  5. #          
  6. #          Also additional options if you have Basic Window Resizer,
  7. #           Basic Message SE, and Basic Autosave.
  8. #
  9. #Usage:    Plug and play unless you want a bit more. Customization below.
  10. #
  11. #----------#
  12. #-- Script by: V.M of D.T
  13. #
  14. #- Questions or comments can be:
  15. #    posted on the thread for the script
  16. #    given by email: sumptuaryspade@live.ca
  17. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  18. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  19. #
  20. #- Free to use in any project with credit given, donations always welcome!
  21.  
  22. #This lets you set the order of the windows via an array
  23. WINDOW_ORDER = [:master,:bgm,:se,:resolution,:switch,:message_se,:autosave]
  24. #Basic options are:
  25. #  :master - Master Volume               :bgm     - Background Music Volume
  26. #  :se     - Sound Effect Volume         :switch  - Allow the player to turn on/off a switch
  27. #
  28. #-- Additional Options are:
  29. #  :resolution     -   If you have Basic Window Resizer installed
  30. #  :message_se     -   If you have Basic Message SE installed
  31. #  :autosave       -   If you have Basic Autosave installed
  32.  
  33. #These are all the strings for the help window and headers:
  34. module OPT_STR
  35.   #When the command window is selected
  36.   COMMAND_HELP       = "Confirm and exit or simply exit"
  37.   #Details for :master
  38.   MASTER_VOLUME      = "Master Volume"
  39.   MASTER_VOLUME_HELP = "Set the volume of all sound"
  40.   #Details for :bgm
  41.   BGM_VOLUME         = "BGM Volume"
  42.   BGM_VOLUME_HELP    = "Set the volume of music"
  43.   #Details for :se
  44.   SE_VOLUME          = "SE Volume"
  45.   SE_VOLUME_HELP     = "Set the volume of sound effects"
  46.   #Details for :resolution
  47.   RESOLUTION         = "Resolution"
  48.   RESOLUTION_HELP    = "Change the resolution of the game window"
  49.   #Details for :autosave
  50.   AUTOSAVE           = "Autosave"
  51.   AUTOSAVE_HELP      = "Enable/Disable autosaving"
  52.   #Details for :message
  53.   MESSAGE_SE         = "Message SE"
  54.   MESSAGE_SE_HELP    = "Enable/Disable the message sound effect"
  55.   #Details for :switch
  56.   SWITCH_ID          = 5
  57.   SWITCH             = ""
  58.   SWITCH_HELP        = "Any unsaved progress will be lost"
  59.   SWITCH_COMMAND     = ["Change Resolution","Off"]
  60. end
  61.  
  62. class Scene_Options < Scene_MenuBase
  63.   def start
  64.     super
  65.     $game_options.memorize_options
  66.     create_base_windows
  67.     @current_index = 1
  68.     @window_index = []
  69.     @size = 0
  70.     WINDOW_ORDER.each do |symbol|
  71.       create_resolution_window if symbol == :resolution
  72.       create_autosave_window   if symbol == :autosave
  73.       create_master_window     if symbol == :master
  74.       create_bgm_window        if symbol == :bgm
  75.       create_se_window         if symbol == :se
  76.       create_message_se_window if symbol == :message_se
  77.       create_window_switch     if symbol == :switch
  78.     end
  79.     create_command_window
  80.     @index = 0
  81.     @old_index = @index
  82.     activate_window(0)
  83.   end
  84.   def create_base_windows
  85.     @help_window = Window_Help.new(1)
  86.     @help_window.set_text("Options")
  87.     @back_window = Window_Options.new
  88.     @back_window.height = (WINDOW_ORDER.size + 1)* 43 + 24
  89.     @back_window.create_contents
  90.   end
  91.   def create_command_window
  92.     @window_command = Window_OCommand.new(48+24 * @current_index)
  93.     @window_command.set_handler(:ok, method(:command_ok))
  94.     @window_index.push(:command)
  95.     @back_window.draw_line(24 * (@current_index - 1))
  96.   end
  97.   def create_resolution_window
  98.     if Module.const_defined?(:Window_Resize)
  99.       @window_resolution = Window_OR.new(48+24 * @current_index)
  100.       @window_resolution.set_handler(:ok, method(:resolution_ok))
  101.       @back_window.add_text(24 * (@current_index - 1),OPT_STR::RESOLUTION)
  102.       @current_index += 2
  103.       @size += 1
  104.       @window_index.push(:resolution)
  105.     end
  106.   end
  107.   def create_autosave_window
  108.     if Module.const_defined?(:AUTOSAVE_FILE_NAME)
  109.       @window_autosave = Window_OAS.new(48+24 * @current_index)
  110.       @window_autosave.set_handler(:ok, method(:autosave_ok))
  111.       @back_window.add_text(24 * (@current_index - 1),OPT_STR::AUTOSAVE)
  112.       @current_index += 2
  113.       @size += 1
  114.       @window_index.push(:autosave)
  115.     end
  116.   end
  117.   def create_master_window
  118.     @window_masterbar = Window_OBar.new(48+24 * @current_index)
  119.     @back_window.add_text(24 * (@current_index - 1),OPT_STR::MASTER_VOLUME)
  120.     @current_index += 2
  121.     @size += 1
  122.     @window_masterbar.refresh($game_options.master_volume)
  123.     @window_index.push(:master)
  124.   end
  125.   def create_bgm_window
  126.     @window_bgmbar = Window_OBar.new(48+24 * @current_index)
  127.     @back_window.add_text(24 * (@current_index - 1),OPT_STR::BGM_VOLUME)
  128.     @current_index += 2
  129.     @size += 1
  130.     @window_bgmbar.refresh($game_options.bgm_volume)
  131.     @window_index.push(:bgm)
  132.   end
  133.   def create_se_window
  134.     @window_sebar = Window_OBar.new(48+24*@current_index)
  135.     @back_window.add_text(24 * (@current_index - 1),OPT_STR::SE_VOLUME)
  136.     @current_index += 2
  137.     @size += 1
  138.     @window_sebar.refresh($game_options.se_volume)
  139.     @window_index.push(:se)
  140.   end
  141.   def create_message_se_window
  142.     if Window_Message.const_defined?(:DEFAULT_SE_FREQ)
  143.       @window_message = Window_OMSE.new(48+24 * @current_index)
  144.       @window_message.set_handler(:ok, method(:message_ok))
  145.       @back_window.add_text(24 * (@current_index - 1),OPT_STR::MESSAGE_SE)
  146.       @current_index += 2
  147.       @size += 1
  148.       @window_index.push(:message)
  149.     end
  150.   end
  151.   def create_window_switch
  152.     @window_switch = Window_OSW.new(35+24 * @current_index)
  153.     @window_switch.set_handler(:ok, method(:switch_ok))
  154.     @back_window.add_text(24 * (@current_index - 1),OPT_STR::SWITCH)
  155.     @back_window.contents.font.size = 24
  156.     @current_index += 2
  157.     @size += 1
  158.     @window_index.push(:switch)
  159.   end
  160.   def activate_window(index)
  161.     case @window_index[index]
  162.     when :resolution
  163.       @window_resolution.select(0)
  164.       @window_resolution.activate
  165.       @help_window.set_text(OPT_STR::RESOLUTION_HELP)
  166.     when :autosave
  167.       @window_autosave.select(0)
  168.       @window_autosave.activate
  169.       @help_window.set_text(OPT_STR::AUTOSAVE_HELP)
  170.     when :master
  171.       @window_masterbar.select(0)
  172.       @window_masterbar.activate
  173.       @help_window.set_text(OPT_STR::MASTER_VOLUME_HELP)
  174.     when :bgm
  175.       @window_bgmbar.select(0)
  176.       @window_bgmbar.activate
  177.       @help_window.set_text(OPT_STR::BGM_VOLUME_HELP)
  178.     when :se
  179.       @window_sebar.select(0)
  180.       @window_sebar.activate
  181.       @help_window.set_text(OPT_STR::SE_VOLUME_HELP)
  182.     when :message
  183.       @window_message.select(0)
  184.       @window_message.activate
  185.       @help_window.set_text(OPT_STR::MESSAGE_SE_HELP)
  186.     when :command
  187.       @window_command.select(0)
  188.       @window_command.activate
  189.       @help_window.set_text(OPT_STR::COMMAND_HELP)
  190.     when :switch
  191.       @window_switch.select(0)
  192.       @window_switch.activate
  193.       @help_window.set_text(OPT_STR::SWITCH_HELP)
  194.     end
  195.   end
  196.   def deactivate_window(index)
  197.     case @window_index[index]
  198.     when :resolution
  199.       @window_resolution.select(-1)
  200.       @window_resolution.deactivate
  201.     when :autosave
  202.       @window_autosave.select(-1)
  203.       @window_autosave.deactivate
  204.     when :master
  205.       @window_masterbar.select(-1)
  206.       @window_masterbar.deactivate
  207.     when :bgm
  208.       @window_bgmbar.select(-1)
  209.       @window_bgmbar.deactivate
  210.     when :se
  211.       @window_sebar.select(-1)
  212.       @window_sebar.deactivate
  213.     when :message
  214.       @window_message.select(-1)
  215.       @window_message.deactivate
  216.     when :command
  217.       @window_command.select(-1)
  218.       @window_command.deactivate
  219.     when :switch
  220.       @window_switch.select(-1)
  221.       @window_switch.deactivate
  222.     end
  223.   end
  224.   def update
  225.     super
  226.     update_input
  227.     update_index
  228.   end
  229.   def update_input
  230.     if Input.trigger?(:UP)
  231.       @index -= 1
  232.       @index = @size if @index < 0
  233.     elsif Input.trigger?(:DOWN)
  234.       @index += 1
  235.       @index = 0 if @index > @size
  236.     elsif Input.repeat?(:LEFT)
  237.       change_volume(@index, -0.01)
  238.     elsif Input.repeat?(:RIGHT)
  239.       change_volume(@index, 0.01)
  240.     elsif Input.trigger?(:B)
  241.       @index = @size
  242.     end
  243.   end
  244.   def update_index
  245.     return if @index == @old_index
  246.     deactivate_window(@old_index)
  247.     activate_window(@index)
  248.     Sound.play_cursor
  249.     @old_index = @index
  250.   end
  251.   def change_volume(index, value)
  252.     return unless audio_index(index)
  253.     $game_options.set_volume(:master, value) if @window_index[index] == :master
  254.     $game_options.set_volume(:bgm, value) if @window_index[index] == :bgm
  255.     $game_options.set_volume(:se, value) if @window_index[index] == :se
  256.     @window_masterbar.refresh($game_options.master_volume)
  257.     @window_bgmbar.refresh($game_options.bgm_volume)
  258.     @window_sebar.refresh($game_options.se_volume)
  259.     Sound.play_cursor
  260.     $game_map.autoplay if $game_map && $game_map.map_id > 0
  261.   end
  262.   def audio_index(index)
  263.     return true if @window_index[index] == :master
  264.     return true if @window_index[index] == :bgm
  265.     return true if @window_index[index] == :se
  266.     return false
  267.   end
  268.   def resolution_ok
  269.     case @window_resolution.index
  270.     when 0
  271.       $game_options.set_resolution(Graphics.width,Graphics.height)
  272.     when 1
  273.       $game_options.set_fullscreen
  274.     when 2
  275.       $game_options.set_fullscreen
  276.     end
  277.     @window_resolution.refresh
  278.     @window_resolution.activate
  279.   end
  280.   def autosave_ok
  281.     $game_options.auto_save = true if @window_autosave.index == 0
  282.     $game_options.auto_save = false if @window_autosave.index == 1
  283.     @window_autosave.refresh
  284.     @window_autosave.activate
  285.   end
  286.   def message_ok
  287.     $game_options.message_se = true if @window_message.index == 0
  288.     $game_options.message_se = false if @window_message.index == 1
  289.     @window_message.refresh
  290.     @window_message.activate
  291.   end
  292.   def switch_ok
  293.     SceneManager.goto(Scene_ResSel)
  294.   end
  295.   def command_ok
  296.     case @window_command.index
  297.     when 0
  298.       $game_options.save_options
  299.       $game_options.clear_memorize
  300.       return_scene
  301.     when 1
  302.       $game_options.copy_memorize
  303.       $game_options.clear_memorize
  304.       return_scene
  305.     end
  306.   end
  307. end
  308.  
  309. class Window_Options < Window_Base
  310.   def initialize
  311.     super(0,48,Graphics.width,Graphics.height-48)
  312.     self.contents.font.color = Color.new(150,100,255,200)
  313.   end
  314.   def add_text(y,string)
  315.     draw_text(15,y,Graphics.width-24,24,string)
  316.   end
  317.   def draw_line(y)
  318.     contents.fill_rect(15,y+12,Graphics.width-24,1,Color.new(75,75,75))
  319.   end
  320. end
  321.  
  322. class Window_OR < Window_Selectable
  323.   TEXT = ["Windowed","Full""screen"]
  324.   def initialize(y)
  325.     super(24,y,Graphics.width-48,48)
  326.     refresh
  327.     self.opacity = 0
  328.   end
  329.   def item_width; self.contents.width / 4; end
  330.   def item_max; return 2; end
  331.   def col_max; return item_max; end
  332.   def row_max; return 1; end
  333.   def draw_item(index)
  334.     rect = item_rect(index)
  335.     change_color(normal_color, index == $game_options.resolution_index)
  336.     draw_text(rect, TEXT[index],1)
  337.   end
  338. end
  339.  
  340. class Window_OAS < Window_Selectable
  341.   def initialize(y)
  342.     super(24,y,Graphics.width-48,48)
  343.     refresh
  344.     self.opacity = 0
  345.   end
  346.   def item_width; return 118; end
  347.   def item_max; return 2; end
  348.   def col_max; return item_max; end
  349.   def row_max; return 1; end
  350.   def draw_item(index)
  351.     rect = item_rect(index)
  352.     $game_options.auto_save ? id = 0 : id = 1
  353.     change_color(normal_color, id == index)
  354.     draw_text(rect, ["Yes","No"][index],1)
  355.   end
  356. end
  357.  
  358. class Window_OSW < Window_Selectable
  359.   def initialize(y)
  360.     super(24,y,Graphics.width-48,48)
  361.     refresh
  362.     self.opacity = 0
  363.   end
  364.   def item_width; return 205; end
  365.   def item_max; return 1; end
  366.   def col_max; return item_max; end
  367.   def row_max; return 1; end
  368.   def draw_item(index)
  369.     rect = item_rect(index)
  370.     $game_switches[OPT_STR::SWITCH_ID] ? id = 0 : id = 1
  371.     change_color(normal_color, id == index)
  372.     contents.font.size = 24
  373.     draw_text(rect, [OPT_STR::SWITCH_COMMAND[0],OPT_STR::SWITCH_COMMAND[1]][index],1)
  374.  
  375.   end
  376. end
  377.  
  378. class Window_OCommand < Window_Selectable
  379.   def initialize(y)
  380.     super(24+96,y,Graphics.width-48,48)
  381.     refresh
  382.     self.opacity = 0
  383.   end
  384.   def item_width; return 118; end
  385.   def item_max; return 2; end
  386.   def col_max; return item_max; end
  387.   def row_max; return 1; end
  388.   def draw_item(index)
  389.     rect = item_rect(index)
  390.     draw_text(rect, ["Apply","Cancel"][index],1)
  391.   end
  392. end
  393.  
  394. class Window_OMSE < Window_OAS
  395.   def initialize(y)
  396.     super
  397.     self.y = y
  398.     refresh
  399.     self.opacity = 0
  400.   end
  401.   def draw_item(index)
  402.     rect = item_rect(index)
  403.     $game_options.message_se ? id = 0 : id = 1
  404.     change_color(normal_color, id == index)
  405.     draw_text(rect, ["Yes","No"][index],1)
  406.   end
  407. end
  408.  
  409. class Window_OBar < Window_Selectable
  410.   def initialize(y)
  411.     super(24,y,Graphics.width-48,48)
  412.     self.opacity = 0
  413.   end
  414.   def item_width; return contents.width; end
  415.   def item_max; return 1; end
  416.   def col_max; return item_max; end
  417.   def row_max; return 1; end
  418.   def refresh(temp_value)
  419.     contents.clear
  420.     temp_value *= 100
  421.     temp_value.to_i.times do |i|
  422.       rect = Rect.new(4+i*4,6,2,8)
  423.       contents.fill_rect(rect, Color.new(75,100,255))
  424.     end
  425.     (100-temp_value).to_i.times do |i|
  426.       rect = Rect.new(396-i*4,6,2,8)
  427.       contents.fill_rect(rect, Color.new(0,0,0))
  428.     end
  429.     draw_text(0,0,contents.width,24,temp_value.to_i.to_s + "%",2)
  430.   end
  431.   def update_mouse
  432.   end
  433. end
  434.  
  435. class Game_Options
  436.   attr_accessor  :fullscreen
  437.   attr_accessor  :resolution
  438.   attr_accessor  :master_volume
  439.   attr_accessor  :bgm_volume
  440.   attr_accessor  :se_volume
  441.   attr_accessor  :auto_save
  442.   attr_accessor  :message_se
  443.   def default_options
  444.     @fullscreen = false
  445.     @resolution = [Graphics.width,Graphics.height]
  446.     @master_volume = 1.0
  447.     @bgm_volume = 1.0
  448.     @se_volume = 1.0
  449.     @auto_save = true
  450.     @message_se = true
  451.     save_options
  452.   end
  453.   def load_options
  454.     if FileTest.exist?("System/Options.dt")
  455.       File.open("System/Options.dt", "rb") do |file|
  456.         $game_options = Marshal.load(file)
  457.       end
  458.     else
  459.       default_options
  460.     end
  461.     reset_screen
  462.   end
  463.   def reset_screen
  464.     if Module.const_defined?(:Window_resize)
  465.       if $game_options.fullscreen
  466.         Window_Resize.f
  467.       else
  468.         Window_Resize.r($game_options.resolution[0],$game_options.resolution[1])
  469.       end
  470.     end
  471.   end
  472.   def save_options
  473.     File.open("System/Options.dt", "wb") do |file|
  474.       Marshal.dump($game_options, file)
  475.     end
  476.   end
  477.   def memorize_options
  478.     @old_options = Marshal.load(Marshal.dump($game_options))
  479.   end
  480.   def copy_memorize
  481.     $game_options = Marshal.load(Marshal.dump(@old_options))
  482.     reset_screen
  483.   end
  484.   def clear_memorize
  485.     @old_options = nil
  486.   end
  487.   def resolution_index
  488.     return 1 if @fullscreen
  489.     return 2 if @resolution[0] == Graphics.width*2
  490.     return 0
  491.   end
  492.   def set_resolution(w,h)
  493.     @resolution = [w,h]
  494.     @fullscreen = false
  495.     Window_Resize.window
  496.     15.times {|i| Graphics.update }
  497.     Window_Resize.r(@resolution[0],@resolution[1])
  498.   end
  499.   def set_fullscreen
  500.     @fullscreen = true
  501.     Window_Resize.f
  502.   end
  503.   def set_volume(symbol, value)
  504.     case symbol
  505.     when :master
  506.       @master_volume += value
  507.       @master_volume = [[@master_volume, 1].min, 0].max
  508.     when :bgm
  509.       @bgm_volume += value
  510.       @bgm_volume = [[@bgm_volume, 1].min, 0].max
  511.     when :se
  512.       @se_volume += value
  513.       @se_volume = [[@se_volume, 1].min, 0].max
  514.     end
  515.   end
  516.   def preset_volume(symbol, value)
  517.     if symbol == :master
  518.       @master_volume = value
  519.       @master_volume = [[@master_volume, 1].min, 0].max
  520.     end
  521.     if symbol == :bgm
  522.       @bgm_volume = value
  523.       @bgm_volume = [[@bgm_volume, 1].min, 0].max
  524.     end
  525.     if symbol == :se
  526.       @se_volume = value
  527.       @se_volume = [[@se_volume, 1].min, 0].max
  528.     end
  529.   end
  530. end
  531.  
  532. class RPG::BGM < RPG::AudioFile
  533.   def play(pos = 0)
  534.     if @name.empty?
  535.       Audio.bgm_stop
  536.       @@last = RPG::BGM.new
  537.     else
  538.       if $game_options
  539.         volume = @volume * $game_options.master_volume
  540.         volume *= $game_options.bgm_volume
  541.       else
  542.         volume = @volume
  543.       end
  544.       Audio.bgm_play('Audio/BGM/' + @name, volume.to_i, @pitch, pos)
  545.       @@last = self.clone
  546.     end
  547.   end
  548. end
  549.  
  550. class RPG::BGS < RPG::AudioFile
  551.   def play(pos = 0)
  552.     if @name.empty?
  553.       Audio.bgs_stop
  554.       @@last = RPG::BGS.new
  555.     else
  556.       if $game_options
  557.         volume = @volume * $game_options.master_volume
  558.         volume *= $game_options.bgm_volume
  559.       else
  560.         volume = @volume
  561.       end
  562.       Audio.bgs_play('Audio/BGS/' + @name, volume.to_i, @pitch, pos)
  563.       @@last = self.clone
  564.     end
  565.   end
  566. end
  567.  
  568. class RPG::ME < RPG::AudioFile
  569.   def play
  570.     if @name.empty?
  571.       Audio.me_stop
  572.     else
  573.       if $game_options
  574.         volume = @volume * $game_options.master_volume
  575.         volume *= $game_options.se_volume
  576.       else
  577.         volume = @volume
  578.       end
  579.       Audio.me_play('Audio/ME/' + @name, volume.to_i, @pitch)
  580.     end
  581.   end
  582. end
  583.  
  584. class RPG::SE < RPG::AudioFile
  585.   def play
  586.     unless @name.empty?
  587.       if $game_options
  588.         volume = @volume * $game_options.master_volume
  589.         volume *= $game_options.se_volume
  590.       else
  591.         volume = @volume
  592.       end
  593.       Audio.se_play('Audio/SE/' + @name, volume.to_i, @pitch)
  594.     end
  595.   end
  596. end
  597.  
  598. module SceneManager
  599.   def self.run
  600.     DataManager.init
  601.     Audio.setup_midi if use_midi?
  602.     $game_options = Game_Options.new
  603.     $game_options.load_options
  604.     @scene = first_scene_class.new
  605.     @scene.main while @scene
  606.   end
  607. end
  608.  
  609. class Window_MenuCommand < Window_Command
  610.   alias options_aoc add_original_commands
  611.   def add_original_commands
  612.     options_aoc
  613.     add_command("Options", :options)
  614.   end
  615. end
  616.  
  617. class Scene_Menu < Scene_MenuBase
  618.   alias options_create_command_window create_command_window
  619.   def create_command_window
  620.     options_create_command_window
  621.     @command_window.set_handler(:options,   method(:command_options))
  622.   end
  623.   def command_options
  624.     SceneManager.call(Scene_Options)
  625.   end
  626. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement