Search in sources :

Example 6 with DisplaySettings

use of watson.DisplaySettings in project watson by totemo.

the class PlayerEditSet method drawVectors.

// --------------------------------------------------------------------------
/**
   * Draw direction vectors indicating motion of the miner.
   *
   * @param colour the colour to draw the vectors.
   */
public synchronized void drawVectors(ARGB colour) {
    DisplaySettings settings = Controller.instance.getDisplaySettings();
    if (settings.areVectorsShown() && isVisible() && !_edits.isEmpty()) {
        final Tessellator tess = Tessellator.getInstance();
        final WorldRenderer wr = tess.getWorldRenderer();
        wr.startDrawing(GL11.GL_LINES);
        // TODO: Make the vector colour and thickness configurable.
        wr.setColorRGBA_I(colour.getRGB(), colour.getAlpha());
        GL11.glLineWidth(0.5f);
        // Unit X and Y vectors used for cross products to get arrow axes.
        Vec3 unitX = new Vec3(1, 0, 0);
        Vec3 unitY = new Vec3(0, 1, 0);
        // We only need to draw vectors if there are at least 2 edits.
        Iterator<BlockEdit> it = _edits.iterator();
        if (it.hasNext()) {
            BlockEdit prev = it.next();
            while (it.hasNext()) {
                BlockEdit next = it.next();
                // Work out whether to link edits with vectors.
                boolean show = (next.creation && settings.isLinkedCreations()) || (!next.creation && settings.isLinkedDestructions());
                if (show) {
                    Vec3 pPos = new Vec3(0.5 + prev.x, 0.5 + prev.y, 0.5 + prev.z);
                    Vec3 nPos = new Vec3(0.5 + next.x, 0.5 + next.y, 0.5 + next.z);
                    // Vector difference, from prev to next.
                    Vec3 diff = nPos.subtract(pPos);
                    // Compute length. We want to scale the arrow heads by the length,
                    // so can't avoid the sqrt() here.
                    double length = diff.lengthVector();
                    if (length >= settings.getMinVectorLength()) {
                        // Draw the vector.
                        wr.addVertex(pPos.xCoord, pPos.yCoord, pPos.zCoord);
                        wr.addVertex(nPos.xCoord, nPos.yCoord, nPos.zCoord);
                        // Length from arrow tip to midpoint of vector as a fraction of
                        // the total vector length. Scale the arrow in proportion to the
                        // square root of the length up to a maximum size.
                        double arrowSize = UNIT_VECTOR_ARROW_SIZE * Math.sqrt(length);
                        if (arrowSize > MAX_ARROW_SIZE) {
                            arrowSize = MAX_ARROW_SIZE;
                        }
                        double arrowScale = arrowSize / length;
                        // Position of the tip and tail of the arrow, sitting in the
                        // middle of the vector.
                        Vec3 tip = new Vec3(pPos.xCoord * (0.5 - arrowScale) + nPos.xCoord * (0.5 + arrowScale), pPos.yCoord * (0.5 - arrowScale) + nPos.yCoord * (0.5 + arrowScale), pPos.zCoord * (0.5 - arrowScale) + nPos.zCoord * (0.5 + arrowScale));
                        Vec3 tail = new Vec3(pPos.xCoord * (0.5 + arrowScale) + nPos.xCoord * (0.5 - arrowScale), pPos.yCoord * (0.5 + arrowScale) + nPos.yCoord * (0.5 - arrowScale), pPos.zCoord * (0.5 + arrowScale) + nPos.zCoord * (0.5 - arrowScale));
                        // Fin axes, perpendicular to vector. Scale by vector length.
                        // If the vector is colinear with the Y axis, use the X axis for
                        // the cross products to derive the fin directions.
                        Vec3 fin1;
                        if (Math.abs(unitY.dotProduct(diff)) > 0.9 * length) {
                            fin1 = unitX.crossProduct(diff).normalize();
                        } else {
                            fin1 = unitY.crossProduct(diff).normalize();
                        }
                        Vec3 fin2 = fin1.crossProduct(diff).normalize();
                        Vec3 draw1 = new Vec3(fin1.xCoord * arrowScale * length, fin1.yCoord * arrowScale * length, fin1.zCoord * arrowScale * length);
                        Vec3 draw2 = new Vec3(fin2.xCoord * arrowScale * length, fin2.yCoord * arrowScale * length, fin2.zCoord * arrowScale * length);
                        // Draw four fins.
                        wr.addVertex(tip.xCoord, tip.yCoord, tip.zCoord);
                        wr.addVertex(tail.xCoord + draw1.xCoord, tail.yCoord + draw1.yCoord, tail.zCoord + draw1.zCoord);
                        wr.addVertex(tip.xCoord, tip.yCoord, tip.zCoord);
                        wr.addVertex(tail.xCoord - draw1.xCoord, tail.yCoord - draw1.yCoord, tail.zCoord - draw1.zCoord);
                        wr.addVertex(tip.xCoord, tip.yCoord, tip.zCoord);
                        wr.addVertex(tail.xCoord + draw2.xCoord, tail.yCoord + draw2.yCoord, tail.zCoord + draw2.zCoord);
                        wr.addVertex(tip.xCoord, tip.yCoord, tip.zCoord);
                        wr.addVertex(tail.xCoord - draw2.xCoord, tail.yCoord - draw2.yCoord, tail.zCoord - draw2.zCoord);
                    }
                    // if we are drawing this vector
                    prev = next;
                }
            // if
            }
            // while
            tess.draw();
        }
    // if
    }
// if drawing
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) Vec3(net.minecraft.util.Vec3) DisplaySettings(watson.DisplaySettings) WorldRenderer(net.minecraft.client.renderer.WorldRenderer)

