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

Project1

 找回密码
 注册会员
搜索
查看: 938|回复: 3
打印 上一主题 下一主题

问一下 随时调用"是/否"脚本的用法

 关闭 [复制链接]

Lv1.梦旅人

梦石
0
星屑
198
在线时间
21 小时
注册时间
2008-7-4
帖子
69
跳转到指定楼层
1
发表于 2008-7-26 16:23:18 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
脚本内容如下

#================================================================
#   可以随时调用的 是/否 选择窗口      by 洛克人SZ
#   用法:                               v 1.3
#     if yes_no("提示信息")
#       选择 是 的情况下
#     else
#       选择 否 的情况下
#     end
#
#   也可以用在事件中的条件分歧里。
#================================================================


def yes_no(info = "请选择:")
  dummy_bitmap = Bitmap.new(608, 32)
  dummy_bitmap.font.size = 22
  strwidth = dummy_bitmap.text_size(info).width
  dummy_bitmap.dispose
  dummy_bitmap = nil
  strwidth = 88 if strwidth < 88
  strwidth = strwidth / 2 + strwidth + 32
  strwidth = 640 if strwidth > 640
  yes_no_window = Window_YesNoCommand.new(info, strwidth)
  yes_no_window.visible = true
  yes_no_window.active = true
  loop do
    Graphics.update
    Input.update
    yes_no_window.update
    if yes_no_window.active != true
      break
    end
  end
  fhxx = yes_no_window.fhxx
  yes_no_window.dispose
  yes_no_window = nil
  return fhxx
end


#==============================================================================
# ■ Window_HorizSelectable
#------------------------------------------------------------------------------
#  拥有光标的移动以及滚动功能的窗口类。 (水平命令窗口专用)
#==============================================================================

class Window_HorizSelectable < Window_Base
  #--------------------------------------------------------------------------
  # ● 定义实例变量
  #--------------------------------------------------------------------------
  attr_reader   :index                    # 光标位置
  attr_reader   :help_window              # 帮助窗口
  attr_reader   :help_windowa             # 帮助窗口a
  #--------------------------------------------------------------------------
  # ● 初始化对像
  #     x      : 窗口的 X 坐标
  #     y      : 窗口的 Y 坐标
  #     width  : 窗口的宽
  #     height : 窗口的高
  #--------------------------------------------------------------------------
  def initialize(x, y, width, height)
    super(x, y, width, height)
    @index = -1
  end
  #--------------------------------------------------------------------------
  # ● 设置光标的位置
  #     index : 新的光标位置
  #--------------------------------------------------------------------------
  def index=(index)
    @index = index
    # 刷新帮助文本 (update_help 定义了继承目标)
    if self.active and @help_window != nil
      update_help
    end
    if self.active and @help_windowa != nil
      update_helpa
    end
    # 刷新光标矩形
    update_cursor_rect
  end
  #--------------------------------------------------------------------------
  # ● 帮助窗口的设置
  #     help_window : 新的帮助窗口
  #--------------------------------------------------------------------------
  def help_window=(help_window)
    @help_window = help_window
    # 刷新帮助文本 (update_help 定义了继承目标)
    if self.active and @help_window != nil
      update_help
    end
  end

  def help_windowa=(help_windowa)
    @help_windowa = help_windowa
    # 刷新帮助文本 (update_help 定义了继承目标)
    if self.active and @help_windowa != nil
      update_helpa
    end
  end
  #--------------------------------------------------------------------------
  # ● 更新光标矩形
  #--------------------------------------------------------------------------
  def update_cursor_rect
    # 光标位置不满 0 的情况下
    if @index < 0
      self.cursor_rect.empty
      return
    end
    # 计算光标的宽度
    cursor_width = self.width / @item_max - 32
    # 计算光标坐标
    x = @index % @item_max * (cursor_width + 32)
    y = @index / @item_max * 32 - self.oy
    # 更新光标矩形
    self.cursor_rect.set(x, y, cursor_width, 32)
  end
  #--------------------------------------------------------------------------
  # ● 刷新画面
  #--------------------------------------------------------------------------
  def update
    super
    # 可以移动光标的情况下
    if self.active and @item_max > 0 and @index >= 0
      # 方向键右被按下的情况下
      if Input.repeat?(Input::RIGHT)
        # 列数为 2 以上并且、光标位置在最后一个项目上的情况下
        if @item_max >= 2 and @index == @item_max - 1 and
          Input.trigger?(Input::RIGHT)
          # 光标返回第一个项目
          $game_system.se_play($data_system.cursor_se)
          @index = 0
        # 列数为 2 以上并且、光标位置在(项目数 - 1)之前的情况下
        elsif @item_max >= 2 and @index < @item_max - 1
          # 光标向右移动
          $game_system.se_play($data_system.cursor_se)
          @index += 1
        end
      end
      # 方向键左被按下的情况下
      if Input.repeat?(Input::LEFT)
        # 列数为 2 以上并且、光标位置在 0 的情况下
        if @item_max >= 2 and @index == 0 and
          Input.trigger?(Input::LEFT)
          # 光标移动到最后一个项目
          $game_system.se_play($data_system.cursor_se)
          @index = @item_max - 1
        # 列数为 2 以上并且、光标位置在 0 之后的情况下
        elsif @item_max >= 2 and @index > 0
          # 光标向左移动
          $game_system.se_play($data_system.cursor_se)
          @index -= 1
        end
      end
    end
    # 刷新帮助文本 (update_help 定义了继承目标)
    if self.active and @help_window != nil
      update_help
    end
    # 刷新帮助文本 (update_help 定义了继承目标)
    if self.active and @help_windowa != nil
      update_helpa
    end
    # 刷新光标矩形
    update_cursor_rect
  end
