Project1

标题: 一个脚本的问题 [打印本页]

作者: 灰太狼与喜羊羊    时间: 2014-2-5 20:52
标题: 一个脚本的问题

  1. class String  
  2.   alias old_plus +  
  3.   def +(other)  
  4.     self.old_plus(other.to_s)      
  5.   end   
  6. end


  7. module Cache
  8.   def self.menu(filename)
  9.     load_bitmap("Graphics/Menus/", filename)
  10.   end
  11. end

  12. class Window_Gold_new < Window_Base
  13.   #--------------------------------------------------------------------------
  14.   # * 物件初始化
  15.   #     x : 视窗X座标
  16.   #     y : 视窗Y座标
  17.   #--------------------------------------------------------------------------
  18.   def initialize(x, y)
  19.     super(x, y, 120, WLH + 32)
  20.     refresh
  21.   end
  22.   #--------------------------------------------------------------------------
  23.   # * 更新内容显示
  24.   #--------------------------------------------------------------------------
  25.   def refresh
  26.     self.contents.clear
  27.     self.opacity = 0
  28.     draw_currency_value($game_party.gold, 4, 0, 80)
  29.   end
  30. end

  31. class Window_Time < Window_Base
  32.   def initialize(x, y)
  33.     super(x, y, 200, WLH + 64)
  34.     self.opacity = 0
  35.     refresh
  36.   end
  37.   def refresh
  38.     self.contents.clear
  39.     self.contents.font.color = system_color
  40.     self.contents.draw_text(4, 0, 120, 32, "游戏时间")
  41.     @total_sec = Graphics.frame_count / Graphics.frame_rate
  42.     hour = @total_sec / 60 / 60
  43.     min = @total_sec / 60 % 60
  44.     sec = @total_sec % 60
  45.     text = sprintf("%02d:%02d:%02d", hour, min, sec)
  46.     self.contents.font.color = normal_color
  47.     self.contents.draw_text(16, 32, 120, 32, text, 2)
  48. end
  49.   def update
  50.     super
  51.     if Graphics.frame_count / Graphics.frame_rate != @total_sec
  52.       refresh
  53.     end
  54.   end
  55. end

  56. class Window_Command_new < Window_Selectable
  57.   #--------------------------------------------------------------------------
  58.   # * 宣告执行个体变数
  59.   #--------------------------------------------------------------------------
  60.   attr_reader   :commands                 # 命令
  61.   #--------------------------------------------------------------------------
  62.   # * 物件初始化
  63.   #     width      : 视窗宽度
  64.   #     commands   : 命令字串(阵列)
  65.   #     column_max : 纵栏数(如果大于等于2则横向分布命令条目)
  66.   #     row_max    : 总横行数(0:与命令条目数匹配)
  67.   #     spacing : 条目水准分布时的间距大小
  68.   #--------------------------------------------------------------------------
  69.   def initialize(width, commands, column_max = 6, row_max = 1, spacing = 12)
  70.     if row_max == 0
  71.       row_max = (commands.size + column_max - 1) / column_max
  72.     end
  73.     super(100, 0, width, row_max * WLH + 32, spacing)
  74.     @commands = commands
  75.     @item_max = commands.size
  76.     @column_max = column_max
  77.     refresh
  78.     self.index = 0
  79.   end
  80.   #--------------------------------------------------------------------------
  81.   # * 更新内容显示
  82.   #--------------------------------------------------------------------------
  83.   def refresh
  84.     self.contents.clear
  85.     for i in 0...@item_max
  86.       draw_item(i)
  87.     end
  88.   end
  89.   #--------------------------------------------------------------------------
  90.   # * 绘制条目
  91.   #     index   : 条目编号
  92.   #     enabled : 可用性标帜,如果为false则半透明化条目绘制。
  93.   #--------------------------------------------------------------------------
  94.   def draw_item(index, enabled = true)
  95.     rect = item_rect(index)
  96.     rect.x += 4
  97.     rect.width -= 8
  98.     self.contents.clear_rect(rect)
  99.     self.contents.font.color = normal_color
  100.     self.contents.font.color.alpha = enabled ? 255 : 128
  101.     self.contents.draw_text(rect, @commands[index])
  102.   end
  103. end


  104. class Scene_Menu < Scene_Base
  105.   def start
  106.     super
  107.     create_command_window
  108.     @gold_window = Window_Gold_new.new(424, 48)
  109.     @time_window = Window_Time.new(0,36)
  110.     @status_window = Window_MenuStatus.new(0, 140)
  111.     @menu_back = Plane.new   
  112.     @menu_back.bitmap = Cache.menu("Background")
  113.   end
  114.   
  115.   def pre_terminate
  116.     @status_window.close
  117.     @time_window.close
  118.     @gold_window.close
  119.     @command_window.close
  120.     begin
  121.     @status_window.update
  122.     @time_window.update
  123.     @gold_window.update
  124.     @command_window.update
  125.     @menu_back.ox += 1
  126.     Graphics.update
  127.     end until @status_window.openness == 0
  128.   end  
  129.   def terminate
  130.     @command_window.dispose
  131.     @gold_window.dispose
  132.     @menu_back.dispose
  133.     @status_window.dispose
  134.     @time_window.dispose
  135.   end
  136.   
  137.   def update
  138.     @menu_back.ox += 1
  139.     @command_window.update
  140.     @gold_window.update
  141.     @status_window.update
  142.     @time_window.update
  143.     if @command_window.active
  144.       update_command_selection
  145.     elsif @status_window.active
  146.       update_actor_selection
  147.     end
  148.   end
  149.   
  150.   #--------------------------------------------------------------------------
  151.   # * 创建命令视窗
  152.   #--------------------------------------------------------------------------
  153.   def create_command_window
  154.     s1 = Vocab::status
  155.     s2 = Vocab::skill
  156.     s3 = Vocab::item
  157.     s4 = Vocab::equip
  158.     s5 = Vocab::save
  159.     s6 = "系统"
  160.     @command_window = Window_Command_new.new(444, [s1, s2, s3, s4, s5, s6])#, s7
  161.     @command_window.index = @menu_index
  162.     if $game_party.members.size == 0          # 如果无人在队
  163.       @command_window.draw_item(0, false)     # 禁用[状态]
  164.       @command_window.draw_item(1, false)     # 禁用[技能]
  165.       @command_window.draw_item(2, false)     # 禁用[用品]
  166.       @command_window.draw_item(3, false)     # 禁用[整备]
  167.     end
  168.     if $game_system.save_disabled             # 如果禁止存档
  169.       @command_window.draw_item(4, false)     # 禁用[存档]
  170.     end
  171.     @command_window.opacity = 0
  172.   end
  173.   
  174.   #--------------------------------------------------------------------------
  175.   # * 更新指令选择输入资讯
  176.   #--------------------------------------------------------------------------
  177.   def update_command_selection
  178.     if Input.trigger?(Input::B)
  179.       Sound.play_cancel
  180.       $scene = Scene_Map.new
  181.     elsif Input.trigger?(Input::C)
  182.       if $game_party.members.size == 0 and @command_window.index < 4
  183.         Sound.play_buzzer
  184.         return
  185.       elsif $game_system.save_disabled and @command_window.index == 4
  186.         Sound.play_buzzer
  187.         return
  188.       end
  189.       Sound.play_decision
  190.       case @command_window.index
  191.       when 2      # 用品
  192.         $scene = Scene_Item.new
  193.       when 0,1,3  # 技能,整备,状态
  194.         start_actor_selection
  195.       when 4      # 存档
  196.         $scene = Scene_File.new(true, false, false)
  197.       when 5      # 结束游戏
  198.         $scene = Scene_End.new
  199.       end
  200.     end
  201.   end
  202.   #--------------------------------------------------------------------------
  203.   # * 开始接收主角选择指令输入资讯
  204.   #--------------------------------------------------------------------------
  205.   def start_actor_selection
  206.     @command_window.active = false
  207.     @status_window.active = true
  208.     if $game_party.last_actor_index < @status_window.item_max
  209.       @status_window.index = $game_party.last_actor_index
  210.     else
  211.       @status_window.index = 0
  212.     end
  213.   end
  214.   #--------------------------------------------------------------------------
  215.   # * 停止接收主角选择指令输入资讯
  216.   #--------------------------------------------------------------------------
  217.   def end_actor_selection
  218.     @command_window.active = true
  219.     @status_window.active = false
  220.     @status_window.index = -1
  221.   end
  222.   #--------------------------------------------------------------------------
  223.   # * 更新主角选择指令输入资讯
  224.   #--------------------------------------------------------------------------
  225.   def update_actor_selection
  226.     if Input.trigger?(Input::B)
  227.       Sound.play_cancel
  228.       end_actor_selection
  229.     elsif Input.trigger?(Input::C)
  230.       $game_party.last_actor_index = @status_window.index
  231.       Sound.play_decision
  232.       case @command_window.index
  233.       when 1  # 技能
  234.         $scene = Scene_Skill.new(@status_window.index)
  235.       when 3  # 整备
  236.         $scene = Scene_Equip.new(@status_window.index)
  237.       when 0  # 状态
  238.         $scene = Scene_Status.new(@status_window.index)
  239.       end
  240.     end
  241.   end
  242. end

  243. class Scene_Item < Scene_Base
  244.   #--------------------------------------------------------------------------
  245.   # * 返回之前的画面
  246.   #--------------------------------------------------------------------------
  247.   def return_scene
  248.     $scene = Scene_Menu.new(2)
  249.   end
  250. end

  251. class Scene_Equip < Scene_Base
  252.   #--------------------------------------------------------------------------
  253.   # * 返回之前的画面
  254.   #--------------------------------------------------------------------------
  255.   def return_scene
  256.     $scene = Scene_Menu.new(3)
  257.   end
  258. end

  259. class Scene_Status < Scene_Base
  260.   #--------------------------------------------------------------------------
  261.   # * 返回之前的画面
  262.   #--------------------------------------------------------------------------
  263.   def return_scene
  264.     $scene = Scene_Menu.new(0)
  265.   end
  266. end

  267. class Window_MenuStatus < Window_Selectable
  268.   #--------------------------------------------------------------------------
  269.   # * 物件初始化
  270.   #     x : 视窗X座标
  271.   #     y : 视窗Y座标
  272.   #--------------------------------------------------------------------------
  273.   def initialize(x, y)
  274.     super(x, y, 544,276)
  275.     refresh
  276.     self.active = false
  277.     self.index = -1
  278.     self.opacity = 0
  279.   end
  280.   #--------------------------------------------------------------------------
  281.   # * 更新内容显示
  282.   #--------------------------------------------------------------------------
  283.   def refresh
  284.     self.contents.clear
  285.     @item_max = $game_party.members.size
  286.     for actor in $game_party.members
  287.       if actor.index < 2
  288.         if actor.index % 2 == 0
  289.           actor_position_x = 0
  290.         else
  291.           actor_position_x = 250
  292.         end
  293.         actor_position_y = 0
  294.       else
  295.         if actor.index % 2 == 0
  296.           actor_position_x = 140
  297.         else
  298.           actor_position_x = 390
  299.         end
  300.         actor_position_y = 110
  301.       end
  302.       draw_halfbody(actor.face_name,actor.face_index,actor_position_x,actor_position_y)
  303.       if actor.index < 2
  304.         if actor.index % 2 == 0
  305.           actor_position_x = 0
  306.         else
  307.           actor_position_x = 250
  308.         end
  309.         actor_position_y = 0
  310.         x = 100 + actor_position_x
  311.         y = actor_position_y + 40 + WLH / 2
  312.       else
  313.         if actor.index % 2 == 0
  314.           actor_position_x = 0
  315.         else
  316.           actor_position_x = 250
  317.         end
  318.         actor_position_y = 100
  319.         x = 20 + actor_position_x
  320.         y = actor_position_y + 45 + WLH / 2
  321.       end
  322.       draw_actor_name(actor, x + 20, y - WLH + 5)
  323.       draw_actor_level(actor, x , y)
  324.       draw_actor_state(actor, x, y + WLH * 2)
  325.       draw_actor_hp(actor, x, y + WLH * 1)
  326.       draw_actor_mp(actor, x, y + WLH * 2)
  327.     end
  328.   end
  329.   
  330.   def draw_halfbody(half_name,half_index, x, y)
  331.       half_name = half_name + "_" + half_index
  332.       bitmap = Cache.load_bitmap("Graphics/Battlers/", half_name)
  333.       rect = Rect.new(0, 0, 0, 0)
  334.       rect.x = 0
  335.       rect.y = 0
  336.       rect.width = 128
  337.       rect.height = 135
  338.       self.contents.blt(x,y,bitmap,rect)
  339.       bitmap.dispose
  340.   end
  341.   
  342.   #--------------------------------------------------------------------------
  343.   # * 更新游标绘制
  344.   #--------------------------------------------------------------------------
  345.   def update_cursor
  346.     if [url=home.php?mod=space&uid=370741]@Index[/url] < 0               # 无光标
  347.       self.cursor_rect.empty
  348.     elsif @index < @item_max    # 正常状态
  349.       if @index < 2
  350.         if @index % 2 == 0
  351.           actor_position_x = 95
  352.         else
  353.           actor_position_x = 345
  354.         end
  355.         actor_position_y = 22+WLH/2
  356.         self.cursor_rect.set(actor_position_x-10, actor_position_y, 165, 96)
  357.       else
  358.         if @index % 2 == 0
  359.           actor_position_x = 22
  360.         else
  361.           actor_position_x = 272
  362.         end
  363.         actor_position_y = 128+WLH/2
  364.         self.cursor_rect.set(actor_position_x-10, actor_position_y, 165, 96)
  365.       end
  366.     elsif @index >= 100         # 使用者自身
  367.       self.cursor_rect.set(0, (@index - 100) * 96, contents.width, 96)
  368.     else                        # 全体队员
  369.       if @item_max < 3
  370.         contents_height = 140
  371.         if @item_max == 1
  372.           contents_width = 177
  373.         else
  374.           contents_width = contents.width
  375.         end
  376.         self.cursor_rect.set(0, 0, contents_width, contents_height )
  377.       else
  378.         contents_height = 244
  379.         self.cursor_rect.set(0, 0, contents.width, contents_height)
  380.       end
  381.     end
  382.   end
  383. end
复制代码

这个脚本用时一按F12就会错误,怎么修复
作者: 灰太狼与喜羊羊    时间: 2014-2-7 17:22
难道没有人知道吗?
作者: fux2    时间: 2014-2-7 19:15
灰太狼与喜羊羊 发表于 2014-2-7 17:22
难道没有人知道吗?

第三行的
  1. alias old_plus +
复制代码
改成
  1. alias old_plus + unless $@
复制代码
另外请不要连帖




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