Search in sources :

Example 1 with StringBuilder

use of com.badlogic.gdx.utils.StringBuilder in project libgdx by libgdx.

the class Hiero method initializeEvents.

private void initializeEvents() {
    fontList.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent evt) {
            if (evt.getValueIsAdjusting())
                return;
            prefs.put("system.font", (String) fontList.getSelectedValue());
            updateFont();
        }
    });
    class FontUpdateListener implements ChangeListener, ActionListener {

        public void stateChanged(ChangeEvent evt) {
            updateFont();
        }

        public void actionPerformed(ActionEvent evt) {
            updateFont();
        }

        public void addSpinners(JSpinner[] spinners) {
            for (int i = 0; i < spinners.length; i++) {
                final JSpinner spinner = spinners[i];
                spinner.addChangeListener(this);
                ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().addKeyListener(new KeyAdapter() {

                    String lastText;

                    public void keyReleased(KeyEvent evt) {
                        JFormattedTextField textField = ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField();
                        String text = textField.getText();
                        if (text.length() == 0)
                            return;
                        if (text.equals(lastText))
                            return;
                        lastText = text;
                        int caretPosition = textField.getCaretPosition();
                        try {
                            spinner.setValue(Integer.valueOf(text));
                        } catch (NumberFormatException ex) {
                        }
                        textField.setCaretPosition(caretPosition);
                    }
                });
            }
        }
    }
    FontUpdateListener listener = new FontUpdateListener();
    listener.addSpinners(new JSpinner[] { padTopSpinner, padRightSpinner, padBottomSpinner, padLeftSpinner, padAdvanceXSpinner, padAdvanceYSpinner });
    fontSizeSpinner.addChangeListener(listener);
    gammaSpinner.addChangeListener(listener);
    glyphPageWidthCombo.addActionListener(listener);
    glyphPageHeightCombo.addActionListener(listener);
    boldCheckBox.addActionListener(listener);
    italicCheckBox.addActionListener(listener);
    monoCheckBox.addActionListener(listener);
    resetCacheButton.addActionListener(listener);
    javaRadio.addActionListener(listener);
    nativeRadio.addActionListener(listener);
    freeTypeRadio.addActionListener(listener);
    sampleTextRadio.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            glyphCachePanel.setVisible(false);
        }
    });
    glyphCacheRadio.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            glyphCachePanel.setVisible(true);
        }
    });
    fontFileText.getDocument().addDocumentListener(new DocumentListener() {

        public void removeUpdate(DocumentEvent evt) {
            changed();
        }

        public void insertUpdate(DocumentEvent evt) {
            changed();
        }

        public void changedUpdate(DocumentEvent evt) {
            changed();
        }

        private void changed() {
            File file = new File(fontFileText.getText());
            if (fontList.isEnabled() && (!file.exists() || !file.isFile()))
                return;
            prefs.put("font.file", fontFileText.getText());
            updateFont();
        }
    });
    final ActionListener al = new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            updateFontSelector();
            updateFont();
        }
    };
    systemFontRadio.addActionListener(al);
    fontFileRadio.addActionListener(al);
    browseButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            FileDialog dialog = new FileDialog(Hiero.this, "Choose TrueType font file", FileDialog.LOAD);
            dialog.setLocationRelativeTo(null);
            dialog.setFile("*.ttf");
            dialog.setDirectory(prefs.get("dir.font", ""));
            dialog.setVisible(true);
            if (dialog.getDirectory() != null) {
                prefs.put("dir.font", dialog.getDirectory());
            }
            String fileName = dialog.getFile();
            if (fileName == null)
                return;
            fontFileText.setText(new File(dialog.getDirectory(), fileName).getAbsolutePath());
        }
    });
    backgroundColorLabel.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent evt) {
            java.awt.Color color = JColorChooser.showDialog(null, "Choose a background color", EffectUtil.fromString(prefs.get("background", "000000")));
            if (color == null)
                return;
            renderingBackgroundColor = new Color(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, 1);
            backgroundColorLabel.setIcon(getColorIcon(color));
            prefs.put("background", EffectUtil.toString(color));
        }
    });
    effectsList.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent evt) {
            ConfigurableEffect selectedEffect = (ConfigurableEffect) effectsList.getSelectedValue();
            boolean enabled = selectedEffect != null;
            for (Iterator iter = effectPanels.iterator(); iter.hasNext(); ) {
                ConfigurableEffect effect = ((EffectPanel) iter.next()).getEffect();
                if (effect == selectedEffect) {
                    enabled = false;
                    break;
                }
            }
            addEffectButton.setEnabled(enabled);
        }
    });
    effectsList.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent evt) {
            if (evt.getClickCount() == 2 && addEffectButton.isEnabled())
                addEffectButton.doClick();
        }
    });
    addEffectButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            new EffectPanel((ConfigurableEffect) effectsList.getSelectedValue());
        }
    });
    openMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            FileDialog dialog = new FileDialog(Hiero.this, "Open Hiero settings file", FileDialog.LOAD);
            dialog.setLocationRelativeTo(null);
            dialog.setFile("*.hiero");
            dialog.setDirectory(prefs.get("dir.open", ""));
            dialog.setVisible(true);
            if (dialog.getDirectory() != null) {
                prefs.put("dir.open", dialog.getDirectory());
            }
            String fileName = dialog.getFile();
            if (fileName == null)
                return;
            lastOpenFilename = fileName;
            open(new File(dialog.getDirectory(), fileName));
        }
    });
    saveMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            FileDialog dialog = new FileDialog(Hiero.this, "Save Hiero settings file", FileDialog.SAVE);
            dialog.setLocationRelativeTo(null);
            dialog.setFile("*.hiero");
            dialog.setDirectory(prefs.get("dir.save", ""));
            if (lastSaveFilename.length() > 0) {
                dialog.setFile(lastSaveFilename);
            } else if (lastOpenFilename.length() > 0) {
                dialog.setFile(lastOpenFilename);
            }
            dialog.setVisible(true);
            if (dialog.getDirectory() != null) {
                prefs.put("dir.save", dialog.getDirectory());
            }
            String fileName = dialog.getFile();
            if (fileName == null)
                return;
            if (!fileName.endsWith(".hiero"))
                fileName += ".hiero";
            lastSaveFilename = fileName;
            File file = new File(dialog.getDirectory(), fileName);
            try {
                save(file);
            } catch (IOException ex) {
                throw new RuntimeException("Error saving Hiero settings file: " + file.getAbsolutePath(), ex);
            }
        }
    });
    saveBMFontMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            FileDialog dialog = new FileDialog(Hiero.this, "Save BMFont files", FileDialog.SAVE);
            dialog.setLocationRelativeTo(null);
            dialog.setFile("*.fnt");
            dialog.setDirectory(prefs.get("dir.savebm", ""));
            if (lastSaveBMFilename.length() > 0) {
                dialog.setFile(lastSaveBMFilename);
            } else if (lastOpenFilename.length() > 0) {
                dialog.setFile(lastOpenFilename.replace(".hiero", ".fnt"));
            }
            dialog.setVisible(true);
            if (dialog.getDirectory() != null) {
                prefs.put("dir.savebm", dialog.getDirectory());
            }
            String fileName = dialog.getFile();
            if (fileName == null)
                return;
            lastSaveBMFilename = fileName;
            saveBm(new File(dialog.getDirectory(), fileName));
        }
    });
    exitMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            dispose();
        }
    });
    sampleNeheButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            sampleTextPane.setText(NEHE_CHARS);
            resetCacheButton.doClick();
        }
    });
    sampleAsciiButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            StringBuilder buffer = new StringBuilder();
            buffer.append(NEHE_CHARS);
            buffer.append('\n');
            int count = 0;
            for (int i = 33; i <= 255; i++) {
                if (buffer.indexOf(Character.toString((char) i)) != -1)
                    continue;
                buffer.append((char) i);
                if (++count % 30 == 0)
                    buffer.append('\n');
            }
            sampleTextPane.setText(buffer.toString());
            resetCacheButton.doClick();
        }
    });
    sampleExtendedButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            sampleTextPane.setText(EXTENDED_CHARS);
            resetCacheButton.doClick();
        }
    });
}
Also used : DocumentListener(javax.swing.event.DocumentListener) StringBuilder(com.badlogic.gdx.utils.StringBuilder) ActionEvent(java.awt.event.ActionEvent) ConfigurableEffect(com.badlogic.gdx.tools.hiero.unicodefont.effects.ConfigurableEffect) KeyAdapter(java.awt.event.KeyAdapter) ListSelectionEvent(javax.swing.event.ListSelectionEvent) KeyEvent(java.awt.event.KeyEvent) Iterator(java.util.Iterator) ChangeListener(javax.swing.event.ChangeListener) MouseEvent(java.awt.event.MouseEvent) Color(com.badlogic.gdx.graphics.Color) JFormattedTextField(javax.swing.JFormattedTextField) MouseAdapter(java.awt.event.MouseAdapter) IOException(java.io.IOException) DocumentEvent(javax.swing.event.DocumentEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) JSpinner(javax.swing.JSpinner) File(java.io.File) FileDialog(java.awt.FileDialog)

Example 2 with StringBuilder

use of com.badlogic.gdx.utils.StringBuilder in project libgdx by libgdx.

the class VBOWithVAOPerformanceTest method create.

@Override
public void create() {
    if (Gdx.gl30 == null) {
        throw new GdxRuntimeException("GLES 3.0 profile required for this test");
    }
    String vertexShader = "attribute vec4 a_position;    \n" + "attribute vec4 a_color;\n" + "attribute vec2 a_texCoord0;\n" + "uniform mat4 u_worldView;\n" + "varying vec4 v_color;" + "varying vec2 v_texCoords;" + "void main()                  \n" + "{                            \n" + "   v_color = a_color; \n" + "   v_texCoords = a_texCoord0; \n" + "   gl_Position =  u_worldView * a_position;  \n" + "}                            \n";
    String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "varying vec4 v_color;\n" + "varying vec2 v_texCoords;\n" + "uniform sampler2D u_texture;\n" + "void main()                                  \n" + "{                                            \n" + "  gl_FragColor = v_color * texture2D(u_texture, v_texCoords);\n" + "}";
    shader = new ShaderProgram(vertexShader, fragmentShader);
    if (shader.isCompiled() == false) {
        Gdx.app.log("ShaderTest", shader.getLog());
        Gdx.app.exit();
    }
    int numSprites = 1000;
    int maxIndices = numSprites * 6;
    int maxVertices = numSprites * 6;
    VertexAttribute[] vertexAttributes = new VertexAttribute[] { VertexAttribute.Position(), VertexAttribute.ColorUnpacked(), VertexAttribute.TexCoords(0) };
    VertexBufferObjectWithVAO newVBOWithVAO = new VertexBufferObjectWithVAO(false, maxVertices, vertexAttributes);
    OldVertexBufferObjectWithVAO oldVBOWithVAO = new OldVertexBufferObjectWithVAO(false, maxVertices, vertexAttributes);
    IndexBufferObjectSubData newIndices = new IndexBufferObjectSubData(false, maxIndices);
    IndexBufferObjectSubData oldIndices = new IndexBufferObjectSubData(false, maxIndices);
    newVBOWithVAOMesh = new Mesh(newVBOWithVAO, newIndices, false) {
    };
    oldVBOWithVAOMesh = new Mesh(oldVBOWithVAO, oldIndices, false) {
    };
    float[] vertexArray = new float[maxVertices * 9];
    int index = 0;
    int stride = 9 * 6;
    for (int i = 0; i < numSprites; i++) {
        addRandomSprite(vertexArray, index);
        index += stride;
    }
    short[] indexArray = new short[maxIndices];
    for (short i = 0; i < maxIndices; i++) {
        indexArray[i] = i;
    }
    newVBOWithVAOMesh.setVertices(vertexArray);
    newVBOWithVAOMesh.setIndices(indexArray);
    oldVBOWithVAOMesh.setVertices(vertexArray);
    oldVBOWithVAOMesh.setIndices(indexArray);
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    batch = new SpriteBatch();
    bitmapFont = new BitmapFont();
    stringBuilder = new StringBuilder();
}
Also used : IndexBufferObjectSubData(com.badlogic.gdx.graphics.glutils.IndexBufferObjectSubData) StringBuilder(com.badlogic.gdx.utils.StringBuilder) Mesh(com.badlogic.gdx.graphics.Mesh) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) VertexBufferObjectWithVAO(com.badlogic.gdx.graphics.glutils.VertexBufferObjectWithVAO) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 3 with StringBuilder