end



#==============================================================================
# ■ Window_YesNoCommand
#------------------------------------------------------------------------------
#  选择是或否的命令选择行窗口。
#==============================================================================

class Window_YesNoCommand < Window_HorizSelectable
  #--------------------------------------------------------------------------
  # ● 定义实例变量
  #--------------------------------------------------------------------------
  attr_reader   :fhxx
  #--------------------------------------------------------------------------
  # ● 初始化对像
  #     info     : 窗口的提示信息
  #     width    : 窗口的宽度
  #     height   : 窗口的高度
  #--------------------------------------------------------------------------
  def initialize(info = "欢迎", width = 480, height = 96)
    x = 320 - width / 2
    y = 240 - height / 2
    super(x, y, width, height)
    self.visible = false
    self.active = false
    self.opacity = 200
    self.contents = Bitmap.new(width - 32, height - 32)
    @commands = ["是", "否"]
    @item_max = @commands.size
    @woff = (self.width - 32) / 4 - 19
    @fhxx = false
    refresh(info)
    self.index = 0
    self.z = 10000
  end
  #--------------------------------------------------------------------------
  # ● 刷新
  #--------------------------------------------------------------------------
  def refresh(info)
    self.contents.clear
    self.contents.font.size = 22
    self.contents.font.color = system_color
    self.contents.draw_text(0, 0, self.width - 32, 32, info, 1)
    for i in 0...@item_max
      draw_item(i, normal_color)
    end
  end
  #--------------------------------------------------------------------------
  # ● 描绘项目
  #     index : 项目编号
  #--------------------------------------------------------------------------
  def draw_item(index, color)
    self.contents.font.color = color
    x = self.width / @item_max * index + @woff
    off = self.width / @item_max - 32
    self.contents.draw_text(x, 32, 32, 32, @commands[index])
  end
  #--------------------------------------------------------------------------
  # ● 项目无效化
  #     index : 项目编号
  #--------------------------------------------------------------------------
  def disable_item(index)
    draw_item(index, disabled_color)
  end
  #--------------------------------------------------------------------------
  # ● 更新光标矩形
  #--------------------------------------------------------------------------
  def update_cursor_rect
    # 光标位置不满 0 的情况下
    if @index < 0
      self.cursor_rect.empty
      return
    end
    # 计算光标的宽度
    cursor_width = self.width / @item_max - 32
    # 计算光标坐标
    x = @index % @item_max * (cursor_width + 32)
    y = 32
    # 更新光标矩形
    self.cursor_rect.set(x, y, cursor_width, 32)
  end
  #--------------------------------------------------------------------------
  # ● 刷新画面
  #--------------------------------------------------------------------------
  def update
    super
    # 按下取消键的情况下
    if Input.trigger?(Input::B)
      # 演奏确定 SE
      $game_system.se_play($data_system.decision_se)
      @fhxx = false
      self.visible = false
      self.active = false
      return
    end
    # 按下确定键的情况下
    if Input.trigger?(Input::C)
      # 演奏确定 SE
      $game_system.se_play($data_system.decision_se)
      # 命令窗口的光标位置分支
      case self.index
      when 0  # 是
        @fhxx = true
        self.visible = false
        self.active = false
      when 1  # 否
        @fhxx = false
        self.visible = false
        self.active = false
      end
      return
    end
  end
end


=======================================
请问这个脚本怎么使用?
在游戏中怎么调出来 "是/否"
此贴于 2008-7-29 7:29:05 被版主darkten提醒,请楼主看到后对本贴做出回应。
版务信息:本贴由楼主自主结贴~
很好很好很好~~

Lv1.梦旅人

邪恶小龙包

梦石
0
星屑
55
在线时间
17 小时
注册时间
2006-5-22
帖子
7006

第2届短篇游戏比赛冠军第3届短篇游戏大赛小游戏及其他组冠军RMVX自由创作大赛冠军

2
发表于 2008-7-26 16:27:36 | 只看该作者
#================================================================
#   可以随时调用的 是/否 选择窗口      by 洛克人SZ
#   用法:                               v 1.3
#     if yes_no("提示信息")
#       选择 是 的情况下
#     else
#       选择 否 的情况下
#     end
#
#   也可以用在事件中的条件分歧里。

用法不就有写了吗……
虚无  堕落
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
198
在线时间
21 小时
注册时间
2008-7-4
帖子
69
3
 楼主| 发表于 2008-7-27 16:53:01 | 只看该作者
我没看懂,我看懂就不来问了 = =!
难道是事件--条件分歧--脚本?
还是????
以下引用暴风の龙于2008-7-26 8:27:36的发言:


#================================================================
#   可以随时调用的 是/否 选择窗口      by 洛克人SZ
#   用法:                               v 1.3
#     if yes_no("提示信息")
#       选择 是 的情况下
#     else
#       选择 否 的情况下
#     end
#
#   也可以用在事件中的条件分歧里。

用法不就有写了吗……

很好很好很好~~
回复 支持 反对

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
39988
在线时间
5813 小时
注册时间
2006-11-10
帖子
6684
4
发表于 2008-7-28 00:49:32 | 只看该作者
在事件第三页的脚本里输入上面那段就行了

比如 if yes_no("你想死一次吗?")
       $scene = Scene_Gameover.new
      else
       $scene = Scene_Map.new
      end

条件分歧就用分歧脚本:yes_no("你想死一次吗?") 这样就行了。
系统信息:本贴由楼主认可为正确答案,66RPG感谢您的热情解答~
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

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

GMT+8, 2025-8-9 15:09

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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