Project1

标题: 求个显示变量槽的脚本。 [打印本页]

作者: jxy    时间: 2014-9-21 20:39
标题: 求个显示变量槽的脚本。
如题。坛内搜索找不到,百度搜的连接挂了……
所以来求一个!
作者: 子弹君    时间: 2014-9-21 20:50
  1. #==============================================================================
  2. # ** 变量槽显示
  3. #  作者:影月千秋
  4. #  适用:VA
  5. #  要求:Smomo Core 1.1+
  6. #------------------------------------------------------------------------------
  7. # * 简介
  8. #   本脚本用以在菜单或地图界面显示一个值槽,它的进度由变量控制
  9. #------------------------------------------------------------------------------
  10. # * 使用方法
  11. #   插入到其他脚本以下,Main以上,按要求在下方设定即可
  12. #==============================================================================
  13. # * 更新
  14. #   V 1.4 2014.08.09 图标型显示不能显示半个图标的修正
  15. #   V 1.3 2014.05.10 支持图标型显示
  16. #   V 1.2 2014.05.01 劳动节 现在支持更丰富的显示效果了
  17. #   V 1.1 2014.02.08 功能微调
  18. #   V 1.0 2013.12.?? 新建
  19. #==============================================================================
  20. # * 声明
  21. #   本脚本来自"影月千秋", 使用/修改/转载请保留此信息
  22. #==============================================================================

  23. if $smomo.nil? || $smomo["Core"].nil? || $smomo["Core"] < 1.1
  24.   msgbox "请先安装Smomo脚本核心!"; %x!start http://tinyurl.com/l9kvg2p!
  25. elsif $smomo["MapVarBar"].nil?
  26. $smomo["MapVarBar"] = 1.3

  27. #==============================================================================
  28. # ** MapVarBar
  29. #------------------------------------------------------------------------------
  30. # 变量槽的设定区域
  31. #==============================================================================
  32. module Smomo::MapVarBar
  33.   
  34.   SWI = 0
  35.   # 游戏中决定是否在地图显示窗口的开关
  36.   # 开关打开时,才会显示 如果设为0 则一直显示

  37.   POS = 3
  38.   # 在地图中变量窗口显示的位置
  39.   #  0不使用 1左上 2左下 3右上 4右下
  40.   
  41.   KEY = :Y
  42.   # 玩家在地图界面显示/隐藏窗口的键,:Y一般为S键,不使用请设为0
  43.    
  44.   VAR = [
  45.   #============================================================================
  46.   # ** 填写格式
  47.   #----------------------------------------------------------------------------
  48.   # * 变量槽模式
  49.   #
  50.   # [当前进度变量, 最大值变量, 附加文本, 基础值, 初始最大值, 进度显示方式,
  51.   # 渐变色1, 渐变色2, 文本颜色, 进度颜色],
  52.   #
  53.   # 变量需要填写变量ID 附加文本形如 "击破数"
  54.   # 附加文本允许使用控制符 因此可以使用图标
  55.   # 基础值:计算比例时,先把当前值加上基础值再进行计算
  56.   # 初始最大值:因为游戏开始时变量为0 不能计算比例(除数不为零) 临时使用这个
  57.   #   作为最大值 当最大值变量不为0时 此值无意义
  58.   # 进度显示方式:有三种选项
  59.   #  '-'   不显示值 只显示附加文本
  60.   #  '/'   在附加文本后 以 69/731 的方式显示进度
  61.   #  '%'   在附加文本后 以 37.1% 的方式显示进度(精确到一位小数)
  62.   # 渐变色1 渐变色2 :描绘值槽使用的渐变颜色*
  63.   # 文本颜色 进度颜色:描绘附加文本和进度值使用的颜色*
  64.   #
  65.   # * 颜色请填写一个整数,参照事件【显示文章】中转义字符【\C[]】的参数
  66.   #
  67.   # 非必填项中 如果想只写后面不写前面,就用 nil 占位
  68.   #
  69.   # 前三项为必填项!
  70.   #----------------------------------------------------------------------------
  71.   # * 图标模式
  72.   #
  73.   # [当前进度变量, 附加文本, 基础值, 图标ID, 步长, 文本颜色],
  74.   #
  75.   # 图标ID可在数据库中查看 例: 3、28、31、67
  76.   # 步长: 一个图标所表示的进度量,即多少量绘制一整个图标
  77.   #  举例 用 爱心符号 表示当前生命(九号变量控制)步长为20
  78.   #  当 九号变量 在20-40之间 绘制一个爱心和一个不完整的爱心
  79.   #   在 40-60之间 绘制两个爱心和一个不完整的爱心
  80.   #    刚好60 绘制三个爱心
  81.   #     诸如此类
  82.   #
  83.   # 前五项为必填项!
  84.   #============================================================================
  85.   # ** 示例
  86.   # 将光标定位在下面的某一行 按Ctrl+D 再按Ctrl+Q 然后填写数据项 就可以直接生效了
  87. #~     [1, 2, "击破数", 0, 1000, '/', 16, 12, 4, 9],
  88. #~     [1, 2, "击破数"],
  89. #~     [1, 2, "击破数", nil, nil, '%'],
  90. #~     [1, 2, "击破数", 20, nil, '-', nil, nil, nil, 15],
  91. #~     [9, "生命", 0, 122, 20],
  92.   #============================================================================
  93.     [1, 2, "\\I[9]击破数"],
  94.     [3, 4, "完成度"],
  95.     [5, 6, "熟练等级"],
  96.     [7, 8, "远征", nil, nil, '%'],
  97.     [9, "生命", 0, 122, 20],
  98.   ] #<-|
  99.   
  100.   D_BA = 0    # 默认基础值
  101.   D_OM = 1000 # 默认初始最大值 不能为零
  102.   D_DM = '/'  # 默认进度显示方式
  103.   D_C1 = 16   # 默认渐变色1
  104.   D_C2 = 12   # 默认渐变色2
  105.   D_CT = 4    # 默认文本颜色
  106.   D_CR = 9    # 默认进度颜色
  107.   
  108.   T_TEXT  = "游戏进度"
  109.   # 在窗口最上方显示的文字 不希望显示的话使用 ""
  110.   T_COLOR = 2
  111.   # 如果显示 使用什么颜色
  112.   
  113.   BV = true
  114.   # 是否描绘窗口本身
  115.   
  116. #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+#
  117. #-------------                     --------------------------------------------#
  118.                "请勿跨过这块区域"
  119. #-------------                     --------------------------------------------#
  120. #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=#
  121.   ICONNUMBER = 0
  122.   VAR.each do |bar|
  123.     ICONNUMBER += 1 if bar[1].is_a?(String)
  124.     bar[3] ||= D_BA
  125.     bar[4] ||= D_OM
  126.     bar[5] ||= D_DM
  127.     bar[6] ||= D_C1
  128.     bar[7] ||= D_C2
  129.     bar[8] ||= D_CT
  130.     bar[9] ||= D_CR
  131.   end
  132. end

  133. #==============================================================================
  134. # ** Window_MapVarBar
  135. #==============================================================================
  136. class Window_MapVarBar < Window_Base
  137.   include Smomo::MapVarBar
  138.   #--------------------------------------------------------------------------
  139.   # * 初始化对象
  140.   #--------------------------------------------------------------------------
  141.   def initialize
  142.     fh = fitting_height (T_TEXT == "" ? 0 : 1) + VAR.size + ICONNUMBER
  143.     case POS
  144.     when 1
  145.       super(0, 20, 160, fh)
  146.     when 2
  147.       super(0, Graphics.height - fh, 160, fh)
  148.     when 3
  149.       super(Graphics.width - 160, 20, 160, fh)
  150.     when 4
  151.       super(Graphics.width - 160, Graphics.height - fh, 160, fh)
  152.     end
  153.     self.openness = 0
  154.     self.opacity = 0 unless BV
  155.     @showing = true
  156.     refresh
  157.   end
  158.   #--------------------------------------------------------------------------
  159.   # * 更新
  160.   #--------------------------------------------------------------------------
  161.   def update
  162.     super
  163.     if Smomo::MapVarBar::SWI == 0 || $game_switches[Smomo::MapVarBar::SWI]
  164.       @showing = !@showing if Input.trigger?(Smomo::MapVarBar::KEY)
  165.       if @showing
  166.         open if close?
  167.         refresh if $game_map.need_refresh
  168.       else
  169.         close if open?
  170.       end
  171.     else
  172.       close if open?
  173.     end
  174.   end
  175.   #--------------------------------------------------------------------------
  176.   # * 刷新
  177.   #--------------------------------------------------------------------------
  178.   def refresh
  179.     contents.clear
  180.     unless T_TEXT == ""
  181.       change_color text_color(T_COLOR)
  182.       draw_text(0, 0, contents.width, line_height, T_TEXT, 1)
  183.     end
  184.     VAR.each_with_index do |(a, b, c, d, e, f, g, h, i, j), id|
  185.       b.is_a?(String) ?
  186.       draw_with_icon(id, a, b, c, d, e, f) :
  187.       draw(id, g, h, i, j, c, *make_rate_n_text(f, a, b, d, e))
  188.     end
  189.   end
  190.   #--------------------------------------------------------------------------
  191.   # * 生成进度值
  192.   #--------------------------------------------------------------------------
  193.   def make_rate_n_text(display, current, max, base, origin_max)
  194.     c = $game_variables[current] + base
  195.     m = $game_variables[max] == 0 ? origin_max : $game_variables[max]
  196.     [rate = c.to_f / m.to_f,
  197.     case display
  198.     when '-'; ""
  199.     when '/'; "#{c}/#{m}"
  200.     when '%'; "#{(rate * 1000).round.to_f / 10.0}%"
  201.     end]
  202.   end
  203.   #--------------------------------------------------------------------------
  204.   # * 进度槽式描绘
  205.   #--------------------------------------------------------------------------
  206.   def draw(index, c1, c2, ct, cr, text, rate, atext)
  207.     pos = fitting_height(index - (T_TEXT == "" ? 1 : 0))
  208.     draw_gauge(0, pos, contents.width, rate, text_color(c1), text_color(c2))
  209.     draw_var_text(ct, pos, text, cr, atext)
  210.   end
  211.   #--------------------------------------------------------------------------
  212.   # * 图标式描绘
  213.   #--------------------------------------------------------------------------
  214.   def draw_with_icon(index, current, text, base, id, step, ct)
  215.     pos = fitting_height(index - (T_TEXT == "" ? 1 : 0))
  216.     ct = ct.is_a?(String) ? D_CT : ct
  217.     draw_var_text(ct, pos, text)
  218.     pos += line_height
  219.     (($game_variables[current] + base) / step).times do |i|
  220.       draw_icon(id, 24 * i, pos)
  221.     end
  222.     if ($game_variables[current] + base) % step != 0
  223.       x = ($game_variables[current] + base) / step
  224.       draw_icon(id, 24 * x, pos)
  225.       contents.clear_rect(24 * x + 12, pos, 12, 24)
  226.     end
  227.   end
  228.   #--------------------------------------------------------------------------
  229.   # * 通用描绘文字
  230.   #--------------------------------------------------------------------------
  231.   def draw_var_text(ct, pos, text, cr = nil, atext = nil)
  232.     make_font_smaller
  233.     change_color(text_color(ct))
  234.     text = convert_escape_characters(text)
  235.     oo = {:x => 0, :y => pos, :new_x => 0, :height => calc_line_height(text)}
  236.     process_character(text.slice!(0, 1), text, oo) until text.empty?
  237.     if cr
  238.       change_color(text_color(cr))
  239.       draw_text(0, pos, contents.width, line_height, atext, 2)
  240.     end
  241.     make_font_bigger
  242.   end
  243. end
  244. #==============================================================================
  245. # ** Scene_Map
  246. #==============================================================================
  247. class Scene_Map
  248.   _def_ :create_all_windows do |*args|
  249.     @mo_var_bar_window = Window_MapVarBar.new unless Smomo::MapVarBar::POS == 0
  250.   end
  251.   _def_ :call_menu, :b do |*args|
  252.     @mo_var_bar_window.close
  253.   end
  254. end

  255. else # unless $smomo["VarBar"]
  256.   msgbox "请不要重复加载此脚本 : )\n(变量槽显示 MapVarBar)"
  257. end # unless $smomo["VarBar"]

  258. #==============================================================================#
  259. #=====                        =================================================#
  260.            "脚 本 尾"
  261. #=====                        =================================================#
  262. #==============================================================================#
复制代码

作者: jxy    时间: 2014-9-21 22:10
请求结贴~解决了!




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1