(include "sci.sh")
(use "Main")
(use "n255")
(use "Print")
(use "Cycle")
(use "Sounds")
(use "View")
(use "Obj")
(script 100)


(local
    local0[2]

)
(instance myDialog of Dialog
    (properties)

    (method (handleEvent pEvent)
        Palette(6 96 218 -1)
        (super:handleEvent(rest pEvent))
    )

)
(instance public rm100 of Rm
    (properties
        picture 300
    )

    (method (init)
        Palette(1 999 2)
        (if (gDialog)
            (send gDialog:dispose())
        )
        (super:init())
        (send gMouseDownHandler:addToFront(self))
        (send gKeyDownHandler:addToFront(self))
        (send gSQ5:setCursor(996 1))
        (send gSq5IconBar:
            hide()
            disable()
        )
        (send gUser:canInput(1))
        (self:setScript(rmScript))
    )


    (method (dispose param1)
        (send gSq5IconBar:
            hide()
            enable()
        )
        = global20 999
        Palette(1 999 2)
        (send gSQ5:setCursor(996 1))
        (send gKeyDownHandler:delete(self))
        (send gMouseDownHandler:delete(self))
        (super:dispose(rest param1))
    )


    (method (handleEvent pEvent)
        (if ((<> (rmScript:state) 4) and (& (send pEvent:type) $4005))
            (rmScript:changeState(4))
            (send pEvent:claimed(1))
            return 
        )(else
            (super:handleEvent(pEvent))
        )
    )

)
(instance rmScript of Script
    (properties)

    (method (doit param1)
        Palette(6 96 218 -1)
        (super:doit(rest param1))
    )


    (method (changeState newState)
        (var temp0, temp1[10])
        (switch (= state newState)
            (case 0
                ((send gSq5Music1:
                    number(1001)
                    loop(1)
                    play()
                )
 (sparkle:init()) = seconds 4  )
            )
            (case 1
                (
                (if (== (send gSq5Music1:prevSignal) 20)
                    (sparkle:setCycle(End self))
                )(else
                    --state
                    = cycles 1
                )
 )
            )
            (case 2
                (
                (if (== (send gSq5Music1:prevSignal) 30)
                    (sparkle:
                        x(60)
                        y(145)
                        loop(1)
                        cel(0)
                        setCycle(End self)
                    )
                )(else
                    --state
                    = cycles 1
                )
 )
            )
            (case 3
                (= seconds 3  )
            )
            (case 4
                ((send gSq5Music1:stop()) (sparkle:hide()) = cycles 5  )
            )
            (case 5
                ((sparkle:dispose()) = seconds 0 = global20 999 (send gSQ5:setCursor(999 1)) (Print:
                    dialog(myDialog)
                    font(gFont)
                    width(150)
                    mode(1)
                    addText(8 1 0 4 0 0 0)
                    addText(8 1 0 5 0 10 0)
                    addColorButton(0 8 1 0 6 0 30 0 0 15 23 5 5 5)
                    addColorButton(1 8 1 0 1 0 40 0 0 15 23 5 5 5)
                    addColorButton(2 8 1 0 2 0 50 0 0 15 23 5 5 5)
                )
 
                (switch (= temp0 (Print:
                        addColorButton(4 8 1 0 7 0 60 0 0 15 23 5 5 5)
                        addColorButton(3 8 1 0 3 0 70 0 0 15 23 5 5 5)
                        init()
                    )
)
                    (case 0
                        ((send gRoom:newRoom(104))  )
                    )
                    (case 1
                        ((send gRoom:newRoom(110))  )
                    )
                    (case 2
                        ((send gSQ5:restore()) (self:changeState(state))  )
                    )
                    (case 3
                        (= global4 1  )
                    )
                    (case 4
                        (= state (- state 2) (send gTestMessager:say(1 0 0 0 self 100))  )
                    )
                    (case 5
                        (= temp1 0 = temp0 (Print:
                                addText("Which room do you want?")
                                addText("Other" 110 25)
                                addEdit(@temp1 6 115 35)
                                posn(50 30)
                                addButton(100 "Start 100" 5 35)
                                init()
                            )
 
                        (if (temp1)
                            (send gRoom:newRoom((= temp0 ReadNumber(@temp1))))
                        )(else
                            (self:changeState(state))
                        )
 )
                    )
                )
 )
            )
        )
    )

)
(instance sparkle of Prop
    (properties
        x 121
        y 54
        view 3001
        priority 15
        signal 16
    )
)
