查看: 5138|回复: 4

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

[复制链接]
梦石
0
星屑
155
在线时间
34 小时
注册时间
2016-12-22
回帖
2
发表于 2017-2-7 12:48:34 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
嗯,叫设置系统也许有点夸张了……

以前是在用XP的,最近转到VA上了,不过……这两都一样,没有游戏设置。(话说开发商为什么不集成一下……)

总之……以前用过XP版的设置系统,后来决定移植到VA上,
说是移植,其实也是照着样子重写了一遍代码,VA和XP很多地方都变了(尤其是VA引入了ScenceManager)

其他的也不多说了,请看图吧

vas1.PNG

vas2.PNG

vas3.PNG

另外提一句,这里用的全屏是VA默认的全屏方式(按Alt+Enter的效果)。如果用了Fullscreen++,需要把module Option中原来的“def self.Fullscr”部分替换成一下内容:

[pre lang="ruby"]
  def self.Fullscr(fulls = true)
    Graphics.fullscreen_mode if fulls && !Fullscr?
    Graphics.windowed_mode if !fulls && Fullscr?
  end
[/pre]

有需要的就拿去吧~

SettingDemo.zip

1.43 MB, 下载次数: 477

VA的游戏设置

梦石
0
星屑
155
在线时间
34 小时
注册时间
2016-12-22
回帖
2
 楼主| 发表于 2017-2-7 14:04:04 | 显示全部楼层
回复

使用道具 举报

梦石
0
星屑
507
在线时间
72 小时
注册时间
2011-8-19
回帖
11
发表于 2017-7-17 16:19:28 | 显示全部楼层
进游戏不先设置音量不舒服斯基星人感谢卤煮ww
回复

使用道具 举报

梦石
0
星屑
50
在线时间
36 小时
注册时间
2017-8-9
回帖
1
发表于 2017-8-13 17:27:47 | 显示全部楼层
楼主你好,我想问一下 这脚本是否可以将中间的框框删除 替换一张背景图呢?
回复

使用道具 举报

梦石
0
星屑
155
在线时间
34 小时
注册时间
2016-12-22
回帖
2
 楼主| 发表于 2017-9-4 08:36:32 | 显示全部楼层
藤原妹红丶 发表于 2017-8-13 17:27
楼主你好,我想问一下 这脚本是否可以将中间的框框删除 替换一张背景图呢? ...

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

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

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

[pre lang="ruby"]#==============================================================================
# ★☆ Game Setting
#------------------------------------------------------------------------------
#    游戏设置菜单 图片背景版
#         By Beka
#                     MinoGS 2017
#
# Free for non commercial and commercial use
# Licence : http://creativecommons.org/licenses/by-sa/3.0/
#==============================================================================
#
# 在任意位置调用打开菜单请执行以下脚本:
#  SceneManager.call(Scene_Setting)
#
#==============================================================================
GS_Set_Define = {
  "path" => "Graphics/Characters/!$Gate2",# 窗口背景地址(建议440*310)
  "butopacity" => 128 # 按钮窗口的透明度(0-255)
}

