查看: 3039|回复: 1

[已经解决] 求教,Theo的地图显示变量脚本怎么变成横向?(已解决)

[复制链接]
梦石
20
星屑
13965
在线时间
1744 小时
注册时间
2017-1-12
回帖
1667

MZ评测员开拓者

发表于 2019-6-3 12:33:24 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 火锅深处 于 2019-6-4 11:07 编辑

现有脚本的三种模式是左上、右上、右下。变量是纵向排列。
我想变成在左上角距离顶边100像素左右,变量横向一字排开,具体应该改哪部分呢?
  1. # =============================================================================
  2. # TheoAllen - 简单变量HUD
  3. # Version : 1.2b
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (This script documentation is written in informal indonesian language)
  6. # =============================================================================
  7. ($imported ||= {})[:Theo_VariableHUD] = true
  8. # =============================================================================
  9. # CHANGE LOGS:
  10. # -----------------------------------------------------------------------------
  11. # 2014.03.13 - Fixed hidden glitch when access menu then back to map
  12. # 2014.02.07 - Make sure that variable HUD is always visible
  13. # 2013.08.09 - Add mutiple variable HUD support
  14. # 2013.07.23 - Finished script
  15. # =============================================================================
  16. =begin

  17.   介绍 :
  18.   本脚本可以简单地在地图上显示变量的数值。
  19.   
  20.   使用方法 :
  21.   将本脚本放在插件脚本之下,Main之上
  22.   
  23.   使用脚本:
  24.   show_variable(变量id) >> 显示变量数值
  25.   show_variable(变量id,图标索引) >> 显示变量数值+一个图标
  26.   show_variable(变量id,图标索引,位置) >> 显示变量数值+一个图标+设定显示位置
  27.   
  28.   多重 HUD 的脚本:
  29.   show_variable([变量id,变量id,变量id],[图标索引,图标索引,图标索引],位置)
  30.   
  31.   hide_variable >> 隐藏所有 HUD
  32.   
  33.     使用条款 :
  34.   署名脚本作者, TheoAllen. 你可以自由编辑此脚本,只要你不声明你是脚本的原作者
  35.   如果你想用此脚本于商业游戏,请和我共享收益.别忘了给我一份免费的游戏拷贝.  
  36.   
  37.   Note :
  38.   Karena ini simple, jadi jangan harap ada banyak kustomisasi bebas

  39. =end
  40. # =============================================================================
  41. # 设定
  42. # =============================================================================
  43.   VarHUD_DefaultPos = 1 # Posisi default HUD
  44. # -----------------------------------------------------------------------------
  45. # 1 >> Kiri Atas
  46. # 2 >> Kanan Atas
  47. # 3 >> Kiri Bawah
  48. # 4 >> Kanan Bawah
  49. # -----------------------------------------------------------------------------
  50.   VarHUD_FontSize = 24 # Ukuran Font
  51. # -----------------------------------------------------------------------------
  52.   VarHUD_MaxVar = 4 # Maksimal variable yg dapat ditampilin
  53. # =============================================================================
  54. # 设定结束
  55. # =============================================================================
  56. class Game_Temp
  57.   attr_accessor :refresh_hud
  58.   
  59.   alias theo_varhud_init initialize
  60.   def initialize
  61.     theo_varhud_init
  62.     @refresh_hud = false
  63.   end
  64.   
  65. end

  66. class Game_Variables
  67.   alias theo_varhud_on_change on_change
  68.   def on_change
  69.     theo_varhud_on_change
  70.     $game_temp.refresh_hud = true
  71.   end
  72. end

  73. class Game_System
  74.   class VarHUD
  75.     attr_accessor :position
  76.     attr_accessor :icon
  77.     attr_accessor :id
  78.    
  79.     def initialize
  80.       @position = 0
  81.       @icon = 0
  82.       @id = 0
  83.     end
  84.   end
  85.   attr_accessor :varhud_visible
  86.   attr_accessor :varhud_position
  87.   attr_reader :varhud
  88.   
  89.   alias theo_varhud_init initialize
  90.   def initialize
  91.     theo_varhud_init
  92.     @varhud = Array.new(VarHUD_MaxVar) { VarHUD.new }
  93.   end
  94.   
  95.   def clear_varhud
  96.     @varhud.each do |hud|
  97.       hud.id = 0
  98.     end
  99.   end
  100.   
  101. end

  102. class Game_Interpreter
  103.   
  104.   def show_variable(id = nil,icon = 0,position = VarHUD_DefaultPos)
  105.     $game_system.clear_varhud
  106.     if id.is_a?(Array)
  107.       icon = [icon] unless icon.is_a?(Array)
  108.       id.each_with_index do |i,index|
  109.         return if index-1 > VarHUD_MaxVar
  110.         hud = $game_system.varhud[index]
  111.         hud.id = i
  112.         hud.icon = icon[index]
  113.       end
  114.     elsif id.is_a?(Numeric)
  115.       hud = $game_system.varhud[0]
  116.       hud.icon = icon
  117.       hud.id = id
  118.     end
  119.     $game_system.varhud_position = position
  120.     $game_system.varhud_visible = true
  121.     $game_temp.refresh_hud = true
  122.   end
  123.   
  124.   def hide_variable
  125.     $game_system.varhud_visible = false
  126.   end
  127.   
  128. end

  129. class Window_VarHUD < Window_Base
  130.   
  131.   def initialize
  132.     super(0,0,window_width,window_height)
  133.     contents.font.size = VarHUD_FontSize
  134.     update_hud_position
  135.     update_visibility
  136.     self.opacity = 0
  137.     refresh
  138.   end
  139.   
  140.   def window_width;Graphics.width;end;
  141.   def window_height;fitting_height(VarHUD_MaxVar);end;
  142.   def line_height;VarHUD_FontSize;end;
  143.    
  144.   def update
  145.     super
  146.     update_visibility
  147.     refresh if $game_temp.refresh_hud
  148.   end
  149.   
  150.   def update_visibility
  151.     self.visible = $game_system.varhud_visible
  152.   end
  153.   
  154.   def refresh
  155.     contents.clear
  156.     active_hud.each_with_index do |hud,i|
  157.       update_hud_contents(hud,i)
  158.     end
  159.     update_hud_position
  160.     $game_temp.refresh_hud = false
  161.   end
  162.   
  163.   def update_hud_position
  164.     pos = $game_system.varhud_position
  165.     if pos == 1 || pos == 2
  166.       self.y = 0
  167.     elsif
  168.       self.y = Graphics.height - self.height
  169.       size = active_hud.size - 1
  170.       return if size < 0
  171.       self.y += size * line_height
  172.     end
  173.   end
  174.   
  175.   def update_hud_contents(hud,i)
  176.     var_id = hud.id
  177.     icon = hud.icon.nil? ? 0 : hud.icon
  178.     return if var_id == 0
  179.     rect = Rect.new(0,0,contents.width,line_height)
  180.     rect.y = i * line_height
  181.     case $game_system.varhud_position
  182.     when 1,3
  183.       if icon != 0
  184.         rect.x += 27
  185.         draw_icon(icon,0,icon_y_pos + (i * line_height))
  186.       end
  187.       draw_text(rect,$game_variables[var_id])
  188.     else
  189.       if icon != 0
  190.         rect.x -= 27
  191.         draw_icon(icon,contents.width-24,icon_y_pos + (i * line_height))
  192.       end
  193.       draw_text(rect,$game_variables[var_id],2)
  194.     end
  195.   end
  196.   
  197.   def icon_y_pos
  198.     return 0 if line_height <= 24
  199.     return line_height/2 - 12
  200.   end
  201.   
  202.   def active_hud
  203.     $game_system.varhud.select {|hud| hud.id > 0}
  204.   end
  205.   
  206. end

  207. class Scene_Map < Scene_Base
  208.   
  209.   alias theo_varhud_start start
  210.   def start
  211.     theo_varhud_start
  212.     create_var_hud
  213.   end
  214.   
  215.   def create_var_hud
  216.     @varhud_viewport = Viewport.new
  217.     @varhud_viewport.z = 9999
  218.     @var_hud = Window_VarHUD.new
  219. #~     @var_hud.z -= 100
  220.     @var_hud.viewport = @vahud_viewport
  221.   end
  222.   
  223.   alias theo_varhud_terminate terminate
  224.   def terminate
  225.     theo_varhud_terminate
  226.     @varhud_viewport.dispose
  227.   end
  228.   
  229. end
