| 16 | import forge.util.ThreadUtil; |
| 17 | |
| 18 | public class VGameMenu extends FDropDownMenu { |
| 19 | public VGameMenu() { |
| 20 | } |
| 21 | |
| 22 | @Override |
| 23 | protected void buildMenu() { |
| 24 | addItem(new FMenuItem(MatchController.instance.getConcedeCaption(), FSkinImage.CONCEDE, e -> |
| 25 | ThreadUtil.invokeInGameThread(MatchController.instance::concede) |
| 26 | )); |
| 27 | // Called directly, not via invokeInGameThread like concede: the offer must register even while |
| 28 | // the game thread is busy (a frozen thread would never drain a queued task). It's applied |
| 29 | // off-thread like concede, safe because a human acts only while the game thread is parked at priority. |
| 30 | addItem(new FMenuItem(Forge.getLocalizer().getMessage("lblOfferDraw"), FSkinImage.OFFERDRAW, e -> |
| 31 | MatchController.instance.getGameController().drawOfferAction(DrawOfferMessage.Action.OFFER) |
| 32 | )); |
| 33 | /*addItem(new FMenuItem("Save Game", FSkinImage.SAVE, new FEventHandler() { |
| 34 | @Override |
| 35 | public void handleEvent(FEvent e) { |
| 36 | GameStateSerializer.saveGameState(MatchUtil.getGame(), ForgeConstants.USER_GAMES_DIR + "GameSave.txt"); |
| 37 | FOptionPane.showMessageDialog("Game saved successfully.", "Save Game", FOptionPane.INFORMATION_ICON); |
| 38 | } |
| 39 | })); |
| 40 | addItem(new FMenuItem("Load Game", FSkinImage.OPEN, new FEventHandler() { |
| 41 | @Override |
| 42 | public void handleEvent(FEvent e) { |
| 43 | GameStateDeserializer.loadGameState(MatchUtil.getGame(), ForgeConstants.USER_GAMES_DIR + "GameSave.txt"); |
| 44 | } |
| 45 | }));*/ |
| 46 | addItem(new FMenuItem(Forge.getLocalizer().getMessage("lblAutoYieldsAndTriggers"), Forge.hdbuttons ? FSkinImage.HDYIELD : FSkinImage.WARNING, new FEventHandler() { |
| 47 | @Override |
| 48 | public void handleEvent(FEvent e) { |
| 49 | final boolean autoYieldsDisabled = MatchController.instance.getGameController().getYieldController().getDisableAutoYields(); |
| 50 | final VAutoYieldsAndTriggers dialog = new VAutoYieldsAndTriggers() { |
| 51 | @Override |
| 52 | public void setVisible(boolean b0) { |
| 53 | super.setVisible(b0); |
| 54 | if (!b0) { |
| 55 | if (autoYieldsDisabled && !MatchController.instance.getGameController().getYieldController().getDisableAutoYields()) { |
| 56 | //if re-enabling auto-yields, auto-yield to current ability on stack if applicable |
| 57 | if (MatchController.instance.getGameView().peekStack() != null) { |
| 58 | final String key = MatchController.instance.getGameView().peekStack().getKey(); |
| 59 | final boolean autoYield = MatchController.instance.getGameController().shouldAutoYield(key); |
| 60 | boolean abilityScope = MatchController.instance.getGameController().getYieldController().isAbilityScope(); |
| 61 | MatchController.instance.getGameController().setShouldAutoYield(key, !autoYield, abilityScope); |
| 62 | if (!autoYield && MatchController.instance.getGameController().shouldAutoYield(key)) { |
| 63 | //auto-pass priority if ability is on top of stack |
| 64 | MatchController.instance.getGameController().passPriority(); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | }; |
| 71 | dialog.show(); |
| 72 | } |
| 73 | })); |
| 74 | addItem(new FMenuItem(Forge.getLocalizer().getMessage("lblYieldSettings"), Forge.hdbuttons ? FSkinImage.HDYIELD : FSkinImage.WARNING, e -> { |
| 75 | new VYieldOptions().show(); |
nothing calls this directly
no outgoing calls
no test coverage detected