Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Generals/Code/GameEngine/Include/GameNetwork/GUIUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,16 @@ void EnableAcceptControls(Bool Enabled, GameInfo *myGame, GameWindow *comboPlaye
GameWindow *comboColor[], GameWindow *comboPlayerTemplate[],
GameWindow *comboTeam[], GameWindow *buttonAccept[], GameWindow *buttonStart,
GameWindow *buttonMapStartPosition[], Int slotNum = -1);

// TheSuperHackers @feature Gives every occupied, non-observer slot a random army from the armies
// selectable in the army combo box. Returns TRUE if any slot was changed.
Bool RandomizeArmies( GameInfo *myGame );

// TheSuperHackers @feature Returns a random army from the armies selectable in the army combo box,
// or PLAYERTEMPLATE_RANDOM if there are none.
Int GetRandomSelectableArmy( GameInfo *myGame );

// TheSuperHackers @feature Creates a "Random Armies" button styled like 'startButton', with the same
// height, centered between 'startButton' and 'backButton'. Clicks go to the start button's owner.
GameWindow *CreateRandomArmiesButton( GameWindow *startButton, GameWindow *backButton,
const char *layoutFilename );
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ static GameWindow *comboBoxColor[MAX_SLOTS] = {0};
static GameWindow *comboBoxPlayerTemplate[MAX_SLOTS] = {0};

static GameWindow *comboBoxTeam[MAX_SLOTS] = {0};
static GameWindow *buttonRandomArmies = nullptr;

//static GameWindow *buttonStartPosition[MAX_SLOTS] = {0};
//
Expand Down Expand Up @@ -712,11 +713,16 @@ void InitLanGameGadgets()
if( buttonAccept[0] )
GadgetButtonSetEnabledColor(buttonAccept[0], acceptTrueColor );

// only the host rolls the armies; everybody else sees the result in the army column
buttonRandomArmies = CreateRandomArmiesButton( buttonStart, buttonBack, "LanGameOptionsMenu.wnd" );
if (buttonRandomArmies)
buttonRandomArmies->winHide( !TheLAN->AmIHost() );
}

void DeinitLanGameGadgets()
{
parentLanGameOptions = nullptr;
buttonRandomArmies = nullptr;
buttonEmote = nullptr;
buttonSelectMap = nullptr;
buttonStart = nullptr;
Expand Down Expand Up @@ -1144,6 +1150,19 @@ WindowMsgHandledType LanGameOptionsMenuSystem( GameWindow *window, UnsignedInt m
if (!txtInput.isEmpty())
TheLAN->RequestChat(txtInput, LANAPIInterface::LANCHAT_EMOTE);
}
else if ( buttonRandomArmies && control == buttonRandomArmies )
{
LANGameInfo *myGame = TheLAN->GetMyGame();
if (myGame && myGame->amIHost() && RandomizeArmies( myGame ))
{
// the armies can be rolled only once per lobby
buttonRandomArmies->winEnable( FALSE );
// send around the new slotlist; everyone has to accept the new armies again
myGame->resetAccepted();
TheLAN->RequestGameOptions(GenerateGameOptionsString(), true);
lanUpdateSlotList();
}
}
else if ( controlID == buttonSelectMapID )
{
//buttonBack->winEnable( false );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ static const char *gadgetsToHide[] =
"MapWindow",
//"StaticTextTitle",
"StaticTextTeam",
"ButtonRandomArmies",
"StaticTextFaction",
"StaticTextColor",
"TextEntryMapDisplay",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ static GameWindow *comboBoxColor[MAX_SLOTS] = {0};
static GameWindow *comboBoxPlayerTemplate[MAX_SLOTS] = {0};

static GameWindow *comboBoxTeam[MAX_SLOTS] = {0};
static GameWindow *buttonRandomArmies = nullptr;

//static GameWindow *buttonStartPosition[MAX_SLOTS] = {0};
//
Expand Down Expand Up @@ -1083,6 +1084,8 @@ void InitSkirmishGameGadgets()
// buttonStartPosition[i]->winHide(TRUE); // not using these right now
}

buttonRandomArmies = CreateRandomArmiesButton( buttonStart, buttonExit, "SkirmishGameOptionsMenu.wnd" );

populateSkirmishBattleHonors();
}

Expand Down Expand Up @@ -1131,6 +1134,7 @@ static const char *gadgetsToHide[] =
"StaticTextColor",
"StaticTextTeam",
"StaticTextFaction",
"ButtonRandomArmies",
nullptr
};
static const char *perPlayerGadgetsToHide[] =
Expand Down Expand Up @@ -1524,6 +1528,15 @@ WindowMsgHandledType SkirmishGameOptionsMenuSystem( GameWindow *window, Unsigned
// GameWindow *sliderGameSpeed = TheWindowManager->winGetWindowFromId( parentSkirmishGameOptions, sliderGameSpeedID );
// GadgetSliderSetPosition( sliderGameSpeed, TheGlobalData->m_framesPerSecondLimit );
// }
else if ( buttonRandomArmies && control == buttonRandomArmies )
{
if (RandomizeArmies( TheSkirmishGameInfo ))
{
// the armies can be rolled only once per lobby
buttonRandomArmies->winEnable( FALSE );
skirmishUpdateSlotList();
}
}
else if ( controlID == buttonSelectMapID )
{
sandboxOk = FALSE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ void showSkirmishGameOptionsUnderlyingGUIElements( Bool show )
win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:StaticTextTeam") );
win->winHide( !show );

win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ButtonRandomArmies") );
if (win)
win->winHide( !show );

win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:StaticTextFaction") );
win->winHide( !show );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ static GameWindow *comboBoxColor[MAX_SLOTS] = {0};
static GameWindow *comboBoxPlayerTemplate[MAX_SLOTS] = {0};

static GameWindow *comboBoxTeam[MAX_SLOTS] = {0};
static GameWindow *buttonRandomArmies = nullptr;

//static GameWindow *buttonStartPosition[MAX_SLOTS] = {0};
//
Expand Down Expand Up @@ -1112,11 +1113,17 @@ void InitWOLGameGadgets()
buttonBack->winEnable(TRUE);
}
//GadgetButtonSetEnabledColor(buttonAccept[0], GameSpyColor[GSCOLOR_ACCEPT_TRUE]);

// only the host rolls the armies; everybody else sees the result in the army column
buttonRandomArmies = CreateRandomArmiesButton( buttonStart, buttonBack, "GameSpyGameOptionsMenu.wnd" );
if (buttonRandomArmies)
buttonRandomArmies->winHide( !TheGameSpyInfo->amIHost() );
}

void DeinitWOLGameGadgets()
{
parentWOLGameSetup = nullptr;
buttonRandomArmies = nullptr;
buttonEmote = nullptr;
buttonSelectMap = nullptr;
buttonStart = nullptr;
Expand Down Expand Up @@ -2518,6 +2525,19 @@ WindowMsgHandledType WOLGameSetupMenuSystem( GameWindow *window, UnsignedInt msg
if (!txtInput.isEmpty())
TheGameSpyInfo->sendChat(txtInput, FALSE, nullptr); // 'emote' button is now carriage-return
}
else if ( buttonRandomArmies && control == buttonRandomArmies )
{
GameInfo *myGame = TheGameSpyInfo->getCurrentStagingRoom();
if (myGame && TheGameSpyInfo->amIHost() && RandomizeArmies( myGame ))
{
// the armies can be rolled only once per lobby
buttonRandomArmies->winEnable( FALSE );
// send around the new slotlist; everyone has to accept the new armies again
myGame->resetAccepted();
TheGameSpyInfo->setGameOptions();
WOLDisplaySlotList();
}
}
else if ( controlID == buttonSelectMapID )
{
WOLMapSelectLayout = TheWindowManager->winCreateLayout( "Menus/WOLMapSelectMenu.wnd" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ static const char *gadgetsToHide[] =
"MapWindow",
//"StaticTextGameName",
"StaticTextTeam",
"ButtonRandomArmies",
"StaticTextFaction",
"StaticTextColor",
"TextEntryMapDisplay",
Expand Down
173 changes: 163 additions & 10 deletions Generals/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "GameNetwork/GameInfo.h"
#include "Common/PlayerTemplate.h"
#include "GameNetwork/LANAPICallbacks.h" // for acceptTrueColor, etc
#include "GameClient/ClientRandomValue.h"


// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -229,17 +230,10 @@ void PopulateColorComboBox(Int comboBox, GameWindow *comboArray[], GameInfo *myG

// -----------------------------------------------------------------------------

void PopulatePlayerTemplateComboBox(Int comboBox, GameWindow *comboArray[], GameInfo *myGame, Bool allowObservers)
// Collects the player template indices that can be picked in the army combo box.
static void getSelectablePlayerTemplates(std::vector<Int> &templates)
{
Int numPlayerTemplates = ThePlayerTemplateStore->getPlayerTemplateCount();
UnicodeString playerTemplateName;

GadgetComboBoxReset(comboArray[comboBox]);

MultiplayerColorDefinition *def = TheMultiplayerSettings->getColor(PLAYERTEMPLATE_RANDOM);
Int newIndex = GadgetComboBoxAddEntry(comboArray[comboBox], TheGameText->fetch("GUI:Random"), def->getColor());
GadgetComboBoxSetItemData(comboArray[comboBox], newIndex, (void *)PLAYERTEMPLATE_RANDOM);

std::set<AsciiString> seenSides;

for (Int c=0; c<numPlayerTemplates; ++c)
Expand All @@ -258,10 +252,30 @@ void PopulatePlayerTemplateComboBox(Int comboBox, GameWindow *comboArray[], Game

seenSides.insert(side);

templates.push_back(c);
}
}

void PopulatePlayerTemplateComboBox(Int comboBox, GameWindow *comboArray[], GameInfo *myGame, Bool allowObservers)
{
GadgetComboBoxReset(comboArray[comboBox]);

MultiplayerColorDefinition *def = TheMultiplayerSettings->getColor(PLAYERTEMPLATE_RANDOM);
Int newIndex = GadgetComboBoxAddEntry(comboArray[comboBox], TheGameText->fetch("GUI:Random"), def->getColor());
GadgetComboBoxSetItemData(comboArray[comboBox], newIndex, (void *)PLAYERTEMPLATE_RANDOM);

std::vector<Int> templates;
getSelectablePlayerTemplates(templates);

for (size_t t = 0; t < templates.size(); ++t)
{
const Int c = templates[t];
const PlayerTemplate *fac = ThePlayerTemplateStore->getNthPlayerTemplate(c);
AsciiString side;
side.format("SIDE:%s", fac->getSide().str());
newIndex = GadgetComboBoxAddEntry(comboArray[comboBox], TheGameText->fetch(side), def->getColor());
GadgetComboBoxSetItemData(comboArray[comboBox], newIndex, (void *)c);
}
seenSides.clear();

// disabling observers for Multiplayer test
if (allowObservers)
Expand Down Expand Up @@ -306,6 +320,145 @@ void PopulateTeamComboBox(Int comboBox, GameWindow *comboArray[], GameInfo *myGa

// -----------------------------------------------------------------------------

Int GetRandomSelectableArmy( GameInfo *myGame )
{
if (!myGame)
return PLAYERTEMPLATE_RANDOM;

// pick from exactly the armies the army combo box offers
std::vector<Int> templates;
getSelectablePlayerTemplates(templates);
if (templates.empty())
return PLAYERTEMPLATE_RANDOM;

return templates[GameClientRandomValue(0, (Int)templates.size() - 1)];
}

Bool RandomizeArmies( GameInfo *myGame )
{
if (!myGame)
return FALSE;

Bool changed = FALSE;
for (Int i = 0; i < MAX_SLOTS; ++i)
{
GameSlot *slot = myGame->getSlot(i);

// every slot that will actually play (humans and AI, but no observers)
if (!slot || !slot->isOccupied() || slot->getPlayerTemplate() == PLAYERTEMPLATE_OBSERVER)
continue;

const Int army = GetRandomSelectableArmy(myGame);
if (army == PLAYERTEMPLATE_RANDOM)
return changed;

slot->setPlayerTemplate(army);
changed = TRUE;
}

return changed;
}

// -----------------------------------------------------------------------------

GameWindow *CreateRandomArmiesButton( GameWindow *startButton, GameWindow *backButton,
const char *layoutFilename )
{
if (!startButton || !backButton)
return nullptr;

GameWindow *parent = startButton->winGetParent();

AsciiString buttonName;
buttonName.format("%s:ButtonRandomArmies", layoutFilename);
const NameKeyType buttonID = NAMEKEY(buttonName);

// the menu may be initialized again while its windows still exist; reuse the button then.
// A new lobby gets a new roll, so make it clickable again.
if (GameWindow *existing = TheWindowManager->winGetWindowFromId( parent, buttonID ))
{
existing->winEnable( TRUE );
return existing;
}

// copy the look of the start button (frame, images, text colors and font)
WinInstanceData *styleData = startButton->winGetInstanceData();
WinInstanceData instData;
instData.init();
BitSet( instData.m_style, GWS_PUSH_BUTTON | GWS_MOUSE_TRACK );
for (Int d = 0; d < MAX_DRAW_DATA; ++d)
{
instData.m_enabledDrawData[d] = styleData->m_enabledDrawData[d];
instData.m_disabledDrawData[d] = styleData->m_disabledDrawData[d];
instData.m_hiliteDrawData[d] = styleData->m_hiliteDrawData[d];
}
instData.m_enabledText = styleData->m_enabledText;
instData.m_disabledText = styleData->m_disabledText;
instData.m_hiliteText = styleData->m_hiliteText;
instData.m_imageOffset = styleData->m_imageOffset;
instData.setTooltipText( TheGameText->FETCH_OR_SUBSTITUTE("TOOLTIP:RandomArmies",
L"Give every player a random army now, so everyone can see who plays what before the game starts.") );

UnsignedInt status = WIN_STATUS_ENABLED;
if (BitIsSet( startButton->winGetStatus(), WIN_STATUS_IMAGE ))
status |= WIN_STATUS_IMAGE;

// start out with exactly the size and row of the start button
Int startX, startY, startW, startH;
startButton->winGetScreenPosition( &startX, &startY );
startButton->winGetSize( &startW, &startH );

GameWindow *button = TheWindowManager->gogoGadgetPushButton( parent, status,
0, 0,
startW, startH,
&instData, startButton->winGetFont(), FALSE );

if (!button)
return nullptr;

button->winSetWindowId( buttonID );

// Route GBM_SELECTED to the same window that receives the start button messages.
button->winSetOwner( startButton->winGetOwner() );
GadgetButtonSetText( button, TheGameText->FETCH_OR_SUBSTITUTE("GUI:RandomArmies", L"RANDOM ARMIES") );

// Same height as the start button and slightly narrower, which still leaves
// enough room for the text on a single line.
Int width = startW * 85 / 100;

// center it between the start and the back button, without overlapping them
Int backX, backY, backW, backH;
backButton->winGetScreenPosition( &backX, &backY );
backButton->winGetSize( &backW, &backH );

Int leftEdge = startX + startW;
Int rightEdge = backX;
if (backX < startX)
{
// the back button is on the left side
leftEdge = backX + backW;
rightEdge = startX;
}
const Int maxWidth = (rightEdge - leftEdge) - startH;
if (maxWidth > 0 && width > maxWidth)
width = maxWidth;

Int screenX = (leftEdge + rightEdge) / 2 - width / 2;
Int screenY = startY;

// convert to coordinates relative to the parent
Int parentX = 0, parentY = 0;
if (parent)
parent->winGetScreenPosition( &parentX, &parentY );

button->winSetSize( width, startH );
button->winSetPosition( screenX - parentX, screenY - parentY );

return button;
}

// -----------------------------------------------------------------------------

// -----------------------------------------------------------------------------------------
// The slot list displaying function
//-------------------------------------------------------------------------------------------------
Expand Down
13 changes: 13 additions & 0 deletions GeneralsMD/Code/GameEngine/Include/GameNetwork/GUIUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,16 @@ void EnableAcceptControls(Bool Enabled, GameInfo *myGame, GameWindow *comboPlaye
GameWindow *comboColor[], GameWindow *comboPlayerTemplate[],
GameWindow *comboTeam[], GameWindow *buttonAccept[], GameWindow *buttonStart,
GameWindow *buttonMapStartPosition[], Int slotNum = -1);

// TheSuperHackers @feature Gives every occupied, non-observer slot a random army from the armies
// selectable in the army combo box. Returns TRUE if any slot was changed.
Bool RandomizeArmies( GameInfo *myGame );

// TheSuperHackers @feature Returns a random army from the armies selectable in the army combo box,
// or PLAYERTEMPLATE_RANDOM if there are none.
Int GetRandomSelectableArmy( GameInfo *myGame );

// TheSuperHackers @feature Creates a "Random Armies" button styled like 'startButton', with the same
// height, centered between 'startButton' and 'backButton'. Clicks go to the start button's owner.
GameWindow *CreateRandomArmiesButton( GameWindow *startButton, GameWindow *backButton,
const char *layoutFilename );
Loading
Loading