复制代码
梦石
0
星屑
34459
在线时间
5096 小时
注册时间
2012-11-19
回帖
4715

开拓者

发表于 2019-6-4 10:08:20 | 显示全部楼层
呃~, 以前有一个 地图显示变量 的存货,可能比较适合LZ的要求。

[pre lang="ruby"]#==============================================================================
# 〓 地图显示变量 〓                              Author:芯☆淡茹水
#==============================================================================
=begin
#==============================================================================
  ◆ 说明 ◆
#==============================================================================
#------------------------------------------------------------------------------
1,变量的命名
   变量命名格式为 => 变量名^图标序号
   未写 图标序号 的变量,不会显示图标。
#------------------------------------------------------------------------------
2,游戏中添加变量显示 => 事件-脚本:show_map_val(id, x, y, w, s, c1, c2)
   id :变量ID
   x  :变量窗口显示的X坐标
   y  :变量窗口显示的Y坐标
   w  :变量窗口宽(可省略,省略后为设置的默认值)
   s  :字体大小(可省略,省略后为设置的默认值)
   c1 :变量名文字色号(可省略,省略后为设置的默认值)
   c2 :变量值文字色号(可省略,省略后为设置的默认值)
   
   ※ 如果对应的变量已经在显示中,此条命令无效 ※
   ※ 地图上显示的变量个数无限制,理论上可显示无数个变量 ※
#------------------------------------------------------------------------------
3,游戏中删除变量显示 => 事件-脚本:delete_map_val(id)
   id :变量ID
   
   ※ 如果对应的变量未在显示中,此条命令无效 ※
#------------------------------------------------------------------------------
4,移动变量窗口 => 事件-脚本:move_val_window(id, direction, duration, speed)
   id        :变量ID
   direction :移动的方向(2:下;4:左;6:右;8:上)
   duration  :移动时持续的帧数
   speed     :移动时每一帧移动的像素值
   
   ※ 如果对应的变量未在显示中或变量窗口正在移动中,此条命令无效 ※
#------------------------------------------------------------------------------
=end
#==============================================================================
module XdRs_Show_Val_Set
#==============================================================================
# ◆ 设置 ◆
#==============================================================================
  #--------------------------------------------------------------------------
  # 窗口边宽
  Standard_padding = 8
  
  #--------------------------------------------------------------------------
  # 窗口不透明度
  Opacity = 255
  
  #--------------------------------------------------------------------------
  # 默认窗口宽度
  Default_window_width = 180
  
  #--------------------------------------------------------------------------
  # 默认窗口字体大小
  Default_font_size = 20
  
  #--------------------------------------------------------------------------
  # 默认变量名字体颜色号
  Default_val_name_color = 0
  
  #--------------------------------------------------------------------------
  # 默认变量值字体颜色号
  Default_val_num_color = 0
  
  #--------------------------------------------------------------------------
  # 初始显示的变量。
  # 格式:变量ID => [X坐标, Y坐标, 窗口宽, 字体大小, 变量名色号, 变量值色号]
  # 其中 窗口宽, 字体大小, 变量名色号, 变量值色号 可省略, 省略后为默认值。
  Initial_vals = {
    11 => [0, 0],
    12 => [10, 40],
    13 => [20, 80, 240, 18, 3, 2]
  }
end
#==============================================================================
class XdRs_Val_Data
  #--------------------------------------------------------------------------
  attr_reader :id, :x, :y
  attr_reader :font_size
  attr_reader :window_width
  attr_reader :window_height
  attr_reader :name_color
  attr_reader :num_color
  #--------------------------------------------------------------------------
  def initialize(id, x, y, w=nil, s=nil, c1=nil, c2=nil)
    @id = id
    @x = x || 0
    @y = y || 0
    @font_size = s || XdRs_Show_Val_Set::Default_font_size
    @window_width =  w || XdRs_Show_Val_Set::Default_window_width
    @window_height = XdRs_Show_Val_Set::Standard_padding * 2 + [@font_size, 24].max
    @name_color = c1 || XdRs_Show_Val_Set::Default_val_name_color
    @num_color  = c2 || XdRs_Show_Val_Set::Default_val_num_color
    clear_move_data
  end
  #--------------------------------------------------------------------------
  def clear_move_data
    @speed = 0
    @move_direction = 0
    @move_duration = 0
  end
  #--------------------------------------------------------------------------
  def name
    text = $data_system.variables[@id]
    return text.split(/\^/)[0] || ""
  end
  #--------------------------------------------------------------------------
  def icon_index
    text = $data_system.variables[@id]
    return (text.split(/\^/)[1] || "0").to_i
  end
  #--------------------------------------------------------------------------
  def start_move(direction, duration, speed)
    return if is_moving?
    @move_direction = direction
    @move_duration = duration
    @speed = speed
  end
  #--------------------------------------------------------------------------
  def is_moving?
    return false if ![2,4,6,8].include?(@move_direction)
    return @speed > 0 && @move_duration > 0
  end
  #--------------------------------------------------------------------------
  def update_move
    return if @move_duration == 0
    @move_duration -= 1
    is_moving? && apply_move
    @move_duration == 0 && clear_move_data
  end
  #--------------------------------------------------------------------------
  def apply_move
    @x += @move_direction == 6 ? @speed : (@move_direction == 4 ? -@speed : 0)
    @y += @move_direction == 2 ? @speed : (@move_direction == 8 ? -@speed : 0)
  end
end
#==============================================================================
class Game_System
  #--------------------------------------------------------------------------
  attr_accessor :additive_val, :deleted_val
  #--------------------------------------------------------------------------
  alias xr_show_val_initialize initialize
  def initialize
    xr_show_val_initialize
    setup_initial_vals
  end
  #--------------------------------------------------------------------------
  def setup_initial_vals
    @xr_map_vals = []
    vals = XdRs_Show_Val_Set::Initial_vals
    vals.keys.each do |id|
      data = vals[id]
      show_map_val(id,data[0],data[1],data[2],data[3],data[4],data[5])
    end
    @additive_val = nil
  end
  #--------------------------------------------------------------------------
  def map_vals
    return @xr_map_vals.map{|d| d.id }
  end
  #--------------------------------------------------------------------------
  def get_map_val_data(id)
    return @xr_map_vals.find{|d| d.id == id }
  end
  #--------------------------------------------------------------------------
  def has_map_val(id)
    return @xr_map_vals.any?{|d| d.id == id}
  end
  #--------------------------------------------------------------------------
  def show_map_val(id, x, y, w=nil, s=nil, c1=nil, c2=nil)
    return if has_map_val(id) || id == 0
    @xr_map_vals.push(XdRs_Val_Data.new(id,x,y,w,s,c1,c2))
    @additive_val = id
  end
  #--------------------------------------------------------------------------
  def delete_map_val(id)
    return if !has_map_val(id)
    @xr_map_vals.delete(get_map_val_data(id))
    @deleted_val = id
  end
  #--------------------------------------------------------------------------
  def move_map_val_window(id, drc, drt, speed)
    has_map_val(id) && get_map_val_data(id).start_move(drc, drt, speed)
  end
