From 08850417be06f17a14af2cd7ef21d15b2bb80699 Mon Sep 17 00:00:00 2001 From: iMoHax Date: Mon, 21 Mar 2016 16:26:13 +0300 Subject: [PATCH] add warning icon. Showed, if need fill station or system --- .../trader/controllers/OffersController.java | 18 ++++ .../trader/controllers/ProfileController.java | 23 +++++ .../java/ru/trader/model/ModelFabric.java | 90 ++++++++++++++++++- .../java/ru/trader/model/StationModel.java | 6 ++ .../java/ru/trader/model/SystemModel.java | 8 ++ client/src/main/resources/view/offers.fxml | 36 +++++--- client/src/main/resources/view/profile.fxml | 9 +- client/src/main/resources/view/style.css | 6 ++ 8 files changed, 179 insertions(+), 17 deletions(-) diff --git a/client/src/main/java/ru/trader/controllers/OffersController.java b/client/src/main/java/ru/trader/controllers/OffersController.java index 3d4e244..912b7e6 100644 --- a/client/src/main/java/ru/trader/controllers/OffersController.java +++ b/client/src/main/java/ru/trader/controllers/OffersController.java @@ -3,6 +3,7 @@ package ru.trader.controllers; import javafx.application.Platform; import javafx.collections.FXCollections; import javafx.fxml.FXML; +import javafx.scene.Node; import javafx.scene.control.*; import javafx.scene.input.MouseButton; import org.slf4j.Logger; @@ -66,6 +67,8 @@ public class OffersController { private CheckBox cbLargeLandpad; @FXML private TitledPane stationPane; + @FXML + private Node warningIcon; private final List sells = FXCollections.observableArrayList(); private final List buys = FXCollections.observableArrayList(); @@ -171,6 +174,7 @@ public class OffersController { sells.addAll(station.getSells()); buys.addAll(station.getBuys()); } + updateIcons(); } private void sort(){ @@ -199,6 +203,20 @@ public class OffersController { return station; } + private void updateIcons(){ + SystemModel s = getSystem(); + if (!s.isCorrect()){ + warningIcon.setVisible(true); + return; + } + StationModel st = getStation(); + if (!st.isCorrect()){ + warningIcon.setVisible(true); + return; + } + warningIcon.setVisible(false); + } + @FXML private void currentSystem(){ ProfileModel profile = MainController.getProfile(); diff --git a/client/src/main/java/ru/trader/controllers/ProfileController.java b/client/src/main/java/ru/trader/controllers/ProfileController.java index 6c92f25..3a2fb28 100644 --- a/client/src/main/java/ru/trader/controllers/ProfileController.java +++ b/client/src/main/java/ru/trader/controllers/ProfileController.java @@ -5,9 +5,11 @@ import javafx.beans.binding.Bindings; import javafx.beans.value.ChangeListener; import javafx.collections.FXCollections; import javafx.fxml.FXML; +import javafx.scene.Node; import javafx.scene.control.*; import javafx.scene.layout.Pane; import javafx.util.StringConverter; +import org.controlsfx.glyphfont.Glyph; import ru.trader.Main; import ru.trader.ServicesManager; import ru.trader.core.Engine; @@ -55,6 +57,8 @@ public class ProfileController { private ToggleButton btnHelper; @FXML private ToggleButton btnEDCE; + @FXML + private Node warningIcon; private AutoCompletion system; private ProfileModel profile; @@ -74,6 +78,7 @@ public class ProfileController { profile.setStation(ModelFabric.NONE_STATION); }); }); + system.valueProperty().addListener(i -> updateIcons()); engine.setItems(FXCollections.observableList(Engine.getEngines())); engine.setConverter(new EngineStringConverter()); btnAddSystem.setOnAction(e -> { @@ -185,11 +190,29 @@ public class ProfileController { bind(); } + private StationModel getStation(){ + return getStation(station.getValue()); + } + private StationModel getStation(String name){ SystemModel s = system.getValue(); return s == null ? ModelFabric.NONE_STATION : s.get(name); } + private void updateIcons(){ + SystemModel s = system.getValue(); + if (!s.isCorrect()){ + warningIcon.setVisible(true); + return; + } + StationModel st = getStation(); + if (!st.isCorrect()){ + warningIcon.setVisible(true); + return; + } + warningIcon.setVisible(false); + } + private void bind(){ profile.nameProperty().addListener(nameListener); profile.balanceProperty().addListener(balanceListener); diff --git a/client/src/main/java/ru/trader/model/ModelFabric.java b/client/src/main/java/ru/trader/model/ModelFabric.java index 9f01107..cb2eb9e 100644 --- a/client/src/main/java/ru/trader/model/ModelFabric.java +++ b/client/src/main/java/ru/trader/model/ModelFabric.java @@ -215,6 +215,46 @@ public class ModelFabric { throw new UnsupportedOperationException("Is fake system, change unsupported"); } + @Override + public FACTION getFaction() { + return FACTION.NONE; + } + + @Override + public void setFaction(FACTION faction) { + throw new UnsupportedOperationException("Is fake system, change unsupported"); + } + + @Override + public GOVERNMENT getGovernment() { + return GOVERNMENT.NONE; + } + + @Override + public void setGovernment(GOVERNMENT government) { + throw new UnsupportedOperationException("Is fake system, change unsupported"); + } + + @Override + public POWER getPower() { + return POWER.NONE; + } + + @Override + public void setPower(POWER power) { + throw new UnsupportedOperationException("Is fake system, change unsupported"); + } + + @Override + public POWER_STATE getPowerState() { + return POWER_STATE.NONE; + } + + @Override + public void setPowerState(POWER_STATE powerState) { + throw new UnsupportedOperationException("Is fake system, change unsupported"); + } + @Override public StationModel get(String name) { return ModelFabric.NONE_STATION; @@ -240,6 +280,16 @@ public class ModelFabric { throw new UnsupportedOperationException("Is fake system, change unsupported"); } + @Override + public boolean isEmpty() { + return true; + } + + @Override + public boolean isCorrect() { + return true; + } + @Override public String toString() { return ""; @@ -267,9 +317,39 @@ public class ModelFabric { return ""; } + @Override + public STATION_TYPE getType() { + return STATION_TYPE.STARPORT; + } + + @Override + public void setType(STATION_TYPE type) { + throw new UnsupportedOperationException("Is fake station, unsupported"); + } + + @Override + public ECONOMIC_TYPE getEconomic() { + return ECONOMIC_TYPE.NONE; + } + + @Override + public void setEconomic(ECONOMIC_TYPE economic) { + throw new UnsupportedOperationException("Is fake station, unsupported"); + } + + @Override + public ECONOMIC_TYPE getSubEconomic() { + return ECONOMIC_TYPE.NONE; + } + + @Override + public void setSubEconomic(ECONOMIC_TYPE economic) { + throw new UnsupportedOperationException("Is fake station, unsupported"); + } + @Override public FACTION getFaction() { - throw new UnsupportedOperationException("Is fake station, unsupported"); + return FACTION.NONE; } @Override @@ -279,7 +359,7 @@ public class ModelFabric { @Override public GOVERNMENT getGovernment() { - throw new UnsupportedOperationException("Is fake station, unsupported"); + return GOVERNMENT.NONE; } @Override @@ -362,6 +442,12 @@ public class ModelFabric { throw new UnsupportedOperationException("Is fake station, unsupported"); } + + @Override + public boolean isCorrect(){ + return true; + } + @Override public String toString() { return ""; diff --git a/client/src/main/java/ru/trader/model/StationModel.java b/client/src/main/java/ru/trader/model/StationModel.java index b98020d..523ff6e 100644 --- a/client/src/main/java/ru/trader/model/StationModel.java +++ b/client/src/main/java/ru/trader/model/StationModel.java @@ -178,6 +178,12 @@ public class StationModel { return station.getModifiedTime(); } + public boolean isCorrect(){ + return !station.getName().isEmpty() && station.getType() != null && station.getDistance() > 0 + && station.getFaction() != null && station.getGovernment() != null + && station.getEconomic() != null && station.getSubEconomic() != null; + } + @Override public String toString() { if (LOG.isTraceEnabled()){ diff --git a/client/src/main/java/ru/trader/model/SystemModel.java b/client/src/main/java/ru/trader/model/SystemModel.java index 1bc42ae..f081880 100644 --- a/client/src/main/java/ru/trader/model/SystemModel.java +++ b/client/src/main/java/ru/trader/model/SystemModel.java @@ -160,6 +160,14 @@ public class SystemModel { return system.isEmpty(); } + public boolean isCorrect(){ + return !system.getName().isEmpty() && (system.getX() != 0 || system.getY() != 0 || system.getZ() != 0 ) + && system.getFaction() != null && system.getGovernment() != null + && system.getPower() != null && system.getPowerState() != null + && (system.getFaction() == FACTION.NONE || !system.isEmpty()); + } + + @Override public String toString() { if (LOG.isTraceEnabled()){ diff --git a/client/src/main/resources/view/offers.fxml b/client/src/main/resources/view/offers.fxml index 9343f69..bb932dd 100644 --- a/client/src/main/resources/view/offers.fxml +++ b/client/src/main/resources/view/offers.fxml @@ -13,6 +13,18 @@ + + + + + + + + + + + + @@ -24,17 +36,7 @@ - - - - - - - - - - - + @@ -47,7 +49,8 @@ - + +