@name New EGP
@inputs EGP:wirelink Up Down
@outputs Inc X Selector Item Last Colors:table
@persist [O E]:entity Tool_List:array [Screen Box Boxes Step Border Menu_Limits]:vector2
@model models/jaanus/wiretool/wiretool_waypoint.mdl

if( duped() ){ reset() }

if(first())
{
    E = EGP:entity()
    O = owner()
    
    EGP:egpClear()
    
    function string getFont(N)
    {
        return select(N,"WireGPU_ConsoleFont",
                    "Coolvetica",
                    "Arial",
                    "Lucida Console",
                    "Trebuchet",
                    "Courier New",
                    "Times New Roman",
                    "ChatFont",
                    "Marlett")
    }
    function number getID(N)
    {
        return EGP:egpNumObjects() + N
    }
    
    Tool_List = array( "easy_precision",
                        "axis",
                        "ballsocket_adv",
                        "elastic",
                        "hydraulic",
                        "muscle",
                        "superparentmulti",
                        "rope",
                        "smart_constraint",
                        "slider",
                        "weld_ez",
                        "weld",
                        "adv_duplicator",
                        "ignite",
                        "hoverball",
                        "dynamite",
                        "duplicator",
                        "bridgetool",
                        "balloon",
                        "freezer",
                        "remover",
                        "physprop",
                        "no_collide_multi",
                        "light",
                        "keepupright",
                        "ol_stacker",
                        "wheel",
                        "weight",
                        "turret",
                        "thruster",
                        "cratemaker",
                        "camera",
                        "colour",
                        "material",
                        "trails",
                        "rtcamera",
                        "paint",
                        "inflator",
                        "statue",
                        "ol_measuringstick",
                        "freezer",
                        "modelmanipulator",
                        "gravturret",
                        "adv_spawner",
                        "positionswitcher",
                        "fadingdoor",
                        "breakableprops",
                        "wire_expression2",
                        "wire_cam",
                        "wire_adv_pod",
                        "wire_numpad",
                        "wire_winch",
                        "wire_dupeport",
                        "wire_vehicle",
                        "wire_keyboard",
                        "wire_rtcam",
                        "wire_joystick_multi",
                        "wire_button",
                        "wire_explosive",
                        "wire_forcer",
                        "wire_grabber",
                        "wire_hoverball",
                        "wire_hydraulic",
                        "wire_thruster",
                        "wire_turret",
                        "wire_user",
                        "wire_vthruster",
                        "wire_wheel",
                        "multi_wire",
                        "wire_adv",
                        "wire_simulate_data" )

    Screen = egpScrSize( findPlayerByName("capt") )
    Box = vec2(Screen[1] / 2,Screen[2]) / 1.5
    
    EGP:egpRoundedBox( getID(1), vec2(Screen[1]-Box[1]/2,Box[2]/2), Box )
    EGP:egpColor( getID(0), hsv2rgb(200,1/6,2/7) )
    EGP:egpRadius( getID(0), 6 )
    
    Boxes = vec2( 3, 24 )
    Step = Box / Boxes
    Border = vec2(4,4)
    
    runOnTick(1)
    
    Menu_Limits = vec2(2, ( Boxes[1] * Boxes[2] ) * 2 - 2 )
    
    Item = 2
}

while(X<Boxes[1] & perf())
{
    X++
    for(I=1,Boxes[2])
    {
        Inc++
        Swap = I%2==0
        EGP:egpRoundedBox( getID(1), vec2(Screen[1]-Box[1] + Step[1]*(X-0.5),Step[2]*(I-0.5)), Step - Border )
        EGP:egpColor( getID(0), hsv2rgb(200,1/6,Swap ? 0.6 : 0.45) )
        Colors[ getID(0), vector ] = hsv2rgb(200,1/6,Swap ? 0.6 : 0.45)
        EGP:egpRadius( getID(0), 6 )
        
        #Pos = EGP:egpPos( getID(-1) )
        EGP:egpText( getID(1), Tool_List[ Inc, string], vec2(0,-Step[2]/4) )
        EGP:egpFont( getID(0), "", 15 )
        EGP:egpAlign( getID(0), 1 )
        EGP:egpParent( getID(0), getID(-1) )
    }
    if( X==Boxes[1] )
    {
        Selector = getID(-1)
        #EGP:egpColor( Selector, vec(255,255,0) )
        #EGP:egpPos( Selector, EGP:egpPos(Item) )
        EGP:egpColor( Item, vec(255,255,0) )
        EGP:egpColor( Item + 1, vec() )
        Last = Item + 1
    }
}

if( ~Up | ~Down )
{
    EGP:egpColor( Last, vec() + 255 )
    EGP:egpColor( Last - 1, Colors[Last-1,vector] )
    Item = clamp( Item + (Up - Down) * 2, Menu_Limits[1], Menu_Limits[2] )
    #EGP:egpPos( Selector, EGP:egpPos(Item) )
    EGP:egpColor( Item, vec(255,255,0) )
    EGP:egpColor( Item + 1, vec() )
    Last = Item + 1
}
