(version 2)
(include "sci.sh")
(exports
    0 proc921_0
    1 proc921_1
    2 proc921_2
    3 proc921_3
)
(use "Main")
(use "Class_255_0")
(use "DIcon")
(use "Obj")
(script 921)



(procedure public (proc921_0 param1)
    (Print:
        addText(rest param1)
        init()
    )
)


(procedure public (proc921_1 param1)
    (Print:
        addTextF(rest param1)
        init()
    )
)


(procedure public (proc921_2 param1 param2 param3 param4)
    (if ((Print:
        font(
            (if (> paramTotal 3)
                param4
            )(else
                0
            )
)
        addText(
            (if ((> paramTotal 2) and param3)
                param3
            )(else
                ""
            )
)
        addEdit(param1 param2 0 12 param1)
        init()
    )
)
        StrLen(param1)
    )
)


(procedure public (proc921_3 param1 param2)
    (var temp0, temp1, temp2, temp3)
    = temp1 StrLen(param1)
    = temp0 temp1
    = temp2 0
    = temp3 0
    (while (< temp3 temp1)
        (if (== StrAt(param1 temp3) 37)
            (switch (StrAt(param1 ++temp3))
                (case 100
                    = temp0 (+ temp0 5)
                )
                (case 120
                    = temp0 (+ temp0 4)
                )
                (case 115
                    = temp0 (+ temp0 StrLen(param2[temp2]))
                )
            )
            ++temp2
        )
        ++temp3
    )
    return ++temp0
)


