Skip to content

Commit

Permalink
Merge pull request #78 from momentum-mod/replayfromleaderboards_wip
Browse files Browse the repository at this point in the history
Replays From Leaderboards
  • Loading branch information
Gocnak authored Jul 13, 2016
2 parents c38900c + 013fd7b commit f664323
Show file tree
Hide file tree
Showing 19 changed files with 253 additions and 57 deletions.
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
New Main Menu UI
Thanks to NicolasDe from Project-9 for GameUI2
New background (from tutorial levels) to accomodate the shininess
Play Replays from Leaderboards
Right-clicking when the leaderboards are open will allow you to right click a run and "Watch Replay"
More functionality in future updates!
Contact/Feedback Panel
Introduced a panel for in-game feedback, available in the menu.
Overhauled Settings Panel
Expand All @@ -23,6 +26,8 @@ Bug/Other fixes
Fixed the Changelog panel to properly scroll to top upon load
Removed ability to save/load (use the checkpoint menu instead!)
Fixed Biohazard90's Source Shader Editor (faulty config)
Fixed Version Update panel showing when you have a higher version than master
Fixed a bug in the blockfix system with incorporating the mom_bhop_playblocksound cvar

0.4.7
Bugfixes
Expand Down
17 changes: 10 additions & 7 deletions mp/game/momentum/resource/ClientScheme.res
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Scheme
"Gray" "128 128 128 150"
"Dark Gray" "64 64 64 200"

"Light Blue" "51 122 183 255"
"Dark Blue" "22 69 119 255"

"Red" "192 28 0 140"
"Black" "0 0 0 196"
"TransparentBlack" "0 0 0 196"
Expand Down Expand Up @@ -145,14 +148,14 @@ Scheme
ListPanel.TextColor "White"
ListPanel.BgColor "TransparentBlack"
ListPanel.SelectedTextColor "Black"
ListPanel.SelectedBgColor "Red"
ListPanel.SelectedOutOfFocusBgColor "Red"
ListPanel.SelectedBgColor "Light Blue"
ListPanel.SelectedOutOfFocusBgColor "Dark Blue"
ListPanel.EmptyListInfoTextColor "White"

Menu.TextColor "White"
Menu.BgColor "TransparentBlack"
Menu.ArmedTextColor "White"
Menu.ArmedBgColor "Red"
Menu.ArmedBgColor "Light Blue"
Menu.TextInset "6"

Chat.TypingText "White"
Expand Down Expand Up @@ -191,10 +194,10 @@ Scheme
SectionedListPanel.TextColor "White"
SectionedListPanel.BrightTextColor "White"
SectionedListPanel.BgColor "TransparentLightBlack"
SectionedListPanel.SelectedTextColor "Black"
SectionedListPanel.SelectedBgColor "Red"
SectionedListPanel.OutOfFocusSelectedTextColor "Black"
SectionedListPanel.OutOfFocusSelectedBgColor "255 255 255 32"
SectionedListPanel.SelectedTextColor "White"
SectionedListPanel.SelectedBgColor "Dark Blue"
SectionedListPanel.OutOfFocusSelectedTextColor "White"
SectionedListPanel.OutOfFocusSelectedBgColor "Light Blue"

