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



(procedure public (proc255_0 param1)
    (var newDialog, newDText, newDIcon, newDEdit, temp4, temp5, temp6, temp7, temp8, theNewDialog, temp10, temp11, newDButton[6], temp18, temp19, temp20, temp21[1000])
    = temp6 (= temp7 -1)
    = theNewDialog (= temp8 (= temp18 (= newDIcon (= newDEdit (= temp19 0)))))
    (send (= newDialog (Dialog:new())):
        window(gSq4Win)
        name(LOOKUP_ERROR)
    )
    = 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:add(newDText))
    = temp5 temp5
    (while (< temp5 paramTotal)
        (switch (param1[temp5])
            (case 30
                (send newDText:mode(param1[++temp5]))
            )
            (case 33
                (send newDText:
                    font(param1[++temp5])
                    setSize(temp8)
                )
            )
            (case 70
                (send newDText:setSize((= temp8 param1[++temp5])))
            )
            (case 25
                (send newDialog:time(param1[++temp5]))
            )
            (case 80
                (send newDialog:text(param1[++temp5]))
            )
            (case 67
                = temp6 param1[++temp5]
                = temp7 param1[++temp5]
            )
            (case 83
                Animate((send global5:elements) 0)
            )
            (case 41
                (send (= newDEdit (DEdit:new())):text(param1[++temp5]))
                (send newDEdit:
                    max(param1[++temp5])
                    setSize()
                )
            )
            (case 81
                (send (= newDButton[temp19] (DButton:new())):
                    text(param1[++temp5])
                    value(param1[++temp5])
                    setSize()
                )
                = temp18 (+ temp18 (+ (send newDButton[temp19]:nsRight) 4))
                ++temp19
            )
            (case 82
                (if (IsObject(param1[+ temp5 1]))
                    (send (= newDIcon (send param1[(+ temp5 1)]:new())):setSize())
                    = temp5 (+ temp5 1)
                )(else
                    = newDIcon (DIcon:new())
                    (send newDIcon:
                        view(param1[+ temp5 1])
                        loop(param1[+ temp5 2])
                        cel(param1[+ temp5 3])
                        setSize()
                    )
                    = temp5 (+ temp5 3)
                )
            )
            (case 103
                (if ((< (+ temp5 1) paramTotal) and IsObject(param1[(+ temp5 1)]))
                    (send newDialog:caller(param1[(+ temp5 1)]))
                    ++temp5
                )
                (if (gTheNewDialog)
                    (send gTheNewDialog:dispose())
                )
                = theNewDialog newDialog
            )
            (case 35
                (send newDialog:window(param1[++temp5]))
            )
        )
        ++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 (< temp5 temp19)
        (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
        )
))
    = temp11 GetPort()
    (send newDialog:open(
        (if ((send newDialog:text))
            4
        )(else
            0
        )
 
        (if (theNewDialog)
            15
        )(else
            -1
        )
))
    (if (theNewDialog)
        = global41 GetPort()
        SetPort(temp11)
        return = gTheNewDialog theNewDialog
    )(else
        (send global8:pause(1))
    )
    (if ((= temp10 (send newDialog:firstTrue(165 1))) and not (send newDialog:firstTrue(165 2)))
        (send temp10:state((| (send temp10:state) $0002)))
    )
    (if (== (= temp4 (send newDialog:doit(temp10))) -1)
        = temp4 0
    )
    = temp5 0
    (while (< temp5 temp19)
        (if (== temp4 newDButton[temp5])
            break
        )
        ++temp5
    )
    (if (not (send newDialog:theItem))
        = temp4 1
    )
    (send newDialog:dispose())
    (send global8:pause(0))
    return temp4
)


(procedure public (proc255_1 param1 param2 param3 param4 param5)
    localproc_113e(param1 82 param2 param3 param4 rest)
)


(procedure public (proc255_2 param1 param2 param3 param4)
    (var temp0[4])
    (if (localproc_113e(
        (if (>= paramTotal 3)
            param3
        )(else
            ""
        )
 41 param1 param2 rest))
        StrLen(param1)
    )
)


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


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


