SHARE
TWEET

Untitled

marlosgama Mar 29th, 2020 315 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. # ** Window_CreateChar
  3. #------------------------------------------------------------------------------
  4. #  Esta classe lida com a janela de criação de personagem.
  5. #------------------------------------------------------------------------------
  6. #  Autor: Valentine
  7. #==============================================================================
  8.  
  9. class Window_CreateChar < Window_Base
  10.  
  11.   def initialize
  12.     # Quando a resolução é alterada, as coordenadas x e y
  13.     #são reajustadas no adjust_windows_position da Scene_Map
  14.     super(adjust_x, adjust_y, 401, 288)
  15.     self.visible = false
  16.     self.closable = true
  17.     self.title = Vocab::NewChar
  18.     create_buttons
  19.   end
  20.  
  21.   def adjust_x
  22.     Graphics.width / 2 - 200
  23.   end
  24.  
  25.   def adjust_y
  26.     Graphics.height / 2 - 154
  27.   end
  28.  
  29.   def max_classes
  30.     $network.vip? ? Configs::MAX_VIP_CLASSES : Configs::MAX_DEFAULT_CLASSES
  31.   end
  32.  
  33.   def class_names
  34.     names = []
  35.     (1..max_classes).each do |class_id|
  36.       names << $data_classes[class_id].name
  37.     end
  38.     names
  39.   end
  40.  
  41.   def create_buttons
  42.     @name_box = Text_Box.new(self, 79, 20, 115, Configs::MAX_CHARACTERS) { enable_create_button }
  43.     @class_box = Combo_Box.new(self, 265, 20, 120, class_names, :down) { change_class } if max_classes > 1
  44.     @next_sex = Image_Button.new(self, 176, 48, 'Right') { change_sex(Constants::SEX_FEMALE) }
  45.     @prev_sex = Image_Button.new(self, 79, 48, 'Left') { change_sex(Constants::SEX_MALE) }
  46.     @next_char = Image_Button.new(self, 176, 75, 'Right') { next_character }
  47.     @prev_char = Image_Button.new(self, 79, 75, 'Left') { prev_character }
  48.     @rem_hp = Button.new(self, 19, 147, '-', 26) { remove_param(0) }
  49.     @rem_mp = Button.new(self, 19, 171, '-', 26) { remove_param(1) }
  50.     @rem_atk = Button.new(self, 19, 195, '-', 26) { remove_param(2) }
  51.     @remo_agi = Button.new(self, 19, 219, '-', 26) { remove_param(3) }
  52.     @add_hp = Button.new(self, 166, 147, '+', 26) { add_param(0) }
  53.     @add_mp = Button.new(self, 166, 171, '+', 26) { add_param(1) }
  54.     @add_atk = Button.new(self, 166, 195, '+', 26) { add_param(2) }
  55.     @add_agi = Button.new(self, 166, 219, '+', 26) { add_param(3) }
  56.     @rem_def = Button.new(self, 211, 147, '-', 26) { remove_param(4) }
  57.     @remo_mat = Button.new(self, 211, 171, '-', 26) { remove_param(5) }
  58.     @rem_mdf = Button.new(self, 211, 195, '-', 26) { remove_param(6) }
  59.     @rem_luk = Button.new(self, 211, 219, '-', 26) { remove_param(7) }
  60.     @add_def = Button.new(self, 356, 147, '+', 26) { add_param(4) }
  61.     @add_mat = Button.new(self, 356, 171, '+', 26) { add_param(5) }
  62.     @add_mdf = Button.new(self, 356, 195, '+', 26) { add_param(6) }
  63.     @add_luk = Button.new(self, 356, 219, '+', 26) { add_param(7) }
  64.     @create_button = Button.new(self, 168, 254, Vocab::Create, 64) { new_character }
  65.     @points_bar = Progress_Bar.new(self, 18, 121, 365, Configs::START_POINTS) if Configs::START_POINTS > 0
  66.   end
  67.  
  68.   def show(actor_id)
  69.     @actor_id = actor_id
  70.     @sex = Constants::SEX_MALE
  71.     @points = Configs::START_POINTS
  72.     @class_id = 1
  73.     @sprite_index = 0
  74.     refresh_character
  75.     @params = Array.new(8, 0)
  76.     @name_box.clear
  77.     @create_button.enable = false
  78.     super()
  79.     # Ativa a caixa de texto após a janela ficar visível
  80.     @name_box.active = true
  81.     enable_buttons
  82.   end
  83.  
  84.   def hide
  85.     super
  86.     $windows[:alert].hide
  87.     $windows[:use_char].show
  88.   end
  89.  
  90.   def invalid_name?
  91.     @name_box.text =~ /[^A-Za-z0-9 ]/
  92.   end
  93.  
  94.   def illegal_name?
  95.     Configs::FORBIDDEN_NAMES.any? { |word| @name_box.text =~ /#{word}/i }
  96.   end
  97.  
  98.   def refresh
  99.     contents.clear
  100.     draw_shadow(108, 73)
  101.     draw_character(@character_name, @character_index, 124, 103)
  102.     change_color(normal_color)
  103.     draw_text(4, 8, 45, line_height, "#{Vocab::Name}:")
  104.     draw_text(196, 8, 60, line_height, Vocab::Class)
  105.     draw_text(260, 8, 150, line_height, $data_classes[@class_id].name) if max_classes == 1
  106.     draw_text(4, 35, 45, line_height, Vocab::Sex)
  107.     draw_text(97, 35, 55, line_height, @sex == Constants::SEX_MALE ? Vocab::Male : Vocab::Female, 1)
  108.     draw_text(4, 62, 70, line_height, Vocab::Graphic)
  109.     draw_text(119, 137, 25, line_height, @params[0] * 10 + $data_classes[@class_id].params[0, 1], 2)
  110.     draw_text(119, 161, 25, line_height, @params[1] * 10 + $data_classes[@class_id].params[1, 1], 2)
  111.     word_wrap($data_actors[@class_id].description.delete("\n"), 210).each_with_index do |text, i|
  112.       draw_text(196, line_height * i + 31, contents_width, line_height, text)
  113.     end
  114.     (2...8).each do |param_id|
  115.       draw_text(param_id / 4 * 189 + 119, param_id % 4 * 24 + 137, 25, line_height, $data_classes[@class_id].params[param_id, 1] + @params[param_id], 2)
  116.     end
  117.     change_color(system_color)
  118.     (0...8).each do |param_id|
  119.       # Largura suficiente para os termos não abreviados
  120.       draw_text(param_id / 4 * 193 + 47, param_id % 4 * 24 + 137, 100, line_height, "#{Vocab::param(param_id)}:")
  121.     end
  122.     if @points_bar
  123.       @points_bar.index = @points
  124.       @points_bar.text = "#{@points}/#{Configs::START_POINTS}"
  125.     end
  126.     @next_char.visible = @prev_char.visible = $data_classes[@class_id].graphics[@sex].size > 1
  127.   end
  128.  
  129.   def refresh_character
  130.     @character_name = $data_classes[@class_id].graphics[@sex][@sprite_index][0]
  131.     @character_index = $data_classes[@class_id].graphics[@sex][@sprite_index][1]
  132.   end
  133.  
  134.   def new_character
  135.     return unless @create_button.enable
  136.     if illegal_name? && $network.standard_group?
  137.       $windows[:alert].show(Vocab::InvalidName)
  138.     elsif invalid_name?
  139.       $windows[:alert].show(Vocab::ForbiddenCharacter)
  140.     else
  141.       $network.send_new_character(@actor_id, @name_box.text, @sprite_index, @class_id, @sex, @params, @points)
  142.     end
  143.   end
  144.  
  145.   def change_sex(sex)
  146.     @sex = sex
  147.     @sprite_index = 0
  148.     refresh_character
  149.     refresh
  150.   end
  151.  
  152.   def change_class
  153.     @class_id = @class_box.index + 1
  154.     @sprite_index = 0
  155.     refresh_character
  156.     refresh
  157.   end
  158.  
  159.   def next_character
  160.     @sprite_index = @sprite_index < $data_classes[@class_id].graphics[@sex].size - 1 ? @sprite_index + 1 : 0
  161.     refresh_character
  162.     refresh
  163.   end
  164.  
  165.   def prev_character
  166.     @sprite_index = @sprite_index > 0 ? @sprite_index - 1 : @sprite_index = $data_classes[@class_id].graphics[@sex].size - 1
  167.     refresh_character
  168.     refresh
  169.   end
  170.  
  171.   def add_param(param_id)
  172.     @points -= 1
  173.     @params[param_id] += 1
  174.     refresh
  175.     enable_buttons
  176.   end
  177.  
  178.   def remove_param(param_id)
  179.     @points += 1
  180.     @params[param_id] -= 1
  181.     refresh
  182.     enable_buttons
  183.   end
  184.  
  185.   def enable_buttons
  186.     @rem_hp.enable = @params[0] > 0
  187.     @rem_mp.enable = @params[1] > 0
  188.     @rem_atk.enable = @params[2] > 0
  189.     @remo_agi.enable = @params[3] > 0
  190.     @rem_def.enable = @params[4] > 0
  191.     @remo_mat.enable = @params[5] > 0
  192.     @rem_mdf.enable = @params[6] > 0
  193.     @rem_luk.enable = @params[7] > 0
  194.     enable = @points > 0
  195.     @add_hp.enable = enable
  196.     @add_mp.enable = enable
  197.     @add_atk.enable = enable
  198.     @add_agi.enable = enable
  199.     @add_def.enable = enable
  200.     @add_mat.enable = enable
  201.     @add_mdf.enable = enable
  202.     @add_luk.enable = enable
  203.   end
  204.  
  205.   def enable_create_button
  206.     @create_button.enable = @name_box.text.strip.size >= Configs::MIN_CHARACTERS
  207.   end
  208.  
  209.   def update
  210.     super
  211.     close_windows
  212.     ok if Input.trigger?(:C)
  213.   end
  214.  
  215.   def close_windows
  216.     return unless Input.trigger?(:B)
  217.     if $windows[:alert].visible || $windows[:config].visible
  218.       $windows[:alert].hide
  219.       $windows[:config].hide
  220.     else
  221.       hide
  222.     end
  223.   end
  224.  
  225.   def ok
  226.     $windows[:alert].visible ? $windows[:alert].hide : new_character
  227.   end
  228.  
  229. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top