赞 | 0 |
VIP | 0 |
好人卡 | 14 |
积分 | 1 |
经验 | 6041 |
最后登录 | 2014-8-16 |
在线时间 | 122 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 122 小时
- 注册时间
- 2009-6-12
- 帖子
- 73
|
帮我看看
#==============================================================================
# ■ Window_Target
#------------------------------------------------------------------------------
# 物品画面与特技画面的、使用对像角色选择窗口。
#==============================================================================
class Window_Target < Window_Selectable
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
def initialize
super(460, 32, 200, 410)
self.contents = Bitmap.new(width - 32, height - 32)
self.opacity = 0
self.active = false
@item_max = $game_party.actors.size
self.cursor_rect.empty
@cursor = Sprite_Cursor.new
$select = []
for i in 0...@item_max
$select[i] = false
end
$refresh_variable = 0
refresh
refresh_face
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.size = 12
self.contents.font.color = Color.new( 0, 0, 0, 255)
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
# 描绘角色状态
bitmap = RPG::Cache.picture("人物状态背景.png" )
self.contents.blt( -8 ,97 * i - 2,bitmap,Rect.new(0,0,bitmap.width,bitmap.height ))
draw_actor_name(actor, 139, 35 + 97 * i)
# 描绘HP,SP
self.contents.draw_text( - 3, 97 * i, 48, 32, actor.hp.to_s, 2)
self.contents.draw_text( 45, 97 * i, 12, 32, "/")
self.contents.draw_text( 51, 97 * i, 48, 32, actor.maxhp.to_s)
self.contents.draw_text( - 3, 46 + 97 * i, 48, 32, actor.sp.to_s, 2)
self.contents.draw_text( 45, 46 + 97 * i, 12, 32, "/")
self.contents.draw_text( 51, 46 + 97 * i, 48, 32, actor.maxsp.to_s)
# 描绘HP,SP条
draw_actor_hp_meter_line(actor, 18, 24 + 97 * i, 62, 4)
draw_actor_sp_meter_line(actor, 18, 70 + 97 * i, 63, 4)
# 描绘MP,MP条
@actor_mp = $game_variables[26 + i]
@actor_maxmp = $game_variables[31 + i]
self.contents.draw_text( - 10, 23 + 97 * i, 48, 32, @actor_mp.to_s, 2)
self.contents.draw_text( 38, 23 + 97 * i, 12, 32, "/")
self.contents.draw_text( 44, 23 + 97 * i, 48, 32, @actor_maxmp.to_s)
draw_actor_mp_meter_line(actor, 12, 47 + 97 * i, 62, 4)
end
end
# 有改动的地方单独刷新,以提高游戏运行效率
def refresh_face
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
# 描绘角色头像
if $select[i] == true
bitmap = RPG::Cache.battler(actor.name + "头像2" , actor.battler_hue)
else
bitmap = RPG::Cache.battler(actor.name + "头像1" , actor.battler_hue)
end
rect = Rect.new(0,0,bitmap.width,bitmap.height)
self.contents.blt(95,12 + 97 * i,bitmap,rect)
end
end
#-------------------------------------------------------------------------
# ● 定义角色名称
#-------------------------------------------------------------------------
def draw_actor_name(actor,x,y)
bitmap = RPG::Cache.battler(actor.name , actor.battler_hue)
self.contents.blt(x,y,bitmap,Rect.new(0,0,bitmap.width,bitmap.height ))
end
#--------------------------------------------------------------------------
# ● ライン描画 by 桜雅 在土
#--------------------------------------------------------------------------
def draw_line(start_x, start_y, end_x, end_y, start_color, width = 1, end_color = start_color)
# 描写距離の計算。大きめに直角時の長さ。
distance = (start_x - end_x).abs + (start_y - end_y).abs
# 描写開始
if end_color == start_color
for i in 1..distance
x = (start_x + (end_x - start_x) * i / distance).to_i
y = (start_y + (end_y - start_y) * i / distance).to_i
if width == 1
self.contents.set_pixel(x, y, start_color)
else
self.contents.fill_rect(x, y, width, width, start_color)
end
end
else
for i in 1..distance
x = (start_x + (end_x - start_x) * i / distance).to_i
y = (start_y + (end_y - start_y) * i / distance).to_i
r = start_color.red * (distance-i)/distance + end_color.red * i/distance
g = start_color.green * (distance-i)/distance + end_color.green * i/distance
b = start_color.blue * (distance-i)/distance + end_color.blue * i/distance
a = start_color.alpha * (distance-i)/distance + end_color.alpha * i/distance
if width == 1
self.contents.set_pixel(x, y, Color.new(r, g, b, a))
else
self.contents.fill_rect(x, y, width, width, Color.new(r, g, b, a))
end
end
end
end
#--------------------------------------------------------------------------
# ● HP的描画
#--------------------------------------------------------------------------
def draw_actor_hp_meter_line(actor, x, y, width = 156, height = 4)
w = width * actor.hp / actor.maxhp
hp_color_1 = Color.new(229, 188, 245, 255)
hp_color_2 = Color.new(171, 59, 245, 255)
i = 0
for i in 0..3
draw_line(x + width - w, y, x + width , y, hp_color_1, 1, hp_color_2)
y += 1
i += 1
end
end
#--------------------------------------------------------------------------
# ● SP的描画
#--------------------------------------------------------------------------
def draw_actor_sp_meter_line(actor, x, y, width = 156, height = 4)
w = width * actor.sp / actor.maxsp
sp_color_1 = Color.new( 245, 209, 187, 255)
sp_color_2 = Color.new( 250, 117, 65, 255)
for i in 0..3
draw_line(x + width - w, y, x + width , y, sp_color_1, 1, sp_color_2)
y += 1
i += 1
end
end
#--------------------------------------------------------------------------
# ● MP的描画
#--------------------------------------------------------------------------
def draw_actor_mp_meter_line(actor, x, y, width = 156, height = 4)
w = width * @actor_mp / @actor_maxmp
mp_color_1 = Color.new( 187, 225, 245, 255)
mp_color_2 = Color.new( 65, 193, 253, 255)
for i in 0..3
draw_line(x + width - w, y, x + width , y, mp_color_1, 1, mp_color_2)
y += 1
i += 1
end
end
#--------------------------------------------------------------------------
# ● 更新光标矩形
#--------------------------------------------------------------------------
def update_cursor_rect
# 光标位置不满 0 的情况下
if @index < 0 or self.active == false
@cursor.visible = false
return
end
@cursor.visible = true if self.visible && self.active
@cursor.opacitysz(1) if @cursor.opacity < 255
# 获取当前的行
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.x = self.x + 128
@cursor.y = self.y + @index * 97 + 100
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def cursor_update
@cursor.update if @cursor.visible and @cursor.opacity == 255 and
self.active and @item_max >= 1
if self.active and @item_max > 0 and @index >= 0
index_var = @index
mouse_x, mouse_y = Mouse.get_mouse_pos
mouse_not_in_rect = true
for i in 0...@item_max
@index = i
update_cursor_rect
if (mouse_x > 565) and (mouse_y > 55 + i * 97) and
(mouse_x < 625) and (mouse_y < 135 + i * 97)
mouse_not_in_rect = false
$select[i] = true
if $refresh_variable == 0
$game_system.se_play($data_system.cursor_se)
refresh_face
end
$refresh_variable +=1
break
end
end
if mouse_not_in_rect
$refresh_variable = 0
@index = index_var
update_cursor_rect
for i in 0...@item_max
$select[i] = false
end
refresh_face
Mouse.click_lock
else
Mouse.click_unlock
end
end
# 刷新光标矩形
update_cursor_rect
end
def dispose
@cursor.dispose
super
end
end
把refresh中要刷新的一部分放到def refresh_face中刷新,可是每次刷新后原来的内容不会清空,两张图片就重叠在一起了,如果加了self.contents.clear就会把refresh中的内容也清空掉 |
|