Skip to content
This repository has been archived by the owner on Oct 1, 2022. It is now read-only.

Only select wounded in selection #746

Merged
merged 9 commits into from
Jan 19, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class GOSwingEventConverter extends AbstractEventConverter
public GOSwingEventConverter(Component component, GOEventHandlerProvider provider) {
super(provider);

component.setFocusTraversalKeysEnabled(false);

component.addKeyListener(this);
component.addMouseListener(this);
component.addMouseMotionListener(this);
Expand Down Expand Up @@ -252,6 +254,9 @@ private String getKeyName(KeyEvent e) {
case KeyEvent.VK_BACK_SPACE:
text = "BACK_SPACE";
break;
case KeyEvent.VK_TAB:
text = "TAB";
break;
default:
text = "" + e.getKeyChar();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public enum EActionType {
*/
SELECT_POINT_TYPE,

/**
* Select only the wounded of the current selection.
*/
FILTER_WOUNDED,

/**
* Skip the next minute of gameplay.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@
import go.graphics.sound.SoundPlayer;
import go.graphics.text.EFontSize;
import go.graphics.text.TextDrawer;

import jsettlers.common.Color;
import jsettlers.common.CommitInfo;
import jsettlers.common.CommonConstants;
import jsettlers.common.action.Action;
import jsettlers.common.action.EActionType;
import jsettlers.common.action.IAction;
import jsettlers.common.action.PointAction;
import jsettlers.common.action.ScreenChangeAction;
import jsettlers.common.action.SelectAreaAction;
import jsettlers.common.action.ShowConstructionMarksAction;
import jsettlers.common.buildings.EBuildingType;
import jsettlers.common.buildings.IBuilding;
import jsettlers.common.images.AnimationSequence;
Expand All @@ -48,22 +56,15 @@
import jsettlers.common.menu.IMapInterfaceListener;
import jsettlers.common.menu.IStartedGame;
import jsettlers.common.menu.UIState;
import jsettlers.common.action.EActionType;
import jsettlers.common.action.IAction;
import jsettlers.common.menu.messages.IMessage;
import jsettlers.common.movable.IMovable;
import jsettlers.common.position.FloatRectangle;
import jsettlers.common.position.ShortPoint2D;
import jsettlers.common.selectable.ISelectionSet;
import jsettlers.common.statistics.IGameTimeProvider;
import jsettlers.common.action.Action;
import jsettlers.graphics.action.ActionFireable;
import jsettlers.graphics.action.ActionHandler;
import jsettlers.graphics.action.ActionThreadBlockingListener;
import jsettlers.common.action.PointAction;
import jsettlers.common.action.ScreenChangeAction;
import jsettlers.common.action.SelectAreaAction;
import jsettlers.common.action.ShowConstructionMarksAction;
import jsettlers.graphics.font.FontDrawerFactory;
import jsettlers.graphics.localization.Labels;
import jsettlers.graphics.map.controls.IControls;
Expand Down Expand Up @@ -707,6 +708,8 @@ private static Action getActionForKeyboard(String keyCode) {
return new Action(EActionType.ZOOM_OUT);
} else if ("F2".equalsIgnoreCase(keyCode)) {
return new Action(EActionType.SAVE);
} else if ("TAB".equalsIgnoreCase(keyCode)) {
return new Action(EActionType.FILTER_WOUNDED);
} else if ("DELETE".equalsIgnoreCase(keyCode)) {
return new Action(EActionType.DESTROY);
} else if ("ESCAPE".equalsIgnoreCase(keyCode)) {
Expand Down
28 changes: 24 additions & 4 deletions jsettlers.logic/src/main/java/jsettlers/input/GuiInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
import java.util.Timer;
import java.util.TimerTask;

import java8.util.Optional;
import java8.util.function.BiFunction;
import java8.util.function.Predicate;
import jsettlers.algorithms.construction.ConstructionMarksThread;
import jsettlers.common.action.BuildAction;
import jsettlers.common.action.ChangeTradingRequestAction;
Expand Down Expand Up @@ -85,11 +82,16 @@
import jsettlers.logic.buildings.military.occupying.OccupyingBuilding;
import jsettlers.logic.buildings.workers.DockyardBuilding;
import jsettlers.logic.constants.MatchConstants;
import jsettlers.logic.movable.Movable;
import jsettlers.logic.movable.interfaces.IDebugable;
import jsettlers.logic.player.Player;
import jsettlers.network.client.interfaces.IGameClock;
import jsettlers.network.client.interfaces.ITaskScheduler;

import java8.util.Optional;
import java8.util.function.BiFunction;
import java8.util.function.Predicate;

/**
* Class to handle the events provided by the user through jsettlers.graphics.
*
Expand Down Expand Up @@ -212,6 +214,10 @@ public void action(IAction action) {
handleSelectPointAction((PointAction) action);
break;

case FILTER_WOUNDED:
filterWounded();
break;

case SELECT_AREA:
selectArea((SelectAreaAction) action);
break;
Expand Down Expand Up @@ -608,6 +614,21 @@ private boolean canSelectPlayer(byte playerIdOfSelected) {
return MatchConstants.ENABLE_ALL_PLAYER_SELECTION || playerIdOfSelected == playerId;
}

private void filterWounded() {
if(currentSelection.getSelectionType() != ESelectionType.SOLDIERS && currentSelection.getSelectionType() != ESelectionType.PEOPLE && currentSelection.getSelectionType() != ESelectionType.SPECIALISTS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new Property to ESelectionType. Then use

if (currentSelection.getSelectionType().allowsFilterForWounded()) { ... }

return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always use the curly brackets for ifs, even if they have only one line.


final List<ISelectable> selected = new LinkedList<>();

for(ISelectable selectable : currentSelection) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use currentSelection.stream().filter(<condition>).collect(Collectors.toList()) instead of the loop.

Movable movable = (Movable)selectable;
if(movable.getHealth() < movable.getMovableType().health)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new Method to ISelectable. Then use:

if (selectable.isWounded()) { ... }

Buildings always return false.

Then you can skip the test at the beginning of the method as well, since all selectables support the same interface.

selected.add(movable);
}

setSelection(new SelectionSet(selected));
}

private void deselect() {
setSelection(new SelectionSet());
}
Expand All @@ -625,7 +646,6 @@ private void handleSelectPointAction(PointAction action) {
} else {
setSelection(new SelectionSet());
}

}

private void scheduleTask(SimpleGuiTask guiTask) {
Expand Down