dsiver144

Dark's Options Menu

Mar 11th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 14.72 KB | None | 0 0
  1. #===============================================================================
  2. #                     ╔══════════════════════════════════╗
  3. #                     ║ ▼ Dark's Options Menu            ║  
  4. #                     ║ ▼ Author: Nhat Nguyen (Dark Sky) ║
  5. #                     ║ ▼ Release Date: March 11th 2016  ║
  6. #                     ╚══════════════════════════════════╝
  7. #-------------------------------------------------------------------------------
  8. #                           Version 1.0: Release!
  9. #-------------------------------------------------------------------------------
  10. #                        Require: Basic Mouse System v2.7g
  11. #===============================================================================
  12.  
  13. module DarkOptions
  14.   Disable_Map_Mouse = true
  15.   HELP_WINDOW_INFO = {
  16.   :master_volume => "Điều chỉnh âm lượng của tòan bộ Game",
  17.   :bgm_volume    => "Điều chỉnh âm lượng nhạc nền của Game",
  18.   :se_volume     => "Điều chỉnh âm lượng hiệu ứng của Game",
  19.   }
  20. end
  21. class Scene_Menu < Scene_MenuBase
  22.   #--------------------------------------------------------------------------
  23.   # * Create Command Window
  24.   #--------------------------------------------------------------------------
  25.   alias dark_create_command_window_option create_command_window
  26.   def create_command_window
  27.     dark_create_command_window_option
  28.     @command_window.set_handler(:darkoptions, method(:command_options))
  29.   end
  30.   #--------------------------------------------------------------------------
  31.   # * Command options
  32.   #--------------------------------------------------------------------------
  33.   def command_options
  34.     SceneManager.call(Scene_MenuOptions)
  35.   end
  36. end
  37. #==============================================================================
  38. # ** Window_MenuCommand
  39. #------------------------------------------------------------------------------
  40. #  This command window appears on the menu screen.
  41. #==============================================================================
  42.  
  43. class Window_MenuCommand < Window_Command
  44.   #--------------------------------------------------------------------------
  45.   # * Add Original Commands to List
  46.   #--------------------------------------------------------------------------
  47.   alias dark_add_original_commands add_original_commands
  48.   def add_original_commands
  49.     dark_add_original_commands
  50.     add_command("Options",   :darkoptions,   true)
  51.   end
  52. end
  53.   module Mouse
  54.     class << self
  55.       alias dark_mouse_update update
  56.     end
  57.     def self.update
  58.       if SceneManager.scene_is?(Scene_Map) && DarkOptions::Disable_Map_Mouse == true
  59.         @enabled = false
  60.       else
  61.         if $game_switches[MOUSE_SWITCH] != true && USE_MOUSE_SWITCH == true
  62.           @enabled = true
  63.         end
  64.       end
  65.       dark_mouse_update
  66.     end
  67.   end
  68.   class Scene_MenuOptions < Scene_Base
  69.     #--------------------------------------------------------------------------
  70.     # * Start Processing
  71.     #--------------------------------------------------------------------------
  72.     def start
  73.       super
  74.       create_background
  75.       create_options
  76.       create_help_window
  77.     end
  78.     #--------------------------------------------------------------------------
  79.     # * Create Background
  80.     #--------------------------------------------------------------------------
  81.     def create_background
  82.       @background_sprite = Sprite.new
  83.       @background_sprite.bitmap = SceneManager.background_bitmap
  84.       @background_sprite.color.set(16, 16, 16, 128)
  85.     end
  86.     def create_options
  87.       @opt_window = Window_MenuOptions.new(0,0)
  88.       @opt_window.y = Graphics.height/2 - @opt_window.height/2
  89.       @opt_window.refresh
  90.     end
  91.     #--------------------------------------------------------------------------
  92.     # * Create Help Window
  93.     #--------------------------------------------------------------------------
  94.     def create_help_window
  95.       @help_window = Window_Help.new
  96.       @help_window.viewport = @viewport
  97.       @help_window.width = @opt_window.width
  98.       @help_window.x = @opt_window.x
  99.       @help_window.y = @opt_window.y - @opt_window.height + 25 + 15
  100.       @help_window.height -= 15
  101.       @help_window.create_contents
  102.       @help_window.refresh
  103.       @help_window.set_text(DarkOptions::HELP_WINDOW_INFO[@opt_window.current_symbol])
  104.     end
  105.     #--------------------------------------------------------------------------
  106.     # * Update
  107.     #--------------------------------------------------------------------------
  108.     def update
  109.       super
  110.       @help_window.set_text(DarkOptions::HELP_WINDOW_INFO[@opt_window.current_symbol])
  111.       if Input.trigger?(:B) or Mouse.rclick?
  112.         return_scene
  113.       end
  114.     end
  115.   end
  116.  
  117.   class Window_MenuOptions < Window_Command
  118.     def initialize(x,y)
  119.       rect1 = Rect.new(233,176,185,17)
  120.       rect2 = Rect.new(233,200,185,17)
  121.       rect3 = Rect.new(233,200+200-176,185,17)
  122.       @volume_rect = [rect1,rect2,rect3]
  123.       @delta = 0
  124.       super(x,y)
  125.       self.x = Graphics.width / 2 - window_width / 2
  126.     end
  127.     #--------------------------------------------------------------------------
  128.     # * Get Window Width
  129.     #--------------------------------------------------------------------------
  130.     def window_width
  131.       return 400
  132.     end
  133.     #--------------------------------------------------------------------------
  134.     # * Update
  135.     #--------------------------------------------------------------------------
  136.     def update
  137.       super
  138.       @sym = @list[@index][:symbol]
  139.       if Mouse.lclick?
  140.         if Mouse.pos?[0] >= @volume_rect[@index-1].x and Mouse.pos?[0] <= @volume_rect[@index-1].x + @volume_rect[@index-1].width
  141.           rate1 = (((Mouse.pos?[0]-233).to_f / 185)*100).to_i
  142.           rate2 = (Mouse.pos?[0]-233).to_f / 185
  143.           $game_options.dark_set_volume(@sym,rate2)
  144.           Audio.se_stop
  145.           sound = RPG::SE.new("Barrier")
  146.           sound.play
  147.           refresh
  148.         end
  149.       end
  150.       if Input.press?(:RIGHT)
  151.         if $game_options.get_volume(@sym) < 1.0
  152.           $game_options.change_volume(@sym,0.01)
  153.           refresh
  154.         end
  155.       end
  156.       if Input.trigger?(:RIGHT) or Input.trigger?(:LEFT)
  157.           Audio.se_stop
  158.           sound = RPG::SE.new("Barrier")
  159.           sound.play
  160.       end
  161.       if Input.press?(:LEFT)
  162.         if $game_options.get_volume(@sym) > 0
  163.           $game_options.change_volume(@sym,-0.01)
  164.           refresh
  165.         end
  166.       end
  167.     end
  168.     #--------------------------------------------------------------------------
  169.     # * Get Number of Lines to Show
  170.     #--------------------------------------------------------------------------
  171.     def visible_line_number
  172.       3
  173.     end
  174.     #--------------------------------------------------------------------------
  175.     # * Update Mouse
  176.     #--------------------------------------------------------------------------
  177.     def update_mouse
  178.       @timer -= 1
  179.       @mouse_all_rects = []
  180.       item_max.times {|i|
  181.         rect = item_rect(i)
  182.         rect.x += self.x + standard_padding - self.ox
  183.         rect.y += self.y + standard_padding - self.oy
  184.         if !self.viewport.nil?
  185.           rect.x += self.viewport.rect.x - self.viewport.ox
  186.           rect.y += self.viewport.rect.y - self.viewport.oy
  187.         end
  188.         @mouse_all_rects.push(rect) }
  189.       item_max.times {|i|
  190.         next if @timer > 0
  191.         next unless Mouse.within?(@mouse_all_rects[i])
  192.         @timer = 10 if i > top_row * 2 + page_item_max - 1
  193.         @timer = 10 if i < top_row * 2
  194.         self.index = i }
  195.       return if MOUSE_CLICK_WITHIN && !within_index
  196.     end
  197.     #--------------------------------------------------------------------------
  198.     # * Create Command List
  199.     #--------------------------------------------------------------------------
  200.     def make_command_list
  201.       add_main_commands
  202.     end
  203.     #--------------------------------------------------------------------------
  204.     # * Add Main Commands to List
  205.     #--------------------------------------------------------------------------
  206.     def add_main_commands
  207.       add_command("Master Volume",   :master_volume,   true)
  208.       add_command("BGM Volume",   :bgm_volume,   true)
  209.       add_command("SE Volume",   :se_volume,   true)
  210.     end
  211.     #--------------------------------------------------------------------------
  212.     # * Draw Item
  213.     #--------------------------------------------------------------------------
  214.     def draw_item(index)
  215.       colors = [Color.new(100,241,40),Color.new(255,171,0),Color.new(0,188,255)]
  216.       color1 = Color.new(255,255,255)
  217.       color2 = colors[index-1]
  218.       sym = @list[index][:symbol]
  219.       cc = ($game_options.get_volume(sym)*100).to_i
  220.       rate = $game_options.get_volume(sym)
  221.       change_color(normal_color, command_enabled?(index))
  222.       draw_text(item_rect_for_text(index), command_name(index), alignment)
  223.       contents.fill_rect(147,item_rect_for_text(index).y+1,191,19+3, Color.new(25,25,25,200))
  224.       contents.gradient_fill_rect( 150,item_rect_for_text(index).y+4,185*rate,15, color1, color2)
  225.       draw_text(item_rect_for_text(index),cc, 2)
  226.     end
  227.   end
  228.  
  229.    
  230. class Game_Options
  231.   attr_accessor  :fullscreen
  232.   attr_accessor  :resolution
  233.   attr_accessor  :master_volume
  234.   attr_accessor  :bgm_volume
  235.   attr_accessor  :se_volume
  236.   attr_accessor  :auto_save
  237.   attr_accessor  :message_se
  238.   def default_options
  239.     @fullscreen = false
  240.     @resolution = [544,416]
  241.     @master_volume = 1.0
  242.     @bgm_volume = 1.0
  243.     @se_volume = 1.0
  244.     @auto_save = true
  245.     @message_se = true
  246.     save_options
  247.   end
  248.  
  249.   def get_volume(type)
  250.     case type
  251.       when :bgm_volume
  252.         @bgm_volume
  253.       when :se_volume
  254.         @se_volume
  255.       when :master_volume
  256.         @master_volume
  257.     end
  258.   end
  259.  
  260.   def dark_set_volume(type,value)
  261.     case type
  262.       when :bgm_volume
  263.         @bgm_volume = value
  264.       when :se_volume
  265.         @se_volume = value
  266.       when :master_volume
  267.         @master_volume = value
  268.     end
  269.   end
  270.  
  271.   def change_volume(type,value)
  272.    
  273.     case type
  274.       when :bgm_volume
  275.         @bgm_volume += value
  276.       when :se_volume
  277.         @se_volume += value
  278.       when :master_volume
  279.         @master_volume += value
  280.     end
  281.  
  282.   end
  283.  
  284.   def load_options
  285.     if FileTest.exist?("System/Options.dt")
  286.       File.open("System/Options.dt", "rb") do |file|
  287.         $game_options = Marshal.load(file)
  288.       end
  289.     else
  290.       default_options
  291.     end
  292.     reset_screen
  293.   end
  294.   def reset_screen
  295.     if Module.const_defined?(:Window_Resize)
  296.       if $game_options.fullscreen
  297.         Window_Resize.f
  298.       else
  299.         Window_Resize.r($game_options.resolution[0],$game_options.resolution[1])
  300.       end
  301.     end
  302.   end
  303.   def save_options
  304.     File.open("System/Options.dt", "wb") do |file|
  305.       Marshal.dump($game_options, file)
  306.     end
  307.   end
  308.   def memorize_options
  309.     @old_options = Marshal.load(Marshal.dump($game_options))
  310.   end
  311.   def copy_memorize
  312.     $game_options = Marshal.load(Marshal.dump(@old_options))
  313.     reset_screen
  314.   end
  315.   def clear_memorize
  316.     @old_options = nil
  317.   end
  318.   def resolution_index
  319.     return 2 if @fullscreen
  320.     return 1 if @resolution[0] == 544*2
  321.     return 0
  322.   end
  323.   def set_resolution(w,h)
  324.     @resolution = [w,h]
  325.     @fullscreen = false
  326.     Window_Resize.window
  327.     15.times {|i| Graphics.update }
  328.     Window_Resize.r(@resolution[0],@resolution[1])
  329.   end
  330.   def set_fullscreen
  331.     @fullscreen = true
  332.     Window_Resize.f
  333.   end
  334.   def set_volume(symbol, value)
  335.     case symbol
  336.     when :master
  337.       @master_volume += value
  338.       @master_volume = [[@master_volume, 1].min, 0].max
  339.     when :bgm
  340.       @bgm_volume += value
  341.       @bgm_volume = [[@bgm_volume, 1].min, 0].max
  342.     when :se
  343.       @se_volume += value
  344.       @se_volume = [[@se_volume, 1].min, 0].max
  345.     end
  346.   end
  347.   def preset_volume(symbol, value)
  348.     if symbol == :master
  349.       @master_volume = value
  350.       @master_volume = [[@master_volume, 1].min, 0].max
  351.     end
  352.     if symbol == :bgm
  353.       @bgm_volume = value
  354.       @bgm_volume = [[@bgm_volume, 1].min, 0].max
  355.     end
  356.     if symbol == :se
  357.       @se_volume = value
  358.       @se_volume = [[@se_volume, 1].min, 0].max
  359.     end
  360.   end
  361. end
  362.  
  363. class RPG::BGM < RPG::AudioFile
  364.   def play(pos = 0)
  365.     if @name.empty?
  366.       Audio.bgm_stop
  367.       @@last = RPG::BGM.new
  368.     else
  369.       if $game_options
  370.         volume = @volume * $game_options.master_volume
  371.         volume *= $game_options.bgm_volume
  372.       else
  373.         volume = @volume
  374.       end
  375.       Audio.bgm_play('Audio/BGM/' + @name, volume.to_i, @pitch, pos)
  376.       @@last = self.clone
  377.     end
  378.   end
  379. end
  380.  
  381. class RPG::BGS < RPG::AudioFile
  382.   def play(pos = 0)
  383.     if @name.empty?
  384.       Audio.bgs_stop
  385.       @@last = RPG::BGS.new
  386.     else
  387.       if $game_options
  388.         volume = @volume * $game_options.master_volume
  389.         volume *= $game_options.bgm_volume
  390.       else
  391.         volume = @volume
  392.       end
  393.       Audio.bgs_play('Audio/BGS/' + @name, volume.to_i, @pitch, pos)
  394.       @@last = self.clone
  395.     end
  396.   end
  397. end
  398.  
  399. class RPG::ME < RPG::AudioFile
  400.   def play
  401.     if @name.empty?
  402.       Audio.me_stop
  403.     else
  404.       if $game_options
  405.         volume = @volume * $game_options.master_volume
  406.         volume *= $game_options.se_volume
  407.       else
  408.         volume = @volume
  409.       end
  410.       Audio.me_play('Audio/ME/' + @name, volume.to_i, @pitch)
  411.     end
  412.   end
  413. end
  414.  
  415. class RPG::SE < RPG::AudioFile
  416.   def play
  417.     unless @name.empty?
  418.       if $game_options
  419.         volume = @volume * $game_options.master_volume
  420.         volume *= $game_options.se_volume
  421.       else
  422.         volume = @volume
  423.       end
  424.       Audio.se_play('Audio/SE/' + @name, volume.to_i, @pitch)
  425.     end
  426.   end
  427. end
  428.  
  429. module SceneManager
  430.   def self.run
  431.     DataManager.init
  432.     Audio.setup_midi if use_midi?
  433.     $game_options = Game_Options.new
  434.     $game_options.load_options
  435.     @scene = first_scene_class.new
  436.     @scene.main while @scene
  437.   end
  438. end
  439.  
  440.  
  441. #==============================================================================
  442. # ** Scene_Save
  443. #------------------------------------------------------------------------------
  444. #  This class performs save screen processing.
  445. #==============================================================================
  446.  
  447. class Scene_Save < Scene_File
  448.   def on_save_success
  449.     $game_options.save_options
  450.     Sound.play_save
  451.     return_scene
  452.   end
  453. end
  454. #===============================================================================
  455. #                                END OF SCRIPT
  456. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment