아이템

아이템 팝업 스크립트

by 스리아씨 posted Oct 17, 2013
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄
  1. #Sleek Item Popup v1.10
  2. #----------#
  3. #Features: A nice and sleek little pop up you can use to tell the player
  4. #           they received (or lost) an item! Now with automatic popups whenever
  5. #           you use the gain item commands in events!
  6. #
  7. #Usage:   Event Script Call:
  8. #           popup(type,item,amount,[duration],[xoff],[yoff])
  9. #
  10. #          Where: type is category of item (0 = item, 1 = weapon,
  11. #                                            2 = armor, 3 = gold)
  12. #                 item is the id number of the item
  13. #                 amount is the amount lost or gained
  14. #                 duration is the time the window is up and is optional
  15. #          
  16. #          Examples:
  17. #            popup(0,1,5)
  18. #            popup(2,12,1,120)
  19. #            $PU_AUTOMATIC_POPUP = false
  20. #            $PU_AUTOMATIC_POPUP = true
  21. #        
  22. #Customization: Everything down there under customization
  23. #
  24. #----------#
  25. #-- Script by: V.M of D.T
  26. #
  27. #- Questions or comments can be:
  28. #    posted on the thread for the script
  29. #    given by email: sumptuaryspade@live.ca
  30. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  31. #    posed on site: daimonioustails.wordpress.com
  32. #
  33. #--- Free to use in any project, commercial or non-commercial, with credit given
  34. # - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  35.  
  36. #Sound effect played on popup: # "Filename", Volume(0-100), Pitch(50-150)
  37. PU_SOUND_EFFECT = ["Item3",100,50]
  38.  
  39. #Animation to be played on the player during popup
  40. PU_USE_ANIMATION = false
  41. PU_POPUP_ANIMATION = 2
  42.  
  43. #Duration in frames of Item Popup fadein and fadeout
  44. PU_FADEIN_TIME = 30
  45. PU_FADEOUT_TIME = 30
  46.  
  47. #Default duration of the popup
  48. PU_DEFAULT_DURATION = 90
  49.  
  50. #Use automatic popup? Can be enabled/disabled in game, see examples
  51. $PU_AUTOMATIC_POPUP = true
  52.  
  53. #Whether to use a custom or default font
  54. PU_USE_CUSTOM_FONT = false
  55.  
  56. #Settings for custom item popup font
  57. PU_DEFAULT_FONT_NAME = ["Verdana"]
  58. PU_DEFAULT_FONT_SIZE = 16
  59. PU_DEFAULT_FONT_COLOR = Color.new(255,255,255,255)
  60. PU_DEFAULT_FONT_BOLD = false
  61. PU_DEFAULT_FONT_ITALIC = false
  62. PU_DEFAULT_FONT_SHADOW = false
  63. PU_DEFAULT_FONT_OUTLINE = true
  64.  
  65. #Compact mode will hide the amount unless it's greater then 1
  66. PU_COMPACT_MODE = true
  67.  
  68. #Background Icon to be displayed under item icon
  69. PU_USE_BACKGROUND_ICON = true
  70. PU_BACKGROUND_ICON = 102
  71.  
  72. #Gold details:
  73. PU_GOLD_NAME = "Gold"
  74. PU_GOLD_ICON = 262
  75.  
  76. #True for single line, false for multi line
  77. PU_SINGLE_LINE = true
  78.  
  79. class Item_Popup < Window_Base
  80.   def initialize(item, amount, duration, nosound,xoff,yoff)
  81.     super(0,0,100,96)
  82.     Audio.se_play('Audio/SE/' + PU_SOUND_EFFECT[0],PU_SOUND_EFFECT[1],PU_SOUND_EFFECT[2]) unless PU_SOUND_EFFECT.nil? or nosound
  83.     self.opacity = 0
  84.     self.x = $game_player.screen_x - 16
  85.     self.y = $game_player.screen_y - 80
  86.     @xoff = 0
  87.     @yoff = 0
  88.     @duration = 90
  89.     @item = item
  90.     @amount = amount
  91.     @name = item.name.clone
  92.     @text = ""
  93.     @timer = 0
  94.     @split = (PU_FADEIN_TIME) / @name.size
  95.     @split = 2 if @split < 2
  96.     amount > 0 ? @red = false : @red = true
  97.     if PU_USE_CUSTOM_FONT
  98.       contents.font.size = PU_DEFAULT_FONT_SIZE
  99.     else
  100.       contents.font.size = 16
  101.     end
  102.     @textsize = text_size(@name)
  103.     textsize2 = text_size("+" + amount.to_s)
  104.     self.width = @textsize.width + 54
  105.     self.width += textsize2.width + 48 if PU_SINGLE_LINE
  106.     self.height = @textsize.height + 54
  107.     self.height -= 24 if PU_SINGLE_LINE
  108.     self.x -= self.width / 4
  109.     create_contents
  110.     if PU_USE_CUSTOM_FONT
  111.       contents.font.name = PU_DEFAULT_FONT_NAME
  112.       contents.font.size = PU_DEFAULT_FONT_SIZE
  113.       contents.font.color = PU_DEFAULT_FONT_COLOR
  114.       contents.font.bold = PU_DEFAULT_FONT_BOLD
  115.       contents.font.italic = PU_DEFAULT_FONT_ITALIC
  116.       contents.font.shadow = PU_DEFAULT_FONT_SHADOW
  117.       contents.font.outline = PU_DEFAULT_FONT_OUTLINE
  118.     end
  119.     self.contents_opacity = 0
  120.     $game_player.animation_id = PU_POPUP_ANIMATION if PU_USE_ANIMATION
  121.     update
  122.   end
  123.   def update
  124.     #super
  125.     return if self.disposed?
  126.     self.visible = true if !self.visible
  127.     self.x = $game_player.screen_x - 16 + @xoff
  128.     self.y = $game_player.screen_y - 80 + @yoff
  129.     self.x -= self.width / 4
  130.     open if @timer < (PU_FADEIN_TIME)
  131.     close if @timer > (PU_FADEOUT_TIME + @duration)
  132.     @timer += 1
  133.     @text += @name.slice!(0,1) if @timer % @split == 0
  134.     contents.clear
  135.     @red ? color = Color.new(255,0,0) : color = Color.new(0,255,0)
  136.     contents.font.color = color
  137.     stringamount = @amount
  138.     stringamount = "+" + @amount.to_s if @amount > 0
  139.     if PU_SINGLE_LINE
  140.       width = text_size(@item.name).width#@textsize.width
  141.       draw_text(27 + width,0,36,24,stringamount) unless PU_COMPACT_MODE and @amount == 1
  142.       contents.font.color = Font.default_color
  143.       draw_text(24,0,contents.width,contents.height,@text)
  144.       draw_icon(PU_BACKGROUND_ICON,0,0) if PU_USE_BACKGROUND_ICON
  145.       draw_icon(@item.icon_index,0,0)
  146.     else
  147.       draw_text(contents.width / 4 + 16,24,36,24,stringamount) unless PU_COMPACT_MODE and @amount == 1
  148.       contents.font.color = Font.default_color
  149.       draw_icon(PU_BACKGROUND_ICON,contents.width / 4 - 12,24) if PU_USE_BACKGROUND_ICON
  150.       draw_icon(@item.icon_index,contents.width / 4 - 12,24)
  151.       draw_text(0,0,contents.width,contents.height,@text)
  152.     end
  153.   end
  154.   def close
  155.     self.contents_opacity -= (255 / (PU_FADEOUT_TIME))
  156.   end
  157.   def open
  158.     self.contents_opacity += (255 / (PU_FADEIN_TIME))
  159.   end
  160. end
  161.  
  162. class Game_Interpreter
  163.   alias pu_command_126 command_126
  164.   alias pu_command_127 command_127
  165.   alias pu_command_128 command_128
  166.   alias pu_command_125 command_125
  167.   def popup(type,item,amount,duration = PU_DEFAULT_DURATION,nosound = false, xo = 0, yo = 0)
  168.     data = $data_items[item] if type == 0
  169.     data = $data_weapons[item] if type == 1
  170.     data = $data_armors[item] if type == 2
  171.     if type == 3
  172.       data = RPG::Item.new
  173.       data.name = PU_GOLD_NAME
  174.       data.icon_index = PU_GOLD_ICON
  175.     end
  176.     Popup_Manager.add(data,amount,duration,nosound,xo,yo)
  177.   end
  178.   def command_126
  179.     pu_command_126
  180.     value = operate_value(@params[1], @params[2], @params[3])
  181.     popup(0,@params[0],value) if $PU_AUTOMATIC_POPUP
  182.   end
  183.   def command_127
  184.     pu_command_127
  185.     value = operate_value(@params[1], @params[2], @params[3])
  186.     popup(1,@params[0],value) if $PU_AUTOMATIC_POPUP
  187.   end
  188.   def command_128
  189.     pu_command_128
  190.     value = operate_value(@params[1], @params[2], @params[3])
  191.     popup(2,@params[0],value) if $PU_AUTOMATIC_POPUP
  192.   end
  193.   def command_125
  194.     pu_command_125
  195.     value = operate_value(@params[0], @params[1], @params[2])
  196.     popup(3,@params[0],value) if $PU_AUTOMATIC_POPUP
  197.   end
  198. end
  199.  
  200. module Popup_Manager
  201.   def self.init
  202.     @queue = []
  203.   end
  204.   def self.add(item,value,dura,ns,xo,yo)
  205.     @queue.insert(0,[item,value,dura,ns,xo,yo])
  206.   end
  207.   def self.queue
  208.     @queue
  209.   end
  210. end  
  211.  
  212. Popup_Manager.init
  213.  
  214. class Scene_Map
  215.   alias popup_update update
  216.   alias popup_preterminate pre_terminate
  217.   def update
  218.     popup_update
  219.     update_popup_window unless $popupwindow.nil?
  220.     return if Popup_Manager.queue.empty?
  221.     if $popupwindow.nil? or $popupwindow.contents_opacity == 0
  222.       var = Popup_Manager.queue.pop
  223.       $popupwindow = Item_Popup.new(var[0],var[1],var[2],var[3],var[4],var[5])
  224.     end
  225.   end
  226.   def update_popup_window
  227.     $popupwindow.update
  228.     if !$popupwindow.disposed? and $popupwindow.contents_opacity == 0
  229.       $popupwindow.dispose
  230.       $popupwindow = nil
  231.     end
  232.   end
  233.   def pre_terminate
  234.     popup_preterminate
  235.     $popupwindow.visible = false unless $popupwindow.nil?
  236.   end
  237. end

 

그러합니다.

제작중인 게임에도 적용해볼까 생각중. . . .