Guest User

Untitled

a guest
Jun 9th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 10.62 KB | None | 0 0
  1. #==============================================================================
  2. # ** Window_Item
  3. #------------------------------------------------------------------------------
  4. #  By Marlos Gama
  5. #==============================================================================
  6.  
  7. class Window_Item2 < Window_IconSelectable
  8.  
  9.   def initialize
  10.     super(100, 85, 192, 192)#(100, 85, 180, 196)
  11.     self.windowskin = RPG::Cache.windowskin("windteste2")
  12.     self.back_opacity = 220
  13.     @column_max = 5
  14.     refresh
  15.    
  16.     #@dragable  = true
  17.     #@scalable  = false
  18.     #@clickable = true
  19.     #@closable  = true
  20.    
  21.     self.index = 0
  22.     self.z = 99998
  23.     #-----
  24.     @scrollbar = Scroll_Bar33.new(self)
  25.   end
  26.  
  27.   def item
  28.     return @data[self.index]
  29.   end
  30.  
  31.   def refresh
  32.    
  33.      # Mostra a imagem de fundo
  34.     #fundo3 = RPG::Cache.picture("inv1")
  35.     #fundo1 = fundo3.width
  36.     #fundo2 = fundo3.height
  37.     #fundo4 = Rect.new(0,0,fundo1,fundo2)
  38.     #self.contents.blt(0,0,fundo3,fundo4)
  39.    
  40.     if self.contents != nil
  41.       self.contents.dispose
  42.       self.contents = nil
  43.     end
  44.     @data = []
  45.     for i in 1...$data_items.size
  46.       if $game_party.item_number(i) > 0
  47.         @data.push($data_items[i])
  48.       end
  49.     end
  50.     unless $game_temp.in_battle
  51.       for i in 1...$data_weapons.size
  52.         if $game_party.weapon_number(i) > 0
  53.           @data.push($data_weapons[i])
  54.         end
  55.       end
  56.       for i in 1...$data_armors.size
  57.         if $game_party.armor_number(i) > 0
  58.           @data.push($data_armors[i])
  59.         end
  60.       end
  61.     end
  62.     @item_max = @data.size
  63.     if @item_max > 0
  64.       self.contents = Bitmap.new(width - 32, row_max * 32)
  65.       for i in 0...@item_max
  66.         #return if i > 20
  67.         draw_item(i)
  68.       end
  69.     end
  70.   end
  71.  
  72.   def selecao
  73.     #-----
  74.     return if $pegando_item_trade   == true
  75.     return if $pegando_item         == true
  76.     return if $pegando_item_loja    == true
  77.     return if $desequipar_arma      == true
  78.     return if $desequipar_armadura  == true
  79.     return if $desequipar_escudo    == true
  80.     return if $desequipar_helmet    == true
  81.     return if $desequipar_acessorio == true
  82.     return if $desequipar_capa      == true
  83.     return if $desequipar_bota      == true
  84.     return if $desequipar_amuleto   == true
  85.     return if $desequipar_luva      == true
  86.     #-----
  87.     if not $pegando_item and $Mouse.x > self.x + 16 and $Mouse.x < (self.x + self.width)  - 16 and
  88.        $Mouse.y > self.y + 16 and $Mouse.y < (self.y + self.height) - 16
  89.        #-----
  90.        mx = (($Mouse.x + self.ox) - (self.x + 16)) / 32
  91.        my = (($Mouse.y + self.oy) - (self.y + 16)) / 32
  92.        #-----
  93.        self.index = mx + (my * @column_max)
  94.        self.index = -1 if self.index > @data.size
  95.     else
  96.       self.index = -1
  97.     end
  98.     #-----
  99.   end  
  100.  
  101.  
  102.   def click
  103.     if Input.pressed?(Input::Mouse_Left) and in_area?
  104.       return if $pegando_item_trade == true
  105.       return if $pegando_item_loja == true
  106.       return if $mouse_active == true
  107.       return if $desequipar_arma == true
  108.       return if $desequipar_armadura== true
  109.       return if $desequipar_escudo == true
  110.       return if $desequipar_helmet== true
  111.       return if $desequipar_acessorio == true
  112.       return if $desequipar_capa == true
  113.       return if $desequipar_bota == true
  114.       return if $desequipar_amuleto == true
  115.       return if $desequipar_luva == true
  116.       #-----
  117.       if not $pegando_item and $Mouse.x > self.x + 16 and $Mouse.x < (self.x + self.width)  - 16 and
  118.          $Mouse.y > self.y + 16 and $Mouse.y < (self.y + self.height) - 16
  119.          #-----
  120.          mx = (($Mouse.x + self.ox) - (self.x + 16)) / 32
  121.          my = (($Mouse.y + self.oy) - (self.y + 16)) / 32
  122.          #-----
  123.          self.index = mx + (my * @column_max)
  124.          self.index = -1 if self.index > @data.size
  125.       else
  126.         self.index = -1
  127.       end
  128.       return if self.index == -1
  129.       #-----
  130.       $pegando_item = true
  131.       item = @data[index]
  132.       return if item == nil  
  133.       $mouse_iconfor = item.icon_name
  134.       $game_temp.atualizar_mouse = true
  135.     end
  136.    
  137.     if Input.pressed?(Input::Mouse_Right)
  138.       if in_area?
  139.        
  140.     return if $mouse_active == true
  141.     $mouse_active = true
  142.     item = @data[index]
  143.     if item.is_a?(RPG::Item)
  144.      if $game_party.item_can_use?(item.id)
  145.       target = $game_party.actors[0]
  146.       used = target.item_effect(item)
  147.       $game_system.se_play(item.menu_se)
  148.       $game_player.animation_id = item.animation1_id
  149.       if item.consumable
  150.         $game_party.lose_item(item.id, 1)
  151.         if item.common_event_id > 0
  152.           $game_temp.common_event_id = item.common_event_id
  153.         end
  154.         refresh      
  155.         end
  156.       end
  157.     end      
  158.   else  
  159.       $help_w.visible = false
  160.       $help_w.active = false
  161.       end
  162.     end
  163.      
  164.   end
  165.  
  166. def use_item_1(item_carregado)
  167.   item = item_carregado#$data_items[1]
  168.   if item.is_a?(RPG::Item)
  169.    if $game_party.item_can_use?(item.id)
  170.     target = $game_party.actors[0]
  171.     used = target.item_effect(item)
  172.     $game_system.se_play(item.menu_se)
  173.     $game_player.animation_id = item.animation1_id
  174.     if item.consumable
  175.     $game_party.lose_item(item.id, 1)
  176.     refresh
  177.     end
  178.     end
  179.   end
  180. end
  181.  
  182. def use_item_2(item_carregado2)
  183.   item = item_carregado2#$data_items[1]
  184.   if item.is_a?(RPG::Item)
  185.    if $game_party.item_can_use?(item.id)
  186.     target = $game_party.actors[0]
  187.     used = target.item_effect(item)
  188.     $game_system.se_play(item.menu_se)
  189.     $game_player.animation_id = item.animation1_id
  190.     if item.consumable
  191.     $game_party.lose_item(item.id, 1)
  192.     refresh
  193.     end
  194.     end
  195.   end
  196. end
  197.  
  198. def use_item_3(item_carregado3)
  199.   item = item_carregado3#$data_items[1]
  200.   if item.is_a?(RPG::Item)
  201.    if $game_party.item_can_use?(item.id)
  202.     target = $game_party.actors[0]
  203.     used = target.item_effect(item)
  204.     $game_system.se_play(item.menu_se)
  205.     $game_player.animation_id = item.animation1_id
  206.     if item.consumable
  207.     $game_party.lose_item(item.id, 1)
  208.     refresh
  209.     end
  210.     end
  211.   end
  212. end
  213.  
  214. def use_item_4(item_carregado4)
  215.   item = item_carregado4#$data_items[1]
  216.   if item.is_a?(RPG::Item)
  217.    if $game_party.item_can_use?(item.id)
  218.     target = $game_party.actors[0]
  219.     used = target.item_effect(item)
  220.     $game_system.se_play(item.menu_se)
  221.     $game_player.animation_id = item.animation1_id
  222.     if item.consumable
  223.     $game_party.lose_item(item.id, 1)
  224.     refresh
  225.     end
  226.     end
  227.   end
  228. end
  229.  
  230.  
  231. def comprar_loja
  232.   if $loja == true
  233. if $pegando_item == true
  234. if !Input.pressed?(Input::Mouse_Left) and $loja_w.in_area?
  235.     $mouse_iconfor = "arrow"
  236.     $game_temp.atualizar_mouse = true
  237.     @item = $item_w.item
  238.     if @item.is_a?(RPG::Item)
  239.     return if @item.id == Item_Ouro::Item_Id.to_i
  240.     end
  241.     if @item == nil
  242.       return
  243.     end
  244.     case @item
  245.     when RPG::Item
  246.       @number = $game_party.item_number(@item.id)
  247.     when RPG::Weapon
  248.       @number = $game_party.weapon_number(@item.id)
  249.     when RPG::Armor
  250.       @number = $game_party.armor_number(@item.id)
  251.     end
  252.     return if @number < $amount
  253.     $game_party.gain_item(Item_Ouro::Item_Id.to_i,$amount * (@item.price/2))
  254.     $game_party.lose_item(Item_Ouro::Item_Id.to_i,$amount * @item.price/2)
  255.     $game_party.gain_gold($amount * (@item.price / 2))
  256.     #$game_system.se_play($data_system.shop_se)
  257.       case @item
  258.       when RPG::Item
  259.         $game_party.lose_item(@item.id, $amount)
  260.       when RPG::Weapon
  261.         $game_party.lose_weapon(@item.id, $amount)
  262.       when RPG::Armor
  263.         $game_party.lose_armor(@item.id, $amount)
  264.       end
  265.     $item_w.refresh
  266.     $loja_w.refresh
  267.     $janela_gold_w.refresh
  268.     $item_w.active = false
  269.     $pegando_item = false
  270. end
  271. end
  272. end
  273. end
  274.  
  275.  def voltar_mouse
  276.   if !Input.pressed?(Input::Mouse_Left)
  277.    $mouse_iconfor = "arrow"
  278.    $game_temp.atualizar_mouse = true
  279.    $pegando_item = false
  280.    $pegando_item_loja = false
  281.    $pegando_item_trade = false
  282.    $desequipar_arma = false
  283.    $desequipar_armadura = false
  284.    $desequipar_escudo = false
  285.    $desequipar_helmet = false
  286.    $desequipar_acessorio = false
  287.    $desequipar_capa = false
  288.    $desequipar_bota = false
  289.    $desequipar_amuleto = false
  290.    $desequipar_luva = false
  291.  end
  292. end
  293.  
  294.   def draw_item(index)
  295.     item = @data[index]
  296.     #return if index > 19
  297.     case item
  298.     when RPG::Item
  299.       number = $game_party.item_number(item.id)
  300.     when RPG::Weapon
  301.       number = $game_party.weapon_number(item.id)
  302.     when RPG::Armor
  303.       number = $game_party.armor_number(item.id)
  304.     end
  305.     #-----
  306.     x = index % @column_max * (width/@column_max - 6)
  307.     y = index / @column_max * 32
  308.     rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  309.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  310.     bitmap = RPG::Cache.icon(item.icon_name)
  311.     if item.is_a?(RPG::Item)
  312.     if item.id != Item_Ouro::Item_Id.to_i
  313.       opacity = 255
  314.       self.contents.font.color = normal_color
  315.     else
  316.       opacity = 128
  317.       self.contents.font.color = Color.new(128,128,128)
  318.     end
  319.     else
  320.     opacity = 255
  321.     self.contents.font.color = normal_color
  322.     end
  323.     #opacity = self.contents.font.color == normal_color ? 255 : 128#255
  324.     self.contents.blt(x, y + 2, bitmap, Rect.new(0, 0, 24, 24), opacity)
  325.     if item.id == 33    
  326.       if number < 1000
  327.         self.contents.draw_text(x - 6, y + 9, 34, 32, number.to_s, 2)
  328.       elsif number > 10000
  329.         self.contents.draw_text(x - 7, y + 9, 34, 32, number.to_s, 2)
  330.       elsif number == 10000
  331.         self.contents.draw_text(x - 7, y + 9, 34, 32, number.to_s, 2)
  332.       elsif number > 100000
  333.         self.contents.draw_text(x + 2, y + 9, 32, 32, number.to_s, 2)
  334.       elsif number == 100000
  335.         self.contents.draw_text(x + 2, y + 9, 32, 32, number.to_s, 2)
  336.       else
  337.         self.contents.draw_text(x - 4, y + 9, 34, 32, number.to_s, 2)
  338.       end
  339.     else
  340.       self.contents.draw_text(x + 2, y + 9, 24, 32, number.to_s, 2)
  341.     end
  342.   end
  343.   def visible=(v)
  344.     super(v) rescue nil
  345.     self.update
  346.   end
  347.   def x=(v)
  348.     super(v)
  349.     @scrollbar.update if @scrollbar
  350.   end
  351.   def y=(v)
  352.     super(v)
  353.     @scrollbar.update if @scrollbar
  354.   end
  355.   def update
  356.     super
  357.     if not $pegando_item and $Mouse.x > self.x + 16 and $Mouse.x < (self.x + self.width)  - 16 and
  358.        $Mouse.y > self.y + 16 and $Mouse.y < (self.y + self.height) - 16
  359.        #-----
  360.        mx = (($Mouse.x + self.ox) - (self.x + 16)) / 32
  361.        my = (($Mouse.y + self.oy) - (self.y + 16)) / 32
  362.        #-----
  363.        self.index = mx + (my * @column_max)
  364.        self.index = -1 if self.index > @data.size
  365.     else
  366.       self.index = -1
  367.     end
  368.   end
  369. end
Add Comment
Please, Sign In to add comment