khanhdu

Profile Slot

Jul 9th, 2017
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.98 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - Profile Slot
  3. # Version : 1.0
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (This script documentation is written in informal indonesian language)
  6. # =============================================================================
  7. ($imported ||= {})[:Theo_ProfileSlot] = true
  8. # =============================================================================
  9. # Change Logs:
  10. # -----------------------------------------------------------------------------
  11. # 2013.11.14 - Finished script
  12. # =============================================================================
  13. =begin
  14.  
  15.   -----------------------------------------------------------------------------
  16.   Perkenalan :
  17.   Script ini menambahkan fitur profile slot. Apa itu profile slot? Yaitu
  18.   sebuah slot untuk tempat kamu menyimpan data di dalam game kamu.
  19.   Gampangannya, kamu memilih slot yang akan di gunakan buat save game nantinya
  20.   di game. Nah, player tidak bisa mengganti slot / save index di tengah
  21.   permainan. Cara new gamenya pun harus dengan memilih index kosong.
  22.  
  23.   -----------------------------------------------------------------------------
  24.   Cara penggunaan :
  25.   Pasang script ini dibawah main namun diatas material
  26.   Edit konfigurasinya untuk mengatur preferensi kamu
  27.  
  28.   Untuk menyimpan game dalam peta (Misalnya checkpoint) cukup dengan
  29.   menggunakan script call seperti ini :
  30.  
  31.   DataManager.save
  32.  
  33.   -----------------------------------------------------------------------------
  34.   Catatan :
  35.   Script ini menghapus command continue pada titlescreen
  36.   Script ini mengalihfungsikan save dalam menu command untuk save game
  37.   Script ini mengalihfungsikan new game untuk masuk ke select profile
  38.  
  39.   -----------------------------------------------------------------------------
  40.   Terms of use :
  41.   Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
  42.   keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
  43.   dipake buat komersil, jangan lupa, gw dibagi gratisannya.
  44.  
  45. =end
  46. # =============================================================================
  47. # Konfigurasi :
  48. # =============================================================================
  49. module Theo
  50.   module ProfSlot
  51.   # --------------------------------------------------------------------
  52.   # Bantuan dan Konfirmasi :
  53.   # --------------------------------------------------------------------
  54.     HelpText        = "Chọn File Lưu Hoặc Nhấn Nút SHIFT Để Xoá"
  55.     DeleteConfirm   = "Bạn Chắc Chắn Sẽ Xoá File Này Chứ ?"
  56.     YesConfirm      = "Vâng"
  57.     CancelConfirm   = "Không"
  58.     DeleteButton    = :SHIFT  # Công Tắt Xoá
  59.   # --------------------------------------------------------------------
  60.    
  61.   # --------------------------------------------------------------------
  62.   # Vokab untuk isi slot :
  63.   # --------------------------------------------------------------------
  64.     VocabFilename   = "File %d"       # Nama file
  65.     VocabLocation   = "Vị Trí : "   # Lokasi peta
  66.     VocabPlaytime   = "Thơi Gian : "   # Lama bermain
  67.     VocabNewGame    = "Trò Mới :"   # Untuk slot kosong
  68.   # --------------------------------------------------------------------  
  69.  
  70.   # --------------------------------------------------------------------
  71.   # Lain-lain :
  72.   # --------------------------------------------------------------------
  73.     Disable_Save    = false       # Nếu bạn để true thì mục save ko hiện trong menu
  74.     Use_Transition  = true       # Transisi saat load / new game?
  75.     Background      = "Wallpaper"
  76.   # -------------------------------------------------------------------
  77.   # ^
  78.   # Wallpaper untuk select profile. Isi dengan "nil" (tanpa kutip) atau
  79.   # kosongkan text diantara "" jika kamu tidak menggunakannya
  80.   # --------------------------------------------------------------------
  81.   end
  82. end
  83. # =============================================================================
  84. # Akhir dari konfigurasi
  85. # =============================================================================
  86. class << DataManager
  87.   attr_accessor :profile_id
  88.  
  89.   alias theo_profile_slot_init init
  90.   def init
  91.     theo_profile_slot_init
  92.     @profile_id = 0
  93.   end
  94.  
  95.   def save
  96.     save_game(profile_id)
  97.   end
  98.  
  99.   alias theo_profslot_save_header make_save_header
  100.   def make_save_header
  101.     header = theo_profslot_save_header
  102.     header[:gold] = $game_party.gold
  103.     header[:location] = $game_map.display_name
  104.     header
  105.   end
  106.  
  107.   def delete_save(index)
  108.     File.delete(make_filename(index))
  109.   end
  110.  
  111. end
  112.  
  113. class Window_ProfileSlot < Window_Base
  114.   attr_reader :index
  115.  
  116.   include Theo::ProfSlot
  117.  
  118.   def initialize(x,y,width,height,index)
  119.     super(x,y,width,height)
  120.     @index = index
  121.     self.active = true
  122.     refresh
  123.     unselect
  124.   end
  125.  
  126.   def item_rect
  127.     xpos = 0
  128.     ypos = 0
  129.     width = 70
  130.     height = line_height
  131.     Rect.new(xpos,ypos,width,height)
  132.   end
  133.  
  134.   def select
  135.     cursor_rect.set(item_rect)
  136.   end
  137.  
  138.   def unselect
  139.     cursor_rect.empty
  140.   end
  141.  
  142.   def refresh
  143.     contents.clear
  144.     change_color(normal_color)
  145.     @header = DataManager.load_header(@index)
  146.     rect = item_rect
  147.     rect.x += 4
  148.     draw_text(rect, sprintf(VocabFilename,@index+1))
  149.     return draw_filled_slot unless slot_empty?
  150.     return draw_empty_slot
  151.   end
  152.  
  153.   def draw_filled_slot
  154.     draw_party
  155.     draw_info
  156.     draw_gold
  157.   end
  158.  
  159.   def draw_party
  160.     x = 24
  161.     y = item_rect.height + line_height * 2 + 12
  162.     @header[:characters].each_with_index do |data, i|
  163.       draw_character(data[0], data[1], x + i * 48, y)
  164.     end
  165.   end
  166.  
  167.   def draw_info
  168.     y = contents.height - line_height*2
  169.     s1 = VocabLocation
  170.     s2 = VocabPlaytime
  171.     width1 = text_size(s1).width
  172.     width2 = text_size(s2).width
  173.     change_color(system_color)
  174.     draw_text(4,y,contents.width,line_height,s1)
  175.     draw_text(4,y + line_height,contents.width,line_height,s2)
  176.     change_color(normal_color)
  177.     draw_text(4+width1,y,contents.width,line_height,@header[:location])
  178.     playtime = @header[:playtime_s]
  179.     draw_text(4+width2,y + line_height,contents.width,line_height,playtime)
  180.   end
  181.  
  182.   def draw_gold
  183.     draw_currency_value(@header[:gold],Vocab.currency_unit,
  184.       4,0,contents.width - 8)
  185.   end
  186.  
  187.   def draw_empty_slot
  188.     rect = contents.rect
  189.     draw_text(rect, VocabNewGame, 1)
  190.   end
  191.  
  192.   def slot_empty?
  193.     @header.nil?
  194.   end
  195.  
  196. end
  197.  
  198. class Window_ProfConfirm < Window_Command
  199.  
  200.   def initialize
  201.     super(0,0)
  202.     self.openness = 0
  203.     deactivate
  204.   end
  205.  
  206.   def make_command_list
  207.     add_command(Theo::ProfSlot::YesConfirm, :yes)
  208.     add_command(Theo::ProfSlot::CancelConfirm, :cancel)
  209.   end
  210.  
  211.   def alignment
  212.     return 1
  213.   end
  214.  
  215. end
  216.  
  217. class Window_ProfConfirmText < Window_Base
  218.  
  219.   def initialize
  220.     super(0,0,1,fitting_height(1))
  221.     resize_window
  222.     self.openness = 0
  223.   end
  224.  
  225.   def resize_window
  226.     @text = Theo::ProfSlot::DeleteConfirm
  227.     size = text_size(@text).width + standard_padding*2 + 4
  228.     self.width = size
  229.     create_contents
  230.     to_center
  231.     refresh
  232.   end
  233.  
  234.   def to_center
  235.     self.x = (Graphics.width - width) / 2
  236.     self.y = ((Graphics.height - height) / 2) - 24
  237.   end
  238.  
  239.   def refresh
  240.     contents.clear
  241.     draw_text(0,0,contents.width,line_height,@text,1)
  242.   end
  243.  
  244. end
  245.  
  246. class Window_MenuCommand < Window_Command
  247.  
  248.   alias theo_profslot_make_command make_command_list
  249.   def make_command_list
  250.     theo_profslot_make_command
  251.     @list.delete_if do |list|
  252.       list[:symbol] == :save
  253.     end if Theo::ProfSlot::Disable_Save
  254.   end
  255.  
  256. end
  257.  
  258. class Window_TitleCommand < Window_Command
  259.  
  260.   alias theo_profslot_make_command make_command_list
  261.   def make_command_list
  262.     theo_profslot_make_command
  263.     @list.delete_if do |list|
  264.       list[:symbol] == :continue
  265.     end
  266.   end
  267.  
  268. end
  269.  
  270. class Scene_Title < Scene_Base
  271.   # --------------------------------------------------------------------------
  272.   # Overwrite Command New Game
  273.   # --------------------------------------------------------------------------
  274.   def command_new_game
  275.     close_command_window
  276.     fadeout_all
  277.     SceneManager.goto(Scene_ProfileSlot)
  278.   end
  279.  
  280. end
  281.  
  282. class Scene_Menu < Scene_MenuBase
  283.   # --------------------------------------------------------------------------
  284.   # Overwrite Command Save
  285.   # --------------------------------------------------------------------------
  286.   def command_save
  287.     DataManager.save
  288.     @command_window.activate
  289.   end
  290.  
  291. end
  292.  
  293. class Scene_ProfileSlot < Scene_MenuBase
  294.   attr_reader :index
  295.  
  296.   def start
  297.     super
  298.     @index = 0
  299.     @viewport2 = Viewport.new
  300.     @viewport2.z = 300
  301.     @active = true
  302.     create_help
  303.     create_slots
  304.     create_confirmation
  305.   end
  306.  
  307.   def create_background
  308.     super
  309.     bgname = Theo::ProfSlot::Background
  310.     @background_sprite.bitmap = Cache.system(bgname) if bgname && !bgname.empty?
  311.   end
  312.  
  313.   def create_help
  314.     @help_window = Window_Help.new(1)
  315.     @help_window.set_text(Theo::ProfSlot::HelpText)
  316.   end
  317.  
  318.   def create_slots
  319.     width = Graphics.width / 2
  320.     height = (Graphics.height - @help_window.height) / 2
  321.     @slots = Array.new(4) do |index|
  322.       xpos = (index % 2) * width
  323.       ypos = (index / 2) * height + @help_window.height
  324.       Window_ProfileSlot.new(xpos,ypos,width,height,index)
  325.     end
  326.     refresh_cursor
  327.   end
  328.  
  329.   def create_confirmation
  330.     @confirm_text = Window_ProfConfirmText.new
  331.     @confirm_command = Window_ProfConfirm.new
  332.     @confirm_command.x = (Graphics.width - @confirm_command.width)/2
  333.     @confirm_command.y = @confirm_text.y + @confirm_text.height
  334.     @confirm_command.set_handler(:yes, method(:on_delete_ok))
  335.     @confirm_command.set_handler(:cancel, method(:on_delete_cancel))
  336.   end
  337.  
  338.   def update
  339.     super
  340.     update_slot
  341.     if @active
  342.       update_cursor
  343.       on_confirm if Input.trigger?(:C)
  344.       on_cancel if Input.trigger?(:B)
  345.       on_delete if Input.trigger?(Theo::ProfSlot::DeleteButton)
  346.     end
  347.   end
  348.  
  349.   def update_slot
  350.     @slots.each {|slot| slot.update}
  351.   end
  352.  
  353.   def update_cursor
  354.     change_index(-2)if Input.trigger?(:UP)
  355.     change_index(2)if Input.trigger?(:DOWN)
  356.     change_index(-1)if Input.trigger?(:LEFT)
  357.     change_index(1)if Input.trigger?(:RIGHT)
  358.   end
  359.  
  360.   def change_index(new_index)
  361.     return unless change_possible?(new_index)
  362.     @index += new_index
  363.     Sound.play_cursor
  364.     refresh_cursor
  365.   end
  366.  
  367.   def change_possible?(new_index)
  368.     n = @index + new_index
  369.     return n >= 0 && n <= 3
  370.   end
  371.  
  372.   def refresh_cursor
  373.     @slots.each do |slot|
  374.       if slot.index == @index
  375.         slot.select
  376.       else
  377.         slot.unselect
  378.       end
  379.     end
  380.   end
  381.  
  382.   def on_confirm
  383.     Sound.play_ok
  384.     start_darken
  385.   end
  386.  
  387.   def start_darken
  388.     @viewport.color = Color.new(0,0,0,0)
  389.     first_transition
  390.     execute_slot
  391.   end
  392.  
  393.   def execute_slot
  394.     @slots[index].slot_empty? ? on_new_game : on_load_game
  395.   end
  396.  
  397.   def on_cancel
  398.     Sound.play_cancel
  399.     return_scene
  400.   end
  401.  
  402.   def on_delete
  403.     if @slots[index].slot_empty?
  404.       Sound.play_buzzer
  405.       return
  406.     end
  407.     Sound.play_ok
  408.     @active = false
  409.     @confirm_text.open
  410.     @confirm_command.open
  411.     @confirm_command.activate
  412.   end
  413.  
  414.   def on_delete_ok
  415.     @active = true
  416.     DataManager.delete_save(index)
  417.     Sound.play_equip
  418.     @slots[index].refresh
  419.     close_confirmation
  420.   end
  421.  
  422.   def on_delete_cancel
  423.     @active = true
  424.     close_confirmation
  425.   end
  426.  
  427.   def close_confirmation
  428.     @confirm_text.close
  429.     @confirm_command.close
  430.     @confirm_command.deactivate
  431.   end
  432.  
  433.   def on_new_game
  434.     second_transition
  435.     DataManager.profile_id = @index
  436.     DataManager.setup_new_game
  437.     $game_map.autoplay
  438.     SceneManager.goto(Scene_Map)
  439.   end
  440.  
  441.   def on_load_game
  442.     second_transition
  443.     DataManager.profile_id = @index
  444.     DataManager.load_game(@index)
  445.     $game_system.on_after_load
  446.     SceneManager.goto(Scene_Map)
  447.   end
  448.  
  449.   def first_transition
  450.     return unless Theo::ProfSlot::Use_Transition
  451.     if $imported[:Theo_Movement]
  452.       x = (Graphics.width - @slots[index].width) / 2
  453.       y = (Graphics.height - @slots[index].height) / 2
  454.       @slots[index].goto(x,y)
  455.     end
  456.     @help_window.viewport = @viewport
  457.     @slots.each do |slot|
  458.       if slot.index == index
  459.         slot.viewport = @viewport2
  460.       else
  461.         slot.viewport = @viewport
  462.       end
  463.     end
  464.     until @viewport.color.alpha == 255
  465.       update_basic
  466.       @slots[index].update
  467.       @viewport.color.alpha += 5
  468.     end
  469.   end
  470.  
  471.   def second_transition
  472.     return unless Theo::ProfSlot::Use_Transition
  473.     60.times { update_basic }
  474.     @viewport2.color = Color.new(0,0,0,0)
  475.     until @viewport2.color.alpha == 255
  476.       update_basic
  477.       @viewport2.color.alpha += 5
  478.     end
  479.     @slots[index].visible = false
  480.     @viewport2.color.alpha = 0
  481.   end
  482.  
  483.   def terminate
  484.     super
  485.     @slots.each {|slot| slot.dispose}
  486.   end
  487.  
  488. end
Add Comment
Please, Sign In to add comment