# Współrządne x i y HUD-a na mapie.
PLAYER_HUD_LOC = [0, 0] # [x, y]
# Położenie tła względem całego HUD-a.
PLAYER_HUD_IMAGE_LOCATION = [0, 0]
# Położenie paska HP względem całego HUD-a.
PLAYER_HP_GAUGE_LOCATION = [0, 0]
# Położenie paska MP względem całego HUD-a.
PLAYER_MP_GAUGE_LOCATION = [0, 0]
#-------
# Nie zmieniaj poniższych wartości, chyba że wiesz, co robisz.
HEALTH_GAUGE_FORMAT = 'hud_bar_%s_%.3d'
PLAYER_FACE_MASK_NAME = 'player_face_mask'
end
class EventHandler
def initialize
@client_map = {}
end
def add_listener(id, func)
(@client_map[id.hash] ||= []) << func
end
def remove_listener(id)
return @client_map.delete(id.hash)
end
def hp_color
return (@window ||= create_dummy_window).hp_color(@actor, true)
end
def mp_color
return (@window ||= create_dummy_window).mp_color(@actor, true)
end
def hud_image
return Cache.picture(PLAYER_HUD_IMAGE_NAME)
end
def hud_location
return PLAYER_HUD_IMAGE_LOCATION
end
def hp_gauge_location
return PLAYER_HP_GAUGE_LOCATION
end
def mp_gauge_location
return PLAYER_MP_GAUGE_LOCATION
end
def name_draw_rect
return Rect.new(
PLAYER_NAME_LOCATION[0],
PLAYER_NAME_LOCATION[1],
PLAYER_NAME_WIDTH,
PLAYER_NAME_HEIGHT
)
end
def level_draw_rect
return Rect.new(
PLAYER_LEVEL_LOCATION[0],
PLAYER_LEVEL_LOCATION[1],
PLAYER_LEVEL_WIDTH,
PLAYER_LEVEL_HEIGHT
)
end
def hp_draw_rect
return Rect.new(
PLAYER_HP_LOCATION[0],
PLAYER_HP_LOCATION[1],
PLAYER_HP_WIDTH,
PLAYER_HP_HEIGHT
)
end
def mp_draw_rect
return Rect.new(
PLAYER_MP_LOCATION[0],
PLAYER_MP_LOCATION[1],
PLAYER_MP_WIDTH,
PLAYER_MP_HEIGHT
)
end
def name_font
font = Font.new(PLAYER_NAME_FONT, PLAYER_NAME_FONT_SIZE)
font.color = PLAYER_NAME_COLOR
font.italic = PLAYER_NAME_USE_ITALICS
font.bold = PLAYER_NAME_USE_BOLD
font.shadow = PLAYER_NAME_USE_SHADOW
return font
end
def hp_font
font = Font.new(PLAYER_HP_FONT, PLAYER_HP_FONT_SIZE)
font.color = hp_color
font.italic = PLAYER_HP_FONT_USE_ITALICS
font.bold = PLAYER_HP_FONT_USE_BOLD
font.shadow = PLAYER_HP_FONT_USE_SHADOW
return font
end
def mp_font
font = Font.new(PLAYER_MP_FONT, PLAYER_MP_FONT_SIZE)
font.color = mp_color
font.italic = PLAYER_MP_FONT_USE_ITALICS
font.bold = PLAYER_MP_FONT_USE_BOLD
font.shadow = PLAYER_MP_FONT_USE_SHADOW
return font
end
def level_font
font = Font.new(PLAYER_LEVEL_FONT, PLAYER_LEVEL_FONT_SIZE)
font.color = PLAYER_LEVEL_COLOR
font.italic = PLAYER_LEVEL_USE_ITALICS
font.bold = PLAYER_LEVEL_USE_BOLD
font.shadow = PLAYER_LEVEL_USE_SHADOW
return font
end
def player_face_mask_image
return Cache.picture(PLAYER_FACE_MASK_NAME)
end
def create_player_face_image(size=96)
face = Cache.face(@actor.face_name)
rect = Rect.new(0, 0, 0, 0)
rect.x = @actor.face_index % 4 * 96 + (96 - size) / 2
rect.y = @actor.face_index / 4 * 96 + (96 - size) / 2
rect.width = size
rect.height = size
mask = player_face_mask_image
@face_image = Bitmap.new(rect.width, rect.height)
@face_image.blt(0, 0, face, rect)
for y in 0...rect.height
for x in 0...rect.width
mask_color = mask.get_pixel(x, y)
@face_image.set_pixel(x, y, mask_color) if mask_color.alpha == 0
end
end
end
def actor=(value)
return if @actor == value || value.nil?
remove_listeners(@actor)
add_listeners(value)
@actor = value
create_player_face_image
refresh
end
def add_listeners(actor)
return if actor.nil?
actor.hp_mp_changed.add_listener(self, lambda { refresh })
end
def remove_listeners(actor)
return if actor.nil?
actor.hp_mp_changed.remove_listener(self)
end
def round_to_multiple_of(multiple_of, num)
leftover = num % multiple_of
return num if leftover.zero?
if leftover > multiple_of / 2
sym = :+
else
sym = :-
end
ret = num
loop do
ret = ret.send sym, 1
break if ret % multiple_of == 0
end
return ret
end
def check_health_bounds(num, multiple)
# dont allow the gauge to read 100 or 0 unless
# the current health actually is 100 or 0.
next_lower = 100 - multiple
if num > next_lower && num < 100
return next_lower
elsif num < multiple && num > 0
return multiple
else
return num
end
end
def draw_custom_hp_gauge
draw_gauge(hp_gauge_location, 'hp', @actor.hp, @actor.mhp)
end
def draw_custom_mp_gauge
draw_gauge(mp_gauge_location, 'mp', @actor.mp, @actor.mmp)
end
def draw_face
self.bitmap.blt(FACE_LOCATION[0], FACE_LOCATION[1], @face_image, @face_image.rect)
end
def draw_name
name = @actor.name
rect = name_draw_rect
font = name_font
temp_font = self.bitmap.font
self.bitmap.font = font
self.bitmap.draw_text(rect, name)
self.bitmap.font = temp_font
end
def draw_level
level = @actor.level
rect = level_draw_rect
font = level_font
temp_font = self.bitmap.font
self.bitmap.font = font
self.bitmap.draw_text(rect, level, 1)
self.bitmap.font = temp_font
end
def use_custom_gauges?
return PLAYER_USE_CUSTOM_GAUGE
end
def health_text(prefix, cur, max)
return "#{prefix}: #{cur}/#{max}"
end
def draw_hp
draw_health(hp_draw_rect, hp_font, Vocab.hp_a, @actor.hp, @actor.mhp)
end
def draw_mp
draw_health(mp_draw_rect, mp_font, Vocab.mp_a, @actor.mp, @actor.mmp)
end
def refresh
self.bitmap.clear
draw_face
draw_hud
return if actor.nil?
draw_name
draw_level
draw_hp if USE_HP_TEXT_DISPLAY
draw_mp if USE_MP_TEXT_DISPLAY
end
def dispose
unless @window.nil?
@window.dispose
@window = nil
end
super
end
end
class Scene_Map < Scene_Base
include HudConfig
attr_reader :player_hud
# used to keep track of the hud location between
# setups and teardowns, i.e., if you enter the menu or battle.
@@last_hud_ox = 0
alias :pre_confhud_sm_start :start unless $@
def start
pre_confhud_sm_start
initialize_hud
end
def initialize_hud
@hud_viewport = Viewport.new(0, 0, 544, 416)
@hud_viewport.z = 9999
@hud_viewport.ox = @@last_hud_ox
@@target_hud_location ||= @hud_viewport.ox
@player_hud = []
if USE_MEMBER_WINDOW
for i in 0...$game_party.members.size
@player_hud.push(MainHud.new(PLAYER_HUD_LOC, @hud_viewport, $game_party.members[i], i))
break if i >= MEMEBER_HUD_MAX-1
end
else
@player_hud.push(MainHud.new(PLAYER_HUD_LOC, @hud_viewport, $game_actors[PLAYER_ID], 0))
end
end
alias :pre_confhud_sm_update :update unless $@
def update
pre_confhud_sm_update
update_hud
update_hud_input
update_hud_transition
end
alias :pre_confhud_sm_update_basic :update_basic unless $@
def update_basic(*args)
pre_confhud_sm_update_basic
update_hud
end
def hide_hud
trigger_scroll
end
def trigger_scroll(force_hide=false)
@@hud_moving = true
if @hud_viewport.ox.zero?
hud_rect = {}
offset = {}
@player_hud.each_index{|i|
hud_rect[i] = @player_hud[i].image_rect
left = HUD_SCROLL_DIRECTION == 0
offset = left ? hud_rect[i].width + hud_rect[i].x : -(Graphics.width - hud_rect[i].x)
@@target_hud_location = @hud_viewport.ox + offset
}
elsif !force_hide
@@target_hud_location = 0
end
end
def update_hud
@hud_viewport.update
end
def update_hud_input
trigger_scroll if ALLOW_HUD_HIDE && Input.trigger?(HIDE_HUD_INPUT)
end
alias :pre_confhud_sm_terminate :terminate unless $@
def terminate
pre_confhud_sm_terminate
@player_hud.each{|i| i.dispose}
@@last_hud_ox = @hud_viewport.ox
end
end
Screeny:
Spoiler:
Materiały:
Dodatkowe informacje:
1. Wklej skrypt nad "Main" w Edytorze Skryptu.
2. Reszta instrukcji znajduje się w treści skryptu.
Moim zdaniem ta grafika nie pasuje do KH i hud powinien znajdować się w innym miejscu, ale skrypt ogólnie fajny ludziom, którzy nie grali się pewnie spodoba xD
Nie możesz pisać nowych tematów Nie możesz odpowiadać w tematach Nie możesz zmieniać swoich postów Nie możesz usuwać swoich postów Nie możesz głosować w ankietach Nie możesz załączać plików na tym forum Możesz ściągać załączniki na tym forum