[UIFeeder] Add select function and use feeder 5 for maps

This commit is contained in:
momo5502 2017-01-21 22:14:23 +01:00
parent ee63346c00
commit 3150950507
6 changed files with 113 additions and 37 deletions

View File

@ -58,13 +58,13 @@ namespace Components
if (info) if (info)
{ {
return ServerList::GetServerText(info, column); return ServerList::GetServerInfoText(info, column);
} }
return ""; return "";
} }
const char* ServerList::GetServerText(ServerList::ServerInfo* server, int column) const char* ServerList::GetServerInfoText(ServerList::ServerInfo* server, int column)
{ {
if (!server) return ""; if (!server) return "";
@ -547,8 +547,8 @@ namespace Components
return ((info1->clients - info2->clients) * (ServerList::SortAsc ? 1 : -1)); return ((info1->clients - info2->clients) * (ServerList::SortAsc ? 1 : -1));
} }
std::string text1 = Colors::Strip(ServerList::GetServerText(info1, ServerList::SortKey)); std::string text1 = Colors::Strip(ServerList::GetServerInfoText(info1, ServerList::SortKey));
std::string text2 = Colors::Strip(ServerList::GetServerText(info2, ServerList::SortKey)); std::string text2 = Colors::Strip(ServerList::GetServerInfoText(info2, ServerList::SortKey));
// ASCII-based comparison // ASCII-based comparison
return (text1.compare(text2) * (ServerList::SortAsc ? 1 : -1)); return (text1.compare(text2) * (ServerList::SortAsc ? 1 : -1));

View File

@ -106,7 +106,7 @@ namespace Components
static unsigned int GetServerCount(); static unsigned int GetServerCount();
static const char* GetServerText(unsigned int index, int column); static const char* GetServerText(unsigned int index, int column);
static const char* GetServerText(ServerInfo* server, int column); static const char* GetServerInfoText(ServerInfo* server, int column);
static void SelectServer(unsigned int index); static void SelectServer(unsigned int index);
static void UpdateSource(); static void UpdateSource();

View File

@ -32,7 +32,11 @@ namespace Components
bool UIFeeder::SetItemSelection() bool UIFeeder::SetItemSelection()
{ {
if (UIFeeder::Feeders.find(UIFeeder::Current.feeder) != UIFeeder::Feeders.end()) if(UIFeeder::Current.feeder == 4.0f)
{
return true;
}
else if (UIFeeder::Feeders.find(UIFeeder::Current.feeder) != UIFeeder::Feeders.end())
{ {
UIFeeder::Feeders[UIFeeder::Current.feeder].select(UIFeeder::Current.index); UIFeeder::Feeders[UIFeeder::Current.feeder].select(UIFeeder::Current.index);
return true; return true;
@ -251,43 +255,105 @@ namespace Components
} }
} }
void UIFeeder::ApplyMapFeeder(Game::dvar_t* dvar, int num) void UIFeeder::Select(float feeder, unsigned int index)
{ {
Dvar::Var(dvar).set(num); if(Game::uiContext->openMenuCount > 0)
if (num < 0 || num >= *Game::arenaCount)
{ {
num = 0; Game::menuDef_t* menu = Game::uiContext->menuStack[Game::uiContext->openMenuCount - 1];
if (menu && menu->items)
{
for (int i = 0; i < menu->itemCount; ++i)
{
Game::itemDef_t* item = menu->items[i];
if (item && item->type == 6 && item->special == feeder)
{
item->cursorPos = static_cast<int>(index);
break;
}
}
}
} }
// UI_SortArenas
Utils::Hook::Call<void()>(0x630AE0)();
int index = reinterpret_cast<int*>(0x633E934)[num];
const char* mapname = ArenaLength::NewArenas[index].mapName;
const char* description = ArenaLength::NewArenas[index].description;
Dvar::Var("ui_mapname").set(mapname);
Dvar::Var("ui_map_desc").set(Game::SEH_StringEd_GetString(description));
// Party_SetDisplayMapName
Utils::Hook::Call<void(const char*)>(0x503B50)(mapname);
} }
void UIFeeder::DoubleClickMapFeeder(const char* /*dvar_name*/, const char* /*name*/) unsigned int UIFeeder::GetMapCount()
{ {
//Game::Dvar_SetStringByName(dvar_name, name); Game::UI_UpdateArenas();
Game::UI_SortArenas();
return *Game::arenaCount;
}
// Party_SetDisplayMapName const char* UIFeeder::GetMapText(unsigned int index, int /*column*/)
//Utils::Hook::Call<void(const char*)>(0x503B50)(name); {
Game::UI_UpdateArenas();
Game::UI_SortArenas();
Command::Execute("closemenu settings_map", false); if (index < static_cast<unsigned int>(*Game::arenaCount))
{
return Game::SEH_StringEd_GetString(ArenaLength::NewArenas[reinterpret_cast<int*>(0x633E934)[index]].uiName);
}
return "";
}
void UIFeeder::SelectMap(unsigned int index)
{
Game::UI_UpdateArenas();
Game::UI_SortArenas();
if (index < static_cast<unsigned int>(*Game::arenaCount))
{
index = reinterpret_cast<int*>(0x633E934)[index];
const char* mapname = ArenaLength::NewArenas[index].mapName;
const char* longname = ArenaLength::NewArenas[index].uiName;
const char* description = ArenaLength::NewArenas[index].description;
Dvar::Var("ui_map_name").set(mapname);
Dvar::Var("ui_map_long").set(Game::SEH_StringEd_GetString(longname));
Dvar::Var("ui_map_desc").set(Game::SEH_StringEd_GetString(description));
}
}
void UIFeeder::ApplyMap(UIScript::Token)
{
std::string mapname = Dvar::Var("ui_map_name").get<std::string>();
Dvar::Var("ui_mapname").set(mapname);
Utils::Hook::Call<void(const char*)>(0x503B50)(mapname.data()); // Party_SetDisplayMapName
}
void UIFeeder::ApplyInitialMap(UIScript::Token)
{
std::string mapname = Dvar::Var("ui_mapname").get<std::string>();
Game::UI_UpdateArenas();
Game::UI_SortArenas();
for(unsigned int i = 0; i < static_cast<unsigned int>(*Game::arenaCount); ++i)
{
if(ArenaLength::NewArenas[i].mapName == mapname)
{
for (unsigned int j = 0; j < static_cast<unsigned int>(*Game::arenaCount); ++j)
{
if (reinterpret_cast<unsigned int*>(0x633E934)[j] == i)
{
UIFeeder::SelectMap(j);
UIFeeder::Select(5.0f, j);
break;
}
}
break;
}
}
} }
UIFeeder::UIFeeder() UIFeeder::UIFeeder()
{ {
Dvar::OnInit([]() Dvar::OnInit([]()
{ {
Dvar::Register<const char*>("ui_map_long", "Afghan", Game::dvar_flag::DVAR_FLAG_NONE, "");
Dvar::Register<const char*>("ui_map_name", "mp_afghan", Game::dvar_flag::DVAR_FLAG_NONE, "");
Dvar::Register<const char*>("ui_map_desc", "", Game::dvar_flag::DVAR_FLAG_NONE, ""); Dvar::Register<const char*>("ui_map_desc", "", Game::dvar_flag::DVAR_FLAG_NONE, "");
}); });
@ -315,9 +381,10 @@ namespace Components
// some thing overwriting feeder 2's data // some thing overwriting feeder 2's data
Utils::Hook::Set<BYTE>(0x4A06A9, 0xEB); Utils::Hook::Set<BYTE>(0x4A06A9, 0xEB);
// correct feeder 4 // Use feeder 5 for maps, as feeder 4 selects on mouse over
Utils::Hook(0x4C260E, UIFeeder::ApplyMapFeeder, HOOK_CALL).install()->quick(); UIFeeder::Add(5.0f, UIFeeder::GetMapCount, UIFeeder::GetMapText, UIFeeder::SelectMap);
Utils::Hook(0x4E304D, UIFeeder::DoubleClickMapFeeder, HOOK_CALL).install()->quick(); UIScript::Add("ApplyMap", UIFeeder::ApplyMap);
UIScript::Add("ApplyInitialMap", UIFeeder::ApplyInitialMap);
// Fix feeder focus // Fix feeder focus
//Utils::Hook::Nop(0x63B1DD, 2); // Flag 4 check (WINDOW_VISIBLE) //Utils::Hook::Nop(0x63B1DD, 2); // Flag 4 check (WINDOW_VISIBLE)

View File

@ -5,9 +5,9 @@ namespace Components
class UIFeeder : public Component class UIFeeder : public Component
{ {
public: public:
typedef unsigned int(__cdecl * GetItemCount_t)(); typedef Utils::Slot<unsigned int()> GetItemCount_t;
typedef const char* (__cdecl * GetItemText_t)(unsigned int index, int column); typedef Utils::Slot<const char*(unsigned int /*index*/, int /*column*/)> GetItemText_t;
typedef void(__cdecl * Select_t)(unsigned int index); typedef Utils::Slot<void(unsigned int /*index*/)> Select_t;
struct Callbacks struct Callbacks
{ {
@ -51,9 +51,14 @@ namespace Components
static void HandleKeyStub(); static void HandleKeyStub();
static void PlaySoundStub(); static void PlaySoundStub();
static void Select(float feeder, unsigned int index);
static std::unordered_map<float, Callbacks> Feeders; static std::unordered_map<float, Callbacks> Feeders;
static void ApplyMapFeeder(Game::dvar_t* dvar, int num); static unsigned int GetMapCount();
static void DoubleClickMapFeeder(const char* dvar_name, const char* name); static const char* GetMapText(unsigned int index, int column);
static void SelectMap(unsigned int index);
static void ApplyMap(UIScript::Token token);
static void ApplyInitialMap(UIScript::Token token);
}; };
} }

View File

@ -244,6 +244,7 @@ namespace Game
UI_CheckStringTranslation_t UI_CheckStringTranslation = UI_CheckStringTranslation_t(0x4FB010); UI_CheckStringTranslation_t UI_CheckStringTranslation = UI_CheckStringTranslation_t(0x4FB010);
UI_LoadMenus_t UI_LoadMenus = UI_LoadMenus_t(0x641460); UI_LoadMenus_t UI_LoadMenus = UI_LoadMenus_t(0x641460);
UI_UpdateArenas_t UI_UpdateArenas = UI_UpdateArenas_t(0x4A95B0); UI_UpdateArenas_t UI_UpdateArenas = UI_UpdateArenas_t(0x4A95B0);
UI_SortArenas_t UI_SortArenas = UI_SortArenas_t(0x630AE0);
UI_DrawHandlePic_t UI_DrawHandlePic = UI_DrawHandlePic_t(0x4D0EA0); UI_DrawHandlePic_t UI_DrawHandlePic = UI_DrawHandlePic_t(0x4D0EA0);
UI_GetContext_t UI_GetContext = UI_GetContext_t(0x4F8940); UI_GetContext_t UI_GetContext = UI_GetContext_t(0x4F8940);
UI_TextWidth_t UI_TextWidth = UI_TextWidth_t(0x6315C0); UI_TextWidth_t UI_TextWidth = UI_TextWidth_t(0x6315C0);

View File

@ -583,6 +583,9 @@ namespace Game
typedef void(__cdecl * UI_UpdateArenas_t)(); typedef void(__cdecl * UI_UpdateArenas_t)();
extern UI_UpdateArenas_t UI_UpdateArenas; extern UI_UpdateArenas_t UI_UpdateArenas;
typedef void(__cdecl * UI_SortArenas_t)();
extern UI_SortArenas_t UI_SortArenas;
typedef void(__cdecl * UI_DrawHandlePic_t)(/*ScreenPlacement*/void *scrPlace, float x, float y, float w, float h, int horzAlign, int vertAlign, const float *color, Material *material); typedef void(__cdecl * UI_DrawHandlePic_t)(/*ScreenPlacement*/void *scrPlace, float x, float y, float w, float h, int horzAlign, int vertAlign, const float *color, Material *material);
extern UI_DrawHandlePic_t UI_DrawHandlePic; extern UI_DrawHandlePic_t UI_DrawHandlePic;