设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索

[RMVA]游戏设置系统(菜单)

查看数: 4567 | 评论数: 4 | 收藏 4
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2017-2-7 12:48

正文摘要:

嗯,叫设置系统也许有点夸张了…… 以前是在用XP的,最近转到VA上了,不过……这两都一样,没有游戏设置。(话说开发商为什么不集成一下……) 总之……以前用过XP版的设置系统,后来决定移植到VA上, 说是移植, ...

回复

beka 发表于 2017-9-4 08:36:32
藤原妹红丶 发表于 2017-8-13 17:27
楼主你好,我想问一下 这脚本是否可以将中间的框框删除 替换一张背景图呢? ...

可以的。最近比较忙没怎么看论坛,请谅解……

重新修改了一下,添加了一个sprite显示窗口背景。代码见下。

要改窗口背景地址和按钮窗口的透明度,修改17-18行的内容就行
注意窗口背景图片会自动居中,为了照顾原窗口的大小建议使用440*310

RUBY 代码复制
  1. #==============================================================================
  2. # ★☆ Game Setting
  3. #------------------------------------------------------------------------------
  4. #    游戏设置菜单 图片背景版
  5. #         By Beka
  6. #                     MinoGS 2017
  7. #
  8. # Free for non commercial and commercial use
  9. # Licence : [url]http://creativecommons.org/licenses/by-sa/3.0/[/url]
  10. #==============================================================================
  11. #
  12. # 在任意位置调用打开菜单请执行以下脚本:
  13. #  SceneManager.call(Scene_Setting)
  14. #
  15. #==============================================================================
  16. GS_Set_Define = {
  17.   "path" => "Graphics/Characters/!$Gate2",# 窗口背景地址(建议440*310)
  18.   "butopacity" => 128 # 按钮窗口的透明度(0-255)
  19. }
  20.  
  21. GS_Set_Def = {
  22.   "music" => 10,
  23.   "sound" => 10,
  24.   "full"  => false
  25. }# 默认缺省设置
  26. #==============================================================================
  27. # ** GameSetting
  28. #------------------------------------------------------------------------------
  29. #  游戏设置模块
  30. #==============================================================================
  31. module Option
  32.   # 用语
  33.   Setting    = "设置"
  34.   OK         = "确定"
  35.   Cancel     = "取消"
  36.   Reset      = "重置"
  37.   MusicVol   = "音乐音量:"
  38.   SoundVol   = "音效音量:"
  39.   Fullscreen = "全屏模式:"
  40.   SwitchON   = "ON"
  41.   SwitchOFF  = "OFF"
  42.  
  43.   # 功能函数
  44.   def self.Fullscr(fulls = true)
  45.     if fulls && !Fullscr? # 窗口模式切全屏
  46.       keybd = Win32API.new 'user32.dll', 'keybd_event', ['i', 'i', 'l', 'l'], 'v'
  47.       keybd.call 0xA4, 0, 0, 0
  48.       keybd.call 13, 0, 0, 0
  49.       keybd.call 13, 0, 2, 0
  50.       keybd.call 0xA4, 0, 2, 0
  51.     elsif !fulls && Fullscr? # 全屏模式切窗口
  52.       keybd = Win32API.new 'user32.dll', 'keybd_event', ['i', 'i', 'l', 'l'], 'v'
  53.       keybd.call 0xA4, 0, 0, 0
  54.       keybd.call 13, 0, 0, 0
  55.       keybd.call 13, 0, 2, 0
  56.       keybd.call 0xA4, 0, 2, 0
  57.     end
  58.   end
  59.   def self.Fullscr?
  60.     get_foreground_wnd = Win32API.new('user32', 'GetForegroundWindow', 'v', 'i')
  61.     get_wnd_long = Win32API.new('user32', 'GetWindowLong', 'ii', 'l')
  62.     if (get_wnd_long.call(get_foreground_wnd.call, -16) & 0x00c00000) == 0
  63.       return true
  64.     else
  65.       return false
  66.     end
  67.   end
  68.   def self.load_setting
  69.     if FileTest.exist?("System/Setting.gsd")
  70.       $GS_Set = load_data("System/Setting.gsd")
  71.     else
  72.       $GS_Set = GS_Set_Def.clone
  73.     end
  74.   end
  75. end
  76. Option.load_setting
  77. Option.Fullscr($GS_Set["full"])
  78.  
  79. #==============================================================================
  80. # ** Scene_Setting
  81. #------------------------------------------------------------------------------
  82. #  处理游戏系统的设置菜单
  83. #==============================================================================
  84. class Scene_Setting < Scene_Base
  85.   #--------------------------------------------------------------------------
  86.   # * Start Processing
  87.   #--------------------------------------------------------------------------
  88.   def start
  89.     super
  90.     create_background
  91.     setting_load
  92.     $GS_Set["full"] = Option.Fullscr?
  93.     create_window
  94.   end
  95.   #--------------------------------------------------------------------------
  96.   # * Termination Processing
  97.   #--------------------------------------------------------------------------
  98.   def terminate
  99.     super
  100.     dispose_background
  101.   end
  102.   #--------------------------------------------------------------------------
  103.   # * Create Background
  104.   #--------------------------------------------------------------------------
  105.   def create_background
  106.     @background_sprite = Sprite.new
  107.     @background_sprite.bitmap = SceneManager.background_bitmap
  108.     @background_sprite.color.set(16, 16, 16, 128)
  109.   end
  110.   #--------------------------------------------------------------------------
  111.   # * Free Background
  112.   #--------------------------------------------------------------------------
  113.   def dispose_background
  114.     @cur.dispose
  115.     @val.dispose
  116.     @main_window.dispose
  117.     @main_back.bitmap.dispose
  118.     @main_back.dispose
  119.     @button_window.dispose
  120.     @background_sprite.dispose
  121.   end
  122.   #--------------------------------------------------------------------------
  123.   # * 创建窗口
  124.   #--------------------------------------------------------------------------
  125.   def create_window
  126.     @main_window = Window_Base.new(0,0, 440, 260)
  127.     @main_window.opacity = 0
  128.     @main_back = Sprite.new
  129.     @main_back.z = @main_window.z - 1
  130.     @main_back.bitmap = Bitmap.new(GS_Set_Define["path"])
  131.     @button_window = Window_SetButton.new(0,0, 440, 50)
  132.     @button_window.set_handler(:ok,         method(:command_ok))
  133.     @button_window.set_handler(:cancel, method(:command_cancel))
  134.     @button_window.set_handler(:reset,   method(:command_reset))
  135.     @button_window.opacity = GS_Set_Define["butopacity"]
  136.     center_window
  137.     # 光标所在的位置(0为按钮窗口,1-3为选项)
  138.     @cur_index = 0
  139.     # 绘制 UI 文字
  140.     @main_window.contents.font.size = 28
  141.     @main_window.contents.font.color.set(255, 255, 128, 255)
  142.     rect = Rect.new(0, 0, @main_window.contents.width, 50)
  143.     @main_window.contents.draw_text(rect, Option::Setting, 1)
  144.     @main_window.contents.font.size = Font.default_size
  145.     draw_x = 40
  146.     @main_window.contents.draw_text(draw_x, 50,150,50, Option::MusicVol,  0)
  147.     @main_window.contents.draw_text(draw_x,110,150,50, Option::SoundVol,  0)
  148.     @main_window.contents.draw_text(draw_x,170,150,50, Option::Fullscreen,0)
  149.     @main_window.contents.font.color.set(255, 255, 255, 255)
  150.     draw_x = @main_window.contents.width - 128
  151.     @main_window.contents.draw_text(draw_x, 50,130,50,"[-]    [+]",1)
  152.     @main_window.contents.draw_text(draw_x,110,130,50,"[-]    [+]",1)
  153.     # 绘制指针与值
  154.     @cur = Sprite.new
  155.     @cur.bitmap = Bitmap.new(40,50)
  156.     @cur.x = @main_window.x + 12
  157.     @cur.z = @main_window.z + 1
  158.     @cur.bitmap.font.color.set(255, 255, 128, 255)
  159.     @cur.bitmap.draw_text(0,0,40,50,">>",1)
  160.     @val = Sprite.new
  161.     @val.bitmap = Bitmap.new(130,200)
  162.     @val.x = @cur.x + @main_window.contents.width - 128
  163.     @val.y = @main_window.y + 12 + 50
  164.     @val.z = @cur.z
  165.     draw_val_cur(@cur_index)
  166.   end
  167.   #--------------------------------------------------------------------------
  168.   # * 居中窗口
  169.   #--------------------------------------------------------------------------
  170.   def center_window
  171.     @main_window.x = (Graphics.width - @main_window.width) / 2
  172.     @button_window.x = @main_window.x
  173.     @main_window.y = (Graphics.height - @main_window.height - @button_window.height) / 2
  174.     @button_window.y = @main_window.y + @main_window.height
  175.     @main_back.x = (Graphics.width - @main_back.width) / 2
  176.     @main_back.y = (Graphics.height - @main_back.height) / 2
  177.   end
  178.   #--------------------------------------------------------------------------
  179.   # * 重写父类的刷新,用于接管键盘输入
  180.   #--------------------------------------------------------------------------
  181.   def update
  182.     last_index = @cur_index
  183.     super
  184.     @cur_index = (@cur_index - 1) % 4 if Input.repeat?(Input::UP)
  185.     @cur_index = (@cur_index + 1) % 4 if Input.repeat?(Input::DOWN)
  186.  
  187.     if last_index != @cur_index
  188.       @cur_index == 0 ? button_enable : button_disable
  189.       last_index = @cur_index
  190.     end
  191.     case @cur_index
  192.     when 1 # Volunm
  193.       $GS_Set["music"] -= 1 if $GS_Set["music"] > 0  && Input.trigger?(Input::LEFT)
  194.       $GS_Set["music"] += 1 if $GS_Set["music"] < 10 && Input.trigger?(Input::RIGHT)
  195.       RPG::BGM.last.play if RPG::BGM.last!= nil
  196.     when 2 #Sound FX
  197.       if Input.trigger?(Input::LEFT)
  198.         $GS_Set["sound"] -= 1 if $GS_Set["sound"] > 0
  199.         Sound.play_cursor
  200.       end
  201.       if Input.trigger?(Input::RIGHT)
  202.         $GS_Set["sound"] += 1 if $GS_Set["sound"] < 10
  203.         Sound.play_cursor
  204.       end
  205.     when 3 # Full Screen
  206.       switch_val("full") if Input.trigger?(Input::LEFT) || Input.trigger?(Input::RIGHT)
  207.     end
  208.     draw_val_cur(@cur_index)
  209.     command_cancel if Input.trigger?(Input::B) && @cur_index != 0
  210.   end
  211.   #--------------------------------------------------------------------------
  212.   # * 绘制值与光标
  213.   #--------------------------------------------------------------------------
  214.   def draw_val_cur(cur_index)
  215.     @val.bitmap.clear
  216.     @val.bitmap.draw_text(0,  0,130,50,$GS_Set["music"].to_s,1)
  217.     @val.bitmap.draw_text(0, 60,130,50,$GS_Set["sound"].to_s,1)
  218.     status = $GS_Set["full"] ? Option::SwitchON : Option::SwitchOFF
  219.     @val.bitmap.draw_text(0,120,130,50,status,1)
  220.     @cur.opacity = cur_index == 0 ? 0 : 255
  221.     @cur.y = @main_window.y + 62 + 60 * (cur_index - 1)
  222.   end
  223.   #--------------------------------------------------------------------------
  224.   # * 启用与停用按钮窗口
  225.   #--------------------------------------------------------------------------
  226.   def button_enable
  227.     @button_window.active = true
  228.     @button_window.update_cursor
  229.   end
  230.   def button_disable
  231.     @button_window.active = false
  232.     @button_window.cursor_rect.empty
  233.   end
  234.   #--------------------------------------------------------------------------
  235.   # * 切换开关(布尔值)
  236.   #--------------------------------------------------------------------------
  237.   def switch_val(val)
  238.     $GS_Set[val] = !$GS_Set[val]
  239.   end
  240.  
  241.   def get_text_size(str)
  242.     text = Bitmap.new(1,1)
  243.     rect = text.text_size(str)
  244.     return [rect.width, rect.height]
  245.   end
  246.   #--------------------------------------------------------------------------
  247.   # * 菜单项功能定义
  248.   #--------------------------------------------------------------------------
  249.   def command_ok
  250.     setting_save
  251.     # 改变屏幕
  252.     $GS_Set["full"] ? Option.Fullscr : Option.Fullscr(false)
  253.     Graphics.freeze
  254.     return_scene
  255.   end
  256.   def command_cancel
  257.     Graphics.freeze
  258.     return_scene
  259.     setting_load
  260.   end
  261.   def command_reset
  262.     setting_reset
  263.     draw_val_cur(0)
  264.     button_enable
  265.   end
  266.   #--------------------------------------------------------------------------
  267.   # * 存储与载入设置数据文件
  268.   #--------------------------------------------------------------------------
  269.   def setting_save
  270.     save_data($GS_Set,"System/Setting.gsd")
  271.   end
  272.   def setting_load
  273.     if FileTest.exist?("System/Setting.gsd")
  274.       $GS_Set = load_data("System/Setting.gsd")
  275.     else
  276.       setting_reset
  277.       setting_save
  278.     end
  279.   end
  280.   def setting_reset
  281.     $GS_Set = GS_Set_Def.clone
  282.     RPG::BGM.last.play if RPG::BGM.last!= nil
  283.   end
  284. end
  285.  
  286. #==============================================================================
  287. # ** Window_SettingButton
  288. #==============================================================================
  289. class Window_SetButton < Window_HorzCommand
  290.   def initialize(x, y, w_width ,w_height)
  291.     @w_width = w_width
  292.     @w_height = w_height
  293.     super(x, y)
  294.     select(1)
  295.   end
  296.   #--------------------------------------------------------------------------
  297.   # * Get Window Width
  298.   #--------------------------------------------------------------------------
  299.   def window_width
  300.     return @w_width
  301.   end
  302.   def window_height
  303.     return @w_height
  304.   end
  305.   #--------------------------------------------------------------------------
  306.   # * Get Digit Count
  307.   #--------------------------------------------------------------------------
  308.   def col_max
  309.     return 3
  310.   end
  311.   #--------------------------------------------------------------------------
  312.   # * Create Command List
  313.   #--------------------------------------------------------------------------
  314.   def make_command_list
  315.     add_command(Option::OK,         :ok)
  316.     add_command(Option::Cancel, :cancel)
  317.     add_command(Option::Reset,   :reset)
  318.   end
  319. end
  320. #==============================================================================
  321. # ** 重定义增加设置入口
  322. #==============================================================================
  323. class Scene_Title < Scene_Base
  324.   alias org_create_win create_command_window
  325.   def create_command_window
  326.     org_create_win
  327.     @command_window.set_handler(:setting, method(:command_setting))
  328.   end
  329.   def command_setting
  330.     close_command_window
  331.     SceneManager.call(Scene_Setting)
  332.   end
  333. end
  334. class Window_TitleCommand < Window_Command
  335.   def make_command_list
  336.     add_command(Vocab::new_game, :new_game)
  337.     add_command(Vocab::continue, :continue, continue_enabled)
  338.     add_command(Option::Setting, :setting)
  339.     add_command(Vocab::shutdown, :shutdown)
  340.   end
  341. end
  342. class Scene_Menu < Scene_MenuBase
  343.   alias org_create_win create_command_window
  344.   def create_command_window
  345.     org_create_win
  346.     @command_window.set_handler(:setting, method(:command_setting))
  347.   end
  348.   def command_setting
  349.     SceneManager.call(Scene_Setting)
  350.   end
  351. end
  352. class Window_MenuCommand < Window_Command
  353.   def make_command_list
  354.     add_main_commands
  355.     add_formation_command
  356.     add_original_commands
  357.     add_save_command
  358.     add_setting
  359.     add_game_end_command
  360.   end
  361.   def add_setting
  362.     add_command(Option::Setting, :setting)
  363.   end
  364. end
  365. #==============================================================================
  366. # ** Game Setting
  367. #------------------------------------------------------------------------------
  368. #  重定义类
  369. #==============================================================================
  370. class RPG::BGM < RPG::AudioFile
  371.   def play(pos = 0)
  372.     if @name.empty?
  373.       Audio.bgm_stop
  374.       @@last = RPG::BGM.new
  375.     else
  376.       Audio.bgm_play('Audio/BGM/' + @name, @volume * $GS_Set["music"] / 10, @pitch, pos)
  377.       @@last = self.clone
  378.     end
  379.   end
  380. end
  381.  
  382. class RPG::BGS < RPG::AudioFile
  383.   def play(pos = 0)
  384.     if @name.empty?
  385.       Audio.bgs_stop
  386.       @@last = RPG::BGS.new
  387.     else
  388.       Audio.bgs_play('Audio/BGS/' + @name, @volume * $GS_Set["sound"] / 10, @pitch, pos)
  389.       @@last = self.clone
  390.     end
  391.   end
  392. end
  393.  
  394. class RPG::ME < RPG::AudioFile
  395.   def play
  396.     if @name.empty?
  397.       Audio.me_stop
  398.     else
  399.       Audio.me_play('Audio/ME/' + @name, @volume * $GS_Set["sound"] / 10, @pitch)
  400.     end
  401.   end
  402. end
  403.  
  404. class RPG::SE < RPG::AudioFile
  405.   def play
  406.     unless @name.empty?
  407.       Audio.se_play('Audio/SE/' + @name, @volume * $GS_Set["sound"] / 10, @pitch)
  408.     end
  409.   end
  410. end
藤原妹红丶 发表于 2017-8-13 17:27:47
楼主你好,我想问一下 这脚本是否可以将中间的框框删除 替换一张背景图呢?
吸血狼人 发表于 2017-7-17 16:19:28
进游戏不先设置音量不舒服斯基星人感谢卤煮ww
beka 发表于 2017-2-7 14:04:04
拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-11-23 17:54

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表