(procedure public (proc255_5 param1 param2 param3)
    (if ((<> (send param2:type) 1) or ((send param1:respondsTo(17)) and (& (send param1:signal) $0080)))
        0
    )(else
        (if (((>= paramTotal 3) and param3) and (== (& (send param2:modifiers) param3) 0))
            0
        )(else
            (if ((send param1:respondsTo(10)))
                proc999_4((send param1:nsLeft) (send param1:nsTop) (send param1:nsRight) (send param1:nsBottom) param2)
            )
        )
    )
)


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


(class Class_255_0 of Obj
    (properties
        state 0
    )

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


    (method (hide)
        DrawMenuBar(0)
    )


    (method (handleEvent pEvent param2)
        (var temp0, temp1)
        = temp0 0
        (if (state)
            = temp1 Joystick(12 30)
            = temp0 MenuSelect(pEvent rest)
            Joystick(12 temp1)
        )
        return temp0
    )


    (method (add param1)
        AddMenu(rest)
    )

)
(class Class_255_1 of Obj
    (properties
        type 0
        state 0
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        key 0
        said 0
        value 0
    )

    (method (doit)
        return value
    )


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


    (method (select param1)
        (if (param1)
            = state (| state $0008)
        )(else
            = state (& state $fff7)
        )
        (self:draw())
    )


    (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 
                    (send (= param1 (Event:new(32768))):localize())
                    (if (<> (= temp0 (self:check(param1))) temp1)
                        HiliteControl(self)
                        = temp1 temp0
                    )
                    (send param1:dispose())
                ) while (not not localproc_0022())
                (if (temp0)
                    HiliteControl(self)
                )
                return temp0
            )(else
                return self
            )
    )


    (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
    )


    (method (cycle)
    )

)
(class DText of Class_255_1
    (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 temp0)
        (send ((super:new())):
            font(global22)
            yourself()
        )
    )


    (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 Class_255_1
    (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 Class_255_1
    (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 Class_255_1
    (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 Class_255_1
    (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
        )
        = temp0 0
        (switch ((send pEvent:type))
            (case 4
                76
                (send pEvent:superClass)
            )
            (case 1
                (if ((self:check(pEvent)))
                    (send pEvent:claimed(1))
                    (if (< (send pEvent:y) (+ nsTop 10))
                        (do 
                            (self:retreat(1))
                        ) while (not not localproc_0022())
                    )(else
                        (if (> (send pEvent:y) (- nsBottom 10))
                            (do 
                                (self:advance(1))
                            ) while (not not localproc_0022())
                        )(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) and (& state $0002))
                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)
        return + text (* x param1)
    )


    (method (advance param1)
        (var temp0)
        (if (not StrAt(cursor 0))
            return not StrAt(cursor 0)
        )
        = temp0 0
        (while (param1 and StrAt(cursor x))
            = temp0 1
            = cursor (+ cursor x)
            (if (< (+ mark 1) y)
                ++mark
            )(else
                = lsTop (+ lsTop x)
            )
            --param1
        )
        return 
            (if (temp0)
                (self:draw())
                1
            )(else
                0
            )
    )


    (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
        )
        return 
            (if (temp0)
                (self:draw())
                1
            )(else
                0
            )
    )

)
(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
        busy 0
        caller 0
        seconds 0
        lastSeconds 0
    )

    (method (doit param1)
        (var temp0, temp1, temp2, temp3, temp4)
        = temp0 0
        = busy 1
        (self:eachElementDo(102))
        (if (theItem)
            (send theItem:select(0))
        )
        = theItem 
            (if (paramTotal and param1)
                param1
            )(else
                (self:firstTrue(165 1))
            )
        (if (theItem)
            (send theItem:select(1))
        )
        (if (not theItem)
            = temp3 60
            = temp4 GetTime()
        )(else
            = temp3 0
        )
        = temp2 0
        (while (not temp2)
            (self:eachElementDo(166))
            = temp1 (send ((Event:new())):localize())
            (if (temp3)
                --temp3
                (if (== (send temp1:type) 1)
                    (send temp1:type(0))
                )
                (while (== temp4 GetTime())
                )
                = temp4 GetTime()
            )
            = temp2 (self:handleEvent(temp1))
            (send temp1:dispose())
            (self:check())
            (if ((== temp2 -1) or not busy)
                break
            )
            Wait(1)
        )
        = busy 0
        return temp2
    )


    (method (dispose)
        (var theCaller)
        (if (== self gTheNewDialog)
            SetPort(global41)
            = gTheNewDialog 0
            = global41 0
        )
        (if (window)
            (send window:dispose())
        )
        = theItem (= window 0)
        = theCaller caller
        (super:dispose())
        (if (theCaller)
            (send theCaller:cue())
        )
    )


    (method (open param1 param2)
        (if (PicNotValid() and global5)
            Animate((send global5:elements) 0)
        )
        = window (send window:new())
        (send window:
            top(nsTop)
            left(nsLeft)
            bottom(nsBottom)
            right(nsRight)
            title(text)
            type(param1)
            priority(param2)
            open()
        )
        = seconds time
        (self:draw())
    )


    (method (draw)
        (self:eachElementDo(83))
    )


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


    (method (advance)
        (var temp0, temp1)
        (if (theItem)
            (send theItem:select(0))
            = temp1 (self:contains(theItem))
            (send theItem:select(1))
            (send global1:setCursor(global19 1 (+ (send theItem:nsLeft) (/ (- (send theItem:nsRight) (send theItem:nsLeft)) 2)) (- (send theItem:nsBottom) 3)))
        )
    )


    (method (retreat)
        (var temp0, temp1)
        (if (theItem)
            (send theItem:select(0))
            = temp1 (self:contains(theItem))
            (send theItem:select(1))
            (send global1:setCursor(global19 1 (+ (send theItem:nsLeft) (/ (- (send theItem:nsRight) (send theItem:nsLeft)) 2)) (- (send theItem:nsBottom) 3)))
        )
    )


    (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((+ (send window:brLeft) (/ (- (- (send window:brRight) (send window:brLeft)) (- nsRight nsLeft)) 2)) (+ (send window:brTop) (/ (- (- (send window:brBottom) (send window:brTop)) (- 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:type) $0040)
            (send pEvent:type(4))
            (switch ((send pEvent:message))
                (case 5
                    (send pEvent:message(20480))
                )
                (case 1
                    (send pEvent:message(18432))
                )
                (case 7
                    (send pEvent:message(19200))
                )
                (case 3
                    (send pEvent:message(19712))
                )
                (default 
                    (send pEvent:type(64))
                )
            )
        )
        (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(124 pEvent)))
            EditControl(theItem 0)
            (if (not (send theTheItem:checkState(2)))
                (if (theItem)
                    (send theItem:select(0))
                )
                (send (= theItem theTheItem):select(1))
                (send theTheItem:doit())
                = 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(165 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 (((IsObject(theItem) and (send theItem:isType(3))) and (== (send pEvent:type) 4)) and (== (send pEvent:message) 19712))
                        (if (>= (send theItem:cursor) StrLen((send theItem:text)))
                            (self:advance())
                        )(else
                            EditControl(theItem pEvent)
                        )
                    )(else
                        (if (((IsObject(theItem) and (send theItem:isType(3))) and (== (send pEvent:type) 4)) and (== (send pEvent:message) 19200))
                            (if (<= (send theItem:cursor) 0)
                                (self:retreat())
                            )(else
                                EditControl(theItem pEvent)
                            )
                        )(else
                            (if ((== 4 (send pEvent:type)) and proc999_5((send pEvent:message) 9 19712 20480))
                                (send pEvent:claimed(1))
                                (self:advance())
                            )(else
                                (if ((== 4 (send pEvent:type)) and proc999_5((send pEvent:message) 3840 19200 18432))
                                    (send pEvent:claimed(1))
                                    (self:retreat())
                                )(else
                                    EditControl(theItem pEvent)
                                )
                            )
                        )
                    )
                )
            )
        )
        return theTheItem
    )


    (method (check)
        (var theLastSeconds)
        (if (seconds and (<> lastSeconds (= theLastSeconds GetTime(1))))
            = lastSeconds theLastSeconds
            (if (not --seconds)
                (self:cue())
            )
        )
    )

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

    (method (draw)
        (self:eachElementDo(160))
        (self:eachElementDo(83))
    )


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

)
