Skip to content

Commit

Permalink
Merge pull request #370 from agateau/fix-crash-in-multiplayer-select-…
Browse files Browse the repository at this point in the history
…screen

MultiPlayerScreen: fix crash when clicking on locked vehicle
  • Loading branch information
agateau authored Jul 24, 2023
2 parents 90b4921 + f13fd6f commit 80327ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 7 additions & 4 deletions core/src/com/agateau/pixelwheels/screens/MultiPlayerScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import com.agateau.pixelwheels.vehicledef.VehicleDef;
import com.agateau.ui.InputMapper;
import com.agateau.ui.anchor.AnchorGroup;
import com.agateau.ui.menu.GridMenuItem;
import com.agateau.ui.menu.Menu;
import com.agateau.ui.menu.MenuItemListener;
import com.agateau.ui.uibuilder.UiBuilder;
import com.agateau.utils.FileUtils;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
Expand Down Expand Up @@ -160,11 +160,14 @@ private void setupCursor(Assets assets, int idx) {
VehicleDef vehicleDef = assets.findVehicleDefById(vehicleId);
mVehicleSelector.setCurrent(idx, vehicleDef);

mVehicleSelector.setListener(
mVehicleSelector.setSelectionListener(
idx,
new MenuItemListener() {
new GridMenuItem.SelectionListener<VehicleDef>() {
@Override
public void triggered() {
public void currentChanged(VehicleDef item, int index) {}

@Override
public void selectionConfirmed() {
VehicleDef vehicleDef = mVehicleSelector.getSelected(idx);
setReadyLabelText(idx, vehicleDef.getName());
nextIfPossible();
Expand Down
6 changes: 5 additions & 1 deletion core/src/com/agateau/ui/menu/GridMenuItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,11 @@ public void setItemDirection(ItemDirection itemDirection) {
}

public void setSelectionListener(SelectionListener<T> selectionListener) {
mCursors.first().mSelectionListener = selectionListener;
setSelectionListener(0, selectionListener);
}

public void setSelectionListener(int idx, SelectionListener<T> selectionListener) {
mCursors.get(idx).mSelectionListener = selectionListener;
}

public void setCurrent(int cursorIdx, T item) {
Expand Down

0 comments on commit 80327ac

Please sign in to comment.