Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Z20
- LockedIndex = 96
- BarGraphic = "AchievementBar"
- Unknown = "Achievement Locked!"
- DATA = [
- ["Game.new", 5, "Accept the mission.", :fenixfx],
- ["Airport Security", 6, "Have CaptainJet join the party", :captainjet],
- ["Is it cold in here?", 7, "Have IceDragon join the party", :icedragon],
- ["It takes four to Stabby", 8, "Have Zetu join the party", :zetu],
- ["Divide By Zero", 4, "Divide by Zero in the Menu Screen.", :divzero]
- ]
- DURATION = 300 #### HARDCODED FOR NOW D:<
- def self.achieve(symbol)
- for i in 0...DATA.size
- if symbol == DATA[i][3]
- unlock(i)
- return
- end
- end
- end
- def self.unlock(i)
- return false if DATA[i].nil?
- if $game_party.achieve.include?(i)
- return false
- else
- $game_party.achieve.push(i)
- $scene.popup(i)
- return true
- end
- end
- def self.description(i)
- return Unknown unless $game_party.achieve.include?(i)
- title = DATA[i][0]
- description = DATA[i][2]
- return "Achievement: \"#{title}\". \"#{description}\""
- end
- def self.stats
- amount = $game_party.achieve.size
- ratio = amount*100 / DATA.size
- return "#{amount} Achievements Unlocked! (#{ratio}%)"
- end
- end
- class Z20_Achievements < Scene_Base
- def initialize
- @help_window = Window_Help.new
- @stats_window = Window_Help.new
- @stats_window.y = 56
- @stats_window.set_text(Z20.stats)
- @data_window = Window_Achieve.new(0, 112, 640, 368)
- @last_index = -2
- end
- def update
- @data_window.update
- if @last_index != @data_window.index
- @last_index = @data_window.index
- @help_window.set_text(Z20.description(@data_window.index))
- end
- if Input.trigger?(Input::B)
- $scene = Scene_Menu.new(0)
- end
- end
- def terminate
- @data_window.dispose
- @help_window.dispose
- @stats_window.dispose
- end
- end
- class Window_Achieve < Window_Command
- def initialize(x, y, width, height)
- column_max = (width-32) / 24
- commands = Z20::DATA
- row_max = (commands.size + column_max - 1) / column_max
- super(width, commands, column_max, 0, 0)
- self.x = x
- self.y = y
- self.height = height
- @item_max = commands.size
- refresh
- self.index = 0
- end
- def draw_item(index, enabled = true)
- rect = item_rect(index)
- self.contents.clear_rect(rect)
- self.contents.font.color = normal_color
- self.contents.font.color.alpha = enabled ? 255 : 128
- enabled = $game_party.achieve.include?(index)
- if enabled
- index = Z20::DATA[index][1]
- else
- index = Z20::LockedIndex
- end
- draw_icon(index, rect.x, rect.y-1, enabled)
- end
- end
- class Game_Party
- attr_accessor :achieve
- alias z20_initialize initialize
- def initialize
- z20_initialize
- @achieve = []
- end
- end
- class Scene_Base
- def popup(i)
- clear_ach
- Sound.play_decision
- @z20_timer = Z20::DURATION
- @achsprite = Sprite.new
- @achsprite.bitmap = Cache.system(Z20::BarGraphic)
- @achsprite.x = (640 - @achsprite.bitmap.width) / 2
- @achsprite.y = 480 - @achsprite.bitmap.height
- tbitmap = Cache.system("Iconset")
- icon_index = Z20::DATA[i][1]
- rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
- @achsprite.bitmap.blt(4, 3, tbitmap, rect, 255)
- tbitmap.dispose
- text = Z20::DATA[i][0]
- width = @achsprite.bitmap.width - 40
- @achsprite.bitmap.draw_text(36, 3, width, 24, text)
- end
- def update_achievement
- return if @achsprite.nil?
- sprite_update(@z20_timer)
- clear_ach if @z20_timer == 0
- @z20_timer -= 1
- end
- def clear_ach
- return if @achsprite.nil?
- @achsprite.dispose
- @achsprite = nil
- @z20_timer = -1
- end
- def sprite_update(i)
- if i >= 270
- @achsprite.opacity = scale_value(30, 255, 0, i-270)
- elsif i <= 150
- @achsprite.opacity = scale_value(150, 255, 0, 150-i)
- end
- end
- def scale_value(duration, min, max, time)
- return (max - min)*time / duration + min
- end
- end
- class Scene_Map < Scene_Base
- alias z20_update update
- def update
- z20_update
- update_achievement
- end
- alias z20_terminate terminate
- def terminate
- z20_terminate
- clear_ach
- end
- end
- class Scene_Menu < Scene_Base
- alias z20_update update
- def update
- z20_update
- update_achievement
- end
- alias z20_terminate terminate
- def terminate
- z20_terminate
- clear_ach
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement