Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
- # --------credits--------
- # * Diagostimo for composing this script
- # * Darkness for requesting it
- #
- # ------Author Notes------
- # * this script shows badge images and details depending if they have been
- # obtained or not
- #
- # * to call the script use this script call : "$scene = Scene_Badges.new"
- #
- # * to add badges to your possesion use this script call : "$game_system.badge_array.push(BADGE_ID)"
- # or you can push multiple like so : "$game_system.badge_array.push(BADGE_ID, BADGE_ID, BADGE_ID)"
- #
- # * add the graphics of the badge to the pictures directory and call it "badge'BADGE_ID'"
- # so for example I add badge 1 : "badge1.png"
- #
- # * if for any reason you need to remove a badge from your possesion you use
- # this script call : "$game_system.badge_array.delete(BADGE_ID)"
- #
- # * if you want to have a conditional branch inside an event to condition to a
- # badge been in possesion use this script call : "$game_system.badge_array.include?(BADGE_ID)"
- #
- # * see below for all other related configuration, note this script only supports
- # 8 badges like pokemon games, adding more details/images for other values than
- # specified will simply be ingnored, also note that badge images should be 32x32 sized images.
- #
- #~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
- #
- # C O N F I G U R A T I O N
- #
- #~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
- module Badges
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-#
- # * set the image opacity for badges not in possession
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-#
- NOT_POSSESSION_OPACITY = 100 #255 max, 0 min
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
- # * configure the following descriptions for badges IN possession
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
- def self.badge_in_possession(index)
- case index
- when 1 then 'this is the first description'
- when 2 then 'this is the second description'
- when 3 then 'this is the third description'
- when 4 then 'this is a really long description, long long long long long long long long long long long long.'
- when 5 then 'and so on'
- when 6 then 'and so on'
- when 7 then 'and so on'
- when 8 then 'and so on'
- end
- end
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
- # * configure the following descriptions for badges NOT in possession
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
- def self.badge_not_in_possession(index)
- case index
- when 1 then 'not in possesion 1'
- when 2 then 'not in possesion 2'
- when 3 then 'not in possesion 3'
- when 4 then 'not in possesion 4'
- when 5 then 'not in possesion 5'
- when 6 then 'not in possesion 6'
- when 7 then 'not in possesion 7'
- when 8 then 'not in possesion 8'
- end
- end
- end
- #~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
- #
- # E N D C O N F I G U R A T I O N
- #
- #~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
- class Bitmap
- def format_text(text, width)
- words = text.split(' ')
- return words if words.size == 1
- result, current_text = [], words.shift
- words.each_index {|i|
- if self.text_size("#{current_text} #{words[i]}").width > width
- result.push(current_text)
- current_text = words[i]
- else
- current_text = "#{current_text} #{words[i]}"
- end
- result.push(current_text) if i >= words.size - 1}
- return result
- end
- end
- class Game_System
- attr_accessor :badge_array
- alias init_init initialize
- def initialize
- init_init
- @badge_array = []
- end
- end
- class Window_Badges < Window_Base
- attr_reader :index
- def initialize
- centre = (640 - 288) / 2
- super(centre, 0, 288, 64)
- self.contents = Bitmap.new(width - 32, height - 32)
- self.index = 0
- refresh
- end
- def index=(index)
- @index = index
- update_cursor_rect
- end
- def update_cursor_rect
- x = 0 + @index * 32
- y = 0
- self.cursor_rect.set(x, y, 32, 32)
- end
- def refresh
- self.contents.clear
- for i in 1..8
- @bitmap = RPG::Cache.picture("badge#{i}")
- x = 0 + (i - 1) % 8 * 32
- rect = Rect.new(0, 0, @bitmap.width, @bitmap.height)
- if $game_system.badge_array.include?(i)
- self.contents.blt(x, 0, @bitmap, rect, 255)
- else
- self.contents.blt(x, 0, @bitmap, rect, Badges::NOT_POSSESSION_OPACITY)
- end
- end
- end
- def update
- super
- if Input.repeat?(Input::RIGHT) && @index < 7
- @index += 1
- $game_system.se_play($data_system.cursor_se)
- end
- if Input.repeat?(Input::LEFT) && @index > 0
- @index -= 1
- $game_system.se_play($data_system.cursor_se)
- end
- update_cursor_rect
- refresh
- end
- end
- class Window_Badge_Description < Window_Base
- attr_accessor :text
- def initialize
- @text = ''
- super(0, 0, 288, 128)
- self.contents = Bitmap.new( width - 32, height - 32)
- end
- def refresh
- self.contents.clear
- text = self.contents.format_text(@text, 256)
- text.each_index {|i|
- self.contents.draw_text(0, 0 + i*32, 256, 32, text[i])}
- end
- def update
- super
- refresh
- end
- end
- class Scene_Badges
- def main
- @badges_window = Window_Badges.new
- @description_window = Window_Badge_Description.new
- @badges_window.y = (480 - @description_window.height) - @badges_window.height
- @description_window.y = @badges_window.y + @badges_window.height
- @description_window.x = @badges_window.x
- @sprite = Spriteset_Map.new
- Graphics.transition
- loop { Graphics.update; Input.update; update; break if $scene != self }
- @badges_window.dispose
- @description_window.dispose
- end
- def update
- $scene = Scene_Map.new if Input.trigger?(Input::B)
- if $game_system.badge_array.include?(@badges_window.index + 1)
- @description_window.text = Badges.badge_in_possession(@badges_window.index + 1)
- else
- @description_window.text = Badges.badge_not_in_possession(@badges_window.index + 1)
- end
- @badges_window.update
- @description_window.update
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment