KingGerar

Kingdom Animated Pop-up

Apr 23rd, 2014
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.72 KB | None | 0 0
  1. #==============================================================================
  2. # Kingdom Animated Pop-up
  3. # por King Gerar
  4. #------------------------------------------------------------------------------
  5. # Este script cria uma janela de pop-up. Esta janela tem a função de, ao ganhar
  6. # algum item, habilidade, ou qualquer rápida informação, seja mostrado
  7. # rapidamente na tela.
  8. # Requere Kingdom Módulo v 1.0 ou mais recente.
  9. #==============================================================================
  10. # Módulo KConfig_12
  11. #------------------------------------------------------------------------------
  12. # - Este módulo serve para você fazer as configurações específicas e restritas
  13. # à este script.
  14. #==============================================================================
  15. module KConfig_12
  16.   # Largura da janela de pop-up.
  17.   Wdw_Widht = 128
  18.  
  19.   # Distância base que a animação percorre.
  20.   Anim_Distance = 50
  21.  
  22.   # Tempo em que a primeira animação ocorre.
  23.   # Valor em frames.
  24.   Anim_Time = 20
  25.  
  26.   # Tempo em que o pop-up fica estático na tela.
  27.   # Valor em frames.
  28.   Anim_Wait = 90
  29.  
  30.   # Valor de correção da posição da janela na altura.
  31.   Move_Y = 0
  32.  
  33. #------------------------------------------------------------------------------
  34. # Este pop-up não é ativado automaticamente. É preciso que você o chame,
  35. # utilizando o comando por eventos "Chamar script", usando este código:
  36. #
  37. # kpopup(event, icon, text, arg, anim)
  38. #
  39. # Substituindo as palavras pelo que você deseja colocar.
  40. # event = ID do evento em que será exibido o pop-up.
  41. # icon = ID do ícone que será exibido no pop-up.
  42. # text = Nome do item, habilidade ou do que deseja colocar.
  43. # arg = Caso for usado para mostrar que ganhou item, coloque somente a
  44. #       quantidade desse item. Caso seja para escrever "ganhou", "aprendeu", ou
  45. #       qualquer outra coisa, coloque o texto ou palavra.
  46. # anim = Animação que o pop-up terá, sendo:
  47. #        0 - Aparece gradativamente e some gradativamente.
  48. #        1 - Aparece gradativamente de baixo para cima e some gradativamente.
  49. #        2 - Aparece gradativamente de baixo para cima e some gradativamente
  50. #            subindo.
  51. #
  52. # Exemplos:
  53. #          kpopup(5, 240, "Chave", 1, 0)
  54. #          kpopup(3, 112, "Curar", "Aprendeu!", 1)
  55. #------------------------------------------------------------------------------
  56. end
  57. #==============================================================================
  58. class Game_Interpreter
  59.   def kpopup(event, icon, text, arg, anim)
  60.     $kpopup_window.begin(event, icon, text, arg, anim)
  61.   end
  62. end
  63. #==============================================================================
  64. class Window_KPopup < Window_Base
  65.   include KConfig_12
  66.   #--------------------------------------------------------------------------
  67.   # * Inicialização do objeto
  68.   #--------------------------------------------------------------------------
  69.   def initialize
  70.     super(0, 0, Wdw_Widht, 64)
  71.     self.windowskin = Cache.system(KMain_Config::Window_Main)
  72.     self.change_color(KMain_Config::Color_MainText)
  73.     self.contents.font.name = KMain_Config::Font_Main
  74.       self.contents.font.size = KMain_Config::Font_Size
  75.     self.opacity = 0
  76.     self.contents_opacity = 0
  77.     @current_time = 0
  78.     refresh
  79.   end
  80.   #--------------------------------------------------------------------------
  81.   # * Atualização das informações.
  82.   #--------------------------------------------------------------------------
  83.   def begin(event, icon, text, arg, anim)
  84.     @event = event
  85.     @icon = icon
  86.     @text = text
  87.     @arg = arg
  88.     @anim = anim
  89.     @show_time = Anim_Time + Anim_Wait
  90.     create
  91.   end
  92.   #--------------------------------------------------------------------------
  93.   # * criação das informações.
  94.   #--------------------------------------------------------------------------
  95.   def create
  96.     self.contents.clear
  97.     draw_icon(@icon, 0, 0)
  98.     self.change_color(KMain_Config::Color_MainText)
  99.     draw_text(24, 0, self.width - 48, line_height, @text, 1)
  100.     self.change_color(KMain_Config::Color_AltText)
  101.     if @arg.is_a?(Integer)
  102.       draw_text(0, 0, self.width - 24, (line_height * 2) + 14, "x" + @arg.to_s, 1)
  103.     else
  104.       draw_text(0, 0, self.width - 24, (line_height * 2) + 14, @arg.to_s, 1)
  105.     end
  106.   end
  107.   #--------------------------------------------------------------------------
  108.   # * Atualização do Pop-up e animação.
  109.   #--------------------------------------------------------------------------
  110.   def refresh
  111.     case @anim
  112.     when 0
  113.       if @current_time == 0
  114.         self.x = $game_map.events[@event].screen_x - (self.width / 2)
  115.         self.y = $game_map.events[@event].screen_y - (self.height * 2) + Move_Y
  116.         @current_time += 1
  117.       elsif @current_time > 0 && @current_time < Anim_Time
  118.         self.opacity += (255 / Anim_Time)
  119.         self.contents_opacity += (255 / Anim_Time)
  120.         @current_time += 1
  121.       elsif @current_time >= Anim_Time && @current_time < @show_time
  122.         @current_time += 1
  123.       elsif @current_time >= @show_time && @current_time < @show_time + 10
  124.         self.opacity -= 26
  125.         self.contents_opacity -= 26
  126.         @current_time += 1
  127.       else
  128.         self.contents.clear
  129.       end
  130.     when 1
  131.       if @current_time == 0
  132.         self.x = $game_map.events[@event].screen_x - (self.width / 2)
  133.         self.y = $game_map.events[@event].screen_y - self.height + Move_Y
  134.         @current_time += 1
  135.       elsif @current_time > 0 && @current_time < Anim_Time
  136.         self.y -= (Anim_Distance / Anim_Time)
  137.         self.opacity += (255 / Anim_Time)
  138.         self.contents_opacity += (255 / Anim_Time)
  139.         @current_time += 1
  140.       elsif @current_time >= Anim_Time && @current_time < @show_time
  141.         @current_time += 1
  142.       elsif @current_time >= @show_time && @current_time < @show_time + 10
  143.         self.y -= 3
  144.         self.opacity -= 26
  145.         self.contents_opacity -= 26
  146.         @current_time += 1
  147.       else
  148.         self.contents.clear
  149.       end
  150.     when 2
  151.       if @current_time == 0
  152.         self.x = $game_map.events[@event].screen_x - (self.width / 2)
  153.         self.y = $game_map.events[@event].screen_y - self.height + Move_Y
  154.         @current_time += 1
  155.       elsif @current_time > 0 && @current_time < Anim_Time
  156.         self.y -= (Anim_Distance / Anim_Time)
  157.         self.opacity += (255 / Anim_Time)
  158.         self.contents_opacity += (255 / Anim_Time)
  159.         @current_time += 1
  160.       elsif @current_time >= Anim_Time && @current_time < @show_time
  161.         @current_time += 1
  162.       elsif @current_time >= @show_time && @current_time < @show_time + 10
  163.         self.opacity -= 26
  164.         self.contents_opacity -= 26
  165.         @current_time += 1
  166.       else
  167.         self.contents.clear
  168.       end
  169.     end
  170.   end
  171. end
  172. #==============================================================================
  173. class Scene_Map < Scene_Base
  174.   #--------------------------------------------------------------------------
  175.   # * Inicialização do processo
  176.   #--------------------------------------------------------------------------
  177.   alias kpopup_start start
  178.   def start
  179.     kpopup_start
  180.     $kpopup_window = Window_KPopup.new
  181.   end
  182.   #--------------------------------------------------------------------------
  183.   # * Atualização da tela
  184.   #--------------------------------------------------------------------------
  185.   alias kpopup_update update
  186.   def update
  187.     kpopup_update
  188.     $kpopup_window.refresh
  189.   end
  190.   #--------------------------------------------------------------------------
  191.   # * Finalização do processo
  192.   #--------------------------------------------------------------------------
  193.   alias kpopup_terminate terminate
  194.   def terminate
  195.     kpopup_terminate
  196.     $kpopup_window.dispose
  197.   end
  198. end
Advertisement
Add Comment
Please, Sign In to add comment