HAnd Range selection implementiert und getestet und funktioniert
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@197 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
223f6d7e85
commit
c5374de06f
1 changed files with 73 additions and 2 deletions
|
@ -2,6 +2,7 @@ package jrummikub.control;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -16,9 +17,32 @@ import jrummikub.util.IEvent;
|
||||||
import jrummikub.util.IListener;
|
import jrummikub.util.IListener;
|
||||||
import jrummikub.util.IListener1;
|
import jrummikub.util.IListener1;
|
||||||
import jrummikub.util.IListener2;
|
import jrummikub.util.IListener2;
|
||||||
|
import jrummikub.util.Pair;
|
||||||
import jrummikub.view.IView;
|
import jrummikub.view.IView;
|
||||||
|
|
||||||
public class TurnControl {
|
public class TurnControl {
|
||||||
|
private static class HandStoneComparator implements
|
||||||
|
Comparator<Pair<Stone, Position>> {
|
||||||
|
@Override
|
||||||
|
public int compare(Pair<Stone, Position> pair1,
|
||||||
|
Pair<Stone, Position> pair2) {
|
||||||
|
Position pos1 = pair1.getSecond(), pos2 = pair2.getSecond();
|
||||||
|
if (pos1.getY() < pos2.getY()) {
|
||||||
|
return -1;
|
||||||
|
} else if (pos1.getY() > pos2.getY()) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
if (pos1.getX() < pos2.getX()) {
|
||||||
|
return -1;
|
||||||
|
} else if (pos1.getX() > pos2.getX()) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private IHand hand;
|
private IHand hand;
|
||||||
private ITable table;
|
private ITable table;
|
||||||
private ITurnTimer timer;
|
private ITurnTimer timer;
|
||||||
|
@ -66,6 +90,15 @@ public class TurnControl {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
connections.add(view.getPlayerPanel().getHandPanel()
|
||||||
|
.getRangeClickEvent().add(new IListener2<Stone, Boolean>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(Stone stone, Boolean collect) {
|
||||||
|
handRangeClick(stone, collect);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
connections.add(view.getTablePanel().getStoneCollectionPanel()
|
connections.add(view.getTablePanel().getStoneCollectionPanel()
|
||||||
.getStoneClickEvent().add(new IListener2<Stone, Boolean>() {
|
.getStoneClickEvent().add(new IListener2<Stone, Boolean>() {
|
||||||
|
|
||||||
|
@ -210,7 +243,7 @@ public class TurnControl {
|
||||||
stoneClick(stone, collect);
|
stoneClick(stone, collect);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Stone lastStone = selectedStones.get(selectedStones.size()-1);
|
Stone lastStone = selectedStones.get(selectedStones.size() - 1);
|
||||||
StoneSet lastSet = table.findStoneSet(lastStone);
|
StoneSet lastSet = table.findStoneSet(lastStone);
|
||||||
StoneSet selectedSet = table.findStoneSet(stone);
|
StoneSet selectedSet = table.findStoneSet(stone);
|
||||||
if (lastSet != selectedSet) {
|
if (lastSet != selectedSet) {
|
||||||
|
@ -237,6 +270,44 @@ public class TurnControl {
|
||||||
view.setSelectedStones(selectedStones);
|
view.setSelectedStones(selectedStones);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handRangeClick(Stone stone, Boolean collect) {
|
||||||
|
if (selectedStones.isEmpty()) {
|
||||||
|
stoneClick(stone, collect);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Stone lastStone = selectedStones.get(selectedStones.size() - 1);
|
||||||
|
StoneSet lastSet = table.findStoneSet(lastStone);
|
||||||
|
if (lastSet != null) {
|
||||||
|
stoneClick(stone, collect);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<Pair<Stone, Position>> handPairs = new ArrayList<Pair<Stone, Position>>();
|
||||||
|
for (Pair<Stone, Position> entry : hand) {
|
||||||
|
handPairs.add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(handPairs, new HandStoneComparator());
|
||||||
|
|
||||||
|
List<Stone> handStones = new ArrayList<Stone>();
|
||||||
|
for (Pair<Stone, Position> entry : handPairs) {
|
||||||
|
handStones.add(entry.getFirst());
|
||||||
|
}
|
||||||
|
|
||||||
|
int firstIndex = handStones.indexOf(lastStone);
|
||||||
|
int lastIndex = handStones.indexOf(stone);
|
||||||
|
if (firstIndex > lastIndex) {
|
||||||
|
int temp = firstIndex;
|
||||||
|
firstIndex = lastIndex;
|
||||||
|
lastIndex = temp;
|
||||||
|
}
|
||||||
|
for (int i = firstIndex; i <= lastIndex; i++) {
|
||||||
|
Stone s = handStones.get(i);
|
||||||
|
selectedStones.remove(s);
|
||||||
|
selectedStones.add(s);
|
||||||
|
}
|
||||||
|
view.setSelectedStones(selectedStones);
|
||||||
|
}
|
||||||
|
|
||||||
private void connectorClick(StoneSet set, boolean right) {
|
private void connectorClick(StoneSet set, boolean right) {
|
||||||
List<Stone> stones = new LinkedList<Stone>();
|
List<Stone> stones = new LinkedList<Stone>();
|
||||||
Position pos = table.getPosition(set);
|
Position pos = table.getPosition(set);
|
||||||
|
|
Reference in a new issue