Advertisement
Guest User

Untitled

a guest
Feb 21st, 2016
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.79 KB | None | 0 0
  1. #Sleek Item Popup v1.14a
  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. # given by email: sumptuaryspade@live.ca
  29. # provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  30. # All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  31. #
  32. #--- Free to use in any project, commercial or non-commercial, with credit given
  33. # - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  34.  
  35. $imported = {} if $imported.nil?
  36. $imported[:Vlue_SleekPopup] = true
  37.  
  38. #Sound effect played on popup: # "Filename", Volume(0-100), Pitch(50-150)
  39. PU_SOUND_EFFECT_GAIN = ["Item3",60,50]
  40. PU_SOUND_EFFECT_LOSE = ["Item3",60,50]
  41. PU_SOUND_GOLD_GAIN = ["Coin",50,50]
  42. PU_SOUND_GOLD_LOSE = ["Coin",50,50]
  43.  
  44. #Animation to be played on the player during popup
  45. PU_USE_ANIMATION = false
  46. PU_POPUP_ANIMATION = 2
  47.  
  48. #Duration in frames of Item Popup fadein and fadeout
  49. PU_FADEIN_TIME = 30
  50. PU_FADEOUT_TIME = 30
  51.  
  52. #Default duration of the popup
  53. PU_DEFAULT_DURATION = 90
  54.  
  55. #Use automatic popup? Can be enabled/disabled in game, see examples
  56. $PU_AUTOMATIC_POPUP = true
  57. PU_IGNORE_ITEM_LOSS = true
  58.  
  59. #Whether to use a custom or default font
  60. PU_USE_CUSTOM_FONT = false
  61.  
  62. #Settings for custom item popup font
  63. PU_DEFAULT_FONT_NAME = ["Verdana"]
  64. PU_DEFAULT_FONT_SIZE = 16
  65. PU_DEFAULT_FONT_COLOR = Color.new(255,255,255,255)
  66. PU_DEFAULT_FONT_BOLD = false
  67. PU_DEFAULT_FONT_ITALIC = false
  68. PU_DEFAULT_FONT_SHADOW = false
  69. PU_DEFAULT_FONT_OUTLINE = true
  70.  
  71. #Compact mode will hide the amount unless it's greater then 1
  72. PU_COMPACT_MODE = true
  73.  
  74. #Background Icon to be displayed under item icon
  75. PU_USE_BACKGROUND_ICON = true
  76. PU_BACKGROUND_ICON = 102
  77.  
  78. #Gold details:
  79. PU_GOLD_NAME = "Gold"
  80. PU_GOLD_ICON = 262
  81.  
  82. #True for single line, false for multi line
  83. PU_SINGLE_LINE = true
  84.  
  85. class Item_Popup < Window_Base
  86. def initialize(item, amount, duration, nosound,xoff,yoff)
  87. super(0,0,100,96)
  88. if item.name == PU_GOLD_NAME
  89. sedg, sedl = PU_SOUND_GOLD_GAIN, PU_SOUND_GOLD_LOSE
  90. else
  91. sedg, sedl = PU_SOUND_EFFECT_GAIN, PU_SOUND_EFFECT_LOSE
  92. end
  93. se = RPG::SE.new(sedg[0],sedg[1],sedg[2]) unless sedg.nil? or nosound
  94. se2 = RPG::SE.new(sedl[0],sedl[1],sedl[2]) unless sedl.nil? or nosound
  95. se.play if se and amount > 0
  96. se2.play if se2 and amount < 0
  97. self.opacity = 0
  98. self.x = $game_player.screen_x - 16
  99. self.y = $game_player.screen_y - 80
  100. @xoff = 0
  101. @yoff = 0
  102. @duration = 90
  103. @item = item
  104. @amount = amount
  105. @name = item.name.clone
  106. @text = ""
  107. @padding = ' '*@name.size
  108. @timer = 0
  109. @split = (PU_FADEIN_TIME) / @name.size
  110. @split = 2 if @split < 2
  111. amount > 0 ? @red = Color.new(0,255,0) : @red = Color.new(255,0,0)
  112. if PU_USE_CUSTOM_FONT
  113. contents.font.size = PU_DEFAULT_FONT_SIZE
  114. else
  115. contents.font.size = 16
  116. end
  117. @textsize = text_size(@name)
  118. textsize2 = text_size("+" + amount.to_s)
  119. self.width = @textsize.width + standard_padding * 2 + 24
  120. self.width += textsize2.width + 48 if PU_SINGLE_LINE
  121. contents.font.size < 24 ? size = 24 : size = contents.font.size
  122. self.height = size + standard_padding * 2
  123. self.height += size if !PU_SINGLE_LINE
  124. self.x -= self.width / 2
  125. create_contents
  126. if PU_USE_CUSTOM_FONT
  127. contents.font.name = PU_DEFAULT_FONT_NAME
  128. contents.font.size = PU_DEFAULT_FONT_SIZE
  129. contents.font.color = PU_DEFAULT_FONT_COLOR
  130. contents.font.bold = PU_DEFAULT_FONT_BOLD
  131. contents.font.italic = PU_DEFAULT_FONT_ITALIC
  132. contents.font.shadow = PU_DEFAULT_FONT_SHADOW
  133. contents.font.outline = PU_DEFAULT_FONT_OUTLINE
  134. end
  135. self.contents_opacity = 0
  136. $game_player.animation_id = PU_POPUP_ANIMATION if PU_USE_ANIMATION
  137. update
  138. end
  139. def update
  140. #super
  141. return if self.disposed?
  142. self.visible = true if !self.visible
  143. self.x = $game_player.screen_x - contents.width/4 + 12
  144. self.y = $game_player.screen_y - 80 + @yoff
  145. self.x -= self.width / 3
  146. open if @timer < (PU_FADEIN_TIME)
  147. close if @timer > (PU_FADEOUT_TIME + @duration)
  148. @timer += 1
  149. return if @timer % @split != 0
  150. @text += @name.slice!(0,1)
  151. @padding.slice!(0,1)
  152. contents.clear
  153. contents.font.color = @red
  154. stringamount = @amount
  155. stringamount = "+" + @amount.to_s if @amount > 0
  156. if PU_SINGLE_LINE
  157. width = text_size(@item.name).width#@textsize.width
  158. draw_text(27 + width,0,36,24,stringamount) unless PU_COMPACT_MODE and @amount == 1
  159. if Module.const_defined?(:AFFIXES)
  160. contents.font.color = @item.color
  161. else
  162. contents.font.color = Font.default_color
  163. end
  164. change_color(@item.rarity_colour) if $imported[:TH_ItemRarity]
  165. draw_text(24,0,contents.width,contents.height,@text+@padding)
  166. change_color(normal_color)
  167. draw_icon(PU_BACKGROUND_ICON,0,0) if PU_USE_BACKGROUND_ICON
  168. draw_icon(@item.icon_index,0,0)
  169. else
  170. draw_text(contents.width / 4 + 16,24,36,24,stringamount) unless PU_COMPACT_MODE and @amount == 1
  171. if Module.const_defined?(:AFFIXES)
  172. contents.font.color = @item.color
  173. else
  174. contents.font.color = Font.default_color
  175. end
  176. draw_icon(PU_BACKGROUND_ICON,contents.width / 2 - 24,24) if PU_USE_BACKGROUND_ICON
  177. draw_icon(@item.icon_index,contents.width / 2 - 24,24)
  178. draw_text(0,0,contents.width,line_height,@text+@padding)
  179. end
  180. end
  181. def close
  182. self.contents_opacity -= (255 / (PU_FADEOUT_TIME))
  183. end
  184. def open
  185. self.contents_opacity += (255 / (PU_FADEIN_TIME))
  186. end
  187. end
  188.  
  189. class Game_Interpreter
  190. alias pu_command_126 command_126
  191. alias pu_command_127 command_127
  192. alias pu_command_128 command_128
  193. alias pu_command_125 command_125
  194. def popup(type,item,amount,duration = PU_DEFAULT_DURATION,nosound = false, xo = 0, yo = 0)
  195. data = $data_items[item] if type == 0
  196. data = $data_weapons[item] if type == 1
  197. data = $data_armors[item] if type == 2
  198. if type == 3
  199. data = RPG::Item.new
  200. data.name = PU_GOLD_NAME
  201. data.icon_index = PU_GOLD_ICON
  202. end
  203. Popup_Manager.add(data,amount,duration,nosound,xo,yo)
  204. end
  205. def command_125
  206. pu_command_125
  207. value = operate_value(@params[0], @params[1], @params[2])
  208. popup(3,@params[0],value) if $PU_AUTOMATIC_POPUP
  209. end
  210. end
  211.  
  212. module Popup_Manager
  213. def self.init
  214. @queue = []
  215. end
  216. def self.add(item,value,dura,ns,xo,yo)
  217. return if PU_IGNORE_ITEM_LOSS && value < 1
  218. @queue.insert(0,[item,value,dura,ns,xo,yo])
  219. end
  220. def self.queue
  221. @queue
  222. end
  223. end
  224.  
  225. Popup_Manager.init
  226.  
  227. class Scene_Map
  228. alias popup_update update
  229. alias popup_preterminate pre_terminate
  230. def update
  231. popup_update
  232. update_popup_window unless $popupwindow.nil?
  233. return if Popup_Manager.queue.empty?
  234. if $popupwindow.nil? or $popupwindow.contents_opacity == 0
  235. var = Popup_Manager.queue.pop
  236. $popupwindow = Item_Popup.new(var[0],var[1],var[2],var[3],var[4],var[5])
  237. end
  238. end
  239. def update_popup_window
  240. $popupwindow.update
  241. $popupwindow.dispose if !$popupwindow.disposed? and $popupwindow.contents_opacity == 0
  242. $popupwindow = nil if $popupwindow.disposed?
  243. end
  244. def pre_terminate
  245. popup_preterminate
  246. $popupwindow.visible = false unless $popupwindow.nil?
  247. end
  248. end
  249.  
  250. class Game_Party
  251. def gain_item(item, amount, include_equip = false)
  252. container = item_container(item.class)
  253. return unless container
  254. last_number = item_number(item)
  255. new_number = last_number + amount
  256. container[item.id] = [[new_number, 0].max, max_item_number(item)].min
  257. container.delete(item.id) if container[item.id] == 0
  258. if include_equip && new_number < 0
  259. discard_members_equip(item, -new_number)
  260. end
  261. $game_map.need_refresh = true
  262. if SceneManager.scene.is_a?(Scene_Map) && $PU_AUTOMATIC_POPUP
  263. Popup_Manager.add(item,amount,90,false,0,0)
  264. end
  265. end
  266. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement