@@ -1144,8 +1144,6 @@ void KartSelectionScreen::eventCallback(Widget* widget,
1144
1144
{
1145
1145
RibbonWidget* tabs = getWidget<RibbonWidget>(" kartgroups" );
1146
1146
assert (tabs != NULL );
1147
- DynamicRibbonWidget* w = getWidget<DynamicRibbonWidget>(" karts" );
1148
- assert (w != NULL );
1149
1147
1150
1148
setKartsFromCurrentGroup ();
1151
1149
@@ -1154,59 +1152,7 @@ void KartSelectionScreen::eventCallback(Widget* widget,
1154
1152
1155
1153
UserConfigParams::m_last_used_kart_group = selected_kart_group;
1156
1154
1157
- RandomGenerator random ;
1158
-
1159
- const int num_players = m_kart_widgets.size ();
1160
- for (int n=0 ; n<num_players; n++)
1161
- {
1162
- // The game master is the one that can change the groups, leave
1163
- // his focus on the tabs for others, remove focus from kart that
1164
- // might no more exist in this tab.
1165
- if (n != PLAYER_ID_GAME_MASTER)
1166
- GUIEngine::focusNothingForPlayer (n);
1167
-
1168
- if (!m_kart_widgets[n].isReady ())
1169
- {
1170
- // try to preserve the same kart for each player (except for
1171
- // game master, since it's the one that can change the
1172
- // groups, so focus for this player must remain on the tabs)
1173
- const std::string& selected_kart =
1174
- m_kart_widgets[n].getKartInternalName ();
1175
- if (!w->setSelection ( selected_kart, n,
1176
- n != PLAYER_ID_GAME_MASTER))
1177
- {
1178
- // if we get here, it means one player "lost" his kart in
1179
- // the tab switch
1180
- if (UserConfigParams::logGUI ())
1181
- Log::info (" KartSelectionScreen" , " Player %u"
1182
- " lost their selection when switching tabs!!!" ,n);
1183
-
1184
- // Select a random kart in this case
1185
- const int count = (int ) w->getItems ().size ();
1186
- if (count > 0 )
1187
- {
1188
- // FIXME: two players may be given the same kart by
1189
- // the use of random
1190
- const int random_id = random .get ( count );
1191
-
1192
- // select kart for players > 0 (player 0 is the one
1193
- // that can change the groups, so focus for player 0
1194
- // must remain on the tabs)
1195
- const bool success =
1196
- w->setSelection ( random_id, n,
1197
- n != PLAYER_ID_GAME_MASTER );
1198
- if (!success)
1199
- Log::warn (" KartSelectionScreen" ,
1200
- " setting kart of player %u failed" );
1201
- }
1202
- else
1203
- {
1204
- Log::warn (" KartSelectionScreen" , " 0 items "
1205
- " in the ribbon" );
1206
- }
1207
- }
1208
- }
1209
- } // end for
1155
+ handleKartListFocus ();
1210
1156
}
1211
1157
else if (name == " karts" )
1212
1158
{
@@ -1215,7 +1161,7 @@ void KartSelectionScreen::eventCallback(Widget* widget,
1215
1161
const std::string selection = w->getSelectionIDString (player_id);
1216
1162
1217
1163
if (getWidget<CheckBoxWidget>(" favorite" )->getState () &&
1218
- player_id == PLAYER_ID_GAME_MASTER &&
1164
+ player_id == PLAYER_ID_GAME_MASTER && !m_game_master_confirmed &&
1219
1165
selection != RANDOM_KART_ID && !selection.empty ())
1220
1166
{
1221
1167
const KartProperties *kp = kart_properties_manager->getKart (selection);
@@ -1229,13 +1175,17 @@ void KartSelectionScreen::eventCallback(Widget* widget,
1229
1175
PlayerManager::getCurrentPlayer ()->addFavoriteKart (kp->getIdent ());
1230
1176
}
1231
1177
setKartsFromCurrentGroup ();
1178
+
1179
+ handleKartListFocus ();
1232
1180
}
1233
1181
else if (m_kart_widgets.size () > unsigned (player_id) && !useContinueButton ())
1234
1182
playerConfirm (player_id);
1235
1183
}
1236
- else if (name == " kart_class" )
1184
+ else if (name == " kart_class" && !m_game_master_confirmed )
1237
1185
{
1238
1186
setKartsFromCurrentGroup ();
1187
+
1188
+ handleKartListFocus ();
1239
1189
}
1240
1190
else if (name == " continue" )
1241
1191
{
@@ -1289,6 +1239,38 @@ bool KartSelectionScreen::onEscapePressed()
1289
1239
1290
1240
// ----------------------------------------------------------------------------
1291
1241
1242
+ void KartSelectionScreen::onFocusChanged (GUIEngine::Widget* previous,
1243
+ GUIEngine::Widget* focus, int playerID)
1244
+ {
1245
+ if (playerID == PLAYER_ID_GAME_MASTER || !previous || !focus)
1246
+ {
1247
+ return ;
1248
+ }
1249
+ GUIEngine::SpinnerWidget* kart_class = getWidget<GUIEngine::SpinnerWidget>(" kart_class" );
1250
+ DynamicRibbonWidget* w = getWidget<DynamicRibbonWidget>(" karts" );
1251
+
1252
+ if (GUIEngine::isFocusedForPlayer (kart_class, playerID))
1253
+ {
1254
+ for (int i = 0 ; i < m_kart_widgets.size (); i++)
1255
+ {
1256
+ if (m_kart_widgets[i].getPlayerID () == playerID)
1257
+ {
1258
+ if (previous->getType () == WTYPE_RIBBON)
1259
+ {
1260
+ m_kart_widgets[i].getPlayerNameSpinner ()->setFocusForPlayer (playerID);
1261
+ }
1262
+ else
1263
+ {
1264
+ w->setSelection (playerID, playerID, true );
1265
+ }
1266
+ break ;
1267
+ }
1268
+ }
1269
+ }
1270
+ }
1271
+
1272
+ // ----------------------------------------------------------------------------
1273
+
1292
1274
#if 0
1293
1275
#pragma mark -
1294
1276
#pragma mark KartSelectionScreen (private)
@@ -1429,6 +1411,68 @@ void KartSelectionScreen::allPlayersDone()
1429
1411
1430
1412
// ----------------------------------------------------------------------------
1431
1413
1414
+ void KartSelectionScreen::handleKartListFocus ()
1415
+ {
1416
+ DynamicRibbonWidget* w = getWidget<DynamicRibbonWidget>(" karts" );
1417
+ assert (w != NULL );
1418
+
1419
+ RandomGenerator random ;
1420
+
1421
+ const int num_players = m_kart_widgets.size ();
1422
+ for (int n=0 ; n<num_players; n++)
1423
+ {
1424
+ // The game master is the one that can change the groups, leave
1425
+ // his focus on the tabs for others, remove focus from kart that
1426
+ // might no more exist in this tab.
1427
+ if (n != PLAYER_ID_GAME_MASTER)
1428
+ GUIEngine::focusNothingForPlayer (n);
1429
+
1430
+ if (!m_kart_widgets[n].isReady ())
1431
+ {
1432
+ // try to preserve the same kart for each player (except for
1433
+ // game master, since it's the one that can change the
1434
+ // groups, so focus for this player must remain on the tabs)
1435
+ const std::string& selected_kart =
1436
+ m_kart_widgets[n].getKartInternalName ();
1437
+ if (!w->setSelection ( selected_kart, n,
1438
+ n != PLAYER_ID_GAME_MASTER))
1439
+ {
1440
+ // if we get here, it means one player "lost" his kart in
1441
+ // the tab switch
1442
+ if (UserConfigParams::logGUI ())
1443
+ Log::info (" KartSelectionScreen" , " Player %u"
1444
+ " lost their selection when switching tabs!!!" ,n);
1445
+
1446
+ // Select a random kart in this case
1447
+ const int count = (int ) w->getItems ().size ();
1448
+ if (count > 0 )
1449
+ {
1450
+ // FIXME: two players may be given the same kart by
1451
+ // the use of random
1452
+ const int random_id = random .get ( count );
1453
+
1454
+ // select kart for players > 0 (player 0 is the one
1455
+ // that can change the groups, so focus for player 0
1456
+ // must remain on the tabs)
1457
+ const bool success =
1458
+ w->setSelection ( random_id, n,
1459
+ n != PLAYER_ID_GAME_MASTER );
1460
+ if (!success)
1461
+ Log::warn (" KartSelectionScreen" ,
1462
+ " setting kart of player %u failed" );
1463
+ }
1464
+ else
1465
+ {
1466
+ Log::warn (" KartSelectionScreen" , " 0 items "
1467
+ " in the ribbon" );
1468
+ }
1469
+ }
1470
+ }
1471
+ } // end for
1472
+ }
1473
+
1474
+ // ----------------------------------------------------------------------------
1475
+
1432
1476
bool KartSelectionScreen::validateIdentChoices ()
1433
1477
{
1434
1478
bool ok = true ;
0 commit comments