Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================#
- # Grid Inventory Script v1.1 #
- #-------------------------------------------------------------------------------#
- # Feito por DarkSchneider (script original) e Gus (edit e conserto de bugs) #
- # ~~~ #
- # Agradecimentos especiais a Schwarz pelo draw_line e à Blizzard pelos #
- # gráficos do Diablo 1 usados nesta demo #
- #-------------------------------------------------------------------------------#
- # Descrição e instruções #
- # Este script muda o inventário, transformando ele em um grid. Foi inspirado #
- # em jogos como Diablo, Resident Evil e Deus Ex. Antes de colocar ele no seu #
- # jogo, CERTIFIQUE-SE DE QUE VOCÊ ADAPTOU SUA DATABASE. Todos os itens devem #
- # começar com o formato [#x#], com o primeiro número sendo a largura do item #
- # e o segundo número a altura. Cheque a database da demo se precisar de mais #
- # informações, e caso você tenha alguma dúvida ou pergunta sobre esse script #
- # mande um email para scripts.gus@gmail.com e eu tentarei te ajudar. #
- #===============================================================================#
- #===============================================================================#
- # Variáveis customizáveis e informações sobre elas
- #===============================================================================#
- module Grid_Variables
- # Largura do grid, em número de quadros
- GRID_WIDTH = 19
- # Altura do grid, em número de quadros
- GRID_HEIGHT = 12
- # Cor para o fundo dos itens (Vermelho, Verde, Azul, Opacidade)
- COLOR_ITEMS = Color.new(0,0,200,50)
- COLOR_WEAPONS = Color.new(200,0,0,50)
- COLOR_ARMORS = Color.new(0,200,0,50)
- # Itens importantes têm um preço de 0. Eles não podem ser vendidos, e se esta
- # variável for verdadeira, eles também não vão poder ser descartados.
- CAN_DROP_IMPORTANT_ITEMS = false
- # Ícones grandes precisam ser exatamente do tamanho do item no script, vezes
- # 32. Dê uma olhada na pasta de ícones se estiver com dúvidas
- USE_BIG_ICONS = true
- # Os ícones grandes precisam ter exatamente o mesmo nome do ícone do item, com
- # alguma coisa na frente do nome para identificação. O padrão é "grid.".
- # IMPORTANTE: Se não for usar os ícones grandes, mude o valor para ""
- BIG_ICONS_PREFIX = "grid."
- # A janela de mini ajuda é aquela janelinha que mostra o nome do item. Se o seu
- # grid não toma a janela inteira, você pode deixar esse valor "true'
- MINIHELP_CAN_BE_OUTSIDE_GRID = false
- # Essa imagem preferencialmente tem que ser 640x480 (ou a resolução que você)
- # está usando, já que assim você vai poder mudar as dimensões sem ter que editar
- # a imagem.
- GRID_BG_LOCATION = RPG::Cache.picture("gridbg")
- # Quando você substitui um item e depois aperta esc, ou não vai acontecer nada
- # (reproduzir SE de erro) ou ele vai ser colocado onde for possível. Se for
- # false ele vai permitir, true ele não fará nada
- ALLOW_ESC_REPLACING = false
- end
- #===============================================================================#
- # Main class, replaces the original Scene_Item
- #===============================================================================#
- class Scene_Item
- # The original script tried to use one inventory for each actor, but RPG Maker
- # doesn't supports that, so this is a workaround, easier than editing a lot of
- # code
- def initialize(actor_index = 0)
- @actor_index = actor_index
- end
- def main
- s1 = "Usar"
- s2 = "Mover"
- s3 = "Jogar"
- @command_window = Window_Command.new(96, [s1, s2 , s3])
- @command_window.active = false
- @command_window.visible = false
- @command_window.z = 120 # So the icons don't overlap the window
- @help_window = Window_Help.new
- @grid = Window_Grid.new(@actor_index)
- @grid.active = true
- @grid.set = 0
- @grid.mode = nil
- # Associate help window
- @grid.help_window = @help_window
- # Make target window (set to invisible / inactive)
- @target_window = Window_Target.new
- @target_window.visible = false
- @target_window.active = false
- # Make target window for equiping items on the grid
- @target_equip = Window_Target_Equip.new
- @target_equip.visible = false
- @target_equip.active = false
- # To avoid problems when moving items
- @moving_item = false
- @call_methods = ""
- # Execute transition
- Graphics.transition
- # Main loop
- loop do
- # Update game screen
- Graphics.update
- # Update input information
- Input.update
- # Frame update
- update
- # Abort loop if screen is changed
- if $scene != self
- break
- end
- end
- # Prepare for transition
- Graphics.freeze
- @cursor_icon.dispose if @cursor_icon != nil
- # Dispose of windows
- @command_window.dispose
- @help_window.dispose
- @target_window.dispose
- @target_equip.dispose
- @grid.dispose
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- # Update windows
- @command_window.update
- @help_window.update
- @target_window.update
- @target_equip.update
- @grid.update
- @grid.movingItemUpdate(@moving_item)
- if @command_window.active
- # Disabling drop option if item price is 0
- if !Grid_Variables::CAN_DROP_IMPORTANT_ITEMS
- if @grid.item.price == 0
- @command_window.disable_item(2)
- else
- @command_window.enable_item(2)
- end
- end
- # Disabling use option if item isn't usable
- if !$game_party.item_can_use?(@grid.item.id) && @grid.item.is_a?(RPG::Item)
- @command_window.disable_item(0)
- else
- @command_window.enable_item(0)
- end
- update_command
- return
- end
- @command_window.x = @grid.x + (@grid.cursor_rect.x + 16) + (@grid.cursor_rect.width)
- @command_window.y = @grid.y + (@grid.cursor_rect.y + 16) - (@command_window.height/ 2) + (@grid.cursor_rect.height / 2)
- @command_window.x = @grid.x + @grid.cursor_rect.x - @command_window.width + 16 if @grid.cursor_rect.x + @grid.cursor_rect.height >= ((Grid_Variables::GRID_WIDTH - 2)* 32)
- if @grid.active
- if Input.trigger?(Input::C) && @grid.item != nil && !@moving_item
- # Play decision SE
- $game_system.se_play($data_system.decision_se)
- @command_window.active = true
- @command_window.visible = true
- @grid.active = false
- end
- # If B button was pressed
- if Input.trigger?(Input::B) && !@moving_item
- # Play cancel SE
- $game_system.se_play($data_system.cancel_se)
- # Switch to menu screen
- $scene = Scene_Menu.new(0)
- return
- end
- # Some methods have to be called here on the update, so this does the job
- case @call_methods
- when "use"
- use_item
- when "cancel moving"
- @cursor_icon = Cursor_Icon.new if @cursor_icon == nil
- @cursor_icon.visible = false
- when "move2"
- @cursor_icon.update
- update_move2
- end
- end
- if @target_window.active
- update_target
- return
- elsif @target_equip.active
- update_target_equip
- return
- end
- end
- #--------------------------------------------------------------------------
- # * Command Window Update
- #--------------------------------------------------------------------------
- def update_command
- if Input.trigger?(Input::B)
- @command_window.active = false
- @command_window.visible = false
- @grid.active = true
- return
- end
- if Input.trigger?(Input::C)
- # Branch by command window cursor position
- case @command_window.index
- when 0 # use
- # Play decision SE
- $game_system.se_play($data_system.decision_se)
- @call_methods = "use"
- when 1 # move
- # Play equip SE
- $game_system.se_play($data_system.equip_se)
- @cursor_icon = Cursor_Icon.new if @cursor_icon == nil
- @cursor_icon.visible = false
- move_item
- when 2 # drop
- if @grid.item != nil
- if !Grid_Variables::CAN_DROP_IMPORTANT_ITEMS
- if @grid.item.price != 0
- # Play cancel SE
- $game_system.se_play($data_system.cancel_se)
- @grid.delete_item(true)
- else
- # Play buzzer SE
- $game_system.se_play($data_system.buzzer_se)
- end
- else
- @grid.delete_item(true)
- end
- end
- end
- @command_window.active = false
- @command_window.visible = false
- @grid.active = true
- return
- end
- end
- #--------------------------------------------------------------------------
- # * Frame Update (when item window is active)
- #--------------------------------------------------------------------------
- def use_item
- # Get currently selected data on the item window
- @item = @grid.item
- # If it's a weapon or armor
- if !@item.is_a?(RPG::Item)
- @grid.active = false
- @target_equip.x = @grid.x + @grid.cursor_rect.x + (@grid.cursor_rect.width / 2) >= 320 ? 0 : 304
- @target_equip.visible = true
- @target_equip.active = true
- @target_equip.index = 0
- for i in 0...$game_party.actors.size
- if $game_party.actors[i].equippable?(@item)
- @target_equip.enable_actor(i)
- else
- @target_equip.disable_actor(i)
- end
- end
- @target_equip.refresh
- else
- # If it can't be used
- unless $game_party.item_can_use?(@item.id)
- # Play buzzer SE
- $game_system.se_play($data_system.buzzer_se)
- @call_methods = ""
- return
- end
- # If effect scope is an ally
- if @item.scope >= 3
- # Activate target window
- @grid.active = false
- @target_window.x = @grid.x + @grid.cursor_rect.x + (@grid.cursor_rect.width / 2) >= 320 ? 0 : 304
- @target_window.visible = true
- @target_window.active = true
- # Set cursor position to effect scope (single / all)
- if @item.scope == 4 || @item.scope == 6
- @target_window.index = -1
- else
- @target_window.index = 0
- end
- # If effect scope is other than an ally
- else
- # If command event ID is valid
- if @item.common_event_id > 0
- # Command event call reservation
- $game_temp.common_event_id = @item.common_event_id
- # Play item use SE
- $game_system.se_play(@item.menu_se)
- # If consumable
- if @item.consumable
- # Decrease used items by 1
- $game_party.eraseDat(@item.id, "i", 1)
- # Draw item window item
- @grid.delete_item
- end
- # Switch to map screen
- $scene = Scene_Map.new
- return
- end
- end
- end
- @call_methods = ""
- return
- end
- #--------------------------------------------------------------------------
- # * Frame Update (when target window is active)
- #--------------------------------------------------------------------------
- def update_target
- # If B button was pressed
- if Input.trigger?(Input::B)
- # Play cancel SE
- $game_system.se_play($data_system.cancel_se)
- # If unable to use because items ran out
- unless $game_party.item_can_use?(@item.id)
- # Remake item window contents
- @grid.refresh
- end
- # Erase target window
- @grid.active = true
- @target_window.visible = false
- @target_window.active = false
- return
- end
- # If C button was pressed
- if Input.trigger?(Input::C)
- # If items are used up
- if @grid.item_del?
- # Play buzzer SE
- $game_system.se_play($data_system.buzzer_se)
- return
- end
- # If target is all
- if @target_window.index == -1
- # Apply item effects to entire party
- used = false
- for i in $game_party.actors
- used |= i.item_effect(@item)
- end
- end
- # If single target
- if @target_window.index >= 0
- # Apply item use effects to target actor
- target = $game_party.actors[@target_window.index]
- used = target.item_effect(@item)
- end
- # If an item was used
- if used
- # Play item use SE
- $game_system.se_play(@item.menu_se)
- # If consumable
- if @item.consumable
- @grid.delete_item(true)
- end
- # Remake target window contents
- @target_window.refresh
- # If all party members are dead
- if $game_party.all_dead?
- # Switch to game over screen
- $scene = Scene_Gameover.new
- return
- end
- # If common event ID is valid
- if @item.common_event_id > 0
- # Common event call reservation
- $game_temp.common_event_id = @item.common_event_id
- # Switch to map screen
- $scene = Scene_Map.new
- return
- end
- if Input.trigger?(Input::B)
- # Erase target window
- @grid.active = true
- @target_window.visible = false
- @target_window.active = false
- return
- end
- end
- # If item wasn't used
- unless used
- # Play buzzer SE
- $game_system.se_play($data_system.buzzer_se)
- end
- return
- end
- end
- #--------------------------------------------------------------------------
- # * Frame Update (when target equip window is active)
- #--------------------------------------------------------------------------
- def update_target_equip
- # If B button was pressed
- if Input.trigger?(Input::B)
- # Play cancel SE
- $game_system.se_play($data_system.cancel_se)
- # If unable to use because items ran out
- unless $game_party.item_can_use?(@item.id)
- # Remake item window contents
- @grid.refresh
- end
- # Erase target window
- @grid.active = true
- @target_equip.visible = false
- @target_equip.active = false
- return
- end
- # If C button was pressed
- if Input.trigger?(Input::C)
- actor = @target_equip.index
- if @target_equip.disabled?(actor)
- # Play buzzer SE
- $game_system.se_play($data_system.buzzer_se)
- return
- end
- if @item.is_a?(RPG::Weapon)
- equipped = $data_weapons[$game_party.actors[actor].weapon_id]
- type = "w"
- itemKind = 0
- elsif @item.is_a?(RPG::Armor)
- type = "a"
- itemKind = $data_armors[@item.id].kind + 1 # +1 because weapons are already at index 0
- case $data_armors[@item.id].kind
- when 0
- equipped = $data_armors[$game_party.actors[actor].armor1_id]
- when 1
- equipped = $data_armors[$game_party.actors[actor].armor2_id]
- when 2
- equipped = $data_armors[$game_party.actors[actor].armor3_id]
- when 3
- equipped = $data_armors[$game_party.actors[actor].armor4_id]
- end
- else
- equipped = nil
- end
- # Check to see if the equipped item and the select item are the same, if
- # so pretend to switch
- if equipped.id == @item.id
- # Play equip SE
- $game_system.se_play($data_system.equip_se)
- @grid.active = true
- @target_equip.visible = false
- @target_equip.active = false
- @call_methods = ""
- return
- end
- # if actor has an item equipped, we need a grid space verification
- if equipped != nil
- gridFull = @grid.checkWithoutDeleting(@item.id, type, equipped.id)
- end
- if !gridFull || equipped == nil
- # Play equip SE
- $game_system.se_play($data_system.equip_se)
- @grid.delete_item
- $game_party.actors[actor].grid_equip(itemKind, @item == nil ? 0 : @item.id)
- $game_party.eraseData(type, @item.id, 1)
- @grid.refresh
- @grid.active = true
- @target_equip.visible = false
- @target_equip.active = false
- @call_methods = ""
- return
- else
- # Play buzzer SE
- $game_system.se_play($data_system.buzzer_se)
- end
- if Input.trigger?(Input::B)
- # Play cancel SE
- $game_system.se_play($data_system.cancel_se)
- @call_methods = ""
- return
- end
- return
- end
- end
- #--------------------------------------------------------------------------
- # * Frame Update (when moving item)
- #--------------------------------------------------------------------------
- def move_item
- if @grid.item != nil
- @grid.get_item
- # Setting the bitmaps for the Cursor_Icon
- if Grid_Variables::USE_BIG_ICONS
- bitmap = Bitmap.new(@grid.itemWidth * 32, @grid.itemHeight * 32)
- x, y = 0, 0
- else
- bitmap = Bitmap.new(32,32)
- x, y = 4 + ((@grid.itemWidth * 32) / 2) - 16, 4 + ((@grid.itemHeight * 32) / 2) - 16
- end
- bitmap.blt(0,0,@grid.contents,Rect.new(@grid.cursor_rect.x + x,
- @grid.cursor_rect.y + y,@grid.cursor_rect.width,@grid.cursor_rect.height))
- @cursor_icon.refresh(bitmap, @grid.itemWidth, @grid.itemHeight)
- @grid.cursor_rect.width = @cursor_icon.bitmap.width
- @grid.cursor_rect.height = @cursor_icon.bitmap.height
- @cursor_icon.x = @grid.cursor_rect.x + @grid.x + 16
- @cursor_icon.y = @grid.cursor_rect.y + @grid.y + 16
- @cursor_icon.visible = true
- @grid.delete_item
- @moving_item = true
- @call_methods = "move2"
- end
- return
- end
- #--------------------------------------------------------------------------
- # * Frame Update (when replacing item)
- #--------------------------------------------------------------------------
- def replace_item
- @grid.updateItemSize
- @grid.get_item2
- @grid.delete_item_replace
- @grid.redraw_item("replace")
- @grid.transfer_get
- @grid.updateItemSizeFirstDraw(@grid.item_saved[0], @grid.item_saved[1])
- if @grid.item_saved[1] == "i" || @grid.item_saved[1] == "w" || @grid.item_saved[1] == "a"
- bitmap = RPG::Cache.icon(Grid_Variables::BIG_ICONS_PREFIX + @grid.item(@grid.item_saved[1], @grid.item_saved[0]).icon_name)
- else
- bitmap = Bitmap.new(@grid.itemWidth * 32, @grid.itemHeight * 32)
- end
- if Grid_Variables::USE_BIG_ICONS
- x, y = 0, 0
- else
- x, y = 4 + ((@grid.itemWidth * 32) / 2) - 16, 4 + ((@grid.itemHeight * 32) / 2) - 16
- end
- bitmap.blt(0,0,Bitmap.new(@grid.itemWidth * 32, @grid.itemHeight * 32),Rect.new(@grid.item_saved[2] + x,
- @grid.item_saved[3] + y,@grid.cursor_rect.width,@grid.cursor_rect.height))
- @cursor_icon.refresh(bitmap, @grid.itemWidth, @grid.itemHeight)
- @grid.cursor_rect.width = @cursor_icon.bitmap.width
- @grid.cursor_rect.height = @cursor_icon.bitmap.height
- @cursor_icon.x = @grid.cursor_rect.x + @grid.x + 16
- @cursor_icon.y = @grid.cursor_rect.y + @grid.y + 16
- @cursor_icon.visible = true
- @moving_item2 = true
- @call_methods = "move2"
- end
- #--------------------------------------------------------------------------
- # * Managing the Cursor_Icon and waiting for input
- #--------------------------------------------------------------------------
- def update_move2
- if Input.trigger?(Input::B)
- if !@moving_item2 # blocks esc if moving a replaced item
- # Play cancel SE
- $game_system.se_play($data_system.cancel_se)
- # Switch to menu screen
- @grid.redraw_item(false)
- #@grid.mode = 1
- @call_methods = "cancel moving"
- @moving_item = false
- return
- elsif @moving_item2 && !Grid_Variables::ALLOW_ESC_REPLACING
- $game_system.se_play($data_system.cancel_se)
- if !$game_party.isGridFull?(@grid.item_saved[0], @grid.item_saved[1])
- pos = $game_party.set_item(@grid.item_saved[0], @grid.item_saved[1], true)
- @grid.draw_item(@grid.item_saved[0], @grid.item_saved[1], pos[0] , pos[1])
- else
- $game_party.eraseData(@grid.item_saved[1], @grid.item_saved[0], 1)
- end
- @call_methods = "cancel moving"
- @moving_item = false
- @moving_item2 = false
- else
- $game_system.se_play($data_system.buzzer_se)
- end
- end
- @grid.cursor_rect.width = @cursor_icon.bitmap.width
- @grid.cursor_rect.height = @cursor_icon.bitmap.height
- @cursor_icon.x = @grid.cursor_rect.x + @grid.x + 16
- @cursor_icon.y = @grid.cursor_rect.y + @grid.y + 16
- if @grid.empty?
- @cursor_icon.blink_on
- @cursor_icon.tone.set(155,0,0,0)
- else
- @cursor_icon.blink_off
- @cursor_icon.tone.set(155,0,0,255)
- end
- if Input.trigger?(Input::C)
- empty = @grid.empty?
- if empty == true
- @grid.redraw_item
- @cursor_icon.visible = false
- # Play equip SE
- $game_system.se_play($data_system.equip_se)
- @call_methods = ""
- @moving_item = false
- @moving_item2 = false
- elsif empty == "replace"
- # Play equip SE
- $game_system.se_play($data_system.equip_se)
- @call_methods = ""
- replace_item
- else
- $game_system.se_play($data_system.buzzer_se)
- end
- return
- end
- end
- end
- #===============================================================================#
- # This edit removes the [#x#] from the item name, and passes it to $data_grid
- #===============================================================================#
- class Scene_Title
- alias old_main main
- def main
- old_main
- $data_grid = [], [], [] # index 0: items, 1: weapons, 2: armors
- # Looping three times, each time for a different item type
- for i in 0..2
- case i
- when 0
- type = $data_items
- when 1
- type = $data_weapons
- when 2
- type = $data_armors
- end
- # Editing the item name and adding the item size to the grid
- for j in 0..type.length - 1
- if type[j] != nil && type[j].name[0,1] == "["
- $data_grid[i][j] = type[j].name.match(/\[(.*)\]/)[1]
- type[j].name = type[j].name.gsub(/\[(.*)\]/, "").lstrip
- end
- end
- end
- end
- end
- #===============================================================================#
- # This edit is to avoid losing money when buying more itens than you can carry.
- # You will only be able to buy a number of items until your inventory is full,
- # and you will only be charged for those items.
- #===============================================================================#
- class Scene_Shop
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def buy_item(item, number)
- if !$game_party.isGridFull?(item.id, "", item)
- case item
- when RPG::Item
- amountBought = $game_party.gain_item(item.id, number)
- when RPG::Weapon
- amountBought = $game_party.gain_weapon(item.id, number)
- when RPG::Armor
- amountBought = $game_party.gain_armor(item.id, number)
- end
- if amountBought != nil
- number = amountBought - 1
- end
- $game_party.lose_gold(number * @item.price)
- $game_system.se_play($data_system.shop_se)
- else
- $game_system.se_play($data_system.buzzer_se)
- @buy_window.gridFull
- end
- end
- # Edit to use buy_item instead of the default way
- def update_number
- if Input.trigger?(Input::B)
- $game_system.se_play($data_system.cancel_se)
- @number_window.active = false
- @number_window.visible = false
- case @command_window.index
- when 0 # Buy
- @buy_window.active = true
- @buy_window.visible = true
- when 1 # Sell
- @sell_window.active = true
- @sell_window.visible = true
- @status_window.visible = false
- end
- return
- end
- if Input.trigger?(Input::C)
- @number_window.active = false
- @number_window.visible = false
- case @command_window.index
- when 0 # Buy
- buy_item(@item, @number_window.number)
- @gold_window.refresh
- @status_window.refresh
- @buy_window.active = true
- @buy_window.visible = true
- when 1 # Sell
- $game_system.se_play($data_system.shop_se)
- $game_party.gain_gold(@number_window.number * (@item.price / 2))
- case @item
- when RPG::Item
- $game_party.lose_item(@item.id, @number_window.number)
- when RPG::Weapon
- $game_party.lose_weapon(@item.id, @number_window.number)
- when RPG::Armor
- $game_party.lose_armor(@item.id, @number_window.number)
- end
- @gold_window.refresh
- @sell_window.refresh
- @status_window.refresh
- @sell_window.active = true
- @sell_window.visible = true
- @status_window.visible = false
- end
- return
- end
- end
- end
- #===============================================================================#
- # This edit is to show "Inventory is full!" on the shop help window
- #===============================================================================#
- class Window_ShopBuy < Window_Selectable
- def update_help
- # Removing the message if player presses up or down
- if @gridIsFull
- if Input.trigger?(Input::UP) || Input.trigger?(Input::DOWN)
- @gridIsFull = false
- end
- end
- @help_window.set_text(self.item == nil ? "" : self.item.description)
- @help_window.set_text("Inventário está cheio!") if @gridIsFull
- end
- # Setting this for remote access later
- def gridFull
- @gridIsFull = true
- end
- end
- #===============================================================================#
- # This edit is to show "Inventory is full!" on the equip help window
- #===============================================================================#
- class Scene_Equip
- def update_item
- # Se o botão B for pressionado
- if Input.trigger?(Input::B)
- # Reproduzir SE de cancelamento
- $game_system.se_play($data_system.cancel_se)
- # Ativar janela da direita
- @right_window.active = true
- @item_window.active = false
- @item_window.index = -1
- return
- end
- # Se o botão C for pressionado
- if Input.trigger?(Input::C)
- # Reproduzir SE de Equipamento
- $game_system.se_play($data_system.equip_se)
- # Selecionar dados escolhidos na janela de Item
- item = @item_window.item
- # Mudar Equipamento
- equip = @actor.equip(@right_window.index, item == nil ? 0 : item.id)
- @right_window.gridFull if equip == nil
- # Ativar janela da direita
- @right_window.active = true
- @item_window.active = false
- @item_window.index = -1
- # Recriar os conteúdos da janela de Itens e da direita
- @right_window.refresh
- @item_window.refresh
- return
- end
- end
- end
- #===============================================================================#
- # Same as above
- #===============================================================================#
- class Window_EquipRight < Window_Selectable
- def update_help
- if @gridIsFull
- if Input.trigger?(Input::UP) || Input.trigger?(Input::DOWN)
- @gridIsFull = false
- end
- end
- @help_window.set_text(self.item == nil ? "" : self.item.description)
- @help_window.set_text("Inventário está cheio!") if @gridIsFull
- end
- def gridFull
- @gridIsFull = true
- end
- end
- #===============================================================================#
- # This is an edit to enable a command window item after it has been disabled. As
- # far as I know there is no default way to do this.
- #===============================================================================#
- class Window_Command < Window_Selectable
- def enable_item(index)
- draw_item(index, normal_color)
- end
- end
- #===============================================================================#
- # This edit changes the behavior of Window_Selectable if the grid is active
- #===============================================================================#
- class Window_Selectable < Window_Base
- alias old_initialize initialize
- def initialize(x, y, width, height)
- old_initialize(x, y, width, height)
- if self.is_a?(Window_Grid)
- @x = 0
- @y = 0
- end
- end
- alias old_update update
- def update
- if !self.is_a?(Window_Grid)
- old_update
- return
- end
- super
- item = $game_party.actors[@actor_index].item_grid
- # If cursor is movable
- if self.active and @x >= 0
- # Using special directional commands if the user is moving an item. Without
- # this sometimes you might get crashes when moving items, since the script
- # can "teleport" your cursor to a coordinate that doesn't exists.
- if self.movingItem?
- if Input.repeat?(Input::DOWN)
- if @y == item.size - @itemHeight
- @y = 0
- else
- @y += 1
- end
- $game_system.se_play($data_system.cursor_se)
- end
- if Input.repeat?(Input::UP)
- if @y == 0
- @y = item.size - @itemHeight
- else
- @y -= 1
- end
- $game_system.se_play($data_system.cursor_se)
- end
- if Input.repeat?(Input::RIGHT)
- if @x == item[@y].size - @itemWidth
- @x = 0
- else
- @x += 1
- end
- $game_system.se_play($data_system.cursor_se)
- end
- if Input.repeat?(Input::LEFT)
- if @x == 0
- @x = item[@y].size - @itemWidth
- else
- @x -= 1
- end
- $game_system.se_play($data_system.cursor_se)
- end
- else
- # This makes the cursor select the entire item, no matter which slot it
- # is in
- if item[@y][@x][1][0,1] == "["
- itemSplit = item[@y][@x][1].gsub(/[\[\]]/, "").split('x')
- iH = itemSplit[0].to_i
- iW = itemSplit[1].to_i
- @x -= iW
- @y -= iH
- end
- if Input.repeat?(Input::DOWN)
- # if @y is at the last tile or above an item that is covering the last
- # tile (and this item exists)
- if @y == item.size - 1 || (@y == item.size - @itemHeight && item[@y][@x][1] != "")
- @y = 0
- else
- @y += item[@y][@x][1] != "" ? @itemHeight : 1 #if the current slot is an item, add the item height, else add 1
- end
- $game_system.se_play($data_system.cursor_se)
- end
- if Input.repeat?(Input::UP)
- # since whenever the item is selected the @y goes to the top tile,
- # there's no need for special checks
- if @y == 0
- @y = item.size - 1
- else
- @y -= 1
- end
- $game_system.se_play($data_system.cursor_se)
- end
- if Input.repeat?(Input::RIGHT)
- # if @x is at the last tile or above an item that is covering the last
- # tile (and this item exists)
- if @x == item[@y].size - 1 || (@x == item[@y].size - @itemWidth && item[@y][@x][1] != "")
- @x = 0
- else
- @x += item[@y][@x][1] != "" ? @itemWidth : 1 #if the current slot is an item, add the item height, else add 1
- end
- $game_system.se_play($data_system.cursor_se)
- end
- if Input.repeat?(Input::LEFT)
- # since whenever the item is selected the @x goes to the top-left tile,
- # there's no need for special checks
- if @x == 0
- @x = item[@y].size - 1
- else
- @x -= 1
- end
- $game_system.se_play($data_system.cursor_se)
- end
- end
- end
- # Update help text (update_help is defined by the subclasses)
- if self.active and @help_window != nil
- update_help
- end
- # Update cursor rectangle
- update_cursor_rect
- end
- def hide_cursor
- self.cursor_rect.empty
- end
- end
- #===============================================================================#
- # The main grid window
- #===============================================================================#
- class Window_Grid < Window_Selectable
- attr_accessor :mode
- attr_reader :itemWidth
- attr_reader :itemHeight
- attr_reader :item_saved
- attr_reader :item_saved2
- def initialize(actor_index)
- # This will center the grid. Feel free to edit it if you don't want that
- super((640/2)-(((Grid_Variables::GRID_WIDTH * 32) + 32) / 2), # x
- 32 + (480 / 2) - (((Grid_Variables::GRID_HEIGHT * 32) + 32) / 2), # y
- (Grid_Variables::GRID_WIDTH * 32)+33, # width
- (Grid_Variables::GRID_HEIGHT * 32)+33) # height
- self.contents = Bitmap.new(width - 32, height - 32)
- self.opacity = 0
- # This window does nothing, it's there just to replace the otherwise black
- # background.
- @dummy_window = Window_Base.new(0, 64, 640, 480 - 64)
- @dummy_window.z = 0
- @window = Window_Base.new(x , y , width, height)
- @window.contents = Bitmap.new(width - 32, height - 32)
- @window.z = self.z - 4
- @window.opacity = 0
- @grid_color = Sprite.new
- @grid_color.bitmap = Bitmap.new(width - 32, height - 32)
- @grid_color.x = self.x + 16
- @grid_color.y = self.y + 16
- @grid_color.z = @window.z + 2
- @actor_index = actor_index
- @mode = 0
- @mini_help = Mini_Help.new
- self.set = -1
- n = self.contents.width / 32
- m = self.contents.height / 32
- @column_max = n
- draw_grid
- @itemWidth = 1
- @itemHeight = 1
- @movingItem = false
- refresh
- end
- def draw_grid
- gridHeight = Grid_Variables::GRID_HEIGHT * 32
- gridWidth = Grid_Variables::GRID_WIDTH * 32
- # Creates the window bg
- @window.contents.blt(0, 0, Grid_Variables::GRID_BG_LOCATION, Rect.new(0, 0, gridWidth, gridHeight))
- i = 0
- color = Color.new(150,150,150)
- while i <= gridHeight
- draw_line(-1, i, gridWidth + 1, i, color)
- i += 32
- end
- i = 0
- while i <= gridWidth
- draw_line(i, 0, i, gridHeight, color)
- i += 32
- end
- end
- def draw_line(sx, sy, ex, ey, color)
- rad = Math.atan2(ey-sy, ex-sx)
- dx = Math.cos(rad)
- dy = Math.sin(rad)
- while (sx - ex).abs > 1 || (sy - ey).abs > 1
- sx += dx
- sy += dy
- @window.contents.set_pixel(sx, sy, color)
- end
- end
- def refresh
- @item_max = 0
- item = $game_party.actors[@actor_index].item_grid
- for i in 0..item.size - 1
- for j in 0..item[i].size - 1
- if item[i][j][0] == 0 and (item[i][j][1] == "i" or item[i][j][1] == "w" or item[i][j][1] == "a")
- @item_max += 1
- end
- end
- end
- for i in 0..item.size - 1
- for j in 0..item[i].size - 1
- draw_item(item[i][j][0], item[i][j][1], i , j)
- end
- end
- end
- # Updates the @movingItem variable. Mostly used on remote access
- def movingItemUpdate(moving_item)
- @movingItem = moving_item
- end
- # Returns true or false, depending on @movingItem. Mostly used on remote access
- def movingItem?
- movingItemUpdate(@movingItem)
- return @movingItem
- end
- def update_cursor_rect
- # @x is the cursor's x
- if @x < 0
- self.cursor_rect.empty
- return
- end
- # Assign the parameters in the item's name to the cursor
- if item != nil
- updateItemSize if !@movingItem
- cursor_width = @itemWidth * 32
- cursor_height = @itemHeight * 32
- else
- # Default values in case the item name has no parameters
- case $game_party.actors[@actor_index].item_grid[@y][@x][1]
- when "i" # Item, uses 1x1
- cursor_width = 32
- cursor_height = 32
- when "w" # Weapon, uses 1x3
- cursor_width = 32
- cursor_height = 96
- when "a" # Armor, uses 2x3
- cursor_width = 64
- cursor_height = 96
- else
- cursor_width = 32
- cursor_height = 32
- end
- end
- # Calculate cursor coordinates
- x = @x * 32
- y = @y * 32
- # Update cursor rectangle
- self.cursor_rect.set(x, y, cursor_width, cursor_height)
- end
- # Deletes the item from the grid. If removeData is true, also removes the item
- # from inventory.
- def delete_item(removeData = false)
- type = $game_party.actors[@actor_index].item_grid[@y][@x][1]
- item_id = $game_party.actors[@actor_index].item_grid[@y][@x][0]
- if type != "" || type[0,1] != "["
- iH, iW = 0, 0
- @grid_color.bitmap.fill_rect(@x*32+1, @y*32+1, (@itemWidth * 32) - 1, (@itemHeight * 32) - 1, Color.new(0,0,0,0))
- self.contents.fill_rect(@x*32, @y*32, @itemWidth*32, @itemHeight*32, Color.new(0,0,0,0))
- for iH in 0...@itemHeight.to_i
- for iW in 0...@itemWidth.to_i
- $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][0] = 0
- $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][1] = ""
- #iW = 0
- end
- end
- end
- if removeData
- $game_party.eraseData(type, item_id, 1)
- end
- end
- # This is a special delete_item, using the @item_saved array as parameters
- def delete_item_replace
- item_id = @item_saved2[0]
- type = @item_saved2[1]
- itemX = @item_saved2[2]
- itemY = @item_saved2[3]
- if type != ""
- updateItemSizeFirstDraw(item_id, type)
- @grid_color.bitmap.fill_rect((itemX)*32+1, (itemY)*32+1, (@itemWidth * 32) - 1, (@itemHeight * 32) - 1, Color.new(0,0,0,0))
- self.contents.fill_rect((itemX)*32, (itemY)*32, @itemWidth*32, @itemHeight*32, Color.new(0,0,0,0))
- for iH in 0...@itemHeight.to_i
- for iW in 0...@itemWidth.to_i
- $game_party.actors[@actor_index].item_grid[itemY + iH][itemX + iW][0] = 0
- $game_party.actors[@actor_index].item_grid[itemY + iH][itemX + iW][1] = ""
- end
- end
- end
- end
- # This iis a method for the grid equip feature. It "pretends" to delete the
- # item to see if there is enough space to unequip the equipped item.
- def checkWithoutDeleting(item_id, type, equip_id)
- for iH in 0...@itemHeight.to_i
- for iW in 0...@itemWidth.to_i
- $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][0] = 0
- $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][1] = ""
- end
- end
- flag = $game_party.isGridFull?(equip_id, type)
- for iH in 0...@itemHeight.to_i
- for iW in 0...@itemWidth.to_i
- if iH == 0 && iW == 0
- $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][0] = item_id
- $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][1] = type
- else
- $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][0] = item_id
- $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][1] = "[#{iH}x#{iW}]"
- end
- end
- end
- return flag
- end
- # Updating the @itemWidth and @itemHeight variables
- def updateItemSize
- if item != nil && itemSize != nil
- gridValues = itemSize.split('x')
- @itemWidth = gridValues[0].to_i
- @itemHeight = gridValues[1].to_i
- else
- @itemWidth = 0
- @itemHeight = 0
- end
- end
- # Manually updating the @itemWidth and @itemHeight variables.
- def updateItemSizeFirstDraw(item_id, type)
- item = itemSize(item_id, type)
- if item != nil
- gridValues = item.split('x')
- @itemWidth = gridValues[0].to_i
- @itemHeight = gridValues[1].to_i
- end
- end
- # Checking the item type and returning the correct $data
- def item(type = nil, id = nil)
- if type == nil && id == nil
- id = $game_party.actors[@actor_index].item_grid[@y][@x][0]
- type = $game_party.actors[@actor_index].item_grid[@y][@x][1]
- end
- case type
- when "i"
- return $data_items[id]
- when "w"
- return $data_weapons[id]
- when "a"
- return $data_armors[id]
- else
- return nil
- end
- end
- # Returns the item size from the $data_grid variables
- def itemSize(id = nil, type = nil)
- if type == nil && id == nil
- id = $game_party.actors[@actor_index].item_grid[@y][@x][0]
- type = $game_party.actors[@actor_index].item_grid[@y][@x][1]
- end
- case type
- when "i"
- return $data_grid[0][id]
- when "w"
- return $data_grid[1][id]
- when "a"
- return $data_grid[2][id]
- else return nil
- end
- end
- # Checking if the item is unusable or not, I guess. This was here on the
- # original script
- def item_del?
- if $game_party.actors[@actor_index].item_grid[@y][@x][0] == 0
- # Unusable
- return true
- else
- return false
- end
- end
- def dispose
- super
- @window.dispose
- @dummy_window.dispose
- @grid_color.dispose
- @mini_help.dispose
- end
- # Updating the help window (with item description) and the mini_help (with
- # item name)
- def update_help
- @mini_help.contents.font.color = (($game_party.item_can_use?(item.id) || !item.is_a?(RPG::Item))? normal_color : disabled_color)
- @help_window.set_text((item == nil || movingItem? == true) ? "" : item.description)
- @mini_help.set_text(item == nil ? "" : item.name)
- @mini_help.visible = false if item == nil || movingItem?
- @mini_help.x = self.x + (self.cursor_rect.x + 16) - (@mini_help.width / 2) + (self.cursor_rect.width / 2)
- @mini_help.y = self.y + (self.cursor_rect.y + 16) + (self.cursor_rect.height)
- if !Grid_Variables::MINIHELP_CAN_BE_OUTSIDE_GRID
- @mini_help.x += (@mini_help.x - self.x - 16) * -1 if @mini_help.x < self.x + 16 # -16 to make it look good even if you hide the windowskin
- @mini_help.x -= (@mini_help.x + @mini_help.width) - (self.x + self.width - 16) if @mini_help.x + @mini_help.width >= self.x + self.width - 16
- @mini_help.y -= self.cursor_rect.height + @mini_help.height - 1 if @mini_help.y + @mini_help.height >= self.y + self.height - 16
- end
- end
- # Stores the item data on an array, and keeps them safe while moving the item.
- def get_item
- @item_saved = [$game_party.actors[@actor_index].item_grid[@y][@x][0],
- $game_party.actors[@actor_index].item_grid[@y][@x][1], @x, @y]
- end
- # Same thing as above, but with some added precautions to make sure it gets
- # the right @x and @y. Used for the replace item method.
- def get_item2
- updateItemSizeFirstDraw(@item_saved[0], @item_saved[1])
- iH, iW = 0, 0
- if $game_party.actors[@actor_index].item_grid[@y][@x][0] == 0
- for iW in 0...@itemWidth.to_i
- for iH in 0...@itemHeight.to_i
- if $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][0] != 0
- break
- end
- end
- break if $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][0] != 0
- end
- end
- if $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][1][0,1] == "["
- itemSplit = $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][1].gsub(/[\[\]]/, "").split('x')
- minusH = itemSplit[0].to_i
- minusW = itemSplit[1].to_i
- else
- minusH = 0
- minusW = 0
- end
- item_id = $game_party.actors[@actor_index].item_grid[@y + iH - minusH][@x + iW - minusW][0]
- type = $game_party.actors[@actor_index].item_grid[@y + iH - minusH][@x + iW - minusW][1]
- @item_saved2 = [item_id, type, @x + iW - minusW, @y + iH - minusH]
- end
- # Clears the @item_saved and transfers the data on @item_saved2 to it
- def transfer_get
- @item_saved = []
- @item_saved2.each{|i| @item_saved.push(i)}
- end
- # Redrawing used for moving items. Using @item_saved parameters if moving was
- # canceled (f = false)
- def redraw_item(f = true)
- if f
- x = 4 + (@x * 32)
- y = @y * 32
- else # the moving has been canceled
- x = 4 + (@item_saved[2] * 32)
- y = @item_saved[3] * 32
- tx = @x
- ty = @y
- @x = @item_saved[2]
- @y = @item_saved[3]
- end
- draw_item(@item_saved[0], @item_saved[1], @y, @x)
- for iH in 0...@itemHeight.to_i
- for iW in 0...@itemWidth.to_i
- if iH == 0 && iW == 0
- $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][0] = @item_saved[0]
- $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][1] = @item_saved[1]
- else
- $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][0] = @item_saved[0]
- $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][1] = "[#{iH}x#{iW}]"
- end
- end
- end
- # Making the cursor go to the replaced item
- if f == "replace"
- @x = @item_saved2[2]
- @y = @item_saved2[3]
- end
- # Uncomment these lines if you don't want the cursor to go back with the
- # item when the player cancels moving.
- #@x = tx if @x != tx and tx != nil
- #@y = ty if @y != ty and ty != nil
- end
- # Checks if the cursor area is empty, and if there is more than one item on it
- def empty?
- n = 0
- arr = []
- for iH in 0...@itemHeight.to_i
- for iW in 0...@itemWidth.to_i
- type = $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][1]
- id = $game_party.actors[@actor_index].item_grid[@y + iH][@x + iW][0]
- cond = (type == "")
- replaceable = true if !cond
- if !cond && (type == "i" || type == "w" || type == "a") && arr[n-1] != "#{@y + iH},#{@x + iW}"
- n += 1
- arr.push("#{@y + iH},#{@x + iW}")
- end
- if type[0,1] == "["
- itemSplit = type.gsub(/[\[\]]/, "").split('x')
- minusH = itemSplit[0].to_i
- minusW = itemSplit[1].to_i
- if arr[n-1] != "#{@y + iH - minusH},#{@x + iW - minusW}"
- n += 1
- arr.push("#{@y + iH - minusH},#{@x + iW - minusW}")
- end
- end
- break if n >= 2
- end
- break if n >= 2
- end
- return "replace" if replaceable && n < 2
- return (n < 2 && !replaceable)
- end
- def set=(set)
- @x = set
- @y = set
- @mini_help.visible = (set == 0 ? true : false)
- end
- # Draws item graphics
- def draw_item(item_id, type, i , j)
- #~ if type == "i" and
- #~ $game_party.item_can_use?($data_items[item_id].id)
- opacity = 255
- #~ else
- #~ opacity = 128
- #~ end
- if item_id != 0
- x = 4 + (j * 32)
- y = i * 32
- itemWeaponArmor = item(type, item_id)
- case type
- when "i"
- color = Grid_Variables::COLOR_ITEMS
- when "w"
- color = Grid_Variables::COLOR_WEAPONS
- when "a"
- color = Grid_Variables::COLOR_ARMORS
- end
- if type != "" && type[0,1] != "["
- x = j * 32
- y = i * 32
- updateItemSizeFirstDraw(item_id, type)
- bitmap = RPG::Cache.icon(Grid_Variables::BIG_ICONS_PREFIX + itemWeaponArmor.icon_name)
- if Grid_Variables::USE_BIG_ICONS && (bitmap.width != 24 && bitmap.height != 24)
- self.contents.blt(x, y, bitmap, Rect.new(0, 0, @itemWidth * 32, @itemHeight * 32), opacity)
- else
- x += ((@itemWidth * 32) / 2) - 16
- y += ((@itemHeight * 32) / 2) - 16
- self.contents.blt(x + 4, y + 4, bitmap, Rect.new(0, 0, 48, 24), opacity)
- end
- @grid_color.bitmap.fill_rect(j*32+1, i*32+1, (@itemWidth * 32) - 1, (@itemHeight * 32) - 1, color)
- end
- end
- end
- end
- #==============================================================================
- # This is Window_Target, edited to darken actors that can't equip the item.
- # Since there is no way to change the normal color on Window_Base, I had to
- # rewrite most draw functions here.
- #==============================================================================
- class Window_Target_Equip < Window_Selectable
- def initialize
- super(0, 0, 336, 480)
- self.contents = Bitmap.new(width - 32, height - 32)
- self.contents.font.name = $fontface
- self.contents.font.size = $fontsize
- self.z += 10
- @item_max = $game_party.actors.size
- @disabled_actor = []
- refresh
- end
- def refresh
- self.contents.clear
- for i in 0...$game_party.actors.size
- disabled = @disabled_actor[i]
- if disabled
- self.contents.font.color = disabled_color
- else
- self.contents.font.color = normal_color
- end
- x = 4
- y = i * 116
- actor = $game_party.actors[i]
- # actor name
- self.contents.draw_text(x, y, 120, 32, actor.name)
- # actor class
- self.contents.draw_text(x + 144, y, 236, 32, actor.class_name)
- # actor level
- self.contents.font.color = system_color if !disabled
- self.contents.draw_text(x + 8, y + 32, 32, 32, "Lv")
- self.contents.font.color = normal_color if !disabled
- self.contents.draw_text(x + 8 + 32, y + 32, 24, 32, actor.level.to_s, 2)
- # actor state
- text = make_battler_state_text(actor, width, true)
- self.contents.font.color = knockout_color if actor.hp == 0 && !disabled
- self.contents.draw_text(x + 8, y + 64, width, 32, text)
- self.contents.font.color = normal_color if actor.hp == 0 && !disabled
- # actor hp
- self.contents.font.color = system_color if !disabled
- self.contents.draw_text(x + 152, y + 32, 32, 32, $data_system.words.hp)
- # Checking if there is enough space for max HP
- if 144 - 32 >= 108
- hp_x = x + 152 + 144 - 108
- flag = true
- elsif 144 - 32 >= 48
- hp_x = x + 152 + 144 - 48
- flag = false
- end
- # Draw HP
- if !disabled
- if actor.hp == 0
- self.contents.font.color = knockout_color
- elsif actor.hp <= actor.maxhp / 4
- self.contents.font.color = crisis_color
- else
- self.contents.font.color = normal_color
- end
- end
- self.contents.draw_text(hp_x, y + 32, 48, 32, actor.hp.to_s, 2)
- # Draw max HP
- if flag
- self.contents.font.color = normal_color if !disabled
- self.contents.draw_text(hp_x + 48, y + 32, 12, 32, "/", 1)
- self.contents.draw_text(hp_x + 60, y + 32, 48, 32, actor.maxhp.to_s)
- end
- # actor sp
- self.contents.font.color = system_color if !disabled
- self.contents.draw_text(x + 152, y + 64, 32, 32, $data_system.words.sp)
- # Check if there is enough space for max SP
- if 144 - 32 >= 108
- sp_x = x + 152+ 144 - 108
- flag = true
- elsif 144 - 32 >= 48
- sp_x = x + 152+ 144 - 48
- flag = false
- end
- # Draw SP
- if !disabled
- if actor.sp == 0
- self.contents.font.color = knockout_color
- elsif actor.sp <= actor.maxsp / 4
- self.contents.font.color = crisis_color
- else
- self.contents.font.color = normal_color
- end
- end
- self.contents.draw_text(sp_x, y + 64, 48, 32, actor.sp.to_s, 2)
- # Draw max SP
- if flag
- self.contents.font.color = normal_color if !disabled
- self.contents.draw_text(sp_x + 48, y + 64, 12, 32, "/", 1)
- self.contents.draw_text(sp_x + 60, y + 64, 48, 32, actor.maxsp.to_s)
- end
- end
- end
- def update_cursor_rect
- # Se define a posição atual -1
- if @index < 0
- self.cursor_rect.set(0, 0, self.width - 32, @item_max * 116 - 20)
- else
- self.cursor_rect.set(0, @index * 116, self.width - 32, 96)
- end
- end
- def disable_actor(actor_id)
- @disabled_actor[actor_id] = true
- end
- def enable_actor(actor_id)
- @disabled_actor[actor_id] = false
- end
- def disabled?(id)
- return @disabled_actor[id]
- end
- end
- #==============================================================================
- # The mini help window shows the item name below the selection cursor
- #==============================================================================
- class Mini_Help < Window_Base
- alias old_initialize initialize
- def initialize
- super(0, 0, 180, 43)
- self.contents = Bitmap.new(width - 32, height - 32)
- self.contents.font.size = 14
- self.back_opacity = 170
- self.z = 102
- self.visible = false
- end
- def set_text(text, align = 1)
- # If at least one part of text and alignment differ from last time
- if text != @text or align != @align
- # Redraw text
- self.contents.clear
- #self.contents.font.color = normal_color
- self.contents.draw_text(4, -12, self.width - 40, 32, text, align)
- #self.width = self.contents.text_size(text).width
- @text = text
- @align = align
- @actor = nil
- end
- self.visible = true
- end
- end
- #==============================================================================
- # Changes the way the game handles item creation
- #==============================================================================
- class Game_Actor < Game_Battler
- attr_accessor :item_grid
- alias old_initialize initialize
- def initialize(actor_id)
- old_initialize(actor_id)
- @item_grid = Array.new(Grid_Variables::GRID_HEIGHT)
- for i in 0..@item_grid.size - 1
- @item_grid[i] = Array.new(Grid_Variables::GRID_WIDTH)
- for k in 0..@item_grid[i].size - 1
- @item_grid[i][k] = Array.new(2)
- @item_grid[i][k][0] = 0
- @item_grid[i][k][1] = ""
- end
- end
- end
- # This edit is to avoid losing the item if your inventory is already full.
- def equip(equip_type, id)
- case equip_type
- when 0 # Weapons
- if id == 0 or $game_party.weapon_number(id) > 0
- $game_party.lose_weapon(id, 1)
- if !$game_party.isGridFull?(@weapon_id, "w") || @weapon_id == 0
- $game_party.gain_weapon(@weapon_id, 1)
- @weapon_id = id
- else
- $game_party.gain_weapon(id, 1)
- $game_system.se_play($data_system.buzzer_se)
- return nil
- end
- end
- when 1 # Shield
- if id == 0 or $game_party.armor_number(id) > 0
- $game_party.lose_armor(id, 1)
- if !$game_party.isGridFull?(@armor1_id, "a") || @armor1_id == 0
- update_auto_state($data_armors[@armor1_id], $data_armors[id])
- $game_party.gain_armor(@armor1_id, 1)
- @armor1_id = id
- else
- $game_party.gain_armor(id, 1)
- return nil
- end
- end
- when 2 # Headgear
- if id == 0 or $game_party.armor_number(id) > 0
- $game_party.lose_armor(id, 1)
- if !$game_party.isGridFull?(@armor2_id, "a") || @armor2_id == 0
- update_auto_state($data_armors[@armor2_id], $data_armors[id])
- $game_party.gain_armor(@armor2_id, 1)
- @armor2_id = id
- else
- $game_party.gain_armor(id, 1)
- return nil
- end
- end
- when 3 # Armor
- if id == 0 or $game_party.armor_number(id) > 0
- $game_party.lose_armor(id, 1)
- if !$game_party.isGridFull?(@armor3_id, "a") || @armor3_id == 0
- update_auto_state($data_armors[@armor3_id], $data_armors[id])
- $game_party.gain_armor(@armor3_id, 1)
- @armor3_id = id
- else
- $game_party.gain_armor(id, 1)
- return nil
- end
- end
- when 4 # Accessory
- if id == 0 or $game_party.armor_number(id) > 0
- $game_party.lose_armor(id, 1)
- if !$game_party.isGridFull?(@armor4_id, "a") || @armor4_id == 0
- update_auto_state($data_armors[@armor4_id], $data_armors[id])
- $game_party.gain_armor(@armor4_id, 1)
- @armor4_id = id
- else
- $game_party.gain_armor(id, 1)
- return nil
- end
- end
- end
- end
- # Same as above, but without deleting item. This one is used for the grid equip
- def grid_equip(equip_type, id)
- case equip_type
- when 0 # Armas
- if id == 0 or $game_party.weapon_number(id) > 0
- $game_party.gain_weapon(@weapon_id, 1)
- @weapon_id = id
- end
- when 1 # Escudo
- if id == 0 or $game_party.armor_number(id) > 0
- update_auto_state($data_armors[@armor1_id], $data_armors[id])
- $game_party.gain_armor(@armor1_id, 1)
- @armor1_id = id
- end
- when 2 # Elmo
- if id == 0 or $game_party.armor_number(id) > 0
- update_auto_state($data_armors[@armor2_id], $data_armors[id])
- $game_party.gain_armor(@armor2_id, 1)
- @armor2_id = id
- end
- when 3 # Armadura
- if id == 0 or $game_party.armor_number(id) > 0
- update_auto_state($data_armors[@armor3_id], $data_armors[id])
- $game_party.gain_armor(@armor3_id, 1)
- @armor3_id = id
- end
- when 4 # Acessório
- if id == 0 or $game_party.armor_number(id) > 0
- update_auto_state($data_armors[@armor4_id], $data_armors[id])
- $game_party.gain_armor(@armor4_id, 1)
- @armor4_id = id
- end
- end
- end
- end
- #==============================================================================
- # Handles most of the grid inventory functions
- #==============================================================================
- class Game_Party
- # These have been edited for the Scene_Shop. If it returns something, that
- # means the grid is full and it couldn't add more items, so we use that number
- # to charge for the items bought
- def gain_item(item_id, n)
- if item_id > 0
- if n.abs == n # if the number is a positive value, add the items
- for k in 1..n
- break if set_item(item_id, "i") == nil
- end
- return k unless k == n
- else # if the number is a negative value, remove the items
- lose_item(item_id, n.abs)
- end
- end
- end
- def gain_weapon(weapon_id, n)
- if weapon_id > 0
- if n.abs == n # if the number is a positive value, add the items
- for k in 1..n
- break if set_item(weapon_id, "w") == nil
- end
- return k unless k == n
- else # if the number is a negative value, remove the items
- lose_weapon(weapon_id, n.abs)
- end
- end
- end
- def gain_armor(armor_id, n)
- if armor_id > 0
- if n.abs == n # if the number is a positive value, add the items
- for k in 1..n
- break if set_item(armor_id, "a") == nil
- end
- return k unless k == n
- else # if the number is a negative value, remove the items
- lose_armor(armor_id, n.abs)
- end
- end
- end
- def lose_item(item_id, n, random = true)
- if random == true
- if item_id > 0
- for k in 1..n
- del_item(item_id, "i")
- end
- end
- end
- @items[item_id] = [[item_number(item_id) + -n, 0].max, 99].min
- end
- def lose_weapon(weapon_id, n, random = true)
- if random == true
- if weapon_id > 0
- for k in 1..n
- del_item(weapon_id, "w")
- end
- end
- end
- @weapons[weapon_id] = [[weapon_number(weapon_id) + -n, 0].max, 99].min
- end
- def lose_armor(armor_id, n, random = true)
- if random == true
- if armor_id > 0
- for k in 1..n
- del_item(armor_id, "a")
- end
- end
- end
- @armors[armor_id] = [[armor_number(armor_id) + -n, 0].max, 99].min
- end
- # Mostly used for the delete_item method. This removes the item from the inventory.
- def eraseData(type, item_id, n)
- case type
- when "i"
- @items[item_id] = [[item_number(item_id) + -n, 0].max, 99].min
- when "w"
- @weapons[item_id] = [[weapon_number(item_id) + -n, 0].max, 99].min
- when "a"
- @armors[item_id] = [[armor_number(item_id) + -n, 0].max, 99].min
- end
- end
- # Update item properties
- def updateItemProp(type, item_id)
- case type
- when "i"
- name = $data_grid[0][item_id]
- when "w"
- name = $data_grid[1][item_id]
- when "a"
- name = $data_grid[2][item_id]
- else
- name = nil
- end
- if name != nil
- gridValues = name.split('x')
- @itemWidth = gridValues[0].to_i
- @itemHeight = gridValues[1].to_i
- end
- end
- # Checks if x and y are empty
- def isEmpty?(x, y)
- for iH in 0...@itemHeight.to_i
- for iW in 0...@itemWidth.to_i
- cond = (self.actors[0].item_grid[x + iH][y + iW][0] == 0)
- break if !cond
- end
- break if !cond
- end
- return cond
- end
- # Checking if there is enough space for the item on the grid
- def isGridFull?(item_id, type, item = false)
- if type == "" && item != false
- case item
- when RPG::Item
- type = "i"
- when RPG::Weapon
- type = "w"
- when RPG::Armor
- type = "a"
- end
- end
- if item == false
- updateItemProp(type, item_id)
- else
- case type
- when "i"
- name = $data_grid[0][item_id]
- when "w"
- name = $data_grid[1][item_id]
- when "a"
- name = $data_grid[2][item_id]
- else
- name = nil
- end
- if name != nil
- gridValues = name.split('x')
- @itemWidth = gridValues[0].to_i
- @itemHeight = gridValues[1].to_i
- end
- end
- for a in 0..self.actors[0].item_grid.size - 1
- for b in 0..self.actors[0].item_grid[a].size - 1
- if b < self.actors[0].item_grid[a].size - (@itemWidth.to_i - 1) and a < self.actors[0].item_grid.size - (@itemHeight.to_i - 1)
- cond = isEmpty?(a, b)
- break if cond
- end
- end
- break if cond
- end
- return !cond #!cond to make it return true if the grid is really full, just to avoid confusion with the method name
- end
- # Checking if the grid is full for multiple items
- def isGridFullMultipleItems?(arrayOfIds, types)
- # Just a little precaution, in case the user forgets the square brackets
- arrayOfIds = [arrayOfIds] if !arrayOfIds.kind_of?(Array)
- for i in 0..arrayOfIds.length - 1
- item_id = arrayOfIds[i]
- if types.length == 1
- type = types
- else
- type = types[i]
- end
- case type
- when "i"
- name = $data_grid[0][item_id]
- when "w"
- name = $data_grid[1][item_id]
- when "a"
- name = $data_grid[2][item_id]
- else
- name = nil
- end
- if name != nil
- gridValues = name.split('x')
- @itemWidth = gridValues[0].to_i
- @itemHeight = gridValues[1].to_i
- end
- for a in 0..self.actors[0].item_grid.size - 1
- for b in 0..self.actors[0].item_grid[a].size - 1
- if b < self.actors[0].item_grid[a].size - (@itemWidth.to_i - 1) and a < self.actors[0].item_grid.size - (@itemHeight.to_i - 1)
- cond = isEmpty?(a, b)
- break if cond
- end
- end
- break if cond
- end
- break if !cond
- end
- return !cond
- end
- # Adds the item values to the grid
- def set_item(item_id, type, returnPos = false)
- for a in 0..self.actors[0].item_grid.size - 1
- for b in 0..self.actors[0].item_grid[a].size - 1
- updateItemProp(type, item_id)
- iW = 0; iH = 0
- if b < self.actors[0].item_grid[a].size - (@itemWidth.to_i - 1) and a < self.actors[0].item_grid.size - (@itemHeight.to_i - 1)
- if isEmpty?(a, b)
- for iH in 0...@itemHeight.to_i
- for iW in 0...@itemWidth.to_i
- if iH == 0 && iW == 0
- self.actors[0].item_grid[a][b][0] = item_id
- self.actors[0].item_grid[a][b][1] = type
- else
- self.actors[0].item_grid[a + iH][b + iW][0] = item_id
- self.actors[0].item_grid[a + iH][b + iW][1] = "[#{iH}x#{iW}]"
- end
- end
- end
- whatToReturn = ""
- case type
- when "i"
- @items[item_id] = [[item_number(item_id) + 1, 0].max, 99].min
- when "w"
- @weapons[item_id] = [[weapon_number(item_id) + 1, 0].max, 99].min
- when "a"
- @armors[item_id] = [[armor_number(item_id) + 1, 0].max, 99].min
- end
- break
- else
- whatToReturn = nil
- end
- end
- end
- break if whatToReturn != nil
- end
- return [a, b] if returnPos
- return whatToReturn
- end
- # Deletes the item values from the grid
- def del_item(item_id, type)
- updateItemProp(type, item_id)
- for a in 0..self.actors[0].item_grid.size - 1
- for b in 0..self.actors[0].item_grid[a].size - 1
- if self.actors[0].item_grid[a][b][0] == item_id and self.actors[0].item_grid[a][b][1] == type
- for iH in 0...@itemHeight.to_i
- for iW in 0...@itemWidth.to_i
- self.actors[0].item_grid[a + iH][b + iW][0] = 0
- self.actors[0].item_grid[a + iH][b + iW][1] = ""
- end
- end
- return
- end
- end
- end
- end
- end
- #==============================================================================
- # This is the cursor used when moving the item.
- #==============================================================================
- class Cursor_Icon < RPG::Sprite
- def initialize
- super
- @color = Color.new(255,255,0,50)
- @rect = Rect.new(0, 0, 24, 24)
- end
- def refresh(bitmap, iW, iH)
- if Grid_Variables::USE_BIG_ICONS
- x = 0
- y = 0
- @rect = Rect.new(0, 0, iW*32, iH*32)
- else
- x = 4 + ((iW * 32) / 2) - 16
- y = 4 + ((iH * 32) / 2) - 16
- end
- width = iW * 32
- height = iH * 32
- if self.bitmap == nil or (self.bitmap.width != width or self.bitmap.height != height)
- self.bitmap = Bitmap.new(width, height)
- else
- self.bitmap.clear
- end
- self.bitmap.fill_rect(0,0,width,height, @color)
- self.bitmap.blt(x, y, bitmap, @rect)
- self.z = 9999
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement