finished radio menus

added a new item flag so radio menus could ignore disabled control items due to a bug where 0 is always white in Valve menus
fixed a bug where ClientPressedKey() did not account for the max page items in a style
fixed some pagination drawing bugs with control items

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40791
This commit is contained in:
David Anderson 2007-05-13 17:12:16 +00:00
parent 8a9b5b7d41
commit f76a2b4e07
6 changed files with 67 additions and 44 deletions

View File

@ -468,7 +468,7 @@ skip_search:
/* Now, we need to check if we need to add anything extra */ /* Now, we need to check if we need to add anything extra */
if (pgn != MENU_NO_PAGINATION) if (pgn != MENU_NO_PAGINATION)
{ {
bool canDrawDisabled = display->CanDrawItem(ITEMDRAW_DISABLED); bool canDrawDisabled = display->CanDrawItem(ITEMDRAW_DISABLED|ITEMDRAW_CONTROL);
bool exitButton = menu->GetExitButton(); bool exitButton = menu->GetExitButton();
char text[50]; char text[50];
@ -517,34 +517,48 @@ skip_search:
display->DrawItem(draw); display->DrawItem(draw);
} }
/* PREVIOUS */
ItemDrawInfo dr(text, 0); ItemDrawInfo dr(text, 0);
if (displayPrev || canDrawDisabled) /**
* If we have one or the other, we need to have spacers for both.
*/
if (displayPrev || displayNext)
{ {
CorePlayerTranslate(client, text, sizeof(text), "Back", NULL); /* PREVIOUS */
dr.style = displayPrev ? 0 : ITEMDRAW_DISABLED; ItemDrawInfo padCtrlItem(NULL, ITEMDRAW_SPACER|ITEMDRAW_CONTROL);
position = display->DrawItem(dr); if (displayPrev || canDrawDisabled)
slots[position].type = ItemSel_Back; {
} else if ((displayNext || canDrawDisabled) || exitButton) { CorePlayerTranslate(client, text, sizeof(text), "Back", NULL);
/* If we can't display this, dr.style = (displayPrev ? 0 : ITEMDRAW_DISABLED)|ITEMDRAW_CONTROL;
* but there is a "next" or "exit" button, we need to pad! position = display->DrawItem(dr);
*/ slots[position].type = ItemSel_Back;
position = display->DrawItem(padItem); } else if (displayNext || exitButton) {
slots[position].type = ItemSel_None; /* If we can't display this, and there is an exit button,
} * we need to pad!
*/
position = display->DrawItem(padCtrlItem);
slots[position].type = ItemSel_None;
}
/* NEXT */ /* NEXT */
if (displayNext || canDrawDisabled) if (displayNext || canDrawDisabled)
{ {
CorePlayerTranslate(client, text, sizeof(text), "Next", NULL); CorePlayerTranslate(client, text, sizeof(text), "Next", NULL);
dr.style = displayNext ? 0 : ITEMDRAW_DISABLED; dr.style = (displayNext ? 0 : ITEMDRAW_DISABLED)|ITEMDRAW_CONTROL;
position = display->DrawItem(dr); position = display->DrawItem(dr);
slots[position].type = ItemSel_Next; slots[position].type = ItemSel_Next;
} else if (exitButton) { } else if (exitButton) {
/* If we can't display this, /* If we can't display this,
* but there is an exit button, we need to pad! * but there is an "exit" button, we need to pad!
*/ */
position = display->DrawItem(padItem); position = display->DrawItem(padCtrlItem);
slots[position].type = ItemSel_None;
}
} else {
/* Otherwise, bump to two slots! */
ItemDrawInfo numBump(NULL, ITEMDRAW_NOTEXT);
position = display->DrawItem(numBump);
slots[position].type = ItemSel_None;
position = display->DrawItem(numBump);
slots[position].type = ItemSel_None; slots[position].type = ItemSel_None;
} }
@ -552,7 +566,7 @@ skip_search:
if (exitButton) if (exitButton)
{ {
CorePlayerTranslate(client, text, sizeof(text), "Exit", NULL); CorePlayerTranslate(client, text, sizeof(text), "Exit", NULL);
dr.style = 0; dr.style = ITEMDRAW_CONTROL;
position = display->DrawItem(dr); position = display->DrawItem(dr);
slots[position].type = ItemSel_Exit; slots[position].type = ItemSel_Exit;
} }

View File

@ -200,7 +200,7 @@ void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press)
if (states.menu == NULL) if (states.menu == NULL)
{ {
item = key_press; item = key_press;
} else if (key_press < 1 || key_press > 8) { } else if (key_press < 1 || key_press > GetMaxPageItems()) {
cancel = true; cancel = true;
} else { } else {
ItemSelection type = states.slots[key_press].type; ItemSelection type = states.slots[key_press].type;

View File

@ -20,13 +20,20 @@
extern const char *g_RadioNumTable[]; extern const char *g_RadioNumTable[];
CRadioStyle g_RadioMenuStyle; CRadioStyle g_RadioMenuStyle;
int g_ShowMenuId = -1; int g_ShowMenuId = -1;
bool g_bRadioInit = false;
CRadioStyle::CRadioStyle() : m_players(new CBaseMenuPlayer[256+1]) CRadioStyle::CRadioStyle() : m_players(new CBaseMenuPlayer[256+1])
{ {
} }
void CRadioStyle::OnSourceModAllInitialized() void CRadioStyle::OnSourceModLevelChange(const char *mapName)
{ {
if (g_bRadioInit)
{
return;
}
g_bRadioInit = true;
const char *msg = g_pGameConf->GetKeyValue("HudRadioMenuMsg"); const char *msg = g_pGameConf->GetKeyValue("HudRadioMenuMsg");
if (!msg || msg[0] == '\0') if (!msg || msg[0] == '\0')
{ {
@ -66,8 +73,10 @@ bool CRadioStyle::OnClientCommand(int client)
{ {
return false; return false;
} }
int arg = atoi(engine->Cmd_Argv(1)); int arg = atoi(engine->Cmd_Argv(1));
ClientPressedKey(client, arg); ClientPressedKey(client, arg);
return true;
} }
return false; return false;
@ -161,6 +170,7 @@ void CRadioDisplay::Reset()
m_BufferText.assign(""); m_BufferText.assign("");
m_Title.assign(""); m_Title.assign("");
m_NextPos = 1; m_NextPos = 1;
keys = 0;
} }
bool CRadioDisplay::SendDisplay(int client, IMenuHandler *handler, unsigned int time) bool CRadioDisplay::SendDisplay(int client, IMenuHandler *handler, unsigned int time)
@ -198,25 +208,27 @@ unsigned int CRadioDisplay::DrawItem(const ItemDrawInfo &item)
{ {
if (item.style & ITEMDRAW_SPACER) if (item.style & ITEMDRAW_SPACER)
{ {
m_BufferText.append("\n"); m_BufferText.append(" \n");
} else { } else {
m_BufferText.append(item.display); m_BufferText.append(item.display);
m_BufferText.append("\n"); m_BufferText.append("\n");
} }
return 0; return 0;
} else if (item.style & ITEMDRAW_SPACER) { } else if (item.style & ITEMDRAW_SPACER) {
m_BufferText.append("\n"); m_BufferText.append(" \n");
return m_NextPos++;
} else if (item.style & ITEMDRAW_NOTEXT) {
return m_NextPos++; return m_NextPos++;
} }
if (item.style & ITEMDRAW_DISABLED) if (item.style & ITEMDRAW_DISABLED)
{ {
m_BufferText.append(g_RadioNumTable[m_NextPos]); m_BufferText.append(g_RadioNumTable[m_NextPos]);
m_BufferText.append(". ");
m_BufferText.append(item.display); m_BufferText.append(item.display);
m_BufferText.append("\n"); m_BufferText.append("\n");
} else { } else {
m_BufferText.append("->. "); m_BufferText.append("->");
m_BufferText.append(g_RadioNumTable[m_NextPos]);
m_BufferText.append(item.display); m_BufferText.append(item.display);
m_BufferText.append("\n"); m_BufferText.append("\n");
keys |= (1<<(m_NextPos-1)); keys |= (1<<(m_NextPos-1));
@ -232,6 +244,11 @@ bool CRadioDisplay::CanDrawItem(unsigned int drawFlags)
return false; return false;
} }
if ((drawFlags & ITEMDRAW_DISABLED) && (drawFlags & ITEMDRAW_CONTROL))
{
return false;
}
return true; return true;
} }
@ -301,5 +318,5 @@ void CRadioMenu::Cancel_Finally()
const char *g_RadioNumTable[11] = const char *g_RadioNumTable[11] =
{ {
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" "0. ", "1. ", "2. ", "3. ", "4. ", "5. ", "6. ", "7. ", "8. ", "9. ", "0. "
}; };

