Ogłoszenie 

Uwaga! To forum jest w trybie offline.
Wszelką pomoc uzyskasz pod adresem
forum.ultimateam.pl


Administracja Forum


Poprzedni temat «» Następny temat
Kingdom Hearts HUD [VXAce]
Autor Wiadomość
Ayene 




Ranga RM:
4 gry

Pomogła: 232 razy
Dołączyła: 18 Wrz 2007
Posty: 2424
Wysłany: Pon 16 Sty, 2012 18:55
Kingdom Hearts HUD [VXAce]
~ Kingdom Hearts HUD [VXAce] ~


Krótki opis:
Skrypt wyświetla okno ze statystykami na wzór tego z Kingdom Heartsa.

Autor:
Ayene, BigED (wersja VX)

Kompatybilność:
RPG Maker VX Ace

Skrypt:
Spoiler:

Kod:
#--------------------------------------------------------------------
# Kingdom Hearts HUD [VXAce]
# Autorzy: Ayene, BigED (wersja VX)
#--------------------------------------------------------------------
#--------------------------------------------------------------------
# * 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 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 alert_listeners(*args)
    @client_map.each_value { |v| v.each { |func| func.call} }
  end
 
  def dispose
    @client_map = nil
  end
 
end


class Game_Actor < Game_Battler
 
  attr_accessor :hp_mp_changed
 
  alias :pre_confhud_ga_init :initialize unless $@
  def initialize(actor_id)
    @hp_mp_changed = EventHandler.new
    pre_confhud_ga_init(actor_id)   
  end
 
  def on_hp_mp_changed(*args)   
    @hp_mp_changed.alert_listeners(*args)
  end
   
  alias :pre_confhud_ga_refresh :refresh unless $@
  def refresh
    pre_confhud_ga_refresh
    on_hp_mp_changed
  end
 
  alias :pre_confhud_ga_recover_all :recover_all unless $@
  def recover_all
    pre_confhud_ga_recover_all
    on_hp_mp_changed
  end
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   
  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(self, 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   
    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
 
  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
    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.

Piszcie w razie problemów.
________________________


 
 
 
Melvin 




Preferowany:
RPG Maker XP

Ranga RM:
1 gra

Pomógł: 35 razy
Dołączył: 23 Paź 2009
Posty: 1063
Wysłany: Pon 16 Sty, 2012 19:09
Niezły... Tylko jak dla mnie trochę za duży jak na tak małą rozdzielczość.
Jakby go zmniejszyć o połowę, byłoby miodzio :->
________________________
MelvinClass:
Spoiler:

 
 
Ayene 




Ranga RM:
4 gry

Pomogła: 232 razy
Dołączyła: 18 Wrz 2007
Posty: 2424
Wysłany: Pon 16 Sty, 2012 19:13
Takie już są grafiki, ale zawsze można je pozmniejszać. Zobaczymy, może coś pokombinuję :->
________________________


 
 
 
CrasheR 




Pomógł: 123 razy
Dołączył: 20 Gru 2010
Posty: 609
Skąd: Nibelheim
Wysłany: Sro 18 Sty, 2012 16:45
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

Oto prawdziwy wygląd.
Kingdom Hearts:
Spoiler:



Kingdom Hearts II:
Spoiler:

________________________



 
 
 
MrBoomGood 




Preferowany:
RPG Maker VX

Pomógł: 3 razy
Dołączył: 07 Kwi 2011
Posty: 292
Skąd: Katowice
Wysłany: Sro 01 Lut, 2012 22:09
Mam problem... liczby nachodzą mi na napis HP i MP ;/
 
 
 
matitus09 




Preferowany:
RPG Maker XP

Dołączył: 01 Wrz 2010
Posty: 53
Wysłany: Czw 08 Mar, 2012 13:44
Po opcji wprowadź imię wyświetlają mi się kwadraciki. :-(
________________________
Moja strona:
http://rm-xp.manifo.com/
 
 
overhill 




Preferowany:
RPG Maker XP

Dołączył: 31 Maj 2010
Posty: 55
Wysłany: Pon 30 Kwi, 2012 20:12
Bardzo ładny, ale wolę nieco mroczniejsze. Wykorzystam chyba, ale jeśli nie będzie to przeszkodą, nieco przyciemnię sobie grafiki.
________________________
 
 
 
GraczWilliam 




Dołączył: 24 Sie 2012
Posty: 3
Wysłany: Sob 25 Sie, 2012 09:53
Podczas próby uzbrojenia się w miecz wyskakuje błąd.
 
 
SaE 





Ranga RM:
2 gry

Pomogła: 8 razy
Dołączyła: 14 Paź 2007
Posty: 189
Wysłany: Sob 25 Sie, 2012 11:17
Jaki błąd? Wklej jego treść lub zrób screena.
________________________
Nie ma śniegu, a na ulicach pełno bałwanów ^^


 
 
 
Wyświetl posty z ostatnich:   
Odpowiedz do tematu
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
Dodaj temat do Ulubionych
Wersja do druku

Skocz do:  

Powered by phpBB modified by Przemo © 2003 phpBB Group | Template Klam by Ayene