Exemplo n.º 1
0
Arquivo: script.c Projeto: m4son/q2pro
static void Parse_Savegame(menuFrameWork_t *menu, menuType_t type)
{
    menuAction_t *a;
    char *status = NULL;
    int c;

    while ((c = Cmd_ParseOptions(o_common)) != -1) {
        switch (c) {
        case 's':
            status = cmd_optarg;
            break;
        default:
            return;
        }
    }

    if (Cmd_Argc() - cmd_optind < 1) {
        Com_Printf("Usage: %s <dir>\n", Cmd_Argv(0));
        return;
    }

    a = UI_Mallocz(sizeof(*a));
    a->generic.type = type;
    a->generic.name = UI_CopyString("<EMPTY>");
    a->generic.activate = Activate;
    a->generic.uiFlags = UI_CENTER;
    a->generic.status = UI_CopyString(status);
    a->cmd = UI_CopyString(Cmd_Argv(cmd_optind));

    if (type == MTYPE_LOADGAME)
        a->generic.flags |= QMF_GRAYED;

    Menu_AddItem(menu, a);
}
Exemplo n.º 2
0
Arquivo: script.c Projeto: m4son/q2pro
static void Parse_Field(menuFrameWork_t *menu)
{
    static const cmd_option_t o_field[] = {
        { "c", "center" },
        { "i", "integer" },
        { "n", "numeric" },
        { "s:", "status" },
        { "w:", "width" },
        { NULL }
    };
    menuField_t *f;
    qboolean center = qfalse;
    int flags = 0;
    char *status = NULL;
    int width = 16;
    int c;

    while ((c = Cmd_ParseOptions(o_field)) != -1) {
        switch (c) {
        case 'c':
            center = qtrue;
            break;
        case 'i':
        case 'n':
            flags |= QMF_NUMBERSONLY;
            break;
        case 's':
            status = cmd_optarg;
            break;
        case 'w':
            width = atoi(cmd_optarg);
            if (width < 1 || width > 32) {
                Com_Printf("Invalid width\n");
                return;
            }
            break;
        default:
            return;
        }
    }

    f = UI_Mallocz(sizeof(*f));
    f->generic.type = MTYPE_FIELD;
    f->generic.name = center ? NULL : UI_CopyString(Cmd_Argv(cmd_optind));
    f->generic.status = UI_CopyString(status);
    f->generic.flags = flags;
    f->cvar = Cvar_WeakGet(Cmd_Argv(center ? cmd_optind : cmd_optind + 1));
    f->width = width;

    Menu_AddItem(menu, f);
}
Exemplo n.º 3
0
Arquivo: script.c Projeto: m4son/q2pro
static void Parse_Toggle(menuFrameWork_t *menu)
{
    static const char *yes_no_names[] = { "no", "yes", NULL };
    menuSpinControl_t *s;
    qboolean negate = qfalse;
    menuType_t type = MTYPE_TOGGLE;
    int c, bit = 0;
    char *b, *status = NULL;

    while ((c = Cmd_ParseOptions(o_common)) != -1) {
        switch (c) {
        case 's':
            status = cmd_optarg;
            break;
        default:
            return;
        }
    }

    if (Cmd_Argc() - cmd_optind < 2) {
        Com_Printf("Usage: %s <name> <cvar> [~][bit]\n", Cmd_Argv(0));
        return;
    }

    b = Cmd_Argv(cmd_optind + 2);
    if (*b == '~') {
        negate = qtrue;
        b++;
    }
    if (*b) {
        bit = atoi(b);
        if (bit < 0 || bit >= 32) {
            Com_Printf("Invalid bit number: %d\n", bit);
            return;
        }
        type = MTYPE_BITFIELD;
    }

    s = UI_Mallocz(sizeof(*s));
    s->generic.type = type;
    s->generic.name = UI_CopyString(Cmd_Argv(cmd_optind));
    s->generic.status = UI_CopyString(status);
    s->cvar = Cvar_WeakGet(Cmd_Argv(cmd_optind + 1));
    s->itemnames = (char **)yes_no_names;
    s->numItems = 2;
    s->negate = negate;
    s->mask = 1U << bit;

    Menu_AddItem(menu, s);
}
Exemplo n.º 4
0
static void M_Custom_Init( void )
{
	menucommon_t *menuitem = NULL;
	int yoffset = 40;
	int i, count;

	s_custom_menu.nitems = 0;

	// parse the command line to create the buttons

	if( trap_Cmd_Argc() < 1 )
		return;

	// first one is always the tittle

	menuitem = UI_InitMenuItem( "m_custom_title1", trap_Cmd_Argv( 1 ), 0, yoffset, MTYPE_SEPARATOR, ALIGN_CENTER_TOP, uis.fontSystemBig, NULL );
	Menu_AddItem( &s_custom_menu, menuitem );
	yoffset += trap_SCR_strHeight( menuitem->font );

	yoffset += trap_SCR_strHeight( menuitem->font );

	// from now on each 2 new arguments define a new button
	for( i = 2, count = 0; i < trap_Cmd_Argc(); i += 2, count++ )
	{
		menuitem = UI_InitMenuItem( va( "m_custom_button%i", count ), trap_Cmd_Argv( i ), 0, yoffset, MTYPE_ACTION, ALIGN_CENTER_TOP, uis.fontSystemBig, M_Custom_ExecuteButton );
		menuitem->itemlocal = UI_CopyString( trap_Cmd_Argv( i + 1 ) );
		Menu_AddItem( &s_custom_menu, menuitem );
		yoffset += UI_SetupButton( menuitem, qtrue ) + UI_BUTTONBOX_VERTICAL_SPACE;
	}

	Menu_Center( &s_custom_menu );
	Menu_Init( &s_custom_menu, qtrue );
	Menu_SetStatusBar( &s_custom_menu, NULL );
}
Exemplo n.º 5
0
Arquivo: script.c Projeto: m4son/q2pro
static void add_string(menuSpinControl_t *s, const char *tok)
{
    if (s->numItems < MAX_MENU_ITEMS) {
        s->itemnames = Z_Realloc(s->itemnames, ALIGN(s->numItems + 2, MIN_MENU_ITEMS) * sizeof(char *));
        s->itemnames[s->numItems++] = UI_CopyString(tok);
    }
}
Exemplo n.º 6
0
Arquivo: script.c Projeto: m4son/q2pro
static void Parse_Bitmap(menuFrameWork_t *menu)
{
    static const cmd_option_t o_bitmap[] = {
        { "s:", "status" },
        { "N:", "altname" },
        { NULL }
    };
    menuBitmap_t *b;
    char *status = NULL, *altname = NULL;
    int c;

    while ((c = Cmd_ParseOptions(o_bitmap)) != -1) {
        switch (c) {
        case 's':
            status = cmd_optarg;
            break;
        case 'N':
            altname = cmd_optarg;
            break;
        default:
            return;
        }
    }

    if (Cmd_Argc() - cmd_optind < 2) {
        Com_Printf("Usage: %s <name> <command>\n", Cmd_Argv(0));
        return;
    }

    if (!altname)
        altname = va("%s_sel", Cmd_Argv(cmd_optind));

    b = UI_Mallocz(sizeof(*b));
    b->generic.type = MTYPE_BITMAP;
    b->generic.activate = Activate;
    b->generic.status = UI_CopyString(status);
    b->cmd = UI_CopyString(Cmd_ArgsFrom(cmd_optind + 1));
    b->pics[0] = R_RegisterPic(Cmd_Argv(cmd_optind));
    b->pics[1] = R_RegisterPic(altname);
    R_GetPicSize(&b->generic.width, &b->generic.height, b->pics[0]);

    Menu_AddItem(menu, b);
}
Exemplo n.º 7
0
Arquivo: script.c Projeto: m4son/q2pro
static void Parse_Spin(menuFrameWork_t *menu, menuType_t type)
{
    menuSpinControl_t *s;
    int c, i, numItems;
    char *status = NULL;

    while ((c = Cmd_ParseOptions(o_common)) != -1) {
        switch (c) {
        case 's':
            status = cmd_optarg;
            break;
        default:
            return;
        }
    }

    numItems = Cmd_Argc() - (cmd_optind + 2);
    if (numItems < 1) {
        Com_Printf("Usage: %s <name> <cvar> <desc1> [...]\n", Cmd_Argv(0));
        return;
    }

    s = UI_Mallocz(sizeof(*s));
    s->generic.type = type;
    s->generic.name = UI_CopyString(Cmd_Argv(cmd_optind));
    s->generic.status = UI_CopyString(status);
    s->cvar = Cvar_WeakGet(Cmd_Argv(cmd_optind + 1));

    cmd_optind += 2;
    if (strchr(Cmd_ArgsFrom(cmd_optind), '$')) {
        long_args_hack(s, numItems);
    } else {
        s->itemnames = UI_Mallocz(sizeof(char *) * (numItems + 1));
        for (i = 0; i < numItems; i++) {
            s->itemnames[i] = UI_CopyString(Cmd_Argv(cmd_optind + i));
        }
        s->numItems = numItems;
    }

    Menu_AddItem(menu, s);
}
Exemplo n.º 8
0
Arquivo: script.c Projeto: m4son/q2pro
static void Parse_Action(menuFrameWork_t *menu)
{
    static const cmd_option_t o_action[] = {
        { "a", "align" },
        { "s:", "status" },
        { NULL }
    };
    menuAction_t *a;
    int uiFlags = UI_CENTER;
    char *status = NULL;
    int c;

    while ((c = Cmd_ParseOptions(o_action)) != -1) {
        switch (c) {
        case 'a':
            uiFlags = UI_LEFT | UI_ALTCOLOR;
            break;
        case 's':
            status = cmd_optarg;
            break;
        default:
            return;
        }
    }

    if (Cmd_Argc() - cmd_optind < 2) {
        Com_Printf("Usage: %s <name> <command>\n", Cmd_Argv(0));
        return;
    }

    a = UI_Mallocz(sizeof(*a));
    a->generic.type = MTYPE_ACTION;
    a->generic.name = UI_CopyString(Cmd_Argv(cmd_optind));
    a->generic.activate = Activate;
    a->generic.uiFlags = uiFlags;
    a->generic.status = UI_CopyString(status);
    a->cmd = UI_CopyString(Cmd_ArgsFrom(cmd_optind + 1));

    Menu_AddItem(menu, a);
}
Exemplo n.º 9
0
Arquivo: script.c Projeto: m4son/q2pro
static void Parse_Bind(menuFrameWork_t *menu)
{
    static const cmd_option_t o_bind[] = {
        { "s:", "status" },
        { "S:", "altstatus" },
        { NULL }
    };
    menuKeybind_t *k;
    char *status = "Press Enter to change, Backspace to clear";
    char *altstatus = "Press the desired key, Escape to cancel";
    int c;

    while ((c = Cmd_ParseOptions(o_bind)) != -1) {
        switch (c) {
        case 's':
            status = cmd_optarg;
            break;
        case 'S':
            altstatus = cmd_optarg;
            break;
        default:
            return;
        }
    }

    if (Cmd_Argc() - cmd_optind < 2) {
        Com_Printf("Usage: %s <name> <command>\n", Cmd_Argv(0));
        return;
    }

    k = UI_Mallocz(sizeof(*k));
    k->generic.type = MTYPE_KEYBIND;
    k->generic.name = UI_CopyString(Cmd_Argv(cmd_optind));
    k->generic.uiFlags = UI_CENTER;
    k->generic.status = UI_CopyString(status);
    k->cmd = UI_CopyString(Cmd_ArgsFrom(cmd_optind + 1));
    k->altstatus = UI_CopyString(altstatus);

    Menu_AddItem(menu, k);
}
Exemplo n.º 10
0
Arquivo: script.c Projeto: m4son/q2pro
static void Parse_Pairs(menuFrameWork_t *menu)
{
    menuSpinControl_t *s;
    int c, i, numItems;
    char *status = NULL;

    while ((c = Cmd_ParseOptions(o_common)) != -1) {
        switch (c) {
        case 's':
            status = cmd_optarg;
            break;
        default:
            return;
        }
    }

    numItems = Cmd_Argc() - (cmd_optind + 2);
    if (numItems < 2 || (numItems & 1)) {
        Com_Printf("Usage: %s <name> <cvar> <desc1> <value1> [...]\n", Cmd_Argv(0));
        return;
    }

    s = UI_Mallocz(sizeof(*s));
    s->generic.type = MTYPE_PAIRS;
    s->generic.name = UI_CopyString(Cmd_Argv(cmd_optind));
    s->generic.status = UI_CopyString(status);
    s->cvar = Cvar_WeakGet(Cmd_Argv(cmd_optind + 1));
    numItems /= 2;
    s->itemnames = UI_Mallocz(sizeof(char *) * (numItems + 1));
    s->itemvalues = UI_Mallocz(sizeof(char *) * (numItems + 1));
    for (i = 0; i < numItems; i++) {
        s->itemnames[i] = UI_CopyString(Cmd_Argv(cmd_optind + 2 + i * 2));
        s->itemvalues[i] = UI_CopyString(Cmd_Argv(cmd_optind + 3 + i * 2));
    }
    s->numItems = numItems;

    Menu_AddItem(menu, s);
}
Exemplo n.º 11
0
Arquivo: script.c Projeto: m4son/q2pro
static void Parse_Range(menuFrameWork_t *menu)
{
    menuSlider_t *s;
    char *status = NULL;
    int c;

    while ((c = Cmd_ParseOptions(o_common)) != -1) {
        switch (c) {
        case 's':
            status = cmd_optarg;
            break;
        default:
            return;
        }
    }

    if (Cmd_Argc() - cmd_optind < 4) {
        Com_Printf("Usage: %s <name> <cvar> <min> <max> [step]\n", Cmd_Argv(0));
        return;
    }

    s = UI_Mallocz(sizeof(*s));
    s->generic.type = MTYPE_SLIDER;
    s->generic.name = UI_CopyString(Cmd_Argv(cmd_optind));
    s->generic.status = UI_CopyString(status);
    s->cvar = Cvar_WeakGet(Cmd_Argv(cmd_optind + 1));
    s->minvalue = atof(Cmd_Argv(cmd_optind + 2));
    s->maxvalue = atof(Cmd_Argv(cmd_optind + 3));
    if (Cmd_Argc() - cmd_optind > 4) {
        s->step = atof(Cmd_Argv(cmd_optind + 4));
    } else {
        s->step = (s->maxvalue - s->minvalue) / SLIDER_RANGE;
    }

    Menu_AddItem(menu, s);
}
Exemplo n.º 12
0
static void AddServer(const netadr_t *address, const char *hostname)
{
    netadr_t tmp;
    serverslot_t *slot;

    if (m_servers.list.numItems >= MAX_STATUS_SERVERS)
        return;

    if (!address) {
        // either address or hostname can be NULL, but not both
        if (!hostname)
            return;

        if (!NET_StringToAdr(hostname, &tmp, PORT_SERVER)) {
            Com_Printf("Bad server address: %s\n", hostname);
            return;
        }

        address = &tmp;
    }

    // ignore if already listed
    if (FindSlot(address, NULL))
        return;

    if (!hostname)
        hostname = NET_AdrToString(address);

    // privileged ports are not allowed
    if (BigShort(address->port) < 1024) {
        Com_Printf("Bad server port: %s\n", hostname);
        return;
    }

    slot = UI_FormatColumns(SLOT_EXTRASIZE, hostname,
                            "???", "???", "?/?", "???", NULL);
    slot->status = SLOT_IDLE;
    slot->address = *address;
    slot->hostname = UI_CopyString(hostname);
    slot->color = U32_WHITE;
    slot->numRules = 0;
    slot->numPlayers = 0;
    slot->timestamp = com_eventTime;

    m_servers.list.items[m_servers.list.numItems++] = slot;
}
Exemplo n.º 13
0
void PlayerModel_Load(void)
{
    char scratch[MAX_QPATH];
    size_t len;
    int ndirs = 0;
    char *dirnames[MAX_PLAYERMODELS];
    int i, j;
    char **list;
    char *s, *p;
    int numFiles;
    playerModelInfo_t *pmi;

    uis.numPlayerModels = 0;

    // get a list of directories
    if (!(list = (char **)FS_ListFiles(NULL, "players/*/tris.md2", FS_SEARCH_BYFILTER | FS_SEARCH_SAVEPATH, &numFiles))) {
        return;
    }

    for (i = 0; i < numFiles; i++) {
        len = Q_strlcpy(scratch, list[i], sizeof(scratch));
        if (len >= sizeof(scratch))
            continue;

        // make short name for the model
        if (!(s = strchr(scratch, '/')))
            continue;
        s++;

        if (!(p = strchr(s, '/')))
            continue;
        *p = 0;

        for (j = 0; j < ndirs; j++) {
            if (!strcmp(dirnames[j], s)) {
                break;
            }
        }

        if (j != ndirs) {
            continue;
        }

        dirnames[ndirs++] = UI_CopyString(s);
        if (ndirs == MAX_PLAYERMODELS) {
            break;
        }
    }

    FS_FreeList((void **)list);

    if (!ndirs) {
        return;
    }

    // go through the subdirectories
    for (i = 0; i < ndirs; i++) {
        int k, s;
        char **pcxnames;
        char **skinnames;
        int npcxfiles;
        int nskins = 0;

        // verify the existence of tris.md2
        Q_concat(scratch, sizeof(scratch), "players/", dirnames[i], "/tris.md2", NULL);
        if (!FS_FileExists(scratch)) {
            goto skip;
        }

        // verify the existence of at least one pcx skin
        Q_concat(scratch, sizeof(scratch), "players/", dirnames[i], NULL);
        pcxnames = (char **)FS_ListFiles(scratch, ".pcx", 0, &npcxfiles);
        if (!pcxnames) {
            goto skip;
        }

        // count valid skins, which consist of a skin with a matching "_i" icon
        for (k = 0; k < npcxfiles; k++) {
            if (!strstr(pcxnames[k], "_i.pcx")) {
                if (IconOfSkinExists(pcxnames[k], pcxnames, npcxfiles)) {
                    nskins++;
                }
            }
        }

        if (!nskins) {
            FS_FreeList((void **)pcxnames);
            goto skip;
        }

        skinnames = UI_Malloc(sizeof(char *) * (nskins + 1));
        skinnames[nskins] = NULL;

        // copy the valid skins
        for (s = 0, k = 0; k < npcxfiles; k++) {
            if (!strstr(pcxnames[k], "_i.pcx")) {
                if (IconOfSkinExists(pcxnames[k], pcxnames, npcxfiles)) {
                    COM_StripExtension(scratch, pcxnames[k], sizeof(scratch));
                    skinnames[s++] = UI_CopyString(scratch);
                }
            }
        }

        FS_FreeList((void **)pcxnames);

        // at this point we have a valid player model
        pmi = &uis.pmi[uis.numPlayerModels++];
        pmi->nskins = nskins;
        pmi->skindisplaynames = skinnames;
        pmi->directory = dirnames[i];
        continue;

skip:
        Z_Free(dirnames[i]);
    }

    qsort(uis.pmi, uis.numPlayerModels, sizeof(uis.pmi[0]), pmicmpfnc);
}
Exemplo n.º 14
0
static bool Push(menuFrameWork_t *self)
{
    // save our arguments for refreshing
    m_servers.args = UI_CopyString(COM_StripQuotes(Cmd_RawArgsFrom(2)));
    return true;
}
Exemplo n.º 15
0
/*
=================
UI_StatusEvent

A server status response has been received, validated and parsed.
=================
*/
void UI_StatusEvent(const serverStatus_t *status)
{
    serverslot_t *slot;
    char *hostname, *host, *mod, *map, *maxclients;
    unsigned timestamp, ping;
    const char *info = status->infostring;
    char key[MAX_INFO_STRING];
    char value[MAX_INFO_STRING];
    int i;

    // ignore unless menu is up
    if (!m_servers.args) {
        return;
    }

    // see if already added
    slot = FindSlot(&net_from, &i);
    if (!slot) {
        // reply to broadcast, create new slot
        if (m_servers.list.numItems >= MAX_STATUS_SERVERS) {
            return;
        }
        m_servers.list.numItems++;
        hostname = UI_CopyString(NET_AdrToString(&net_from));
        timestamp = m_servers.timestamp;
    } else {
        // free previous data
        hostname = slot->hostname;
        timestamp = slot->timestamp;
        FreeSlot(slot);
    }

    host = Info_ValueForKey(info, "hostname");
    if (COM_IsWhite(host)) {
        host = hostname;
    }

    mod = Info_ValueForKey(info, "game");
    if (COM_IsWhite(mod)) {
        mod = "baseq2";
    }

    map = Info_ValueForKey(info, "mapname");
    if (COM_IsWhite(map)) {
        map = "???";
    }

    maxclients = Info_ValueForKey(info, "maxclients");
    if (!COM_IsUint(maxclients)) {
        maxclients = "?";
    }

    if (timestamp > com_eventTime)
        timestamp = com_eventTime;

    ping = com_eventTime - timestamp;
    if (ping > 999)
        ping = 999;

    slot = UI_FormatColumns(SLOT_EXTRASIZE, host, mod, map,
                            va("%d/%s", status->numPlayers, maxclients),
                            va("%u", ping),
                            NULL);
    slot->status = SLOT_VALID;
    slot->address = net_from;
    slot->hostname = hostname;
    slot->color = ColorForStatus(status, ping);

    m_servers.list.items[i] = slot;

    slot->numRules = 0;
    while (slot->numRules < MAX_STATUS_RULES) {
        Info_NextPair(&info, key, value);
        if (!info)
            break;

        if (!key[0])
            strcpy(key, "<MISSING KEY>");

        if (!value[0])
            strcpy(value, "<MISSING VALUE>");

        slot->rules[slot->numRules++] =
            UI_FormatColumns(0, key, value, NULL);
    }

    slot->numPlayers = status->numPlayers;
    for (i = 0; i < status->numPlayers; i++) {
        slot->players[i] =
            UI_FormatColumns(0,
                             va("%d", status->players[i].score),
                             va("%d", status->players[i].ping),
                             status->players[i].name,
                             NULL);
    }

    slot->timestamp = timestamp;

    // don't sort when manually refreshing
    if (m_servers.pingstage)
        m_servers.list.sort(&m_servers.list);

    UpdateStatus();
    UpdateSelection();
}
Exemplo n.º 16
0
static void M_Msgbox_Init( void )
{
	int i, j, s;
	int lineend, len;
	int n = 0;
	const char *p;
	menucommon_t *menuitem = NULL;
	char menuitem_name[40];
	char scnd_btn_name[120] = { '\0' }, scnd_btn_action[120] = { '\0' };
	int width = 0, yoffset = 40;

	s_msgbox_menu.nitems = 0;

	mbtext[0] = 0;

	for( i = 1; i < trap_Cmd_Argc(); i++ )
	{
		Q_strncpyz( mbtext, trap_Cmd_Argv(i), sizeof( mbtext ) );
		len = strlen( mbtext );

		// a secret second button
		if( !strncmp( mbtext, "\\btn\\", 5 ) )
		{
			p = strstr( mbtext + 6, "\\" );
			if( p ) {
				mbtext[p - mbtext] = '\0';

				Q_strncpyz( scnd_btn_name, mbtext + 5, sizeof( scnd_btn_name ) );
				Q_strncpyz( scnd_btn_action, p + 1, sizeof( scnd_btn_action ) );
			}

			continue;
		}

		// split the text into lines
		for( s = 0; s <= len; s += j + 1 )
		{
			lineend = min( len - s, M_MSGBOX_LINELEN );

			for( j = lineend; j && mbtext[s+j] && mbtext[s+j] != ' '; j-- );
			if( !j ) j = lineend;

			mbtext[s+j] = '\0';

			Q_snprintfz( menuitem_name, sizeof( menuitem_name ), "m_msgbox_textline_%i", n );
			menuitem = UI_InitMenuItem( menuitem_name, mbtext + s, 0, yoffset, MTYPE_SEPARATOR, ALIGN_CENTER_TOP, uis.fontSystemSmall, NULL );
			Menu_AddItem( &s_msgbox_menu, menuitem );
			yoffset += trap_SCR_strHeight( menuitem->font );

			n++;
		}
	}

	//if we printed something, add one line separation
	if( menuitem )
		yoffset += trap_SCR_strHeight( menuitem->font );

	if( scnd_btn_name[0] && scnd_btn_action[0] )
		width = UI_StringWidth( "close", uis.fontSystemBig );
	else
		width = 0;

	menuitem = UI_InitMenuItem( "m_msgbox_close", "close", -width, yoffset, MTYPE_ACTION, ALIGN_CENTER_TOP, uis.fontSystemBig, M_genericBackFunc );
	Menu_AddItem( &s_msgbox_menu, menuitem );

	if( scnd_btn_name[0] && scnd_btn_action[0] )
	{
		UI_SetupButton( menuitem, qtrue );

		menuitem = UI_InitMenuItem( "m_msgbox_connect", scnd_btn_name, width, yoffset, MTYPE_ACTION, ALIGN_CENTER_TOP, uis.fontSystemBig, M_Msgbox_SecondButton );
		menuitem->itemlocal = UI_CopyString( scnd_btn_action );
		Menu_AddItem( &s_msgbox_menu, menuitem );
	}

	yoffset += UI_SetupButton( menuitem, qtrue ) + UI_BUTTONBOX_VERTICAL_SPACE;

	Menu_Center( &s_msgbox_menu );
	Menu_Init( &s_msgbox_menu, qfalse );
	Menu_SetStatusBar( &s_msgbox_menu, NULL );
}
Exemplo n.º 17
0
Arquivo: script.c Projeto: m4son/q2pro
static qboolean Parse_File(const char *path, int depth)
{
    char *raw, *data, *p, *cmd;
    int argc;
    menuFrameWork_t *menu = NULL;
    qerror_t ret;

    ret = FS_LoadFile(path, (void **)&raw);
    if (!raw) {
        if (ret != Q_ERR_NOENT || depth) {
            Com_WPrintf("Couldn't %s %s: %s\n", depth ? "include" : "load",
                        path, Q_ErrorString(ret));
        }
        return qfalse;
    }

    data = raw;
    COM_Compress(data);

    while (*data) {
        p = strchr(data, '\n');
        if (p) {
            *p = 0;
        }

        Cmd_TokenizeString(data, qtrue);

        argc = Cmd_Argc();
        if (argc) {
            cmd = Cmd_Argv(0);
            if (menu) {
                if (!strcmp(cmd, "end")) {
                    if (menu->nitems) {
                        List_Append(&ui_menus, &menu->entry);
                    } else {
                        Com_WPrintf("Menu entry without items\n");
                        menu->free(menu);
                    }
                    menu = NULL;
                } else if (!strcmp(cmd, "title")) {
                    if (menu->title) {
                        Z_Free(menu->title);
                    }
                    menu->title = UI_CopyString(Cmd_Argv(1));
                } else if (!strcmp(cmd, "plaque")) {
                    Parse_Plaque(menu);
                } else if (!strcmp(cmd, "banner")) {
                    Parse_Banner(menu);
                } else if (!strcmp(cmd, "background")) {
                    Parse_Background(menu);
                } else if (!strcmp(cmd, "style")) {
                    Parse_Style(menu);
                } else if (!strcmp(cmd, "values")) {
                    Parse_Spin(menu, MTYPE_SPINCONTROL);
                } else if (!strcmp(cmd, "strings")) {
                    Parse_Spin(menu, MTYPE_STRINGS);
                } else if (!strcmp(cmd, "pairs")) {
                    Parse_Pairs(menu);
                } else if (!strcmp(cmd, "range")) {
                    Parse_Range(menu);
                } else if (!strcmp(cmd, "action")) {
                    Parse_Action(menu);
                } else if (!strcmp(cmd, "bitmap")) {
                    Parse_Bitmap(menu);
                } else if (!strcmp(cmd, "bind")) {
                    Parse_Bind(menu);
                } else if (!strcmp(cmd, "savegame")) {
                    Parse_Savegame(menu, MTYPE_SAVEGAME);
                } else if (!strcmp(cmd, "loadgame")) {
                    Parse_Savegame(menu, MTYPE_LOADGAME);
                } else if (!strcmp(cmd, "toggle")) {
                    Parse_Toggle(menu);
                } else if (!strcmp(cmd, "field")) {
                    Parse_Field(menu);
                } else if (!strcmp(cmd, "blank")) {
                    Parse_Blank(menu);
                } else {
                    Com_WPrintf("Unknown keyword '%s'\n", cmd);
                }
            } else {
                if (!strcmp(cmd, "begin")) {
                    char *s = Cmd_Argv(1);
                    if (!*s) {
                        Com_WPrintf("Expected menu name after '%s'\n", cmd);
                        break;
                    }
                    menu = UI_FindMenu(s);
                    if (menu) {
                        if (menu->free) {
                            menu->free(menu);
                        }
                        List_Remove(&menu->entry);
                    }
                    menu = UI_Mallocz(sizeof(*menu));
                    menu->name = UI_CopyString(s);
                    menu->push = Menu_Push;
                    menu->pop = Menu_Pop;
                    menu->free = Menu_Free;
                    menu->image = uis.backgroundHandle;
                    menu->color.u32 = uis.color.background.u32;
                    menu->transparent = uis.transparent;
                } else if (!strcmp(cmd, "include")) {
                    char *s = Cmd_Argv(1);
                    if (!*s) {
                        Com_WPrintf("Expected file name after '%s'\n", cmd);
                        break;
                    }
                    if (depth == 16) {
                        Com_WPrintf("Includes too deeply nested\n");
                    } else {
                        Parse_File(s, depth + 1);
                    }
                } else if (!strcmp(cmd, "color")) {
                    Parse_Color();
                } else if (!strcmp(cmd, "background")) {
                    char *s = Cmd_Argv(1);

                    if (SCR_ParseColor(s, &uis.color.background)) {
                        uis.backgroundHandle = 0;
                        uis.transparent = uis.color.background.u8[3] != 255;
                    } else {
                        uis.backgroundHandle = R_RegisterPic(s);
                        uis.transparent = R_GetPicSize(NULL, NULL, uis.backgroundHandle);
                    }
                } else if (!strcmp(cmd, "font")) {
                    uis.fontHandle = R_RegisterFont(Cmd_Argv(1));
                } else if (!strcmp(cmd, "cursor")) {
                    uis.cursorHandle = R_RegisterPic(Cmd_Argv(1));
                    R_GetPicSize(&uis.cursorWidth,
                                 &uis.cursorHeight, uis.cursorHandle);
                } else if (!strcmp(cmd, "weapon")) {
                    Cmd_ArgvBuffer(1, uis.weaponModel, sizeof(uis.weaponModel));
                } else {
                    Com_WPrintf("Unknown keyword '%s'\n", cmd);
                    break;
                }
            }
        }

        if (!p) {
            break;
        }

        data = p + 1;
    }

    FS_FreeFile(raw);

    if (menu) {
        Com_WPrintf("Menu entry without 'end' terminator\n");
        menu->free(menu);
    }

    return qtrue;
}
Exemplo n.º 18
0
static void MapsList_CreateItems( const char *lastmap )
{
    int i, j, validmaps;
    int order;
    maplist_item_t *items;
    char mapinfo[MAX_CONFIGSTRING_CHARS], *mapname, *fullname;

    UI_FreeScrollItemList( &mapList );

    for( validmaps = 0; trap_ML_GetMapByNum( validmaps, NULL, 0 ); validmaps++ )
        ;

    if( !validmaps )
    {
        Menu_SetStatusBar( &s_startserver_menu, "No maps found" );
        return;
    }

    order = trap_Cvar_Value( "ui_maplist_sortmethod" );
    items = UI_Malloc( sizeof( *items ) * validmaps );
    for( i = 0; i < validmaps; i++ )
    {
        trap_ML_GetMapByNum( i, mapinfo, sizeof( mapinfo ) );

        mapname = mapinfo;
        fullname = mapinfo + strlen( mapname ) + 1;

        if( order )
            items[i].name = UI_CopyString( *fullname ? fullname : mapname );
        else
            items[i].name = UI_CopyString( mapname );
        items[i].mapname = UI_CopyString( mapname );
        items[i].index = i;

        // uppercase the first letter and letters that follow whitespaces
        if( order )
        {
            if( *fullname )
            {
                items[i].name[0] = toupper( items[i].name[0] );
                for( j = 1; items[i].name[j]; j++ )
                    if( items[i].name[j-1] == ' ' )
                        items[i].name[j] = toupper( items[i].name[j] );
            }
            else
            {
                Q_strlwr( items[i].name );
            }
        }
        else
        {
            Q_strlwr( items[i].name );
        }
    }

    qsort( items, validmaps, sizeof( *items ), ( int ( * )( const void *, const void * ) )MapList_MapSort );

    for( i = 0; i < validmaps; i++ )
    {
        if( !strcmp( items[i].mapname, lastmap ) )
            mapList_cur_idx = i;

        UI_AddItemToScrollList( &mapList, items[i].name, (void *)((size_t)(items[i].index)) );
        UI_Free( items[i].mapname );
        UI_Free( items[i].name );
    }

    UI_Free( items );
}
Exemplo n.º 19
0
static void Performance_Init( void )
{
    menucommon_t *menuitem;
    int yoffset = 0;

    char custom_resolution[64];
    static char **resolutions;

    static char *colordepth_names[] = { "desktop", "16 bits", "32 bits", 0 };

    static char *plighting_names[] = { "vertex (fast)", "lightmaps (normal)", "per pixel (quality)", "per pixel (no specular)", 0 };

    static char **texfilter_names;
    int anisotropic, spinindex;

#ifndef PREDEFINES_PROFILES
    if( !gfx_profiles )
    {
        int i = 0, num, total, len;
        char *current, buffer[1024];
        total = trap_FS_GetFileList( "profiles", ".cfg", NULL, 0, 0, 0 );

        if( total )
            gfx_profiles = UI_Malloc( sizeof( char * ) * ( total + 1 ) );

        while( i < total )
        {
            if( ( num = trap_FS_GetFileList( "profiles", ".cfg", buffer, sizeof( buffer ), i, total ) ) == 0 )
            {
                i++; // can happen if the filename is too long to fit into the buffer or we're done
                continue;
            }

            // add profiles to profiles list
            for( current = buffer ; num ; i++, num--, current += len )
            {
                len = strlen( current ) + 1;
                if( strncmp( current, "gfx_", 4 ) )
                    continue;

                COM_StripExtension( current );

                gfx_profiles[i] = UI_Malloc( strlen( current + 4 ) + 1 );
                strcpy( gfx_profiles[i], current + 4 );
            }
        }
    }
#endif

    if( !resolutions )
    {   // count video modes
        int i, width, height;
        qboolean wideScreen;

        for( i = 0; trap_VID_GetModeInfo( &width, &height, &wideScreen, i - 1 ); i++ ) ;

        resolutions = (char **)UI_Malloc( sizeof( char * ) * ( i + 1 ) );

        for( i = 0; trap_VID_GetModeInfo( &width, &height, &wideScreen, i - 1 ); i++ )
        {
            Q_snprintfz( custom_resolution, sizeof( custom_resolution ), "%s%s%i x %i", i ? "" : "custom: ", ( wideScreen ? "W " : "" ), width, height );
            resolutions[i] = UI_CopyString( custom_resolution );
        }
        resolutions[i] = NULL;
    }

    if( !texfilter_names )
    {
        int i, count;

        for( count = 0; ; count++ )
        {
            if( trap_Cvar_Value( "gl_ext_texture_filter_anisotropic_max" ) <= (1<<count) )
                break;
        }

        texfilter_names = (char **)UI_Malloc( sizeof( char * ) * ( count + 1 + 1 ) );

        texfilter_names[0] = UI_CopyString( "bilinear" );
        for( i = 0; i < count; i++ )
            texfilter_names[i+1] = UI_CopyString( va( "trilinear %ixAF", (1<<i) ) );
        texfilter_names[i+1] = NULL;
    }

    menuitem = UI_InitMenuItem( "m_performance_title1", "GRAPHICS OPTIONS", 0, yoffset, MTYPE_SEPARATOR, ALIGN_CENTER_TOP, uis.fontSystemBig, NULL );
    Menu_AddItem( &s_performance_menu, menuitem );
    yoffset += trap_SCR_strHeight( menuitem->font );
    yoffset += trap_SCR_strHeight( menuitem->font );

    menuitem = UI_InitMenuItem( "m_performance_profile", "profile", 0, yoffset, MTYPE_SPINCONTROL, ALIGN_RIGHT_TOP, uis.fontSystemSmall, NULL );
    Menu_AddItem( &s_performance_menu, menuitem );
    UI_SetupSpinControl( menuitem, gfx_profiles, trap_Cvar_Value( "ui_gfxprofile" ) );
    yoffset += trap_SCR_strHeight( menuitem->font );
    yoffset += trap_SCR_strHeight( menuitem->font );

    menuitem = UI_InitMenuItem( "m_performance_applyprofile", "apply profile", 0, yoffset, MTYPE_ACTION, ALIGN_CENTER_TOP, uis.fontSystemBig, ApplyProfileButton );
    Menu_AddItem( &s_performance_menu, menuitem );
    yoffset += 1.5 * UI_SetupButton( menuitem, qtrue );

    menuitem = UI_InitMenuItem( "m_performance_resolution", "resolution", 0, yoffset, MTYPE_SPINCONTROL, ALIGN_RIGHT_TOP, uis.fontSystemSmall, NULL );
    Menu_AddItem( &s_performance_menu, menuitem );
    UI_SetupSpinControl( menuitem, resolutions, max( trap_Cvar_Value( "r_mode" ), -1 ) + 1 );
    yoffset += trap_SCR_strHeight( menuitem->font );

    menuitem = UI_InitMenuItem( "m_performance_fullscreen", "fullscreen", 0, yoffset, MTYPE_SPINCONTROL, ALIGN_RIGHT_TOP, uis.fontSystemSmall, NULL );
    Menu_AddItem( &s_performance_menu, menuitem );
    UI_SetupSpinControl( menuitem, noyes_names, trap_Cvar_Value( "vid_fullscreen" ) != 0 );
    yoffset += trap_SCR_strHeight( menuitem->font );

    menuitem = UI_InitMenuItem( "m_performance_swapinterval", "vertical sync", 0, yoffset, MTYPE_SPINCONTROL, ALIGN_RIGHT_TOP, uis.fontSystemSmall, NULL );
    Menu_AddItem( &s_performance_menu, menuitem );
    UI_SetupSpinControl( menuitem, noyes_names, trap_Cvar_Value( "r_swapinterval" ) );
    yoffset += trap_SCR_strHeight( menuitem->font );

    menuitem = UI_InitMenuItem( "m_performance_gamma", "brightness", 0, yoffset, MTYPE_SLIDER, ALIGN_RIGHT_TOP, uis.fontSystemSmall, NULL );
    Menu_AddItem( &s_performance_menu, menuitem );
    UI_SetupSlider( menuitem, 12, bound( (int)( trap_Cvar_Value( "r_gamma" ) * 10.0f ), 5, 13 ), 5, 13 );
    yoffset += trap_SCR_strHeight( menuitem->font );

    menuitem = UI_InitMenuItem( "m_performance_colorbits", "color quality", 0, yoffset, MTYPE_SPINCONTROL, ALIGN_RIGHT_TOP, uis.fontSystemSmall, NULL );
    Menu_AddItem( &s_performance_menu, menuitem );
    if( !Q_stricmp( trap_Cvar_String( "r_colorbits" ), "16" ) )
        UI_SetupSpinControl( menuitem, colordepth_names, 1 );
    else if( !Q_stricmp( trap_Cvar_String( "r_colorbits" ), "32" ) )
        UI_SetupSpinControl( menuitem, colordepth_names, 2 );
    else
        UI_SetupSpinControl( menuitem, colordepth_names, 0 );
    yoffset += trap_SCR_strHeight( menuitem->font );

    menuitem = UI_InitMenuItem( "m_performance_picmip", "texture quality", 0, yoffset, MTYPE_SLIDER, ALIGN_RIGHT_TOP, uis.fontSystemSmall, NULL );
    Menu_AddItem( &s_performance_menu, menuitem );
    UI_SetupSlider( menuitem, 12, 6-trap_Cvar_Value( "r_picmip" ), 0, 6 );
    yoffset += trap_SCR_strHeight( menuitem->font );

    menuitem = UI_InitMenuItem( "m_performance_filter", "texture filter", 0, yoffset, MTYPE_SPINCONTROL, ALIGN_RIGHT_TOP, uis.fontSystemSmall, NULL );
    Menu_AddItem( &s_performance_menu, menuitem );
    anisotropic = trap_Cvar_Value( "r_texturefilter" );
    if( anisotropic >= 2 )
        spinindex = NEARESTEXPOF2( anisotropic ) + 1;
    else if( !Q_stricmp( trap_Cvar_String( "r_texturemode" ), "GL_LINEAR_MIPMAP_NEAREST" ) )
        spinindex = 0;
    else
        spinindex = 1;
    UI_SetupSpinControl( menuitem, texfilter_names, spinindex );
    yoffset += trap_SCR_strHeight( menuitem->font );

    menuitem = UI_InitMenuItem( "m_performance_skymip", "sky quality", 0, yoffset, MTYPE_SLIDER, ALIGN_RIGHT_TOP, uis.fontSystemSmall, NULL );
    Menu_AddItem( &s_performance_menu, menuitem );
    UI_SetupSlider( menuitem, 12, (trap_Cvar_Value( "r_fastsky" ) ? 0 : 4-trap_Cvar_Value( "r_skymip" )), 0, 4 );
    yoffset += trap_SCR_strHeight( menuitem->font );

    menuitem = UI_InitMenuItem( "m_performance_LOD_slider", "geometry level of detail", 0, yoffset, MTYPE_SLIDER, ALIGN_RIGHT_TOP, uis.fontSystemSmall, NULL );
    Menu_AddItem( &s_performance_menu, menuitem );
    UI_SetupSlider( menuitem, 12, 4-max( trap_Cvar_Value( "r_lodbias" ), NEARESTEXPOF2( trap_Cvar_Value( "r_subdivisions" ) ) ), 0, 4 );
    yoffset += trap_SCR_strHeight( menuitem->font );

#if 0
    menuitem = UI_InitMenuItem( "m_performance_glsl", "opengl shaders", 0, yoffset, MTYPE_SPINCONTROL, ALIGN_RIGHT_TOP, uis.fontSystemSmall, NULL );
    Menu_AddItem( &s_performance_menu, menuitem );
    UI_SetupSpinControl( menuitem, offon_names, trap_Cvar_Value( "gl_ext_GLSL" ) );
    yoffset += trap_SCR_strHeight( menuitem->font );
#endif

    if( trap_Cvar_Value( "r_lighting_vertexlight" ) )
        spinindex = 0;
    else if( !trap_Cvar_Value( "r_lighting_deluxemapping" ) )
        spinindex = 1;
    else if( trap_Cvar_Value( "r_lighting_specular" ) )
        spinindex = 2;
    else
        spinindex = 3;

    menuitem = UI_InitMenuItem( "m_performance_pplighting", "lighting", 0, yoffset, MTYPE_SPINCONTROL, ALIGN_RIGHT_TOP, uis.fontSystemSmall, NULL );
    Menu_AddItem( &s_performance_menu, menuitem );
    UI_SetupSpinControl( menuitem, plighting_names, spinindex );
    yoffset += trap_SCR_strHeight( menuitem->font );

    yoffset += trap_SCR_strHeight( menuitem->font );

    menuitem = UI_InitMenuItem( "m_performance_back", "back", -16, yoffset, MTYPE_ACTION, ALIGN_RIGHT_TOP, uis.fontSystemBig, M_genericBackFunc );
    Menu_AddItem( &s_performance_menu, menuitem );
    UI_SetupButton( menuitem, qtrue );
    menuitem = UI_InitMenuItem( "m_performance_apply", "apply", 16, yoffset, MTYPE_ACTION, ALIGN_LEFT_TOP, uis.fontSystemBig, ApplyButton );
    Menu_AddItem( &s_performance_menu, menuitem );
    yoffset += UI_SetupButton( menuitem, qtrue ) + UI_BUTTONBOX_VERTICAL_SPACE;;

    yoffset += trap_SCR_strHeight( uis.fontSystemSmall );

    menuitem = UI_InitMenuItem( "m_performance_advanced", "advanced options", 0, yoffset, MTYPE_ACTION, ALIGN_CENTER_TOP, uis.fontSystemBig, AdvancedButton );
    Menu_AddItem( &s_performance_menu, menuitem );
    UI_SetupButton( menuitem, qtrue );

    Menu_Center( &s_performance_menu );
    Menu_Init( &s_performance_menu, qfalse );
}
Exemplo n.º 20
0
static qboolean Push(menuFrameWork_t *self)
{
    // save our arguments for refreshing
    m_servers.args = UI_CopyString(Cmd_RawArgsFrom(2));
    return qtrue;
}