View File

@ -33,7 +33,7 @@ class CRadioStyle :
public: public:
CRadioStyle(); CRadioStyle();
public: //SMGlobalClass public: //SMGlobalClass
void OnSourceModAllInitialized(); void OnSourceModLevelChange(const char *mapName);
void OnSourceModShutdown(); void OnSourceModShutdown();
public: //BaseMenuStyle public: //BaseMenuStyle
CBaseMenuPlayer *GetMenuPlayer(int client); CBaseMenuPlayer *GetMenuPlayer(int client);

View File

@ -27,15 +27,6 @@ extern const char *g_OptionCmdTable[];
IServerPluginCallbacks *g_pVSPHandle = NULL; IServerPluginCallbacks *g_pVSPHandle = NULL;
CallClass<IServerPluginHelpers> *g_pSPHCC = NULL; CallClass<IServerPluginHelpers> *g_pSPHCC = NULL;
class TestHandler : public IMenuHandler
{
public:
virtual void OnMenuEnd(IBaseMenu *menu)
{
menu->Destroy();
}
};
ValveMenuStyle::ValveMenuStyle() : m_players(new CValveMenuPlayer[256+1]) ValveMenuStyle::ValveMenuStyle() : m_players(new CValveMenuPlayer[256+1])
{ {
} }

View File

@ -84,6 +84,7 @@ namespace SourceMod
#define ITEMDRAW_NOTEXT (1<<2) /**< No text should be drawn */ #define ITEMDRAW_NOTEXT (1<<2) /**< No text should be drawn */
#define ITEMDRAW_SPACER (1<<3) /**< Item should be drawn as a spacer, if possible */ #define ITEMDRAW_SPACER (1<<3) /**< Item should be drawn as a spacer, if possible */
#define ITEMDRAW_IGNORE ((1<<1)|(1<<2)) /**< Item should be completely ignored (rawline + notext) */ #define ITEMDRAW_IGNORE ((1<<1)|(1<<2)) /**< Item should be completely ignored (rawline + notext) */
#define ITEMDRAW_CONTROL (1<<4) /**< Item is control text (back/next/exit) */
/** /**
* @brief Information about item drawing. * @brief Information about item drawing.