Advertisement
Raizen

Lune Vault System

May 5th, 2014
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 28.66 KB | None | 0 0
  1. #=======================================================
  2. #         Lune Item Vault
  3. # Autor : Raizen
  4. # Comunidade: www.centrorpg.com
  5. # Função do script: O script adiciona um baú ou banco,
  6. # dependendo da preferência, que permite guardar itens,
  7. # depositar dinheiro, sacar itens e sacar o dinheiro guardado
  8. #=======================================================
  9.  
  10. # Explicações e Funções:
  11.  
  12. # Para Chamar a tela do script basta ir no
  13. # Chamar Script: SceneManager.call(Scene_Vault)
  14.  
  15. #==============================================================#
  16. #=========== GERENCIANDO OS ITENS DO BAÚ / BANCO ==============#
  17. #==============================================================#
  18.  
  19. # Para mudar um certo item do banco, remover, adicionar
  20. # Basta utilizar o Comando Chamar Script: com o seguinte.
  21.  
  22. # Chamar Script: Lune_Vault.change_item(n, item, type)
  23.  
  24. # Aonde n é a quantidade de itens, pode ter valor negativo
  25. # Aonde item é o ID do item no database.
  26. # Aonde type é o tipo de item que pretende adicionar ou remover.
  27. #     Seguindo o seguinte. 1 = itens, 2= armas, 3 = armaduras
  28. # Exemplo: Quero retirar 5 armas de ID 3 do database,
  29. # Chamar Script: Lune_Vault.change_item(-5, 3, 2)
  30.  
  31. #==============================================================#
  32. #=========== GERENCIANDO O DINHEIRO DO BAÚ/BANCO ==============#
  33. #==============================================================#
  34.  
  35. # Para mudar a quantidade de dinheiro que se tem no banco
  36. # Basta utilizar o Comando Chamar Script: com o seguinte.
  37.  
  38. # Chamar Script: Lune_Vault.gold(n)
  39. # Aonde n é a quantidade de gold que você irá adicionar ou remover,
  40. # lembrando que pode ser um número negativo.
  41. # Por exemplo, quero adicionar 500G no banco.
  42.  
  43. # Chamar Script: Lune_Vault.gold(500)
  44.  
  45. # Ideal para utilizar com sistemas que geram uma % ou taxas caso utilize
  46. # o script como banco, o valor total de dinheiro no banco está
  47. # salvo nessa variável.
  48. # $game_party.hold_money
  49. # Você pode igualar a uma variável e trabalhar com ela
  50.  
  51. #==============================================================#
  52. #===================== Configurações ==========================#
  53. #==============================================================#
  54. module Lune_Vault
  55. # Som que tocará ao depositar/sacar um item
  56. Sound_Item = "Decision2"
  57. # Som que tocará caso não tenha itens ou dinheiro suficiente
  58. Sound_Item2 = "Buzzer2"
  59.  
  60. #==========================================================================
  61. #==================== Configure aqui o vocabulário =======================#
  62. #==========================================================================
  63. # Frase que aparecerá na janela abaixo para indicar que
  64. # é para sacar os itens.
  65. Vault_text = "Está janela gerencia os itens a serem retirados"
  66. # Frase que aparecerá na janela abaixo para indicar que
  67. # é para depositar os itens.
  68. Vault_text2 = "Está janela gerencia os itens a serem depositados"
  69.  
  70. # Frase que aparecerá para indicar a quantidade carregada
  71. Gold_text = "Quantia carregada:"
  72. # Frase que aparecerá para indicar a quantidade que está no baú, ou no
  73. # banco.
  74. Gold_text2 = "Quantia no baú:"
  75. #==================
  76. # Nome dos comandos
  77. #==================
  78. # Saque em dinheiro
  79. Com1 = "Sacar"
  80. # Depósito em dinheiro
  81. Com2 = "Depositar"
  82. # Saque de itens
  83. Com3 = "Retirar Item"
  84. # Depósito de itens
  85. Com4 = "Guardar Item"
  86. # Sair
  87. Com5 = "Sair"
  88. #==============================================================================#
  89. #==============================================================================#
  90. #======================== A PARTIR DAQUI COMEÇA O SCRIPT ======================#
  91. #==============================================================================#
  92. #==============================================================================#
  93.  
  94.  
  95.  
  96.   def self.change_item(n, item, type)
  97.     case type
  98.     when 1  # Item
  99.       $game_party.gain_item_vault($data_items[item], n)
  100.     when 2  # Arma
  101.       $game_party.gain_item_vault($data_weapons[item], n)
  102.     when 3  # Armadura
  103.       $game_party.gain_item_vault($data_armors[item], n)
  104.     end
  105.   end
  106.   def self.gold(n)
  107.     $game_party.hold_money(n)
  108.   end
  109. end
  110.  
  111.  
  112.  
  113. #==============================================================================
  114. # ** Scene_Menu
  115. #------------------------------------------------------------------------------
  116. #  Esta classe executa o processamento da tela de menu.
  117. #==============================================================================
  118.  
  119. class Scene_Vault < Scene_MenuBase
  120.   #--------------------------------------------------------------------------
  121.   # * Inicialização do processo
  122.   #--------------------------------------------------------------------------
  123.   def start
  124.     Window_MenuCommand::init_command_position
  125.     super
  126.     create_help_window
  127.     create_category_window
  128.     create_item_window
  129.     create_command_window
  130.     @command_window.activate
  131.     @category_window.deactivate
  132.   end
  133.   #--------------------------------------------------------------------------
  134.   # * Criação da janela de ajuda.
  135.   #--------------------------------------------------------------------------
  136.   def create_help_window
  137.     unless $lune_weight_script
  138.       super
  139.     else
  140.       @help_window = Window_Weight_Help.new
  141.       @help_window.viewport = @viewport
  142.     end
  143.   end
  144.   def create_command_window
  145.     @command_window = Window_Create_Vault.new
  146.     @command_window.set_handler(:deposit, method(:deposit))
  147.     @command_window.set_handler(:draw, method(:draw))
  148.     @command_window.set_handler(:depoitem, method(:depoitem))
  149.     @command_window.set_handler(:drawitem, method(:drawitem))
  150.     @command_window.set_handler(:exit, method(:exit))
  151.     @command_window.viewport = @viewport
  152.     @command_window.open
  153.     @money_window = Window_NumberInput_Deposit.new(Window_Base.new(0,0,0,0))
  154.     @money_window.viewport = @viewport
  155.     @item_get_window = Window_Item_Deposit.new(Window_Base.new(0,0,0,0))
  156.     @item_get_window.viewport = @viewport
  157.   end
  158.   def update
  159.     super
  160.     if @item_window.active || @category_window.active || @item_get_window.active
  161.       @item_window.change_view ? @bank_window.refresh(1) : @bank_window.refresh(2)
  162.     else
  163.       @bank_window.refresh(0)
  164.     end
  165.     if Input.trigger?(:B)
  166.       SceneManager.goto(Scene_Map) if @command_window.active
  167.       if @money_window.open?
  168.         @command_window.activate
  169.         @money_window.close
  170.       end
  171.       if @item_get_window.open?
  172.         @item_window.activate
  173.         @item_get_window.close
  174.       end
  175.     end
  176.     change_itens(@item_get_window.nitens) if @item_get_window.nitens
  177.     @command_window.activate unless all_windows_down?
  178.   end
  179.   def all_windows_down?
  180.     @command_window.active || @category_window.active || @item_window.active || !@money_window.close? || !@item_get_window.close?
  181.   end
  182.   #--------------------------------------------------------------------------
  183.   # * Criação da janela de categorias
  184.   #--------------------------------------------------------------------------
  185.   def create_category_window
  186.     @bank_window = Window_Bank_System.new
  187.     @bank_window.viewport = @viewport
  188.     @category_window = Window_ItemCategory.new
  189.     @category_window.viewport = @viewport
  190.     @category_window.help_window = @help_window
  191.     @category_window.y = @help_window.height
  192.     @category_window.set_handler(:ok,     method(:on_category_ok))
  193.     @category_window.set_handler(:cancel, method(:on_select_choice))
  194.   end
  195.   #--------------------------------------------------------------------------
  196.   # * Criação da janela de itens
  197.   #--------------------------------------------------------------------------
  198.   def create_item_window
  199.     wy = @category_window.y + @category_window.height
  200.     wh = Graphics.height - wy - @bank_window.height
  201.     @item_window = Window_ItemList_Vault.new(0, wy, Graphics.width, wh)
  202.     @item_window.viewport = @viewport
  203.     @item_window.help_window = @help_window
  204.     @item_window.set_handler(:ok,     method(:on_item_ok))
  205.     @item_window.set_handler(:cancel, method(:on_item_cancel))
  206.     @item_window.get_pos(true)
  207.     @category_window.item_window = @item_window
  208.   end
  209.   def change_itens(n)
  210.     $game_party.gain_item(@item_window.item, n)
  211.     $game_party.gain_item_vault(@item_window.item, -n)
  212.     @item_get_window.nitens = nil
  213.     on_item_cancel
  214.     @item_window.refresh
  215.   end
  216.   #--------------------------------------------------------------------------
  217.   # * Categoria [Confirmação]
  218.   #--------------------------------------------------------------------------
  219.   def on_category_ok
  220.     @item_window.activate
  221.     @item_window.select_last
  222.   end
  223.   #--------------------------------------------------------------------------
  224.   # * Item [Confirmação]
  225.   #--------------------------------------------------------------------------
  226.   def on_item_ok
  227.     @item_get_window.start(false, @item_window.item)
  228.   end
  229.   #--------------------------------------------------------------------------
  230.   # * Item [Cancelamento]
  231.   #--------------------------------------------------------------------------
  232.   def on_item_cancel(t = nil)
  233.     @item_window.unselect
  234.     @item_window.get_pos(t)
  235.     @item_get_window.get_pos(t)
  236.     @category_window.activate
  237.     @command_window.close
  238.   end
  239.   def on_select_choice
  240.     @category_window.deactivate
  241.     @command_window.open
  242.     @command_window.activate
  243.   end
  244.   #--------------------------------------------------------------------------
  245.   # * Comando [Gerenciar GPs]
  246.   #--------------------------------------------------------------------------
  247.   def draw
  248.     on_money_get
  249.   end
  250.   def deposit
  251.     on_money_dep
  252.   end
  253.   def on_money_dep
  254.     @money_window.start(false)
  255.   end
  256.   def on_money_get
  257.     @money_window.start(true)
  258.   end
  259.   #--------------------------------------------------------------------------
  260.   # * Comando [Deposito de itens]
  261.   #--------------------------------------------------------------------------
  262.   def depoitem
  263.     @help_window.on_bau(true) if $lune_weight_script
  264.     on_item_cancel(false)
  265.   end
  266.   #--------------------------------------------------------------------------
  267.   # * Comando [Sacar Itens]
  268.   #--------------------------------------------------------------------------
  269.   def drawitem
  270.     @help_window.on_bau if $lune_weight_script
  271.     on_item_cancel(true)
  272.   end
  273.   #--------------------------------------------------------------------------
  274.   # * Comando [Fechar]
  275.   #--------------------------------------------------------------------------
  276.   def exit
  277.     return_scene
  278.   end
  279. end
  280.  
  281.  
  282. #==============================================================================
  283. # ** Window_MenuStatus
  284. #------------------------------------------------------------------------------
  285. #  Esta janela exibe os parâmetros dos membros do grupo na tela de menu.
  286. #==============================================================================
  287.  
  288. class Window_Create_Vault < Window_Command
  289. include Lune_Vault
  290.   #--------------------------------------------------------------------------
  291.   # * Inicialização do objeto
  292.   #--------------------------------------------------------------------------
  293.   def initialize
  294.     super(0, 0)
  295.     self.z = 9999
  296.     self.x = (Graphics.width / 2) - (window_width / 2)
  297.     self.y = Graphics.height / 2 - 80
  298.     self.openness = 0
  299.   end
  300.   #--------------------------------------------------------------------------
  301.   # * Aquisição da largura da janela
  302.   #--------------------------------------------------------------------------
  303.   def window_width
  304.     return 160
  305.   end
  306.   #--------------------------------------------------------------------------
  307.   # * Criação da lista de comandos
  308.   #--------------------------------------------------------------------------
  309.   def make_command_list
  310.     add_main_commands
  311.   end
  312.   #--------------------------------------------------------------------------
  313.   # * Adição dos comandos principais
  314.   #--------------------------------------------------------------------------
  315.   def add_main_commands
  316.     add_command(Com2,   :deposit,   true)
  317.     add_command(Com1,  :draw,  true)
  318.     add_command(Com4,  :depoitem,  true)
  319.     add_command(Com3,  :drawitem,  true)
  320.     add_command(Com5,  :exit,  true)
  321.   end
  322. end
  323.  
  324. #==============================================================================
  325. # ** Window_NumberInputInner
  326. #------------------------------------------------------------------------------
  327. #  Esta janela é utilizada para o comando de eventos [Armazenar Número]
  328. #==============================================================================
  329.  
  330. class Window_NumberInput_Deposit < Window_NumberInput
  331. attr_accessor :nitens
  332. def initialize(message_window)
  333.   @get_lost_itens = 0
  334.   super(message_window)
  335. end
  336.   #--------------------------------------------------------------------------
  337.   # * Inicialização do processo
  338.   #--------------------------------------------------------------------------
  339.   def start(cond)
  340.     @cond = cond
  341.     @digits_max = 8
  342.     @number = @get_lost_itens
  343.     @number = [[@number, 0].max, 10 ** @digits_max - 1].min
  344.     @index = 0
  345.     update_placement
  346.     create_contents
  347.     refresh
  348.     open
  349.     activate
  350.   end
  351.   #--------------------------------------------------------------------------
  352.   # * Atualização da posição da janela
  353.   #--------------------------------------------------------------------------
  354.   def update_placement
  355.     self.width = @digits_max * 20 + padding * 2
  356.     self.height = fitting_height(1)
  357.     self.x = (Graphics.width - width) / 2
  358.     self.y = Graphics.height/2 + height + 20
  359.     self.z = 150
  360.   end
  361.  
  362.   #--------------------------------------------------------------------------
  363.   # * Definição de resultado ao pressionar o botão de confirmação
  364.   #--------------------------------------------------------------------------
  365.   def process_ok
  366.     if @cond
  367.       number = $game_party.hold_money
  368.       if @number <= number
  369.         Sound.play_shop
  370.         make_draw
  371.       else
  372.         RPG::SE.new(Lune_Vault::Sound_Item2).play
  373.       end
  374.     else
  375.       number = $game_party.gold
  376.       if @number <= number
  377.         Sound.play_shop
  378.         make_deposit
  379.       else
  380.         RPG::SE.new(Lune_Vault::Sound_Item2).play
  381.       end
  382.     end
  383.     deactivate
  384.     close
  385.   end
  386.   def make_deposit
  387.     $game_party.hold_money(@number)
  388.     $game_party.gold -= @number
  389.   end
  390.   def make_draw
  391.     $game_party.hold_money(-@number)
  392.     $game_party.gold += @number
  393.   end
  394. end
  395.  
  396.  
  397.  
  398. #==============================================================================
  399. # ** Game_Party
  400. #------------------------------------------------------------------------------
  401. #  Esta classe gerencia o grupo. Contém informações sobre dinheiro, itens.
  402. # A instância desta classe é referenciada por $game_party.
  403. #==============================================================================
  404.  
  405. class Game_Party < Game_Unit
  406. alias :lune_vault_initialize :initialize
  407. attr_accessor :gold
  408. attr_accessor :hold_itens
  409.   def initialize
  410.     @hold_money = 0
  411.     @items_vault = {}
  412.     @weapons_vault = {}
  413.     @armors_vault = {}
  414.     lune_vault_initialize
  415.   end
  416.   #--------------------------------------------------------------------------
  417.   # * Acrescentar item (redução)
  418.   #     item          : item
  419.   #     amount        : quantia alterada
  420.   #     include_equip : incluir itens equipados
  421.   #--------------------------------------------------------------------------
  422.   def gain_item_vault(item, amount, include_equip = false)
  423.     container = item_container_vault(item.class)
  424.     return unless container
  425.     last_number = item_number_vault(item)
  426.     new_number = last_number + amount
  427.     container[item.id] = [[new_number, 0].max, max_item_number(item)].min
  428.     container.delete(item.id) if container[item.id] == 0
  429.     if include_equip && new_number < 0
  430.       discard_members_equip(item, -new_number)
  431.     end
  432.     $game_map.need_refresh = true
  433.   end
  434.   def hold_money(g = nil)
  435.     g == nil ? (return @hold_money) : (@hold_money += g)
  436.   end
  437.   def all_items_vault
  438.     items_vault + equip_items_vault
  439.   end
  440.   #--------------------------------------------------------------------------
  441.   # * Lista de itens do grupo
  442.   #--------------------------------------------------------------------------
  443.   def items_vault
  444.     @items_vault.keys.sort.collect {|id| $data_items[id] }
  445.   end
  446.   #--------------------------------------------------------------------------
  447.   # * Lista de armas do grupo
  448.   #--------------------------------------------------------------------------
  449.   def weapons_vault
  450.     @weapons_vault.keys.sort.collect {|id| $data_weapons[id] }
  451.   end
  452.   #--------------------------------------------------------------------------
  453.   # * Lista de armadures do grupo
  454.   #--------------------------------------------------------------------------
  455.   def armors_vault
  456.     @armors_vault.keys.sort.collect {|id| $data_armors[id] }
  457.   end
  458.   #--------------------------------------------------------------------------
  459.   # * Lista de equipamentos do grupo
  460.   #--------------------------------------------------------------------------
  461.   def equip_items_vault
  462.     weapons_vault + armors_vault
  463.   end
  464.   def item_number_vault(item)
  465.     container = item_container_vault(item.class)
  466.     container ? container[item.id] || 0 : 0
  467.   end
  468.   #--------------------------------------------------------------------------
  469.   # * Aquisição das informações da classe de determinado item
  470.   #     item_class : classe do item
  471.   #--------------------------------------------------------------------------
  472.   def item_container_vault(item_class)
  473.     return @items_vault   if item_class == RPG::Item
  474.     return @weapons_vault if item_class == RPG::Weapon
  475.     return @armors_vault  if item_class == RPG::Armor
  476.     return nil
  477.   end
  478.   def items_on_vault
  479.     @all_vault_items = 0
  480.     all_items_vault.each {|item| get_vault_weight(item)}
  481.     @all_vault_items
  482.   end
  483.   #--------------------------------------------------------------------------
  484.   # * Calculo do peso de um item no inventário
  485.   #--------------------------------------------------------------------------
  486.   def get_vault_weight(item)
  487.     if item.note =~ /<peso (.*)>/i
  488.       @all_vault_items += $1.to_i * item_number_vault(item)
  489.     else
  490.       @all_vault_items += Lune_Weight::Default * item_number_vault(item)
  491.     end
  492.   end
  493. end
  494.  
  495.  
  496. #==============================================================================
  497. # ** Window_Bank_System
  498. #------------------------------------------------------------------------------
  499. #  Esta janela exibe a quantia de dinheiro.
  500. #==============================================================================
  501.  
  502. class Window_Bank_System < Window_Base
  503. include Lune_Vault
  504.   #--------------------------------------------------------------------------
  505.   # * Inicialização do objeto
  506.   #--------------------------------------------------------------------------
  507.   def initialize
  508.     super(0, Graphics.height - fitting_height(2), window_width, fitting_height(2))
  509.     refresh(0)
  510.   end
  511.   #--------------------------------------------------------------------------
  512.   # * Aquisição da largura da janela
  513.   #--------------------------------------------------------------------------
  514.   def window_width
  515.     return Graphics.width
  516.   end
  517.   #--------------------------------------------------------------------------
  518.   # * Renovação
  519.   #--------------------------------------------------------------------------
  520.   def refresh(n)
  521.     contents.clear
  522.     case n
  523.     when 0
  524.       draw_text(window_width/10, 0, window_width / 2, line_height, Gold_text, 2 )
  525.       draw_currency_value(value, currency_unit, 4, 0, contents.width - 8)
  526.       draw_text(window_width/10, line_height, window_width / 2, line_height, Gold_text2, 2 )
  527.       draw_currency_value($game_party.hold_money, currency_unit, 4, line_height, contents.width - 8)
  528.     when 1
  529.       draw_text(0, 0, window_width, line_height*2, Vault_text, 0)
  530.     when 2
  531.       draw_text(0, 0, window_width, line_height*2, Vault_text2, 0)
  532.     end
  533.   end
  534.   #--------------------------------------------------------------------------
  535.   # * Aquisição do valor em dinheiro
  536.   #--------------------------------------------------------------------------
  537.   def value
  538.     $game_party.gold
  539.   end
  540.   #--------------------------------------------------------------------------
  541.   # * Aquisição da unidade monetária
  542.   #--------------------------------------------------------------------------
  543.   def currency_unit
  544.     Vocab::currency_unit
  545.   end
  546.   #--------------------------------------------------------------------------
  547.   # * Abertura da janela
  548.   #--------------------------------------------------------------------------
  549. end
  550.  
  551. #==============================================================================
  552. # ** Window_NumberInputInner
  553. #------------------------------------------------------------------------------
  554. #  Esta janela é utilizada para o comando de eventos [Armazenar Número]
  555. #==============================================================================
  556.  
  557. class Window_Item_Deposit < Window_NumberInput
  558. attr_accessor :nitens
  559. def initialize(message_window)
  560.   @get_lost_itens = 0
  561.   @nitens = nil
  562.   super(message_window)
  563. end
  564.   #--------------------------------------------------------------------------
  565.   # * Inicialização do processo
  566.   #--------------------------------------------------------------------------
  567.   def start(cond, item)
  568.     @digits_max = 2
  569.     @item = item
  570.     @number = @get_lost_itens
  571.     @number = [[@number, 0].max, 10 ** @digits_max - 1].min
  572.     @index = 0
  573.     update_placement
  574.     create_contents
  575.     refresh
  576.     open
  577.     activate
  578.   end
  579.   def get_pos(t)
  580.     @cond = t unless t == nil
  581.   end
  582.   #--------------------------------------------------------------------------
  583.   # * Atualização da posição da janela
  584.   #--------------------------------------------------------------------------
  585.   def update_placement
  586.     self.width = @digits_max * 20 + padding * 2
  587.     self.height = fitting_height(1)
  588.     self.x = (Graphics.width - width) / 2
  589.     self.y = Graphics.height/2 + height + 20
  590.     self.z = 150
  591.   end
  592.  
  593.   #--------------------------------------------------------------------------
  594.   # * Definição de resultado ao pressionar o botão de confirmação
  595.   #--------------------------------------------------------------------------
  596.   def process_ok
  597.     @nitens = 0
  598.     if @cond
  599.       make_draw
  600.     else
  601.       make_deposit
  602.     end
  603.     deactivate
  604.     close
  605.   end
  606.   def make_deposit
  607.     if @number <= $game_party.item_number(@item)
  608.       if $lune_weight_script
  609.         if Lune_Weight::LimiteB.is_a?(Integer)
  610.           if $game_party.carried_items + $game_party.calc_weight(@item, @number) > Lune_Weight::LimiteB
  611.             RPG::SE.new(Lune_Vault::Sound_Item2).play
  612.           else
  613.             @nitens = -@number
  614.             RPG::SE.new(Lune_Vault::Sound_Item).play
  615.           end
  616.         else
  617.           @nitens = -@number
  618.           RPG::SE.new(Lune_Vault::Sound_Item).play
  619.         end
  620.       else
  621.           @nitens = -@number
  622.           RPG::SE.new(Lune_Vault::Sound_Item).play
  623.       end
  624.     else
  625.       RPG::SE.new(Lune_Vault::Sound_Item2).play
  626.     end  
  627.   end
  628.   def make_draw
  629.     if @number <= $game_party.item_number_vault(@item)
  630.       if $lune_weight_script
  631.         if $game_party.carried_items + $game_party.calc_weight(@item, @number) > Lune_Weight.weight_limit
  632.           RPG::SE.new(Lune_Vault::Sound_Item2).play
  633.         else
  634.           @nitens = @number
  635.           RPG::SE.new(Lune_Vault::Sound_Item).play
  636.         end
  637.       else
  638.           @nitens = @number
  639.           RPG::SE.new(Lune_Vault::Sound_Item).play
  640.       end
  641.     else
  642.       RPG::SE.new(Lune_Vault::Sound_Item2).play
  643.     end
  644.   end
  645. end
  646.  
  647.  
  648. #==============================================================================
  649. # ** Window_ItemList
  650. #------------------------------------------------------------------------------
  651. #  Esta janela exibe a lista de itens possuidos na tela de itens.
  652. #==============================================================================
  653.  
  654. class Window_ItemList_Vault < Window_Selectable
  655. attr_reader :change_view
  656.   #--------------------------------------------------------------------------
  657.   # * Inicialização do objeto
  658.   #     x      : coordenada X
  659.   #     y      : coordenada Y
  660.   #     width  : largura
  661.   #     height : altura
  662.   #--------------------------------------------------------------------------
  663.   def initialize(x, y, width, height)
  664.     @change_view = false
  665.     super
  666.     @category = :none
  667.     @data = []
  668.   end
  669.   #--------------------------------------------------------------------------
  670.   # * Definição de categoria
  671.   #--------------------------------------------------------------------------
  672.   def category=(category)
  673.     return if @category == category
  674.     @category = category
  675.     refresh
  676.     self.oy = 0
  677.   end
  678.   #--------------------------------------------------------------------------
  679.   # * Aquisição do número de colunas
  680.   #--------------------------------------------------------------------------
  681.   def col_max
  682.     return 2
  683.   end
  684.   #--------------------------------------------------------------------------
  685.   # * Aquisição do número máximo de itens
  686.   #--------------------------------------------------------------------------
  687.   def item_max
  688.     @data ? @data.size : 1
  689.   end
  690.   #--------------------------------------------------------------------------
  691.   # * Aquisição das informações do item
  692.   #--------------------------------------------------------------------------
  693.   def item
  694.     @data && index >= 0 ? @data[index] : nil
  695.   end
  696.   #--------------------------------------------------------------------------
  697.   # * Definição de habilitação de seleção
  698.   #--------------------------------------------------------------------------
  699.   def current_item_enabled?
  700.     enable?(@data[index])
  701.   end
  702.   #--------------------------------------------------------------------------
  703.   # * Inclusão do item na lista
  704.   #     item : item
  705.   #--------------------------------------------------------------------------
  706.   def include?(item)
  707.     case @category
  708.     when :item
  709.       item.is_a?(RPG::Item) && !item.key_item?
  710.     when :weapon
  711.       item.is_a?(RPG::Weapon)
  712.     when :armor
  713.       item.is_a?(RPG::Armor)
  714.     when :key_item
  715.       item.is_a?(RPG::Item) && item.key_item?
  716.     else
  717.       false
  718.     end
  719.   end
  720.   #--------------------------------------------------------------------------
  721.   # * Definição de habilitação do item
  722.   #     item : item
  723.   #--------------------------------------------------------------------------
  724.   def enable?(item)
  725.     true
  726.   end
  727.   #--------------------------------------------------------------------------
  728.   # * Criação da lista de itens
  729.   #--------------------------------------------------------------------------
  730.   def make_item_list
  731.     if @change_view
  732.       @data = $game_party.all_items_vault.select {|item| include?(item) }
  733.     else
  734.       @data = $game_party.all_items.select {|item| include?(item) }
  735.     end
  736.     @data.push(nil) if include?(nil)
  737.   end
  738.   #--------------------------------------------------------------------------
  739.   # * Retorno à seleção anterior
  740.   #--------------------------------------------------------------------------
  741.   def select_last
  742.     select(@data.index($game_party.last_item.object) || 0)
  743.   end
  744.   #--------------------------------------------------------------------------
  745.   # * Desenho de um item
  746.   #     index : índice do item
  747.   #--------------------------------------------------------------------------
  748.   def draw_item(index)
  749.     item = @data[index]
  750.     if item
  751.       rect = item_rect(index)
  752.       rect.width -= 4
  753.       draw_item_name(item, rect.x, rect.y, enable?(item))
  754.       draw_item_number(rect, item)
  755.     end
  756.   end
  757.   def get_pos(t)
  758.     @change_view = t unless t == nil
  759.     refresh
  760.   end
  761.   #--------------------------------------------------------------------------
  762.   # * Desenho do número de itens possuido
  763.   #     rect : retângulo
  764.   #     item : item
  765.   #--------------------------------------------------------------------------
  766.   def draw_item_number(rect, item)
  767.     if @change_view
  768.       draw_text(rect, sprintf(":%2d", $game_party.item_number_vault(item)), 2)
  769.     else
  770.       draw_text(rect, sprintf(":%2d", $game_party.item_number(item)), 2)
  771.     end
  772.   end
  773.   #--------------------------------------------------------------------------
  774.   # * Atualização da janela de ajuda
  775.   #--------------------------------------------------------------------------
  776.   def update_help
  777.     @help_window.set_item(item)
  778.   end
  779.   #--------------------------------------------------------------------------
  780.   # * Renovação
  781.   #--------------------------------------------------------------------------
  782.   def refresh
  783.     make_item_list
  784.     create_contents
  785.     draw_all_items
  786.   end
  787. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement