(include "sci.sh")
(use "Main")
(use "Sound")
(use "Obj")
(script 255)


(local
    local0
    local1[20]

)
(procedure public (Print param1)
    (var newDialog, newDText, newDIcon, newDEdit, temp4, temp5, temp6, temp7, temp8, theGTheNewDialog, temp10, temp11, newDButton[6], temp18, temp19, temp20, temp21[1000])
    = temp11 GetPort()
    = temp6 (= temp7 -1)
    = theGTheNewDialog (= temp8 (= temp18 (= newDIcon (= newDEdit (= temp19 0)))))
    = newDButton[0] (= newDButton[1] (= newDButton[2] (= newDButton[3] (= newDButton[4] (= newDButton[5] 0)))))
    = newDialog (Dialog:new())
    = newDText (DText:new())
    (if (<u param1[0] 1000)
        GetFarText(param1[0] param1[1] @temp21)
        = temp5 2
    )(else
        (if (param1[0])
            StrCpy(@temp21 param1[0])
            = temp5 1
        )(else
            = temp21 0
            = temp5 0
        )
    )
    (send newDText:
        text(@temp21)
        moveTo(4 4)
        font(global22)
        setSize()
    )
    (send newDialog:
        name("PrintD")
        add(newDText)
    )
    = temp5 temp5
    (while (< temp5 paramTotal)
        (switch (param1[temp5])
            (case 60
                ((send newDText:mode(param1[++temp5]))  )
            )
            (case 66
                ((send newDText:
                    font(param1[++temp5])
                    setSize(temp8)
                )
  )
            )
            (case 140
                (= temp8 param1[++temp5] (send newDText:setSize(temp8))  )
            )
            (case 50
                ((send newDialog:time(param1[++temp5]))  )
            )
            (case 160
                ((send newDialog:text(param1[++temp5]))  )
            )
            (case 134
                (= temp6 param1[++temp5] = temp7 param1[++temp5]  )
            )
            (case 166
                (Animate((send gCast:elements()) 0)  )
            )
            (case 82
                ((send (= newDEdit (DEdit:new())):text(param1[++temp5])) (send newDEdit:
                    max(param1[++temp5])
                    setSize()
                )
  )
            )
            (case 162
                ((send (= newDButton[temp19] (DButton:new())):
                    text(param1[++temp5])
                    value(param1[++temp5])
                    setSize()
                )
 = temp18 (+ temp18 (+ (send newDButton[temp19]:nsRight()) 4)) ++temp19  )
            )
            (case 164
                (= newDIcon (DIcon:new()) (send newDIcon:view(param1[++temp5])) (send newDIcon:loop(param1[++temp5])) (send newDIcon:cel(param1[++temp5])) (send newDIcon:setSize())  )
            )
            (case 172
                (
                (if (gTheNewDialog)
                    (send gTheNewDialog:dispose())
                )
 = theGTheNewDialog newDialog )
            )
        )
        ++temp5
    )
    (if (newDIcon)
        (send newDIcon:moveTo(4 4))
        (send newDText:moveTo((+ 4 (send newDIcon:nsRight())) (send newDText:nsTop())))
        (send newDialog:add(newDIcon))
    )
    (send newDialog:setSize())
    (if (newDEdit)
        (send newDEdit:moveTo((send newDText:nsLeft()) (+ 4 (send newDText:nsBottom()))))
        (send newDialog:
            add(newDEdit)
            setSize()
        )
    )
    = temp20 
        (if (> temp18 (send newDialog:nsRight()))
            4
        )(else
            (- (send newDialog:nsRight()) temp18)
        )
    = temp5 0
    (while (newDButton[temp5])
        (send newDButton[temp5]:moveTo(temp20 (send newDialog:nsBottom())))
        (send newDialog:add(newDButton[temp5]))
        = temp20 (+ 4 (send newDButton[temp5]:nsRight()))
        ++temp5
    )
    (send newDialog:
        setSize()
        center()
    )
    (if (newDIcon and not StrLen(@temp21))
        (send newDIcon:moveTo((/ (- (- (send newDialog:nsRight()) (send newDialog:nsLeft())) (- (send newDIcon:nsRight()) (send newDIcon:nsLeft()))) 2) 4))
    )
    (send newDialog:moveTo(
        (if (== -1 temp6)
            (send newDialog:nsLeft())
        )(else
            temp6
        )
 
        (if (== -1 temp7)
            (send newDialog:nsTop())
        )(else
            temp7
        )
))
    (send newDialog:open(
        (if ((send newDialog:text()))
            4
        )(else
            0
        )
 
        (if (theGTheNewDialog)
            15
        )(else
            -1
        )
))
    (if (theGTheNewDialog)
        = local0 GetPort()
        SetPort(temp11)
        return = gTheNewDialog theGTheNewDialog
    )
    (if ((= temp10 (send newDialog:firstTrue(268 1))) and not (send newDialog:firstTrue(268 2)))
        (send temp10:state((| (send temp10:state()) $0002)))
    )
    (if (== (= temp4 (send newDialog:doit(temp10))) -1)
        = temp4 0
    )
    = temp5 0
    (while (newDButton[temp5])
        (if (== temp4 newDButton[temp5])
            break
        )
        ++temp5
    )
    (send newDialog:dispose())
    return temp4
)


