赞 | 93 |
VIP | 0 |
好人卡 | 13 |
积分 | 80 |
经验 | 53314 |
最后登录 | 2024-8-13 |
在线时间 | 1183 小时 |
Lv4.逐梦者
- 梦石
- 0
- 星屑
- 7981
- 在线时间
- 1183 小时
- 注册时间
- 2007-7-29
- 帖子
- 2055
|
本帖最后由 enghao_lim 于 2010-12-31 02:56 编辑
结果最后竟然又问回来……汗……沒下工程……不过这个是当初你提问时就写好的了……自己慢慢看,我还打算删了呢。- #==============================================================================
- # ■ Window_Item
- #------------------------------------------------------------------------------
- # 物品画面、战斗画面、显示浏览物品的窗口。
- #==============================================================================
- class Window_Item < Window_Base
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_reader :index # 光标位置
- attr_reader :help_window # 帮助窗口
- #--------------------------------------------------------------------------
- # ● 初始化对像
- #--------------------------------------------------------------------------
- def initialize
- super(0, 64, 320, 416)
- @column_max = 1
- refresh
- self.index = 0
- # 战斗中的情况下将窗口移至中央并将其半透明化
- if $game_temp.in_battle
- self.y = 64
- self.height = 256
- self.back_opacity = 160
- end
- end
- #--------------------------------------------------------------------------
- # ● 获取物品
- #--------------------------------------------------------------------------
- def item
- return @data[self.index]
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- def refresh
- if self.contents != nil
- self.contents.dispose
- self.contents = nil
- end
- @data = []
- # 添加物品
- for i in 1...$data_items.size
- if $game_party.item_number(i) > 0
- (0...$game_party.item_number(i)).each{|j|@data.push($data_items[i])}
- end
- end
- # 在战斗中以外添加武器、防具
- unless $game_temp.in_battle
- for i in 1...$data_weapons.size
- if $game_party.weapon_number(i) > 0
- (0...$game_party.weapon_number(i)).each{|j|@data.push($data_weapons[i])}
- end
- end
- for i in 1...$data_armors.size
- if $game_party.armor_number(i) > 0
- (0...$game_party.armor_number(i)).each{|j|@data.push($data_armors[i])}
- end
- end
- end
- # 如果项目数不是 0 就生成位图、重新描绘全部项目
- @item_max = @data.size
- if @item_max > 0
- self.contents = Bitmap.new(width - 32, row_max * 32)
- for i in 0...@item_max
- draw_item(i)
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 描绘项目
- # index : 项目编号
- #--------------------------------------------------------------------------
- def draw_item(index)
- item = @data[index]
- case item
- when RPG::Item
- number = $game_party.item_number(item.id)
- when RPG::Weapon
- number = $game_party.weapon_number(item.id)
- when RPG::Armor
- number = $game_party.armor_number(item.id)
- end
- if item.is_a?(RPG::Item) and
- $game_party.item_can_use?(item.id)
- self.contents.font.color = normal_color
- else
- self.contents.font.color = disabled_color
- end
- x = 4
- y = index * 32
- rect = Rect.new(x, y, self.width / @column_max - 32, 32)
- self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
- bitmap = RPG::Cache.icon(item.icon_name)
- opacity = self.contents.font.color == normal_color ? 255 : 128
- self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
- self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
- end
- #--------------------------------------------------------------------------
- # ● 刷新帮助文本
- #--------------------------------------------------------------------------
- def update_help
- now_page = self.index/self.page_row_max
- word = self.item == nil ? "" : self.item.description
- word += " Page: #{now_page+1}"
- @help_window.set_text(word)
- end
- #--------------------------------------------------------------------------
- # ● 设置光标的位置
- # index : 新的光标位置
- #--------------------------------------------------------------------------
- def index=(index)
- @index = index
- # 刷新帮助文本 (update_help 定义了继承目标)
- if self.active and @help_window != nil
- update_help
- end
- # 刷新光标矩形
- update_cursor_rect
- end
- #--------------------------------------------------------------------------
- # ● 获取行数
- #--------------------------------------------------------------------------
- def row_max
- # 由项目数和列数计算出行数
- return (@item_max + @column_max - 1) / @column_max
- end
- #--------------------------------------------------------------------------
- # ● 获取开头行
- #--------------------------------------------------------------------------
- def top_row
- # 将窗口内容的传送源 Y 坐标、1 行的高 32 等分
- return self.oy / 32
- end
- #--------------------------------------------------------------------------
- # ● 设置开头行
- # row : 显示开头的行
- #--------------------------------------------------------------------------
- def top_row=(row)
- # row 未满 0 的场合更正为 0
- if row < 0
- row = 0
- end
- # row 超过 row_max - 1 的情况下更正为 row_max - 1
- if row > row_max - 1
- row = row_max - 1
- end
- # row 1 行高的 32 倍、窗口内容的传送源 Y 坐标
- self.oy = row * 32
- end
- #--------------------------------------------------------------------------
- # ● 获取 1 页可以显示的行数
- #--------------------------------------------------------------------------
- def page_row_max
- # 窗口的高度,设置画面的高度减去 32 ,除以 1 行的高度 32
- return (self.height - 32) / 32
- end
- #--------------------------------------------------------------------------
- # ● 获取 1 页可以显示的项目数
- #--------------------------------------------------------------------------
- def page_item_max
- # 将行数 page_row_max 乘上列数 @column_max
- return page_row_max * @column_max
- 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 update_cursor_rect
- # 光标位置不满 0 的情况下
- if @index < 0
- self.cursor_rect.empty
- return
- end
- # 获取当前的行
- row = @index / @column_max
- # 当前行被显示开头行前面的情况下
- if row < self.top_row
- # 从当前行向开头行滚动
- self.top_row = row
- end
- # 当前行被显示末尾行之后的情况下
- if row > self.top_row + (self.page_row_max - 1)
- # 从当前行向末尾滚动
- self.top_row = row - (self.page_row_max - 1)
- end
- # 计算光标的宽度
- cursor_width = self.width / @column_max - 32
- # 计算光标坐标
- x = @index % @column_max * (cursor_width + 32)
- y = @index / @column_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::DOWN)
- $game_system.se_play($data_system.cursor_se)
- now_page = self.index/self.page_row_max
- max_page = @item_max/self.page_row_max
- max_page -= 1 if @item_max % self.page_row_max == 0
- if now_page == max_page
- d = @item_max%self.page_row_max
- d = self.page_row_max if d == 0
- else
- d = self.page_row_max
- end
- @index += 1
- @index -= now_page * self.page_row_max
- @index %= d
- @index += now_page * self.page_row_max
- end
- # 方向键上被按下的情况下
- if Input.repeat?(Input::UP)
- $game_system.se_play($data_system.cursor_se)
- now_page = self.index/self.page_row_max
- max_page = @item_max/self.page_row_max
- max_page -= 1 if @item_max % self.page_row_max == 0
- d = nil
- if now_page == max_page
- d = @item_max%self.page_row_max
- d = self.page_row_max if d == 0
- else
- d = self.page_row_max
- end
- @index -= 1
- @index = d - 1 if @index < 0
- @index -= now_page * self.page_row_max
- @index %= d
- @index += now_page * self.page_row_max
- end
- # 方向键右被按下的情况下
- if Input.repeat?(Input::RIGHT) or Input.repeat?(Input::R)
- $game_system.se_play($data_system.cursor_se)
- now_page = self.index/self.page_row_max
- max_page = @item_max/self.page_row_max
- max_page -= 1 if @item_max % self.page_row_max == 0
- now_page += 1
- now_page = 0 if now_page > max_page
- @index = 0
- @index = now_page * self.page_row_max
- self.top_row = @index
- end
- # 方向键左被按下的情况下
- if Input.repeat?(Input::LEFT) or Input.repeat?(Input::L)
- $game_system.se_play($data_system.cursor_se)
- now_page = self.index/self.page_row_max
- max_page = @item_max/self.page_row_max
- max_page -= 1 if @item_max % self.page_row_max == 0
- now_page -= 1
- now_page = max_page if now_page == -1
- @index = 0
- @index = now_page * self.page_row_max
- self.top_row = @index
- end
- end
- # 刷新帮助文本 (update_help 定义了继承目标)
- if self.active and @help_window != nil
- update_help
- end
- # 刷新光标矩形
- update_cursor_rect
- end
- end
复制代码 |
评分
-
查看全部评分
|