aboutsummaryrefslogtreecommitdiff
path: root/src/Java/binnie/craftgui/extratrees/dictionary/PageSpeciesTreeGenome.java
blob: 22a1a67b296b5e527cacc2728749a246863366fd (plain)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package binnie.craftgui.extratrees.dictionary;

import binnie.Binnie;
import binnie.core.BinnieCore;
import binnie.core.genetics.BreedingSystem;
import binnie.core.genetics.ManagerGenetics;
import binnie.core.proxy.BinnieProxy;
import binnie.craftgui.controls.ControlText;
import binnie.craftgui.controls.core.Control;
import binnie.craftgui.controls.scroll.ControlScrollableContent;
import binnie.craftgui.core.IWidget;
import binnie.craftgui.core.geometry.IArea;
import binnie.craftgui.core.geometry.IPoint;
import binnie.craftgui.core.geometry.TextJustification;
import binnie.craftgui.minecraft.control.ControlItemDisplay;
import binnie.craftgui.mod.database.DatabaseTab;
import binnie.craftgui.mod.database.PageSpecies;
import binnie.extratrees.ExtraTrees;
import binnie.extratrees.proxy.Proxy;
import forestry.api.arboriculture.EnumTreeChromosome;
import forestry.api.arboriculture.IAlleleTreeSpecies;
import forestry.api.arboriculture.IFruitProvider;
import forestry.api.arboriculture.IGrowthProvider;
import forestry.api.arboriculture.ITree;
import forestry.api.arboriculture.ITreeGenome;
import forestry.api.arboriculture.ITreeRoot;
import forestry.api.core.EnumTemperature;
import forestry.api.core.ForestryAPI;
import forestry.api.core.ITextureManager;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IAlleleSpecies;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.EnumPlantType;

