Skip to content

Commit

Permalink
Chat overlay screen and NSMAN singleton in lua
Browse files Browse the repository at this point in the history
  • Loading branch information
nico-abram committed Mar 27, 2018
1 parent c34436c commit 69503d2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return {}
6 changes: 5 additions & 1 deletion Themes/_fallback/metrics.ini
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ SelectMusicScreen="ScreenSelectMusic"

# Screens that show over everything else.
# Only mess with this if you know what you're doing.
OverlayScreens="ScreenSystemLayer,ScreenSyncOverlay,ScreenStatsOverlay,ScreenDebugOverlay,ScreenInstallOverlay"
OverlayScreens="ScreenSystemLayer,ScreenSyncOverlay,ScreenStatsOverlay,ScreenDebugOverlay,ScreenInstallOverlay,ScreenChatOverlay"

# Used in PlayerStageStats for formatting scores.
PercentScoreDecimalPlaces=2
Expand Down Expand Up @@ -1533,6 +1533,10 @@ StatusX=SCREEN_LEFT+10
StatusY=SCREEN_TOP+10
StatusOnCommand=halign,0;valign,0;shadowlength,1;maxwidth, SCREEN_WIDTH/2;zoom,0.5;

[ScreenChatOverlay]
Class="ScreenWithMenuElements"
Fallback="ScreenWithMenuElements"
PlayMusic=false

[ScreenSyncOverlay]
Class="ScreenSyncOverlay"
Expand Down
32 changes: 31 additions & 1 deletion src/NetworkSyncManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ NetworkSyncManager::NetworkSyncManager( LoadingWindow *ld )
m_startupStatus = 0; //By default, connection not tried.
m_ActivePlayers = 0;
StartUp();

// Register with Lua.
{
Lua *L = LUA->Get();
lua_pushstring(L, "NSMAN");
this->PushSelf(L);
lua_settable(L, LUA_GLOBALSINDEX);
LUA->Release(L);
}
}

SMOProtocol::~SMOProtocol()
Expand Down Expand Up @@ -426,8 +435,9 @@ void ETTProtocol::Update(NetworkSyncManager* n, float fDeltaTime)
string tab = (*it)["tab"].get<string>();
n->chat[{tab, type}].emplace_back((*it)["msg"].get<string>());
SCREENMAN->SendMessageToTopScreen(ETTP_IncomingChat);
Message msg("NewChat");
Message msg("Chat");
msg.SetParam("tab", RString(tab.c_str()));
msg.SetParam("msg", RString((*it)["msg"].get<string>().c_str()));
msg.SetParam("type", type);
MESSAGEMAN->Broadcast(msg);
//Should end here
Expand Down Expand Up @@ -1795,6 +1805,26 @@ LuaFunction( ReportStyle, ReportStyle() )
LuaFunction( GetServerName, NSMAN->GetServerName() )
LuaFunction( CloseConnection, CloseNetworkConnection() )

// lua start
#include "LuaBinding.h"

class LunaNetworkSyncManager : public Luna<NetworkSyncManager>
{
public:
static int GetChatMsg(T* p, lua_State *L) {
unsigned int l = IArg(1);
int tabType = IArg(2);
string tabName = SArg(3);
lua_pushstring(L,p->chat[{tabName, tabType}][l].c_str());
return 1;
}
LunaNetworkSyncManager() {
ADD_METHOD(GetChatMsg);
}
};

LUA_REGISTER_CLASS(NetworkSyncManager)
// lua end
/*
* (c) 2003-2004 Charles Lohr, Joshua Allen
* All rights reserved.
Expand Down
4 changes: 4 additions & 0 deletions src/NetworkSyncManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ class NetworkSyncManager
SMOStepType TranslateStepType(int score);
vector<NetServerInfo> m_vAllLANServers;
bool m_scoreboardchange[NUM_NSScoreBoardColumn];

//Lua
void PushSelf(lua_State *L);

private:

void ProcessInput();
Expand Down

0 comments on commit 69503d2

Please sign in to comment.