Example 7 with DisplaySettings

use of watson.DisplaySettings in project watson by totemo.

the class WatsonGuiScreen method initGui.

// --------------------------------------------------------------------------
/**
   * @see GuiScreen#initGui()
   */
@SuppressWarnings("unchecked")
@Override
public void initGui() {
    Minecraft mc = Minecraft.getMinecraft();
    FontRenderer fr = mc.fontRendererObj;
    _rowHeight = (int) (fr.FONT_HEIGHT * 2.75);
    int startY = height / 2 - 4 * _rowHeight;
    int currentRow = 0;
    buttonList.clear();
    buttonList.add(new GuiButton(ID_SHOW_WATSON, width / 2 - 175, startY + currentRow * _rowHeight, 150, 20, getButtonLabel(ID_SHOW_WATSON)));
    buttonList.add(new GuiButton(ID_CLEAR_EDITS, width / 2 + 25, startY + currentRow++ * _rowHeight, 150, 20, getButtonLabel(ID_CLEAR_EDITS)));
    buttonList.add(new GuiButton(ID_SHOW_VECTORS, width / 2 - 175, startY + currentRow * _rowHeight, 150, 20, getButtonLabel(ID_SHOW_VECTORS)));
    GuiResponder sliderResponder = new GuiPageButtonList.GuiResponder() {

        @Override
        public void onTick(int id, float value) {
            // Update the display when the slider slides. Save the new length in
            // the configuration when the GUI closes.
            DisplaySettings ds = Controller.instance.getDisplaySettings();
            ds.setMinVectorLength((int) value, false);
        }

        @Override
        public void func_175321_a(int id, boolean value) {
        }

        @Override
        public void func_175319_a(int id, String value) {
        }
    };
    Configuration config = Configuration.instance;
    GuiSlider slider = new GuiSlider(sliderResponder, ID_MIN_VECTOR_LENGTH, width / 2 + 25, startY + currentRow++ * _rowHeight, "Min Vector Length", 0, 20, config.getVectorLength(), new GuiSlider.FormatHelper() {

        @Override
        public String getText(int id, String name, float value) {
            return "Min Vector Length: " + Integer.toString((int) value);
        }
    });
    buttonList.add(slider);
    buttonList.add(new GuiButton(ID_SHOW_LABELS, width / 2 - 175, startY + currentRow * _rowHeight, 150, 20, getButtonLabel(ID_SHOW_LABELS)));
    buttonList.add(new GuiButton(ID_LABEL_ORDER, width / 2 + 25, startY + currentRow++ * _rowHeight, 150, 20, getButtonLabel(ID_LABEL_ORDER)));
    buttonList.add(new GuiButton(ID_SHOW_ANNOTATIONS, width / 2 - 175, startY + currentRow * _rowHeight, 150, 20, getButtonLabel(ID_SHOW_ANNOTATIONS)));
    buttonList.add(new GuiButton(ID_SHOW_SELECTION, width / 2 + 25, startY + currentRow++ * _rowHeight, 150, 20, getButtonLabel(ID_SHOW_SELECTION)));
    buttonList.add(new GuiOptionButton(ID_DONE, width / 2 - 40, startY + (currentRow + 2) * _rowHeight, 80, 20, I18n.format("gui.done", new Object[0])));
    enableButtons();
}
Also used : GuiResponder(net.minecraft.client.gui.GuiPageButtonList.GuiResponder) Configuration(watson.Configuration) GuiOptionButton(net.minecraft.client.gui.GuiOptionButton) GuiSlider(net.minecraft.client.gui.GuiSlider) Minecraft(net.minecraft.client.Minecraft) GuiButton(net.minecraft.client.gui.GuiButton) FontRenderer(net.minecraft.client.gui.FontRenderer) DisplaySettings(watson.DisplaySettings)

