Skip to content

Commit

Permalink
Merge pull request #12 from Nickito12/master
Browse files Browse the repository at this point in the history
Chatbox functions available from lua
  • Loading branch information
MinaciousGrace authored Dec 31, 2016
2 parents 3c12c85 + 25c4e5e commit 431ef6b
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 17 deletions.
12 changes: 0 additions & 12 deletions src/PlayerState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,6 @@ class LunaPlayerState: public Luna<PlayerState>
p->m_PlayerOptions.GetCurrent().PushSelf(L);
return 1;
}
static int EnableChatboxInput(T* p, lua_State *L)
{
p->onlineChatboxInput = true;
return 1;
}
static int DisableChatboxInput(T* p, lua_State *L)
{
p->onlineChatboxInput = false;
return 1;
}
DEFINE_METHOD( GetHealthState, m_HealthState );
DEFINE_METHOD( GetSuperMeterLevel, m_fSuperMeter );
static int SetTargetGoal(T* p, lua_State *L) {
Expand All @@ -298,8 +288,6 @@ class LunaPlayerState: public Luna<PlayerState>
ADD_METHOD( GetHealthState );
ADD_METHOD( GetSuperMeterLevel );
ADD_METHOD( SetTargetGoal );
ADD_METHOD(EnableChatboxInput);
ADD_METHOD(DisableChatboxInput);
}
};

Expand Down
3 changes: 1 addition & 2 deletions src/PlayerState.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ class PlayerState
void SetNumCols(int ncol) { m_NumCols = ncol; };
int GetNumCols() { return m_NumCols; };

// Disable/Enable online chatbox input - Nick12
bool onlineChatboxInput = true;


// Lua
void PushSelf( lua_State *L );
Expand Down
74 changes: 72 additions & 2 deletions src/ScreenNetSelectBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ bool ScreenNetSelectBase::Input( const InputEventPlus &input )

if( (c >= L' ') && (!bHoldingCtrl) )
{
if (!(GAMESTATE->m_pPlayerState[PLAYER_1])->onlineChatboxInput)
if (!enableChatboxInput)
return true;
m_sTextInput += WStringToRString(wstring()+c);
UpdateTextInput();
Expand Down Expand Up @@ -195,6 +195,10 @@ void ScreenNetSelectBase::UpdateUsers()

this->AddChild( &m_textUsers[i] );
}
if (!usersVisible)
for (unsigned i = 0; i < NSMAN->m_ActivePlayer.size(); i++)
m_textUsers[i].SetVisible(false);
MESSAGEMAN->Broadcast("UsersUpdate");
}

/** ColorBitmapText ***********************************************************/
Expand Down Expand Up @@ -437,8 +441,74 @@ void ColorBitmapText::SetMaxLines( int iNumLines, int iDirection )
}


#endif
void ScreenNetSelectBase::SetChatboxVisible(bool visibility)
{
m_textChatInput.SetVisible(visibility);
m_textChatOutput.SetVisible(visibility);
return;
}
void ScreenNetSelectBase::SetUsersVisible(bool visibility)
{
usersVisible = visibility;
for (unsigned int i = 0; i < m_textUsers.size(); i++)
m_textUsers[i].SetVisible(visibility);
return;
}

vector<BitmapText>* ScreenNetSelectBase::ToUsers()
{
return &m_textUsers;
}

// lua start
#include "LuaBinding.h"

/** @brief Allow Lua to have access to the PlayerState. */
class LunaScreenNetSelectBase : public Luna<ScreenNetSelectBase>
{
static int ChatboxInput(T* p, lua_State *L)
{
p->enableChatboxInput = BArg(1);
return 1;
}
static int UsersVisible(T* p, lua_State *L)
{
p->SetUsersVisible(BArg(1));
return 1;
}
static int ChatboxVisible(T* p, lua_State *L)
{
p->SetChatboxVisible(BArg(1));
return 1;
}
static int GetUserQty(T* p, lua_State *L)
{
lua_pushnumber(L, p->ToUsers()->size());
return 1;
}
static int GetUser(T* p, lua_State *L)
{
if (IArg(1) <= p->ToUsers()->size() && IArg(1) >= 1)
lua_pushstring(L, (*(p->ToUsers()))[IArg(1)-1].GetText());
else
lua_pushstring(L, "");
return 1;
}
public:
LunaScreenNetSelectBase()
{
ADD_METHOD(GetUser);
ADD_METHOD(UsersVisible);
ADD_METHOD(ChatboxInput);
ADD_METHOD(ChatboxVisible);
ADD_METHOD(GetUserQty);
}
};

LUA_REGISTER_DERIVED_CLASS(ScreenNetSelectBase, ScreenWithMenuElements)
// lua end

#endif
/*
* (c) 2004 Charles Lohr
* All rights reserved.
Expand Down
8 changes: 8 additions & 0 deletions src/ScreenNetSelectBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ class ScreenNetSelectBase : public ScreenWithMenuElements

void UpdateUsers();
void UpdateTextInput();

bool usersVisible = true;
bool enableChatboxInput = true;
void SetChatboxVisible(bool visibility);
void SetUsersVisible(bool visibility);
vector<BitmapText>* ToUsers();
// Lua
virtual void PushSelf(lua_State *L);
private:
//Chatting
ColorBitmapText m_textChatInput;
Expand Down
27 changes: 26 additions & 1 deletion src/ScreenNetSelectMusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,33 @@ void ScreenNetSelectMusic::Update( float fDeltaTime )
ScreenNetSelectBase::Update( fDeltaTime );
}

#endif
MusicWheel* ScreenNetSelectMusic::GetMusicWheel()
{
return &m_MusicWheel;
}


// lua start
#include "LuaBinding.h"

/** @brief Allow Lua to have access to the PlayerState. */
class LunaScreenNetSelectMusic : public Luna<ScreenNetSelectMusic>
{
public:
static int GetMusicWheel(T* p, lua_State *L) {
p->GetMusicWheel()->PushSelf(L);
return 1;
}
LunaScreenNetSelectMusic()
{
ADD_METHOD(GetMusicWheel);
}
};

LUA_REGISTER_DERIVED_CLASS(ScreenNetSelectMusic, ScreenNetSelectBase)
// lua end

#endif
/*
* (c) 2004-2005 Charles Lohr
* All rights reserved.
Expand Down
4 changes: 4 additions & 0 deletions src/ScreenNetSelectMusic.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class ScreenNetSelectMusic : public ScreenNetSelectBase

void StartSelectedSong();

MusicWheel* GetMusicWheel();
// Lua
virtual void PushSelf(lua_State *L);

protected:
virtual bool MenuStart( const InputEventPlus &input );
virtual bool MenuBack( const InputEventPlus &input );
Expand Down

0 comments on commit 431ef6b

Please sign in to comment.