diff --git a/src/command.c b/src/command.c index 49bba34e7..46709fc67 100644 --- a/src/command.c +++ b/src/command.c @@ -634,10 +634,44 @@ static void COM_ExecuteString(char *ptext) static void COM_Alias_f(void) { cmdalias_t *a; + const char *alias_format = "\x87%-8s:\x80 %s\n"; + int argc = COM_Argc(); - if (COM_Argc() < 3) + if (argc == 2) { + const char *begin = COM_Argv(1); + size_t szBegin = strlen(begin); + + /* Display all aliases that start with `begin`. */ + CONS_Printf(M_GetText("All aliases that start with \x87'%s'\x80 are:\n"), begin); + + int count = 0; + for (cmdalias_t *head = com_alias; head->next != NULL; head = head->next) + { + if (strncmp(begin, head->name, szBegin) == 0) + { + CONS_Printf(alias_format, head->name, head->value); + count++; + } + } + + if (count == 0) + { + CONS_Printf(M_GetText("There are none.\n")); + } + + return; + } + else if (argc < 3) + { + /* Display alias subtext, show all aliases. */ CONS_Printf(M_GetText("alias : create a shortcut command that executes other command(s)\n")); + + for (cmdalias_t *head = com_alias; head->next != NULL; head = head->next) + { + CONS_Printf(alias_format, head->name, head->value); + } + return; } diff --git a/src/d_netcmd.c b/src/d_netcmd.c index c9989137d..acd8b6300 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -190,6 +190,9 @@ static void Command_ShowTime_f(void); static void Command_Isgamemodified_f(void); static void Command_Cheats_f(void); + +static void Command_ListSkins(void); + #ifdef _DEBUG static void Command_Togglemodified_f(void); #ifdef HAVE_BLUA @@ -1147,8 +1150,34 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_discordstreamer); CV_RegisterVar(&cv_discordasks); #endif + + COM_AddCommand("listskins", Command_ListSkins); } +/** + * Searches the skins list for a skin of the "realname", if found, changes + * the CVAR value to be the "name" of the skin. + * \sa cv_skin, Skin_OnChange, Skin2_OnChange + * \author karen + */ +static void Skin_FindRealNameSkin(consvar_t *cvar) +{ + // Not the best way to implements this but it will do. + + int i; + const char *value = cvar->string; + for (i = 0; i < numskins; i++) + { + if (strncmp(value, skins[i].realname, sizeof skins[i].realname) == 0) + { + // Change the cvar to be the value of the name. + CV_StealthSet(cvar, skins[i].name); + return; + } + } +} + + /** Checks if a name (as received from another player) is okay. * A name is okay if it is no fewer than 1 and no more than ::MAXPLAYERNAME * chars long (not including NUL), it does not begin or end with a space, @@ -5741,6 +5770,8 @@ static void Name4_OnChange(void) */ static void Skin_OnChange(void) { + Skin_FindRealNameSkin(&cv_skin); + if (!Playing()) return; // do whatever you want @@ -5767,6 +5798,8 @@ static void Skin_OnChange(void) */ static void Skin2_OnChange(void) { + Skin_FindRealNameSkin(&cv_skin2); + if (!Playing() || !splitscreen) return; // do whatever you want @@ -5781,6 +5814,8 @@ static void Skin2_OnChange(void) static void Skin3_OnChange(void) { + Skin_FindRealNameSkin(&cv_skin3); + if (!Playing() || splitscreen < 2) return; // do whatever you want @@ -5795,6 +5830,8 @@ static void Skin3_OnChange(void) static void Skin4_OnChange(void) { + Skin_FindRealNameSkin(&cv_skin4); + if (!Playing() || splitscreen < 3) return; // do whatever you want @@ -5807,6 +5844,74 @@ static void Skin4_OnChange(void) } } +static void Command_ListSkins(void) +{ + int i; + int page = 0; + int numpages = numskins / 10 + (numskins % 10 ? 1 : 0); + int longest_name = 0; + + if (COM_Argc() > 1) + { + if (sscanf(COM_Argv(1), " %d", &page) == 0) + { + CONS_Printf("Expected a number.\n"); + return; + } + else if (page > numpages) + { + CONS_Printf("There are only %d pages.\n", numpages); + return; + } + else if (page < 0) + { + CONS_Printf("Page number cannot be negative.\n"); + return; + } + else if (page == 0) + { + CONS_Printf("There is no 0th page. (What are you a programmer?)\n"); + return; + } + + --page; + } + + CONS_Printf("Total %d skins. Page (%d/%d)\n", numskins, page + 1, numpages); + + // Find the longest name and realname in the skins list. (used for alignment) + for (i = page * 10; i < numskins && i < (page + 1) * 10; i++) + { + int length; + skin_t *skin = &skins[i]; + + if ((length = strlen(skin->name)) > longest_name) + longest_name = length; + } + + for (i = page * 10; i < numskins && i < (page + 1) * 10; i++) + { + skin_t *skin = &skins[i]; + + CONS_Printf( + "%s[%-*s]\x80 %s\n", + HU_SkinColorToConsoleColor(skin->prefcolor), + longest_name, + skin->name, + skin->realname); + } + + if (page + 1 != numpages) + { + CONS_Printf("Use \"listskins %d\" to see the next page.\n", page + 2); + } + else + { + CONS_Printf("There are no more pages.\n"); + } +} + + /** Sends a color change for the console player, unless that player is moving. * \sa cv_playercolor, Color2_OnChange, Skin_OnChange * \author Graue diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 0768cd489..dc52dfe7f 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -686,6 +686,134 @@ static void Command_CSay_f(void) } static tic_t stop_spamming[MAXPLAYERS]; +const char *HU_SkinColorToConsoleColor(skincolors_t color) +{ + // Move this ugly switch into a function you can collapse. + switch (color) + { + case SKINCOLOR_WHITE: + case SKINCOLOR_SILVER: + case SKINCOLOR_SLATE: + return "\x80"; // White + case SKINCOLOR_GREY: + case SKINCOLOR_NICKEL: + case SKINCOLOR_BLACK: + case SKINCOLOR_SKUNK: + case SKINCOLOR_JET: + return "\x86"; // V_GRAYMAP + case SKINCOLOR_SEPIA: + case SKINCOLOR_BEIGE: + case SKINCOLOR_WALNUT: + case SKINCOLOR_BROWN: + case SKINCOLOR_LEATHER: + case SKINCOLOR_RUST: + case SKINCOLOR_WRISTWATCH: + return "\x8e"; // V_BROWNMAP + case SKINCOLOR_FAIRY: + case SKINCOLOR_SALMON: + case SKINCOLOR_PINK: + case SKINCOLOR_ROSE: + case SKINCOLOR_BRICK: + case SKINCOLOR_LEMONADE: + case SKINCOLOR_BUBBLEGUM: + case SKINCOLOR_LILAC: + return "\x8d"; // V_PINKMAP + case SKINCOLOR_CINNAMON: + case SKINCOLOR_RUBY: + case SKINCOLOR_RASPBERRY: + case SKINCOLOR_CHERRY: + case SKINCOLOR_RED: + case SKINCOLOR_CRIMSON: + case SKINCOLOR_MAROON: + case SKINCOLOR_FLAME: + case SKINCOLOR_SCARLET: + case SKINCOLOR_KETCHUP: + return "\x85"; // V_REDMAP + case SKINCOLOR_DAWN: + case SKINCOLOR_SUNSET: + case SKINCOLOR_CREAMSICLE: + case SKINCOLOR_ORANGE: + case SKINCOLOR_PUMPKIN: + case SKINCOLOR_ROSEWOOD: + case SKINCOLOR_BURGUNDY: + case SKINCOLOR_TANGERINE: + return "\x87"; // V_ORANGEMAP + case SKINCOLOR_PEACH: + case SKINCOLOR_CARAMEL: + case SKINCOLOR_CREAM: + return "\x8f"; // V_PEACHMAP + case SKINCOLOR_GOLD: + case SKINCOLOR_ROYAL: + case SKINCOLOR_BRONZE: + case SKINCOLOR_COPPER: + case SKINCOLOR_THUNDER: + return "\x8A"; // V_GOLDMAP + case SKINCOLOR_POPCORN: + case SKINCOLOR_QUARRY: + case SKINCOLOR_YELLOW: + case SKINCOLOR_MUSTARD: + case SKINCOLOR_CROCODILE: + case SKINCOLOR_OLIVE: + return "\x82"; // V_YELLOWMAP + case SKINCOLOR_ARTICHOKE: + case SKINCOLOR_VOMIT: + case SKINCOLOR_GARDEN: + case SKINCOLOR_TEA: + case SKINCOLOR_PISTACHIO: + return "\x8b"; // V_TEAMAP + case SKINCOLOR_LIME: + case SKINCOLOR_HANDHELD: + case SKINCOLOR_MOSS: + case SKINCOLOR_CAMOUFLAGE: + case SKINCOLOR_ROBOHOOD: + case SKINCOLOR_MINT: + case SKINCOLOR_GREEN: + case SKINCOLOR_PINETREE: + case SKINCOLOR_EMERALD: + case SKINCOLOR_SWAMP: + case SKINCOLOR_DREAM: + case SKINCOLOR_PLAGUE: + case SKINCOLOR_ALGAE: + return "\x83"; // V_GREENMAP + case SKINCOLOR_CARIBBEAN: + case SKINCOLOR_AZURE: + case SKINCOLOR_AQUA: + case SKINCOLOR_TEAL: + case SKINCOLOR_CYAN: + case SKINCOLOR_JAWZ: + case SKINCOLOR_CERULEAN: + case SKINCOLOR_NAVY: + case SKINCOLOR_SAPPHIRE: + return "\x88"; // V_SKYMAP + case SKINCOLOR_PIGEON: + case SKINCOLOR_PLATINUM: + case SKINCOLOR_STEEL: + return "\x8c"; // V_STEELMAP + case SKINCOLOR_PERIWINKLE: + case SKINCOLOR_BLUE: + case SKINCOLOR_BLUEBERRY: + case SKINCOLOR_NOVA: + return "\x84"; // V_BLUEMAP + case SKINCOLOR_ULTRAVIOLET: + case SKINCOLOR_PURPLE: + case SKINCOLOR_FUCHSIA: + return "\x81"; // V_PURPLEMAP + case SKINCOLOR_PASTEL: + case SKINCOLOR_MOONSLAM: + case SKINCOLOR_DUSK: + case SKINCOLOR_TOXIC: + case SKINCOLOR_MAUVE: + case SKINCOLOR_LAVENDER: + case SKINCOLOR_BYZANTIUM: + case SKINCOLOR_POMEGRANATE: + return "\x89"; // V_LAVENDERMAP + + default: + return "\x83"; + } +} + + /** Receives a message, processing an ::XD_SAY command. * \sa DoSayCommand * \author Graue @@ -832,145 +960,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) { const UINT8 color = players[playernum].skincolor; - cstart = "\x83"; - - switch (color) - { - case SKINCOLOR_WHITE: - case SKINCOLOR_SILVER: - case SKINCOLOR_SLATE: - cstart = "\x80"; // White - break; - case SKINCOLOR_GREY: - case SKINCOLOR_NICKEL: - case SKINCOLOR_BLACK: - case SKINCOLOR_SKUNK: - case SKINCOLOR_JET: - cstart = "\x86"; // V_GRAYMAP - break; - case SKINCOLOR_SEPIA: - case SKINCOLOR_BEIGE: - case SKINCOLOR_WALNUT: - case SKINCOLOR_BROWN: - case SKINCOLOR_LEATHER: - case SKINCOLOR_RUST: - case SKINCOLOR_WRISTWATCH: - cstart = "\x8e"; // V_BROWNMAP - break; - case SKINCOLOR_FAIRY: - case SKINCOLOR_SALMON: - case SKINCOLOR_PINK: - case SKINCOLOR_ROSE: - case SKINCOLOR_BRICK: - case SKINCOLOR_LEMONADE: - case SKINCOLOR_BUBBLEGUM: - case SKINCOLOR_LILAC: - cstart = "\x8d"; // V_PINKMAP - break; - case SKINCOLOR_CINNAMON: - case SKINCOLOR_RUBY: - case SKINCOLOR_RASPBERRY: - case SKINCOLOR_CHERRY: - case SKINCOLOR_RED: - case SKINCOLOR_CRIMSON: - case SKINCOLOR_MAROON: - case SKINCOLOR_FLAME: - case SKINCOLOR_SCARLET: - case SKINCOLOR_KETCHUP: - cstart = "\x85"; // V_REDMAP - break; - case SKINCOLOR_DAWN: - case SKINCOLOR_SUNSET: - case SKINCOLOR_CREAMSICLE: - case SKINCOLOR_ORANGE: - case SKINCOLOR_PUMPKIN: - case SKINCOLOR_ROSEWOOD: - case SKINCOLOR_BURGUNDY: - case SKINCOLOR_TANGERINE: - cstart = "\x87"; // V_ORANGEMAP - break; - case SKINCOLOR_PEACH: - case SKINCOLOR_CARAMEL: - case SKINCOLOR_CREAM: - cstart = "\x8f"; // V_PEACHMAP - break; - case SKINCOLOR_GOLD: - case SKINCOLOR_ROYAL: - case SKINCOLOR_BRONZE: - case SKINCOLOR_COPPER: - case SKINCOLOR_THUNDER: - cstart = "\x8A"; // V_GOLDMAP - break; - case SKINCOLOR_POPCORN: - case SKINCOLOR_QUARRY: - case SKINCOLOR_YELLOW: - case SKINCOLOR_MUSTARD: - case SKINCOLOR_CROCODILE: - case SKINCOLOR_OLIVE: - cstart = "\x82"; // V_YELLOWMAP - break; - case SKINCOLOR_ARTICHOKE: - case SKINCOLOR_VOMIT: - case SKINCOLOR_GARDEN: - case SKINCOLOR_TEA: - case SKINCOLOR_PISTACHIO: - cstart = "\x8b"; // V_TEAMAP - break; - case SKINCOLOR_LIME: - case SKINCOLOR_HANDHELD: - case SKINCOLOR_MOSS: - case SKINCOLOR_CAMOUFLAGE: - case SKINCOLOR_ROBOHOOD: - case SKINCOLOR_MINT: - case SKINCOLOR_GREEN: - case SKINCOLOR_PINETREE: - case SKINCOLOR_EMERALD: - case SKINCOLOR_SWAMP: - case SKINCOLOR_DREAM: - case SKINCOLOR_PLAGUE: - case SKINCOLOR_ALGAE: - cstart = "\x83"; // V_GREENMAP - break; - case SKINCOLOR_CARIBBEAN: - case SKINCOLOR_AZURE: - case SKINCOLOR_AQUA: - case SKINCOLOR_TEAL: - case SKINCOLOR_CYAN: - case SKINCOLOR_JAWZ: - case SKINCOLOR_CERULEAN: - case SKINCOLOR_NAVY: - case SKINCOLOR_SAPPHIRE: - cstart = "\x88"; // V_SKYMAP - break; - case SKINCOLOR_PIGEON: - case SKINCOLOR_PLATINUM: - case SKINCOLOR_STEEL: - cstart = "\x8c"; // V_STEELMAP - break; - case SKINCOLOR_PERIWINKLE: - case SKINCOLOR_BLUE: - case SKINCOLOR_BLUEBERRY: - case SKINCOLOR_NOVA: - cstart = "\x84"; // V_BLUEMAP - break; - case SKINCOLOR_ULTRAVIOLET: - case SKINCOLOR_PURPLE: - case SKINCOLOR_FUCHSIA: - cstart = "\x81"; // V_PURPLEMAP - break; - case SKINCOLOR_PASTEL: - case SKINCOLOR_MOONSLAM: - case SKINCOLOR_DUSK: - case SKINCOLOR_TOXIC: - case SKINCOLOR_MAUVE: - case SKINCOLOR_LAVENDER: - case SKINCOLOR_BYZANTIUM: - case SKINCOLOR_POMEGRANATE: - cstart = "\x89"; // V_LAVENDERMAP - break; - default: - break; - } + cstart = HU_SkinColorToConsoleColor(color); } prefix = cstart; diff --git a/src/hu_stuff.h b/src/hu_stuff.h index e81a519a6..eb2461146 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -122,6 +122,7 @@ void HU_drawPing(INT32 x, INT32 y, UINT32 ping, INT32 flags); // Lat': Ping draw //void HU_DrawDualTabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, INT32 whiteplayer); void HU_DrawTabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, INT32 whiteplayer, INT32 hilicol); void HU_DrawEmeralds(INT32 x, INT32 y, INT32 pemeralds); +const char *HU_SkinColorToConsoleColor(skincolors_t color); INT32 HU_CreateTeamScoresTbl(playersort_t *tab, UINT32 dmtotals[]);