mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-22 21:09:51 +00:00
Clean Up Climate Bar
This commit is contained in:
1 parent
0a2ca1febc
commit
6d774de5a6
14 files changed
+89
-86
No files matched your search
@@ -7,7 +7,7 @@ import net.minecraft.util.math.MathHelper;
|
||||
public enum ClimateStateType {
|
||||
IMMUTABLE(0.0F, 2.0F),
|
||||
MUTABLE(0.0F, 2.0F),
|
||||
CHANGE(-2.0F, 2.0F);
|
||||
CHANGE(-3.0F, 3.0F);
|
||||
|
||||
public final Function<Float, Float> bounds;
|
||||
|
||||
|
||||
@@ -32,11 +32,7 @@ public interface IClimateState extends INbtWritable {
|
||||
return type == ClimateType.HUMIDITY ? getHumidity() : getTemperature();
|
||||
}
|
||||
|
||||
IClimateState toImmutable();
|
||||
|
||||
IClimateState toMutable();
|
||||
|
||||
IClimateState toChange();
|
||||
IClimateState toState(ClimateStateType type);
|
||||
|
||||
IClimateState setTemperature(float temperature);
|
||||
|
||||
|
||||
@@ -21,17 +21,7 @@ public final class AbsentClimateState implements IClimateState {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState toImmutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState toMutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState toChange() {
|
||||
public IClimateState toState(ClimateStateType type) {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public class ClimateContainer implements IClimateContainer, IStreamable {
|
||||
this.listeners = new ClimateContainerListeners();
|
||||
this.sources = new HashSet<>();
|
||||
this.delay = 20;
|
||||
this.state = parent.getDefaultClimate().toMutable();
|
||||
this.state = parent.getDefaultClimate().toState(ClimateStateType.MUTABLE);
|
||||
this.modifierData = new NBTTagCompound();
|
||||
this.boundaryUp = ClimateState.MIN;
|
||||
this.boundaryDown = ClimateState.MIN;
|
||||
@@ -84,11 +84,12 @@ public class ClimateContainer implements IClimateContainer, IStreamable {
|
||||
if(!listeners.isClosed(this)) {
|
||||
returnClimateToDefault();
|
||||
}else{
|
||||
IClimateState oldState = state.toImmutable();
|
||||
state = parent.getDefaultClimate().toMutable();
|
||||
IClimateState oldState = state.toState(ClimateStateType.IMMUTABLE);
|
||||
state = parent.getDefaultClimate().toState(ClimateStateType.CHANGE);
|
||||
for(IClimateModifier modifier : GreenhouseClimateManager.getInstance().getModifiers()){
|
||||
state = modifier.modifyTarget(this, state, oldState, modifierData).toMutable();
|
||||
state = modifier.modifyTarget(this, state, oldState, modifierData).toState(ClimateStateType.CHANGE);
|
||||
}
|
||||
state = state.toState(ClimateStateType.MUTABLE);
|
||||
if(!state.equals(oldState)) {
|
||||
BlockPos coordinates = parent.getCoordinates();
|
||||
NetworkUtil.sendNetworkPacket(new PacketUpdateClimate(coordinates, this), coordinates, parent.getWorldObj());
|
||||
|
||||
@@ -37,10 +37,10 @@ public class ClimateState implements IClimateState, IClimateInfo {
|
||||
}
|
||||
|
||||
public ClimateState(float temperature, float humidity, ClimateStateType type) {
|
||||
addTemperature(temperature);
|
||||
addHumidity(humidity);
|
||||
this.type = type;
|
||||
this.bounds = type.bounds;
|
||||
addTemperature(temperature);
|
||||
addHumidity(humidity);
|
||||
}
|
||||
|
||||
public ClimateState(NBTTagCompound compound, ClimateStateType type) {
|
||||
@@ -94,23 +94,13 @@ public class ClimateState implements IClimateState, IClimateInfo {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState toImmutable() {
|
||||
return new ClimateState(this, ClimateStateType.IMMUTABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState toMutable() {
|
||||
return new ClimateState(this, ClimateStateType.MUTABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState toChange() {
|
||||
return new ClimateState(this, ClimateStateType.CHANGE);
|
||||
public IClimateState toState(ClimateStateType type) {
|
||||
return new ClimateState(this, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState addTemperature(float temperature){
|
||||
this.temperature=+ temperature;
|
||||
this.temperature= bounds.apply(this.temperature + temperature);
|
||||
if(!isPresent()){
|
||||
return AbsentClimateState.INSTANCE;
|
||||
}
|
||||
@@ -119,7 +109,7 @@ public class ClimateState implements IClimateState, IClimateInfo {
|
||||
|
||||
@Override
|
||||
public IClimateState addHumidity(float humidity){
|
||||
this.humidity=+ humidity;
|
||||
this.humidity= bounds.apply(this.humidity + humidity);
|
||||
if(!isPresent()){
|
||||
return AbsentClimateState.INSTANCE;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,11 @@ public class Table {
|
||||
lines.add(new TableTitle(title));
|
||||
}
|
||||
|
||||
public Table clear(){
|
||||
lines.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Table addValueEntry(String textKey, String value) {
|
||||
lines.add(new TableValueText(textKey + ": ", value));
|
||||
return this;
|
||||
|
||||
@@ -13,5 +13,8 @@ public interface IClimateData {
|
||||
|
||||
IClimateData addData(ClimateType type, String displayName, float value);
|
||||
|
||||
/**
|
||||
* @return A map with all data that this object contains.
|
||||
*/
|
||||
Map<String, Float> getData(ClimateType type);
|
||||
}
|
||||
@@ -27,7 +27,7 @@ import forestry.greenhouse.api.climate.IClimateModifier;
|
||||
|
||||
public class TimeModifier implements IClimateModifier {
|
||||
|
||||
private static final float TEMPERATURE_CHANGE = 0.01F;
|
||||
private static final float TEMPERATURE_CHANGE = 0.1F;
|
||||
|
||||
public static float calculateLightRatio(World world) {
|
||||
int lightValue = EnumSkyBlock.SKY.defaultLightValue - world.getSkylightSubtracted();
|
||||
|
||||
@@ -24,7 +24,6 @@ import forestry.core.gui.GuiForestryTitled;
|
||||
import forestry.core.gui.TextLayoutHelper;
|
||||
import forestry.core.utils.NetworkUtil;
|
||||
import forestry.greenhouse.api.climate.IClimateContainer;
|
||||
import forestry.greenhouse.api.climate.IClimateData;
|
||||
import forestry.greenhouse.gui.widgets.WidgetCamouflageTab;
|
||||
import forestry.greenhouse.gui.widgets.WidgetClimateBar;
|
||||
import forestry.greenhouse.gui.widgets.WidgetClimatePanel;
|
||||
@@ -51,15 +50,13 @@ public class GuiGreenhouse extends GuiForestryTitled<ContainerGreenhouse> {
|
||||
this.xSize = 196;
|
||||
this.ySize = 202;
|
||||
|
||||
IClimateData data = container.getData();
|
||||
|
||||
//Add the camouflage tab
|
||||
widgetManager.add(new WidgetCamouflageTab(widgetManager, xSize / 4 - WidgetCamouflageTab.WIDTH / 2, -WidgetCamouflageTab.HEIGHT, controller, tile));
|
||||
if(container.getTargetedState().isPresent()) {
|
||||
widgetManager.add(new WidgetClimateBar(widgetManager, xSize / 3 + WidgetClimateBar.WIDTH / 3, -WidgetClimateBar.HEIGHT));
|
||||
}
|
||||
widgetManager.add(temperaturePanel = new WidgetClimatePanel(widgetManager, this, 9, 18, ClimateType.TEMPERATURE, data));
|
||||
widgetManager.add(humidityPanel = new WidgetClimatePanel(widgetManager, this, 102, 18, ClimateType.HUMIDITY, data));
|
||||
widgetManager.add(temperaturePanel = new WidgetClimatePanel(widgetManager, this, 9, 18, ClimateType.TEMPERATURE));
|
||||
widgetManager.add(humidityPanel = new WidgetClimatePanel(widgetManager, this, 102, 18, ClimateType.HUMIDITY));
|
||||
}
|
||||
|
||||
public void sendNetworkUpdate() {
|
||||
|
||||
@@ -17,12 +17,16 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.init.Biomes;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.climate.ClimateStateType;
|
||||
import forestry.api.climate.IClimateState;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.core.climate.ClimateState;
|
||||
import forestry.core.gui.tooltips.ToolTip;
|
||||
import forestry.core.gui.widgets.Widget;
|
||||
import forestry.core.gui.widgets.WidgetManager;
|
||||
@@ -40,27 +44,8 @@ public class WidgetClimateBar extends Widget {
|
||||
super(manager, xPos, yPos);
|
||||
this.width = WIDTH;
|
||||
this.height = HEIGHT;
|
||||
for (int i = 1; i < 6; i++) {
|
||||
EnumTemperature temp = EnumTemperature.VALUES[i];
|
||||
float value;
|
||||
switch (temp) {
|
||||
case ICY:
|
||||
value = 0.0F;
|
||||
break;
|
||||
case COLD:
|
||||
value = 0.2F;
|
||||
break;
|
||||
case WARM:
|
||||
value = 0.9F;
|
||||
break;
|
||||
case HOT:
|
||||
value = 1.2F;
|
||||
break;
|
||||
default:
|
||||
value = 0.5F;
|
||||
break;
|
||||
}
|
||||
buttons.add(new ClimateButton(this, temp, value, xPos + 5 + (i - 1) * 16, yPos + 5));
|
||||
for(EnumClimate climate : EnumClimate.values()){
|
||||
buttons.add(new ClimateButton(this, climate, xPos + 5 + climate.ordinal() * 16, yPos + 5));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +75,9 @@ public class WidgetClimateBar extends Widget {
|
||||
mouseY -= manager.gui.getGuiTop();
|
||||
for (ClimateButton button : buttons) {
|
||||
if (button.isMouseOver(mouseX, mouseY)) {
|
||||
((GuiGreenhouse) manager.gui).temperaturePanel.setValue(button.value);
|
||||
IClimateState climateState = button.climate.climateState;
|
||||
((GuiGreenhouse) manager.gui).temperaturePanel.setValue(climateState.getTemperature());
|
||||
((GuiGreenhouse) manager.gui).humidityPanel.setValue(climateState.getHumidity());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,31 +95,49 @@ public class WidgetClimateBar extends Widget {
|
||||
manager.gui.drawTexturedModalRect(x, y, sprite, 16, 16);
|
||||
}
|
||||
|
||||
private static class ClimateButton {
|
||||
private enum EnumClimate {
|
||||
ICY("habitats/snow", Biomes.ICE_PLAINS),
|
||||
COLD("habitats/taiga", Biomes.TAIGA),
|
||||
NORMAL("habitats/plains", Biomes.PLAINS),
|
||||
WARM("habitats/jungle", Biomes.JUNGLE),
|
||||
HOT("habitats/desert", Biomes.DESERT);
|
||||
IClimateState climateState;
|
||||
String spriteName;
|
||||
|
||||
EnumClimate(String spriteName, Biome biome) {
|
||||
climateState = new ClimateState(biome.getTemperature(), biome.getRainfall(), ClimateStateType.IMMUTABLE);
|
||||
this.spriteName = spriteName;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public TextureAtlasSprite getSprite() {
|
||||
return ForestryAPI.textureManager.getDefault(spriteName);
|
||||
}
|
||||
}
|
||||
|
||||
private class ClimateButton {
|
||||
final WidgetClimateBar parent;
|
||||
final EnumTemperature temperature;
|
||||
final float value;
|
||||
final EnumClimate climate;
|
||||
protected final ToolTip toolTip = new ToolTip(250) {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void refresh() {
|
||||
toolTip.clear();
|
||||
toolTip.add("T: " + AlleleManager.climateHelper.toDisplay(temperature));
|
||||
toolTip.add("V: " + value);
|
||||
toolTip.add("T: " + climate.climateState.getTemperature());
|
||||
toolTip.add("H: " + climate.climateState.getHumidity());
|
||||
}
|
||||
};
|
||||
final int xPos, yPos;
|
||||
|
||||
public ClimateButton(WidgetClimateBar parent, EnumTemperature temperature, float value, int xPos, int yPos) {
|
||||
public ClimateButton(WidgetClimateBar parent, EnumClimate climate, int xPos, int yPos) {
|
||||
this.parent = parent;
|
||||
this.temperature = temperature;
|
||||
this.value = value;
|
||||
this.climate = climate;
|
||||
this.xPos = xPos;
|
||||
this.yPos = yPos;
|
||||
}
|
||||
|
||||
public void draw(int startX, int startY) {
|
||||
parent.drawSprite(temperature.getSprite(), startX + xPos, startY + yPos);
|
||||
parent.drawSprite(climate.getSprite(), startX + xPos, startY + yPos);
|
||||
}
|
||||
|
||||
public ToolTip getToolTip() {
|
||||
|
||||
@@ -28,13 +28,13 @@ import forestry.core.gui.tables.Table;
|
||||
import forestry.core.gui.widgets.Widget;
|
||||
import forestry.core.gui.widgets.WidgetManager;
|
||||
import forestry.core.render.ColourProperties;
|
||||
import forestry.core.utils.StringUtil;
|
||||
import forestry.core.utils.Translator;
|
||||
import forestry.greenhouse.api.climate.IClimateData;
|
||||
import forestry.greenhouse.gui.GuiGreenhouse;
|
||||
|
||||
public class WidgetClimatePanel extends Widget {
|
||||
|
||||
protected static final int TEXT_FIELD_LENGTH = 50;
|
||||
protected static final Predicate<String> NUMBER_FILTER = text -> {
|
||||
if (text == null) {
|
||||
return false;
|
||||
@@ -58,14 +58,13 @@ public class WidgetClimatePanel extends Widget {
|
||||
private final Table table;
|
||||
private final GuiTextField textField;
|
||||
|
||||
public WidgetClimatePanel(WidgetManager manager, GuiGreenhouse gui, int xPos, int yPos, ClimateType type, IClimateData data) {
|
||||
public WidgetClimatePanel(WidgetManager manager, GuiGreenhouse gui, int xPos, int yPos, ClimateType type) {
|
||||
super(manager, xPos, yPos);
|
||||
this.width = 85;
|
||||
this.height = 98;
|
||||
this.type = type;
|
||||
this.gui = gui;
|
||||
int textFieldLength = 50;
|
||||
textField = new GuiTextField(0, Minecraft.getMinecraft().fontRenderer, xPos + width / 2 - textFieldLength / 2, yPos + 14, textFieldLength, 10);
|
||||
textField = new GuiTextField(0, Minecraft.getMinecraft().fontRenderer, xPos + width / 2 - TEXT_FIELD_LENGTH / 2, yPos + 14, TEXT_FIELD_LENGTH, 10);
|
||||
textField.setValidator(NUMBER_FILTER);
|
||||
textField.setEnableBackgroundDrawing(false);
|
||||
IClimateState climateState = gui.container.getTargetedState();
|
||||
@@ -76,9 +75,6 @@ public class WidgetClimatePanel extends Widget {
|
||||
textField.setEnabled(false);
|
||||
}
|
||||
table = new Table();
|
||||
for (Map.Entry<String, Float> entry : data.getData(type).entrySet()) {
|
||||
table.addValueEntry(entry.getKey(), StringUtil.floatAsPercent(entry.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,7 +82,7 @@ public class WidgetClimatePanel extends Widget {
|
||||
GlStateManager.color(1.0f, 1.0f, 1.0f);
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
mc.getTextureManager().bindTexture(gui.textureFile);
|
||||
gui.drawTexturedModalRect(startX + textField.x - 2, startY + textField.y - 2, 204, 115, 52, 12);
|
||||
gui.drawTexturedModalRect(startX + textField.x - 2, startY + textField.y - 2, 196, 50, 52, 12);
|
||||
|
||||
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
|
||||
String title = Translator.translateToLocal("for.gui." + type.getName());
|
||||
@@ -95,9 +91,29 @@ public class WidgetClimatePanel extends Widget {
|
||||
GlStateManager.color(1.0f, 1.0f, 1.0f);
|
||||
textField.drawTextBox();
|
||||
|
||||
updateData();
|
||||
table.draw(xPos + startX - 2, yPos + startY + 26, 14737632, false);
|
||||
}
|
||||
|
||||
private int updateTimer = 0;
|
||||
|
||||
private void updateData(){
|
||||
if(updateTimer > 0){
|
||||
updateTimer--;
|
||||
return;
|
||||
}
|
||||
updateTimer = 40;
|
||||
table.clear();
|
||||
IClimateData data = gui.container.getData();
|
||||
for (Map.Entry<String, Float> entry : data.getData(type).entrySet()) {
|
||||
float value = entry.getValue();
|
||||
int percent = (int)(value * 100);
|
||||
if(percent != 0) {
|
||||
table.addValueEntry(entry.getKey(), percent + " %");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseClick(int mouseX, int mouseY, int mouseButton) {
|
||||
boolean wasFocused = textField.isFocused();
|
||||
|
||||
@@ -401,7 +401,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
limits = createLimits();
|
||||
if(!climateContainer.getTargetedState().isPresent()) {
|
||||
IClimateState defaultClimate = getDefaultClimate();
|
||||
climateContainer.setState(defaultClimate.toMutable());
|
||||
climateContainer.setState(defaultClimate.toState(ClimateStateType.MUTABLE));
|
||||
climateContainer.setTargetedState(defaultClimate);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user