(include "sci.sh")
(use "Main")
(use "IconI")
(use "Obj")
(script 934)



(class Slider of IconI
    (properties
        view -1
        loop -1
        cel -1
        nsLeft 0
        nsTop -1
        nsRight 0
        nsBottom 0
        state 0
        cursor -1
        type 16384
        message -1
        modifiers 0
        signal 1
        helpStr 0
        maskView 0
        maskLoop 0
        maskCel 0
        highlightColor 0
        lowlightColor 0
        sliderView 0
        sliderLoop 0
        sliderCel 0
        sTop 0
        sLeft 0
        sRight 0
        maxY 0
        minY 0
        underBits 0
        yStep 1
        theObj 0
        selector 0
        bottomValue 0
        topValue 0
    )

    (method (show param1)
        (super:show(rest param1))
        (if (not sRight)
            = sLeft nsLeft
            = sRight nsRight
            = maxY (- nsBottom CelHigh(sliderView sliderLoop sliderCel))
            = minY nsTop
        )
        = sTop (self:valueToPosn())
        DrawCel(sliderView sliderLoop sliderCel sLeft sTop -1)
        Graph(12 - nsTop 1 - nsLeft 1 + 2 nsBottom + 2 nsRight 1)
    )


    (method (select param1)
        (var newEvent)
        return 
            (if (paramTotal and param1)
                (while (<> (send ((= newEvent (Event:new()))):type) 2)
                    (send newEvent:localize())
                    (if (< (send newEvent:y) (- sTop yStep))
                        (self:move(yStep))
                    )(else
                        (if (> (send newEvent:y) (+ sTop yStep))
                            (self:move(neg yStep))
                        )
                    )
                    (send newEvent:dispose())
                )
                (send newEvent:dispose())
            )(else
                return 1
            )
    )


    (method (highlight)
    )


    (method (advance)
        (self:move(proc999_3(yStep (- sTop (self:valueToPosn((+ proc999_7(theObj selector) proc999_0((- topValue bottomValue)))))))))
    )


    (method (retreat)
        (self:move(proc999_2(neg yStep (- sTop (self:valueToPosn((- proc999_7(theObj selector) proc999_0((- topValue bottomValue)))))))))
    )


    (method (move param1)
        (var temp0, temp1, temp2, temp3, temp4, temp5, temp6)
        = temp5 proc999_0(param1)
        = temp4 param1
        (while (<= yStep Abs(temp4))
            = temp0 (- sTop (* temp5 yStep))
            = temp1 CelHigh(sliderView sliderLoop sliderCel)
            = sTop 
                (if (< temp0 minY)
                    minY
                )(else
                    (if (> temp0 maxY)
                        maxY
                    )(else
                        temp0
                    )
                )
            = temp2 PicNotValid()
            PicNotValid(1)
            DrawCel(view loop cel nsLeft nsTop -1)
            DrawCel(sliderView sliderLoop sliderCel sLeft sTop -1)
            Graph(12 - nsTop 1 - nsLeft 1 + 2 nsBottom + 2 nsRight 1)
            PicNotValid(temp2)
            = temp3 (self:posnToValue(sTop))
            = temp6 
                (if (theObj)
                    proc999_7(theObj selector temp3)
                )(else
                    0
                )
            = temp4 (- temp4 (* yStep temp5))
        )
        return temp6
    )


    (method (valueToPosn param1)
        (var temp0)
        = temp0 
            (if (paramTotal)
                param1
            )(else
                proc999_7(theObj selector)
            )
        return 
            (if ((< (= temp0 
                (if (paramTotal)
                    param1
                )(else
                    proc999_7(theObj selector)
                )
) topValue) and (< temp0 bottomValue))
                (if (< bottomValue topValue)
                    maxY
                )(else
                    minY
                )
            )(else
                (if ((> temp0 topValue) and (> temp0 bottomValue))
                    (if (< bottomValue topValue)
                        minY
                    )(else
                        maxY
                    )
                )(else
                    + minY (/ (* Abs((- topValue temp0)) (- maxY minY)) Abs((- topValue bottomValue)))
                )
            )
    )


    (method (posnToValue param1)
        return + bottomValue (/ (* (- maxY param1) (- topValue bottomValue)) (- maxY minY))
    )

)
(class GameControls of IconBar
    (properties
        elements 0
        size 0
        height 200
        underBits 0
        oldMouseX 0
        oldMouseY 0
        curIcon 0
        highlightedIcon 0
        prevIcon 0
        curInvIcon 0
        useIconItem 0
        helpIconItem 0
        port 0
        window 0
        state 0
        activateHeight 0
        okButton 0
    )

    (method (show)
        (var temp0, temp1, temp2, temp3, temp4)
        (send gSounds:pause())
        (if (gPseudoMouse and (send gPseudoMouse:respondsTo(149)))
            (send gPseudoMouse:stop())
        )
        = state (| state $0020)
        (if (IsObject(window))
            (send window:open())
        )(else
            = window (send ((send gSq4Win:new())):
                    top(46)
                    left(24)
                    bottom(155)
                    right(296)
                    priority(15)
                    open()
                    yourself()
                )
        )
        = temp0 30
        = temp1 30
        = temp2 FirstNode(elements)
        (while (temp2)
            = temp3 NextNode(temp2)
            = temp4 NodeValue(temp2)
            (if (not IsObject(temp4))
                return 
            )
            (if (not (& (send temp4:signal) $0080) and (<= (send temp4:nsRight) 0))
                (send temp4:show(temp0 temp1))
                = temp0 (+ 20 (send temp4:nsRight))
            )(else
                (send temp4:show())
            )
            = temp2 temp3
        )
        (if (not okButton)
            = okButton NodeValue((self:first()))
        )
        (if (curIcon)
            (send gGame:setCursor(global19 1 (+ (send curIcon:nsLeft) (/ (- (send curIcon:nsRight) (send curIcon:nsLeft)) 2)) (- (send curIcon:nsBottom) 3)))
        )
        (self:
            doit()
            hide()
        )
    )


    (method (hide)
        (if (window)
            (send window:dispose())
        )
        (if (& state $0020)
            (send gSounds:pause(0))
            = state (& state $ffdf)
        )
    )


    (method (select param1 param2)
        (send param1:select(
            (if (>= paramTotal 2)
                param2
            )(else
                0
            )
))
    )


    (method (swapCurIcon)
    )


    (method (advanceCurIcon)
        (var temp0)
    )


    (method (dispatchEvent param1)
        return 
            (if (& (send param1:type) $0040)
                (switch ((send param1:message))
                    (case 5
                        (send param1:dispose())
                        (if (IsObject(highlightedIcon) and (send highlightedIcon:respondsTo(168)))
                            (send highlightedIcon:retreat())
                            return 0
                        )(else
                            (if (& (send highlightedIcon:signal) $0100)
                                (self:advance())
                                return 0
                            )
                        )
                    )
                    (case 1
                        (send param1:dispose())
                        (if (IsObject(highlightedIcon) and (send highlightedIcon:respondsTo(167)))
                            (send highlightedIcon:advance())
                            return 0
                        )(else
                            (if (& (send highlightedIcon:signal) $0100)
                                (self:retreat())
                                return 0
                            )
                        )
                    )
                    (default 
                        (super:dispatchEvent(param1))
                    )
                )
            )(else
                (super:dispatchEvent(param1))
            )
    )

)
(class ControlIcon of IconI
    (properties
        view -1
        loop -1
        cel -1
        nsLeft 0
        nsTop -1
        nsRight 0
        nsBottom 0
        state 0
        cursor -1
        type 16384
        message -1
        modifiers 0
        signal 1
        helpStr 0
        maskView 0
        maskLoop 0
        maskCel 0
        highlightColor 0
        lowlightColor 0
        theObj 0
        selector 0
    )

    (method (select param1)
        (if (theObj)
            (if ((super:select(rest param1)))
                (GameControls:hide())
                proc999_7(theObj selector)
            )
        )(else
            (super:select(rest param1))
        )
    )

)
