(version 2)
(include "sci.sh")
(exports
    0 dInvD
    1 dCastD
    2 showFeatureCode
)
(use "Main")
(use "Class_255_0")
(use "Print")
(use "DIcon")
(use "SysWindow")
(use "InvI")
(use "User")
(use "Obj")
(script 25)


(local
    newDButton
    local1
    theGCursorNumber

)
(instance public dInvD of Dialog
    (properties)

    (method (init)
        (var temp0, temp1, temp2, temp3, newDText, gInvFirst, temp6)
        (send gGame:setCursor(999 1))
        = temp1 4
        = temp0 temp1
        = temp2 temp0
        = temp3 0
        = gInvFirst (send gInv:first())
        (while (gInvFirst)
            = temp6 NodeValue(gInvFirst)
            ++temp3
            (if ((send temp6:isKindOf(InvI)))
                = newDText (DText:new())
                (self:add((send newDText:
                        value(temp6)
                        text((send temp6:name))
                        nsLeft(temp0)
                        nsTop(temp1)
                        state(3)
                        font(1207)
                        setSize()
                        yourself()
                    )
))
            )
            (if (< temp2 (- (send newDText:nsRight) (send newDText:nsLeft)))
                = temp2 (- (send newDText:nsRight) (send newDText:nsLeft))
            )
            = temp1 (+ temp1 (- (send newDText:nsBottom) (send newDText:nsTop)))
            (if (> temp1 140)
                = temp1 4
                = temp0 (+ temp0 (+ temp2 5))
                = temp2 0
            )
            = gInvFirst (send gInv:next(gInvFirst))
        )
        = window SysWindow
        (self:setSize())
        = newDButton (DButton:new())
        (send newDButton:
            font(1207)
            text("Outta here!")
            setSize()
            moveTo(- nsRight (+ 4 (send newDButton:nsRight)) - nsBottom 17)
        )
        (send newDButton:move((- (send newDButton:nsLeft) (send newDButton:nsRight)) 0))
        (self:
            add(newDButton)
            setSize()
            center()
        )
        return temp3
    )


    (method (doit)
        (var theNewDButton)
        (self:init())
        (self:open())
        = theNewDButton newDButton
        (while (TRUE)
            = theNewDButton (super:doit(theNewDButton))
            (if ((not theNewDButton or (== theNewDButton -1)) or (== theNewDButton newDButton))
                break
            )
            (send gEgo:get(-1 (send gInv:indexOf((send theNewDButton:value)))))
        )
        (self:
            eachElementDo(#dispose 1)
            dispose()
        )
        (send gGame:setCursor(0 1))
    )


    (method (handleEvent pEvent)
        (var pEventMessage, pEventType)
        = pEventMessage (send pEvent:message)
        (switch (= pEventType (send pEvent:type))
            (case 4
                (switch (pEventMessage)
                    (case 18432
                        = pEventMessage 3840
                    )
                    (case 20480
                        = pEventMessage 9
                    )
                )
            )
            (case 64
                (switch (pEventMessage)
                    (case 1
                        = pEventMessage 3840
                        = pEventType 4
                    )
                    (case 5
                        = pEventMessage 9
                        = pEventType 4
                    )
                )
            )
        )
        (send pEvent:
            type(pEventType)
            message(pEventMessage)
        )
        (super:handleEvent(pEvent))
    )

)
(instance public dCastD of Dialog
    (properties)

    (method (init)
        (var temp0, temp1, temp2, temp3, newDText, gOldCastFirst, temp6)
        = temp1 4
        = temp0 temp1
        = temp2 temp0
        = temp3 0
        = gOldCastFirst (send gOldCast:first())
        (while (gOldCastFirst)
            = temp6 NodeValue(gOldCastFirst)
            ++temp3
            = newDText (DText:new())
            (self:add((send newDText:
                    value(temp6)
                    text((send temp6:name))
                    nsLeft(temp0)
                    nsTop(temp1)
                    state(3)
                    font(global23)
                    setSize()
                    yourself()
                )
))
            (if (< temp2 (- (send newDText:nsRight) (send newDText:nsLeft)))
                = temp2 (- (send newDText:nsRight) (send newDText:nsLeft))
            )
            = temp1 (+ temp1 (+ (- (send newDText:nsBottom) (send newDText:nsTop)) 1))
            (if (> temp1 100)
                = temp1 4
                = temp0 (+ temp0 (+ temp2 10))
                = temp2 0
            )
            = gOldCastFirst (send gOldCast:next(gOldCastFirst))
        )
        = window gFpWin
        (self:setSize())
        = newDButton (DButton:new())
        (send newDButton:
            text("exit")
            setSize()
            moveTo(- nsRight (+ 4 (send newDButton:nsRight)) nsBottom)
        )
        (send newDButton:move((- (send newDButton:nsLeft) (send newDButton:nsRight)) 0))
        (self:
            add(newDButton)
            setSize()
            center()
        )
        return temp3
    )


    (method (doit)
        (var theNewDButton, temp1)
        (self:init())
        (self:open(4 15))
        = theNewDButton newDButton
        (while (TRUE)
            = theNewDButton (super:doit(theNewDButton))
            (if ((not theNewDButton or (== theNewDButton -1)) or (== theNewDButton newDButton))
                break
            )
            = gTheNewDButtonValue (send theNewDButton:value)
        )
        (self:dispose())
    )


    (method (handleEvent pEvent)
        (var pEventMessage, pEventType)
        = pEventMessage (send pEvent:message)
        (switch (= pEventType (send pEvent:type))
            (case 4
                (switch (pEventMessage)
                    (case 18432
                        = pEventMessage 3840
                    )
                    (case 20480
                        = pEventMessage 9
                    )
                )
            )
            (case 64
                (switch (pEventMessage)
                    (case 1
                        = pEventMessage 3840
                        = pEventType 4
                    )
                    (case 5
                        = pEventMessage 9
                        = pEventType 4
                    )
                )
            )
        )
        (send pEvent:
            type(pEventType)
            message(pEventMessage)
        )
        (super:handleEvent(pEvent))
    )

)
(instance public showFeatureCode of Code
    (properties)

    (method (doit param1 param2)
        (var temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8, temp9, temp10, temp11)
        (if (param2)
            = temp0 (send param1:brTop)
            = temp1 (send param1:brLeft)
            = temp3 (send param1:brBottom)
            = temp2 (send param1:brRight)
            Graph(grDRAW_LINE temp0 temp1 temp0 temp2 40)
            Graph(grDRAW_LINE temp3 temp1 temp3 temp2 40)
            Graph(grDRAW_LINE temp0 temp1 temp3 temp1 40)
            Graph(grDRAW_LINE temp0 temp2 temp3 temp2 40)
        )(else
            = temp0 (send param1:nsTop)
            = temp1 (send param1:nsLeft)
            = temp3 (send param1:nsBottom)
            = temp2 (send param1:nsRight)
            Graph(grDRAW_LINE temp0 temp1 temp0 temp2 0)
            Graph(grDRAW_LINE temp3 temp1 temp3 temp2 0)
            Graph(grDRAW_LINE temp0 temp1 temp3 temp1 0)
            Graph(grDRAW_LINE temp0 temp2 temp3 temp2 0)
        )
        = temp4 (- (send param1:y) 1)
        = temp5 (- (send param1:x) 1)
        = temp7 (+ (send param1:y) 1)
        = temp6 (+ (send param1:x) 1)
        Graph(grDRAW_LINE temp4 temp5 temp4 temp6 44)
        Graph(grDRAW_LINE + temp4 1 temp5 + temp4 1 temp6 44)
        Graph(grDRAW_LINE temp7 temp5 temp7 temp6 44)
        = temp8 proc999_2(temp0 temp4)
        = temp9 proc999_2(temp1 temp5)
        = temp11 proc999_3(temp3 temp7)
        = temp10 proc999_3(temp2 temp6)
        Graph(grREDRAW_BOX temp8 temp9 + temp11 1 + temp10 1)
    )

)
(class NameFeatureCode of Code
    (properties)

    (method (init)
        (send gOldKH:addToFront(self))
        (send gGame:setCursor(999))
        (self:doit())
    )


    (method (doit)
        (var onMeAndLowYTheObj, temp1[40], newEvent, temp42[10])
        (while (not (self:handleEvent((= newEvent (Event:new())))))
            (send newEvent:localize())
            (OnMeAndLowY:init())
            (send gOldFeatures:eachElementDo(#perform OnMeAndLowY newEvent))
            (send gOldCast:eachElementDo(#perform OnMeAndLowY newEvent))
            = onMeAndLowYTheObj (OnMeAndLowY:theObj)
            (if (onMeAndLowYTheObj)
                (if ((send ((= onMeAndLowYTheObj (OnMeAndLowY:theObj))):onMeCheck) and (<> (send onMeAndLowYTheObj:onMeCheck) 26505))
                    Format(@temp42 25 0 (send onMeAndLowYTheObj:onMeCheck))
                )(else
                    (if ((send onMeAndLowYTheObj:respondsTo(#view)))
                        Format(@temp42 25 1 (send onMeAndLowYTheObj:view) (send onMeAndLowYTheObj:loop) (send onMeAndLowYTheObj:cel))
                    )(else
                        Format(@temp42 25 2 "")
                    )
                )
                DrawStatus(Format(@temp1 25 3 (send newEvent:x) (send newEvent:y) (send onMeAndLowYTheObj:name) (send ((send onMeAndLowYTheObj:{-super-})):name) @temp42))
            )
            (send newEvent:dispose())
        )
        (send newEvent:dispose())
        (self:dispose())
    )


    (method (dispose)
        DrawStatus(0)
        DrawStatus(" " 0 0)
        (if ((Print:
            addText("Erase outlines?")
            addButton(0 "No" 0 12)
            addButton(1 "Yes" 40 12)
            init()
        )
)
            DrawPic((send global2:picture) 100)
            (if (gOldATPs)
                (send gOldATPs:doit())
            )
        )
        (send gOldKH:delete(self))
        (send gTheDoits:delete(self))
        (send gGame:setCursor((send ((send gIconBar:curIcon)):cursor)))
    )


    (method (handleEvent pEvent)
        return 
            (if ((== (send pEvent:type) 4) and (== (send pEvent:message) 27))
                (send pEvent:claimed(1))
                return 1
            )(else
                0
            )
    )

)
(class JustifyText of Obj
    (properties
        lastX 0
        lastY 0
        unders 0
        font 2510
        color 0
    )

    (method (init)
        (super:init())
        (send gOldMH:addToFront(self))
        (send gOldKH:addToFront(self))
        (send gOldDH:addToFront(self))
        (send gTheDoits:addToFront(self))
        = local1 0
        proc921_2(@local1 50 "Enter text (after this, get help with '?')")
        (send gIconBar:curIcon((send gIconBar:at(5))))
        = theGCursorNumber gCursorNumber
        (send gGame:setCursor(69 0))
        (self:doit(1))
    )


    (method (doit param1)
        (var theLastX, theLastY)
        (if (paramTotal and param1)
            = lastX (= lastY 0)
        )
        = theLastX (send ((User:curEvent)):x)
        = theLastY (send ((User:curEvent)):y)
        (if ((<> theLastX lastX) or (<> theLastY lastY))
            (if (unders)
                Display(25 4 108 unders)
            )
            = unders Display(@local1 100 theLastX theLastY 102 color 103 
                    (if (color)
                        0
                    )(else
                        6
                    )
 105 font 107)
            = lastX theLastX
            = lastY theLastY
        )
    )


    (method (dispose)
        (send gOldMH:delete(self))
        (send gOldKH:delete(self))
        (send gOldDH:delete(self))
        (send gTheDoits:delete(self))
        (send gGame:setCursor(theGCursorNumber 1))
        UnLoad(133 unders)
        (super:dispose())
    )


    (method (handleEvent pEvent)
        (var temp0, pEventX, pEventY, pEventType, pEventMessage, pEventModifiers, temp6[25])
        = pEventX (send pEvent:x)
        = pEventY (send pEvent:y)
        = pEventType (send pEvent:type)
        = pEventMessage (send pEvent:message)
        = pEventModifiers (send pEvent:modifiers)
        (if (== pEventType 4)
            (switch (pEventMessage)
                (case 27
                    Display(25 4 108 unders)
                    (self:dispose())
                )
                (case 13
                    (self:showCoord(pEvent))
                )
                (case 6
                    (switch (font)
                        (case 1207
                            = font 2107
                        )
                        (case 2107
                            = font 2108
                        )
                        (case 2108
                            = font 2407
                        )
                        (case 2407
                            = font 2510
                        )
                        (case 2510
                            = font 4115
                        )
                        (case 4115
                            = font 999
                        )
                        (case 999
                            = font 0
                        )
                        (default 
                            = font proc255_1("Font Number:")
                        )
                    )
                    (send gGame:setCursor(gCursorNumber 0 pEventX pEventY))
                    (self:doit(1))
                )
                (case 14
                    = temp6 0
                    proc921_2(@temp6 50 "Enter text (then get help with `?')")
                    (if (temp6)
                        StrCpy(@local1 @temp6)
                        = lastX (= lastY 0)
                        (self:doit(1))
                    )
                )
                (case 3
                    (if (> ++color 15)
                        = color 0
                    )
                    (self:doit(1))
                )
                (case 63
                    proc921_0("Move text with mouse or direction keys\nSHIFT + arrows for fine adjustment\n\nENTER or click shows text position\n\nCtrl-F (shift click) changes font\nCtrl-N to enter new text\nCtrl-C (control click) changes color\nESC aborts")
                )
            )
            (send pEvent:claimed(1))
        )(else
            (if (== pEventType 1)
                (if (& pEventModifiers $0003)
                    (send pEvent:
                        type(4)
                        message(6)
                    )
                    (self:handleEvent(pEvent))
                )(else
                    (if (& pEventModifiers $0004)
                        (send pEvent:
                            type(4)
                            message(3)
                        )
                        (self:handleEvent(pEvent))
                    )(else
                        (self:showCoord(pEvent))
                        (send pEvent:claimed(1))
                    )
                )
            )(else
                (if (& pEventType $0040)
                    = temp0 
                        (if (& pEventModifiers $0003)
                            1
                        )(else
                            10
                        )
                    (if (proc999_5(pEventMessage 3 2 4))
                        = pEventX (+ pEventX temp0)
                    )
                    (if (proc999_5(pEventMessage 7 8 6))
                        = pEventX (- pEventX temp0)
                    )
                    (if (proc999_5(pEventMessage 8 1 2))
                        = pEventY (- pEventY temp0)
                    )
                    (if (proc999_5(pEventMessage 6 5 4))
                        = pEventY (+ pEventY temp0)
                    )
                    (send pEvent:claimed(1))
                    (send gGame:setCursor(gCursorNumber 0 pEventX pEventY))
                    (self:doit())
                )
            )
        )
    )


    (method (showCoord param1)
        (Print:
            addTextF("Position: %d, %d" (send param1:x) (send param1:y))
            init()
        )
        (self:dispose())
    )

)
