Project1

标题: 战斗中物品框出现问题了!!! [打印本页]

作者: 倚天    时间: 2009-1-21 23:42
提示: 作者被禁止或删除 内容自动屏蔽
作者: ONEWateR    时间: 2009-1-21 23:49
已修改

  1. #==============================================================================
  2. # ■ Window_Item
  3. #------------------------------------------------------------------------------
  4. #  物品画面、战斗画面、显示浏览物品的窗口。
  5. #==============================================================================

  6. class Window_Item < Window_Selectable
  7.   #--------------------------------------------------------------------------
  8.   # ● 初始化对像
  9.   #--------------------------------------------------------------------------
  10.   def initialize
  11.     super(0, 480-(5*51+32), 338, 5*51+32)
  12.    
  13.     @column_max = 6
  14.     refresh
  15.     self.index = 0
  16.     # 战斗中的情况下将窗口移至中央并将其半透明化
  17.     if $game_temp.in_battle
  18.       self.y = 480-(5*51+32)
  19. #      self.x = -10
  20.       self.height = 5*51+32
  21.       self.opacity = 255
  22. #      self.back_opacity = 0
  23.     end
  24.   end
  25.   #--------------------------------------------------------------------------
  26.   # ● 获取物品
  27.   #--------------------------------------------------------------------------
  28.   def item
  29.     return @data[self.index]
  30.   end
  31.   #--------------------------------------------------------------------------
  32.   # ● 刷新
  33.   #--------------------------------------------------------------------------
  34.   def refresh
  35.     if self.contents != nil
  36.       self.contents.dispose
  37.       self.contents = nil
  38.     end
  39.     @data = []
  40.     # 添加报务
  41.     for i in 1...$data_items.size
  42.       if $game_party.item_number(i) > 0
  43.         @data.push($data_items[i])
  44.       end
  45.     end
  46.     # 在战斗中以外添加武器、防具
  47.     unless $game_temp.in_battle
  48.       for i in 1...$data_weapons.size
  49.         if $game_party.weapon_number(i) > 0
  50.           @data.push($data_weapons[i])
  51.         end
  52.       end
  53.       for i in 1...$data_armors.size
  54.         if $game_party.armor_number(i) > 0
  55.           @data.push($data_armors[i])
  56.         end
  57.       end
  58.     end
  59.     # 如果项目数不是 0 就生成位图、重新描绘全部项目
  60.     @item_max = @data.size
  61.     if @item_max > 0
  62.       self.contents = Bitmap.new(width - 51, row_max * 51)
  63.       self.contents.font.size = 17
  64.       for i in 0...@item_max
  65.         draw_item(i)
  66.       end
  67.     end
  68.   end
  69.   #--------------------------------------------------------------------------
  70.   # ● 描绘项目
  71.   #     index : 项目编号
  72.   #--------------------------------------------------------------------------
  73.   def draw_item(index)
  74.     item = @data[index]
  75.     case item
  76.     when RPG::Item
  77.       number = $game_party.item_number(item.id)
  78.     when RPG::Weapon
  79.       number = $game_party.weapon_number(item.id)
  80.     when RPG::Armor
  81.       number = $game_party.armor_number(item.id)
  82.     end
  83.     if item.is_a?(RPG::Item) and
  84.        $game_party.item_can_use?(item.id)
  85.       self.contents.font.color = normal_color
  86.     else
  87.       self.contents.font.color = disabled_color
  88.     end
  89.     x = index % 6 * 51
  90.     y = index / 6 * 51
  91.     rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  92.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  93.     bitmap = RPG::Cache.icon(item.icon_name)
  94.     self.contents.font.size = 15
  95.     opacity = self.contents.font.color == normal_color ? 255 : 128
  96.     self.contents.blt(x, y , bitmap, Rect.new(0, 0, 51, 51), opacity)
  97. #    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  98. #    self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
  99.     self.contents.font.color = Color.new(255, 255, 255, 255)
  100.     self.contents.draw_text(x -7, y - 7, 24, 32, number.to_s, 2)
  101.   end
  102.   #--------------------------------------------------------------------------
  103.   # ● 刷新帮助文本
  104.   #--------------------------------------------------------------------------
  105.   def update_help
  106.     @help_window.set_text(self.item == nil ? "" : self.item.description)
  107.   end
  108.   #--------------------------------------------------------------------------
  109.   # ● 获取 1 页可以显示的行数
  110.   #--------------------------------------------------------------------------
  111.   def page_row_max
  112.     return (self.height - 32) / 51
  113.   end
  114.   #--------------------------------------------------------------------------
  115.   # ● 更新光标举行
  116.   #--------------------------------------------------------------------------
  117.   def update_cursor_rect
  118.     if @index < 0
  119.       self.cursor_rect.empty
  120.       return
  121.     end
  122.     row = @index / @column_max
  123.     if row < self.top_row
  124.       self.top_row = row
  125.     end
  126.     if row > self.top_row + (self.page_row_max - 1)
  127.       self.top_row = row - (self.page_row_max - 1)
  128.     end
  129.     x = @index % @column_max * 51
  130.     y = @index / @column_max * 51 - self.oy# + 2
  131.     self.cursor_rect.set(x, y, 51, 51)
  132.   end
  133.   #--------------------------------------------------------------------------
  134.   # ● 设置开头行
  135.   #     row : 显示开头的行
  136.   #--------------------------------------------------------------------------
  137.   def top_row=(row)
  138.     if row < 0
  139.       row = 0
  140.     end
  141.     if row > row_max - 1
  142.       row = row_max - 1
  143.     end
  144.     self.oy = row * 51
  145.   end
  146.   #--------------------------------------------------------------------------
  147.   # ● 刷新帮助文本
  148.   #--------------------------------------------------------------------------
  149.   def update_help_self
  150.     @help_window_self.set_text(item)
  151.   end  
  152.   end
复制代码





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