From 1de0f06f9ab6762da3a2693952ead880980fe131 Mon Sep 17 00:00:00 2001 From: Josh Allen Date: Mon, 14 Aug 2006 15:41:53 +0000 Subject: [PATCH] Move RoomInfoDisplay into its own files --- stepmania/src/RoomInfoDisplay.cpp | 198 ++++++++++++++++++++++++++++++ stepmania/src/RoomInfoDisplay.h | 76 ++++++++++++ 2 files changed, 274 insertions(+) create mode 100644 stepmania/src/RoomInfoDisplay.cpp create mode 100644 stepmania/src/RoomInfoDisplay.h diff --git a/stepmania/src/RoomInfoDisplay.cpp b/stepmania/src/RoomInfoDisplay.cpp new file mode 100644 index 0000000000..59055fe27c --- /dev/null +++ b/stepmania/src/RoomInfoDisplay.cpp @@ -0,0 +1,198 @@ +#include "global.h" +#include "RoomInfoDisplay.h" +#include "ActorUtil.h" +#include "NetworkSyncManager.h" + +AutoScreenMessage( SM_RoomInfoRetract ) +AutoScreenMessage( SM_RoomInfoDeploy ) + +RoomInfoDisplay::~RoomInfoDisplay() +{ + for (size_t i = 0; i < m_playerList.size(); i++) + { + this->RemoveChild(m_playerList[i]); + SAFE_DELETE(m_playerList[i]); + } +} + +void RoomInfoDisplay::DeployInfoBox() +{ + if (m_state == CLOSED) + { + SET_XY_AND_ON_COMMAND( this ); + m_state = OPEN; + } +} + +void RoomInfoDisplay::RetractInfoBox() +{ + if (m_state == OPEN) + OFF_COMMAND( this ); + + m_state = LOCKED; +} + +void RoomInfoDisplay::Load( RString sType ) +{ + DEPLOY_DELAY.Load(sType, "DeployDelay"); + RETRACT_DELAY.Load(sType, "RetractDelay"); + PLAYERLISTX.Load(sType, "PlayerListElementX"); + PLAYERLISTY.Load(sType, "PlayerListElementY"); + PLAYERLISTOFFSETX.Load(sType, "PlayerListElementOffsetX"); + PLAYERLISTOFFSETY.Load(sType, "PlayerListElementOffsetY"); + + m_state = LOCKED; + + m_bg.Load( THEME->GetPathG(m_sName,"Background") ); + m_bg->SetName("Background"); + this->AddChild(m_bg); + + m_Title.LoadFromFont( THEME->GetPathF(sType,"text") ); + m_Title.SetName("RoomTitle"); + m_Title.SetShadowLength( 0 ); + m_Title.SetHorizAlign( align_left ); + SET_XY_AND_ON_COMMAND(m_Title); + this->AddChild(&m_Title); + + m_Desc.LoadFromFont( THEME->GetPathF(sType,"text") ); + m_Desc.SetName("RoomDesc"); + m_Desc.SetShadowLength( 0 ); + m_Desc.SetHorizAlign( align_left ); + SET_XY_AND_ON_COMMAND(m_Desc); + this->AddChild(&m_Desc); + + m_lastRound.LoadFromFont( THEME->GetPathF(sType,"text") ); + m_lastRound.SetName("LastRound"); + m_lastRound.SetText("Last Round Info:"); + m_lastRound.SetShadowLength( 0 ); + m_lastRound.SetHorizAlign( align_left ); + SET_XY_AND_ON_COMMAND(m_lastRound); + this->AddChild(&m_lastRound); + + m_songTitle.LoadFromFont( THEME->GetPathF(sType,"text") ); + m_songTitle.SetName("SongTitle"); + m_songTitle.SetShadowLength( 0 ); + m_songTitle.SetHorizAlign( align_left ); + SET_XY_AND_ON_COMMAND(m_songTitle); + this->AddChild(&m_songTitle); + + m_songSub.LoadFromFont( THEME->GetPathF(sType,"text") ); + m_songSub.SetName("SongSubTitle"); + m_songSub.SetShadowLength( 0 ); + m_songSub.SetHorizAlign( align_left ); + SET_XY_AND_ON_COMMAND(m_songSub); + this->AddChild(&m_songSub); + + m_songArtist.LoadFromFont( THEME->GetPathF(sType,"text") ); + m_songArtist.SetName("SongArtist"); + m_songArtist.SetShadowLength( 0 ); + m_songArtist.SetHorizAlign( align_left ); + SET_XY_AND_ON_COMMAND(m_songArtist); + this->AddChild(&m_songArtist); + + m_players.LoadFromFont( THEME->GetPathF(sType,"text") ); + m_players.SetName("Players"); + m_players.SetShadowLength( 0 ); + m_players.SetHorizAlign( align_left ); + SET_XY_AND_ON_COMMAND(m_players); + this->AddChild(&m_players); + + SET_XY_AND_ON_COMMAND( this ); + OFF_COMMAND(this); + StopTweening(); +} + +void RoomInfoDisplay::SetRoom( const RoomWheelData* roomData ) +{ + RequestRoomInfo(roomData->m_sText); + + m_Title.SetText(ssprintf("Name: %s", roomData->m_sText.c_str())); + m_Desc.SetText(ssprintf("Description: %s", roomData->m_sDesc.c_str())); +} + +void RoomInfoDisplay::Update( float fDeltaTime ) +{ + if ((m_deployDelay.PeekDeltaTime() >= DEPLOY_DELAY) && (m_deployDelay.PeekDeltaTime() < (DEPLOY_DELAY + RETRACT_DELAY))) + DeployInfoBox(); + else if (m_deployDelay.PeekDeltaTime() >= DEPLOY_DELAY + RETRACT_DELAY) + RetractInfoBox(); + + ActorFrame::Update(fDeltaTime); +} + +void RoomInfoDisplay::RequestRoomInfo(const RString& name) +{ + NSMAN->m_SMOnlinePacket.ClearPacket(); + NSMAN->m_SMOnlinePacket.Write1((uint8_t)3); //Request Room Info + NSMAN->m_SMOnlinePacket.WriteNT(name); + NSMAN->SendSMOnline( ); +} + +void RoomInfoDisplay::SetRoomInfo( const RoomInfo& info) +{ + m_songTitle.SetText(ssprintf("Title: %s", info.songTitle.c_str())); + m_songSub.SetText(ssprintf("Subtitle: %s", info.songSubTitle.c_str())); + m_songArtist.SetText(ssprintf("Artist: %s", info.songArtist.c_str())); + m_players.SetText(ssprintf("Players (%d/%d):", info.numPlayers, info.maxPlayers)); + + if (m_playerList.size() > info.players.size()) + { + for (size_t i = info.players.size(); i < m_playerList.size(); i++) + { + //if our old list is larger remove some elements + this->RemoveChild(m_playerList[i]); + SAFE_DELETE(m_playerList[i]); + } + m_playerList.resize(info.players.size()); + } + else if (m_playerList.size() < info.players.size()) + { + //add elements if our old list is smaller + int oldsize = m_playerList.size(); + m_playerList.resize(info.players.size()); + for (size_t i = oldsize; i < m_playerList.size(); i++) + { + m_playerList[i] = new BitmapText; + m_playerList[i]->LoadFromFont( THEME->GetPathF(GetName(),"text") ); + m_playerList[i]->SetName("PlayerListElement"); + m_playerList[i]->SetShadowLength( 0 ); + m_playerList[i]->SetHorizAlign( align_left ); + m_playerList[i]->SetX(PLAYERLISTX + (i * PLAYERLISTOFFSETX)); + m_playerList[i]->SetY(PLAYERLISTY + (i * PLAYERLISTOFFSETY)); + ON_COMMAND(m_playerList[i]); + this->AddChild(m_playerList[i]); + } + + } + + for (size_t i = 0; i < m_playerList.size(); i++) + m_playerList[i]->SetText(info.players[i]); + + m_state = CLOSED; + m_deployDelay.Touch(); +} + +/* + * (c) 2006 Josh Allen + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ \ No newline at end of file diff --git a/stepmania/src/RoomInfoDisplay.h b/stepmania/src/RoomInfoDisplay.h new file mode 100644 index 0000000000..f9aa5365ff --- /dev/null +++ b/stepmania/src/RoomInfoDisplay.h @@ -0,0 +1,76 @@ +#ifndef ROOM_INFO_DISPLAY_H +#define ROOM_INFO_DISPLAY_H + +#include "RoomWheel.h" +#include "ActorFrame.h" + +class RoomInfoDisplay : public ActorFrame +{ +public: + ~RoomInfoDisplay(); + virtual void Load( RString sType ); + virtual void Update( float fDeltaTime ); + void SetRoom( const RoomWheelData* roomData ); + void SetRoomInfo( const RoomInfo& info); + void DeployInfoBox(); + void RetractInfoBox(); +private: + void RequestRoomInfo(const RString& name); + enum RoomInfoDisplayState + { + OPEN = 0, + CLOSED, + LOCKED + }; + + RoomInfoDisplayState m_state; + AutoActor m_bg; + BitmapText m_Title; + BitmapText m_Desc; + + BitmapText m_lastRound; + BitmapText m_songTitle; + BitmapText m_songSub; + BitmapText m_songArtist; + + BitmapText m_players; + vector m_playerList; + + RageTimer m_deployDelay; + + ThemeMetric X; + ThemeMetric Y; + ThemeMetric DEPLOY_DELAY; + ThemeMetric RETRACT_DELAY; + ThemeMetric PLAYERLISTX; + ThemeMetric PLAYERLISTY; + ThemeMetric PLAYERLISTOFFSETX; + ThemeMetric PLAYERLISTOFFSETY; +}; + +#endif + +/* + * (c) 2006 Josh Allen + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ \ No newline at end of file