Slider.NobColor "108 108 108 255"
Slider.TextColor "127 140 127 255"
Expand Down
Binary file modified mp/game/momentum/resource/momentum_english.txt
Binary file not shown.
2 changes: 1 addition & 1 deletion mp/game/momentum/resource2/schememainmenu.res
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"Colors"
{
"White" "255 255 255 255"
"Light.Blue" "51 122 183 255"
"Light Blue" "51 122 183 255"
"Dark Blue" "22 69 119 255"

"MainMenu.Logo.Left" "255 255 255 255"
Expand Down
4 changes: 3 additions & 1 deletion mp/src/game/client/client_momentum.vpc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ $Project "Client (Momentum)"

$File "momentum\ui\ClientTimesDisplay.h"
$File "momentum\ui\ClientTimesDisplay.cpp"

$File "momentum\ui\ReplayContextMenu.h"
$File "momentum\ui\ReplayContextMenu.cpp"

$File "momentum\ui\IVersionWarnPanel.h"
$File "momentum\ui\VersionWarnPanel.cpp"
$File "momentum\ui\VersionWarnPanel.h"
Expand Down
101 changes: 86 additions & 15 deletions mp/src/game/client/momentum/ui/ClientTimesDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <vgui/ILocalize.h>
#include <vgui/ISurface.h>
#include <vgui/IVGui.h>
#include <vgui/IInput.h>
#include <vstdlib/IKeyValuesSystem.h>

#include <KeyValues.h>
Expand Down Expand Up @@ -69,16 +70,16 @@ CClientTimesDisplay::CClientTimesDisplay(IViewPort *pViewPort) : EditablePanel(n
m_pPlayerList = new SectionedListPanel(this, "PlayerList");
m_pPlayerList->SetVerticalScrollbar(false);

LoadControlSettings("Resource/UI/timesdisplay.res");
LoadControlSettings("resource/ui/timesdisplay.res");

m_pHeader = FindControl<Panel>("Header", true);
m_lMapSummary = FindControl<Label>("MapSummary", true);
m_pMomentumLogo = FindControl<ImagePanel>("MomentumLogo", true);
m_pPlayerStats = FindControl<Panel>("PlayerStats", true);
m_pPlayerAvatar = FindControl<ImagePanel>("PlayerAvatar", true);
m_lPlayerName = FindControl<Label>("PlayerName", true);
m_lPlayerMapRank = FindControl<Label>("PlayerMapRank", true);
m_lPlayerGlobalRank = FindControl<Label>("PlayerGlobalRank", true);
m_lPlayerMapRank = FindControl<Label>("PlayerMapRank", true);
m_lPlayerGlobalRank = FindControl<Label>("PlayerGlobalRank", true);
m_pLeaderboards = FindControl<Panel>("Leaderboards", true);
m_pOnlineLeaderboards = FindControl<SectionedListPanel>("OnlineLeaderboards", true);
m_pLocalLeaderboards = FindControl<SectionedListPanel>("LocalLeaderboards", true);
Expand Down Expand Up @@ -108,10 +109,16 @@ CClientTimesDisplay::CClientTimesDisplay(IViewPort *pViewPort) : EditablePanel(n
m_pLocalLeaderboards->SetVerticalScrollbar(false);
m_pFriendsLeaderboards->SetVerticalScrollbar(false);

m_pLeaderboards->SetMouseInputEnabled(true);

m_pLocalLeaderboards->SetMouseInputEnabled(true);
m_pOnlineLeaderboards->SetMouseInputEnabled(true);
m_pFriendsLeaderboards->SetMouseInputEnabled(true);

m_pLocalLeaderboards->SetKeyBoardInputEnabled(true);
m_pLocalLeaderboards->SetClickable(true);
m_pLocalLeaderboards->AddActionSignalTarget(this);

m_pMomentumLogo->GetImage()->SetSize(scheme()->GetProportionalScaledValue(256), scheme()->GetProportionalScaledValue(64));

m_iDesiredHeight = GetTall();
Expand All @@ -122,6 +129,8 @@ CClientTimesDisplay::CClientTimesDisplay(IViewPort *pViewPort) : EditablePanel(n
ListenForGameEvent("run_upload");
ListenForGameEvent("game_newmap");

m_pLeaderboardReplayCMenu = new CReplayContextMenu(this);

m_pImageList = nullptr;
m_mapAvatarsToImageList.SetLessFunc(DefLessFunc(CSteamID));
m_mapAvatarsToImageList.RemoveAll();
Expand All @@ -137,6 +146,12 @@ CClientTimesDisplay::~CClientTimesDisplay()
delete m_pImageList;
m_pImageList = nullptr;
}

if (m_pLeaderboardReplayCMenu)
{
delete m_pLeaderboardReplayCMenu;
m_pLeaderboardReplayCMenu = nullptr;
}
// MOM_TODO: Ensure a good destructor
}

Expand Down Expand Up @@ -178,7 +193,7 @@ void CClientTimesDisplay::OnThink()
//-----------------------------------------------------------------------------
void CClientTimesDisplay::OnPollHideCode(int code)
{
m_nCloseKey = (ButtonCode_t) code;
m_nCloseKey = (ButtonCode_t)code;
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -260,7 +275,7 @@ void CClientTimesDisplay::InitScoreboardSections()
void CClientTimesDisplay::ApplySchemeSettings(IScheme *pScheme)
{
BaseClass::ApplySchemeSettings(pScheme);

if (m_pImageList)
delete m_pImageList;
m_pImageList = new ImageList(false);
Expand Down Expand Up @@ -321,6 +336,14 @@ void CClientTimesDisplay::ShowPanel(bool bShow)
InvalidateLayout(true, true);
}

if (m_pLeaderboardReplayCMenu)
{
//Close the menu
m_pLeaderboardReplayCMenu->OnKillFocus();
m_pLeaderboardReplayCMenu->DeletePanel();
}
m_pLeaderboardReplayCMenu = nullptr;

if (!bShow)
{
m_nCloseKey = BUTTON_CODE_INVALID;
Expand All @@ -337,7 +360,7 @@ void CClientTimesDisplay::ShowPanel(bool bShow)
MoveToFront();
}
else
{
{
SetVisible(false);
SetMouseInputEnabled(false);//Turn mouse off
SetKeyBoardInputEnabled(false);
Expand Down Expand Up @@ -525,13 +548,14 @@ void CClientTimesDisplay::LoadLocalTimes(KeyValues *kv)

//Load from .tim file
KeyValues *pLoaded = new KeyValues("local");
char fileName[MAX_PATH];

Q_snprintf(fileName, MAX_PATH, "maps/%s.tim", g_pGameRules->MapName() ? g_pGameRules->MapName() : "FIXME");
char fileName[MAX_PATH], filePath[MAX_PATH];
const char *mapName = g_pGameRules->MapName();
Q_snprintf(fileName, MAX_PATH, "%s%s", mapName ? mapName : "FIXME", EXT_TIME_FILE);
V_ComposeFileName(MAP_FOLDER, fileName, filePath, MAX_PATH);

if (pLoaded->LoadFromFile(filesystem, fileName, "MOD"))
DevLog("Loading from file %s...\n", filePath);
if (pLoaded->LoadFromFile(filesystem, filePath, "MOD"))
{
DevLog("Loading from file %s...\n", fileName);
for (KeyValues* kvLocalTime = pLoaded->GetFirstSubKey(); kvLocalTime; kvLocalTime = kvLocalTime->GetNextKey())
{
Time t = Time(kvLocalTime);
Expand All @@ -554,7 +578,6 @@ void CClientTimesDisplay::ConvertLocalTimes(KeyValues *kvInto)
FOR_EACH_VEC(m_vLocalTimes, i)
{
Time t = m_vLocalTimes[i];
//MOM_TODO: consider adding a "100 tick" column?

KeyValues *kvLocalTimeFormatted = new KeyValues("localtime");
kvLocalTimeFormatted->SetFloat("time_f", t.time_sec);//Used for static compare
Expand Down Expand Up @@ -646,7 +669,7 @@ void CClientTimesDisplay::UpdatePlayerAvatar(int playerIndex, KeyValues *kv)

kv->SetInt("avatar", iImageIndex);

CAvatarImage *pAvIm = (CAvatarImage *) m_pImageList->GetImage(iImageIndex);
CAvatarImage *pAvIm = (CAvatarImage *)m_pImageList->GetImage(iImageIndex);
pAvIm->UpdateFriendStatus();
// Set friend draw to false, so the offset is not set
pAvIm->SetDrawFriend(false);
Expand Down Expand Up @@ -737,8 +760,7 @@ void CClientTimesDisplay::FillScoreBoard(bool pFullUpdate)
KeyValues *kvLocalTimes = kvLeaderboards->FindKey("local");
if (kvLocalTimes && !kvLocalTimes->IsEmpty())
{
for (KeyValues *kvLocalTime = kvLocalTimes->GetFirstSubKey(); kvLocalTime;
kvLocalTime = kvLocalTime->GetNextKey())
FOR_EACH_SUBKEY(kvLocalTimes, kvLocalTime)
{
int itemID = FindItemIDForLocalTime(kvLocalTime);
if (itemID == -1)
Expand Down Expand Up @@ -808,4 +830,53 @@ void CClientTimesDisplay::MoveToCenterOfScreen()
int wx, wy, ww, wt;
surface()->GetWorkspaceBounds(wx, wy, ww, wt);
SetPos((ww - GetWide()) / 2, (wt - GetTall()) / 2);
}

CReplayContextMenu *CClientTimesDisplay::GetLeaderboardReplayContextMenu(Panel *pParent)
{
// create a drop down for this object's states
// This will stop being created after the second time you open the leaderboards?
if (m_pLeaderboardReplayCMenu)
delete m_pLeaderboardReplayCMenu;
m_pLeaderboardReplayCMenu = new CReplayContextMenu(this);
m_pLeaderboardReplayCMenu->SetAutoDelete(false);

if (!pParent)
{
m_pLeaderboardReplayCMenu->SetParent(this);
}
else
{
m_pLeaderboardReplayCMenu->AddActionSignalTarget(pParent);
m_pLeaderboardReplayCMenu->SetParent(pParent);
}

m_pLeaderboardReplayCMenu->SetVisible(false);
return m_pLeaderboardReplayCMenu;
}

void CClientTimesDisplay::OnContextWatchReplay(const char *runName)
{
if (runName)
{
char command[MAX_PATH];
Q_snprintf(command, MAX_PATH, "mom_replay_play %s", runName);
engine->ServerCmd(command);
ShowPanel(false);
}
}

void CClientTimesDisplay::OnItemContextMenu(KeyValues *pData)
{
int itemID = pData->GetInt("itemID", -1);
Panel *pPanel = static_cast<Panel*>(pData->GetPtr("SubPanel", nullptr));

KeyValues * selectedRun = m_pLocalLeaderboards->GetItemData(itemID);
char recordingName[MAX_PATH];
Q_snprintf(recordingName, MAX_PATH, "%i-%f", selectedRun->GetInt("date_t"), selectedRun->GetFloat("time_f"));

if (pPanel->GetParent())
{
GetLeaderboardReplayContextMenu(pPanel->GetParent())->ShowMenu(this, recordingName);
}
}
20 changes: 9 additions & 11 deletions mp/src/game/client/momentum/ui/ClientTimesDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <vgui_controls/EditablePanel.h>
#include <vgui_controls/SectionedListPanel.h>

#include "ReplayContextMenu.h"

#define TYPE_NOTEAM 0 // NOTEAM must be zero :)
#define TYPE_TEAM 1 // a section for a single team
#define TYPE_PLAYERS 2
Expand All @@ -28,6 +30,7 @@

#define SCALE(num) scheme()->GetProportionalScaledValueEx(GetScheme(), (num))


//-----------------------------------------------------------------------------
// Purpose: Game ScoreBoard
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -81,18 +84,13 @@ class CClientTimesDisplay : public vgui::EditablePanel, public IViewPortPanel, p

virtual void UpdatePlayerAvatar(int playerIndex, KeyValues *kv);

void OnMousePressed(vgui::MouseCode code) override
{
//Log("MOUSE RELEASED: %i\n", code);

if (code == MOUSE_RIGHT)
{
//MOM_TODO: Show a menu with like "Watch Replay"
}
}
CReplayContextMenu *GetLeaderboardReplayContextMenu(vgui::Panel *pParent);

protected:
MESSAGE_FUNC_INT(OnPollHideCode, "PollHideCode", code);
MESSAGE_FUNC_PARAMS(OnItemContextMenu, "ItemContextMenu", data);//Catching from SectionedListPanel
MESSAGE_FUNC_CHARPTR(OnContextWatchReplay, "ContextWatchReplay", runName);


// functions to override
virtual bool GetPlayerTimes(KeyValues *outPlayerInfo);
Expand Down Expand Up @@ -149,7 +147,6 @@ class CClientTimesDisplay : public vgui::EditablePanel, public IViewPortPanel, p
CPanelAnimationVarAliasType(int, m_iScoreWidth, "score_width", "35", "proportional_int");
CPanelAnimationVarAliasType(int, m_iDeathWidth, "death_width", "35", "proportional_int");
CPanelAnimationVarAliasType(int, m_iPingWidth, "ping_width", "23", "proportional_int");

private:
int m_iPlayerIndexSymbol;
int m_iDesiredHeight;
Expand Down Expand Up @@ -183,6 +180,7 @@ class CClientTimesDisplay : public vgui::EditablePanel, public IViewPortPanel, p
void FillScoreBoard(bool pFullUpdate);
void LoadLocalTimes(KeyValues *kv);
void ConvertLocalTimes(KeyValues *);
};

CReplayContextMenu *m_pLeaderboardReplayCMenu;
};
#endif // CLIENTSCOREBOARDDIALOG_H
Loading

0 comments on commit f664323

Please sign in to comment.