Example 8 with DisplaySettings

use of watson.DisplaySettings in project watson by totemo.

the class WatsonGuiScreen method getButtonLabel.

// actionPerformed
// --------------------------------------------------------------------------
/**
   * Return the label text for a toggle button, based on its ID.
   *
   * @param id the control ID.
   * @return the label text for a toggle button, based on its ID.
   */
protected String getButtonLabel(int id) {
    DisplaySettings ds = Controller.instance.getDisplaySettings();
    Configuration config = Configuration.instance;
    switch(id) {
        case ID_CLEAR_EDITS:
            return "Clear Edits";
        case ID_SHOW_WATSON:
            return "Watson Display: " + (ds.isDisplayed() ? "ON" : "OFF");
        case ID_SHOW_VECTORS:
            return "Show Vectors: " + (ds.areVectorsShown() ? "ON" : "OFF");
        case ID_MIN_VECTOR_LENGTH:
            // Slider uses a callback to set text.
            return "";
        case ID_SHOW_LABELS:
            return "Show Labels: " + (ds.areLabelsShown() ? "ON" : "OFF");
        case ID_LABEL_ORDER:
            return "Label Order: " + (config.timeOrderedDeposits() ? "TIMESTAMPS" : "IMPORTANCE");
        case ID_SHOW_ANNOTATIONS:
            return "Show Annotations: " + (ds.areAnnotationsShown() ? "ON" : "OFF");
        case ID_SHOW_SELECTION:
            return "Show Selection: " + (ds.isSelectionShown() ? "ON" : "OFF");
        default:
            return "";
    }
}
Also used : Configuration(watson.Configuration) DisplaySettings(watson.DisplaySettings)

Aggregations

DisplaySettings (watson.DisplaySettings)8 Configuration (watson.Configuration)4 Minecraft (net.minecraft.client.Minecraft)1 FontRenderer (net.minecraft.client.gui.FontRenderer)1 GuiButton (net.minecraft.client.gui.GuiButton)1 GuiOptionButton (net.minecraft.client.gui.GuiOptionButton)1 GuiResponder (net.minecraft.client.gui.GuiPageButtonList.GuiResponder)1 GuiSlider (net.minecraft.client.gui.GuiSlider)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 WorldRenderer (net.minecraft.client.renderer.WorldRenderer)1 Vec3 (net.minecraft.util.Vec3)1 Filters (watson.db.Filters)1 OreDB (watson.db.OreDB)1