Archived
0

add faction and government fields

This commit is contained in:
Mo
2015-09-27 14:56:00 +03:00
parent bcd7ebbd04
commit fb98d8860a
34 changed files with 621 additions and 44 deletions

View File

@@ -17,6 +17,8 @@ import ru.trader.model.StationModel;
import ru.trader.model.SystemModel;
import ru.trader.model.support.BindingsHelper;
import ru.trader.model.support.ChangeMarketListener;
import ru.trader.view.support.FactionStringConverter;
import ru.trader.view.support.GovernmentStringConverter;
import ru.trader.view.support.ViewUtils;
import java.util.List;
@@ -39,6 +41,10 @@ public class OffersController {
@FXML
private TableView<OfferModel> tblBuy;
@FXML
private Label faction;
@FXML
private Label government;
@FXML
private Label distance;
@FXML
private CheckBox cbMarket;
@@ -137,6 +143,8 @@ public class OffersController {
sells.clear();
buys.clear();
distance.setText("");
government.setText("");
faction.setText("");
cbMarket.setSelected(false);
cbBlackMarket.setSelected(false);
cbMunition.setSelected(false);
@@ -146,6 +154,8 @@ public class OffersController {
cbMediumLandpad.setSelected(false);
cbLargeLandpad.setSelected(false);
if (station != null){
faction.setText(FactionStringConverter.toLocalizationString(station.getFaction()));
government.setText(GovernmentStringConverter.toLocalizationString(station.getGovernment()));
distance.setText(String.valueOf(station.getDistance()));
cbMarket.setSelected(station.hasService(SERVICE_TYPE.MARKET));
cbBlackMarket.setSelected(station.hasService(SERVICE_TYPE.BLACK_MARKET));

View File

@@ -1,5 +1,6 @@
package ru.trader.controllers;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.Parent;
import javafx.scene.control.*;
@@ -7,15 +8,14 @@ import javafx.util.converter.LongStringConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.trader.EMDNUpdater;
import ru.trader.core.FACTION;
import ru.trader.core.GOVERNMENT;
import ru.trader.core.SERVICE_TYPE;
import ru.trader.model.ItemModel;
import ru.trader.model.StationModel;
import ru.trader.model.SystemModel;
import ru.trader.model.support.StationUpdater;
import ru.trader.view.support.Localization;
import ru.trader.view.support.NumberField;
import ru.trader.view.support.PriceStringConverter;
import ru.trader.view.support.ViewUtils;
import ru.trader.view.support.*;
import ru.trader.view.support.cells.EditOfferCell;
import ru.trader.view.support.cells.TextFieldCell;
@@ -28,6 +28,12 @@ public class StationEditorController {
@FXML
private TextField name;
@FXML
private ComboBox<FACTION> faction;
@FXML
private ComboBox<GOVERNMENT> government;
@FXML
private TableView<StationUpdater.FakeOffer> items;
@FXML
@@ -64,6 +70,10 @@ public class StationEditorController {
@FXML
private void initialize() {
faction.setItems(FXCollections.observableArrayList(FACTION.values()));
faction.setConverter(new FactionStringConverter());
government.setItems(FXCollections.observableArrayList(GOVERNMENT.values()));
government.setConverter(new GovernmentStringConverter());
items.getSelectionModel().setCellSelectionEnabled(true);
buy.setCellFactory(EditOfferCell.forTable(new PriceStringConverter(), false));
sell.setCellFactory(EditOfferCell.forTable(new PriceStringConverter(), true));
@@ -80,10 +90,14 @@ public class StationEditorController {
void init(){
if (updater != null){
name.textProperty().unbindBidirectional(updater.nameProperty());
faction.valueProperty().unbindBidirectional(updater.factionProperty());
government.valueProperty().unbindBidirectional(updater.governmentProperty());
distance.numberProperty().unbindBidirectional(updater.distanceProperty());
}
updater = new StationUpdater(MainController.getMarket());
name.textProperty().bindBidirectional(updater.nameProperty());
faction.valueProperty().bindBidirectional(updater.factionProperty());
government.valueProperty().bindBidirectional(updater.governmentProperty());
distance.numberProperty().bindBidirectional(updater.distanceProperty());
cbMarket.selectedProperty().bindBidirectional(updater.serviceProperty(SERVICE_TYPE.MARKET));
cbBlackMarket.selectedProperty().bindBidirectional(updater.serviceProperty(SERVICE_TYPE.BLACK_MARKET));

View File

@@ -4,7 +4,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.trader.core.*;
import java.util.*;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
public class StationModel {
@@ -42,6 +43,24 @@ public class StationModel {
station.setName(value);
}
public FACTION getFaction() {return station.getFaction();}
public void setFaction(FACTION faction) {
FACTION oldFaction = getFaction();
if (oldFaction != null && oldFaction.equals(faction) || faction == null) return;
LOG.info("Change faction station {} to {}", station, faction);
station.setFaction(faction);
}
public GOVERNMENT getGovernment() {return station.getGovernment();}
public void setGovernment(GOVERNMENT government) {
GOVERNMENT oldGovernment = getGovernment();
if (oldGovernment != null && oldGovernment.equals(government) || government == null) return;
LOG.info("Change government station {} to {}", station, government);
station.setGovernment(government);
}
public double getDistance(){
return station.getDistance();
}

View File

@@ -1,13 +1,13 @@
package ru.trader.model;
import javafx.beans.property.*;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.trader.core.Place;
import ru.trader.core.SERVICE_TYPE;
import ru.trader.core.Vendor;
import ru.trader.core.*;
import java.util.List;
import java.util.stream.Collectors;
@@ -52,6 +52,24 @@ public class SystemModel {
return name;
}
public FACTION getFaction() {return system.getFaction();}
public void setFaction(FACTION faction) {
FACTION oldFaction = getFaction();
if (oldFaction != null && oldFaction.equals(faction) || faction == null) return;
LOG.info("Change faction station {} to {}", system, faction);
system.setFaction(faction);
}
public GOVERNMENT getGovernment() {return system.getGovernment();}
public void setGovernment(GOVERNMENT government) {
GOVERNMENT oldGovernment = getGovernment();
if (oldGovernment != null && oldGovernment.equals(government) || government == null) return;
LOG.info("Change government station {} to {}", system, government);
system.setGovernment(government);
}
public double getX(){
return system.getX();
}

View File

@@ -5,6 +5,8 @@ import javafx.collections.ObservableList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.trader.controllers.MainController;
import ru.trader.core.FACTION;
import ru.trader.core.GOVERNMENT;
import ru.trader.core.OFFER_TYPE;
import ru.trader.core.SERVICE_TYPE;
import ru.trader.model.*;
@@ -17,6 +19,8 @@ public class StationUpdater {
private final static SERVICE_TYPE[] SERVICE_TYPES = SERVICE_TYPE.values();
private final ObservableList<FakeOffer> offers;
private final StringProperty name;
private final ObjectProperty<FACTION> faction;
private final ObjectProperty<GOVERNMENT> government;
private final DoubleProperty distance;
private final BooleanProperty[] services;
private final MarketModel market;
@@ -30,6 +34,8 @@ public class StationUpdater {
this.offers = BindingsHelper.observableList(MainController.getMarket().itemsProperty(), FakeOffer::new);
this.name = new SimpleStringProperty();
this.distance = new SimpleDoubleProperty(0);
this.faction = new SimpleObjectProperty<>(FACTION.NONE);
this.government = new SimpleObjectProperty<>(GOVERNMENT.NONE);
this.services = new BooleanProperty[SERVICE_TYPES.length];
for (int i = 0; i < services.length; i++) {
services[i] = new SimpleBooleanProperty();
@@ -54,6 +60,8 @@ public class StationUpdater {
}
if (station != null){
name.setValue(station.getName());
faction.setValue(station.getFaction());
government.setValue(station.getGovernment());
distance.setValue(station.getDistance());
for (SERVICE_TYPE service : station.getServices()) {
serviceProperty(service).set(true);
@@ -62,6 +70,8 @@ public class StationUpdater {
station.getBuys().forEach(this::fillOffer);
} else {
name.setValue("");
faction.setValue(FACTION.NONE);
government.setValue(GOVERNMENT.NONE);
distance.setValue(0);
}
}
@@ -106,6 +116,30 @@ public class StationUpdater {
this.name.set(name);
}
public FACTION getFaction() {
return faction.get();
}
public ObjectProperty<FACTION> factionProperty() {
return faction;
}
public void setFaction(FACTION faction) {
this.faction.set(faction);
}
public GOVERNMENT getGovernment() {
return government.get();
}
public ObjectProperty<GOVERNMENT> governmentProperty() {
return government;
}
public void setGovernment(GOVERNMENT government) {
this.government.set(government);
}
public double getDistance() {
return distance.get();
}
@@ -132,6 +166,8 @@ public class StationUpdater {
Notificator notificator = market.getNotificator();
notificator.setAlert(false);
station = system.add(name.get());
station.setFaction(faction.get());
station.setGovernment(government.get());
station.setDistance(distance.get());
for (int i = 0; i < services.length; i++) {
if (services[i].get()){
@@ -143,6 +179,8 @@ public class StationUpdater {
notificator.sendAdd(station);
} else {
station.setName(name.get());
station.setFaction(faction.get());
station.setGovernment(government.get());
station.setDistance(distance.get());
for (int i = 0; i < services.length; i++) {
if (services[i].get()){

View File

@@ -0,0 +1,24 @@
package ru.trader.view.support;
import javafx.util.StringConverter;
import ru.trader.core.FACTION;
public class FactionStringConverter extends StringConverter<FACTION> {
@Override
public String toString(FACTION faction) {
return toLocalizationString(faction);
}
@Override
public FACTION fromString(String faction) {
return FACTION.valueOf(faction);
}
public static String toLocalizationString(FACTION faction){
if (faction == null) return null;
return Localization.getString("faction." + faction.toString(), faction.toString());
}
}

View File

@@ -0,0 +1,24 @@
package ru.trader.view.support;
import javafx.util.StringConverter;
import ru.trader.core.GOVERNMENT;
public class GovernmentStringConverter extends StringConverter<GOVERNMENT> {
@Override
public String toString(GOVERNMENT government) {
return toLocalizationString(government);
}
@Override
public GOVERNMENT fromString(String government) {
return GOVERNMENT.valueOf(government);
}
public static String toLocalizationString(GOVERNMENT government){
if (government == null) return null;
return Localization.getString("government." + government.toString(), government.toString());
}
}

View File

@@ -1,3 +1,24 @@
faction.FEDERATION=Federation
faction.EMPIRE=Empire
faction.ALLIANCE=Alliance
faction.INDEPENDENT=Independent
faction.NONE=None
government.ANARCHY=Anarchy
government.COLONY=Colony
government.COMMUNISM=Communism
government.CONFEDERACY=Confederacy
government.COOPERATIVE=Cooperative
government.CORPORATE=Corporate
government.DEMOCRACY=Democracy
government.DICTATORSHIP=Dictatorship
government.FEUDAL=Feudal
government.IMPERIAL=Imperial
government.PATRONAGE=Patronage
government.PRISON_COLONY=Prison colony
government.THEOCRACY=Theocracy
government.NONE=None
services.MARKET=Commodities
services.BLACK_MARKET=Black Market
services.REPAIR=Repair
@@ -6,6 +27,7 @@ services.OUTFIT=Outfit
services.SHIPYARD=Shipyard
services.MEDIUM_LANDPAD=Medium Pad
services.LARGE_LANDPAD=Large Pad
item.group.chemicals=Chemicals
item.explosives=Explosives
item.hydrogenfuel=Hydrogen Fuel

View File

@@ -8,6 +8,8 @@ market.offers=Offers
market.item.name=Commodity
market.system.name=System
market.station.name=Station
market.allegiance=Allegiance
market.government=Government
# Offer
market.offer.buy=Buy

View File

@@ -8,6 +8,8 @@ market.offers=\u0417\u0430\u043A\u0430\u0437\u044B
market.item.name=\u0422\u043E\u0432\u0430\u0440
market.system.name=\u0421\u0438\u0441\u0442\u0435\u043C\u0430
market.station.name=\u0421\u0442\u0430\u043D\u0446\u0438\u044F
market.allegiance=\u041F\u0440\u0438\u043D\u0430\u0434\u043B\u0435\u0436\u043D\u043E\u0441\u0442\u044C
market.government=\u0424\u043E\u0440\u043C\u0430 \u043F\u0440\u0430\u0432\u043B\u0435\u043D\u0438\u044F
# Offer
market.offer.buy=\u041F\u043E\u043A\u0443\u043F\u043A\u0430

View File

@@ -1,5 +1,26 @@
main.menu.settings.language.item=\u0420\u0443\u0441\u0441\u043A\u0438\u0439
faction.FEDERATION=\u0424\u0435\u0434\u0435\u0440\u0430\u0446\u0438\u044F
faction.EMPIRE=\u0418\u043C\u043F\u0435\u0440\u0438\u044F
faction.ALLIANCE=\u0410\u043B\u044C\u044F\u043D\u0441
faction.INDEPENDENT=\u041D\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043C\u044B\u0435
faction.NONE=\u041D\u0435\u0442
government.ANARCHY=\u0410\u043D\u0430\u0440\u0445\u0438\u044F
government.COLONY=\u041A\u043E\u043B\u043E\u043D\u0438\u044F
government.COMMUNISM=\u041A\u043E\u043C\u043C\u0443\u043D\u0438\u0437\u043C
government.CONFEDERACY=\u041A\u043E\u043D\u0444\u0435\u0434\u0435\u0440\u0430\u0446\u0438\u044F
government.COOPERATIVE=\u041A\u043E\u043E\u043F\u0435\u0440\u0430\u0446\u0438\u044F
government.CORPORATE=\u041A\u043E\u0440\u043F\u043E\u0440\u0430\u0442\u0438\u0432\u043D\u0430\u044F
government.DEMOCRACY=\u0414\u0435\u043C\u043E\u043A\u0440\u0430\u0442\u0438\u044F
government.DICTATORSHIP=\u0414\u0438\u043A\u0442\u0430\u0442\u0443\u0440\u0430
government.FEUDAL=\u0424\u0435\u043E\u0434\u0430\u043B\u044C\u043D\u0430\u044F
government.IMPERIAL=\u0418\u043C\u043F\u0435\u0440\u0441\u043A\u0430\u044F
government.PATRONAGE=\u041F\u043E\u043F\u0435\u0447\u0438\u0442\u0435\u043B\u044C\u0441\u0442\u0432\u043E
government.PRISON_COLONY=\u0422\u044E\u0440\u0435\u043C\u043D\u0430\u044F \u043A\u043E\u043B\u043E\u043D\u0438\u044F
government.THEOCRACY=\u0422\u0435\u043E\u043A\u0440\u0430\u0442\u0438\u044F
government.NONE=\u041D\u0435\u0442
services.MARKET=\u0420\u044B\u043D\u043E\u043A
services.BLACK_MARKET=\u0427\u0435\u0440\u043D\u044B\u0439 \u0440\u044B\u043D\u043E\u043A
services.REPAIR=\u0420\u0435\u043C\u043E\u043D\u0442

View File

@@ -1,16 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.cell.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.cell.PropertyValueFactory?>
<?import ru.trader.view.support.cells.PriceCellImpl?>
<?import ru.trader.view.support.cells.OfferCellValueImpl?>
<?import ru.trader.view.support.cells.DoubleCell?>
<?import org.controlsfx.glyphfont.Glyph?>
<?import org.controlsfx.control.SegmentedButton?>
<?import ru.trader.view.support.cells.*?>
<GridPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="ru.trader.controllers.OffersController">
@@ -39,9 +34,16 @@
<SegmentedButton fx:id="stationsBar" />
</TitledPane>
<TitledPane GridPane.rowIndex="1" GridPane.columnIndex="1" text="" maxHeight="60" collapsible="false">
<HBox spacing="4">
<Label text="%offers.text.distance"/>
<Label fx:id="distance" minWidth="60"/>
<VBox>
<HBox spacing="4">
<Label text="%offers.text.distance"/>
<Label fx:id="distance" minWidth="60"/>
<Label text="%market.allegiance"/>
<Label fx:id="faction" minWidth="60"/>
<Label text="%market.government"/>
<Label fx:id="government" minWidth="60"/>
</HBox>
<HBox spacing="4">
<Label text="%offers.text.services"/>
<HBox spacing="15">
<CheckBox fx:id="cbMarket" text="%services.MARKET"/>
@@ -54,6 +56,7 @@
<CheckBox fx:id="cbLargeLandpad" text="%services.LARGE_LANDPAD"/>
</HBox>
</HBox>
</VBox>
</TitledPane>
<Accordion GridPane.rowIndex="2" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS" GridPane.vgrow="ALWAYS">

View File

@@ -1,20 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.cell.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.cell.PropertyValueFactory?>
<?import org.controlsfx.glyphfont.Glyph?>
<?import ru.trader.view.support.NumberField?>
<?import javafx.geometry.Insets?>
<GridPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8"
fx:controller="ru.trader.controllers.StationEditorController" styleClass="dialog"
vgap="10" hgap="4">
<fx:define><Insets fx:id="hbox_margin" left="10" /></fx:define>
<TextField fx:id="name" GridPane.columnSpan="2" alignment="CENTER" />
<HBox GridPane.rowIndex="1" GridPane.columnIndex="1" spacing="4">
<HBox GridPane.rowIndex="1" GridPane.columnSpan="2" spacing="10" alignment="CENTER">
<VBox prefWidth="200" alignment="CENTER">
<Label text="%market.allegiance"/>
<ComboBox fx:id="faction" maxWidth="200" />
</VBox>
<VBox prefWidth="200" alignment="CENTER">
<Label text="%market.government"/>
<ComboBox fx:id="government" maxWidth="200" />
</VBox>
</HBox>
<HBox GridPane.rowIndex="2" GridPane.columnIndex="1" spacing="4">
<VBox prefWidth="200" alignment="CENTER">
<Label text="%vEditor.text.distance"/>
<NumberField fx:id="distance" maxWidth="60" />
@@ -33,13 +41,13 @@
</TilePane>
</VBox>
</HBox>
<VBox GridPane.rowIndex="2" alignment="CENTER" spacing="10">
<VBox GridPane.rowIndex="3" alignment="CENTER" spacing="10">
<Button prefWidth="30" onAction="#up"><graphic><Glyph text="FontAwesome|ARROW_UP"/></graphic></Button>
<Button prefWidth="30" onAction="#down"><graphic><Glyph text="FontAwesome|ARROW_DOWN"/></graphic></Button>
<Button prefWidth="30" onAction="#add"><graphic><Glyph text="FontAwesome|PLUS"/></graphic></Button>
<Button prefWidth="30" onAction="#updateFromEMDN"><graphic><Glyph text="FontAwesome|REFRESH"/></graphic></Button>
</VBox>
<TableView fx:id="items" prefWidth="575" editable="true" GridPane.columnIndex="1" GridPane.rowIndex="2">
<TableView fx:id="items" prefWidth="575" editable="true" GridPane.columnIndex="1" GridPane.rowIndex="3">
<columns>
<TableColumn minWidth="200.0" text="%market.item.name" editable="false">
<cellValueFactory><PropertyValueFactory property="name"/></cellValueFactory>