(include "sci.sh")
(use "Main")
(use "AnimDialog")
(use "n255")
(use "Print")
(use "Blink")
(use "RandCycle")
(use "Obj")
(script 30)



(class AnimDialog of Dialog
    (properties
        elements 0
        size 0
        text 0
        font 0
        window 0
        theItem 0
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        time 0
        caller 0
        seconds 0
        lastSeconds 0
        eatTheMice 0
        lastTicks 0
    )

    (method (doit param1)
        (var temp0, temp1, temp2)
        = gCycleCnt (+ global86 GetTime())
        = temp2 0
        (self:eachElementDo(110))
        (if (theItem)
            (send theItem:select(0))
        )
        = theItem 
            (if (paramTotal and param1)
                param1
            )(else
                (self:firstTrue(191 1))
            )
        (if (theItem)
            (send theItem:select(1))
        )
        (if (not theItem)
            = eatTheMice gEatTheMice
            = lastTicks GetTime()
        )(else
            = eatTheMice 0
        )
        = temp1 0
        (while (not temp1)
            (if (IsObject(gNewEventHandler))
                (send gNewEventHandler:eachElementDo(57))
            )(else
                (if (IsObject(gTheDoits))
                    (send gTheDoits:eachElementDo(57))
                )
            )
            = gCycleCnt (+ global86 GetTime())
            (self:eachElementDo(192))
            = temp0 (send ((Event:new())):localize())
            (if (eatTheMice)
                --eatTheMice
                (if (== (send temp0:type) 1)
                    (send temp0:type(0))
                )
                (while (== lastTicks GetTime())
                )
                = lastTicks GetTime()
            )
            (self:eachElementDo(96 checkHiliteCode self temp0))
            = temp1 (self:handleEvent(temp0))
            (send temp0:dispose())
            (if ((self:check()))
                break
            )
            (if (== temp1 65534)
                break
            )
            Wait(1)
        )
        return temp1
    )

)
(instance checkHiliteCode of Code
    (properties)

    (method (doit param1 param2 param3)
        (if (((& (send param1:state) $0001) and (send param1:check(param3))) and not (& (send param1:state) $0008))
            (send ((send param2:theItem)):select(0))
            (send param2:theItem(param1))
            (send param1:select(1))
        )
    )

)
(class ChoiceNarrator of Narrator
    (properties
        x -1
        y -1
        z 0
        heading 0
        noun 0
        modNum -1
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        sightAngle 26505
        actions 0
        onMeCheck 26505
        state 0
        approachX 0
        approachY 0
        approachDist 0
        _approachVerbs 0
        yStep 2
        view -1
        loop 0
        cel 0
        priority 0
        underBits 0
        signal 0
        lsTop 0
        lsLeft 0
        lsBottom 0
        lsRight 0
        brTop 0
        brLeft 0
        brBottom 0
        brRight 0
        scaleSignal 0
        scaleX 128
        scaleY 128
        maxScale 128
        cycleSpeed 6
        script 0
        cycler 0
        timer 0
        detailLevel 0
        scaler 0
        caller 0
        disposeWhenDone 1
        ticks 0
        talkWidth 0
        keepWindow 0
        modeless 0
        font 0
        cueVal 0
        initialized 0
        showTitle 0
        color 0
        back 5
        curVolume 0
        saveCursor 0
        whichSelect 0
        normal 0
        curNoun 0
        curVerb 0
        curCase 0
    )

    (method (display param1 param2)
        (var theTalkWidth, newGSq5Win, temp2, temp3, temp4, temp5, newPrint)
        (if (normal)
            (super:display(param1 rest param2))
        )(else
            (if (> (+ x talkWidth) 318)
                = theTalkWidth (- 318 x)
            )(else
                = theTalkWidth talkWidth
            )
            (send (= newGSq5Win (send gSq5Win:new())):
                color(color)
                back(back)
            )
            (if (not HaveMouse() and (<> gSaveCursor 996))
                = saveCursor gSaveCursor
                (send gSQ5:setCursor(996))
            )(else
                = saveCursor 0
            )
            (if (showTitle)
                (Print:addTitle(name))
            )
            (send (= newPrint (Print:new())):
                dialog((AnimDialog:new()))
                window(newGSq5Win)
                posn(x y)
                font(font)
                width(theTalkWidth)
                addText(param1)
                modeless(0)
            )
            (if (not normal)
                = temp3 (+ (+ (- (send ((= temp2 NodeValue((send ((send newPrint:dialog)):last())))):nsBottom) (send temp2:nsTop)) 4) y)
                = temp4 2
                (while (= temp5 GetMessage(2 modNum curNoun curVerb curCase temp4))
                    (send newPrint:addColorButton((- temp4 1) curNoun curVerb curCase temp4 x temp3 modNum))
                    = temp3 (+ temp3 (+ (- (send ((= temp2 NodeValue((send ((send newPrint:dialog)):last())))):nsBottom) (send temp2:nsTop)) 4))
                    ++temp4
                )
                = whichSelect (send newPrint:init())
                (self:dispose(1))
            )(else
                (send newPrint:init())
            )
        )
    )

)
(class ChoiceTalker of Talker
    (properties
        x -1
        y -1
        z 0
        heading 0
        noun 0
        modNum -1
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        sightAngle 26505
        actions 0
        onMeCheck 26505
        state 0
        approachX 0
        approachY 0
        approachDist 0
        _approachVerbs 0
        yStep 2
        view -1
        loop 0
        cel 0
        priority 0
        underBits 0
        signal 0
        lsTop 0
        lsLeft 0
        lsBottom 0
        lsRight 0
        brTop 0
        brLeft 0
        brBottom 0
        brRight 0
        scaleSignal 0
        scaleX 128
        scaleY 128
        maxScale 128
        cycleSpeed 6
        script 0
        cycler 0
        timer 0
        detailLevel 0
        scaler 0
        caller 0
        disposeWhenDone 1
        ticks 0
        talkWidth 318
        keepWindow 0
        modeless 0
        font 0
        cueVal 0
        initialized 0
        showTitle 0
        color 0
        back 5
        curVolume 0
        saveCursor 0
        bust 0
        eyes 0
        mouth 0
        viewInPrint 0
        textX 0
        textY 0
        useFrame 0
        blinkSpeed 100
        verb 0
        case 0
        whichSelect 0
        normal 0
        curNoun 0
        curVerb 0
        curCase 0
    )

    (method (show param1)
        (var temp0, temp1)
        (if (normal)
            (super:show(rest param1))
        )(else
            = temp1 GetPort()
            SetPort(0)
            (if (not underBits)
                = underBits Graph(7 nsTop nsLeft nsBottom nsRight 1)
            )
            = temp0 PicNotValid()
            PicNotValid(1)
            (if (bust)
                DrawCel((send bust:view) (send bust:loop) (send bust:cel) + (send bust:nsLeft) nsLeft + (send bust:nsTop) nsTop -1)
            )
            (if (eyes)
                DrawCel((send eyes:view) (send eyes:loop) (send eyes:cel) + (send eyes:nsLeft) nsLeft + (send eyes:nsTop) nsTop -1)
            )
            (if (mouth)
                DrawCel((send mouth:view) (send mouth:loop) (send mouth:cel) + (send mouth:nsLeft) nsLeft + (send mouth:nsTop) nsTop -1)
            )
            DrawCel(view loop cel nsLeft nsTop -1)
            Graph(12 nsTop nsLeft nsBottom nsRight 1)
            SetPort(temp1)
            PicNotValid(temp0)
        )
    )


    (method (say param1 param2 param3)
        return 
            (if (normal)
                (super:say(param1 param2 rest param3))
            )(else
                (if ((> view 0) and not underBits)
                    (self:init())
                )
                (if (gSq5IconBar)
                    (send gSq5IconBar:disable())
                )
                (if (not initialized)
                    (self:init())
                )
                = caller 
                    (if ((> paramTotal 1) and param2)
                        param2
                    )(else
                        0
                    )
                (if (IsObject(gNewEventHandler))
                    (send gNewEventHandler:add(self))
                )(else
                    (send (= gNewEventHandler (EventHandler:new())):
                        name("fastCast")
                        add(self)
                    )
                )
                (if (& global90 $0002)
                    (self:startAudio())
                )
                (if (& global90 $0001)
                    (self:startText(param1))
                )
                = ticks (+ (+ ticks 60) gCycleCnt)
                return 1
            )
    )


    (method (startText param1 param2)
        (var temp0)
        return 
            (if (normal)
                (super:startText(param1 rest param2))
            )(else
                (if (not viewInPrint)
                    (self:show())
                )
                (if (not & global90 $0002)
                    = ticks proc999_3(240 (* 8 (= temp0 StrLen(param1))))
                )
                (if (mouth)
                    (send mouth:setCycle(RandCycle (* 4 temp0) 0 1))
                )
                (if (eyes and not (send eyes:cycler))
                    (send eyes:setCycle(Blink blinkSpeed))
                )
                (if (gDialog)
                    (send gDialog:dispose())
                )
                (self:display(param1))
                return temp0
            )
    )


    (method (display param1 param2)
        (var temp0, theTalkWidth, temp2, newGSq5Win, temp4, temp5, temp6, temp7, newPrint)
        (if (normal)
            (super:display(param1 rest param2))
        )(else
            (send (= newGSq5Win (send gSq5Win:new())):
                color(color)
                back(back)
            )
            (if (not HaveMouse() and (<> gSaveCursor 996))
                = saveCursor gSaveCursor
                (send gSQ5:setCursor(996))
            )(else
                = saveCursor 0
            )
            = newPrint (Print:new())
            (if (viewInPrint)
                = temp0 
                    (if (useFrame)
                        loop
                    )(else
                        (send bust:loop)
                    )
                (if (showTitle)
                    (send newPrint:addTitle(name))
                )
                (send newPrint:
                    window(newGSq5Win)
                    dialog((AnimDialog:new()))
                    posn(x y)
                    modeless(0)
                    font(font)
                    addIcon(view temp0 cel 0 0)
                    addText(param1 + x textX)
                    width(theTalkWidth)
                )
            )(else
                (if (not + textX textY)
                    = textX (+ (- nsRight nsLeft) 5)
                )
                (if (> (+ (= temp2 (+ nsLeft textX)) talkWidth) 318)
                    = theTalkWidth (- 318 temp2)
                )(else
                    = theTalkWidth talkWidth
                )
                (if (showTitle)
                    (send newPrint:addTitle(name))
                )
                (send newPrint:
                    window(newGSq5Win)
                    dialog((AnimDialog:new()))
                    posn(+ x textX + y textY)
                    modeless(0)
                    font(font)
                    addText(param1 4)
                    width(theTalkWidth)
                )
            )
            (if (not normal)
                = temp5 (+ (- (send ((= temp4 NodeValue((send ((send newPrint:dialog)):last())))):nsBottom) (send temp4:nsTop)) 4)
                = temp6 2
                (while (= temp7 GetMessage(2 modNum curNoun curVerb curCase temp6))
                    (send newPrint:addColorButton((- temp6 1) curNoun curVerb curCase temp6 4 temp5 modNum))
                    = temp5 (+ temp5 (+ (- (send ((= temp4 NodeValue((send ((send newPrint:dialog)):last())))):nsBottom) (send temp4:nsTop)) 4))
                    ++temp6
                )
                = whichSelect (send newPrint:init())
                (self:dispose(1))
            )(else
                (send newPrint:
                    width(theTalkWidth)
                    init()
                )
            )
        )
    )


    (method (cycle param1 param2)
        (var temp0, temp1[100], temp101)
        (if (normal)
            (super:cycle(param1 rest param2))
        )(else
            (if (param1 and (send param1:cycler))
                = temp101 GetPort()
                SetPort(0)
                = temp0 (send param1:cel)
                (send ((send param1:cycler)):doit())
                (if (<> temp0 (send param1:cel))
                    DrawCel((send param1:view) (send param1:loop) (send param1:cel) + (send param1:nsLeft) nsLeft + (send param1:nsTop) nsTop -1)
                    (send param1:nsRight((+ (send param1:nsLeft) CelWide((send param1:view) (send param1:loop) (send param1:cel)))))
                    (send param1:nsBottom((+ (send param1:nsTop) CelHigh((send param1:view) (send param1:loop) (send param1:cel)))))
                    Graph(12 + (send param1:nsTop) nsTop + (send param1:nsLeft) nsLeft + (send param1:nsBottom) nsTop + (send param1:nsRight) nsLeft 1)
                )
                SetPort(temp101)
            )
        )
    )

)
