Advertisement
marlosgama

Untitled

Mar 29th, 2020
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.75 KB | None | 0 0
  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.     @class_box.index = 0
  79.     super()
  80.     # Ativa a caixa de texto após a janela ficar visível
  81.     @name_box.active = true
  82.     enable_buttons
  83.   end
  84.  
  85.   def hide
  86.     super
  87.     $windows[:alert].hide
  88.     $windows[:use_char].show
  89.   end
  90.  
  91.   def invalid_name?
  92.     @name_box.text =~ /[^A-Za-z0-9 ]/
  93.   end
  94.  
  95.   def illegal_name?
  96.     Configs::FORBIDDEN_NAMES.any? { |word| @name_box.text =~ /#{word}/i }
  97.   end
  98.  
  99.   def refresh
  100.     contents.clear
  101.     draw_shadow(108, 73)
  102.     draw_character(@character_name, @character_index, 124, 103)
  103.     change_color(normal_color)
  104.     draw_text(4, 8, 45, line_height, "#{Vocab::Name}:")
  105.     draw_text(196, 8, 60, line_height, Vocab::Class)
  106.     draw_text(260, 8, 150, line_height, $data_classes[@class_id].name) if max_classes == 1
  107.     draw_text(4, 35, 45, line_height, Vocab::Sex)
  108.     draw_text(97, 35, 55, line_height, @sex == Constants::SEX_MALE ? Vocab::Male : Vocab::Female, 1)
  109.     draw_text(4, 62, 70, line_height, Vocab::Graphic)
  110.     draw_text(119, 137, 25, line_height, @params[0] * 10 + $data_classes[@class_id].params[0, 1], 2)
  111.     draw_text(119, 161, 25, line_height, @params[1] * 10 + $data_classes[@class_id].params[1, 1], 2)
  112.     word_wrap($data_actors[@class_id].description.delete("\n"), 210).each_with_index do |text, i|
  113.       draw_text(196, line_height * i + 31, contents_width, line_height, text)
  114.     end
  115.     (2...8).each do |param_id|
  116.       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)
  117.     end
  118.     change_color(system_color)
  119.     (0...8).each do |param_id|
  120.       # Largura suficiente para os termos não abreviados
  121.       draw_text(param_id / 4 * 193 + 47, param_id % 4 * 24 + 137, 100, line_height, "#{Vocab::param(param_id)}:")
  122.     end
  123.     if @points_bar
  124.       @points_bar.index = @points
  125.       @points_bar.text = "#{@points}/#{Configs::START_POINTS}"
  126.     end
  127.     @next_char.visible = @prev_char.visible = $data_classes[@class_id].graphics[@sex].size > 1
  128.   end
  129.  
  130.   def refresh_character
  131.     @character_name = $data_classes[@class_id].graphics[@sex][@sprite_index][0]
  132.     @character_index = $data_classes[@class_id].graphics[@sex][@sprite_index][1]
  133.   end
  134.  
  135.   def new_character
  136.     return unless @create_button.enable
  137.     if illegal_name? && $network.standard_group?
  138.       $windows[:alert].show(Vocab::InvalidName)
  139.     elsif invalid_name?
  140.       $windows[:alert].show(Vocab::ForbiddenCharacter)
  141.     else
  142.       $network.send_new_character(@actor_id, @name_box.text, @sprite_index, @class_id, @sex, @params, @points)
  143.     end
  144.   end
  145.  
  146.   def change_sex(sex)
  147.     @sex = sex
  148.     @sprite_index = 0
  149.     refresh_character
  150.     refresh
  151.   end
  152.  
  153.   def change_class
  154.     @class_id = @class_box.index + 1
  155.     @sprite_index = 0
  156.     refresh_character
  157.     refresh
  158.   end
  159.  
  160.   def next_character
  161.     @sprite_index = @sprite_index < $data_classes[@class_id].graphics[@sex].size - 1 ? @sprite_index + 1 : 0
  162.     refresh_character
  163.     refresh
  164.   end
  165.  
  166.   def prev_character
  167.     @sprite_index = @sprite_index > 0 ? @sprite_index - 1 : @sprite_index = $data_classes[@class_id].graphics[@sex].size - 1
  168.     refresh_character
  169.     refresh
  170.   end
  171.  
  172.   def add_param(param_id)
  173.     @points -= 1
  174.     @params[param_id] += 1
  175.     refresh
  176.     enable_buttons
  177.   end
  178.  
  179.   def remove_param(param_id)
  180.     @points += 1
  181.     @params[param_id] -= 1
  182.     refresh
  183.     enable_buttons
  184.   end
  185.  
  186.   def enable_buttons
  187.     @rem_hp.enable = @params[0] > 0
  188.     @rem_mp.enable = @params[1] > 0
  189.     @rem_atk.enable = @params[2] > 0
  190.     @remo_agi.enable = @params[3] > 0
  191.     @rem_def.enable = @params[4] > 0
  192.     @remo_mat.enable = @params[5] > 0
  193.     @rem_mdf.enable = @params[6] > 0
  194.     @rem_luk.enable = @params[7] > 0
  195.     enable = @points > 0
  196.     @add_hp.enable = enable
  197.     @add_mp.enable = enable
  198.     @add_atk.enable = enable
  199.     @add_agi.enable = enable
  200.     @add_def.enable = enable
  201.     @add_mat.enable = enable
  202.     @add_mdf.enable = enable
  203.     @add_luk.enable = enable
  204.   end
  205.  
  206.   def enable_create_button
  207.     @create_button.enable = @name_box.text.strip.size >= Configs::MIN_CHARACTERS
  208.   end
  209.  
  210.   def update
  211.     super
  212.     close_windows
  213.     ok if Input.trigger?(:C)
  214.   end
  215.  
  216.   def close_windows
  217.     return unless Input.trigger?(:B)
  218.     if $windows[:alert].visible || $windows[:config].visible
  219.       $windows[:alert].hide
  220.       $windows[:config].hide
  221.     else
  222.       hide
  223.     end
  224.   end
  225.  
  226.   def ok
  227.     $windows[:alert].visible ? $windows[:alert].hide : new_character
  228.   end
  229.  
  230. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement