(include "sci.sh")
(use "Main")
(use "Class_255_0")
(use "Obj")
(script 995)


(local
    newDButton

)
(class InvI
    (properties
        said 0
        description 0
        owner 0
        view 0
        loop 0
        cel 0
        script 0
    )

    (method (saidMe)
        Said(said)
    )


    (method (ownedBy param1)
        return == owner param1
    )


    (method (showSelf)
        proc255_1(
            (if (description)
            )(else
                name
            )
 view loop cel)
    )


    (method (moveTo theOwner)
        = owner theOwner
        return self
    )


    (method (changeState newState)
        (if (script)
            (send script:changeState(newState))
        )
    )

)
(class Inv of Set
    (properties
        elements 0
        size 0
        carrying "You are carrying:"
        empty "You are carrying nothing!"
    )

    (method (init)
        = gInv self
    )


    (method (showSelf param1)
        (invD:
            text(carrying)
            doit(param1)
        )
    )


    (method (saidMe)
        (self:firstTrue(286))
    )


    (method (ownedBy param1)
        (self:firstTrue(288 param1))
    )

)
(instance invD of Dialog
    (properties)

    (method (init param1)
        (var temp0, temp1, temp2, temp3, newDText, gInvFirst, temp6)
        = temp2 (= temp0 (= temp1 4))
        = temp3 0
        = gInvFirst (send gInv:first())
        (while (gInvFirst)
            (if ((send (= temp6 NodeValue(gInvFirst)):ownedBy(param1)))
                ++temp3
                (self:add((send ((= newDText (DText:new()))):
                        value(temp6)
                        text((send temp6:name()))
                        nsLeft(temp0)
                        nsTop(temp1)
                        state(3)
                        font(global23)
                        setSize()
                        yourself()
                    )
))
                (if (< temp2 (- (send newDText:nsRight()) (send newDText:nsLeft())))
                    = temp2 (- (send newDText:nsRight()) (send newDText:nsLeft()))
                )
                (if (> (= temp1 (+ temp1 (+ (- (send newDText:nsBottom()) (send newDText:nsTop())) 1))) 140)
                    = temp1 4
                    = temp0 (+ temp0 (+ temp2 10))
                    = temp2 0
                )
            )
            = gInvFirst (send gInv:next(gInvFirst))
        )
        (if (not temp3)
            (self:dispose())
            return 0
        )
        (self:setSize())
        = newDButton (DButton:new())
        (send newDButton:
            text("OK")
            setSize()
            moveTo(- nsRight (+ 4 (send newDButton:nsRight())) nsBottom)
        )
        (send newDButton:move((- (send newDButton:nsLeft()) (send newDButton:nsRight())) 0))
        (self:
            add(newDButton)
            setSize()
            center()
        )
        return temp3
    )


    (method (doit param1)
        (var theNewDButton)
        (if (not (self:init(param1)))
            Print((send gInv:empty()))
            return 
        )
        (self:open(4 15))
        = theNewDButton newDButton
        (while (TRUE)
            (if ((not (= theNewDButton (super:doit(theNewDButton))) or (== theNewDButton -1)) or (== theNewDButton newDButton))
                break
            )
            (send ((send theNewDButton:value())):showSelf())
        )
        (self:dispose())
    )


    (method (handleEvent pEvent)
        (var pEventMessage, pEventType)
        = pEventMessage (send pEvent:message())
        (switch (= pEventType (send pEvent:type()))
            (case 4
                (
                (switch (pEventMessage)
                    (case 18432
                        (= pEventMessage 3840  )
                    )
                    (case 20480
                        (= pEventMessage 9 )
                    )
                )
  )
            )
            (case 64
                (
                (switch (pEventMessage)
                    (case 1
                        (= pEventMessage 3840 = pEventType 4  )
                    )
                    (case 5
                        (= pEventMessage 9 = pEventType 4 )
                    )
                )
 )
            )
        )
        (send pEvent:
            type(pEventType)
            message(pEventMessage)
        )
        (super:handleEvent(pEvent))
    )

)
