add legal state item in factions and governments
This commit is contained in:
@@ -34,6 +34,10 @@ public class ItemsController {
|
|||||||
private TableColumn<ItemModel, Collection<FACTION>> factions;
|
private TableColumn<ItemModel, Collection<FACTION>> factions;
|
||||||
@FXML
|
@FXML
|
||||||
private TableColumn<ItemModel, Collection<GOVERNMENT>> governments;
|
private TableColumn<ItemModel, Collection<GOVERNMENT>> governments;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<ItemModel, Collection<FACTION>> legalFactions;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<ItemModel, Collection<GOVERNMENT>> legalGovernments;
|
||||||
|
|
||||||
private ObservableList<ItemModel> items = FXCollections.observableArrayList();
|
private ObservableList<ItemModel> items = FXCollections.observableArrayList();
|
||||||
private ObservableList<GroupModel> groups = FXCollections.observableArrayList();
|
private ObservableList<GroupModel> groups = FXCollections.observableArrayList();
|
||||||
@@ -49,6 +53,12 @@ public class ItemsController {
|
|||||||
governments.setCellFactory(CheckComboBoxTableCell.forTableColumn(governments,
|
governments.setCellFactory(CheckComboBoxTableCell.forTableColumn(governments,
|
||||||
FXCollections.observableArrayList(GOVERNMENT.values()), new GovernmentStringConverter(), ItemModel::setIllegal)
|
FXCollections.observableArrayList(GOVERNMENT.values()), new GovernmentStringConverter(), ItemModel::setIllegal)
|
||||||
);
|
);
|
||||||
|
legalFactions.setCellFactory(CheckComboBoxTableCell.forTableColumn(legalFactions,
|
||||||
|
FXCollections.observableArrayList(FACTION.values()), new FactionStringConverter(), ItemModel::setLegal)
|
||||||
|
);
|
||||||
|
legalGovernments.setCellFactory(CheckComboBoxTableCell.forTableColumn(legalGovernments,
|
||||||
|
FXCollections.observableArrayList(GOVERNMENT.values()), new GovernmentStringConverter(), ItemModel::setLegal)
|
||||||
|
);
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -120,10 +120,6 @@ public class ItemModel implements Comparable<ItemModel> {
|
|||||||
return item.getIllegalFactions();
|
return item.getIllegalFactions();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIllegalFactions(Collection<FACTION> factions){
|
|
||||||
LOG.debug("Set illegal factions {}", factions);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIllegal(FACTION faction, boolean illegal){
|
public void setIllegal(FACTION faction, boolean illegal){
|
||||||
item.setIllegal(faction, illegal);
|
item.setIllegal(faction, illegal);
|
||||||
}
|
}
|
||||||
@@ -136,6 +132,22 @@ public class ItemModel implements Comparable<ItemModel> {
|
|||||||
item.setIllegal(government, illegal);
|
item.setIllegal(government, illegal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<FACTION> getLegalFactions(){
|
||||||
|
return item.getLegalFactions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLegal(FACTION faction, boolean legal){
|
||||||
|
item.setLegal(faction, legal);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<GOVERNMENT> getLegalGovernments(){
|
||||||
|
return item.getLegalGovernments();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLegal(GOVERNMENT government, boolean legal){
|
||||||
|
item.setLegal(government, legal);
|
||||||
|
}
|
||||||
|
|
||||||
public void refresh(){
|
public void refresh(){
|
||||||
LOG.trace("Refresh stats of itemDesc {}", this);
|
LOG.trace("Refresh stats of itemDesc {}", this);
|
||||||
statBuy.refresh();
|
statBuy.refresh();
|
||||||
|
|||||||
@@ -27,6 +27,12 @@
|
|||||||
<TableColumn fx:id="governments" minWidth="145" text="Запрещено в">
|
<TableColumn fx:id="governments" minWidth="145" text="Запрещено в">
|
||||||
<cellValueFactory><PropertyValueFactory property="illegalGovernments"/></cellValueFactory>
|
<cellValueFactory><PropertyValueFactory property="illegalGovernments"/></cellValueFactory>
|
||||||
</TableColumn>
|
</TableColumn>
|
||||||
|
<TableColumn fx:id="legalFactions" minWidth="145" text="Разрешено в">
|
||||||
|
<cellValueFactory><PropertyValueFactory property="legalFactions"/></cellValueFactory>
|
||||||
|
</TableColumn>
|
||||||
|
<TableColumn fx:id="legalGovernments" minWidth="145" text="Разрешено в">
|
||||||
|
<cellValueFactory><PropertyValueFactory property="legalGovernments"/></cellValueFactory>
|
||||||
|
</TableColumn>
|
||||||
</columns>
|
</columns>
|
||||||
<columnResizePolicy>
|
<columnResizePolicy>
|
||||||
<TableView fx:constant="UNCONSTRAINED_RESIZE_POLICY"/>
|
<TableView fx:constant="UNCONSTRAINED_RESIZE_POLICY"/>
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ public abstract class AbstractItem implements Item {
|
|||||||
protected abstract void updateName(String name);
|
protected abstract void updateName(String name);
|
||||||
protected abstract void updateIllegalState(FACTION faction, boolean illegal);
|
protected abstract void updateIllegalState(FACTION faction, boolean illegal);
|
||||||
protected abstract void updateIllegalState(GOVERNMENT government, boolean illegal);
|
protected abstract void updateIllegalState(GOVERNMENT government, boolean illegal);
|
||||||
|
protected abstract void updateLegalState(FACTION faction, boolean legal);
|
||||||
|
protected abstract void updateLegalState(GOVERNMENT government, boolean legal);
|
||||||
|
|
||||||
protected final void setMarket(AbstractMarket market){
|
protected final void setMarket(AbstractMarket market){
|
||||||
assert this.market == null;
|
assert this.market == null;
|
||||||
@@ -52,6 +54,28 @@ public abstract class AbstractItem implements Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void setLegal(FACTION faction, boolean legal){
|
||||||
|
if (market != null){
|
||||||
|
LOG.debug("Change legal state of item {} for faction {} to {}", this, faction, legal);
|
||||||
|
updateLegalState(faction, legal);
|
||||||
|
market.setChange(true);
|
||||||
|
} else {
|
||||||
|
updateLegalState(faction, legal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void setLegal(GOVERNMENT government, boolean legal){
|
||||||
|
if (market != null){
|
||||||
|
LOG.debug("Change legal state of item {} for government {} to {}", this, government, legal);
|
||||||
|
updateLegalState(government, legal);
|
||||||
|
market.setChange(true);
|
||||||
|
} else {
|
||||||
|
updateLegalState(government, legal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return getName();
|
return getName();
|
||||||
|
|||||||
@@ -12,8 +12,10 @@ public interface Item extends Comparable<Item> {
|
|||||||
default boolean isIllegal(Vendor vendor){
|
default boolean isIllegal(Vendor vendor){
|
||||||
FACTION faction = vendor.getFaction();
|
FACTION faction = vendor.getFaction();
|
||||||
GOVERNMENT government = vendor.getGovernment();
|
GOVERNMENT government = vendor.getGovernment();
|
||||||
return faction != null && getIllegalFactions().contains(vendor.getFaction())
|
if (faction != null && getLegalFactions().contains(faction)) return false;
|
||||||
|| government != null && getIllegalGovernments().contains(government);
|
if (government != null && getLegalGovernments().contains(government)) return false;
|
||||||
|
return faction != null && getIllegalFactions().contains(faction) ||
|
||||||
|
government != null && getIllegalGovernments().contains(government);
|
||||||
}
|
}
|
||||||
|
|
||||||
Collection<FACTION> getIllegalFactions();
|
Collection<FACTION> getIllegalFactions();
|
||||||
@@ -21,6 +23,11 @@ public interface Item extends Comparable<Item> {
|
|||||||
Collection<GOVERNMENT> getIllegalGovernments();
|
Collection<GOVERNMENT> getIllegalGovernments();
|
||||||
void setIllegal(GOVERNMENT government, boolean illegal);
|
void setIllegal(GOVERNMENT government, boolean illegal);
|
||||||
|
|
||||||
|
Collection<FACTION> getLegalFactions();
|
||||||
|
void setLegal(FACTION faction, boolean legal);
|
||||||
|
Collection<GOVERNMENT> getLegalGovernments();
|
||||||
|
void setLegal(GOVERNMENT government, boolean legal);
|
||||||
|
|
||||||
Group getGroup();
|
Group getGroup();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -122,6 +122,18 @@ public interface Market {
|
|||||||
for (Item item : items) {
|
for (Item item : items) {
|
||||||
Item nItem = getItem(item.getName());
|
Item nItem = getItem(item.getName());
|
||||||
if (nItem == null) nItem = this.addItem(item.getName(), mapGroups.get(item.getGroup()));
|
if (nItem == null) nItem = this.addItem(item.getName(), mapGroups.get(item.getGroup()));
|
||||||
|
for (FACTION faction : item.getIllegalFactions()) {
|
||||||
|
nItem.setIllegal(faction, true);
|
||||||
|
}
|
||||||
|
for (FACTION faction : item.getLegalFactions()) {
|
||||||
|
nItem.setLegal(faction, true);
|
||||||
|
}
|
||||||
|
for (GOVERNMENT government : item.getIllegalGovernments()) {
|
||||||
|
nItem.setIllegal(government, true);
|
||||||
|
}
|
||||||
|
for (GOVERNMENT government : item.getLegalGovernments()) {
|
||||||
|
nItem.setLegal(government, true);
|
||||||
|
}
|
||||||
mapItems.put(item, nItem);
|
mapItems.put(item, nItem);
|
||||||
}
|
}
|
||||||
mapGroups.clear();
|
mapGroups.clear();
|
||||||
|
|||||||
@@ -59,6 +59,28 @@ public class ItemProxy extends AbstractItem {
|
|||||||
return item.getIllegalGovernments();
|
return item.getIllegalGovernments();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateLegalState(FACTION faction, boolean legal) {
|
||||||
|
item.setLegal(faction, legal);
|
||||||
|
store.getItemAccessor().update(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<FACTION> getLegalFactions() {
|
||||||
|
return item.getLegalFactions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateLegalState(GOVERNMENT government, boolean legal) {
|
||||||
|
item.setLegal(government, legal);
|
||||||
|
store.getItemAccessor().update(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<GOVERNMENT> getLegalGovernments() {
|
||||||
|
return item.getLegalGovernments();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Group getGroup() {
|
public Group getGroup() {
|
||||||
if (group == null){
|
if (group == null){
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import ru.trader.core.GOVERNMENT;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
@Entity(version = 2)
|
@Entity(version = 3)
|
||||||
public class BDBItem {
|
public class BDBItem {
|
||||||
@PrimaryKey(sequence="I_ID")
|
@PrimaryKey(sequence="I_ID")
|
||||||
private long id;
|
private long id;
|
||||||
@@ -19,10 +19,10 @@ public class BDBItem {
|
|||||||
onRelatedEntityDelete = DeleteAction.CASCADE)
|
onRelatedEntityDelete = DeleteAction.CASCADE)
|
||||||
private String groupId;
|
private String groupId;
|
||||||
|
|
||||||
@SecondaryKey(relate=Relationship.MANY_TO_MANY)
|
HashSet<FACTION> fIllegals = new HashSet<>();
|
||||||
Collection<FACTION> fIllegals = new HashSet<>();
|
HashSet<GOVERNMENT> gIllegals = new HashSet<>();
|
||||||
@SecondaryKey(relate=Relationship.MANY_TO_MANY)
|
HashSet<FACTION> fLegals = new HashSet<>();
|
||||||
Collection<GOVERNMENT> gIllegals = new HashSet<>();
|
HashSet<GOVERNMENT> gLegals = new HashSet<>();
|
||||||
|
|
||||||
private BDBItem() {
|
private BDBItem() {
|
||||||
}
|
}
|
||||||
@@ -62,6 +62,25 @@ public class BDBItem {
|
|||||||
return gIllegals;
|
return gIllegals;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLegal(FACTION faction, boolean legal) {
|
||||||
|
if (legal) fLegals.add(faction);
|
||||||
|
else fLegals.remove(faction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<FACTION> getLegalFactions() {
|
||||||
|
return fLegals;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLegal(GOVERNMENT government, boolean legal) {
|
||||||
|
if (legal) gLegals.add(government);
|
||||||
|
else gLegals.remove(government);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<GOVERNMENT> getLegalGovernments() {
|
||||||
|
return gLegals;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getGroupId() {
|
public String getGroupId() {
|
||||||
return groupId;
|
return groupId;
|
||||||
}
|
}
|
||||||
@@ -78,6 +97,8 @@ public class BDBItem {
|
|||||||
if (!name.equals(bdbItem.name)) return false;
|
if (!name.equals(bdbItem.name)) return false;
|
||||||
if (!fIllegals.equals(bdbItem.fIllegals)) return false;
|
if (!fIllegals.equals(bdbItem.fIllegals)) return false;
|
||||||
if (!gIllegals.equals(bdbItem.gIllegals)) return false;
|
if (!gIllegals.equals(bdbItem.gIllegals)) return false;
|
||||||
|
if (!fLegals.equals(bdbItem.fLegals)) return false;
|
||||||
|
if (!gLegals.equals(bdbItem.gLegals)) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ public class MarketDocHandler extends DefaultHandler {
|
|||||||
protected final static String ITEM_ATTR = "item";
|
protected final static String ITEM_ATTR = "item";
|
||||||
protected final static String ILLEGAL_FACTION_ATTR = "illegalf";
|
protected final static String ILLEGAL_FACTION_ATTR = "illegalf";
|
||||||
protected final static String ILLEGAL_GOVERNMENT__ATTR = "illegalg";
|
protected final static String ILLEGAL_GOVERNMENT__ATTR = "illegalg";
|
||||||
|
protected final static String LEGAL_FACTION_ATTR = "legalf";
|
||||||
|
protected final static String LEGAL_GOVERNMENT__ATTR = "legalg";
|
||||||
protected final static String DISTANCE_ATTR = "distance";
|
protected final static String DISTANCE_ATTR = "distance";
|
||||||
protected final static String X_ATTR = "x";
|
protected final static String X_ATTR = "x";
|
||||||
protected final static String Y_ATTR = "y";
|
protected final static String Y_ATTR = "y";
|
||||||
@@ -155,8 +157,23 @@ public class MarketDocHandler extends DefaultHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.debug("parse item {} ({}), illegal - {}, {}", name, id, factions, governments);
|
String legalFactions = attributes.getValue(LEGAL_FACTION_ATTR);
|
||||||
onItem(name, id, factions, governments);
|
String legalGovernments = attributes.getValue(LEGAL_GOVERNMENT__ATTR);
|
||||||
|
EnumSet<FACTION> legalf = EnumSet.noneOf(FACTION.class);
|
||||||
|
if (legalFactions != null){
|
||||||
|
for (String f : legalFactions.split(",")) {
|
||||||
|
legalf.add(FACTION.valueOf(f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EnumSet<GOVERNMENT> legalg = EnumSet.noneOf(GOVERNMENT.class);
|
||||||
|
if (legalGovernments != null){
|
||||||
|
for (String f : legalGovernments.split(",")) {
|
||||||
|
legalg.add(GOVERNMENT.valueOf(f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.debug("parse item {} ({}), illegal - {}, {}, legal - {}, {}", name, id, factions, governments, legalf, legalg);
|
||||||
|
onItem(name, id, factions, governments, legalf, legalg);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void parseOffer(Attributes attributes) throws SAXException {
|
protected void parseOffer(Attributes attributes) throws SAXException {
|
||||||
@@ -209,7 +226,8 @@ public class MarketDocHandler extends DefaultHandler {
|
|||||||
curVendor.add(type);
|
curVendor.add(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onItem(String name, String id, Collection<FACTION> illegalFactions, Collection<GOVERNMENT> illegalGovernment) {
|
protected void onItem(String name, String id, Collection<FACTION> illegalFactions, Collection<GOVERNMENT> illegalGovernment,
|
||||||
|
Collection<FACTION> legalFactions, Collection<GOVERNMENT> legalGovernment) {
|
||||||
Item item = world.addItem(name, curGroup);
|
Item item = world.addItem(name, curGroup);
|
||||||
for (FACTION faction : illegalFactions) {
|
for (FACTION faction : illegalFactions) {
|
||||||
item.setIllegal(faction, true);
|
item.setIllegal(faction, true);
|
||||||
@@ -217,6 +235,12 @@ public class MarketDocHandler extends DefaultHandler {
|
|||||||
for (GOVERNMENT government : illegalGovernment) {
|
for (GOVERNMENT government : illegalGovernment) {
|
||||||
item.setIllegal(government, true);
|
item.setIllegal(government, true);
|
||||||
}
|
}
|
||||||
|
for (FACTION faction : legalFactions) {
|
||||||
|
item.setLegal(faction, true);
|
||||||
|
}
|
||||||
|
for (GOVERNMENT government : legalGovernment) {
|
||||||
|
item.setLegal(government, true);
|
||||||
|
}
|
||||||
items.put(id, item);
|
items.put(id, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,17 @@ public class MarketStreamWriter {
|
|||||||
String str = governments.stream().map(GOVERNMENT::toString).collect(Collectors.joining(","));
|
String str = governments.stream().map(GOVERNMENT::toString).collect(Collectors.joining(","));
|
||||||
out.writeAttribute(MarketDocHandler.ILLEGAL_GOVERNMENT__ATTR, str);
|
out.writeAttribute(MarketDocHandler.ILLEGAL_GOVERNMENT__ATTR, str);
|
||||||
}
|
}
|
||||||
|
factions = item.getLegalFactions();
|
||||||
|
if (!factions.isEmpty()) {
|
||||||
|
String str = factions.stream().map(FACTION::toString).collect(Collectors.joining(","));
|
||||||
|
out.writeAttribute(MarketDocHandler.LEGAL_FACTION_ATTR, str);
|
||||||
|
}
|
||||||
|
governments = item.getLegalGovernments();
|
||||||
|
if (!governments.isEmpty()) {
|
||||||
|
String str = governments.stream().map(GOVERNMENT::toString).collect(Collectors.joining(","));
|
||||||
|
out.writeAttribute(MarketDocHandler.LEGAL_GOVERNMENT__ATTR, str);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writePlaces() throws XMLStreamException {
|
protected void writePlaces() throws XMLStreamException {
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ public class SimpleItem extends AbstractItem {
|
|||||||
private Group group;
|
private Group group;
|
||||||
private final EnumSet<GOVERNMENT> gIllegals = EnumSet.noneOf(GOVERNMENT.class);
|
private final EnumSet<GOVERNMENT> gIllegals = EnumSet.noneOf(GOVERNMENT.class);
|
||||||
private final EnumSet<FACTION> fIllegals = EnumSet.noneOf(FACTION.class);
|
private final EnumSet<FACTION> fIllegals = EnumSet.noneOf(FACTION.class);
|
||||||
|
private final EnumSet<GOVERNMENT> gLegals = EnumSet.noneOf(GOVERNMENT.class);
|
||||||
|
private final EnumSet<FACTION> fLegals = EnumSet.noneOf(FACTION.class);
|
||||||
|
|
||||||
public SimpleItem(String name) {
|
public SimpleItem(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -55,6 +57,28 @@ public class SimpleItem extends AbstractItem {
|
|||||||
return gIllegals;
|
return gIllegals;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateLegalState(FACTION faction, boolean legal) {
|
||||||
|
if (legal) fLegals.add(faction);
|
||||||
|
else fLegals.remove(faction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<FACTION> getLegalFactions() {
|
||||||
|
return fLegals;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateLegalState(GOVERNMENT government, boolean legal) {
|
||||||
|
if (legal) gLegals.add(government);
|
||||||
|
else gLegals.remove(government);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<GOVERNMENT> getLegalGovernments() {
|
||||||
|
return gLegals;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Group getGroup() {
|
public Group getGroup() {
|
||||||
return group;
|
return group;
|
||||||
|
|||||||
@@ -50,6 +50,8 @@
|
|||||||
<xs:attribute name="name" type="xs:string" use="required"/>
|
<xs:attribute name="name" type="xs:string" use="required"/>
|
||||||
<xs:attribute name="illegalf" type="xs:string" use="optional"/>
|
<xs:attribute name="illegalf" type="xs:string" use="optional"/>
|
||||||
<xs:attribute name="illegalg" type="xs:string" use="optional"/>
|
<xs:attribute name="illegalg" type="xs:string" use="optional"/>
|
||||||
|
<xs:attribute name="legalf" type="xs:string" use="optional"/>
|
||||||
|
<xs:attribute name="legalg" type="xs:string" use="optional"/>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
|
|
||||||
<xs:complexType name="placeType" mixed="true">
|
<xs:complexType name="placeType" mixed="true">
|
||||||
|
|||||||
Reference in New Issue
Block a user