Advertisement
KingGerar

Kingdom Animated Pop-up + Módulo

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