Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # =============================================================================
- # TheoAllen - Highscore Board
- # Version : 1.0
- # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
- # (This script documentation is written in informal indonesian language)
- # =============================================================================
- ($imported ||= {})[:Theo_HighScore] = true
- # =============================================================================
- # Change Logs:
- # -----------------------------------------------------------------------------
- # 2013.10.24 - Finished Script
- # =============================================================================
- =begin
- Perkenalan :
- Mau game kamu punya fitur highscore? Script ini mungkin bisa mengabulkan
- permintaan kamu
- Cara penggunaan :
- Pasang script ini dibawah material namun diatas main
- Gunakan beberapa script call berikut untuk keperluan tertentu
- *) Untuk masuk ke menu High Score
- - SceneManager.goto_scoreboard
- *) Untuk memasukkan nama buat score, gunakan script call ini
- - SceneManager.input_scorename(max_char)
- Ganti max_char dengan angka. Angka tersebut adalah untuk menentukan
- sebanyak apa player boleh memasukkan huruf untuk nama
- Instruksi lain ada di konfigurasi
- Terms of use :
- Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
- keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
- dipake buat komersil, jangan lupa, gw dibagi gratisannya.
- =end
- # =============================================================================
- # Konfigurasi :
- # =============================================================================
- module Theo
- module HScore
- # --------------------------------------------------------------------
- # *) Setting umum
- # --------------------------------------------------------------------
- Variable_ID = 1
- # Tentukan variable ID yang akan jadi acuan untuk penilaian skor
- Reset_Key = :SHIFT
- # Key buat ngereset score kalo kamu lagi di menu highscore
- # --------------------------------------------------------------------
- # *) Kosakata umum
- # --------------------------------------------------------------------
- ScoreTitle = "HighScore Board" # Title untuk menu highscore
- ScoreTable = "No. Name" # Text untuk tabel kiri
- ScoreVocab = "Score" # Sebutan untuk skor
- ScoreCommand = "HighScore" # Command yang ada di title screen
- YourScore = "Your Score :" # Text saat kamu memasukkan nama
- # --------------------------------------------------------------------
- # *) Untuk perihal konfirmasi ngereset skor
- # --------------------------------------------------------------------
- ScoreFooter = "Press SHIFT to reset your score"
- # Kata bantuan untuk ngereset
- Confirmation = "Are you sure want to reset the highscore?"
- # Konfirmasi saat player mo ngereset skor
- YesCommand = "Yes" # Kata untuk iya
- NoCommand = "No" # Kata untuk tidak
- end
- end
- # =============================================================================
- # Akhir dari konfigurasi
- # =============================================================================
- class << DataManager
- alias theo_hscore_load_db load_database
- def load_database
- theo_hscore_load_db
- load_scoreboard
- end
- def load_scoreboard
- open_scoreboard
- $scoreboard = load_data(score_path)
- end
- def open_scoreboard(reset = false)
- if !FileTest.exist?(score_path) || reset
- score = []
- File.open(score_path, "w") do |file|
- Marshal.dump(score, file)
- end
- end
- end
- def reset_score
- open_scoreboard(true)
- $scoreboard = load_data(score_path)
- end
- def update_score
- save_data($scoreboard, score_path)
- end
- def score_path
- return "Data/Score.rvdata2"
- end
- def score
- $game_variables[Theo::HScore::Variable_ID]
- end
- end
- class ScoreBoard
- attr_accessor :name
- attr_accessor :score
- def initialize(name, score)
- @name = name
- @score = score
- end
- end
- class Window_HScoreTitle < Window_Base
- def initialize
- super(0,0,Graphics.width,fitting_height(2))
- draw_title
- end
- def draw_title
- draw_text(contents.rect, Theo::HScore::ScoreTitle,1)
- end
- end
- class Window_HScoreBoard < Window_Base
- def initialize(y)
- super(0,y,Graphics.width, Graphics.height - y - line_height*2)
- refresh
- end
- def refresh
- contents.clear
- draw_contents
- end
- def draw_contents
- scorelist = $scoreboard.sort {|a,b| b.score <=> a.score }
- draw_header
- ((contents.height / line_height) - 1).times do |line|
- score = scorelist[line]
- line += 1
- rect = Rect.new(0,line*line_height,contents.width,line_height)
- if score
- txt = sprintf("%d. %s",line, score.name)
- draw_text(rect,txt)
- draw_text(rect, score.score,2)
- else
- txt = sprintf("%d. ",line)
- draw_text(rect,txt)
- end
- end
- end
- def draw_header
- rect = Rect.new(0,0,contents.width, line_height)
- change_color(system_color)
- draw_text(rect, Theo::HScore::ScoreTable)
- draw_text(rect, Theo::HScore::ScoreVocab, 2)
- change_color(normal_color)
- color = Color.new(255,255,255,128)
- contents.fill_rect(0,23,contents.width,2,color)
- end
- end
- class Window_HScoreFooter < Window_Base
- def initialize
- super(0,0,Graphics.width, fitting_height(1))
- self.y = Graphics.height - height
- draw_text(contents.rect, Theo::HScore::ScoreFooter,1)
- end
- end
- class Window_HScoreCommand < Window_Command
- def initialize
- super(0,0)
- self.openness = 0
- select(0)
- deactivate
- end
- def make_command_list
- add_command(Theo::HScore::YesCommand, :yes)
- add_command(Theo::HScore::NoCommand, :cancel)
- end
- end
- class Window_HScoreConfirm < Window_Base
- def initialize
- super(0,0,window_width,fitting_height(1))
- self.openness = 0
- update_placement
- draw_text(contents.rect, Theo::HScore::Confirmation, 1)
- end
- def update_placement
- self.x = (Graphics.width - width) / 2
- self.y = ((Graphics.height - height) / 2) - 25
- end
- def window_width
- return 400
- end
- end
- class Scene_ScoreBoard < Scene_Base
- def start
- super
- @title = Window_HScoreTitle.new
- @score = Window_HScoreBoard.new(@title.height)
- @footer = Window_HScoreFooter.new
- @confirm = Window_HScoreConfirm.new
- create_confirm
- end
- def create_confirm
- @command = Window_HScoreCommand.new
- @command.x = (Graphics.width - @command.width) / 2
- @command.y = @confirm.y + @confirm.height
- @command.set_handler(:yes, method(:reset_score))
- @command.set_handler(:cancel, method(:close_confirm))
- end
- def update
- super
- if Input.trigger?(:B) && !@command.active
- Input.update
- Sound.play_cancel
- return_scene
- elsif Input.trigger?(Theo::HScore::Reset_Key) && !@command_active
- open_confirmation
- end
- end
- def open_confirmation
- @command.activate
- @command.open
- @confirm.open
- end
- def reset_score
- DataManager.reset_score
- @score.refresh
- close_confirm
- end
- def close_confirm
- @command.deactivate
- @command.close
- @confirm.close
- end
- end
- class Window_ScoreName < Window_NameEdit
- class PseudoChar
- attr_accessor :name
- def initialize
- @name = ""
- end
- end
- attr_reader :actor
- def initialize(max_char)
- super(PseudoChar.new, max_char)
- end
- def draw_actor_face(actor, x, y)
- rect = Rect.new(0,0,100,line_height)
- change_color(system_color)
- draw_text(rect, Theo::HScore::YourScore)
- rect.y += line_height
- change_color(normal_color)
- draw_text(rect, DataManager.score)
- end
- end
- class Scene_ScoreName < Scene_MenuBase
- def prepare(max_char)
- @max_char = max_char
- end
- def start
- super
- @edit_window = Window_ScoreName.new(@max_char)
- @input_window = Window_NameInput.new(@edit_window)
- @input_window.set_handler(:ok, method(:on_input_ok))
- end
- def on_input_ok
- $scoreboard.push(ScoreBoard.new(@edit_window.name, DataManager.score))
- DataManager.update_score
- return_scene
- end
- def return_scene
- SceneManager.goto(Scene_ScoreBoard)
- end
- end
- class Window_TitleCommand < Window_Command
- alias theo_hscore_make_command make_command_list
- def make_command_list
- theo_hscore_make_command
- hash = {
- :name=> Theo::HScore::ScoreCommand,
- :symbol=> :hscore,
- :enabled=> true,
- :ext=> nil
- }
- @list.insert(2, hash)
- end
- end
- class Scene_Title < Scene_Base
- alias theo_hscore_start start
- def start
- theo_hscore_start
- @command_window.set_handler(:hscore,method(:goto_hscore)) if @command_window
- end
- def goto_hscore
- SceneManager.goto_scoreboard
- end
- end
- class << SceneManager
- def goto_scoreboard
- call(Scene_ScoreBoard)
- end
- def input_scorename(max_char = 8)
- call(Scene_ScoreName)
- scene.prepare(max_char)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment