Pokémon Essentials All questions and discussion about Pokémon Essentials, the Pokémon game kit for RPG Maker XP, go in here. Also contains links to the latest downloads and the Essentials Wiki.

TrollandToad.com
Reply
 
Thread Tools
  #1    
Old September 14th, 2017 (3:35 AM). Edited September 14th, 2017 by Blake7.
Blake7's Avatar
Blake7 Blake7 is offline
To Ignite all people within our nation
     
    Join Date: Aug 2016
    Gender: Male
    Posts: 47
    I am using Shiney570's bag script and in the mouse function whenever I try to click the switch button when the last pocket is selected I get this error.
    Spoiler:
    ---------------------------
    Pokemon Aeon
    ---------------------------
    Script 'BW_Bag2' line 177: NoMethodError occurred.

    undefined method `length' for nil:NilClass
    ---------------------------
    OK
    ---------------------------

    The line is this -> @item_max=thispocket.length (only happens when i mouse click on the right switch when bottom pocket is selected, if I use keyboard it goes to top of list without error. But with mouse it gives the above error. Loop on the left switch is fine, if I click left switch when first pocket is selected it goes to bottom pocket without error. )

    Instead I want it to either stop there or go back to the top of the list.
    Here is the script:
    Spoiler:
    #=====================================================================================
    # * Bag Script by shiney570. (Originally written for the Essentials BW2 Mod)
    #=====================================================================================

    #===============================================================================
    # * adding and defining variables for the class PokeBattle_Trainer
    #===============================================================================
    class PokeBattle_Trainer
    attr_accessor :registeredItems
    attr_accessor :freeSpaceItems

    def registeredItems
    @registeredItems=[] if !@registeredItems
    return @registeredItems
    end

    def freeSpaceItems
    @freeSpaceItems=[] if !@freeSpaceItems
    return @freeSpaceItems
    end
    end

    # Function for checking if an item is a battle item.
    def pbIsBattleItem?(item)
    return $ItemData[item] && ($ItemData[item][ITEMBATTLEUSE]==0 && $ItemData[item][ITEMPOCKET]==1)
    end

    # Function for checking if an item belongs to the medicine pocket.
    def pbIsMedicineItem?(item)
    return ($ItemData[item][ITEMPOCKET]==2)
    end

    # Function for checking if an item is in the Free Space.
    def pbIsInFreeSpace?(item)
    if item.is_a?(Array)
    item=item[0]
    end
    for i in 0...$Trainer.freeSpaceItems.length
    return true if item==$Trainer.freeSpaceItems[i][0]
    end
    return false
    end

    # Function for adding an item to the Free Space.
    def pbAddItemToFreeSpace(item)
    if !pbIsInFreeSpace?(item)
    $Trainer.freeSpaceItems.push(item)
    elsif $DEBUG
    p "Something went wrong. The Item is already in the Free Space."
    end
    end

    # Function for deleting an item from the Free Space.
    def pbDeleteItemFromFreeSpace(item)
    if item.is_a?(Array)
    item=item[0]
    end
    if pbIsInFreeSpace?(item)
    for i in 0...$Trainer.freeSpaceItems.length
    if $Trainer.freeSpaceItems[i][0]==item
    $Trainer.freeSpaceItems.delete_at(i)
    break
    end
    end
    elsif $DEBUG
    p "Something went wrong. The Item isn't even in the Free Space."
    end
    end

    # Function for checking if an item is a registered item.
    def pbIsRegisteredItem?(item)
    for i in 0...$Trainer.registeredItems.length
    return true if item==$Trainer.registeredItems[i]
    end
    return false
    end

    # Function to register another item.
    def pbRegisterItem(item)
    if item.is_a?(Array)
    item=item[0]
    end
    $Trainer.registeredItems.push(item) if !pbIsRegisteredItem?(item)
    end

    # Function to deselect a registered item.
    def pbRemoveRegisteredItem(item)
    if item.is_a?(Array)
    item=item[0]
    end
    for i in 0...$Trainer.registeredItems.length
    if item==$Trainer.registeredItems[i]
    $Trainer.registeredItems.delete_at(i)
    break
    end
    end
    end

    # Updating pbGetPocket to work with BW2 Pockets. It won't use the bag number
    # from the items.txt anymore. defining it is still very very important.
    def pbGetPocket(item)
    if item.is_a?(Array)
    item=item[0]
    end
    return 0 if !item
    pocket=1
    # Adding Pockets together.
    if pbIsInFreeSpace?(item) # Free Space
    pocket=6
    elsif pbIsKeyItem?(item) # Key Item
    pocket=5
    elsif pbIsBerry?(item) # Berry
    pocket=4
    elsif pbIsMachine?(item) # TM / HM
    pocket=3
    elsif pbIsMedicineItem?(item) # Medicine
    pocket=2
    end
    return pocket
    end
    # Returns the name of the pocket an item belongs to as a string.
    def pbGetPocketName(item)
    if item.is_a?(Array)
    item=item[0]
    end
    return "NONE" if !item
    # Checking for the Pocket the item is in regulary. (I could not use
    # the method pbGetPocket since I don't want to get "Free Space" returned
    # by any chanche.)
    pocket=1
    if pbIsKeyItem?(item) # Key Item
    pocket=5
    elsif pbIsBerry?(item) # Berry
    pocket=4
    elsif pbIsMachine?(item) # TM / HM
    pocket=3
    elsif pbIsMedicineItem?(item) # Medicine
    pocket=2
    end
    return pbPocketNames[pocket]
    end

    #===============================================================================
    # * Bag screen
    #===============================================================================
    class Window_PokemonBag < Window_DrawableCommand
    attr_reader :pocket
    attr_reader :sortIndex

    def initialize(bag,pocket,x,y,width,height)
    @bag=bag
    @pocket=pocket
    @sortIndex=-1
    @adapter=PokemonMartAdapter.new
    super(x,y,width,height)
    @row_height=48
    @selarrow=AnimatedBitmap.new("Graphics/Pictures/Bag/panel_select")
    @selarrowy=0
    @panel=AnimatedBitmap.new("Graphics/Pictures/Bag/panel")
    @pokeball=AnimatedBitmap.new("Graphics/Pictures/Bag/icon_pokeball")
    @mail=AnimatedBitmap.new("Graphics/Pictures/Bag/icon_mail")
    @tm=AnimatedBitmap.new("Graphics/Pictures/Bag/icon_tm")
    @hm=AnimatedBitmap.new("Graphics/Pictures/Bag/icon_hm")
    @battle_item=AnimatedBitmap.new("Graphics/Pictures/Bag/icon_item")
    @box=AnimatedBitmap.new("Graphics/Pictures/Universal/box")
    @box_check=AnimatedBitmap.new("Graphics/Pictures/Universal/box_check")
    self.windowskin=nil
    end

    def pocket=(value)
    @pocket=value
    thispocket=@bag.pockets[@pocket]
    @item_max=thispocket.length-1#+1
    self.index=@bag.getChoice(@pocket)
    refresh
    end

    def sortIndex=(value)
    @sortIndex=value
    refresh
    end

    def page_row_max; return PokemonBag_Scene::ITEMSVISIBLE; end
    def page_item_max; return PokemonBag_Scene::ITEMSVISIBLE; end

    def itemRect(item)
    if item<0 || item>=@item_max || itemself.top_item+self.page_item_max
    return Rect.new(0,0,0,0)
    else
    cursor_width = (self.width-self.borderX-(@column_max-1)*@column_spacing) / @column_max
    x = item % @column_max * (cursor_width + @column_spacing)
    y = item / @column_max * @row_height- @virtualOy #48 , virtualoy*1.5
    return Rect.new(x, y, cursor_width,48)
    end
    end

    def selectedNumber
    ret=@selarrowy/48
    ret+=1
    return ret
    end

    def drawCursor(index,rect)
    # Creating panels
    if self.index==index
    pbCopyBitmap(self.contents,@selarrow.bitmap,rect.x+6+48,rect.y+24)
    @selarrowy=rect.y+24
    else
    @panel=AnimatedBitmap.new("Graphics/Pictures/Bag/panel") if !@panel
    pbCopyBitmap(self.contents,@panel.bitmap,rect.x+6+48,rect.y+24) #6
    end
    return Rect.new(rect.x+16,rect.y+24,rect.width-16,rect.height+24)
    end

    def item
    thispocket=@bag.pockets[self.pocket]
    item=thispocket[self.index]
    return item ? item[0] : 0
    end

    def itemCount
    return @bag.pockets[self.pocket].length+1
    end

    def drawItem(index,count,rect)
    # Defining the variables again since i got a lot of different errors
    # telling me that a random of these variables below is undefined so yeah...
    @pokeball=AnimatedBitmap.new("Graphics/Pictures/Bag/icon_pokeball") if !@pokeball
    @mail=AnimatedBitmap.new("Graphics/Pictures/Bag/icon_mail") if !@mail
    @tm=AnimatedBitmap.new("Graphics/Pictures/Bag/icon_tm") if !@tm
    @hm=AnimatedBitmap.new("Graphics/Pictures/Bag/icon_hm") if !@hm
    @battle_item=AnimatedBitmap.new("Graphics/Pictures/Bag/icon_item") if !@battle_item
    @box=AnimatedBitmap.new("Graphics/Pictures/Universal/box") if !@box
    @box_check=AnimatedBitmap.new("Graphics/Pictures/Universal/box_check") if !@box_check
    textpos=[]
    rect=drawCursor(index,rect)
    ypos=rect.y+8
    if index==@bag.pockets[self.pocket].length
    textpos.push([_INTL("CLOSE BAG"),rect.x+48,ypos,false,
    self.baseColor,self.shadowColor])
    else
    item=@bag.pockets[self.pocket][index][0]
    @current_item=item
    itemname=@adapter.getDisplayName(item)
    qty=_ISPRINTF("x{1: 2d}",@bag.pockets[self.pocket][index][1])
    sizeQty=self.contents.text_size(qty).width
    xQty=rect.x+rect.width-sizeQty-16
    baseColor=(index==@sortIndex) ? Color.new(255,255,255) : self.baseColor
    shadowColor=(index==@sortIndex) ? Color.new(165,165,173) : self.shadowColor
    # Drawing item type icons behind the panels.
    if pbIsPokeBall?(item)
    pbCopyBitmap(self.contents,@pokeball.bitmap,rect.x+6,rect.y)
    elsif pbIsMail?(item)
    pbCopyBitmap(self.contents,@mail.bitmap,rect.x+6,rect.y)
    elsif pbIsTechnicalMachine?(item)
    pbCopyBitmap(self.contents,@tm.bitmap,rect.x-2,rect.y)
    elsif pbIsHiddenMachine?(item)
    pbCopyBitmap(self.contents,@hm.bitmap,rect.x-2,rect.y)
    elsif pbIsBattleItem?(item)
    pbCopyBitmap(self.contents,@battle_item.bitmap,rect.x+6,rect.y)
    elsif pbIsKeyItem?(item) && ItemHandlers.hasKeyItemHandler(item)
    if pbIsRegisteredItem?(item)
    pbCopyBitmap(self.contents,@box_check.bitmap,rect.x+6,rect.y+8)
    else
    pbCopyBitmap(self.contents,@box.bitmap,rect.x+6,rect.y+8)
    end
    end
    if pbIsHiddenMachine?(item) && self.index==index
    textpos.push([itemname,rect.x+48,ypos,false,Color.new(239,214,255),Color.new(189,148,206)])
    elsif pbIsHiddenMachine?(item)
    textpos.push([itemname,rect.x+48,ypos,false,Color.new(206,123,255),Color.new(123,82,148)])
    else
    textpos.push([itemname,rect.x+48,ypos,false,baseColor,shadowColor])
    end
    if !pbIsImportantItem?(item) # Not a Key item or HM (or infinite TM)
    textpos.push([qty,xQty+48,ypos,false,baseColor,shadowColor])
    end
    end
    pbDrawTextPositions(self.contents,textpos)
    if index!=@bag.pockets[self.pocket].length
    if @bag.registeredItem==@bag.pockets[self.pocket][index][0]
    pbDrawImagePositions(self.contents,[
    ["Graphics/Pictures/bagReg",rect.x+rect.width-58,ypos+4,0,0,-1,-1]
    ])
    end
    end
    end

    def refresh
    @item_max=itemCount()
    dwidth=self.width-self.borderX
    dheight=self.height-self.borderY
    self.contents=pbDoEnsureBitmap(self.contents,dwidth,dheight)
    self.contents.clear
    $bag_bitmap=self.contents
    for i in 0...@item_max
    if iself.top_item+self.page_item_max
    next
    end
    drawItem(i,@item_max,itemRect(i))
    end
    end
    end

    class PokemonBag_Scene

    ## Configuration
    ITEMLISTBASECOLOR = Color.new(88,88,80)
    ITEMLISTSHADOWCOLOR = Color.new(168,184,184)
    ITEMTEXTBASECOLOR = Color.new(248,248,248)
    ITEMTEXTSHADOWCOLOR = Color.new(0,0,0)
    POCKETNAMEBASECOLOR = Color.new(88,88,80)
    POCKETNAMESHADOWCOLOR = Color.new(168,184,184)
    ITEMSVISIBLE = 6

    def update
    pbUpdateSpriteHash(@sprites)
    end

    def sprites
    return @sprites
    end

    def pbStartScene(bag)
    pockets=pbPocketNames
    @bag=bag
    @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
    @viewport.z=99999
    @sprites={}
    lastpocket=@bag.lastpocket
    lastitem=@bag.getChoice(lastpocket)
    @sprites["background"]=IconSprite.new(0,0,@viewport)
    @sprites["background"].setBitmap("Graphics/Pictures/Bag/bg")
    @sprites["background"].setBitmap("Graphics/Pictures/Bag/bg_f") if $Trainer.isFemale?
    @sprites["item_bg"]=IconSprite.new(0,0,@viewport)
    @sprites["item_bg"].setBitmap("Graphics/Pictures/Bag/item_bg")
    @sprites["item_bg"].setBitmap("Graphics/Pictures/Bag/item_bg_f") if $Trainer.isFemale?
    @sprites["item_bg"].visible=false
    # Ignore the last argument of the arrays. editing it won't make a difference,
    # deleting it will give you an error.
    x=[0,0,66,135,130,104,1337,1337]
    y=[84,188,222,208,124,32,1337,1337]
    # (the bag's in BW2 have different coordinates for different gender's
    # because the bag's have different height's and width's.)
    x=[0,0,66,137,131,99,1337,1337] if $Trainer.isFemale?
    y=[40,181,223,205,112,56,1337,1337] if $Trainer.isFemale?

    for i in 1..pockets.length
    if x[i-1]
    @sprites["bag_#{i}"]=IconSprite.new(x[i-1],y[i-1],@viewport)
    else
    @sprites["bag_#{i}"]=IconSprite.new(1337,1337,@viewport)
    end

    fbagexists=pbResolveBitmap(sprintf("Graphics/Pictures/Bag/bag#{i}f"))
    if $Trainer.isFemale? && fbagexists
    @sprites["bag_#{i}"].setBitmap("Graphics/Pictures/Bag/bag#{i}f")
    else
    @sprites["bag_#{i}"].setBitmap("Graphics/Pictures/Bag/bag#{i}")
    end
    @sprites["bag_#{i}"].src_rect.width=@sprites["bag_#{i}"].bitmap.width/3
    # Changing the priority. it's kinda stupid because in BW2 the first pocket
    # isn't the top/bottom one.
    if i<5
    @sprites["bag_#{i}"].z+=2
    @sprites["bag_#{i}"].z+=1 if i==3
    elsif i==5
    @sprites["bag_#{i}"].z+=1
    end
    end
    @sprites["itemwindow"]=Window_PokemonBag.new(@bag,lastpocket,281-32-48,-16,512,384-16)
    @sprites["itemwindow"].viewport=@viewport
    @sprites["itemwindow"].pocket=lastpocket
    @sprites["itemwindow"].index=lastitem
    @sprites["itemwindow"].baseColor=Color.new(255,255,255)
    @sprites["itemwindow"].shadowColor=Color.new(156,156,156)
    @sprites["itemwindow"].refresh
    @sprites["slider_bg"]=IconSprite.new(490,36,@viewport)
    @sprites["slider_bg"].setBitmap("Graphics/Pictures/Bag/slider_bg")
    @sprites["slider"]=IconSprite.new(Graphics.width-40,60,@viewport)
    @sprites["slider"].setBitmap(sprintf("Graphics/Pictures/Bag/slider"))
    @sprites["slider"].x=486
    @sprites["itemtextwindow"]=Window_UnformattedTextPokemon.new("")
    @sprites["itemtextwindow"].x=20
    @sprites["itemtextwindow"].y=184
    @sprites["itemtextwindow"].visible=false
    @sprites["itemtextwindow"].width=Graphics.width-72
    @sprites["itemtextwindow"].height=128
    @sprites["itemtextwindow"].baseColor=Color.new(255,255,255)
    @sprites["itemtextwindow"].shadowColor=Color.new(123,148,173)
    @sprites["itemtextwindow"].shadowColor=Color.new(231,123,148) if $Trainer.isFemale?
    @sprites["itemtextwindow"].viewport=@viewport
    @sprites["itemtextwindow"].windowskin=nil
    @sprites["helpwindow"]=Window_UnformattedTextPokemon.new("")
    @sprites["helpwindow"].visible=false
    @sprites["helpwindow"].viewport=@viewport
    @sprites["msgwindow"]=Window_AdvancedTextPokemon.new("")
    @sprites["msgwindow"].visible=false
    @sprites["msgwindow"].viewport=@viewport
    @sprites["down_bg"]=IconSprite.new(0,0,@viewport)
    @sprites["down_bg"].setBitmap("Graphics/Pictures/Universal/down_bg")
    @sprites["down_bg"].y= 384-48
    @sprites["switch"]=IconSprite.new(0,0,@viewport)
    @sprites["switch"].setBitmap("Graphics/Pictures/Bag/switch")
    @sprites["switch"].x=6
    @sprites["switch"].y=346
    @sprites["exit"]=IconSprite.new(0,0,@viewport)
    @sprites["exit"].setBitmap("Graphics/Pictures/Universal/exit")
    @sprites["exit"].x=385
    @sprites["exit"].y=346
    @sprites["return"]=IconSprite.new(0,0,@viewport)
    @sprites["return"].setBitmap("Graphics/Pictures/Universal/return")
    @sprites["return"].x=459
    @sprites["return"].y=346
    @sprites["icon"]=IconSprite.new(231,128,@viewport)
    @sprites["icon"].visible=false
    @sprites["overlay"]=BitmapSprite.new(Graphics.width, Graphics.height, @viewport)
    @sprites["overlay"].visible=false
    @sprites["pocketwindow"]=BitmapSprite.new(512,384,@viewport)# medicine,key items etc...
    pbSetSystemFont(@sprites["pocketwindow"].bitmap)
    pbBottomLeftLines(@sprites["helpwindow"],1)
    pbDeactivateWindows(@sprites)
    pbRefresh
    pbFadeInAndShow(@sprites)
    end

    # Method for moving an Item to the Free Space and moving it back to the pocket
    # if the item is already in the Free Space.
    def moveItemToFreeSpace(item)
    adapter=PokemonMartAdapter.new
    itemname=adapter.getDisplayName(item)
    # Moving Item to Free Space if it isn't already.
    if !pbIsInFreeSpace?(item)
    pockets=pbPocketNames
    for i in 1..pockets.length
    for u in 0...@bag.pockets[i].length
    return if !@bag.pockets[i][u]
    if item==@bag.pockets[i][u][0]
    array=@bag.pockets[i][u]
    pbAddItemToFreeSpace(@bag.pockets[i][u])
    @bag.pockets[i].delete_at(u)
    @bag.pockets[6]=$Trainer.freeSpaceItems
    Kernel.pbMessage("Moved the #{itemname} to the FREE SPACE!")
    return
    end
    end
    end
    # Moving Item from Free Space back to the pocket
    # if it is already in the Free Space.
    else
    for i in 0...$Trainer.freeSpaceItems.length
    if $Trainer.freeSpaceItems[i][0]==item
    full_item=$Trainer.freeSpaceItems[i]
    end
    end
    pbDeleteItemFromFreeSpace(item)
    @bag.pockets[pbGetPocket(item)].push(full_item)
    Kernel.pbMessage("Returned the #{itemname} to the #{pbGetPocketName(item)}!")
    end
    end

    def pbEndScene
    pbFadeOutAndHide(@sprites)
    pbDisposeSpriteHash(@sprites)
    @viewport.dispose
    end

    def pbChooseNumber(helptext,maximum)
    return UIHelper.pbChooseNumber(
    @sprites["helpwindow"],helptext,maximum) { update }
    end

    def pbDisplay(msg,brief=false)
    UIHelper.pbDisplay(@sprites["msgwindow"],msg,brief) { update }
    end

    def pbConfirm(msg)
    UIHelper.pbConfirm(@sprites["msgwindow"],msg) { update }
    end

    def pbShowCommands(helptext,commands)
    return UIHelper.pbShowCommands(
    @sprites["helpwindow"],helptext,commands) { update }
    end

    # Quick method for updating the pockets. Will be called in pbRefresh.
    def pbUpdatePockets
    pockets=pbPocketNames
    for i in 1..pockets.length
    if i==@bag.lastpocket
    @sprites["bag_#{i}"].src_rect.x=@sprites["bag_#{i}"].bitmap.width*2/3
    else
    @sprites["bag_#{i}"].src_rect.x=0
    end
    end
    end

    # Quick method for showing the little animation (showing the middle pocket
    # image for 5 frames)
    def showPocketAnimation(pocket)
    pockets=pbPocketNames
    for i in 1..pockets.length
    @sprites["bag_#{i}"].src_rect.x=0
    @sprites["bag_#{i}"].src_rect.x=@sprites["bag_#{i}"].bitmap.width/3 if i==pocket
    end
    pbWait(5)
    end

    def pbRefresh
    @sprites["itemwindow"].visible=false if @page==2
    bm=@sprites["pocketwindow"].bitmap
    bm.clear
    pbUpdatePockets
    # Draw the pocket name.
    name=PokemonBag.pocketNames()[@bag.lastpocket]
    base=Color.new(255,255,255)
    shadow=Color.new(165,165,173)
    pbDrawTextPositions(bm,[
    [name,117+28,344,2,base,shadow]
    ])
    itemwindow=@sprites["itemwindow"]
    # Reposition the slider.
    ycoord=36
    if itemwindow.itemCount>1
    ycoord+=228.0 * itemwindow.index/(itemwindow.itemCount-1)
    end
    @sprites["slider"].y=ycoord
    # Set the icon for the currently selected item
    filename=pbItemIconFile(itemwindow.item)
    @sprites["icon"].setBitmap(filename)
    # Display the item's description
    @sprites["itemtextwindow"].text=(itemwindow.item==0) ? _INTL("Close bag.") :
    pbGetMessage(MessageTypes::ItemDescriptions,itemwindow.item)
    # Refresh the item window
    itemwindow.refresh
    drawPageTwo if @page==2
    end

    # "draws" the first page. basically it's just changing visibility but yeah...
    def drawPageOne
    @page=1
    pockets=pbPocketNames
    for i in 1..pockets.length
    @sprites["bag_#{i}"].visible=true
    end
    @sprites["itemwindow"].visible=true
    @sprites["pocketwindow"].visible=true
    @sprites["item_bg"].visible=false
    @sprites["itemtextwindow"].visible=false
    @sprites["icon"].visible=false
    @sprites["overlay"].visible=false
    end

    # draws the second page (the page when you click on an item).
    def drawPageTwo
    @page=2
    pockets=pbPocketNames
    for i in 1..pockets.length
    @sprites["bag_#{i}"].visible=false
    end
    @sprites["itemwindow"].visible=false
    @sprites["item_bg"].visible=true
    @sprites["itemtextwindow"].visible=true
    @sprites["icon"].visible=true
    @sprites["overlay"].visible=true
    if @sprites["itemwindow"].pocket==6 # Free Space Pocket.
    @sprites["item_bg"].setBitmap("Graphics/Pictures/Bag/item_bg2")
    @sprites["item_bg"].setBitmap("Graphics/Pictures/Bag/item_bg_f2") if $Trainer.isFemale?
    else
    @sprites["item_bg"].setBitmap("Graphics/Pictures/Bag/item_bg")
    @sprites["item_bg"].setBitmap("Graphics/Pictures/Bag/item_bg_f") if $Trainer.isFemale?
    end
    $bag_bitmap.clear
    overlay= @sprites["overlay"].bitmap
    overlay.clear
    base=Color.new(255,255,255)
    shadow=Color.new(123,148,173)
    shadow=Color.new(231,123,148) if $Trainer.isFemale?
    pbSetSystemFont(@sprites["overlay"].bitmap)
    @adapter=PokemonMartAdapter.new
    textos=[]
    # If it's not the last one (Close Bag.)
    last_one=(@sprites["itemwindow"].index == (@sprites["itemwindow"].itemCount-1))
    if !last_one
    item=@bag.pockets[@sprites["itemwindow"].pocket][@sprites["itemwindow"].index][0]
    itemname=@adapter.getDisplayName(item)
    # Changes String of TMs + HMs.
    # Example 1: TM02 Dragon Claw --> No. 02 Dragon Claw
    # Example 2: HM03 Surf ---> Hidden 03 Surf
    if pbIsMachine?(item)
    itemname=itemname[2..-1] # deleting first two characters of the string.
    if pbIsTechnicalMachine?(item)
    itemname.insert(0,"No. ") # adding characters to the string.
    elsif pbIsHiddenMachine?(item)
    itemname.insert(0,"Hidden ") # adding characters to the string.
    end
    end
    textos.push([itemname,256,86,2,base,shadow])
    show_itemquantity=true
    show_itemquantity=false if pbIsKeyItem?(item)
    show_itemquantity=false if pbIsHiddenMachine?(item)
    show_itemquantity=false if (pbIsTechnicalMachine?(item) && INFINITETMS)

    if show_itemquantity
    textos.push([_INTL("x#{@bag.pbQuantity(item)}"),315,136,0,base,shadow])
    end
    end
    textos.push([_INTL("Close Bag."),256,86,2,base,shadow]) if last_one
    textos.push([pbGetPocketName(item),256,16,2,base,shadow]) if @sprites["itemwindow"].pocket==6 # Free Space Pocket.
    pbDrawTextPositions(overlay,textos)
    end

    # Called when the item screen wants an item to be chosen from the screen
    def pbChooseItem
    if @bag.pockets[@sprites["itemwindow"].pocket][@sprites["itemwindow"].index]
    index=@bag.pockets[@sprites["itemwindow"].pocket][@sprites["itemwindow"].index][0]
    else
    index=0 # Close Bag.
    end
    @page=1 if !@page
    pbRefresh
    @sprites["helpwindow"].visible=false
    itemwindow=@sprites["itemwindow"]
    itemwindow.refresh
    sorting=false
    sortindex=-1
    pbActivateWindow(@sprites,"itemwindow"){
    loop do
    Graphics.update
    Input.update
    olditem=itemwindow.item
    oldindex=itemwindow.index
    self.update
    if itemwindow.item!=olditem
    # Update slider position
    ycoord=36
    if itemwindow.itemCount>1
    ycoord+=228.0 * itemwindow.index/(itemwindow.itemCount-1)
    end
    @sprites["slider"].y=ycoord
    # Update item icon and description
    drawPageTwo if @page==2
    filename=pbItemIconFile(itemwindow.item)
    @sprites["icon"].setBitmap(filename)
    @sprites["itemtextwindow"].text=(itemwindow.item==0) ? _INTL("Close bag.") :
    pbGetMessage(MessageTypes::ItemDescriptions,itemwindow.item)
    end
    if itemwindow.index!=oldindex
    # Update selected item for current pocket
    @bag.setChoice(itemwindow.pocket,itemwindow.index)
    end
    # Change pockets if Left/Right pressed
    numpockets=PokemonBag.numPockets
    if Input.trigger?(Input::LEFT)
    if !sorting
    @sprites["switch"].setBitmap("Graphics/Pictures/Bag/switch2")
    pbWait(5)
    @sprites["switch"].setBitmap("Graphics/Pictures/Bag/switch")
    itemwindow.pocket=(itemwindow.pocket==1) ? numpockets : itemwindow.pocket-1
    @bag.lastpocket=itemwindow.pocket
    showPocketAnimation(itemwindow.pocket)
    pbRefresh
    end
    elsif Input.trigger?(Input::RIGHT)
    if !sorting
    @sprites["switch"].setBitmap("Graphics/Pictures/Bag/switch3")
    pbWait(5)
    @sprites["switch"].setBitmap("Graphics/Pictures/Bag/switch")
    itemwindow.pocket=(itemwindow.pocket==numpockets) ? 1 : itemwindow.pocket+1
    @bag.lastpocket=itemwindow.pocket
    showPocketAnimation(itemwindow.pocket)
    pbRefresh
    end
    end
    # Select item for switching if A is pressed
    if Input.trigger?(Input::A)
    thispocket=@bag.pockets[itemwindow.pocket]
    if itemwindow.index1 &&
    !POCKETAUTOSORT[itemwindow.pocket]
    sortindex=itemwindow.index
    sorting=true
    @sprites["itemwindow"].sortIndex=sortindex
    else
    next
    end
    end
    # Cancel switching or cancel the item screen
    if Input.trigger?(Input::B)
    @sprites["exit"].setBitmap("Graphics/Pictures/Universal/exit2")
    pbWait(10)
    @sprites["exit"].setBitmap("Graphics/Pictures/Universal/exit")
    pbWait(5)
    if @page==2
    drawPageOne
    pbRefresh
    elsif sorting
    sorting=false
    @sprites["itemwindow"].sortIndex=-1
    else
    return 0
    end
    end
    if defined?($mouse)
    if $mouse.leftClick?(@sprites["exit"])
    @sprites["exit"].setBitmap("Graphics/Pictures/Universal/exit2")
    pbWait(10)
    @sprites["exit"].setBitmap("Graphics/Pictures/Universal/exit")
    pbWait(5)
    if @page==2
    drawPageOne
    pbRefresh
    elsif sorting
    sorting=false
    @sprites["itemwindow"].sortIndex=-1
    else
    return 0
    end
    elsif $mouse.leftClick?(@sprites["return"])
    @sprites["return"].setBitmap("Graphics/Pictures/Universal/return2")
    pbWait(10)
    @sprites["return"].setBitmap("Graphics/Pictures/Universal/return")
    pbWait(5)
    $MenuClose=true
    return 0
    elsif $mouse.inAreaLeft?(6,346,33,28) && !sorting
    @sprites["switch"].setBitmap("Graphics/Pictures/Bag/switch2")
    pbWait(5)
    @sprites["switch"].setBitmap("Graphics/Pictures/Bag/switch")
    itemwindow.pocket=(itemwindow.pocket==1) ? numpockets : itemwindow.pocket-1
    @bag.lastpocket=itemwindow.pocket
    showPocketAnimation(itemwindow.pocket) if @page==1
    pbRefresh
    elsif $mouse.inAreaLeft?(247,346,33,28) && !sorting
    @sprites["switch"].setBitmap("Graphics/Pictures/Bag/switch3")
    pbWait(5)
    @sprites["switch"].setBitmap("Graphics/Pictures/Bag/switch")
    itemwindow.pocket=(itemwindow.pocket==MAXPOCKETSIZE.length) ? 1 : (itemwindow.pocket+1)
    @bag.lastpocket=itemwindow.pocket
    showPocketAnimation(itemwindow.pocket) if @page==1
    pbRefresh
    end
    # Mouse Scroll Bar
    if $mouse.inAreaPress?(482,10,512-482,300)
    max=@sprites["itemwindow"].itemCount-1
    @sprites["itemwindow"].index=($mouse.y-36)*max/264
    @sprites["itemwindow"].index=max if @sprites["itemwindow"].index>max
    @sprites["itemwindow"].index=0 if @sprites["itemwindow"].index<0
    pbRefresh
    end
    # clicking on a panel or on the box to register an item.
    if $mouse.leftClick?(@sprites["itemwindow"]) && @sprites["itemwindow"].visible==true
    if $mouse.inAreaLeft?(239,25,243,288) #itemwindow.index<@bag.pockets[itemwindow.pocket].length && !sorting
    for i in 1...7
    break if sorting
    if $mouse.inAreaLeft?(239,-24+i*48,243,48)
    num=i
    break
    end
    end
    if num
    val=@sprites["itemwindow"].selectedNumber-num
    # Getting the value of the clicked item.
    if @bag.pockets[itemwindow.pocket][@sprites["itemwindow"].index-val]
    item=@bag.pockets[itemwindow.pocket][@sprites["itemwindow"].index-val][0]
    # If clicking on the box for registering an item.
    if $mouse.inAreaPress?(239,33,31,272) && pbIsKeyItem?(item) && ItemHandlers.hasKeyItemHandler(item)
    if pbIsRegisteredItem?(item)
    pbRemoveRegisteredItem(item)
    else
    pbRegisterItem(item)
    end
    pbRefresh
    # If clicking on the panel.
    elsif $mouse.inAreaLeft?(271,25,211,288)
    @sprites["itemwindow"].index-=val
    thispocket=@bag.pockets[itemwindow.pocket]
    pbRefresh
    pbWait(10)
    drawPageTwo
    end
    end
    end
    end
    end
    # Clicking on the pockets.
    pockets=pbPocketNames
    for i in 1..pockets.length
    if $mouse.leftClick?(@sprites["bag_#{i}"]) &&
    !($mouse.leftClick?(@sprites["itemwindow"]) &&
    @sprites["itemwindow"].visible==true) &&
    $mouse.overPixel?(@sprites["bag_#{i}"])
    itemwindow.pocket=i
    @bag.lastpocket=itemwindow.pocket
    showPocketAnimation(itemwindow.pocket) if @page==1
    pbRefresh
    end
    end
    end
    # Confirm selection or item switch
    if Input.trigger?(Input::C)
    thispocket=@bag.pockets[@sprites["itemwindow"].pocket]
    @bag.pockets[itemwindow.pocket]
    if @page==1 && itemwindow.index1
    qty=@scene.pbChooseNumber(_INTL("Toss out how many {1}(s)?",itemname),qty)
    end
    if qty>0
    if pbConfirm(_INTL("Is it OK to throw away {1} {2}(s)?",qty,itemname))
    if !storage.pbDeleteItem(item,qty)
    raise "Can't delete items from storage"
    end
    pbDisplay(_INTL("Threw away {1} {2}(s).",qty,itemname))
    end
    end
    end
    @scene.pbEndScene
    end

    # UI logic for withdrawing an item in the item screen.
    def pbWithdrawItemScreen
    if !$PokemonGlobal.pcItemStorage
    $PokemonGlobal.pcItemStorage=PCItemStorage.new
    end
    storage=$PokemonGlobal.pcItemStorage
    @scene.pbStartScene(storage)
    loop do
    item=@scene.pbChooseItem
    break if item==0
    commands=[_INTL("Withdraw"),_INTL("Give"),_INTL("Cancel")]
    itemname=PBItems.getName(item)
    command=@scene.pbShowCommands(_INTL("{1} is selected.",itemname),commands)
    if command==0
    qty=storage.pbQuantity(item)
    if qty>1
    qty=@scene.pbChooseNumber(_INTL("How many do you want to withdraw?"),qty)
    end
    if qty>0
    if !@bag.pbCanStore?(item,qty)
    pbDisplay(_INTL("There's no more room in the Bag."))
    else
    pbDisplay(_INTL("Withdrew {1} {2}(s).",qty,itemname))
    if !storage.pbDeleteItem(item,qty)
    raise "Can't delete items from storage"
    end
    if !@bag.pbStoreItem(item,qty)
    raise "Can't withdraw items from storage"
    end
    end
    end
    elsif command==1 # Give
    if $Trainer.pokemonCount==0
    @scene.pbDisplay(_INTL("There is no Pokmon."))
    return 0
    elsif pbIsImportantItem?(item)
    @scene.pbDisplay(_INTL("The {1} can't be held.",itemname))
    else
    pbFadeOutIn(99999){
    sscene=PokemonScreen_Scene.new
    sscreen=PokemonScreen.new(sscene,$Trainer.party)
    if sscreen.pbPokemonGiveScreen(item)
    # If the item was held, delete the item from storage
    if !storage.pbDeleteItem(item,1)
    raise "Can't delete item from storage"
    end
    end
    updateBag
    }
    end
    end
    end
    @scene.pbEndScene
    end

    # UI logic for depositing an item in the item screen.
    def pbDepositItemScreen
    @scene.pbStartScene(@bag)
    if !$PokemonGlobal.pcItemStorage
    $PokemonGlobal.pcItemStorage=PCItemStorage.new
    end
    storage=$PokemonGlobal.pcItemStorage
    item=0
    loop do
    item=@scene.pbChooseItem
    break if item==0
    qty=@bag.pbQuantity(item)
    if qty>1
    qty=@scene.pbChooseNumber(_INTL("How many do you want to deposit?"),qty)
    end
    if qty>0
    itemname=PBItems.getName(item)
    if !storage.pbCanStore?(item,qty)
    pbDisplay(_INTL("There's no room to store items."))
    else
    pbDisplay(_INTL("Deposited {1} {2}(s).",qty,itemname))
    if !@bag.pbDeleteItem(item,qty)
    raise "Can't delete items from bag"
    end
    if !storage.pbStoreItem(item,qty)
    raise "Can't deposit items to storage"
    end
    end
    end
    end
    @scene.pbEndScene
    end

    def updateBag
    return if !@scene.sprites["pocketwindow"]
    #bag.pbRefresh
    @scene.drawPageTwo
    end

    def pbStartScreen
    @scene.pbStartScene(@bag)
    item=0
    loop do
    item=@scene.pbChooseItem
    break if item==0
    cmdUse=-1
    cmdRegister=-1
    cmdGive=-1
    cmdToss=-1
    cmdRead=-1
    cmdMysteryGift=-1
    cmdFreeSpace=-1
    commands=[]
    # Generate command list
    commands[cmdRead=commands.length]=_INTL("Read") if pbIsMail?(item)
    commands[cmdUse=commands.length]=_INTL("Use") if ItemHandlers.hasOutHandler(item) || (pbIsMachine?(item) && $Trainer.party.length>0)
    commands[cmdGive=commands.length]=_INTL("Give") if $Trainer.party.length>0 && !pbIsImportantItem?(item)
    commands[cmdToss=commands.length]=_INTL("Toss") if !pbIsImportantItem?(item) || $DEBUG
    if @bag.registeredItem==item || pbIsRegisteredItem?(item)
    commands[cmdRegister=commands.length]=_INTL("Deselect")
    elsif pbIsKeyItem?(item) && ItemHandlers.hasKeyItemHandler(item)
    commands[cmdRegister=commands.length]=_INTL("Register")
    end
    if pbIsInFreeSpace?(item)
    commands[cmdFreeSpace=commands.length]=_INTL("Return to Case")
    else
    commands[cmdFreeSpace=commands.length]=_INTL("To Free Space")
    end
    commands[cmdMysteryGift=commands.length]=_INTL("Make Mystery Gift") if $DEBUG
    commands[commands.length]=_INTL("Cancel")
    # Show commands generated above
    itemname=PBItems.getName(item) # Get item name
    command=@scene.pbShowCommands(_INTL("{1} is selected.",itemname),commands)
    if cmdUse>=0 && command==cmdUse # Use item
    ret=pbUseItem(@bag,item,@scene)
    # 0=Item wasn't used; 1=Item used; 2=Close Bag to use in field
    break if ret==2 # End screen
    updateBag
    next
    elsif cmdRead>=0 && command==cmdRead # Read mail
    pbFadeOutIn(99999){
    pbDisplayMail(PokemonMail.new(item,"",""))
    }
    elsif cmdRegister>=0 && command==cmdRegister # Register key item
    @bag.pbRegisterKeyItem(item)
    #updateBag
    @scene.drawPageTwo
    elsif cmdGive>=0 && command==cmdGive # Give item to Pokmon
    if $Trainer.pokemonCount==0
    @scene.pbDisplay(_INTL("There is no Pokmon."))
    elsif pbIsImportantItem?(item)
    @scene.pbDisplay(_INTL("The {1} can't be held.",itemname))
    else
    # Give item to a Pokmon
    pbFadeOutIn(99999){
    #updateBag
    sscene=PokemonScreen_Scene.new
    sscreen=PokemonScreen.new(sscene,$Trainer.party)
    sscreen.pbPokemonGiveScreen(item)
    }
    updateBag
    end
    elsif cmdToss>=0 && command==cmdToss # Toss item
    qty=@bag.pbQuantity(item)
    helptext=_INTL("Toss out how many {1}(s)?",itemname)
    qty=@scene.pbChooseNumber(helptext,qty)
    if qty>0
    if pbConfirm(_INTL("Is it OK to throw away {1} {2}(s)?",qty,itemname))
    pbDisplay(_INTL("Threw away {1} {2}(s).",qty,itemname))
    qty.times { @bag.pbDeleteItem(item) }
    end
    end
    elsif cmdFreeSpace>=0 && command==cmdFreeSpace
    @scene.moveItemToFreeSpace(item)
    elsif cmdMysteryGift>=0 && command==cmdMysteryGift # Export to Mystery Gift
    pbCreateMysteryGift(1,item)
    end
    end
    @scene.pbEndScene
    return item
    end
    end

    #===============================================================================
    # The Bag object, which actually contains all the items
    #===============================================================================
    class PokemonBag
    attr_reader :registeredItem
    attr_accessor :lastpocket
    attr_reader :pockets

    def self.pocketNames()
    return pbPocketNames
    end

    def self.numPockets()
    return self.pocketNames().length-1
    end

    def initialize
    @lastpocket=1
    @pockets=[]
    @choices=[]
    # Initialize each pocket of the array
    for i in 0..PokemonBag.numPockets
    @pockets[i]=[]
    @choices[i]=0
    end
    @registeredItem=0
    end

    def pockets
    rearrange
    return @pockets
    end

    def rearrange
    if (@pockets.length-1)!=PokemonBag.numPockets
    newpockets=[]
    for i in 0..PokemonBag.numPockets
    newpockets[i]=[]
    @choices[i]=0 if !@choices[i]
    end
    nump=PokemonBag.numPockets
    for i in 0...@pockets.length
    for item in @pockets[i]
    p=pbGetPocket(item[0])
    newpockets[p].push(item) if p<=nump
    end
    end
    @pockets=newpockets
    end
    end

    # Gets the index of the current selected item in the pocket
    def getChoice(pocket)
    if pocket<=0 || pocket>PokemonBag.numPockets
    raise ArgumentError.new(_INTL("Invalid pocket: {1}",pocket.inspect))
    end
    rearrange
    return [@choices[pocket],@pockets[pocket].length].min || 0
    end

    # Clears the entire bag
    def clear
    for pocket in @pockets
    pocket.clear
    end
    end

    # Sets the index of the current selected item in the pocket
    def setChoice(pocket,value)
    if pocket<=0 || pocket>PokemonBag.numPockets
    raise ArgumentError.new(_INTL("Invalid pocket: {1}",pocket.inspect))
    end
    rearrange
    @choices[pocket]=value if value<=@pockets[pocket].length
    end

    # Registers the item as a key item. Can be retrieved with $PokemonBag.registeredItem
    def pbRegisterKeyItem(item)
    if item.is_a?(String) || item.is_a?(Symbol)
    item=getID(PBItems,item)
    end
    if !item || item<1
    raise ArgumentError.new(_INTL("The item number is invalid.",item))
    return
    end
    @registeredItem=(item!=@registeredItem) ? item : 0
    if pbIsRegisteredItem?(item)
    pbRemoveRegisteredItem(item)
    else
    pbRegisterItem(item)
    end
    end

    def maxPocketSize(pocket)
    maxsize=MAXPOCKETSIZE[pocket]
    return -1 if !maxsize
    return maxsize
    end

    def pbQuantity(item)
    if item.is_a?(String) || item.is_a?(Symbol)
    item=getID(PBItems,item)
    end
    if !item || item<1
    raise ArgumentError.new(_INTL("The item number is invalid.",item))
    return 0
    end
    pocket=pbGetPocket(item)
    maxsize=maxPocketSize(pocket)
    maxsize=@pockets[pocket].length if maxsize<0
    return ItemStorageHelper.pbQuantity(@pockets[pocket],maxsize,item)
    end

    def pbDeleteItem(item,qty=1)
    if item.is_a?(String) || item.is_a?(Symbol)
    item=getID(PBItems,item)
    end
    if !item || item<1
    raise ArgumentError.new(_INTL("The item number is invalid.",item))
    return false
    end
    pocket=pbGetPocket(item)
    maxsize=maxPocketSize(pocket)
    maxsize=@pockets[pocket].length if maxsize<0
    ret=ItemStorageHelper.pbDeleteItem(@pockets[pocket],maxsize,item,qty)
    if ret
    @registeredItem=0 if @registeredItem==item && pbQuantity(item)<=0
    end
    return ret
    end

    def pbCanStore?(item,qty=1)
    if item.is_a?(String) || item.is_a?(Symbol)
    item=getID(PBItems,item)
    end
    if !item || item<1
    raise ArgumentError.new(_INTL("The item number is invalid.",item))
    return false
    end
    pocket=pbGetPocket(item)
    maxsize=maxPocketSize(pocket)
    maxsize=@pockets[pocket].length+1 if maxsize<0
    return ItemStorageHelper.pbCanStore?(
    @pockets[pocket],maxsize,BAGMAXPERSLOT,item,qty)
    end

    def pbStoreAllOrNone(item,qty=1)
    if item.is_a?(String) || item.is_a?(Symbol)
    item=getID(PBItems,item)
    end
    if !item || item<1
    raise ArgumentError.new(_INTL("The item number is invalid.",item))
    return false
    end
    pocket=pbGetPocket(item)
    maxsize=maxPocketSize(pocket)
    maxsize=@pockets[pocket].length+1 if maxsize<0
    return ItemStorageHelper.pbStoreAllOrNone(
    @pockets[pocket],maxsize,BAGMAXPERSLOT,item,qty)
    end

    def pbStoreItem(item,qty=1)
    if item.is_a?(String) || item.is_a?(Symbol)
    item=getID(PBItems,item)
    end
    if !item || item<1
    raise ArgumentError.new(_INTL("The item number is invalid.",item))
    return false
    end
    pocket=1
    # Adding Pockets together.
    if pbIsInFreeSpace?(item)
    pocket=6
    elsif pbIsKeyItem?(item)
    pocket=5
    elsif pbIsBerry?(item)
    pocket=4
    elsif pbIsMachine?(item)
    pocket=3
    elsif pbIsMedicineItem?(item) # Medicine
    pocket=2
    end
    maxsize=maxPocketSize(pocket)
    maxsize=@pockets[pocket].length+1 if maxsize<0
    return ItemStorageHelper.pbStoreItem(
    @pockets[pocket],maxsize,BAGMAXPERSLOT,item,qty,true)
    end
    end

    #===============================================================================
    # PC item storage screen
    #===============================================================================
    class Window_PokemonItemStorage < Window_DrawableCommand
    attr_reader :bag
    attr_reader :pocket
    attr_reader :sortIndex

    def sortIndex=(value)
    @sortIndex=value
    refresh
    end

    def initialize(bag,x,y,width,height)
    @bag=bag
    @sortIndex=-1
    @adapter=PokemonMartAdapter.new
    super(x,y,width,height)
    self.windowskin=nil
    end

    def item
    item=@bag[self.index]
    return item ? item[0] : 0
    end

    def itemCount
    return @bag.length+1
    end

    def drawItem(index,count,rect)
    textpos=[]
    rect=drawCursor(index,rect)
    ypos=rect.y
    if index==@bag.length
    textpos.push([_INTL("CANCEL"),rect.x,ypos,false,
    self.baseColor,self.shadowColor])
    else
    item=@bag[index][0]
    itemname=@adapter.getDisplayName(item)
    qty=_ISPRINTF("x{1: 2d}",@bag[index][1])
    sizeQty=self.contents.text_size(qty).width
    xQty=rect.x+rect.width-sizeQty-2
    baseColor=(index==@sortIndex) ? Color.new(248,24,24) : self.baseColor
    textpos.push([itemname,rect.x,ypos,false,self.baseColor,self.shadowColor])
    if !pbIsImportantItem?(item) # Not a Key item or HM (or infinite TM)
    textpos.push([qty,xQty,ypos,false,baseColor,self.shadowColor])
    end
    end
    pbDrawTextPositions(self.contents,textpos)
    end
    end



    class ItemStorageScene
    ## Configuration
    ITEMLISTBASECOLOR = Color.new(88,88,80)
    ITEMLISTSHADOWCOLOR = Color.new(168,184,184)
    ITEMTEXTBASECOLOR = Color.new(248,248,248)
    ITEMTEXTSHADOWCOLOR = Color.new(0,0,0)
    TITLEBASECOLOR = Color.new(248,248,248)
    TITLESHADOWCOLOR = Color.new(0,0,0)
    ITEMSVISIBLE = 7

    def initialize(title)
    @title=title
    end

    def update
    pbUpdateSpriteHash(@sprites)
    end

    def pbStartScene(bag)
    @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
    @viewport.z=99999
    @bag=bag
    @sprites={}
    @sprites["background"]=IconSprite.new(0,0,@viewport)
    @sprites["background"].setBitmap("Graphics/Pictures/pcItembg")
    @sprites["icon"]=IconSprite.new(270,247,@viewport)
    # Item list
    @sprites["itemwindow"]=Window_PokemonItemStorage.new(@bag,98,14,334,32+ITEMSVISIBLE*32) #32
    @sprites["itemwindow"].viewport=@viewport
    @sprites["itemwindow"].index=0
    @sprites["itemwindow"].baseColor=ITEMLISTBASECOLOR
    @sprites["itemwindow"].shadowColor=ITEMLISTSHADOWCOLOR
    @sprites["itemwindow"].refresh
    # Title
    @sprites["pocketwindow"]=BitmapSprite.new(88,64,@viewport)
    @sprites["pocketwindow"].x=14
    @sprites["pocketwindow"].y=16
    pbSetNarrowFont(@sprites["pocketwindow"].bitmap)
    # Item description
    @sprites["itemtextwindow"]=Window_UnformattedTextPokemon.newWithSize("",84,270,Graphics.width-84,128,@viewport)
    @sprites["itemtextwindow"].baseColor=ITEMTEXTBASECOLOR
    @sprites["itemtextwindow"].shadowColor=ITEMTEXTSHADOWCOLOR
    @sprites["itemtextwindow"].windowskin=nil
    @sprites["helpwindow"]=Window_UnformattedTextPokemon.new("")
    @sprites["helpwindow"].visible=false
    @sprites["helpwindow"].viewport=@viewport
    # Letter-by-letter message window
    @sprites["msgwindow"]=Window_AdvancedTextPokemon.new("")
    @sprites["msgwindow"].visible=false
    @sprites["msgwindow"].viewport=@viewport
    pbBottomLeftLines(@sprites["helpwindow"],1)
    pbDeactivateWindows(@sprites)
    pbRefresh
    pbFadeInAndShow(@sprites)
    end

    def pbEndScene
    pbFadeOutAndHide(@sprites)
    pbDisposeSpriteHash(@sprites)
    @viewport.dispose
    end

    def pbRefresh
    bm=@sprites["pocketwindow"].bitmap
    # Draw title at upper left corner ("Toss Item/Withdraw Item")
    drawTextEx(bm,0,0,bm.width,2,@title,TITLEBASECOLOR,TITLESHADOWCOLOR)
    itemwindow=@sprites["itemwindow"]
    # Draw item icon
    filename=pbItemIconFile(itemwindow.item)
    @sprites["icon"].setBitmap(filename)
    # Get item description
    @sprites["itemtextwindow"].text=(itemwindow.item==0) ? _INTL("Close storage.") :
    pbGetMessage(MessageTypes::ItemDescriptions,itemwindow.item)
    itemwindow.refresh
    end

    def pbChooseItem
    pbRefresh
    @sprites["helpwindow"].visible=false
    itemwindow=@sprites["itemwindow"]
    itemwindow.refresh
    pbActivateWindow(@sprites,"itemwindow"){
    loop do
    Graphics.update
    Input.update
    olditem=itemwindow.item
    self.update
    if itemwindow.item!=olditem
    self.pbRefresh
    end
    if Input.trigger?(Input::B)
    return 0
    end
    if Input.trigger?(Input::C)
    if itemwindow.index<@bag.length
    pbRefresh
    return @bag[itemwindow.index][0]
    else
    return 0
    end
    end
    end
    }
    end

    def pbChooseNumber(helptext,maximum)
    return UIHelper.pbChooseNumber(
    @sprites["helpwindow"],helptext,maximum) { update }
    end

    def pbDisplay(msg,brief=false)
    UIHelper.pbDisplay(@sprites["msgwindow"],msg,brief) { update }
    end

    def pbConfirm(msg)
    UIHelper.pbConfirm(@sprites["msgwindow"],msg) { update }
    end

    def pbShowCommands(helptext,commands)
    return UIHelper.pbShowCommands(
    @sprites["helpwindow"],helptext,commands) { update }
    end
    end



    class WithdrawItemScene < ItemStorageScene
    def initialize
    super(_INTL("Withdraw\nItem"))
    end
    end



    class TossItemScene < ItemStorageScene
    def initialize
    super(_INTL("Toss\nItem"))
    end
    end

    #===============================================================================
    # The PC item storage object, which actually contains all the items
    #===============================================================================
    class PCItemStorage
    MAXSIZE = 50 # Number of different slots in storage
    MAXPERSLOT = 999 # Max. number of items per slot

    def initialize
    @items=[]
    # Start storage with a Potion
    if hasConst?(PBItems,:POTION)
    ItemStorageHelper.pbStoreItem(
    @items,MAXSIZE,MAXPERSLOT,getConst(PBItems,:POTION),1)
    end
    end

    def empty?
    return @items.length==0
    end

    def length
    @items.length
    end

    def [](i)
    @items[i]
    end

    def getItem(index)
    if index<0 || index>=@items.length
    return 0
    else
    return @items[index][0]
    end
    end

    def getCount(index)
    if index<0 || index>=@items.length
    return 0
    else
    return @items[index][1]
    end
    end

    def pbQuantity(item)
    return ItemStorageHelper.pbQuantity(@items,MAXSIZE,item)
    end

    def pbDeleteItem(item,qty=1)
    return ItemStorageHelper.pbDeleteItem(@items,MAXSIZE,item,qty)
    end

    def pbCanStore?(item,qty=1)
    return ItemStorageHelper.pbCanStore?(@items,MAXSIZE,MAXPERSLOT,item,qty)
    end

    def pbStoreItem(item,qty=1)
    return ItemStorageHelper.pbStoreItem(@items,MAXSIZE,MAXPERSLOT,item,qty)
    end
    end



    #===============================================================================
    # Common UI functions used in both the Bag and item storage screens.
    # Allows the user to choose a number. The window _helpwindow_ will
    # display the _helptext_.
    #===============================================================================
    module UIHelper
    def self.pbChooseNumber(helpwindow,helptext,maximum)
    oldvisible=helpwindow.visible
    helpwindow.visible=true
    helpwindow.text=helptext
    helpwindow.letterbyletter=false
    curnumber=1
    ret=0
    using(numwindow=Window_UnformattedTextPokemon.new("x000")){
    numwindow.viewport=helpwindow.viewport
    numwindow.letterbyletter=false
    numwindow.text=_ISPRINTF("x{1:03d}",curnumber)
    numwindow.resizeToFit(numwindow.text,480)
    pbBottomRight(numwindow) # Move number window to the bottom right
    helpwindow.resizeHeightToFit(helpwindow.text,480-numwindow.width)
    pbBottomLeft(helpwindow) # Move help window to the bottom left
    loop do
    Graphics.update
    Input.update
    numwindow.update
    block_given? ? yield : helpwindow.update
    if Input.repeat?(Input::LEFT)
    curnumber-=10
    curnumber=1 if curnumber<1
    numwindow.text=_ISPRINTF("x{1:03d}",curnumber)
    pbPlayCursorSE()
    elsif Input.repeat?(Input::RIGHT)
    curnumber+=10
    curnumber=maximum if curnumber>maximum
    numwindow.text=_ISPRINTF("x{1:03d}",curnumber)
    pbPlayCursorSE()
    elsif Input.repeat?(Input::UP)
    curnumber+=1
    curnumber=1 if curnumber>maximum
    numwindow.text=_ISPRINTF("x{1:03d}",curnumber)
    pbPlayCursorSE()
    elsif Input.repeat?(Input::DOWN)
    curnumber-=1
    curnumber=maximum if curnumber<1
    numwindow.text=_ISPRINTF("x{1:03d}",curnumber)
    pbPlayCursorSE()
    elsif Input.trigger?(Input::C)
    ret=curnumber
    pbPlayDecisionSE()
    break
    elsif Input.trigger?(Input::B)
    ret=0
    pbPlayCancelSE()
    break
    end
    end
    }
    helpwindow.visible=oldvisible
    return ret
    end

    def self.pbDisplayStatic(msgwindow,message)
    oldvisible=msgwindow.visible
    msgwindow.visible=true
    msgwindow.letterbyletter=false
    msgwindow.width=Graphics.width
    msgwindow.resizeHeightToFit(message,Graphics.width)
    msgwindow.text=message
    pbBottomRight(msgwindow)
    loop do
    Graphics.update
    Input.update
    if Input.trigger?(Input::B)
    break
    end
    if Input.trigger?(Input::C)
    break
    end
    block_given? ? yield : msgwindow.update
    end
    msgwindow.visible=oldvisible
    Input.update
    end

    # Letter by letter display of the message _msg_ by the window _helpwindow_.
    def self.pbDisplay(helpwindow,msg,brief)
    cw=helpwindow
    cw.letterbyletter=true
    cw.text=msg+"\1"
    pbBottomLeftLines(cw,2)
    oldvisible=cw.visible
    cw.visible=true
    loop do
    Graphics.update
    Input.update
    block_given? ? yield : cw.update
    if brief && !cw.busy?
    cw.visible=oldvisible
    return
    end
    if Input.trigger?(Input::C) && cw.resume && !cw.busy?
    cw.visible=oldvisible
    return
    end
    end
    end

    # Letter by letter display of the message _msg_ by the window _helpwindow_,
    # used to ask questions. Returns true if the user chose yes, false if no.
    def self.pbConfirm(helpwindow,msg)
    dw=helpwindow
    oldvisible=dw.visible
    dw.letterbyletter=true
    dw.text=msg
    dw.visible=true
    pbBottomLeftLines(dw,2)
    commands=[_INTL("Yes"),_INTL("No")]
    cw = Window_CommandPokemon.new(commands)
    cw.viewport=helpwindow.viewport
    pbBottomRight(cw)
    cw.y-=dw.height
    cw.index=0
    loop do
    cw.visible=!dw.busy?
    Graphics.update
    Input.update
    cw.update
    block_given? ? yield : dw.update
    if Input.trigger?(Input::B) && dw.resume && !dw.busy?
    cw.dispose
    dw.visible=oldvisible
    pbPlayCancelSE()
    return false
    end
    if Input.trigger?(Input::C) && dw.resume && !dw.busy?
    cwIndex=cw.index
    cw.dispose
    dw.visible=oldvisible
    pbPlayDecisionSE()
    return (cwIndex==0)?true:false
    end
    end
    end

    def self.pbShowCommands(helpwindow,helptext,commands)
    ret=-1
    oldvisible=helpwindow.visible
    helpwindow.visible=helptext ? true : false
    helpwindow.letterbyletter=false
    helpwindow.text=helptext ? helptext : ""
    cmdwindow=Window_CommandPokemon.new(commands)
    begin
    cmdwindow.viewport=helpwindow.viewport
    pbBottomRight(cmdwindow)
    helpwindow.resizeHeightToFit(helpwindow.text,480-cmdwindow.width)
    pbBottomLeft(helpwindow)
    loop do
    Graphics.update
    Input.update
    yield
    cmdwindow.update
    if Input.trigger?(Input::B)
    ret=-1
    pbPlayCancelSE()
    break
    end
    if Input.trigger?(Input::C)
    ret=cmdwindow.index
    pbPlayDecisionSE()
    break
    end
    end
    ensure
    cmdwindow.dispose if cmdwindow
    end
    helpwindow.visible=oldvisible
    return ret
    end
    end
    Reply With Quote

    Relevant Advertising!

    Reply

    Quick Reply

    Join the conversation!

    Create an account to post a reply in this thread, participate in other discussions, and more!

    Create a PokéCommunity Account

    Sponsored Links
    Thread Tools

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off

    Forum Jump


    All times are GMT -8. The time now is 10:32 AM.