(procedure public (proc255_1 param1 param2 param3 param4 param5)
    Print(param1 164 param2 param3 param4 rest)
)


(procedure public (proc255_2 param1 param2 param3 param4)
    (var temp0[2], temp2, temp3)
    = temp3 (Sound:pause(1))
    = temp2 Print(
            (if (>= paramTotal 3)
                param3
            )(else
                ""
            )
 82 param1 param2 rest)
    (Sound:pause(temp3))
    return temp2
)


(procedure public (proc255_3 param1 param2)
    (var temp0[40])
    = temp0 0
    (if (> paramTotal 1)
        Format(@temp0 255 0 param2)
    )
    return 
        (if (proc255_2(@temp0 5 param1))
            ReadNumber(@temp0)
        )(else
            -1
        )
)


(procedure public (proc255_4 param1)
    (var temp0[500])
    Format(@temp0 rest)
    Print(@temp0)
)


(procedure (localproc_0016)
    (var newEvent, temp1)
    = temp1 (<> (send ((= newEvent (Event:new()))):type()) 2)
    (send newEvent:dispose())
    return temp1
)


(class Class_255_0
    (properties
        type 0
        state 0
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        key 0
        said 0
        value 0
    )

    (method (new)
        Clone(self)
    )


    (method (dispose)
        DisposeClone(self)
    )


    (method (enable param1)
        (if ((== paramTotal 0) or param1)
            = state (| state $0001)
        )(else
            = state (& state $fffe)
        )
    )


    (method (select param1)
        (if ((== paramTotal 0) or param1)
            = state (| state $0008)
        )(else
            = state (& state $fff7)
        )
    )


    (method (handleEvent pEvent)
        (var temp0, pEventType, temp2)
        (if ((send pEvent:claimed()))
            return 0
        )
        = temp0 0
        (if ((& state $0001) and ((((== (= pEventType (send pEvent:type())) 128) and Said(said)) or ((== pEventType 4) and (== (send pEvent:message()) key))) or ((== pEventType 1) and (self:check(pEvent)))))
            (send pEvent:claimed(1))
            = temp0 (self:track(pEvent))
        )
        return temp0
    )


    (method (check param1)
        return 
            (if (((>= (send param1:x()) nsLeft) and (>= (send param1:y()) nsTop)) and (< (send param1:x()) nsRight))
                < (send param1:y()) nsBottom
            )(else
                0
            )
    )


    (method (track param1)
        (var temp0, temp1)
        return 
            (if (== 1 (send param1:type()))
                = temp1 0
                (do 
                    = param1 (Event:new(32768))
                    GlobalToLocal(param1)
                    (if (<> (= temp0 (self:check(param1))) temp1)
                        HiliteControl(self)
                        = temp1 temp0
                    )
                    (send param1:dispose())
                ) while (not not localproc_0016())
                (if (temp0)
                    HiliteControl(self)
                )
                return temp0
            )(else
                return self
            )
    )


    (method (doit)
        return self
    )


    (method (yourself)
        return self
    )

)
(class Class_255_1 of Obj
    (properties
        state 0
    )

    (method (draw)
        = state 1
        DrawMenuBar(1)
    )


    (method (hide)
        DrawMenuBar(0)
    )


    (method (handleEvent pEvent)
        return 
            (if (state)
                MenuSelect(pEvent)
            )(else
                0
            )
    )


    (method (add param1)
        AddMenu(rest)
    )

)
(class DItem of Class_255_0
    (properties
        type 0
        state 0
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        key 0
        said 0
        value 0
    )

    (method (select param1)
        (super:select(param1))
        (self:draw())
    )


    (method (doit)
        return value
    )


    (method (setSize)
    )


    (method (move param1 param2)
        = nsRight (+ nsRight param1)
        = nsLeft (+ nsLeft param1)
        = nsTop (+ nsTop param2)
        = nsBottom (+ nsBottom param2)
    )


    (method (moveTo param1 param2)
        (self:move((- param1 nsLeft) (- param2 nsTop)))
    )


    (method (draw)
        DrawControl(self)
    )


    (method (isType param1)
        return == type param1
    )


    (method (checkState param1)
        return & state param1
    )

)
(class DText of DItem
    (properties
        type 2
        state 0
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        key 0
        said 0
        value 0
        text 0
        font 1
        mode 0
    )

    (method (new)
        (var newSuper)
        (send (= newSuper (super:new())):font(global22))
        return newSuper
    )


    (method (setSize param1)
        (var temp0[4])
        TextSize(@temp0[0] text font 
            (if (paramTotal)
                param1
            )(else
                0
            )
)
        = nsBottom (+ nsTop temp0[2])
        = nsRight (+ nsLeft temp0[3])
    )

)
(class DIcon of DItem
    (properties
        type 4
        state 0
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        key 0
        said 0
        value 0
        view 0
        loop 0
        cel 0
    )

    (method (setSize)
        (var temp0[4])
        = nsRight (+ nsLeft CelWide(view loop cel))
        = nsBottom (+ nsTop CelHigh(view loop cel))
    )

)
(class DButton of DItem
    (properties
        type 1
        state 3
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        key 0
        said 0
        value 0
        text 0
        font 0
    )

    (method (setSize)
        (var temp0[4])
        = temp0[2] (+ temp0[2] TextSize(@temp0[0] text font))
        = temp0[3] (+ temp0[3] 2)
        = nsBottom (+ nsTop temp0[2])
        = temp0[3] (* (/ (+ temp0[3] 15) 16) 16)
        = nsRight (+ temp0[3] nsLeft)
    )

)
(class DEdit of DItem
    (properties
        type 3
        state 1
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        key 0
        said 0
        value 0
        text 0
        font 0
        max 0
        cursor 0
    )

    (method (track param1)
        EditControl(self param1)
        return self
    )


    (method (setSize)
        (var temp0[4])
        TextSize(@temp0[0] "M" font)
        = nsBottom (+ nsTop temp0[2])
        = nsRight (+ nsLeft (/ (* (* temp0[3] max) 3) 4))
        = cursor StrLen(text)
    )

)
(class DSelector of DItem
    (properties
        type 6
        state 0
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        key 0
        said 0
        value 0
        font 0
        x 20
        y 6
        text 0
        cursor 0
        lsTop 0
        mark 0
    )

    (method (handleEvent pEvent)
        (var temp0, temp1[3], temp4, temp5[4])
        (if ((send pEvent:claimed()))
            return 0
        )
        (if (== 64 (send pEvent:type()))
            (send pEvent:type(4))
            (switch ((send pEvent:message()))
                (case 5
                    (send pEvent:message(20480))
                )
                (case 1
                    (send pEvent:message(18432))
                )
                (default 
                    (send pEvent:type(64))
                )
            )
        )
        = temp0 0
        (switch ((send pEvent:type()))
            (case 4
                ((send pEvent:claimed(1)) 
                (switch ((send pEvent:message()))
                    (case 18176
                        ((self:retreat(50))  )
                    )
                    (case 20224
                        ((self:advance(50))  )
                    )
                    (case 20736
                        ((self:advance((- y 1)))  )
                    )
                    (case 18688
                        ((self:retreat((- y 1)))  )
                    )
                    (case 20480
                        ((self:advance(1))  )
                    )
                    (case 18432
                        ((self:retreat(1))  )
                    )
                    (default 
                        ((send pEvent:claimed(0)) )
                    )
                )
  )
            )
            (case 1
                (
                (if ((self:check(pEvent)))
                    (send pEvent:claimed(1))
                    (if (< (send pEvent:y()) (+ nsTop 10))
                        (do 
                            (self:retreat(1))
                        ) while (not not localproc_0016())
                    )(else
                        (if (> (send pEvent:y()) (- nsBottom 10))
                            (do 
                                (self:advance(1))
                            ) while (not not localproc_0016())
                        )(else
                            TextSize(@temp5[0] "M" font)
                            (if (> (= temp4 (/ (- (send pEvent:y()) (+ nsTop 10)) temp5[2])) mark)
                                (self:advance((- temp4 mark)))
                            )(else
                                (self:retreat((- mark temp4)))
                            )
                        )
                    )
                )
 )
            )
        )
        return 
            (if ((send pEvent:claimed()))
                self
            )(else
                0
            )
    )


    (method (setSize)
        (var temp0[4])
        TextSize(@temp0[0] "M" font)
        = nsBottom (+ (+ nsTop 20) (* temp0[2] y))
        = nsRight (+ nsLeft (/ (* (* temp0[3] x) 3) 4))
        = lsTop (= cursor text)
        = mark 0
    )


    (method (indexOf param1)
        (var theText, temp1)
        = theText text
        = temp1 0
        return (while (< temp1 300)
                (if (== 0 StrLen(theText))
                    return -1
                )
 
                (if (not StrCmp(param1 theText))
                    return temp1
                )
 = theText (+ theText x) ++temp1  )
    )


    (method (at param1)
        (var theText, temp1)
        = theText (+ (= theText text) (* x param1))
    )


    (method (advance param1)
        (var temp0)
        = temp0 0
        (while (param1 and kernel[102](cursor x))
            = temp0 1
            = cursor (+ cursor x)
            (if (< (+ mark 1) y)
                ++mark
            )(else
                = lsTop (+ lsTop x)
            )
            --param1
        )
        (if (temp0)
            (self:draw())
        )
    )


    (method (retreat param1)
        (var temp0)
        = temp0 0
        (while (param1 and (<> cursor text))
            = temp0 1
            = cursor (- cursor x)
            (if (mark)
                --mark
            )(else
                = lsTop (- lsTop x)
            )
            --param1
        )
        (if (temp0)
            (self:draw())
        )
    )

)
(class Dialog of List
    (properties
        elements 0
        size 0
        text 0
        window 0
        theItem 0
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        time 0
        timer 0
        busy 0
    )

    (method (doit param1)
        (var temp0, temp1, temp2, temp3, temp4)
        (asm
            ldi     0
            sat     temp0
            ldi     1
            aTop    busy
            pToa    theItem
            bnt     code_095c
            pushi   #select
            pushi   1
            pushi   0
            send    6
code_095c:  lap     paramTotal
            bnt     code_096b
            lap     param1
            bnt     code_096b
            lap     param1
            jmp     code_0975
code_096b:  pushi   #firstTrue
            pushi   2
            pushi   268
            pushi   1
            self    8
code_0975:  aTop    theItem
            pToa    theItem
            bnt     code_0983
            pushi   #select
            pushi   1
            pushi   1
            send    6
code_0983:  pToa    theItem
            not     
            bnt     code_0996
            ldi     60
            sat     temp3
            pushi   0
            callk   GetTime, 0
            sat     temp4
            jmp     code_099a
code_0996:  ldi     0
            sat     temp3
code_099a:  ldi     0
            sat     temp2
code_099e:  lat     temp2
            not     
            bnt     code_0a21
            pushi   1
            pushi   #new
            pushi   0
            class   Event
            send    4
            sat     temp1
            push    
            callk   GlobalToLocal, 2
            lat     temp3
            bnt     code_09e6
            -at     temp3
            pushi   #type
            pushi   0
            lat     temp1
            send    4
            push    
            ldi     1
            eq?     
            bnt     code_09d0
            pushi   #type
            pushi   1
            pushi   0
            lat     temp1
            send    6
code_09d0:  lst     temp4
            pushi   0
            callk   GetTime, 0
            eq?     
            bnt     code_09e0
            jmp     code_09d0
            jmp     code_09d0
code_09e0:  pushi   0
            callk   GetTime, 0
            sat     temp4
code_09e6:  pushi   #handleEvent
            pushi   1
            lst     temp1
            self    6
            sat     temp2
            pushi   #dispose
            pushi   0
            lat     temp1
            send    4
            pToa    timer
            bnt     code_0a02
            pushi   #doit
            pushi   0
            send    4
code_0a02:  lst     temp2
            ldi     65535
            eq?     
            bt      code_0a10
            pToa    busy
            not     
            bnt     code_099e
code_0a10:  ldi     0
            sat     temp2
            pushi   2
            pTos    theItem
            pushi   0
            callk   EditControl, 4
            jmp     code_0a21
            jmp     code_099e
code_0a21:  ldi     0
            aTop    busy
            lat     temp2
            ret     
        )
    )


    (method (dispose)
        (if (== self gTheNewDialog)
            SetPort(local0)
        )
        (if (window)
            DisposeWindow(window)
        )
        = window 0
        (if (== self gTheNewDialog)
            = gTheNewDialog 0
            = local0 0
        )
        (if (timer)
            (send timer:
                dispose()
                delete()
            )
        )
        = theItem 0
        (super:dispose())
    )


    (method (open param1 param2)
        (if (not window)
            (if (PicNotValid() and gCast)
                Animate((send gCast:elements()) 0)
            )
            = window NewWindow(nsTop nsLeft nsBottom nsRight text param1 param2)
        )
        (if (time)
            (Timer:setReal(self time))
        )
        (self:draw())
    )


    (method (draw)
        (self:eachElementDo(166))
    )


    (method (cue)
        (if (not busy)
            (self:dispose())
        )(else
            = busy 0
        )
    )


    (method (advance)
        (var temp0, temp1)
        (asm
            pToa    theItem
            bnt     code_0ad4
            pushi   #select
            pushi   1
            pushi   0
            send    6
            pushi   #contains
            pushi   1
            pTos    theItem
            self    6
            sat     temp1
code_0a99:  pushi   #next
            pushi   1
            lst     temp1
            self    6
            sat     temp1
            not     
            bnt     code_0aaf
            pushi   #first
            pushi   0
            self    4
            sat     temp1
code_0aaf:  pushi   1
            lst     temp1
            callk   NodeValue, 2
            aTop    theItem
            pushi   #state
            pushi   0
            pToa    theItem
            send    4
            push    
            ldi     1
            and     
            bnt     code_0a99
            jmp     code_0acb
            jmp     code_0a99
code_0acb:  pushi   #select
            pushi   1
            pushi   1
            pToa    theItem
            send    6
code_0ad4:  ret     
        )
    )


    (method (retreat)
        (var temp0, temp1)
        (asm
            pToa    theItem
            bnt     code_0b28
            pushi   #select
            pushi   1
            pushi   0
            send    6
            pushi   #contains
            pushi   1
            pTos    theItem
            self    6
            sat     temp1
code_0aed:  pushi   #prev
            pushi   1
            lst     temp1
            self    6
            sat     temp1
            not     
            bnt     code_0b03
            pushi   #last
            pushi   0
            self    4
            sat     temp1
code_0b03:  pushi   1
            lst     temp1
            callk   NodeValue, 2
            aTop    theItem
            pushi   #state
            pushi   0
            pToa    theItem
            send    4
            push    
            ldi     1
            and     
            bnt     code_0aed
            jmp     code_0b1f
            jmp     code_0aed
code_0b1f:  pushi   #select
            pushi   1
            pushi   1
            pToa    theItem
            send    6
code_0b28:  ret     
        )
    )


    (method (move param1 param2)
        = nsRight (+ nsRight param1)
        = nsLeft (+ nsLeft param1)
        = nsTop (+ nsTop param2)
        = nsBottom (+ nsBottom param2)
    )


    (method (moveTo param1 param2)
        (self:move((- param1 nsLeft) (- param2 nsTop)))
    )


    (method (center)
        (self:moveTo((/ (- 320 (- nsRight nsLeft)) 2) (/ (- 200 (- nsBottom nsTop)) 2)))
    )


    (method (setSize)
        (var DialogFirst, temp1, theNsTop[4])
        (if (text)
            TextSize(@temp2[0] text 0 -1)
            = nsTop theNsTop[0]
            = nsLeft theNsTop[1]
            = nsBottom theNsTop[2]
            = nsRight theNsTop[3]
        )(else
            = nsRight (= nsBottom (= nsLeft (= nsTop 0)))
        )
        = DialogFirst (self:first())
        (while (DialogFirst)
            (if (< (send ((= temp1 NodeValue(DialogFirst))):nsLeft()) nsLeft)
                = nsLeft (send temp1:nsLeft())
            )
            (if (< (send temp1:nsTop()) nsTop)
                = nsTop (send temp1:nsTop())
            )
            (if (> (send temp1:nsRight()) nsRight)
                = nsRight (send temp1:nsRight())
            )
            (if (> (send temp1:nsBottom()) nsBottom)
                = nsBottom (send temp1:nsBottom())
            )
            = DialogFirst (self:next(DialogFirst))
        )
        = nsRight (+ nsRight 4)
        = nsBottom (+ nsBottom 4)
        (self:moveTo(0 0))
    )


    (method (handleEvent pEvent)
        (var theTheItem)
        (if (((send pEvent:claimed()) or (== (send pEvent:type()) 0)) or ((((<> 1 (send pEvent:type())) and (<> 4 (send pEvent:type()))) and (<> 64 (send pEvent:type()))) and (<> 256 (send pEvent:type()))))
            EditControl(theItem pEvent)
            return 0
        )
        (if (= theTheItem (self:firstTrue(232 pEvent)))
            EditControl(theItem 0)
            (if ((send theTheItem:isType(3)))
                (if (theItem)
                    (send theItem:select(0))
                )
                (send (= theItem theTheItem):select(1))
                = theTheItem 0
            )(else
                (if (not (send theTheItem:isType(6)) and not (send theTheItem:checkState(2)))
                    (send theTheItem:doit())
                    (self:advance())
                    = theTheItem 0
                )
            )
        )(else
            = theTheItem 0
            (if ((((== (send pEvent:type()) 256) or ((== 4 (send pEvent:type())) and (== 13 (send pEvent:message())))) and theItem) and (send theItem:checkState(1)))
                = theTheItem theItem
                EditControl(theItem 0)
                (send pEvent:claimed(1))
            )(else
                (if ((not (self:firstTrue(268 1)) and ((((== 4 (send pEvent:type())) and (== 13 (send pEvent:message()))) or (== 1 (send pEvent:type()))) or (== 256 (send pEvent:type())))) or ((== 4 (send pEvent:type())) and (== 27 (send pEvent:message()))))
                    (send pEvent:claimed(1))
                    = theTheItem -1
                )(else
                    (if ((== 4 (send pEvent:type())) and (== 9 (send pEvent:message())))
                        (send pEvent:claimed(1))
                        (self:advance())
                    )(else
                        (if ((== 4 (send pEvent:type())) and (== 3840 (send pEvent:message())))
                            (send pEvent:claimed(1))
                            (self:retreat())
                        )(else
                            EditControl(theItem pEvent)
                        )
                    )
                )
            )
        )
        return theTheItem
    )

)
(class Controls of List
    (properties
        elements 0
        size 0
    )

    (method (draw)
        (self:eachElementDo(258))
        (self:eachElementDo(166))
    )


    (method (handleEvent pEvent)
        (var temp0)
        (if ((send pEvent:claimed()))
            return 0
        )
        (if ((= temp0 (self:firstTrue(232 pEvent))) and not (send ((= temp0 (self:firstTrue(232 pEvent)))):checkState(2)))
            (send temp0:doit())
            = temp0 0
        )
        return temp0
    )

)
