-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCropFieldGrowingMenuControllerBuilder.java
112 lines (91 loc) · 3.72 KB
/
CropFieldGrowingMenuControllerBuilder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package controller.menu.builder.building.crop_field;
import controller.GameController;
import controller.command.Command;
import controller.command.CompoundCommand;
import controller.command.ConditionalCommand;
import controller.command.controller_state.SetControllerStateCommand;
import controller.command.farm.crop_field.RemoveCropCommand;
import controller.menu.element.ButtonController;
import controller.menu.MenuController;
import controller.menu.PopupMenuControllerWithTimePassedReaction;
import controller.menu.builder.MenuControllerBuilder;
import controller.menu.builder.PopupMenuControllerBuilder;
import model.Position;
import model.farm.Farm;
import model.farm.building.crop_field.CropField;
import model.farm.building.crop_field.state.ReadyToHarvest;
import model.menu.Button;
import model.menu.Menu;
import model.menu.label.Label;
import java.util.List;
public class CropFieldGrowingMenuControllerBuilder extends PopupMenuControllerBuilder {
private Farm farm;
private CropField cropField;
public CropFieldGrowingMenuControllerBuilder(GameController controller, Farm farm, CropField cropField) {
super(controller);
this.farm = farm;
this.cropField = cropField;
}
@Override
protected MenuController getMenuController(Menu menu) {
MenuControllerBuilder harvestMenuControllerBuilder = new HarvestMenuControllerBuilder(
this.controller, this.farm.getInventory(), this.cropField);
MenuController harvestMenuController = harvestMenuControllerBuilder.buildMenuCentered(
this.controller.getWindowWidth(), this.controller.getWindowHeight());
Command closingCondition = new ConditionalCommand(() -> this.cropField.getState() instanceof ReadyToHarvest)
.ifTrue(new SetControllerStateCommand(this.controller, harvestMenuController));
return new PopupMenuControllerWithTimePassedReaction(menu, this.controller,
this.controller.getGameControllerState(), closingCondition);
}
@Override
protected List<ButtonController> getButtons() {
List<ButtonController> buttons = super.getButtons();
addRemoveCropButton(buttons);
return buttons;
}
private void addRemoveCropButton(List<ButtonController> buttons) {
Button removeCropButton = new Button(new Position(1, 8), "REMOVE CROP");
Command removeCropButtonCommand = new CompoundCommand()
.addCommand(new RemoveCropCommand(this.cropField))
.addCommand(super.getClosePopupMenuCommand());
buttons.add(new ButtonController(removeCropButton, removeCropButtonCommand));
}
@Override
protected List<Label> getLabels() {
List<Label> labels = super.getLabels();
addCropTypeLabel(labels);
addRemainingTimeLabel(labels);
addQuantityLabel(labels);
return labels;
}
private void addCropTypeLabel(List<Label> labels) {
labels.add(new Label(
new Position(1, 4),
() -> "CROP: " + this.cropField.getState().getCrop().getName()
));
}
private void addRemainingTimeLabel(List<Label> labels) {
labels.add(new Label(
new Position(1, 5),
() -> "REMAINING TIME: " + this.cropField.getRemainingTime().getTimerString()
));
}
private void addQuantityLabel(List<Label> labels) {
labels.add( new Label(
new Position(1, 6),
() -> "QUANTITY: " + this.cropField.getHarvestAmount()
));
}
@Override
protected int getHeight() {
return 12;
}
@Override
protected int getWidth() {
return 23;
}
@Override
public String getTitle() {
return "GROWING";
}
}