Advertisement
marlosgama

Untitled

Aug 30th, 2019
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.23 KB | None | 0 0
  1. #==============================================================================
  2. # ** Window_Panel
  3. #------------------------------------------------------------------------------
  4. #  Esta classe lida com o painel de administração.
  5. #------------------------------------------------------------------------------
  6. #  Autor: Valentine
  7. #==============================================================================
  8.  
  9. class Window_Panel < Window_Base
  10.  
  11.   def initialize
  12.     super(adjust_x, adjust_y, 385, 302)
  13.     self.visible = false
  14.     self.closable = true
  15.     self.windowskin = Cache.system('Window2')
  16.     self.title = Vocab::AdmPanel
  17.     #load_maps
  18.     load_items
  19.     create_buttons
  20.     @item_type = 0
  21.     @x = @y = 0
  22.   end
  23.  
  24.   def adjust_x
  25.     Graphics.width / 2 - 192
  26.   end
  27.  
  28.   def adjust_y
  29.     Graphics.height / 2 - 176
  30.   end
  31. =begin
  32.   def load_maps
  33.     @map_ids = []
  34.     @map_names = []
  35.     $data_mapinfos.each do |map_id, map|
  36.       @map_ids << map_id
  37.       @map_names << map.name
  38.     end
  39.   end
  40. =end
  41.   def load_items
  42.     @items = []
  43.     @items << $data_items.drop(1).map { |item| item.name }
  44.     @items << $data_weapons.drop(1).map { |weapon| weapon.name }
  45.     @items << $data_armors.drop(1).map { |armor| armor.name }
  46.   end
  47.  
  48.   def create_buttons
  49.     @name_box = Text_Box.new(self, 53, 16, 163, Configs::MAX_CHARACTERS, false, Vocab::SecondaryPanelText)
  50.     @kick_button = Button.new(self, 15, 40, Vocab::Kick, 99) { kick_player }
  51.     @mute_button = Button.new(self, 118, 40, Vocab::Mute, 98) { mute_player }
  52.     @pull_button = Button.new(self, 15, 66, Vocab::Pull, 99) { pull_player }
  53.     @go_button = Button.new(self, 118, 66, Vocab::GoTo, 98) { go_to_player }
  54.     @motd_box = Text_Box.new(self, 15, 110, 145, 120)
  55.     @change_button = Button.new(self, 165, 109, Vocab::Change) { change_motd }
  56.     @days_box = Number_Box.new(self, 53, 152, 61, 5)
  57.     @unban_button = Button.new(self, 118, 151, Vocab::Unban, 98) { unban }
  58.     @ban_account = Button.new(self, 15, 177, Vocab::BanAcc, 98) { ban_account }
  59.     @ban_ip = Button.new(self, 118, 177, Vocab::BanIP, 98) { ban_ip }
  60.     @switch_box = Number_Box.new(self, 39, 222, 45, 4)
  61.     @switch_on = Button.new(self, 89, 221, Vocab::On, 51) { switch_on }
  62.     @switch_off = Button.new(self, 144, 221, Vocab::Off, 72) { switch_off }
  63.     @map_box = Number_Box.new(self, 272, 16, 98, 5)
  64.     #@map_box.text = $game_map.map_id.to_s
  65.     #@map_box = Combo_Box.new(self, 234, 16, 136, @map_names) { refresh }
  66.     @teleport_button = Button.new(self, 234, 150, Vocab::Teleport, 136) { teleport }
  67.     @prev_button = Image_Button.new(self, 271, 194, 'Left') { prev_item_type }
  68.     @next_button = Image_Button.new(self, 347, 194, 'Right') { next_item_type }
  69.     @amount_box = Number_Box.new(self, 314, 244, 56, 5)
  70.     @item_box = Number_Box.new(self, 258, 220, 112, 5)
  71.     #@item_box = Combo_Box.new(self, 234, 220, 136, @items[0])
  72.     @item_button = Button.new(self, 234, 268, Vocab::GiveItem, 136) { give_item }
  73.     @message_box = Text_Box.new(self, 15, 268, 138, 120)
  74.     @send_button = Button.new(self, 158, 267, Vocab::Send, 57) { admin_message }
  75.     disable_buttons
  76.   end
  77.  
  78.   def disable_buttons
  79.     return if $game_player.admin?
  80.     @kick_button.enable = false
  81.     @change_button.enable = false
  82.     @ban_account.enable = false
  83.     @ban_ip.enable = false
  84.     @unban_button.enable = false
  85.     @switch_on.enable = false
  86.     @switch_off.enable = false
  87.     #@map_box.enable = false
  88.     @teleport_button.enable = false
  89.     @prev_button.enable = false
  90.     @next_button.enable = false
  91.     #@item_box.enable = false
  92.     @item_button.enable = false
  93.     @send_button.enable = false
  94.   end
  95.  
  96.   def show
  97.     @name_box.clear
  98.     @motd_box.clear
  99.     @days_box.clear
  100.     @switch_box.clear
  101.     @map_box.clear
  102.     @amount_box.clear
  103.     @item_box.clear
  104.     @message_box.clear
  105.     #@map_box.index = $game_map.map_id - 1
  106.     @map_box.text = $game_map.map_id.to_s
  107.     super
  108.   end
  109.  
  110.   def refresh
  111.     contents.clear
  112.     change_color(system_color)
  113.     draw_text(3, 77, 205, line_height, Vocab::Motd, 1)
  114.     draw_text(3, 119, 205, line_height, Vocab::Banishment, 1)
  115.     draw_text(3, 189, 205, line_height, Vocab::GlobalSwitch, 1)
  116.     draw_text(222, 161, 136, line_height, "#{Vocab::Item}:", 1)
  117.     draw_text(3, 234, 205, line_height, Vocab::AlertMessage, 1)
  118.     change_color(normal_color)
  119.     draw_text(3, 4, 45, line_height, "#{Vocab::Name}:")
  120.     draw_text(3, 139, 200, line_height, "#{Vocab::Days}:")
  121.     draw_text(3, 207, 200, line_height, Vocab::ID)
  122.     draw_text(222, 4, 200, line_height, "#{Vocab::Map}:")
  123.     draw_text(222, 181, 136, line_height, Vocab::ItemType)
  124.     draw_text(222, 207, 136, line_height, Vocab::ID)
  125.     draw_text(222, 231, 136, line_height, "#{Vocab::Amount}:")
  126.     case @item_type
  127.     when 0
  128.       item_type = Vocab::Item
  129.     when 1
  130.       item_type = Vocab.weapon
  131.     when 2
  132.       item_type = Vocab.armor
  133.     when 3
  134.       item_type = Vocab.currency_unit
  135.     end
  136.     draw_text(276, 181, 60, line_height, item_type, 1)
  137.     draw_map
  138.     draw_player_point
  139.   end
  140.  
  141.   def draw_map
  142.     return unless FileTest.exist?("Graphics/Minimaps/#{@map_box.text}.png")
  143.     bitmap = Cache.minimap(@map_box.text)
  144.         contents.blt(222, 25, bitmap, bitmap.rect)
  145.   end
  146.  
  147.   def draw_player_point
  148.         rect = Rect.new(142, 0, 16, 16)
  149.     x = [[222 + @x, 222].max, 342].min
  150.     y = [[25 + @y, 25].max, 118].min
  151.     bitmap = Cache.system('Minimap')
  152.         contents.blt(x, y, bitmap, rect)
  153.   end
  154.  
  155.   def kick_player
  156.     return if @name_box.text.strip.empty?
  157.     $network.send_admin_command(Constants::COMMAND_KICK, @name_box.text)
  158.   end
  159.  
  160.   def mute_player
  161.     return if @name_box.text.strip.empty?
  162.     $network.send_admin_command(Constants::COMMAND_MUTE, @name_box.text)
  163.   end
  164.  
  165.   def pull_player
  166.     return if @name_box.text.strip.empty?
  167.     $network.send_admin_command(Constants::COMMAND_PULL, @name_box.text)
  168.   end
  169.  
  170.   def go_to_player
  171.     return if @name_box.text.strip.empty?
  172.     $network.send_admin_command(Constants::COMMAND_GO, @name_box.text)
  173.   end
  174.  
  175.   def change_motd
  176.     return if @motd_box.text.strip.empty?
  177.     $network.send_admin_command(Constants::COMMAND_MOTD, @motd_box.text)
  178.   end
  179.  
  180.   def ban_account
  181.     return if @name_box.text.strip.empty?
  182.     return if @days_box.value == 0
  183.     $network.send_admin_command(Constants::COMMAND_BAN_ACC, @name_box.text, @days_box.value)
  184.   end
  185.  
  186.   def ban_ip
  187.     return if @name_box.text.strip.empty?
  188.     return if @days_box.value == 0
  189.     $network.send_admin_command(Constants::COMMAND_BAN_IP, @name_box.text, @days_box.value)
  190.   end
  191.  
  192.   def unban
  193.     return if @name_box.text.strip.empty?
  194.     $network.send_admin_command(Constants::COMMAND_UNBAN, @name_box.text)
  195.   end
  196.  
  197.   def switch_on
  198.     return if @switch_box.value == 0
  199.     $network.send_admin_command(Constants::COMMAND_SWITCH, @switch_box.text, 1)
  200.   end
  201.  
  202.   def switch_off
  203.     return if @switch_box.value == 0
  204.     $network.send_admin_command(Constants::COMMAND_SWITCH, @switch_box.text, 0)
  205.   end
  206.  
  207.   def teleport
  208.     return if @name_box.text.strip.empty?
  209.     x = @x * $game_map.width / 136
  210.     y = @y * $game_map.height / 109
  211.     $network.send_admin_command(Constants::COMMAND_TELEPORT, @name_box.text, @map_box.text.to_i, x, y)
  212.   end
  213.  
  214.   def prev_item_type
  215.     return if @item_type == 0
  216.     @item_type -= 1
  217.     refresh_item_list
  218.   end
  219.  
  220.   def next_item_type
  221.     return if @item_type == 3
  222.     @item_type += 1
  223.     refresh_item_list
  224.   end
  225.  
  226.   def refresh_item_list
  227.     if @item_type < 3
  228.       @item_box.enable = true
  229.       #@item_box.list = @items[@item_type]
  230.       #@item_box.index = 0
  231.     else
  232.       @item_box.enable = false
  233.     end
  234.     refresh
  235.   end
  236.  
  237.   def give_item
  238.     return if @name_box.text.strip.empty?
  239.     return if @amount_box.value == 0
  240.     $network.send_admin_command(Constants::COMMAND_ITEM + @item_type, @name_box.text, @item_box.text.to_i + 1, @amount_box.value)
  241.   end
  242.  
  243.   def admin_message
  244.     return if @message_box.text.strip.empty?
  245.     $network.send_admin_command(Constants::COMMAND_MSG, @message_box.text)
  246.     @message_box.clear
  247.   end
  248.  
  249.   def update
  250.     super
  251.     if Mouse.click?(:L) && in_area?(234, 37, 136, 109)
  252.       @x = Mouse.x - x - 234
  253.       @y = Mouse.y - y - 37
  254.       refresh
  255.     end
  256.   end
  257.  
  258. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement