pigu_6

VM| Sleek item popup

Nov 24th, 2012
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.88 KB | None | 0 0
  1. #Sleek Item Popup v1.9.1
  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, 2 = armor)
  11. # item is the id number of the item
  12. # amount is the amount lost or gained
  13. # duration is the time the window is up and is optional
  14. #
  15. # Examples:
  16. # popup(0,1,5)
  17. # popup(2,12,1,120)
  18. # $PU_AUTOMATIC_POPUP = false
  19. # $PU_AUTOMATIC_POPUP = true
  20. #
  21. #Customization: Just the Sound Effect, set to nil for no sound effect
  22. #
  23. #----------#
  24. #-- Script by: V.M of D.T
  25. #--- Free to use in any non-commercial project with credit given
  26.  
  27. #Sound effect played on popup: # "Filename", Volume(0-100), Pitch(50-150)
  28. PU_SOUND_EFFECT = ["Item3",100,50]
  29.  
  30. #Animation to be played on the player during popup
  31. PU_USE_ANIMATION = false
  32. PU_POPUP_ANIMATION = 2
  33.  
  34. #Duration in frames of Item Popup fadein and fadeout
  35. PU_FADEIN_TIME = 30
  36. PU_FADEOUT_TIME = 30
  37.  
  38. #Default duration of the popup
  39. PU_DEFAULT_DURATION = 90
  40.  
  41. #Use automatic popup? Can be enabled/disabled in game, see examples
  42. $PU_AUTOMATIC_POPUP = true
  43.  
  44. #Whether to use a custom or default font
  45. PU_USE_CUSTOM_FONT = false
  46.  
  47. #Settings for custom item popup font
  48. PU_DEFAULT_FONT_NAME = ["Verdana"]
  49. PU_DEFAULT_FONT_SIZE = 16
  50. PU_DEFAULT_FONT_COLOR = Color.new(255,255,255,255)
  51. PU_DEFAULT_FONT_BOLD = false
  52. PU_DEFAULT_FONT_ITALIC = false
  53. PU_DEFAULT_FONT_SHADOW = false
  54. PU_DEFAULT_FONT_OUTLINE = true
  55.  
  56. #Compact mode will hide the amount unless it's greater then 1
  57. PU_COMPACT_MODE = true
  58.  
  59. #Background Icon to be displayed under item icon
  60. PU_USE_BACKGROUND_ICON = true
  61. PU_BACKGROUND_ICON = 102
  62.  
  63. #True for single line, false for multi line
  64. PU_SINGLE_LINE = true
  65.  
  66. class Item_Popup < Window_Base
  67. def initialize(item, amount, duration, nosound,xoff,yoff)
  68. super(0,0,100,96)
  69. Audio.se_play('Audio/SE/' + PU_SOUND_EFFECT[0],PU_SOUND_EFFECT[1],PU_SOUND_EFFECT[2]) unless PU_SOUND_EFFECT.nil? or nosound
  70. self.opacity = 0
  71. self.x = $game_player.screen_x - 16
  72. self.y = $game_player.screen_y - 80
  73. @xoff = 0
  74. @yoff = 0
  75. @duration = 90
  76. @item = item
  77. @amount = amount
  78. @name = item.name.clone
  79. @text = ""
  80. @timer = 0
  81. @split = (PU_FADEIN_TIME) / @name.size
  82. @split = 2 if @split < 2
  83. amount > 0 ? @red = false : @red = true
  84. if PU_USE_CUSTOM_FONT
  85. contents.font.size = PU_DEFAULT_FONT_SIZE
  86. else
  87. contents.font.size = 16
  88. end
  89. @textsize = text_size(@name)
  90. textsize2 = text_size("+" + amount.to_s)
  91. self.width = @textsize.width + 54
  92. self.width += textsize2.width + 48 if PU_SINGLE_LINE
  93. self.height = @textsize.height + 54
  94. self.height -= 24 if PU_SINGLE_LINE
  95. self.x -= self.width / 4
  96. create_contents
  97. if PU_USE_CUSTOM_FONT
  98. contents.font.name = PU_DEFAULT_FONT_NAME
  99. contents.font.size = PU_DEFAULT_FONT_SIZE
  100. contents.font.color = PU_DEFAULT_FONT_COLOR
  101. contents.font.bold = PU_DEFAULT_FONT_BOLD
  102. contents.font.italic = PU_DEFAULT_FONT_ITALIC
  103. contents.font.shadow = PU_DEFAULT_FONT_SHADOW
  104. contents.font.outline = PU_DEFAULT_FONT_OUTLINE
  105. end
  106. self.contents_opacity = 0
  107. $game_player.animation_id = PU_POPUP_ANIMATION if PU_USE_ANIMATION
  108. update
  109. end
  110. def update
  111. #super
  112. return if self.disposed?
  113. self.visible = true if !self.visible
  114. self.x = $game_player.screen_x - 16 + @xoff
  115. self.y = $game_player.screen_y - 80 + @yoff
  116. self.x -= self.width / 4
  117. open if @timer < (PU_FADEIN_TIME)
  118. close if @timer > (PU_FADEOUT_TIME + @duration)
  119. @timer += 1
  120. @text += @name.slice!(0,1) if @timer % @split == 0
  121. contents.clear
  122. @red ? color = Color.new(255,0,0) : color = Color.new(0,255,0)
  123. contents.font.color = color
  124. stringamount = @amount
  125. stringamount = "+" + @amount.to_s if @amount > 0
  126. if PU_SINGLE_LINE
  127. width = text_size(@item.name).width#@textsize.width
  128. draw_text(27 + width,0,36,24,stringamount) unless PU_COMPACT_MODE and @amount == 1
  129. contents.font.color = Font.default_color
  130. draw_text(24,0,contents.width,contents.height,@text)
  131. draw_icon(PU_BACKGROUND_ICON,0,0) if PU_USE_BACKGROUND_ICON
  132. draw_icon(@item.icon_index,0,0)
  133. else
  134. draw_text(contents.width / 4 + 16,24,36,24,stringamount) unless PU_COMPACT_MODE and @amount == 1
  135. contents.font.color = Font.default_color
  136. draw_icon(PU_BACKGROUND_ICON,contents.width / 4 - 12,24) if PU_USE_BACKGROUND_ICON
  137. draw_icon(@item.icon_index,contents.width / 4 - 12,24)
  138. draw_text(0,0,contents.width,contents.height,@text)
  139. end
  140. end
  141. def close
  142. self.contents_opacity -= (255 / (PU_FADEOUT_TIME))
  143. end
  144. def open
  145. self.contents_opacity += (255 / (PU_FADEIN_TIME))
  146. end
  147. end
  148.  
  149. class Game_Interpreter
  150. alias pu_command_126 command_126
  151. alias pu_command_127 command_127
  152. alias pu_command_128 command_128
  153. def popup(type,item,amount,duration = PU_DEFAULT_DURATION,nosound = false, xo = 0, yo = 0)
  154. data = $data_items[item] if type == 0
  155. data = $data_weapons[item] if type == 1
  156. data = $data_armors[item] if type == 2
  157. Popup_Manager.add(data,amount,duration,nosound,xo,yo)
  158. end
  159. def command_126
  160. pu_command_126
  161. value = operate_value(@params[1], @params[2], @params[3])
  162. popup(0,@params[0],value) if $PU_AUTOMATIC_POPUP
  163. end
  164. def command_127
  165. pu_command_127
  166. value = operate_value(@params[1], @params[2], @params[3])
  167. popup(1,@params[0],value) if $PU_AUTOMATIC_POPUP
  168. end
  169. def command_128
  170. pu_command_128
  171. value = operate_value(@params[1], @params[2], @params[3])
  172. popup(2,@params[0],value) if $PU_AUTOMATIC_POPUP
  173. end
  174. end
  175.  
  176. module Popup_Manager
  177. def self.init
  178. @queue = []
  179. end
  180. def self.add(item,value,dura,ns,xo,yo)
  181. @queue.insert(0,[item,value,dura,ns,xo,yo])
  182. end
  183. def self.queue
  184. @queue
  185. end
  186. end
  187.  
  188. Popup_Manager.init
  189.  
  190. class Scene_Map
  191. alias popup_update update
  192. alias popup_preterminate pre_terminate
  193. def update
  194. popup_update
  195. update_popup_window unless $popupwindow.nil?
  196. return if Popup_Manager.queue.empty?
  197. if $popupwindow.nil? or $popupwindow.contents_opacity == 0
  198. var = Popup_Manager.queue.pop
  199. $popupwindow = Item_Popup.new(var[0],var[1],var[2],var[3],var[4],var[5])
  200. end
  201. end
  202. def update_popup_window
  203. $popupwindow.update
  204. if !$popupwindow.disposed? and $popupwindow.contents_opacity == 0
  205. $popupwindow.dispose
  206. $popupwindow = nil
  207. end
  208. end
  209. def pre_terminate
  210. popup_preterminate
  211. $popupwindow.visible = false unless $popupwindow.nil?
  212. end
  213. end
Advertisement
Add Comment
Please, Sign In to add comment