The Shaggy Selector or how to add a menu pop up

Developer discussion of experimental fixes, changes, and improvements.

Moderators: Nexuiz Moderators, Moderators


  • Several days ago on IRC, [GT] Shaggy asked if it was possible to have an ingame pop-up with lots of command buttons. After much experimenting with the menu code I managed to create two pop-ups.

    1) A modified version of the F5 Team Select menu. I'll make a seperate post about it.

    2) A new menu with 18 buttons

    Image

    You can change the width, colour, label and action of all the buttons - you can even hide them. You can also change the pop-ups title, colour and width, but currently not its height.

    Image


    Use the diff's in this zip http://www.leela.org.uk/nexuiz/?action=show&file=shaggy_selector.zip or try and follow the notes below.

    Add to Nexuiz/trunk/data/qcsrc/menu/classes.c
    Code: Select all
    #include "nexuiz/dialog_shaggyselect.c



    Add to Nexuiz/trunk/data/qcsrc/menu/nexuiz/mainwindow.c
    Code: Select all
    near the start

    ATTRIB(MainWindow, shaggyInfoDialog, entity, NULL)


    in the middle

    i = spawnNexuizShaggySelectDialog();

    i.configureDialog(i);

    me.addItemCentered(me, i, i.intendedWidth * eX + i.intendedHeight * eY, SKINALPHAS_MAINMENU_z);




    Create dialog_shaggyselect.c in Nexuiz/trunk/data/qcsrc/menu/nexuiz/ with the following code
    Code: Select all
    #ifdef INTERFACE
    CLASS(NexuizShaggySelectDialog) EXTENDS(NexuizRootDialog)
       METHOD(NexuizShaggySelectDialog, fill, void(entity))  // to be overridden by user to fill the dialog with controls
       ATTRIB(NexuizShaggySelectDialog, title, string, strzone(cvar_string("msb_name")))  // name of the pop up
       ATTRIB(NexuizShaggySelectDialog, color, vector, stov(cvar_string("msb_colour")))  // 'R G B' range 0 - 1
       ATTRIB(NexuizShaggySelectDialog, intendedWidth, float, cvar("msb_width"))  // width of the pop up 0 - 1
       ATTRIB(NexuizShaggySelectDialog, intendedHeight, float, cvar("msb_height"))  // height of the pop up 0 - 1
       ATTRIB(NexuizShaggySelectDialog, rows, float, cvar("msb_rows"))  // number of rows
       ATTRIB(NexuizShaggySelectDialog, columns, float, cvar("msb_columns"))  // number of columns
       ATTRIB(NexuizShaggySelectDialog, name, string, "ShaggySelect")  // name used to call the pop up
    ENDCLASS(NexuizShaggySelectDialog)

    float msb_width(string);
    string msb_label(string);
    vector msb_colour(string);
    string msb_action(string);
    #endif

    #ifdef IMPLEMENTATION
    entity makeShaggyButton(string theName, vector theColor, string commandtheName)
    {
       entity b;
       b = makeNexuizCommandButton(theName, theColor, commandtheName, 1);
       return b;
    }

    void fillNexuizShaggySelectDialog(entity me)
    {
       me.TR(me);
          if (msb_width("0") > 0)
             me.TD(me, 1, msb_width("0"), makeShaggyButton(msb_label("0"), msb_colour("0"), msb_action("0")));
          if (msb_width("1") > 0)
             me.TD(me, 1, msb_width("1"), makeShaggyButton(msb_label("1"), msb_colour("1"), msb_action("1")));
          if (msb_width("2") > 0)
             me.TD(me, 1, msb_width("2"), makeShaggyButton(msb_label("2"), msb_colour("2"), msb_action("2")));
       me.TR(me);
          if (msb_width("3") > 0)
             me.TD(me, 1, msb_width("3"), makeShaggyButton(msb_label("3"), msb_colour("3"), msb_action("3")));
          if (msb_width("4") > 0)
             me.TD(me, 1, msb_width("4"), makeShaggyButton(msb_label("4"), msb_colour("4"), msb_action("4")));
          if (msb_width("5") > 0)
             me.TD(me, 1, msb_width("5"), makeShaggyButton(msb_label("5"), msb_colour("5"), msb_action("5")));
       me.TR(me);
          if (msb_width("6") > 0)
             me.TD(me, 1, msb_width("6"), makeShaggyButton(msb_label("6"), msb_colour("6"), msb_action("6")));
          if (msb_width("7") > 0)
             me.TD(me, 1, msb_width("7"), makeShaggyButton(msb_label("7"), msb_colour("7"), msb_action("7")));
          if (msb_width("8") > 0)
             me.TD(me, 1, msb_width("8"), makeShaggyButton(msb_label("8"), msb_colour("8"), msb_action("8")));
       me.TR(me);
          if (msb_width("9") > 0)
             me.TD(me, 1, msb_width("9"), makeShaggyButton(msb_label("9"), msb_colour("9"), msb_action("9")));
          if (msb_width("10") > 0)
             me.TD(me, 1, msb_width("10"), makeShaggyButton(msb_label("10"), msb_colour("10"), msb_action("10")));
          if (msb_width("11") > 0)
             me.TD(me, 1, msb_width("11"), makeShaggyButton(msb_label("11"), msb_colour("11"), msb_action("11")));
       me.TR(me);
          if (msb_width("12") > 0)
             me.TD(me, 1, msb_width("12"), makeShaggyButton(msb_label("12"), msb_colour("12"), msb_action("12")));
          if (msb_width("13") > 0)
             me.TD(me, 1, msb_width("13"), makeShaggyButton(msb_label("13"), msb_colour("13"), msb_action("13")));
          if (msb_width("14") > 0)
             me.TD(me, 1, msb_width("14"), makeShaggyButton(msb_label("14"), msb_colour("14"), msb_action("14")));
       me.TR(me);
          if (msb_width("15") > 0)
             me.TD(me, 1, msb_width("15"), makeShaggyButton(msb_label("15"), msb_colour("15"), msb_action("15")));
          if (msb_width("16") > 0)
             me.TD(me, 1, msb_width("16"), makeShaggyButton(msb_label("16"), msb_colour("16"), msb_action("16")));
          if (msb_width("17") > 0)
             me.TD(me, 1, msb_width("17"), makeShaggyButton(msb_label("17"), msb_colour("17"), msb_action("17")));
       me.TR(me);
    }

    float msb_width(string btn)
    {
       return cvar(strcat("msb_width", btn));
    }

    string msb_label(string btn)
    {
       return strzone(cvar_string((strcat("msb_label", btn))));
    }

    vector msb_colour(string btn)
    {
       return stov(cvar_string(strcat("msb_colour", btn)));
    }

    string msb_action(string btn)
    {
       return strzone(cvar_string((strcat("msb_action", btn))));
    }
    #endif

    // click. The C-word so you can grep for it.



    Create menu.cfg in .nexuiz/data/ (or ? on Windows) and add the following lines to it

    Code: Select all
    //shaggy select
    set msb_name "Shaggy Selector"  // name of the pop up
    set msb_colour "0.7 0.7 1"  // 'R G B' range 0 - 1
    set msb_width 0.4  // width of the pop up 0 - 1
    set msb_height 0.4  // height of the pop up 0 - 1
    set msb_rows 6  // number of rows
    set msb_columns 6  // number of columns

    //row 0
    set msb_width0 2.0
    set msb_label0 "0"
    set msb_action0 "say 0"
    set msb_colour0 "0.8 0.4 0.1"

    set msb_width1 2.0
    set msb_label1 "1"
    set msb_action1 "say 1"
    set msb_colour1 "0.5 0 0.6"

    set msb_width2 2.0
    set msb_label2 "2"
    set msb_action2 "say 2"
    set msb_colour2 "0.9 0 0.9"

    //row 1
    set msb_width3 2.0
    set msb_label3 "3"
    set msb_action3 "say 3"
    set msb_colour3 "0.1 0.5 0.9"

    set msb_width4 2.0
    set msb_label4 "4"
    set msb_action4 "say 4"
    set msb_colour4 "0.6 0.9 0.9"

    set msb_width5 2.0
    set msb_label5 "5"
    set msb_action5 "say 5"
    set msb_colour5 "1 0.3 0.5"

    //row 2
    set msb_width6 2.0
    set msb_label6 "6"
    set msb_action6 "say 6"
    set msb_colour6 "0.2 0.5 0.1"

    set msb_width7 2.0
    set msb_label7 "7"
    set msb_action7 "say 7"
    set msb_colour7 "0.9 0.4 0.1"

    set msb_width8 2.0
    set msb_label8 "8"
    set msb_action8 "say 8"
    set msb_colour8 "0.8 0.2 0.9"

    //row 3
    set msb_width9 2.0
    set msb_label9 "9"
    set msb_action9 "say 9"
    set msb_colour9 "0.5 0.5 0.6"

    set msb_width10 2.0
    set msb_label10 "10"
    set msb_action10 "say 10"
    set msb_colour10 "0.3 0 0.3"

    set msb_width11 2.0
    set msb_label11 "11"
    set msb_action11 "say 11"
    set msb_colour11 "0.4 0.5 0.2"

    //row 4
    set msb_width12 2.0
    set msb_label12 "12"
    set msb_action12 "say 12"
    set msb_colour12 "0.2 0.6 0.7"

    set msb_width13 2.0
    set msb_label13 "13"
    set msb_action13 "say 13"
    set msb_colour13 "0.9 0.9 1"

    set msb_width14 2.0
    set msb_label14 "14"
    set msb_action14 "say 14"
    set msb_colour14 "0.8 0.9 0.7"

    //row 5
    set msb_width15 2.0
    set msb_label15 "15"
    set msb_action15 "say 15"
    set msb_colour15 "0.3 0.7 0.5"

    set msb_width16 2.0
    set msb_label16 "16"
    set msb_action16 "say 16"
    set msb_colour16 "0.7 0.4 0.3"

    set msb_width17 2.0
    set msb_label17 "17"
    set msb_action17 "say 17"
    set msb_colour17 "0.6 0.2 0.5"
    //end



    Add the following to your autoexec.cfg
    Code: Select all
    exec menu.cfg  // load the new menu buttons



    Use bind ?? "menu_cmd directmenu ShaggySelect" to show the new pop-up.
    Last edited by Spaceman on Sun Jul 13, 2008 7:13 pm, edited 1 time in total.
    Spaceman
    Alien trapper
     
    Posts: 264
    Joined: Tue Aug 28, 2007 10:53 am

