Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
艦隊晒しページ(仮)に対応
Browse files Browse the repository at this point in the history
  • Loading branch information
sanaehirotaka committed Jul 31, 2018
1 parent 86b460d commit cf1baad
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 1 deletion.
133 changes: 133 additions & 0 deletions src/main/java/logbook/internal/gui/ShipTablePane.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -54,13 +60,16 @@
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;
import logbook.internal.LoggerHolder;
import logbook.internal.Operator;
import logbook.internal.ShipFilter;
import logbook.internal.Ships;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.val;

/**
Expand Down Expand Up @@ -759,6 +768,22 @@ void removeLabel() {
}
}

/**
* 艦隊晒しページ(仮).全員をクリップボードにコピー
*/
@FXML
void kanmusuListCopyAll() {
KanmusuList.copyAll();
}

/**
* 艦隊晒しページ(仮).選択した艦のみクリップボードにコピー
*/
@FXML
void kanmusuListSelectionCopy() {
KanmusuList.selectionCopy(this.table);
}

/**
* テーブル列の表示・非表示の設定
*/
Expand Down Expand Up @@ -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<ShipItem> 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<Ship> ships) {
// 艦船マスタID => 艦隊晒しページ(仮)のID
Map<Integer, Kanmusu> map = new LinkedHashMap<>();
// 艦船マスタ
Map<Integer, ShipMst> shipMstMap = ShipMstCollection.get().getShipMap();

// 改装に関連する艦をグルーピングする
Map<Integer, Set<Integer>> groupMap = new LinkedHashMap<>();
for (ShipMst shipMst : shipMstMap.values()) {
Integer id = shipMst.getId();
Integer afterid = shipMst.getAftershipid();
if (afterid == null) {
continue;
}

Set<Integer> 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<Set<Integer>> link = new HashSet<>(groupMap.values());
for (Set<Integer> list : link) {
List<Integer> 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;
}
}

}
10 changes: 9 additions & 1 deletion src/main/resources/logbook/gui/ship_table.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.ContextMenu?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.SeparatorMenuItem?>
<?import javafx.scene.control.TableColumn?>
Expand All @@ -14,7 +15,7 @@
<?import javafx.scene.text.TextFlow?>
<?import org.controlsfx.control.ToggleSwitch?>

<fx:root prefHeight="600.0" prefWidth="800.0" type="VBox" xmlns="http://javafx.com/javafx/8.0.161" xmlns:fx="http://javafx.com/fxml/1">
<fx:root prefHeight="600.0" prefWidth="800.0" type="VBox" xmlns="http://javafx.com/javafx/8.0.162" xmlns:fx="http://javafx.com/fxml/1">
<children>
<VBox>
<children>
Expand Down Expand Up @@ -143,6 +144,13 @@
<MenuItem mnemonicParsing="false" onAction="#selectAll" text="すべてを選択" />
<MenuItem mnemonicParsing="false" onAction="#store" text="CSVファイルとして保存" />
<SeparatorMenuItem mnemonicParsing="false" />
<Menu mnemonicParsing="false" text="艦隊晒しページ(仮)">
<items>
<MenuItem mnemonicParsing="false" onAction="#kanmusuListCopyAll" text="全員をクリップボードにコピー" />
<MenuItem mnemonicParsing="false" onAction="#kanmusuListSelectionCopy" text="選択した艦のみクリップボードにコピー" />
</items>
</Menu>
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" onAction="#columnVisible" text="列の表示・非表示" />
</items>
</ContextMenu>
Expand Down

0 comments on commit cf1baad

Please sign in to comment.