(class Print of Obj
    (properties
        dialog 0
        window 0
        title 0
        mode 0
        font 0
        width 0
        x -1
        y -1
        ticks 0
        caller 0
        retValue 0
        modeless 0
        first 0
        saveCursor 0
    )

    (method (init theCaller param2)
        = caller 0
        (if (paramTotal)
            = caller theCaller
        )
        (if (> paramTotal 1)
            (self:addText(rest param2))
        )
        (if (not modeless)
            (if (not IsObject(global92))
                = global92 (send ((EventHandler:new())):name("prints"))
            )
            (send global92:add(self))
        )
        (self:showSelf())
    )


    (method (doit)
        (send dialog:eachElementDo(57))
    )


    (method (dispose)
        (if (global92 and (send global92:contains(self)))
            (send global92:delete(self))
            (if ((send global92:isEmpty()))
                (send global92:dispose())
                = global92 0
            )
        )
        (if (title)
            Memory(3 title)
        )
        = title (= first (= saveCursor (= window 0)))
        = font gFont
        = width (= mode 0)
        = x (= y -1)
        = modeless 0
        (send gSounds:pause(0))
        (super:dispose())
    )


    (method (showSelf)
        (var theFirst, temp1, temp2, temp3, temp4)
        (if (saveCursor)
            (send gGame:setCursor(999))
        )
        (if (not dialog)
            = dialog (Dialog:new())
        )
        (send dialog:
            window(
                (if (window)
                )(else
                    gGloryWindow
                )
)
            name("PODialog")
            caller(self)
        )
        (send dialog:
            text(title)
            time(ticks)
            setSize()
        )
        (send dialog:center())
        = temp3 
            (if (== x -1)
                (send dialog:nsLeft)
            )(else
                x
            )
        = temp4 
            (if (== y -1)
                (send dialog:nsTop)
            )(else
                y
            )
        (send dialog:moveTo(temp3 temp4))
        = temp1 GetPort()
        (send dialog:open(
            (if (title)
                4
            )(else
                0
            )
 15))
        return 
            (if (modeless)
                = global41 GetPort()
                SetPort(temp1)
                = gDialog dialog
            )(else
                (send gSounds:pause(1))
                = theFirst first
                (if (not theFirst)
                    = theFirst (send dialog:firstTrue(#checkState 1))
                    (if (theFirst and not (send dialog:firstTrue(#checkState 2)))
                        (send theFirst:state((| (send theFirst:state) $0002)))
                    )
                )(else
                    (if (not IsObject(theFirst))
                        = theFirst (send dialog:at(theFirst))
                    )
                )
                = retValue (send dialog:doit(theFirst))
                SetPort(temp1)
                (if (== retValue -1)
                    = retValue 0
                )(else
                    (if (IsObject(retValue) and (send retValue:isKindOf(DButton)))
                        = retValue (send retValue:value)
                    )(else
                        (if (not (send dialog:theItem))
                            = retValue 1
                        )
                    )
                )
                (if (saveCursor)
                    (send gGame:setCursor((send ((send gMainIconBar:curIcon)):cursor)))
                )
                (send dialog:dispose())
                return retValue
            )
    )


    (method (addButton param1 theTheGClientModNum)
        (var theTheTheGClientModNum, theTheTheGClientModNum_2, theTheTheGClientModNum_3, temp3, theTheTheGClientModNum_4, theTheTheGClientModNum_5, theGClientModNum, temp7, temp8)
        (if (not dialog)
            = dialog (Dialog:new())
        )
        (if (> paramTotal 4)
            = theTheTheGClientModNum theTheGClientModNum[0]
            = theTheTheGClientModNum_2 theTheGClientModNum[1]
            = theTheTheGClientModNum_3 theTheGClientModNum[2]
            = temp3 
                (if (theTheGClientModNum[3])
                    theTheGClientModNum[3]
                )(else
                    1
                )
            = theTheTheGClientModNum_4 0
            = theTheTheGClientModNum_5 0
            = theGClientModNum gClientModNum
            (if (> paramTotal 5)
                = theTheTheGClientModNum_4 theTheGClientModNum[4]
                (if (> paramTotal 6)
                    = theTheTheGClientModNum_5 theTheGClientModNum[5]
                    (if (> paramTotal 7)
                        = theGClientModNum theTheGClientModNum[6]
                    )
                )
            )
            = temp8 Message(2 theGClientModNum theTheTheGClientModNum theTheTheGClientModNum_2 theTheTheGClientModNum_3 temp3)
            (if (temp8)
                = temp7 Memory(1 (= temp8 Message(2 theGClientModNum theTheTheGClientModNum theTheTheGClientModNum_2 theTheTheGClientModNum_3 temp3)))
                (if (not Message(0 theGClientModNum theTheTheGClientModNum theTheTheGClientModNum_2 theTheTheGClientModNum_3 temp3 temp7))
                    = temp7 0
                )
            )
        )(else
            = theTheTheGClientModNum_4 0
            = theTheTheGClientModNum_5 0
            (if (> paramTotal 2)
                = theTheTheGClientModNum_4 theTheGClientModNum[1]
                (if (> paramTotal 3)
                    = theTheTheGClientModNum_5 theTheGClientModNum[2]
                )
            )
            = temp7 Memory(1 (+ StrLen(theTheGClientModNum[0]) 1))
            StrCpy(temp7 theTheGClientModNum[0])
        )
        (if (temp7)
            (send dialog:
                add((send ((DButton:new())):
                        value(param1)
                        font(font)
                        text(temp7)
                        setSize()
                        moveTo(+ 4 theTheTheGClientModNum_4 + 4 theTheTheGClientModNum_5)
                        yourself()
                    )
)
                setSize()
            )
        )
    )


    (method (addEdit param1 param2 param3 param4 param5)
        (var temp0, temp1)
        (if (not dialog)
            = dialog (Dialog:new())
        )
        StrCpy(param1 
            (if (> paramTotal 4)
                param5
            )(else
                ""
            )
)
        (if (> paramTotal 2)
            = temp0 param3
            (if (> paramTotal 3)
                = temp1 param4
            )
        )
        (send dialog:
            add((send ((DEdit:new())):
                    text(param1)
                    max(param2)
                    setSize()
                    moveTo(+ temp0 4 + temp1 4)
                    yourself()
                )
)
            setSize()
        )
    )


    (method (addIcon param1 param2 param3 param4 param5)
        (var temp0, temp1)
        (if (not dialog)
            = dialog (Dialog:new())
        )
        (if (> paramTotal 3)
            = temp0 param4
            = temp1 param5
        )(else
            = temp1 0
            = temp0 temp1
        )
        (if (IsObject(param1))
            (send dialog:
                add((send param1:
                        setSize()
                        moveTo(+ temp0 4 + temp1 4)
                        yourself()
                    )
)
                setSize()
            )
        )(else
            (send dialog:
                add((send ((DIcon:new())):
                        view(param1)
                        loop(param2)
                        cel(param3)
                        setSize()
                        moveTo(+ temp0 4 + temp1 4)
                        yourself()
                    )
)
                setSize()
            )
        )
    )


    (method (addText theTheGClientModNum)
        (var theTheTheGClientModNum, theTheTheGClientModNum_2, theTheTheGClientModNum_3, temp3, theTheTheGClientModNum_4, theTheTheGClientModNum_5, theGClientModNum, temp7, temp8)
        (if (not dialog)
            = dialog (Dialog:new())
        )
        (if (> paramTotal 3)
            = theTheTheGClientModNum theTheGClientModNum[0]
            = theTheTheGClientModNum_2 theTheGClientModNum[1]
            = theTheTheGClientModNum_3 theTheGClientModNum[2]
            = temp3 
                (if (theTheGClientModNum[3])
                    theTheGClientModNum[3]
                )(else
                    1
                )
            = theTheTheGClientModNum_4 0
            = theTheTheGClientModNum_5 0
            = theGClientModNum gClientModNum
            (if (>= paramTotal 5)
                = theTheTheGClientModNum_4 theTheGClientModNum[4]
                (if (>= paramTotal 6)
                    = theTheTheGClientModNum_5 theTheGClientModNum[5]
                    (if (>= paramTotal 7)
                        = theGClientModNum theTheGClientModNum[6]
                    )
                )
            )
            = temp8 Message(2 theGClientModNum theTheTheGClientModNum theTheTheGClientModNum_2 theTheTheGClientModNum_3 temp3)
            (if (temp8)
                = temp7 Memory(1 (= temp8 Message(2 theGClientModNum theTheTheGClientModNum theTheTheGClientModNum_2 theTheTheGClientModNum_3 temp3)))
                (if (Message(0 theGClientModNum theTheTheGClientModNum theTheTheGClientModNum_2 theTheTheGClientModNum_3 temp3 temp7))
                    (send dialog:
                        add((send ((DText:new())):
                                text(temp7)
                                font(font)
                                mode(mode)
                                setSize(width)
                                moveTo(+ 4 theTheTheGClientModNum_4 + 4 theTheTheGClientModNum_5)
                                yourself()
                            )
)
                        setSize()
                    )
                )
            )
        )(else
            = theTheTheGClientModNum_4 0
            = theTheTheGClientModNum_5 0
            (if (>= paramTotal 2)
                = theTheTheGClientModNum_4 theTheGClientModNum[1]
                (if (>= paramTotal 3)
                    = theTheTheGClientModNum_5 theTheGClientModNum[2]
                )
            )
            = temp7 Memory(1 (+ StrLen(theTheGClientModNum[0]) 1))
            StrCpy(temp7 theTheGClientModNum[0])
            (send dialog:
                add((send ((DText:new())):
                        text(temp7)
                        font(font)
                        mode(mode)
                        setSize(width)
                        moveTo(+ 4 theTheTheGClientModNum_4 + 4 theTheTheGClientModNum_5)
                        yourself()
                    )
)
                setSize()
            )
        )
    )


    (method (addTextF param1)
        (var temp0, temp1)
        = temp0 proc921_3(rest param1)
        = temp1 Memory(1 temp0)
        Format(temp1 rest param1)
        (self:addText(temp1))
        Memory(3 temp1)
    )


    (method (addTitle param1)
        (var temp0, temp1, temp2, temp3, temp4, temp5)
        (if (> paramTotal 1)
            = temp0 param1[0]
            = temp1 param1[1]
            = temp2 param1[2]
            = temp3 param1[3]
            = temp4 param1[4]
            proc921_1("%d: %d %d %d %d" temp4 temp0 temp1 temp2 temp3)
            = temp5 Message(2 temp4 temp0 temp1 temp2 temp3)
            (if (temp5)
                = title Memory(1 (= temp5 Message(2 temp4 temp0 temp1 temp2 temp3)))
                Message(0 temp4 temp0 temp1 temp2 temp3 title)
            )
        )(else
            = title Memory(1 (+ StrLen(param1[0]) 1))
            StrCpy(title param1[0])
        )
    )


    (method (posn theX theY)
        = x theX
        = y theY
    )


    (method (handleEvent pEvent)
        (if ((send dialog:handleEvent(pEvent)))
            (send dialog:dispose())
        )
    )


    (method (cue)
        (var theCaller)
        = theCaller caller
        = dialog 0
        (if (window)
            (send window:dispose())
        )
        (self:dispose())
        (if (theCaller)
            (send theCaller:cue())
        )
    )

)