GS_Set_Def = {
  "music" => 10,
  "sound" => 10,
  "full"  => false
}# 默认缺省设置
#==============================================================================
# ** GameSetting
#------------------------------------------------------------------------------
#  游戏设置模块
#==============================================================================
module Option
  # 用语
  Setting    = "设置"
  OK         = "确定"
  Cancel     = "取消"
  Reset      = "重置"
  MusicVol   = "音乐音量:"
  SoundVol   = "音效音量:"
  Fullscreen = "全屏模式:"
  SwitchON   = "ON"
  SwitchOFF  = "OFF"

  # 功能函数
  def self.Fullscr(fulls = true)
    if fulls && !Fullscr? # 窗口模式切全屏
      keybd = Win32API.new 'user32.dll', 'keybd_event', ['i', 'i', 'l', 'l'], 'v'
      keybd.call 0xA4, 0, 0, 0
      keybd.call 13, 0, 0, 0
      keybd.call 13, 0, 2, 0
      keybd.call 0xA4, 0, 2, 0
    elsif !fulls && Fullscr? # 全屏模式切窗口
      keybd = Win32API.new 'user32.dll', 'keybd_event', ['i', 'i', 'l', 'l'], 'v'
      keybd.call 0xA4, 0, 0, 0
      keybd.call 13, 0, 0, 0
      keybd.call 13, 0, 2, 0
      keybd.call 0xA4, 0, 2, 0
    end
  end
  def self.Fullscr?
    get_foreground_wnd = Win32API.new('user32', 'GetForegroundWindow', 'v', 'i')
    get_wnd_long = Win32API.new('user32', 'GetWindowLong', 'ii', 'l')
    if (get_wnd_long.call(get_foreground_wnd.call, -16) & 0x00c00000) == 0
      return true
    else
      return false
    end
  end
  def self.load_setting
    if FileTest.exist?("System/Setting.gsd")
      $GS_Set = load_data("System/Setting.gsd")
    else
      $GS_Set = GS_Set_Def.clone
    end
  end
end
Option.load_setting
Option.Fullscr($GS_Set["full"])

