#--------------------------------------------------------------------
# Kingdom Hearts HUD [VXAce]
# Autorzy: Ayene, BigED (wersja VX)
#
# Scene_Save bug fixed [30.06.2013]
#--------------------------------------------------------------------
#--------------------------------------------------------------------
# * Konfiguracja
#--------------------------------------------------------------------
# * Poza poniższymi ustawieniami HUD można schować wywołując komendę
# "Script..." i wpisując poniższy kod:
#
# SceneManager.scene.hide_hud
#--------------------------------------------------------------------
module HudConfig
# ID głównego bohatera, którego dane będą wyświetlane.
PLAYER_ID = 1
# Nazwa grafiki HUD-a (Graphics/Pictures)
PLAYER_HUD_IMAGE_NAME = 'player_hud'
PLAYER_USE_CUSTOM_GAUGE = true
# 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]
# Umiejscowienie twarzy bohatera.
FACE_LOCATION = [35, 0]
# Czy pokazać resztę bohaterów w drużynie?
USE_MEMBER_WINDOW = true
MEMBER_HUD_IMAGE_NAME = 'member_hud'
MEMBER_USE_CUSTOM_GAUGE = false
# Maksymalna liczba wyświetlonych postaci.
MEMEBER_HUD_MAX = 2
# Pozwalać graczowi chować okno?
ALLOW_HUD_HIDE = true
# Przycik, który chowa okno.
HIDE_HUD_INPUT = Input::X
# Szybkość chowanego okna.
HUD_HIDE_SPEED = 7
# Kierunek w którym chowa się okno: 0 - lewo, 1 - prawo.
HUD_SCROLL_DIRECTION = 0
# Ustawienia czcionki.
GLOBAL_FONT_NAME = ['Magneto', 'Consolas', 'Verdana', 'Ariel', 'Courier New']
GLOBAL_PLAYER_FONT_SIZE = 22
GLOBAL_MEMBER_FONT_SIZE = 22
# Reszta ustawień.
PLAYER_NAME_FONT = GLOBAL_FONT_NAME
PLAYER_NAME_COLOR = Color.new(192,192,192)
PLAYER_NAME_USE_ITALICS = false
PLAYER_NAME_USE_BOLD = false
PLAYER_NAME_USE_SHADOW = true
PLAYER_NAME_FONT_SIZE = 20
PLAYER_NAME_LOCATION = [125, 0]
PLAYER_NAME_WIDTH = 90
PLAYER_NAME_HEIGHT = 22
MEMBER_NAME_FONT = GLOBAL_FONT_NAME
MEMBER_NAME_COLOR = Color.new(255,255,255)
MEMBER_NAME_FONT_SIZE = GLOBAL_MEMBER_FONT_SIZE
MEMBER_NAME_LOCATION = [0, 0]
USE_HP_TEXT_DISPLAY = true
PLAYER_HP_FONT = ['Consolas', 'Verdana', 'Ariel', 'Courier New']
PLAYER_FULL_HP_COLOR = Color.new(202,241,126)
PLAYER_HP_FONT_USE_ITALICS = false
PLAYER_HP_FONT_USE_BOLD = true
PLAYER_HP_FONT_USE_SHADOW = true
PLAYER_HP_FONT_SIZE = 14
PLAYER_HP_LOCATION = [130, 66]
PLAYER_HP_WIDTH = 76
PLAYER_HP_HEIGHT = 14
MEMBER_HP_FONT = GLOBAL_FONT_NAME
MEMBER_HP_FONT_SIZE = GLOBAL_MEMBER_FONT_SIZE
MEMBER_HP_LOCATION = [0, 0]
USE_MP_TEXT_DISPLAY = USE_HP_TEXT_DISPLAY
PLAYER_MP_FONT = PLAYER_HP_FONT
PLAYER_FULL_MP_COLOR = Color.new(137,222,254)
PLAYER_MP_FONT_USE_ITALICS = PLAYER_HP_FONT_USE_ITALICS
PLAYER_MP_FONT_USE_BOLD = PLAYER_HP_FONT_USE_BOLD
PLAYER_MP_FONT_USE_SHADOW = PLAYER_HP_FONT_USE_SHADOW
PLAYER_MP_FONT_SIZE = PLAYER_HP_FONT_SIZE
PLAYER_MP_LOCATION = [PLAYER_HP_LOCATION[0], PLAYER_HP_LOCATION[1] + PLAYER_HP_HEIGHT + 1]#Point.new(PLAYER_HP_LOCATION.x, PLAYER_HP_LOCATION.y + PLAYER_HP_HEIGHT + 1)
PLAYER_MP_WIDTH = PLAYER_HP_WIDTH
PLAYER_MP_HEIGHT = PLAYER_HP_HEIGHT
MEMBER_MP_FONT = GLOBAL_FONT_NAME
MEMBER_MP_FONT_SIZE = GLOBAL_MEMBER_FONT_SIZE
MEMBER_MP_LOCATION = [0, 0]
PLAYER_LEVEL_FONT = GLOBAL_FONT_NAME
PLAYER_LEVEL_COLOR = Color.new(255,215,0)
PLAYER_LEVEL_USE_ITALICS = false
PLAYER_LEVEL_USE_BOLD = false
PLAYER_LEVEL_USE_SHADOW = true
PLAYER_LEVEL_FONT_SIZE = 18
PLAYER_LEVEL_LOCATION = [136, 24]
PLAYER_LEVEL_WIDTH = 36
PLAYER_LEVEL_HEIGHT = 35
MEMBER_LEVEL_FONT = GLOBAL_FONT_NAME
MEMBER_LEVEL_COLOR = PLAYER_LEVEL_COLOR
MEMBER_LEVEL_FONT_SIZE = 10
MEMBER_LEVEL_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 Window_Base < Window
alias :pre_confhud_wb_hp_color :hp_color unless $@
def hp_color(actor, for_hud=false)
return HudConfig::PLAYER_FULL_HP_COLOR if for_hud && actor.hp == actor.mhp
return pre_confhud_wb_hp_color(actor)
end
alias :pre_confhud_wb_mp_color :mp_color unless $@
def mp_color(actor, for_hud=false)
return HudConfig::PLAYER_FULL_MP_COLOR if for_hud && actor.mp == actor.mmp
return pre_confhud_wb_mp_color(actor)
end
end
class MainHud < Sprite_Base
include HudConfig
WLH = 24
attr_accessor :actor
def initialize(location, viewport=nil, actor=nil, index=0)
super(viewport)
self.bitmap = Bitmap.new(Graphics.width, Graphics.height)
h = MEMEBER_HUD_MAX > 3 ? 416/[MEMEBER_HUD_MAX, $game_party.members.size].min : 145
self.x, self.y = location[0], location[1] + h*index
self.actor = actor
clear_vars
end
def image_rect
ret = hud_image.rect
ret.x, ret.y = *PLAYER_HUD_LOC
return ret
end
def create_dummy_window
win = Window_Base.new(0, 0, 64, 64)
win.visible = false
return win
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(lambda{refresh})
end
def remove_listeners(actor)
return if actor.nil?
actor.hp_mp_changed.remove_listener(self)
end
def draw_hud
draw_custom_mp_gauge
draw_custom_hp_gauge
image = hud_image
location = hud_location
self.bitmap.blt(location[0], location[1], image, image.rect)
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_gauge(location, stat_name, current, max)
percent_health = (current / max.to_f) * 100
multiple = 5
percent_health = check_health_bounds(percent_health, multiple)
percent_health = round_to_multiple_of(multiple, percent_health.round)
file_name = HEALTH_GAUGE_FORMAT % [stat_name, percent_health]
image = Cache.picture(file_name)
self.bitmap.blt(location[0], location[1], image, image.rect)
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_health(rect, font, prefix, cur, max)
self.bitmap.font = font
w = 5
xr = rect.x + rect.width
health_width = (rect.width * 0.33).round + w
spacer_width = (health_width / 2.1).round
temp_font = self.bitmap.font
prefixf = prefix + ':'
self.bitmap.draw_text(rect.x, rect.y, self.bitmap.text_size(prefixf).width+w, rect.height, prefixf)
self.bitmap.draw_text(xr - spacer_width - health_width * 2 + (health_width * 0.15).round, rect.y, health_width+w, rect.height, cur, 2)
self.bitmap.draw_text(xr - spacer_width - health_width, rect.y, spacer_width+(w/2), rect.height, "/", 2)
self.bitmap.draw_text(xr - health_width - w, rect.y, health_width+w, rect.height, max, 2)
self.bitmap.font = temp_font
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
if on_change?
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
end
def clear_vars
@level = @actor.level
@hp = @actor.hp
@mp = @actor.mp
end
def on_change?
if @level != @actor.level or @hp != @actor.hp or @mp != @actor.mp
clear_vars
return true
end
return false
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_create_all_windows :create_all_windows unless $@
def create_all_windows
initialize_hud
pre_confhud_sm_create_all_windows
end
def initialize_hud
@hud_viewport = Viewport.new
@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_scene unless $@
def update_scene
pre_confhud_sm_update
update_hud unless scene_changing?
update_hud_input unless scene_changing?
update_hud_transition unless scene_changing?
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
@player_hud.each{|i| i.refresh}
@hud_viewport.update
end
def update_hud_input
trigger_scroll if ALLOW_HUD_HIDE && Input.trigger?(HIDE_HUD_INPUT)
end
def update_hud_transition
@@hud_moving = @hud_viewport.ox != @@target_hud_location
return unless @@hud_moving
incr = @hud_viewport.ox < @@target_hud_location ? HUD_HIDE_SPEED : -HUD_HIDE_SPEED
@hud_viewport.ox += [incr, (@hud_viewport.ox - @@target_hud_location).abs].min
end
alias :pre_confhud_sm_terminate :terminate unless $@
def terminate
@player_hud.each{|i| i.dispose}
@@last_hud_ox = @hud_viewport.ox
pre_confhud_sm_terminate
end
end