@Override public void click(UIDisplayElement element, int button) { UIStateButton b = (UIStateButton) element; if (button == 0) b.nextState(); else if (button == 1) b.previousState(); }
public UIMenuConfigVideo() { setId("config:video"); setBackgroundImage("engine:loadingbackground"); setModal(true); maximize(); title = new UIImage(Assets.getTexture("engine:terasology")); title.setHorizontalAlign(EHorizontalAlign.CENTER); title.setPosition(new Vector2f(0f, 128f)); title.setVisible(true); title.setSize(new Vector2f(512f, 128f)); version = new UILabel("Video Settings"); version.setHorizontalAlign(EHorizontalAlign.CENTER); version.setPosition(new Vector2f(0f, 230f)); version.setVisible(true); graphicsQualityButton = new UIStateButton(new Vector2f(256f, 32f)); StateButtonAction graphicsQualityStateAction = new StateButtonAction() { @Override public void action(UIDisplayElement element) { UIStateButton button = (UIStateButton) element; switch (button.getState()) { case 0: Config.getInstance().setEnablePostProcessingEffects(false); Config.getInstance().setFlickeringLight(false); break; case 1: Config.getInstance().setEnablePostProcessingEffects(false); Config.getInstance().setFlickeringLight(true); break; case 2: Config.getInstance().setEnablePostProcessingEffects(true); Config.getInstance().setFlickeringLight(true); break; } ShaderManager.getInstance().recompileAllShaders(); } }; graphicsQualityButton.addState("Graphics Quality: Ugly", graphicsQualityStateAction); graphicsQualityButton.addState("Graphics Quality: Nice", graphicsQualityStateAction); graphicsQualityButton.addState("Graphics Quality: Epic", graphicsQualityStateAction); graphicsQualityButton.addClickListener(clickAction); graphicsQualityButton.setHorizontalAlign(EHorizontalAlign.CENTER); graphicsQualityButton.setPosition( new Vector2f(-graphicsQualityButton.getSize().x / 2f - 10f, 300f)); graphicsQualityButton.setVisible(true); viewingDistanceButton = new UIStateButton(new Vector2f(256f, 32f)); StateButtonAction viewingDistanceStateAction = new StateButtonAction() { @Override public void action(UIDisplayElement element) { UIStateButton button = (UIStateButton) element; Config.getInstance().setViewingDistanceById(button.getState()); } }; viewingDistanceButton.addState("Viewing Distance: Near", viewingDistanceStateAction); viewingDistanceButton.addState("Viewing Distance: Moderate", viewingDistanceStateAction); viewingDistanceButton.addState("Viewing Distance: Far", viewingDistanceStateAction); viewingDistanceButton.addState("Viewing Distance: Ultra", viewingDistanceStateAction); viewingDistanceButton.addClickListener(clickAction); viewingDistanceButton.setHorizontalAlign(EHorizontalAlign.CENTER); viewingDistanceButton.setPosition( new Vector2f(-viewingDistanceButton.getSize().x / 2f - 10f, 300f + 40f)); viewingDistanceButton.setVisible(true); fovButton = new UISlider(new Vector2f(256f, 32f), 75, 130); fovButton.addChangedListener( new ChangedListener() { @Override public void changed(UIDisplayElement element) { UISlider slider = (UISlider) element; slider.setText("FOV: " + String.valueOf(slider.getValue())); Config.getInstance().setFov(slider.getValue()); } }); fovButton.setHorizontalAlign(EHorizontalAlign.CENTER); fovButton.setPosition(new Vector2f(-fovButton.getSize().x / 2f - 10f, 300f + 2 * 40f)); fovButton.setVisible(true); bobbingButton = new UIStateButton(new Vector2f(256f, 32f)); StateButtonAction bobbingStateAction = new StateButtonAction() { @Override public void action(UIDisplayElement element) { UIStateButton button = (UIStateButton) element; if (button.getState() == 0) Config.getInstance().setCameraBobbing(false); else Config.getInstance().setCameraBobbing(true); } }; bobbingButton.addState("Bobbing: Off", bobbingStateAction); bobbingButton.addState("Bobbing: On", bobbingStateAction); bobbingButton.addClickListener(clickAction); bobbingButton.setHorizontalAlign(EHorizontalAlign.CENTER); bobbingButton.setPosition(new Vector2f(-bobbingButton.getSize().x / 2f - 10f, 300f + 3 * 40f)); bobbingButton.setVisible(true); animateGrassButton = new UIStateButton(new Vector2f(256f, 32f)); StateButtonAction animateGrassStateAction = new StateButtonAction() { @Override public void action(UIDisplayElement element) { UIStateButton button = (UIStateButton) element; if (button.getState() == 0) Config.getInstance().setAnimatedGrass(false); else Config.getInstance().setAnimatedGrass(true); ShaderManager.getInstance().recompileAllShaders(); } }; animateGrassButton.addState("Animate Grass: Off", animateGrassStateAction); animateGrassButton.addState("Animate Grass: On", animateGrassStateAction); animateGrassButton.addClickListener(clickAction); animateGrassButton.setHorizontalAlign(EHorizontalAlign.CENTER); animateGrassButton.setPosition(new Vector2f(animateGrassButton.getSize().x / 2f, 300f)); animateGrassButton.setVisible(true); reflectiveWaterButton = new UIStateButton(new Vector2f(256f, 32f)); StateButtonAction reflectiveWaterStateAction = new StateButtonAction() { @Override public void action(UIDisplayElement element) { UIStateButton button = (UIStateButton) element; if (button.getState() == 0) Config.getInstance().setComplexWater(false); else Config.getInstance().setComplexWater(true); ShaderManager.getInstance().recompileAllShaders(); } }; reflectiveWaterButton.addState("Water World Reflection: Off", reflectiveWaterStateAction); reflectiveWaterButton.addState("Water World Reflection: On", reflectiveWaterStateAction); reflectiveWaterButton.addClickListener(clickAction); reflectiveWaterButton.setHorizontalAlign(EHorizontalAlign.CENTER); reflectiveWaterButton.setPosition( new Vector2f(reflectiveWaterButton.getSize().x / 2f, 300f + 40f)); reflectiveWaterButton.setVisible(true); blurIntensityButton = new UIStateButton(new Vector2f(256f, 32f)); StateButtonAction blurIntensityStateAction = new StateButtonAction() { @Override public void action(UIDisplayElement element) { UIStateButton button = (UIStateButton) element; Config.getInstance().setBlurIntensity(button.getState()); ShaderManager.getInstance().recompileAllShaders(); } }; blurIntensityButton.addState("Blur Intensity: Off", blurIntensityStateAction); blurIntensityButton.addState("Blur Intensity: Some", blurIntensityStateAction); blurIntensityButton.addState("Blur Intensity: Normal", blurIntensityStateAction); blurIntensityButton.addState("Blur Intensity: Max", blurIntensityStateAction); blurIntensityButton.addClickListener(clickAction); blurIntensityButton.setHorizontalAlign(EHorizontalAlign.CENTER); blurIntensityButton.setPosition( new Vector2f(blurIntensityButton.getSize().x / 2f, 300f + 2 * 40f)); blurIntensityButton.setVisible(true); backToConfigMenuButton = new UIButton(new Vector2f(256f, 32f), UIButton.ButtonType.NORMAL); backToConfigMenuButton.getLabel().setText("Back"); backToConfigMenuButton.setHorizontalAlign(EHorizontalAlign.CENTER); backToConfigMenuButton.setPosition(new Vector2f(0f, 300f + 7 * 40f)); backToConfigMenuButton.setVisible(true); backToConfigMenuButton.addClickListener( new ClickListener() { @Override public void click(UIDisplayElement element, int button) { getGUIManager().openWindow("config"); } }); addDisplayElement(title); addDisplayElement(version); addDisplayElement(graphicsQualityButton); addDisplayElement(fovButton); addDisplayElement(viewingDistanceButton); addDisplayElement(animateGrassButton); addDisplayElement(reflectiveWaterButton); addDisplayElement(blurIntensityButton); addDisplayElement(bobbingButton); addDisplayElement(backToConfigMenuButton); setup(); }
public void setup() { fovButton.setValue((int) Config.getInstance().getFov()); viewingDistanceButton.setState(Config.getInstance().getActiveViewingDistanceId()); blurIntensityButton.setState(Config.getInstance().getBlurIntensity()); if (Config.getInstance().isEnablePostProcessingEffects() && Config.getInstance().isFlickeringLight()) graphicsQualityButton.setState(2); else if (!Config.getInstance().isEnablePostProcessingEffects() && Config.getInstance().isFlickeringLight()) graphicsQualityButton.setState(1); else graphicsQualityButton.setState(0); if (Config.getInstance().isAnimatedGrass()) { animateGrassButton.setState(1); } else { animateGrassButton.setState(0); } if (Config.getInstance().isComplexWater()) { reflectiveWaterButton.setState(1); } else { reflectiveWaterButton.setState(0); } if (Config.getInstance().isCameraBobbing()) { bobbingButton.setState(1); } else { bobbingButton.setState(0); } }