diff --git a/core/MenuStyle_Radio.cpp b/core/MenuStyle_Radio.cpp index c891025b..188c0247 100644 --- a/core/MenuStyle_Radio.cpp +++ b/core/MenuStyle_Radio.cpp @@ -42,9 +42,15 @@ extern const char *g_RadioNumTable[]; CRadioStyle g_RadioMenuStyle; int g_ShowMenuId = -1; bool g_bRadioInit = false; +unsigned int g_RadioMenuTimeout = 0; -CRadioStyle::CRadioStyle() : m_players(new CBaseMenuPlayer[256+1]) +CRadioStyle::CRadioStyle() { + m_players = new CRadioMenuPlayer[256+1]; + for (size_t i = 0; i < 256+1; i++) + { + m_players[i].Radio_SetIndex(i); + } } void CRadioStyle::OnSourceModAllInitialized() @@ -73,6 +79,16 @@ void CRadioStyle::OnSourceModLevelChange(const char *mapName) return; } + const char *val = g_pGameConf->GetKeyValue("RadioMenuTimeout"); + if (val != NULL) + { + g_RadioMenuTimeout = atoi(val); + } + else + { + g_RadioMenuTimeout = 0; + } + g_Menus.AddStyle(this); g_Menus.SetDefaultStyle(this); @@ -203,6 +219,38 @@ void CRadioStyle::FreeRadioDisplay(CRadioDisplay *display) m_FreeDisplays.push(display); } +CRadioMenuPlayer *CRadioStyle::GetRadioMenuPlayer(int client) +{ + return &m_players[client]; +} + +void CRadioStyle::ProcessWatchList() +{ + if (!g_RadioMenuTimeout) + { + BaseMenuStyle::ProcessWatchList(); + return; + } + + BaseMenuStyle::ProcessWatchList(); + + CRadioMenuPlayer *pPlayer; + float curtime = gpGlobals->curtime; + unsigned int max_clients = g_Players.GetMaxClients(); + for (unsigned int i = 1; i <= max_clients; i++) + { + pPlayer = GetRadioMenuPlayer(i); + if (!pPlayer->bInMenu || pPlayer->bInExternMenu) + { + continue; + } + if (pPlayer->Radio_NeedsRefresh()) + { + pPlayer->Radio_Refresh(); + } + } +} + CRadioDisplay::CRadioDisplay() { Reset(); @@ -326,17 +374,50 @@ bool CRadioDisplay::CanDrawItem(unsigned int drawFlags) void CRadioDisplay::SendRawDisplay(int client, unsigned int time) { - char buffer[4096]; - size_t len; - - len = UTIL_Format(buffer, sizeof(buffer), "%s\n%s", m_Title.c_str(), m_BufferText.c_str()); - - cell_t players[1] = {client}; - int _sel_keys = (keys == 0) ? (1<<9) : keys; + CRadioMenuPlayer *pPlayer = g_RadioMenuStyle.GetRadioMenuPlayer(client); + pPlayer->Radio_Init(_sel_keys, m_Title.c_str(), m_BufferText.c_str()); + pPlayer->Radio_Refresh(); +} - char *ptr = buffer; +void CRadioMenuPlayer::Radio_SetIndex(unsigned int index) +{ + m_index = index; +} + +bool CRadioMenuPlayer::Radio_NeedsRefresh() +{ + return (gpGlobals->curtime - display_last_refresh >= g_RadioMenuTimeout); +} + +void CRadioMenuPlayer::Radio_Init(int keys, const char *title, const char *text) +{ + display_len = UTIL_Format(display_pkt, + sizeof(display_pkt), + "%s\n%s", + title, + text); + display_keys = keys; +} + +void CRadioMenuPlayer::Radio_Refresh() +{ + cell_t players[1] = {m_index}; + char *ptr = display_pkt; char save = 0; + size_t len = display_len; + unsigned int time; + + /* Compute the new time */ + if (menuHoldTime == 0) + { + time = 0; + } + else + { + time = menuHoldTime - (unsigned int)(gpGlobals->curtime - menuStartTime); + } + while (true) { if (len > 240) @@ -345,7 +426,7 @@ void CRadioDisplay::SendRawDisplay(int client, unsigned int time) ptr[240] = '\0'; } bf_write *buffer = g_UserMsgs.StartMessage(g_ShowMenuId, players, 1, USERMSG_BLOCKHOOKS); - buffer->WriteWord(_sel_keys); + buffer->WriteWord(display_keys); buffer->WriteChar(time ? time : -1); buffer->WriteByte( (len > 240) ? 1 : 0 ); buffer->WriteString(ptr); @@ -355,10 +436,14 @@ void CRadioDisplay::SendRawDisplay(int client, unsigned int time) ptr[240] = save; ptr = &ptr[240]; len -= 240; - } else { + } + else + { break; } } + + display_last_refresh = gpGlobals->curtime; } int CRadioDisplay::GetAmountRemaining() diff --git a/core/MenuStyle_Radio.h b/core/MenuStyle_Radio.h index 35f30cf0..a1b8971b 100644 --- a/core/MenuStyle_Radio.h +++ b/core/MenuStyle_Radio.h @@ -47,6 +47,21 @@ using namespace SourceMod; class CRadioDisplay; class CRadioMenu; +class CRadioMenuPlayer : public CBaseMenuPlayer +{ +public: + void Radio_Init(int keys, const char *title, const char *buffer); + bool Radio_NeedsRefresh(); + void Radio_Refresh(); + void Radio_SetIndex(unsigned int index); +private: + unsigned int m_index; + size_t display_len; + char display_pkt[512]; + int display_keys; + float display_last_refresh; +}; + class CRadioStyle : public BaseMenuStyle, public SMGlobalClass, @@ -61,6 +76,7 @@ public: //SMGlobalClass public: //BaseMenuStyle CBaseMenuPlayer *GetMenuPlayer(int client); void SendDisplay(int client, IMenuPanel *display); + void ProcessWatchList(); public: //IMenuStyle const char *GetStyleName(); IMenuPanel *CreatePanel(); @@ -75,8 +91,9 @@ public: public: CRadioDisplay *MakeRadioDisplay(CRadioMenu *menu=NULL); void FreeRadioDisplay(CRadioDisplay *display); + CRadioMenuPlayer *GetRadioMenuPlayer(int client); private: - CBaseMenuPlayer *m_players; + CRadioMenuPlayer *m_players; CStack m_FreeDisplays; }; diff --git a/gamedata/core.games.txt b/gamedata/core.games.txt index ac01dc0c..0077e39f 100644 --- a/gamedata/core.games.txt +++ b/gamedata/core.games.txt @@ -87,4 +87,12 @@ "GameExtension" "game.cstrike" } } + + "tf" + { + "Keys" + { + "RadioMenuTimeout" "4" + } + } }