use of com.badlogic.gdx.utils.StringBuilder in project Eidolons by IDemiurge.

the class ValueContainer method cropName.

public void cropName() {
    if (nameContainer.getActor() != null) {
        StringBuilder text = nameContainer.getActor().getText();
        text.replace("Modifier", "Mod");
        text.replace("Damage", "Dmg");
        text.replace("Capacity", "Cap.");
        text.replace("Protection", "Prot.");
        text.replace("Penalty", "Pen.");
        text.replace("Restoration", "Rest");
        text.replace("Concentration", "Concentr");
        text.replace("Memorization", "Memorize");
        text.replace("Retainment", "Retain");
        text.replace("Close Quarters", "Close");
        text.replace("Long Reach", "Long");
        text.replace("Defense", "Def.");
        text.replace("Sneak", "Snk.");
        text.replace("Cadence", "Cad.");
        text.replace("Watch", "W.");
        text.replace("Attack", "Attk");
        text.replace("Penetration", "Penetr.");
        text.replace("Diagonal", "Diag.");
        if (StringUtils.contains(text, "Chance")) {
            text.replace("Chance", "");
            if (valueContainer.getActor() != null) {
                if (valueContainer.getActor() instanceof Label) {
                    final Label actor = valueContainer.getActor();
                    actor.getText().append("%");
                }
            }
        }
    }
}
Also used : StringBuilder(com.badlogic.gdx.utils.StringBuilder) Label(com.badlogic.gdx.scenes.scene2d.ui.Label)