#==============================================================================
# ** Scene_Setting
#------------------------------------------------------------------------------
#  处理游戏系统的设置菜单
#==============================================================================
class Scene_Setting < Scene_Base
  #--------------------------------------------------------------------------
  # * Start Processing
  #--------------------------------------------------------------------------
  def start
    super
    create_background
    setting_load
    $GS_Set["full"] = Option.Fullscr?
    create_window
  end
  #--------------------------------------------------------------------------
  # * Termination Processing
  #--------------------------------------------------------------------------
  def terminate
    super
    dispose_background
  end
  #--------------------------------------------------------------------------
  # * Create Background
  #--------------------------------------------------------------------------
  def create_background
    @background_sprite = Sprite.new
    @background_sprite.bitmap = SceneManager.background_bitmap
    @background_sprite.color.set(16, 16, 16, 128)
  end
  #--------------------------------------------------------------------------
  # * Free Background
  #--------------------------------------------------------------------------
  def dispose_background
    @cur.dispose
    @val.dispose
    @main_window.dispose
    @main_back.bitmap.dispose
    @main_back.dispose
    @button_window.dispose
    @background_sprite.dispose
  end
  #--------------------------------------------------------------------------
  # * 创建窗口
  #--------------------------------------------------------------------------
  def create_window
    @main_window = Window_Base.new(0,0, 440, 260)
    @main_window.opacity = 0
    @main_back = Sprite.new
    @main_back.z = @main_window.z - 1
    @main_back.bitmap = Bitmap.new(GS_Set_Define["path"])
    @button_window = Window_SetButton.new(0,0, 440, 50)
    @button_window.set_handler(:ok,         method(:command_ok))
    @button_window.set_handler(:cancel, method(:command_cancel))
    @button_window.set_handler(:reset,   method(:command_reset))
    @button_window.opacity = GS_Set_Define["butopacity"]
    center_window
    # 光标所在的位置(0为按钮窗口,1-3为选项)
    @cur_index = 0
    # 绘制 UI 文字
    @main_window.contents.font.size = 28
    @main_window.contents.font.color.set(255, 255, 128, 255)
    rect = Rect.new(0, 0, @main_window.contents.width, 50)
    @main_window.contents.draw_text(rect, Option::Setting, 1)
    @main_window.contents.font.size = Font.default_size
    draw_x = 40
    @main_window.contents.draw_text(draw_x, 50,150,50, Option::MusicVol,  0)
    @main_window.contents.draw_text(draw_x,110,150,50, Option::SoundVol,  0)
    @main_window.contents.draw_text(draw_x,170,150,50, Option::Fullscreen,0)
    @main_window.contents.font.color.set(255, 255, 255, 255)
    draw_x = @main_window.contents.width - 128
    @main_window.contents.draw_text(draw_x, 50,130,50,"[-]    [+]",1)
    @main_window.contents.draw_text(draw_x,110,130,50,"[-]    [+]",1)
    # 绘制指针与值
    @cur = Sprite.new
    @cur.bitmap = Bitmap.new(40,50)
    @cur.x = @main_window.x + 12
    @cur.z = @main_window.z + 1
    @cur.bitmap.font.color.set(255, 255, 128, 255)
    @cur.bitmap.draw_text(0,0,40,50,">>",1)
    @val = Sprite.new
    @val.bitmap = Bitmap.new(130,200)
    @val.x = @cur.x + @main_window.contents.width - 128
    @val.y = @main_window.y + 12 + 50
    @val.z = @cur.z
    draw_val_cur(@cur_index)
  end
  #--------------------------------------------------------------------------
  # * 居中窗口
  #--------------------------------------------------------------------------
  def center_window
    @main_window.x = (Graphics.width - @main_window.width) / 2
    @button_window.x = @main_window.x
    @main_window.y = (Graphics.height - @main_window.height - @button_window.height) / 2
    @button_window.y = @main_window.y + @main_window.height
    @main_back.x = (Graphics.width - @main_back.width) / 2
    @main_back.y = (Graphics.height - @main_back.height) / 2
  end
  #--------------------------------------------------------------------------
  # * 重写父类的刷新,用于接管键盘输入
  #--------------------------------------------------------------------------
  def update
    last_index = @cur_index
    super
    @cur_index = (@cur_index - 1) % 4 if Input.repeat?(Input::UP)
    @cur_index = (@cur_index + 1) % 4 if Input.repeat?(Input::DOWN)
   
    if last_index != @cur_index
      @cur_index == 0 ? button_enable : button_disable
      last_index = @cur_index
    end
    case @cur_index
    when 1 # Volunm
      $GS_Set["music"] -= 1 if $GS_Set["music"] > 0  && Input.trigger?(Input::LEFT)
      $GS_Set["music"] += 1 if $GS_Set["music"] < 10 && Input.trigger?(Input::RIGHT)
      RPG::BGM.last.play if RPG::BGM.last!= nil
    when 2 #Sound FX
      if Input.trigger?(Input::LEFT)
        $GS_Set["sound"] -= 1 if $GS_Set["sound"] > 0
        Sound.play_cursor
      end
      if Input.trigger?(Input::RIGHT)
        $GS_Set["sound"] += 1 if $GS_Set["sound"] < 10
        Sound.play_cursor
      end
    when 3 # Full Screen
      switch_val("full") if Input.trigger?(Input::LEFT) || Input.trigger?(Input::RIGHT)
    end
    draw_val_cur(@cur_index)
    command_cancel if Input.trigger?(Input::B) && @cur_index != 0
  end
  #--------------------------------------------------------------------------
  # * 绘制值与光标
  #--------------------------------------------------------------------------
  def draw_val_cur(cur_index)
    @val.bitmap.clear
    @val.bitmap.draw_text(0,  0,130,50,$GS_Set["music"].to_s,1)
    @val.bitmap.draw_text(0, 60,130,50,$GS_Set["sound"].to_s,1)
    status = $GS_Set["full"] ? Option::SwitchON : Option::SwitchOFF
    @val.bitmap.draw_text(0,120,130,50,status,1)
    @cur.opacity = cur_index == 0 ? 0 : 255
    @cur.y = @main_window.y + 62 + 60 * (cur_index - 1)
  end
  #--------------------------------------------------------------------------
  # * 启用与停用按钮窗口
  #--------------------------------------------------------------------------
  def button_enable
    @button_window.active = true
    @button_window.update_cursor
  end
  def button_disable
    @button_window.active = false
    @button_window.cursor_rect.empty
  end
  #--------------------------------------------------------------------------
  # * 切换开关(布尔值)
  #--------------------------------------------------------------------------
  def switch_val(val)
    $GS_Set[val] = !$GS_Set[val]
  end
  
  def get_text_size(str)
    text = Bitmap.new(1,1)
    rect = text.text_size(str)
    return [rect.width, rect.height]
  end
  #--------------------------------------------------------------------------
  # * 菜单项功能定义
  #--------------------------------------------------------------------------
  def command_ok
    setting_save
    # 改变屏幕
    $GS_Set["full"] ? Option.Fullscr : Option.Fullscr(false)
    Graphics.freeze
    return_scene
  end
  def command_cancel
    Graphics.freeze
    return_scene
    setting_load
  end
  def command_reset
    setting_reset
    draw_val_cur(0)
    button_enable
  end
  #--------------------------------------------------------------------------
  # * 存储与载入设置数据文件
  #--------------------------------------------------------------------------
  def setting_save
    save_data($GS_Set,"System/Setting.gsd")
  end
  def setting_load
    if FileTest.exist?("System/Setting.gsd")
      $GS_Set = load_data("System/Setting.gsd")
    else
      setting_reset
      setting_save
    end
  end
  def setting_reset
    $GS_Set = GS_Set_Def.clone
    RPG::BGM.last.play if RPG::BGM.last!= nil
  end