Fri Jul 11, 2008 11:15 pm

  • Do you want me to write some binds for this?
    User avatar
    shaggy
    Alien trapper
     
    Posts: 419
    Joined: Tue Apr 03, 2007 6:12 am

Tue Dec 23, 2008 2:00 am

Tue Dec 23, 2008 2:20 am

  • I am thinking of putting a log in screen which user can register to get the username and password from server,

    any idea :)
    X-vEn-TuRE
    Xventure7
    Member
     
    Posts: 16
    Joined: Wed Dec 17, 2008 10:15 am
    Location: US

Tue Dec 23, 2008 6:01 pm

  • How many possibilites does the menu code give you? Could one have access to things like the playerlist on the server so that I could somehow have a "admin menu" where I can select players and kick them using a GUI, and getting away from feeling like a linux user who likes ancient console commands ?
    IRC quote:
    [kojn] I've been coming a bit more recently
    [kojn] she took it the dirty way
    GreEn`mArine
    Forum addon
     
    Posts: 1509
    Joined: Tue Feb 28, 2006 9:33 pm
    Location: Germany

Tue Dec 23, 2008 7:42 pm

  • bah, no it doesn't (or I haven't noticed that it's possible). Unless you code another menu for rcon or add extensions to dp.

    Btw, console has power (you can't batch jobs using gui usually).
    Alien
    Forum addon
     
    Posts: 1212
    Joined: Tue Apr 22, 2008 7:12 am

Tue Dec 23, 2008 8:46 pm

  • GreEn`mArine wrote:How many possibilites does the menu code give you? Could one have access to things like the playerlist on the server so that I could somehow have a "admin menu" where I can select players and kick them using a GUI, and getting away from feeling like a linux user who likes ancient console commands ?


    This is actually what I was beginning to work on. It's a little above my head at the moment... but so far I've been able to create a new element that's a textbox/button combo. I'm trying to keep this abstract so we can have the code written once and update the internals via cfg files.

    I figured I could pull the player info in a similar manner to the server info window... but I'm not sure if that has the player numbers needed to do the action.

    Ideally, I'd like a list of players on the server, with a filter box much like the server list... so you filter / highlight the name of the player and take action via buttons on the right >> mute, kick, ban, etc.
    User avatar
    [-z-]
    Site Admin and Nexuiz Ninja
     
    Posts: 1794
    Joined: Mon Nov 13, 2006 12:20 am
    Location: Florida



Return to Nexuiz - Development




Information
  • Who is online
  • Users browsing this forum: No registered users and 1 guest