public class PageSpeciesTreeGenome
  extends PageSpecies
{
  public PageSpeciesTreeGenome(IWidget parent, DatabaseTab tab)
  {
    super(parent, tab);
  }
  
  public void onValueChanged(IAlleleSpecies species)
  {
    deleteAllChildren();
    IAllele[] template = Binnie.Genetics.getTreeRoot().getTemplate(species.getUID());
    if (template == null) {
      return;
    }
    ITree tree = Binnie.Genetics.getTreeRoot().templateAsIndividual(template);
    if (tree == null) {
      return;
    }
    ITreeGenome genome = tree.getGenome();
    IAlleleTreeSpecies treeSpecies = genome.getPrimary();
    
    int w = 144;
    int h = 176;
    
    new ControlText(this, new IArea(0.0F, 4.0F, w, 16.0F), ((DatabaseTab)getValue()).toString(), TextJustification.MiddleCenter);
    
    ControlScrollableContent scrollable = new ControlScrollableContent(this, 4.0F, 20.0F, w - 8, h - 8 - 16, 12.0F);
    
    Control contents = new Control(scrollable, 0.0F, 0.0F, w - 8 - 12, h - 8 - 16);
    
    int tw = w - 8 - 12;
    int w1 = 65;
    int w2 = tw - 50;
    int y = 0;
    int th = 14;
    int th2 = 18;
    
    BreedingSystem syst = Binnie.Genetics.treeBreedingSystem;
    
    new ControlText(contents, new IArea(0.0F, y, w1, th), syst.getChromosomeShortName(EnumTreeChromosome.PLANT) + " : ", TextJustification.MiddleRight);
    new ControlText(contents, new IArea(w1, y, w2, th), treeSpecies.getPlantType().toString(), TextJustification.MiddleLeft);
    
    y += th;
    
    new ControlText(contents, new IArea(0.0F, y, w1, th), BinnieCore.proxy.localise("gui.temperature.short") + " : ", TextJustification.MiddleRight);
    new ControlText(contents, new IArea(w1, y, w2, th), treeSpecies.getTemperature().getName(), TextJustification.MiddleLeft);
    
    y += th;
    
    IIcon leaf = ForestryAPI.textureManager.getIcon(treeSpecies.getLeafIconIndex(tree, false));
    
    IIcon fruit = null;
    int fruitColour = 16777215;
    try
    {
      fruit = ForestryAPI.textureManager.getIcon(genome.getFruitProvider().getIconIndex(genome, null, 0, 0, 0, 100, false));
      fruitColour = genome.getFruitProvider().getColour(genome, null, 0, 0, 0, 100);
    }
    catch (Exception e) {}
    if (leaf != null)
    {
      new ControlText(contents, new IArea(0.0F, y, w1, th2), ExtraTrees.proxy.localise("gui.database.leaves") + " : ", TextJustification.MiddleRight);
      
      new ControlBlockIconDisplay(contents, w1, y, leaf).setColour(treeSpecies.getLeafColour(tree));
      if ((fruit != null) && (!treeSpecies.getUID().equals("forestry.treeOak"))) {
        new ControlBlockIconDisplay(contents, w1, y, fruit).setColour(fruitColour);
      }
      y += th2;
    }
    ItemStack log = treeSpecies.getLogStacks().length > 0 ? treeSpecies.getLogStacks()[0] : null;
    if (log != null)
    {
      new ControlText(contents, new IArea(0.0F, y, w1, th2), ExtraTrees.proxy.localise("gui.database.log") + " : ", TextJustification.MiddleRight);
      
      ControlItemDisplay display = new ControlItemDisplay(contents, w1, y);
      display.setItemStack(log);
      display.setTooltip();
      
      y += th2;
    }
    new ControlText(contents, new IArea(0.0F, y, w1, th), syst.getChromosomeShortName(EnumTreeChromosome.GROWTH) + " : ", TextJustification.MiddleRight);
    new ControlText(contents, new IArea(w1, y, w2, th), genome.getGrowthProvider().getDescription(), TextJustification.MiddleLeft);
    y += th;
    
    new ControlText(contents, new IArea(0.0F, y, w1, th), syst.getChromosomeShortName(EnumTreeChromosome.HEIGHT) + " : ", TextJustification.MiddleRight);
    new ControlText(contents, new IArea(w1, y, w2, th), genome.getHeight() + "x", TextJustification.MiddleLeft);
    y += th;
    
    new ControlText(contents, new IArea(0.0F, y, w1, th), syst.getChromosomeShortName(EnumTreeChromosome.FERTILITY) + " : ", TextJustification.MiddleRight);
    new ControlText(contents, new IArea(w1, y, w2, th), genome.getFertility() + "x", TextJustification.MiddleLeft);
    y += th;
    
    List<ItemStack> fruits = new ArrayList();
    for (ItemStack stack : genome.getFruitProvider().getProducts()) {
      fruits.add(stack);
    }
    if (!fruits.isEmpty())
    {
      new ControlText(contents, new IArea(0.0F, y, w1, th2), syst.getChromosomeShortName(EnumTreeChromosome.FRUITS) + " : ", TextJustification.MiddleRight);
      for (ItemStack fruitw : fruits)
      {
        ControlItemDisplay display = new ControlItemDisplay(contents, w1, y);
        display.setItemStack(fruitw);
        display.setTooltip();
        
        y += th2;
      }
    }
    new ControlText(contents, new IArea(0.0F, y, w1, th), syst.getChromosomeShortName(EnumTreeChromosome.YIELD) + " : ", TextJustification.MiddleRight);
    new ControlText(contents, new IArea(w1, y, w2, th), genome.getYield() + "x", TextJustification.MiddleLeft);
    y += th;
    
    new ControlText(contents, new IArea(0.0F, y, w1, th), syst.getChromosomeShortName(EnumTreeChromosome.SAPPINESS) + " : ", TextJustification.MiddleRight);
    new ControlText(contents, new IArea(w1, y, w2, th), genome.getSappiness() + "x", TextJustification.MiddleLeft);
    y += th;
    
    new ControlText(contents, new IArea(0.0F, y, w1, th), syst.getChromosomeShortName(EnumTreeChromosome.MATURATION) + " : ", TextJustification.MiddleRight);
    new ControlText(contents, new IArea(w1, y, w2, th), genome.getMaturationTime() + "x", TextJustification.MiddleLeft);
    y += th;
    
    new ControlText(contents, new IArea(0.0F, y, w1, th), syst.getChromosomeShortName(EnumTreeChromosome.GIRTH) + " : ", TextJustification.MiddleRight);
    new ControlText(contents, new IArea(w1, y, w2, th), genome.getGirth() + "x" + genome.getGirth(), TextJustification.MiddleLeft);
    y += th;
    
    contents.setSize(new IPoint(contents.size().x(), y));
    
    scrollable.setScrollableContent(contents);
  }
  
  public static String tolerated(boolean t)
  {
    if (t) {
      return BinnieCore.proxy.localise("gui.tolerated");
    }
    return BinnieCore.proxy.localise("gui.nottolerated");
  }
}