Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 059e06b

Browse files
committed
Update sites slider in metagame setup
1 parent 268d7ce commit 059e06b

File tree

4 files changed

+39
-36
lines changed

4 files changed

+39
-36
lines changed

GUI/GUISlider.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -632,10 +632,13 @@ int GUISlider::GetTickDirection(void)
632632

633633
void GUISlider::SetMinimum(int Minimum)
634634
{
635-
m_Minimum = Minimum;
635+
if (Minimum != m_Minimum) {
636+
m_Minimum = Minimum;
637+
m_Value = std::max(m_Value, m_Minimum);
636638

637-
// Re-Calculate the knob info
638-
CalculateKnob();
639+
// Re-Calculate the knob info
640+
CalculateKnob();
641+
}
639642
}
640643

641644

@@ -657,10 +660,13 @@ int GUISlider::GetMinimum(void)
657660

658661
void GUISlider::SetMaximum(int Maximum)
659662
{
660-
m_Maximum = Maximum;
663+
if (Maximum != m_Maximum) {
664+
m_Maximum = Maximum;
665+
m_Value = std::min(m_Value, m_Maximum);
661666

662-
// Re-Calculate the knob info
663-
CalculateKnob();
667+
// Re-Calculate the knob info
668+
CalculateKnob();
669+
}
664670
}
665671

666672

Managers/MetaMan.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ int MetaMan::Create()
9090
//////////////////////////////////////////////////////////////////////////////////////////
9191
// Description: Wipes any current and sets up a new game based on a size parameter.
9292

93-
int MetaMan::NewGame(float gameSize)
93+
int MetaMan::NewGame(int gameSize)
9494
{
9595
// Grab a random selection of Scene presets from all available
9696
list<Scene *> scenePresets;
97-
SelectScenePresets(gameSize, m_Players.size(), &scenePresets);
97+
SelectScenePresets(gameSize, &scenePresets);
9898

9999
// Destroy and clear any pre-existing scenes from previous games
100100
for (vector<Scene *>::iterator sItr = m_Scenes.begin(); sItr != m_Scenes.end(); ++sItr)
@@ -1035,29 +1035,19 @@ int MetaMan::TotalScenePresets(std::list<Scene *> *pScenes)
10351035
//////////////////////////////////////////////////////////////////////////////////////////
10361036
// Description: Yields a set of randomly selected Scene presets for a new game.
10371037

1038-
int MetaMan::SelectScenePresets(float gameSize, int playerCount, list<Scene *> *pSelected)
1038+
int MetaMan::SelectScenePresets(int gameSize, list<Scene *> *pSelected)
10391039
{
10401040
// Get the list of ALL eligible read-in Scene presets
10411041
list<Scene *> scenePresets;
10421042
TotalScenePresets(&scenePresets);
10431043

1044-
// How many scenes the game should end up with, according to the specified game size.
1045-
// Note that it will never be all or none of all the available scenes!
1046-
// TODO: Hook these constants up to settings!!
1047-
int minCount = MAX(3, MIN(floorf(playerCount * 1.5), scenePresets.size()));
1048-
int maxCount = MAX(floorf(scenePresets.size() * 0.7), minCount);
1049-
// Determine the actual game size
1050-
int gameSceneCount = minCount + floorf((maxCount - minCount) * gameSize);
1051-
// Clamp
1052-
gameSceneCount = MIN(gameSceneCount, maxCount);
1053-
gameSceneCount = MAX(gameSceneCount, minCount);
1054-
10551044
// If we need to actually fill the list, do so
10561045
if (pSelected)
10571046
{
10581047
// Go through the list and randomly knock out as many presets as necessary to reach the number we need for this game
1059-
int randomIndex, currentIndex;
1060-
while (scenePresets.size() > gameSceneCount)
1048+
int randomIndex;
1049+
int currentIndex;
1050+
while (scenePresets.size() > gameSize)
10611051
{
10621052
// Randomly select one of the scenes and remove it
10631053
currentIndex = 0;
@@ -1075,11 +1065,12 @@ int MetaMan::SelectScenePresets(float gameSize, int playerCount, list<Scene *> *
10751065

10761066
// Cast and copy (not deep!) to fill the provided list
10771067
pSelected->clear();
1078-
for (list<Scene *>::iterator pItr = scenePresets.begin(); pItr != scenePresets.end(); ++pItr)
1079-
pSelected->push_back(dynamic_cast<Scene *>(*pItr));
1068+
for (Scene *scenePointer : scenePresets) {
1069+
pSelected->push_back(scenePointer);
1070+
}
10801071
}
10811072

1082-
return gameSceneCount;
1073+
return gameSize;
10831074
}
10841075

10851076

Managers/MetaMan.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ friend class MetaSave;
120120
// Method: NewGame
121121
//////////////////////////////////////////////////////////////////////////////////////////
122122
// Description: Wipes any current and sets up a new game based on a size parameter.
123-
// Arguments: The size of the new Metagame, from 0 to 1.0, which will affect how
123+
// Arguments: The size of the new Metagame, which will affect how
124124
// many Scenes/Sites will ultimately be used.
125125
// Return value: An error return value signaling success or any particular failure.
126126
// Anything below 0 is an error signal.
127127

128-
int NewGame(float gameSize = 0.5);
128+
int NewGame(int gameSize = 3);
129129

130130

131131
//////////////////////////////////////////////////////////////////////////////////////////
@@ -535,14 +535,13 @@ friend class MetaSave;
535535
// Method: SelectScenePresets
536536
//////////////////////////////////////////////////////////////////////////////////////////
537537
// Description: Yields a set of randomly selected Scene presets for a new game.
538-
// Arguments: The normalized scalar from 0 to 1.0 that controls the size of the set.
539-
// The number of players that will be playing this new game.
538+
// Arguments: The size of the set.
540539
// The list to fill with the selected presets, depending on currently
541540
// set player numbers and loaded eligible scenes. If no list is passed
542541
// it will be ignored. Presets returned in list are NOT OWNED there.
543542
// Return value: The count of selected preset scenes.
544543

545-
int SelectScenePresets(float gameSize, int playerCount, std::list<Scene *> *pSelected = 0);
544+
int SelectScenePresets(int gameSize, std::list<Scene *> *pSelected = 0);
546545

547546

548547
//////////////////////////////////////////////////////////////////////////////////////////

Menus/MetagameGUI.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ bool MetagameGUI::StartNewGame()
12271227

12281228

12291229
// Start game of specified size!
1230-
g_MetaMan.NewGame((float)m_pSizeSlider->GetValue() / 100.0);
1230+
g_MetaMan.NewGame(m_pSizeSlider->GetValue());
12311231

12321232
return true;
12331233
}
@@ -6244,12 +6244,19 @@ void MetagameGUI::UpdateGameSizeLabels()
62446244
if (m_apPlayerControlButton[player]->GetText() != "None")
62456245
++playerCount;
62466246

6247-
// How many scenes does the current slider setting yield
6248-
int selectedCount = g_MetaMan.SelectScenePresets((float)m_pSizeSlider->GetValue() / 100.0, playerCount);
6249-
// How many scenes are there total
6250-
int totalCount = g_MetaMan.TotalScenePresets();
6247+
// How many scenes the game should end up with, according to the specified game size.
6248+
// Note that it will never be all or none of all the available scenes!
6249+
// TODO: Hook these constants up to settings!!
6250+
// How many scenes are there total
6251+
int totalCount = g_MetaMan.TotalScenePresets();
6252+
int minCount = std::clamp((playerCount * 3 / 2), 3, totalCount);
6253+
int maxCount = std::max(totalCount * 7 / 10, minCount);
6254+
m_pSizeSlider->SetMinimum(minCount);
6255+
m_pSizeSlider->SetMaximum(maxCount);
6256+
m_pSizeSlider->SetValueResolution(1);
6257+
62516258
char str[256];
6252-
sprintf_s(str, sizeof(str), "Game Size: %d/%d sites", selectedCount, totalCount);
6259+
sprintf_s(str, sizeof(str), "Game Size: %d/%d sites", m_pSizeSlider->GetValue(), totalCount);
62536260
m_pSizeLabel->SetText(str);
62546261

62556262
// How much starting gold does the slider yield

0 commit comments

Comments
 (0)