Advertisement

change color

Started by March 04, 2017 04:37 PM
2 comments, last by Pedro Alves 7 years, 11 months ago

i cant change the color of my progress bar

this is my code


import com.jme3.app.Application;
import com.jme3.app.state.BaseAppState;

import com.jme3.math.Vector3f;
import com.jme3.scene.Node;

import com.simsilica.lemur.Axis;
import com.simsilica.lemur.FillMode;
import com.simsilica.lemur.*;

import com.simsilica.lemur.component.SpringGridLayout;

/**
 *
 * @author Pedro Quesado
 */
public class CharactersStatusState extends BaseAppState {


     private Container loginPanel;
    private Container xp;
    private Container skill;

    @Override
    protected void initialize(Application app) {
        loginPanel = new Container();
        xp = new Container();
        skill = new Container();
        Container props = loginPanel.addChild(new Container(new SpringGridLayout(Axis.Y, Axis.X, FillMode.None, FillMode.Last)));
        // props.setBackground(null);
        props.setPreferredSize(new Vector3f(200, 70, 0));

        props.addChild(new Label("HP"));
        ProgressBar HP = props.addChild(new ProgressBar(), 1); 
        HP.setProgressValue(100); //i want this with color red

        // HP.setBackground(new QuadBackgroundComponent(ColorRGBA.Red));
        props.addChild(new Label("MP")); //this is gonna be blue 
        ProgressBar MP = props.addChild(new ProgressBar(), 1);
        MP.setProgressValue(100);
        //  MP.setBackground(new QuadBackgroundComponent(ColorRGBA.Blue));
        props.addChild(new Label("DR"));
        ProgressBar DR = props.addChild(new ProgressBar(), 1);
        DR.setProgressValue(20);
        //    DR.setBackground(new QuadBackgroundComponent(ColorRGBA.Gray));
        Container pgrosse = xp.addChild(new Container(new SpringGridLayout(Axis.Y, Axis.X, FillMode.None, FillMode.Last)));
        pgrosse.setPreferredSize(new Vector3f(1000, 20, 0));
        pgrosse.addChild(new Label("XP")); //this yellow
        ProgressBar XP = pgrosse.addChild(new ProgressBar(), 1);
        XP.setProgressValue(10);
        XP.setPreferredSize(new Vector3f(1000, 20, 0));
        //    XP.setBackground(new QuadBackgroundComponent(ColorRGBA.Brown));
        Container skillmenu = skill.addChild(new Container());
        skillmenu.setPreferredSize(new Vector3f(500, 50, 0));
        Container q = skillmenu.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
        q.addChild(new Container());
        q.addChild(new Container());
        q.addChild(new Container());
        q.addChild(new Container());
        q.addChild(new Container());
        q.addChild(new Container());
        q.addChild(new Container());
        q.addChild(new Container());
        q.addChild(new Container());
        q.addChild(new Container());
        q.addChild(new Container());
        q.addChild(new Container());
        q.setPreferredSize(new Vector3f(50, 20, 0));
        
        float scale = 1.5f * getState(MainMenuState.class).getStandardScale();
        //  loginPanel.setLocalScale(scale);
        loginPanel.setBackground(null);
        Vector3f prefs = loginPanel.getPreferredSize().clone();
        prefs.x = Math.max(20, prefs.x);
        loginPanel.setPreferredSize(prefs.clone());

        // Now account for scaling
        prefs.multLocal(scale);

        int width = app.getCamera().getWidth();
        int height = app.getCamera().getHeight();

        loginPanel.setLocalTranslation(width * 0.10f - prefs.x * 0.10f, height * 0.10f - prefs.y * 0.0f, 10);
        xp.setLocalTranslation(width * 0.10f - prefs.x * 0.10f, height * 0.03f - prefs.y * 0.0f, 10);
        skill.setLocalTranslation(width * 0.23f - prefs.x * 0.0f, height * 0.080f - prefs.y * 0.0f, 10);
        //  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    protected void cleanup(Application app) {
        //  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    protected void onEnable() {
        Node root = ((Main) getApplication()).getGuiNode();
        root.attachChild(loginPanel);
        root.attachChild(xp);
        root.attachChild(skill);
///  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    protected void onDisable() {
        loginPanel.removeFromParent();
        xp.removeFromParent();
        skill.removeFromParent();//  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

}

Hello

What have you tried? When you tried it, what were the results? Have you checked the documentation?

Specifically, the bit of documentation that says:


For styling, each nested element's style element ID is based on the element ID used when creating the slider. By default this is "progress". The relative IDs are as follows:

  • .container: The actual style element ID of the progress bar itself. Note: it is not a Container but a Panel the name is semantic with respect to it's relationship to the other child elements.
  • .label: The label that displays the progress message.
  • .value: The Panel that grows/shrinks to show the progress value within the .container.

Checking on Google, you already asked the same question on the jMonkeyEngine hub site, and got a proper response already: You get the progress bar's value Panel object (using the function they indicated) then set the style of the panel to the style you want to use. Presumably that style includes the color red.

Is there something about their answer you didn't understand? It looks like after you got the answer to the question, you reposted your original question here without adding the functions they told you.

Advertisement

A better place for asking such specific information is a search machine, site like stack-overflow, or a forum or irc channel dedicated to your gui toolit.

I never used your tookit, but a quick peek suggests you should look into styles.

https://github.com/jMonkeyEngine-Contributions/Lemur/wiki/Styling

No idea how that works, better try to find some examples, or someone with a better understanding, I think.

problem as been solve it

topic can be close

Hello

This topic is closed to new replies.

Advertisement