mirror of
https://github.com/glest/glest-source.git
synced 2025-08-20 07:01:21 +02:00
clients can choose team and faction ... client triggered slot change is prepared
This commit is contained in:
@@ -137,7 +137,7 @@ void GraphicListBox::setSelectedItemIndex(int index){
|
|||||||
void GraphicListBox::setEditable(bool editable){
|
void GraphicListBox::setEditable(bool editable){
|
||||||
graphButton1.setEditable(editable);
|
graphButton1.setEditable(editable);
|
||||||
graphButton2.setEditable(editable);
|
graphButton2.setEditable(editable);
|
||||||
editable=true;
|
GraphicComponent::setEditable(editable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicListBox::setSelectedItem(string item){
|
void GraphicListBox::setSelectedItem(string item){
|
||||||
|
@@ -51,8 +51,8 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
|
|||||||
NetworkManager &networkManager= NetworkManager::getInstance();
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
||||||
Config &config = Config::getInstance();
|
Config &config = Config::getInstance();
|
||||||
needToSetChangedGameSettings = false;
|
needToSetChangedGameSettings = false;
|
||||||
lastSetChangedGameSettings = time(NULL);;
|
lastSetChangedGameSettings = time(NULL);
|
||||||
|
|
||||||
|
|
||||||
currentFactionName="";
|
currentFactionName="";
|
||||||
currentMap="";
|
currentMap="";
|
||||||
@@ -116,6 +116,8 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
|
|||||||
listBoxTeams[i].init(600, 550-i*30, 60);
|
listBoxTeams[i].init(600, 550-i*30, 60);
|
||||||
listBoxTeams[i].setEditable(false);
|
listBoxTeams[i].setEditable(false);
|
||||||
labelNetStatus[i].init(700, 550-i*30, 60);
|
labelNetStatus[i].init(700, 550-i*30, 60);
|
||||||
|
grabSlotButton[i].init(700, 550-i*30, 30);
|
||||||
|
grabSlotButton[i].setText(">");
|
||||||
}
|
}
|
||||||
|
|
||||||
labelControl.init(200, 600, GraphicListBox::defW, GraphicListBox::defH, true);
|
labelControl.init(200, 600, GraphicListBox::defW, GraphicListBox::defH, true);
|
||||||
@@ -214,6 +216,28 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
for(int i=0; i<GameConstants::maxPlayers; ++i)
|
||||||
|
{
|
||||||
|
if(listBoxFactions[i].getEditable()){
|
||||||
|
if(listBoxFactions[i].mouseClick(x, y)){
|
||||||
|
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
|
||||||
|
if(clientInterface->isConnected()){
|
||||||
|
clientInterface->setGameSettingsReceived(false);
|
||||||
|
clientInterface->sendSwitchSetupRequest(listBoxFactions[i].getSelectedItem(),clientInterface->getGameSettings()->getThisFactionIndex(),-1,listBoxTeams[i].getSelectedItemIndex());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(listBoxTeams[i].getEditable()){
|
||||||
|
if(listBoxTeams[i].mouseClick(x, y)){
|
||||||
|
if(clientInterface->isConnected()){
|
||||||
|
clientInterface->setGameSettingsReceived(false);
|
||||||
|
clientInterface->sendSwitchSetupRequest(listBoxFactions[i].getSelectedItem(),clientInterface->getGameSettings()->getThisFactionIndex(),-1,listBoxTeams[i].getSelectedItemIndex());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// for(int i=0; i<mapInfo.players; ++i)
|
// for(int i=0; i<mapInfo.players; ++i)
|
||||||
// {
|
// {
|
||||||
// //ensure thet only 1 human player is present
|
// //ensure thet only 1 human player is present
|
||||||
@@ -306,7 +330,10 @@ void MenuStateConnectedGame::render(){
|
|||||||
renderer.renderListBox(&listBoxTeams[i]);
|
renderer.renderListBox(&listBoxTeams[i]);
|
||||||
//renderer.renderLabel(&labelNetStatus[i]);
|
//renderer.renderLabel(&labelNetStatus[i]);
|
||||||
|
|
||||||
if((listBoxControls[i].getSelectedItemIndex()==ctNetwork) ||
|
if((listBoxControls[i].getSelectedItemIndex()==ctNetwork) && (labelNetStatus[i].getText()=="???")){
|
||||||
|
renderer.renderButton(&grabSlotButton[i]);
|
||||||
|
}
|
||||||
|
else if((listBoxControls[i].getSelectedItemIndex()==ctNetwork) ||
|
||||||
(listBoxControls[i].getSelectedItemIndex()==ctHuman)){
|
(listBoxControls[i].getSelectedItemIndex()==ctHuman)){
|
||||||
renderer.renderLabel(&labelNetStatus[i]);
|
renderer.renderLabel(&labelNetStatus[i]);
|
||||||
}
|
}
|
||||||
@@ -476,6 +503,8 @@ void MenuStateConnectedGame::update()
|
|||||||
// Control
|
// Control
|
||||||
for(int i=0; i<GameConstants::maxPlayers; ++i){
|
for(int i=0; i<GameConstants::maxPlayers; ++i){
|
||||||
listBoxControls[i].setSelectedItemIndex(ctClosed);
|
listBoxControls[i].setSelectedItemIndex(ctClosed);
|
||||||
|
listBoxFactions[i].setEditable(false);
|
||||||
|
listBoxTeams[i].setEditable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i=0; i<gameSettings->getFactionCount(); ++i){
|
for(int i=0; i<gameSettings->getFactionCount(); ++i){
|
||||||
@@ -491,6 +520,8 @@ void MenuStateConnectedGame::update()
|
|||||||
if(gameSettings->getFactionControl(i) == ctNetwork && gameSettings->getThisFactionIndex() == i){
|
if(gameSettings->getFactionControl(i) == ctNetwork && gameSettings->getThisFactionIndex() == i){
|
||||||
// set my current slot to ctHuman
|
// set my current slot to ctHuman
|
||||||
listBoxControls[slot].setSelectedItemIndex(ctHuman);
|
listBoxControls[slot].setSelectedItemIndex(ctHuman);
|
||||||
|
listBoxFactions[slot].setEditable(true);
|
||||||
|
listBoxTeams[slot].setEditable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
settingsReceivedFromServer=true;
|
settingsReceivedFromServer=true;
|
||||||
|
@@ -49,6 +49,7 @@ private:
|
|||||||
GraphicListBox listBoxFactions[GameConstants::maxPlayers];
|
GraphicListBox listBoxFactions[GameConstants::maxPlayers];
|
||||||
GraphicListBox listBoxTeams[GameConstants::maxPlayers];
|
GraphicListBox listBoxTeams[GameConstants::maxPlayers];
|
||||||
GraphicLabel labelNetStatus[GameConstants::maxPlayers];
|
GraphicLabel labelNetStatus[GameConstants::maxPlayers];
|
||||||
|
GraphicButton grabSlotButton[GameConstants::maxPlayers];
|
||||||
MapInfo mapInfo;
|
MapInfo mapInfo;
|
||||||
|
|
||||||
bool needToSetChangedGameSettings;
|
bool needToSetChangedGameSettings;
|
||||||
@@ -61,7 +62,7 @@ private:
|
|||||||
string currentMap;
|
string currentMap;
|
||||||
bool settingsReceivedFromServer;
|
bool settingsReceivedFromServer;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MenuStateConnectedGame(Program *program, MainMenu *mainMenu, bool openNetworkSlots= false);
|
MenuStateConnectedGame(Program *program, MainMenu *mainMenu, bool openNetworkSlots= false);
|
||||||
|
|
||||||
|
@@ -523,6 +523,26 @@ void MenuStateCustomGame::update()
|
|||||||
needToSetChangedGameSettings = false;
|
needToSetChangedGameSettings = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SwitchSetupRequest** switchSetupRequests=serverInterface->getSwitchSetupRequests();
|
||||||
|
for(int i= 0; i<mapInfo.players; ++i)
|
||||||
|
{
|
||||||
|
if(switchSetupRequests[i]!=NULL)
|
||||||
|
{
|
||||||
|
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork)
|
||||||
|
{
|
||||||
|
//printf("switchSetupRequests[i]->getSelectedFactionName()=%s\n",switchSetupRequests[i]->getSelectedFactionName().c_str());
|
||||||
|
//printf("switchSetupRequests[i]->getToTeam()=%d\n",switchSetupRequests[i]->getToTeam());
|
||||||
|
|
||||||
|
if(switchSetupRequests[i]->getSelectedFactionName()!=""){
|
||||||
|
listBoxFactions[i].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName());
|
||||||
|
}
|
||||||
|
if(switchSetupRequests[i]->getToTeam()!=-1)
|
||||||
|
listBoxTeams[i].setSelectedItemIndex(switchSetupRequests[i]->getToTeam());
|
||||||
|
}
|
||||||
|
delete switchSetupRequests[i];
|
||||||
|
switchSetupRequests[i]=NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
if(difftime(time(NULL),lastSetChangedGameSettings) >= 2)
|
if(difftime(time(NULL),lastSetChangedGameSettings) >= 2)
|
||||||
{
|
{
|
||||||
GameSettings gameSettings;
|
GameSettings gameSettings;
|
||||||
|
@@ -687,6 +687,15 @@ void ClientInterface::stopServerDiscovery() {
|
|||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClientInterface::sendSwitchSetupRequest(string selectedFactionName, int8 currentFactionIndex, int8 toFactionIndex,int8 toTeam)
|
||||||
|
{
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
//printf("string-cuf-tof-team= %s-%d-%d-%d\n",selectedFactionName.c_str(),currentFactionIndex,toFactionIndex,toTeam);
|
||||||
|
SwitchSetupRequest message=SwitchSetupRequest(selectedFactionName, currentFactionIndex, toFactionIndex,toTeam);
|
||||||
|
sendMessage(&message);
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
bool ClientInterface::getFogOfWar()
|
bool ClientInterface::getFogOfWar()
|
||||||
{
|
{
|
||||||
|
@@ -72,6 +72,7 @@ public:
|
|||||||
bool getLaunchGame() const {return launchGame;}
|
bool getLaunchGame() const {return launchGame;}
|
||||||
bool getIntroDone() const {return introDone;}
|
bool getIntroDone() const {return introDone;}
|
||||||
bool getGameSettingsReceived() const {return gameSettingsReceived;}
|
bool getGameSettingsReceived() const {return gameSettingsReceived;}
|
||||||
|
void setGameSettingsReceived(bool value) {gameSettingsReceived=value;}
|
||||||
int getPlayerIndex() const {return playerIndex;}
|
int getPlayerIndex() const {return playerIndex;}
|
||||||
//const GameSettings *getGameSettings() {return &gameSettings;}
|
//const GameSettings *getGameSettings() {return &gameSettings;}
|
||||||
|
|
||||||
@@ -80,6 +81,8 @@ public:
|
|||||||
|
|
||||||
void discoverServers(DiscoveredServersInterface *cb);
|
void discoverServers(DiscoveredServersInterface *cb);
|
||||||
void stopServerDiscovery();
|
void stopServerDiscovery();
|
||||||
|
|
||||||
|
void sendSwitchSetupRequest(string selectedFactionName, int8 currentFactionIndex, int8 toFactionIndex, int8 toTeam);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void waitForMessage();
|
void waitForMessage();
|
||||||
|
@@ -314,6 +314,22 @@ void ConnectionSlot::update(bool checkForNewClients)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case nmtSwitchSetupRequest:
|
||||||
|
{
|
||||||
|
SwitchSetupRequest switchSetupRequest;
|
||||||
|
if(receiveMessage(&switchSetupRequest))
|
||||||
|
{
|
||||||
|
if(serverInterface->getSwitchSetupRequests()[switchSetupRequest.getCurrentFactionIndex()]==NULL)
|
||||||
|
{
|
||||||
|
serverInterface->getSwitchSetupRequests()[switchSetupRequest.getCurrentFactionIndex()]= new SwitchSetupRequest();
|
||||||
|
}
|
||||||
|
*(serverInterface->getSwitchSetupRequests()[switchSetupRequest.getCurrentFactionIndex()])=switchSetupRequest;
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
//throw runtime_error("Unexpected message in connection slot: " + intToStr(networkMessageType));
|
//throw runtime_error("Unexpected message in connection slot: " + intToStr(networkMessageType));
|
||||||
|
@@ -449,4 +449,42 @@ void NetworkMessageSynchNetworkGameDataFileGet::send(Socket* socket) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class NetworkMessageSynchNetworkGameDataFileGet
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
SwitchSetupRequest::SwitchSetupRequest()
|
||||||
|
{
|
||||||
|
data.messageType= nmtSwitchSetupRequest;
|
||||||
|
data.selectedFactionName="";
|
||||||
|
data.currentFactionIndex=-1;
|
||||||
|
data.toFactionIndex=-1;
|
||||||
|
data.toTeam = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SwitchSetupRequest::SwitchSetupRequest(string selectedFactionName, int8 currentFactionIndex, int8 toFactionIndex,int8 toTeam)
|
||||||
|
{
|
||||||
|
data.messageType= nmtSwitchSetupRequest;
|
||||||
|
data.selectedFactionName=selectedFactionName;
|
||||||
|
data.currentFactionIndex=currentFactionIndex;
|
||||||
|
data.toFactionIndex=toFactionIndex;
|
||||||
|
data.toTeam = toTeam;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SwitchSetupRequest::receive(Socket* socket)
|
||||||
|
{
|
||||||
|
return NetworkMessage::receive(socket, &data, sizeof(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitchSetupRequest::send(Socket* socket) const
|
||||||
|
{
|
||||||
|
assert(data.messageType==nmtSwitchSetupRequest);
|
||||||
|
NetworkMessage::send(socket, &data, sizeof(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
@@ -38,7 +38,7 @@ enum NetworkMessageType{
|
|||||||
nmtSynchNetworkGameDataFileCRCCheck,
|
nmtSynchNetworkGameDataFileCRCCheck,
|
||||||
nmtSynchNetworkGameDataFileGet,
|
nmtSynchNetworkGameDataFileGet,
|
||||||
nmtBroadCastSetup,
|
nmtBroadCastSetup,
|
||||||
|
nmtSwitchSetupRequest,
|
||||||
|
|
||||||
nmtCount
|
nmtCount
|
||||||
};
|
};
|
||||||
@@ -412,6 +412,43 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class SwitchSetupRequest
|
||||||
|
//
|
||||||
|
// Message sent from the server to the client
|
||||||
|
// when the client connects and vice versa
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
class SwitchSetupRequest: public NetworkMessage{
|
||||||
|
private:
|
||||||
|
static const int maxStringSize= 256;
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Data{
|
||||||
|
int8 messageType;
|
||||||
|
NetworkString<maxStringSize> selectedFactionName; //wanted faction name
|
||||||
|
int8 currentFactionIndex;
|
||||||
|
int8 toFactionIndex;
|
||||||
|
int8 toTeam;
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
Data data;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SwitchSetupRequest();
|
||||||
|
SwitchSetupRequest( string selectedFactionName, int8 currentFactionIndex, int8 toFactionIndex,int8 toTeam);
|
||||||
|
|
||||||
|
string getSelectedFactionName() const {return data.selectedFactionName.getString();}
|
||||||
|
int getCurrentFactionIndex() const {return data.currentFactionIndex;}
|
||||||
|
int getToFactionIndex() const {return data.toFactionIndex;}
|
||||||
|
int getToTeam() const {return data.toTeam;}
|
||||||
|
|
||||||
|
virtual bool receive(Socket* socket);
|
||||||
|
virtual void send(Socket* socket) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -40,6 +40,7 @@ ServerInterface::ServerInterface(){
|
|||||||
|
|
||||||
for(int i= 0; i<GameConstants::maxPlayers; ++i){
|
for(int i= 0; i<GameConstants::maxPlayers; ++i){
|
||||||
slots[i]= NULL;
|
slots[i]= NULL;
|
||||||
|
switchSetupRequests[i]= NULL;
|
||||||
}
|
}
|
||||||
serverSocket.setBlock(false);
|
serverSocket.setBlock(false);
|
||||||
serverSocket.bind(Config::getInstance().getInt("ServerPort",intToStr(GameConstants::serverPort).c_str()));
|
serverSocket.bind(Config::getInstance().getInt("ServerPort",intToStr(GameConstants::serverPort).c_str()));
|
||||||
@@ -50,6 +51,9 @@ ServerInterface::~ServerInterface(){
|
|||||||
|
|
||||||
for(int i= 0; i<GameConstants::maxPlayers; ++i){
|
for(int i= 0; i<GameConstants::maxPlayers; ++i){
|
||||||
delete slots[i];
|
delete slots[i];
|
||||||
|
slots[i]=NULL;
|
||||||
|
delete switchSetupRequests[i];
|
||||||
|
switchSetupRequests[i]=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
close();
|
close();
|
||||||
@@ -217,7 +221,7 @@ void ServerInterface::update()
|
|||||||
chatTeamIndex= networkMessageText.getTeamIndex();
|
chatTeamIndex= networkMessageText.getTeamIndex();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -43,6 +43,7 @@ private:
|
|||||||
ServerSocket serverSocket;
|
ServerSocket serverSocket;
|
||||||
bool gameHasBeenInitiated;
|
bool gameHasBeenInitiated;
|
||||||
int gameSettingsUpdateCount;
|
int gameSettingsUpdateCount;
|
||||||
|
SwitchSetupRequest* switchSetupRequests[GameConstants::maxPlayers];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ServerInterface();
|
ServerInterface();
|
||||||
@@ -66,6 +67,7 @@ public:
|
|||||||
virtual string getNetworkStatus() const;
|
virtual string getNetworkStatus() const;
|
||||||
|
|
||||||
ServerSocket* getServerSocket() {return &serverSocket;}
|
ServerSocket* getServerSocket() {return &serverSocket;}
|
||||||
|
SwitchSetupRequest** getSwitchSetupRequests() {return &switchSetupRequests[0];}
|
||||||
void addSlot(int playerIndex);
|
void addSlot(int playerIndex);
|
||||||
void removeSlot(int playerIndex);
|
void removeSlot(int playerIndex);
|
||||||
ConnectionSlot* getSlot(int playerIndex);
|
ConnectionSlot* getSlot(int playerIndex);
|
||||||
|
Reference in New Issue
Block a user