赞 | 0 |
VIP | 12 |
好人卡 | 5 |
积分 | 1 |
经验 | 43535 |
最后登录 | 2020-11-2 |
在线时间 | 1050 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 136
- 在线时间
- 1050 小时
- 注册时间
- 2006-5-3
- 帖子
- 774
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 gaofei677 于 2015-1-15 00:14 编辑
- #encoding:utf-8
- #==============================================================================
- # ■ Window_ChoiceList
- #------------------------------------------------------------------------------
- # 此窗口使用于事件指令中的“显示选项”的功能。
- #==============================================================================
- class Window_ChoiceList < Window_Command
- #--------------------------------------------------------------------------
- # ● 初始化对象
- #--------------------------------------------------------------------------
- alias old_initialize initialize
- def initialize(message_window)
- @choice_closed = false
- old_initialize(message_window)
- self.opacity = 0
- creat_choicelist_bg
- update
- end
- #--------------------------------------------------------------------------
- # ● 更新窗口的位置
- #--------------------------------------------------------------------------
- def update_placement
- self.width = [max_choice_width + 12, 96].max + padding * 2
- self.width = [width, Graphics.width].min
- self.width = self.width*2
- self.height = fitting_height($game_message.choices.size)*2-22
- self.x = Graphics.width/2-300#Graphics.width - width
- if @message_window.y >= Graphics.height / 2
- self.y = @message_window.y - height-150
- else
- self.y = @message_window.y + @message_window.height-150
- end
- end
- #--------------------------------------------------------------------------
- # ● 绘制带有控制符的文本内容
- #--------------------------------------------------------------------------
- def draw_text_ex(x, y, text)
- reset_font_settings
- text = convert_escape_characters(text)
- x = (self.width-text_size(text).width)/2 -15
- pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)*2}
- process_character(text.slice!(0, 1), text, pos) until text.empty?
- end
- #--------------------------------------------------------------------------
- # ● 显示选项条
- #--------------------------------------------------------------------------
- def show_choice_pad(x,x_2,y,y_2)
- return if @choice_closed == true
- @choice_pad_open = [] unless @choice_pad_open.is_a?(Array)
- if mouse_in?(x,x_2,y,y_2)
- return if @choice_pad_sprite[@index] == nil
- return if @index_last == @index
- @choice_pad_sprite[@index].bitmap = Cache.ui("dialog_select_1").clone
- Sound.play_cursor unless item_max == 1
- if (item_max == 1) and (@choice_pad_only_one != true)
- Sound.play_cursor
- @choice_pad_only_one = true
- end
- @index_last = 1 if @index_last == nil
- return if item_max == 1
- if @index_last != @index
- @choice_pad_sprite[@index_last].bitmap = Cache.ui("dialog_select_2").clone
- @index_last = @index
- end
- elsif item_max == 1
- return if @choice_pad_sprite == nil
- return if @choice_pad_sprite[@index] == nil
- return if @index_last == nil
- @choice_pad_sprite[@index].bitmap = Cache.ui("dialog_select_2").clone
- @choice_pad_only_one = false
- end
- end
- #--------------------------------------------------------------------------
- # ● 检查光标是否在选项内
- #--------------------------------------------------------------------------
- def mouse_in?(x,x_2,y,y_2)
- if (Mouse.x>=x) and (Mouse.x<=x_2)
- if (Mouse.y>=y) and (Mouse.y<=y_2)
- return true
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 获取项目的高度
- #--------------------------------------------------------------------------
- def item_height
- line_height*2
- end
- #--------------------------------------------------------------------------
- # ● 更新画面
- #--------------------------------------------------------------------------
- alias old_update update
- def update
- old_update
- return if @choice_closed == true
- a = item_rect_for_text(@index)
- #show_choice_pad((a.x+110),(a.x+a.width+110),(a.y+70),(a.y+a.height+70))
- #rect = item_rect_for_text(@index)
- case item_max
- when 4
- #sprite.x = rect.x+60
- #sprite.y = rect.y+70
- show_choice_pad((a.x+110),(a.x+a.width+110),(a.y+70),(a.y+a.height+70))
- when 3
- #sprite.x = rect.x+60
- #sprite.y = rect.y+70
- show_choice_pad((a.x+110),(a.x+a.width+110),(a.y+70+48),(a.y+a.height+70+48))
- when 2
- #sprite.x = rect.x+60
- #sprite.y = rect.y+165
- show_choice_pad((a.x+110),(a.x+a.width+110),(a.y+70+96),(a.y+a.height+70+96))
- when 1
- #sprite.x = rect.x+60
- #sprite.y = rect.y+70
- show_choice_pad((a.x+110),(a.x+a.width+110),(a.y+70+144),(a.y+a.height+70+144))
- end
- creat_choicelist_bg
- clear_selected_flash
- end
- #--------------------------------------------------------------------------
- # ● 清除选择框的闪烁
- #--------------------------------------------------------------------------
- def clear_selected_flash
- return if cursor_rect == Rect.new
- @backup_cursor_rect = cursor_rect.clone
- cursor_rect.empty
- end
- #--------------------------------------------------------------------------
- # ● 判断鼠标是位于光标矩形处
- #--------------------------------------------------------------------------
- def mouse_out_rect?
- if viewport.nil?
- vp_x, vp_y = 0, 0
- else
- vp_x = viewport.rect.x - viewport.ox
- vp_y = viewport.rect.y - viewport.oy
- end
- mouse_rx = ox + Mouse.x - (x + vp_x + standard_padding )
- mouse_ry = oy + Mouse.y - (y + vp_y + standard_padding )
- return if @backup_cursor_rect == Rect.new
- return @backup_cursor_rect.x > mouse_rx ||
- @backup_cursor_rect.y > mouse_ry ||
- @backup_cursor_rect.x + @backup_cursor_rect.width < mouse_rx ||
- @backup_cursor_rect.y + @backup_cursor_rect.height< mouse_ry
- end
- #--------------------------------------------------------------------------
- # ● 创建选项背景
- #--------------------------------------------------------------------------
- def creat_choicelist_bg
- return if @choice_closed == true
- return if item_max == 0 or item_max==nil
- return if @choice_pad_sprite.is_a?(Array)
- @choice_pad_sprite = Array.new(item_max)
- for x in 0..(item_max-1)
- @choice_pad_sprite[x] = Sprite.new
- end
- i = -1
- @choice_pad_sprite.each {|sprite|
- i+=1
- rect = item_rect_for_text(i)
- case item_max
- when 4
- sprite.x = rect.x+60
- sprite.y = rect.y+70
- when 3
- sprite.x = rect.x+60
- sprite.y = rect.y+70+48
- when 2
- sprite.x = rect.x+60
- sprite.y = rect.y+165
- when 1
- sprite.x = rect.x+60
- sprite.y = rect.y+70+144
- end
- sprite.bitmap = Cache.ui("dialog_select_2").clone
- }
- end
- #--------------------------------------------------------------------------
- # ● 关闭窗口
- #--------------------------------------------------------------------------
- alias old_close close
- def close
- @choice_pad_sprite.each {|sprite|
- sprite.bitmap.dispose
- sprite.dispose
- }
- @choice_pad_sprite = nil
- @choice_pad_open = nil
- @index_last = nil
- @choice_pad_only_one = nil
- @backup_cursor_rect = nil
- @choice_closed = true
- old_close
- end
- end
复制代码 使用一次之后,似乎释放得不干净,再用第二次之后,就会出现各种问题,就大大们指点,如何释放干净,使用完之后能还原到 未使用过的状态……
@喵呜喵5 |
|