Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # -- Script : DSI-Leaderboard
- # -- Author : dsiver144
- # -- Last Updated : 01/06/2021
- #==============================================================================
- # > Script Calls:
- # ---------------------------------------------------------------------
- # 1. open_leaderboard(board_key, point_column_name)
- # ex: open_leaderboard(:dart, "Darts")
- # 2. add_item_to_leaderboard(board_key, name, point)
- # ex: add_item_to_leaderboard(:dart, "Alex", 10)
- # 2. add_actor_to_leaderboard(board_key, actor_index_in_database, point)
- # ex: add_actor_to_leaderboard(:dart, 1, 25)
- #==============================================================================
- module DSIVER144
- module LEADERBOARD
- TEXTS = {}
- TEXTS["Title"] = "~ Leaderboard ~"
- TEXTS["Rank"] = "Rank"
- TEXTS["Name"] = "Name"
- TEXT_COLORS = {}
- TEXT_COLORS["Title"] = 14
- TEXT_COLORS["Column_Name"] = 16
- SELECTED_COLOR0 = Color.new(250, 208, 152, 0)
- SELECTED_COLOR1 = Color.new(252, 186, 3, 255)
- end
- end
- class Game_Interpreter
- #--------------------------------------------------------------------------
- # * Open Leaderboard
- #--------------------------------------------------------------------------
- def open_leaderboard(key, point_column_name)
- SceneManager.call(Scene_Leaderboard)
- SceneManager.scene.prepare(key, point_column_name)
- Fiber.yield
- end
- end
- class Scene_Leaderboard < Scene_MenuBase
- include DSIVER144::LEADERBOARD
- #--------------------------------------------------------------------------
- # * Prepare
- #--------------------------------------------------------------------------
- def prepare(board_key, point_column_name)
- @board_key = board_key
- @point_column_name = point_column_name
- end
- #--------------------------------------------------------------------------
- # * Start Scene
- #--------------------------------------------------------------------------
- def start
- super
- @list_window = Window_RankList.new(0, 0)
- @list_window.set_data($game_party.leader, @board_key)
- @list_window.x = (Graphics.width - @list_window.width) / 2
- @list_window.y = (Graphics.height - @list_window.height) / 2
- @temp_window = Window_Base.new(0, 0, @list_window.width, @list_window.height + @list_window.fitting_height(1) + 12)
- @temp_window.z = 0
- @list_window.z = 10
- @list_window.opacity = 0
- @list_window.back_opacity = 0
- @temp_window.x = (Graphics.width - @temp_window.width) / 2
- @temp_window.y = (Graphics.height - @temp_window.height) / 2
- @list_window.x = @temp_window.x
- @list_window.y = @temp_window.y + @temp_window.height - @list_window.height
- @list_window.set_handler(:cancel, method(:return_scene))
- cw = @temp_window.contents_width
- lh = @temp_window.line_height
- @temp_window.contents.font.size += 4
- @temp_window.contents.font.bold = true
- @temp_window.change_color(@temp_window.text_color(TEXT_COLORS["Title"]))
- @temp_window.draw_text(0, 0, cw, lh, TEXTS["Title"], 1)
- @temp_window.contents.font.size -= 4
- @temp_window.change_color(@temp_window.text_color(TEXT_COLORS["Column_Name"]))
- @temp_window.draw_text(0, lh + 4, cw, lh, TEXTS["Rank"], 0)
- @temp_window.draw_text(0, lh + 4, cw, lh, TEXTS["Name"], 1)
- @temp_window.draw_text(0, lh + 4, cw, lh, @point_column_name, 2)
- @temp_window.contents.fill_rect(0, lh + 4, cw, 1, Color.new(255, 255, 255))
- @temp_window.contents.fill_rect(0, lh + 5, cw, 1, Color.new(0, 0, 0, 100))
- @temp_window.contents.fill_rect(0, lh * 2 + 4, cw, 1, Color.new(255, 255, 255))
- @temp_window.contents.fill_rect(0, lh * 2+ 5, cw, 1, Color.new(0, 0, 0, 100))
- end
- end
- class Window_RankList < Window_Command
- #--------------------------------------------------------------------------
- # * Window Width
- #--------------------------------------------------------------------------
- def window_width
- return Graphics.width - 200
- end
- #--------------------------------------------------------------------------
- # * Window Height
- #--------------------------------------------------------------------------
- def window_height
- fitting_height(10)
- end
- #--------------------------------------------------------------------------
- # * Set Data
- #--------------------------------------------------------------------------
- def set_data(actor, board_key)
- board = $game_system.init_leaderboard(board_key)
- @data = {:actor => actor, :board => board}
- refresh
- end
- #--------------------------------------------------------------------------
- # * Make Command List
- #--------------------------------------------------------------------------
- def make_command_list
- return unless @data
- @show_leader = true
- @data[:board].each do |item|
- add_command("#{item.name}-#{item.points}", :ok, true)
- end
- end
- #--------------------------------------------------------------------------
- # * Get Command Ext
- #--------------------------------------------------------------------------
- def command_ext(index)
- @list[index][:ext]
- end
- #--------------------------------------------------------------------------
- # * Processing When OK Button Is Pressed
- #--------------------------------------------------------------------------
- def process_ok
- if current_item_enabled?
- Input.update
- deactivate
- call_ok_handler
- else
- Sound.play_buzzer
- end
- end
- #--------------------------------------------------------------------------
- # * Draw Item
- #--------------------------------------------------------------------------
- def draw_item(index)
- rect = item_rect(index)
- rect_text = item_rect_for_text(index)
- name, point = command_name(index).split("-")
- isLeader = @data[:actor].name == name && @show_leader
- contents.font.bold = false
- temp_rect = rect.clone
- if isLeader
- color1 = DSIVER144::LEADERBOARD::SELECTED_COLOR0
- color2 = DSIVER144::LEADERBOARD::SELECTED_COLOR1
- temp_rect.width /= 2
- contents.gradient_fill_rect(temp_rect, color1, color2)
- temp_rect.x = temp_rect.width
- contents.gradient_fill_rect(temp_rect, color2, color1)
- @show_leader = false
- contents.font.bold = true
- else
- temp_rect.y += 1
- temp_rect.height -= 2
- contents.fill_rect(temp_rect, Color.new(0, 0, 0, 50))
- end
- rank = index + 1
- draw_text(rect_text, rank, 0)
- draw_text(rect_text, name, 1)
- draw_text(rect_text, point, 2)
- end
- end
- class Game_System
- #--------------------------------------------------------------------------
- # * Init Leaderboard
- #--------------------------------------------------------------------------
- def init_leaderboard(key)
- @leaderboards ||= {}
- @leaderboards[key] ||= []
- end
- #--------------------------------------------------------------------------
- # * Clear Leaderboard
- #--------------------------------------------------------------------------
- def clear_leaderboard(key)
- return if @leaderboards.nil?
- @leaderboards[key] = []
- end
- #--------------------------------------------------------------------------
- # * Add Item To Leaderboard
- #--------------------------------------------------------------------------
- def add_item_to_leaderboard(key, name, points)
- board = init_leaderboard(key)
- board << Leaderboard_Item.new(name, points)
- sort_leaderboard(key)
- end
- #--------------------------------------------------------------------------
- # * Add Actor To Leaderboard
- #--------------------------------------------------------------------------
- def add_actor_to_leaderboard(key, actor_index, points)
- name = $game_actors[actor_index].name
- add_item_to_leaderboard(key, name, points)
- end
- #--------------------------------------------------------------------------
- # * Sort Leaderboard
- #--------------------------------------------------------------------------
- def sort_leaderboard(key)
- board = init_leaderboard(key)
- board.sort! {|a, b| b.points <=> a.points}
- end
- end
- class Leaderboard_Item
- attr_accessor :name
- attr_accessor :points
- #--------------------------------------------------------------------------
- # * Initialize Leaderboard Item
- #--------------------------------------------------------------------------
- def initialize(name, points)
- @name = name
- @points = points
- end
- end
Add Comment
Please, Sign In to add comment