Skip to content

Commit 00aa0e6

Browse files
committed
Address review comments
1 parent d1b4568 commit 00aa0e6

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

C7/UIElements/NewGame/PlayerSetup.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,23 +161,31 @@ private void AddOpponentSelectors() {
161161
popup.SetItemAsRadioCheckable(k, false);
162162
popup.SetItemAsCheckable(k, false);
163163
}
164+
165+
optionButton.ItemSelected += (long i) => { UpdateOpponentSelectors(); };
164166
}
165167

166168
UpdateOpponentSelectors();
167169
}
168170

169171
private void UpdateOpponentSelectors() {
170-
foreach (OptionButton ob in opponentSelectors) {
171-
int index = civilizations.FindIndex(x => x == this.civilization);
172+
HashSet<string> civsTaken = new();
173+
civsTaken.Add(civilization.name);
172174

173-
for (int i = 0; i < ob.GetPopup().ItemCount; ++i) {
174-
ob.SetItemDisabled(i, this.civilization.name == ob.GetItemText(i));
175-
}
175+
foreach (OptionButton ob in opponentSelectors) {
176+
string selection = ob.GetItemText(ob.Selected);
176177

177178
// If the player decides to play as civ X and one of the opponent
178-
// selectors has X selected, change it to random.
179-
if (ob.Selected == index) {
179+
// selectors has X selected, change it to random. Similarly if one
180+
// of the previous option buttons has selected this civ.
181+
if (civsTaken.Contains(selection)) {
180182
ob.Select(ob.GetPopup().ItemCount - 1);
183+
} else if (selection != "Random") {
184+
civsTaken.Add(selection);
185+
}
186+
187+
for (int i = 0; i < ob.GetPopup().ItemCount; ++i) {
188+
ob.SetItemDisabled(i, civsTaken.Contains(ob.GetItemText(i)));
181189
}
182190
}
183191
}
@@ -196,10 +204,10 @@ private void DisplaySelectedLeader() {
196204
}
197205

198206
private SaveGame GetSave() {
199-
try {
207+
if (!Engine.IsEditorHint()) {
200208
GlobalSingleton Global = GetNode<GlobalSingleton>("/root/GlobalSingleton");
201209
return SaveManager.LoadSave(Global.DefaultGamePath, Global.DefaultBicPath, (string unused) => { return unused; });
202-
} catch (Exception e) {
210+
} else {
203211
// Hardcoded fallback for the godot editor, which doesn't handle the
204212
// global.
205213
return SaveManager.LoadSave(@"./Text/c7-static-map-save.json", "", (string unused) => { return unused; });

0 commit comments

Comments
 (0)