Fix server sorting.

This commit is contained in:
momo5502 2016-01-04 01:30:15 +01:00
parent 1fd40424e4
commit 32977b448d
4 changed files with 74 additions and 4 deletions

View File

@ -68,6 +68,11 @@ namespace Components
return (server->Password ? "X" : "");
}
case Column::Matchtype:
{
return ((server->MatchType == 1) ? "L" : "D");
}
case Column::Hostname:
{
return server->Hostname.data();
@ -84,13 +89,18 @@ namespace Components
}
case Column::Gametype:
{
return Game::UI_LocalizeGameType(server->Gametype.data());
}
case Column::Mod:
{
if (server->Mod != "")
{
return (server->Mod.data() + 5);
}
return Game::UI_LocalizeGameType(server->Gametype.data());
return "";
}
case Column::Ping:
@ -107,6 +117,12 @@ namespace Components
ServerList::CurrentServer = (unsigned int)index;
}
void ServerList::RefreshVisibleList()
{
// TODO: Update the list
ServerList::Refresh();
}
void ServerList::Refresh()
{
// ServerList::OnlineList.clear();
@ -255,8 +271,8 @@ namespace Components
ServerInfo* info1 = nullptr;
ServerInfo* info2 = nullptr;
if (ServerList::OnlineList.size() > (unsigned int)server1) info1 = &ServerList::OnlineList[server1];
if (ServerList::OnlineList.size() > (unsigned int)server2) info2 = &ServerList::OnlineList[server2];
if (ServerList::GetList().size() > (unsigned int)server1) info1 = &ServerList::GetList()[server1];
if (ServerList::GetList().size() > (unsigned int)server2) info2 = &ServerList::GetList()[server2];
if (!info1) return 1;
if (!info2) return -1;
@ -336,6 +352,22 @@ namespace Components
ServerList::RefreshContainer.Mutex.unlock();
}
void ServerList::UpdateSource()
{
Dvar::Var netSource("ui_netSource");
int source = netSource.Get<int>();
if (++source > netSource.Get<Game::dvar_t*>()->max.i)
{
source = 0;
}
netSource.Set(source);
ServerList::RefreshVisibleList();
}
ServerList::ServerList()
{
ServerList::OnlineList.clear();
@ -412,6 +444,10 @@ namespace Components
ServerList::SortList();
});
// Add required ownerDraws
UIScript::AddOwnerDraw(220, ServerList::UpdateSource);
//UIScript::AddOwnerDraw(253, ServerList_ClickHandler_GameType);
// Add frame callback
Renderer::OnFrame(ServerList::Frame);
}

View File

@ -26,6 +26,7 @@ namespace Components
const char* GetName() { return "ServerList"; };
static void Refresh();
static void RefreshVisibleList();
static void InsertRequest(Network::Address address, bool accquireMutex = true);
static void Insert(Network::Address address, Utils::InfoString info);
@ -37,10 +38,12 @@ namespace Components
enum Column
{
Password,
Matchtype,
Hostname,
Mapname,
Players,
Gametype,
Mod,
Ping,
};
@ -93,6 +96,8 @@ namespace Components
static const char* GetServerText(ServerInfo* server, int column);
static void SelectServer(int index);
static void UpdateSource();
static void Frame();
static void SortList();

View File

@ -3,6 +3,7 @@
namespace Components
{
std::map<std::string, UIScript::Callback> UIScript::UIScripts;
std::map<int, UIScript::CallbackRaw> UIScript::UIOwnerDraws;
template<> int UIScript::Token::Get()
{
@ -57,6 +58,11 @@ namespace Components
UIScript::Add(name, reinterpret_cast<UIScript::Callback>(callback));
}
void UIScript::AddOwnerDraw(int ownerdraw, UIScript::CallbackRaw callback)
{
UIScript::UIOwnerDraws[ownerdraw] = callback;
}
bool UIScript::RunMenuScript(const char* name, const char** args)
{
if (UIScript::UIScripts.find(name) != UIScript::UIScripts.end())
@ -68,6 +74,22 @@ namespace Components
return false;
}
void UIScript::OwnerDrawHandleKeyStub(int ownerDraw, int flags, float *special, int key)
{
if (key == 200 || key == 201) //mouse buttons
{
for (auto i = UIScript::UIOwnerDraws.begin(); i != UIScript::UIOwnerDraws.end(); i++)
{
if (i->first == ownerDraw)
{
i->second();
}
}
}
Utils::Hook::Call<void(int, int, float*, int)>(0x4F58A0)(ownerDraw, flags, special, key);
}
void __declspec(naked) UIScript::RunMenuScriptStub()
{
__asm
@ -101,10 +123,14 @@ namespace Components
{
// Install handler
Utils::Hook::Set<int>(0x45EC5B, (DWORD)UIScript::RunMenuScriptStub - 0x45EC59 - 6);
// Install ownerdraw handler
Utils::Hook(0x63D233, UIScript::OwnerDrawHandleKeyStub, HOOK_CALL).Install()->Quick();
}
UIScript::~UIScript()
{
UIScript::UIScripts.clear();
UIScript::UIOwnerDraws.clear();
}
}

View File

@ -29,11 +29,14 @@ namespace Components
static void Add(std::string name, Callback callback);
static void Add(std::string name, CallbackRaw callback);
private:
static void AddOwnerDraw(int ownerdraw, CallbackRaw callback);
private:
static void OwnerDrawHandleKeyStub(int ownerDraw, int flags, float *special, int key);
static bool RunMenuScript(const char* name, const char** args);
static void RunMenuScriptStub();
static std::map<std::string, Callback> UIScripts;
static std::map<int, CallbackRaw> UIOwnerDraws;
};
}