赞 | 5 |
VIP | 620 |
好人卡 | 38 |
积分 | 69 |
经验 | 125468 |
最后登录 | 2015-7-27 |
在线时间 | 1666 小时 |
Lv4.逐梦者
- 梦石
- 0
- 星屑
- 6860
- 在线时间
- 1666 小时
- 注册时间
- 2008-10-29
- 帖子
- 6710
|
做了个按钮式的.范例只有核心部分和物品菜单的.
装备、技能、商店的没做
窗口增加翻页按钮.rar
(261.1 KB, 下载次数: 33)
核心部分是拿 Window_Selectable 改的
- #==============================================================================
- # ■ 此脚本来自 www.66rpg.com 使用和转载时请保留此信息
- =begin
- 功能:给窗口增加翻页按钮
- 作者:后知后觉 2011-8-31
- 说明:请自备 鼠标脚本(whbm)
- 把此核心部分放在 Window_Base 的下面 最好和他挨着
- 把需要有这样效果的窗口将其父类设置为 Window_MouseSelectable
- 然后在相关 Scene 增加对 窗口实例的 hzhj_state 属性判断
- 如果为 1 则是向上翻页 对窗口实例掉用 up_page 即可
- 如果为 2 则是向下翻页 对窗口实例调用 down_page 即可
- 还可以在窗口初始化后调用 make_rect(x1, y1, x2, y2)
- 参数可以省略 省略则为默认值 这是在设置翻页图标的位置
- 是相对于本窗口的坐标位置
- 如果你的窗口在运行中进行了移动(x y变化了)
- 或者是窗口大小被改变了(width、height)
- 都最好再调用一次 make_rect 来更新数据
- =end
- #==============================================================================
- #==============================================================================
- # ■ Window_MouseSelectable
- #==============================================================================
- class Window_MouseSelectable < Window_Base
- UpBitmap = "Graphics/Icons/wdup.png"
- DnBitmap = "Graphics/Icons/wddn.png"
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_reader :index # 光标位置
- attr_reader :help_window # 帮助窗口
- attr_reader :hzhj_state
- #--------------------------------------------------------------------------
- # ● 初始画对像
- #--------------------------------------------------------------------------
- def initialize(x, y, width, height)
- super(x, y, width, height)
- @item_max = 1
- @column_max = 1
- @index = -1
- @up_sprite = Sprite.new
- @dn_sprite = Sprite.new
- @up_sprite.bitmap = Bitmap.new(UpBitmap)
- @dn_sprite.bitmap = Bitmap.new(DnBitmap)
- @up_sprite.z = self.z + 2
- @dn_sprite.z = self.z + 2
- make_rect(*@hzhj_xy)
- @hzhj_state = 0
- @up_sprite.visible = self.visible
- @dn_sprite.visible = self.visible
- 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
- 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 make_rect(hux = nil, huy = nil, hdx = nil, hdy = nil)
- if hux.nil?
- upx = self.x + self.width / 4
- else
- upx = self.x + hux
- end
- if huy.nil?
- upy = self.y + self.height - @up_sprite.bitmap.height
- else
- upy = self.y + huy
- end
- upw = [upx + @up_sprite.bitmap.width, self.x + self.width].min
- uph = [upy + @up_sprite.bitmap.height, self.y + self.height].min
- upxr = [upx, self.x].max
- upyr = [upy, self.y].max
- @up_rect = Rect.new(upxr, upyr, upw, uph)
-
- if hdx.nil?
- dnx = self.x + self.width - self.width / 4
- else
- dnx = self.x + hdx
- end
- if hdy.nil?
- dny = self.y + self.height - @dn_sprite.bitmap.height
- else
- dny = self.y + hdy
- end
- dnw = [dnx + @dn_sprite.bitmap.width, self.x + self.width].min
- dnh = [dny + @dn_sprite.bitmap.height, self.y + self.height].min
- dnxr = [dnx, self.x].max
- dnyr = [dny, self.y].max
- @dn_rect = Rect.new(dnxr, dnyr, dnw, dnh)
-
- @up_sprite.x = upx
- @up_sprite.y = upy
- @dn_sprite.x = dnx
- @dn_sprite.y = dny
- end
- def update
- super
- @up_sprite.update
- @dn_sprite.update
- if self.active and @item_max > 0 and @index >= 0
- mx,my = Mouse.get_mouse_pos
- if mx.between?(@up_rect.x, @up_rect.width) and my.between?(@up_rect.y, @up_rect.height)
- if @hzhj_state != 1
- @hzhj_state = 1
- @up_sprite.tone.set(64, 64, 64)
- @dn_sprite.tone.set(0, 0, 0)
- end
- return
- elsif mx.between?(@dn_rect.x, @dn_rect.width) and my.between?(@dn_rect.y, @dn_rect.height)
- if @hzhj_state != 2
- @hzhj_state = 2
- @up_sprite.tone.set(0, 0, 0)
- @dn_sprite.tone.set(64, 64, 64)
- end
- return
- else
- if @hzhj_state != 0
- @hzhj_state = 0
- @up_sprite.tone.set(0, 0, 0)
- @dn_sprite.tone.set(0, 0, 0)
- end
- end
- now_index = @index
- start_index = top_row * @column_max
- end_index = (top_row + page_row_max) * @column_max
- for i in start_index..end_index
- if i >= @item_max or i == end_index
- self.index = now_index
- break
- end
- @index = i
- update_cursor_rect
- sx = self.x + 16 + self.cursor_rect.x
- sy = self.y + 16 + self.cursor_rect.y
- ex = sx + self.cursor_rect.width
- ey = sy + self.cursor_rect.height
- if mx.between?(sx, ex) and my.between?(sy, ey)
- if @index != now_index
- $game_system.se_play($data_system.cursor_se)
- end
- break
- end
- end
- if Input.repeat?(Input::DOWN)
- if (@column_max == 1 and Input.trigger?(Input::DOWN)) or
- @index < @item_max - @column_max
- $game_system.se_play($data_system.cursor_se)
- @index = (@index + @column_max) % @item_max
- end
- end
- if Input.repeat?(Input::UP)
- if (@column_max == 1 and Input.trigger?(Input::UP)) or
- @index >= @column_max
- $game_system.se_play($data_system.cursor_se)
- @index = (@index - @column_max + @item_max) % @item_max
- end
- end
- if Input.repeat?(Input::RIGHT)
- if @column_max >= 2 and @index < @item_max - 1
- $game_system.se_play($data_system.cursor_se)
- @index += 1
- end
- end
- if Input.repeat?(Input::LEFT)
- if @column_max >= 2 and @index > 0
- $game_system.se_play($data_system.cursor_se)
- @index -= 1
- end
- end
- if Input.repeat?(Input::R)
- if self.top_row + (self.page_row_max - 1) < (self.row_max - 1)
- $game_system.se_play($data_system.cursor_se)
- @index = [@index + self.page_item_max, @item_max - 1].min
- self.top_row += self.page_row_max
- end
- end
- if Input.repeat?(Input::L)
- if self.top_row > 0
- $game_system.se_play($data_system.cursor_se)
- @index = [@index - self.page_item_max, 0].max
- self.top_row -= self.page_row_max
- end
- end
- end
- if self.active and @help_window != nil
- update_help
- end
- update_cursor_rect
- end
- def dispose
- @up_sprite.bitmap.dispose
- @up_sprite.dispose
- @dn_sprite.bitmap.dispose
- @dn_sprite.dispose
- super
- end
- def up_page
- if self.top_row > 0
- $game_system.se_play($data_system.cursor_se)
- @index = [@index - self.page_item_max, 0].max
- self.top_row -= self.page_row_max
- end
- end
- def down_page
- if self.top_row + (self.page_row_max - 1) < (self.row_max - 1)
- $game_system.se_play($data_system.cursor_se)
- @index = [@index + self.page_item_max, @item_max - 1].min
- self.top_row += self.page_row_max
- end
- end
- def visible=(visible)
- super(visible)
- @up_sprite.visible = visible
- @dn_sprite.visible = visible
- end
- end
复制代码 |
|