end
#==============================================================================
class Game_Interpreter
  #--------------------------------------------------------------------------
  def show_map_val(id, x, y, w=nil, s=nil, c1=nil, c2=nil)
    $game_system.show_map_val(id, x, y, w, s, c1, c2)
  end
  #--------------------------------------------------------------------------
  def delete_map_val(id)
    $game_system.delete_map_val(id)
  end
  #--------------------------------------------------------------------------
  def move_val_window(id, direction, duration, speed)
    $game_system.move_map_val_window(id, direction, duration, speed)
  end
end
#==============================================================================
class Window_Map_Val < Window_Base
  #--------------------------------------------------------------------------
  def initialize(data)
    @data = data
    super(@data.x, @data.y, @data.window_width, @data.window_height)
    self.opacity = XdRs_Show_Val_Set::Opacity
    self.z = 9999
    refresh
  end
  #--------------------------------------------------------------------------
  def line_height
    return [@data.font_size, 24].max
  end
  #--------------------------------------------------------------------------
  def standard_padding
    return XdRs_Show_Val_Set::Standard_padding
  end
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    contents.font.size = @data.font_size
    @last_num = $game_variables[@data.id]
    draw_val_name(draw_val_icon(0))
    draw_val_num
  end
  #--------------------------------------------------------------------------
  def draw_val_icon(x)
    return x if @data.icon_index == 0
    y = (line_height - 24) / 2
    draw_icon(@data.icon_index, x, y)
    return x + 28
  end
  #--------------------------------------------------------------------------
  def draw_val_name(x)
    change_color(text_color(@data.name_color))
    tw = text_size(@data.name).width + 4
    y = (line_height - @data.font_size) / 2
    draw_text(x, y, tw, @data.font_size, @data.name)
  end
  #--------------------------------------------------------------------------
  def draw_val_num
    change_color(text_color(@data.num_color))
    y = (line_height - @data.font_size) / 2
    draw_text(0, y, contents_width, @data.font_size, @last_num.to_s, 2)
  end
  #--------------------------------------------------------------------------
  def is_val_changed?
    return @last_num != $game_variables[@data.id]
  end
  #--------------------------------------------------------------------------
  def update
    super
    @data.update_move
    update_state
    update_location
  end
  #--------------------------------------------------------------------------
  def update_state
    is_val_changed? && refresh
  end
  #--------------------------------------------------------------------------
  def update_location
    self.x = @data.x
    self.y = @data.y
  end
end
#==============================================================================
class Scene_Map
  #--------------------------------------------------------------------------
  def create_xr_val_window(id)
    $game_system.additive_val = nil
    window_name = "@xr_val_window#{id}"
    data = $game_system.get_map_val_data(id)
    window = instance_variable_get(window_name)
    return if !!window && !window.disposed? || !data
    instance_variable_set(window_name, Window_Map_Val.new(data))
  end
  #--------------------------------------------------------------------------
  def dispose_xr_val_window(id)
    $game_system.deleted_val = nil
    window_name = "@xr_val_window#{id}"
    return if !instance_variable_get(window_name)
    instance_variable_get(window_name).dispose
    instance_variable_set(window_name, nil)
  end
  #--------------------------------------------------------------------------
  alias xr_map_val_create_all_windows create_all_windows
  def create_all_windows  
    xr_map_val_create_all_windows
    $game_system.map_vals.each{|id| create_xr_val_window(id) }
  end
  #--------------------------------------------------------------------------
  alias xr_map_val_update update
  def update
    xr_map_val_update
    update_xr_map_val
  end
  #--------------------------------------------------------------------------
  def update_xr_map_val
    $game_system.additive_val && create_xr_val_window($game_system.additive_val)
    $game_system.deleted_val  && dispose_xr_val_window($game_system.deleted_val)
  end
end
#==============================================================================[/pre]

这儿也有个示范用法的范例工程

地图显示变量.rar (1.42 MB, 下载次数: 102)

评分

参与人数 2星屑 +30 赞 +1 收起 理由
VIPArcher + 30 认可答案
火锅深处 + 1 感谢大佬

查看全部评分

xp vx va mv  va mz 各类型脚本/插件定制
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部