From cf1baad9b47487d5c2f8ad6ce1c00e04acc4145a Mon Sep 17 00:00:00 2001 From: sanaehirotaka Date: Tue, 31 Jul 2018 23:38:08 +0900 Subject: [PATCH] =?UTF-8?q?=E8=89=A6=E9=9A=8A=E6=99=92=E3=81=97=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=82=B8=EF=BC=88=E4=BB=AE=EF=BC=89=E3=81=AB=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logbook/internal/gui/ShipTablePane.java | 133 ++++++++++++++++++ .../resources/logbook/gui/ship_table.fxml | 10 +- 2 files changed, 142 insertions(+), 1 deletion(-) diff --git a/src/main/java/logbook/internal/gui/ShipTablePane.java b/src/main/java/logbook/internal/gui/ShipTablePane.java index 8316aaae..09e8aa69 100644 --- a/src/main/java/logbook/internal/gui/ShipTablePane.java +++ b/src/main/java/logbook/internal/gui/ShipTablePane.java @@ -1,9 +1,13 @@ package logbook.internal.gui; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -42,6 +46,8 @@ import javafx.scene.control.TitledPane; import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.image.ImageView; +import javafx.scene.input.Clipboard; +import javafx.scene.input.ClipboardContent; import javafx.scene.layout.FlowPane; import javafx.scene.layout.VBox; import javafx.stage.Stage; @@ -54,6 +60,7 @@ import logbook.bean.ShipCollection; import logbook.bean.ShipLabelCollection; import logbook.bean.ShipMst; +import logbook.bean.ShipMstCollection; import logbook.bean.SlotItem; import logbook.bean.SlotItemCollection; import logbook.internal.Items; @@ -61,6 +68,8 @@ import logbook.internal.Operator; import logbook.internal.ShipFilter; import logbook.internal.Ships; +import lombok.AllArgsConstructor; +import lombok.Data; import lombok.val; /** @@ -759,6 +768,22 @@ void removeLabel() { } } + /** + * 艦隊晒しページ(仮).全員をクリップボードにコピー + */ + @FXML + void kanmusuListCopyAll() { + KanmusuList.copyAll(); + } + + /** + * 艦隊晒しページ(仮).選択した艦のみクリップボードにコピー + */ + @FXML + void kanmusuListSelectionCopy() { + KanmusuList.selectionCopy(this.table); + } + /** * テーブル列の表示・非表示の設定 */ @@ -1126,4 +1151,112 @@ private String colorCode(int seed) { return "#" + ("000000" + hex).substring(hex.length()); } } + + /** + * 艦隊晒しページ(仮) + */ + public static class KanmusuList { + + /** + * すべての艦をクリップボードにコピーする。 + */ + public static void copyAll() { + ClipboardContent content = new ClipboardContent(); + content.putString(text(ShipCollection.get() + .getShipMap() + .values())); + Clipboard.getSystemClipboard().setContent(content); + } + + /** + * 選択された艦のみをクリップボードにコピーする。 + * + * @param table テーブル + */ + public static void selectionCopy(TableView table) { + ClipboardContent content = new ClipboardContent(); + content.putString(text(table.getSelectionModel() + .getSelectedItems() + .stream() + .map(ShipItem::getShip) + .collect(Collectors.toList()))); + Clipboard.getSystemClipboard().setContent(content); + } + + private static String text(Collection ships) { + // 艦船マスタID => 艦隊晒しページ(仮)のID + Map map = new LinkedHashMap<>(); + // 艦船マスタ + Map shipMstMap = ShipMstCollection.get().getShipMap(); + + // 改装に関連する艦をグルーピングする + Map> groupMap = new LinkedHashMap<>(); + for (ShipMst shipMst : shipMstMap.values()) { + Integer id = shipMst.getId(); + Integer afterid = shipMst.getAftershipid(); + if (afterid == null) { + continue; + } + + Set list = new HashSet<>(); + list.addAll(groupMap.computeIfAbsent(id, HashSet::new)); + list.add(id); + if (afterid != 0) { + list.addAll(groupMap.computeIfAbsent(afterid, HashSet::new)); + list.add(afterid); + } + for (Integer linkid : list) { + groupMap.put(linkid, list); + } + } + // グループごとのループ + Set> link = new HashSet<>(groupMap.values()); + for (Set list : link) { + List sorted = new ArrayList<>(); + // グループの中で改装レベルが最も小さい艦を選択 + ShipMst mst = list.stream() + .map(shipMstMap::get) + .filter(m -> m.getAftershipid() != 0) + .sorted(Comparator.comparing(ShipMst::getAfterlv)) + .findFirst() + .get(); + // 選択した艦を親にしてaftershipidを順に辿っていく + while (true) { + if (mst == null) + break; + sorted.add(mst.getId()); + if (sorted.contains(mst.getAftershipid())) + break; + mst = shipMstMap.get(mst.getAftershipid()); + } + for (int i = 0; i < sorted.size(); i++) { + map.put(sorted.get(i), new Kanmusu(sorted.get(0), i + 1)); + } + } + return ".2|" + ships.stream() + .filter(s -> map.containsKey(s.getShipId())) + .map(s -> new Value(map.get(s.getShipId()), s.getLv())) + .sorted(Comparator.comparing(v -> v.ship.id)) + .collect(Collectors.groupingBy(v -> v.ship.id, LinkedHashMap::new, Collectors.toList())) + .entrySet().stream() + .map(e -> e.getKey() + ":" + + e.getValue().stream().map(v -> v.lv + "." + v.ship.kai).collect(Collectors.joining(","))) + .collect(Collectors.joining("|")); + } + + @Data + @AllArgsConstructor + private static class Kanmusu { + private int id; + private int kai; + } + + @Data + @AllArgsConstructor + private static class Value { + private Kanmusu ship; + private int lv; + } + } + } diff --git a/src/main/resources/logbook/gui/ship_table.fxml b/src/main/resources/logbook/gui/ship_table.fxml index fadd2236..ab5dbf48 100644 --- a/src/main/resources/logbook/gui/ship_table.fxml +++ b/src/main/resources/logbook/gui/ship_table.fxml @@ -3,6 +3,7 @@ + @@ -14,7 +15,7 @@ - + @@ -143,6 +144,13 @@ + + + + + + +