Example 4 with StringBuilder

use of com.badlogic.gdx.utils.StringBuilder in project Eidolons by IDemiurge.

the class SpecialLogger method getBuilder.

private StringBuilder getBuilder(SPECIAL_LOG log) {
    StringBuilder builder = builderMap.get(log);
    if (builder == null) {
        builder = new StringBuilder();
        builderMap.put(log, builder);
    }
    return builder;
}
Also used : StringBuilder(com.badlogic.gdx.utils.StringBuilder)

Example 5 with StringBuilder

use of com.badlogic.gdx.utils.StringBuilder in project Eidolons by IDemiurge.

the class DC_LogManager method logBattle.

public void logBattle(boolean start) {
    StringBuilder text = new StringBuilder();
    if (start)
        text.append("Combat started, opponents: ");
    else
        text.append("Combat ended, enemies slain: ");
    // TODO + "N"
    Map<String, Integer> map = new LinkedHashMap<>();
    getGame().getUnits().forEach(unit -> {
        if (unit.isHostileTo(getGame().getPlayer(true)))
            if (!unit.getAI().isOutsideCombat())
                if ((!start && unit.isDead()) || (start && unit.getPlayerVisionStatus(false) != PLAYER_VISION.INVISIBLE)) {
                    String name = unit.getNameIfKnown();
                    if (map.containsKey(name))
                        MapMaster.addToIntegerMap(map, name, 1);
                    else {
                        map.put(name, 1);
                    }
                }
    });
    map.keySet().forEach(unit -> {
        int i = map.get(unit);
        if (i > 1) {
            unit = unit + StringMaster.wrapInParenthesis(i + "");
        }
        text.append(unit + ", ");
    });
    text.delete(text.length() - 2, text.length());
    String message = text.toString();
    SpecialLogger.getInstance().appendSpecialLog(SPECIAL_LOG.MAIN, message);
    SpecialLogger.getInstance().appendSpecialLog(SPECIAL_LOG.COMBAT, message);
    log(message);
}
Also used : StringBuilder(com.badlogic.gdx.utils.StringBuilder) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

StringBuilder (com.badlogic.gdx.utils.StringBuilder)10 FileHandle (com.badlogic.gdx.files.FileHandle)2 Texture (com.badlogic.gdx.graphics.Texture)2 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)2 Array (com.badlogic.gdx.utils.Array)2 IntArray (com.badlogic.gdx.utils.IntArray)2 AttributedString (java.text.AttributedString)2 FreePaint (var3d.net.center.freefont.FreePaint)2 AssetManager (com.badlogic.gdx.assets.AssetManager)1 Camera (com.badlogic.gdx.graphics.Camera)1 Color (com.badlogic.gdx.graphics.Color)1 Mesh (com.badlogic.gdx.graphics.Mesh)1 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)1 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)1 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 Material (com.badlogic.gdx.graphics.g3d.Material)1 Model (com.badlogic.gdx.graphics.g3d.Model)1 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)1 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)1 TextureAttribute (com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)1