end

#==============================================================================
# ** Window_SettingButton
#==============================================================================
class Window_SetButton < Window_HorzCommand
  def initialize(x, y, w_width ,w_height)
    @w_width = w_width
    @w_height = w_height
    super(x, y)
    select(1)
  end
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    return @w_width
  end
  def window_height
    return @w_height
  end
  #--------------------------------------------------------------------------
  # * Get Digit Count
  #--------------------------------------------------------------------------
  def col_max
    return 3
  end
  #--------------------------------------------------------------------------
  # * Create Command List
  #--------------------------------------------------------------------------
  def make_command_list
    add_command(Option::OK,         :ok)
    add_command(Option::Cancel, :cancel)
    add_command(Option::Reset,   :reset)
  end
end
#==============================================================================
# ** 重定义增加设置入口
#==============================================================================
class Scene_Title < Scene_Base
  alias org_create_win create_command_window
  def create_command_window
    org_create_win
    @command_window.set_handler(:setting, method(:command_setting))
  end
  def command_setting
    close_command_window
    SceneManager.call(Scene_Setting)
  end
end
class Window_TitleCommand < Window_Command
  def make_command_list
    add_command(Vocab::new_game, :new_game)
    add_command(Vocab::continue, :continue, continue_enabled)
    add_command(Option::Setting, :setting)
    add_command(Vocab::shutdown, :shutdown)
  end
end
class Scene_Menu < Scene_MenuBase
  alias org_create_win create_command_window
  def create_command_window
    org_create_win
    @command_window.set_handler(:setting, method(:command_setting))
  end
  def command_setting
    SceneManager.call(Scene_Setting)
  end
end
class Window_MenuCommand < Window_Command
  def make_command_list
    add_main_commands
    add_formation_command
    add_original_commands
    add_save_command
    add_setting
    add_game_end_command
  end
  def add_setting
    add_command(Option::Setting, :setting)
  end
end
#==============================================================================
# ** Game Setting
#------------------------------------------------------------------------------
#  重定义类
#==============================================================================
class RPG::BGM < RPG::AudioFile
  def play(pos = 0)
    if @name.empty?
      Audio.bgm_stop
      @@last = RPG::BGM.new
    else
      Audio.bgm_play('Audio/BGM/' + @name, @volume * $GS_Set["music"] / 10, @pitch, pos)
      @@last = self.clone
    end
  end
end

class RPG::BGS < RPG::AudioFile
  def play(pos = 0)
    if @name.empty?
      Audio.bgs_stop
      @@last = RPG::BGS.new
    else
      Audio.bgs_play('Audio/BGS/' + @name, @volume * $GS_Set["sound"] / 10, @pitch, pos)
      @@last = self.clone
    end
  end
end

class RPG::ME < RPG::AudioFile
  def play
    if @name.empty?
      Audio.me_stop
    else
      Audio.me_play('Audio/ME/' + @name, @volume * $GS_Set["sound"] / 10, @pitch)
    end
  end
end

class RPG::SE < RPG::AudioFile
  def play
    unless @name.empty?
      Audio.se_play('Audio/SE/' + @name, @volume * $GS_Set["sound"] / 10, @pitch)
    end
  end
end[/pre]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部