<commit_before>/*
 * Copyright 2012 <NAME> <<EMAIL>>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.terasology.rendering.gui.menus;

import org.lwjgl.opengl.Display;
import org.terasology.asset.AssetManager;
import org.terasology.logic.manager.Config;
import org.terasology.logic.manager.ShaderManager;
import org.terasology.rendering.gui.components.UIButton;
import org.terasology.rendering.gui.components.UIImageOverlay;
import org.terasology.rendering.gui.components.UISlider;
import org.terasology.rendering.gui.components.UIStateButton;
import org.terasology.rendering.gui.components.UIText;
import org.terasology.rendering.gui.framework.IChangedListener;
import org.terasology.rendering.gui.framework.IClickListener;
import org.terasology.rendering.gui.framework.IStateButtonAction;
import org.terasology.rendering.gui.framework.UIDisplayElement;
import org.terasology.rendering.gui.framework.UIDisplayWindow;
import org.terasology.rendering.gui.framework.UIGraphicsElement;

import javax.vecmath.Vector2f;

/**
 * @author Overdhose
 * @author <NAME> <<EMAIL>>
 *         Date: 29/07/12
 */
public class UIConfigMenuVideo extends UIDisplayWindow {

    final UIImageOverlay _overlay;
    final UIGraphicsElement _title;

    private final UIStateButton _graphicsQualityButton;
    private final UIStateButton _viewingDistanceButton;
    private final UISlider _fovButton;
    private final UIStateButton _animateGrassButton;
    private final UIStateButton _reflectiveWaterButton;
    private final UIStateButton _blurIntensityButton;
    private final UIStateButton _bobbingButton;
    private final UIButton _backToConfigMenuButton;

    final UIText _version;
    
    private final IClickListener clickAction = new IClickListener() {
        @Override
        public void clicked(UIDisplayElement element) {
        	UIStateButton button = (UIStateButton) element;
            button.nextState();
        }
    };

    public UIConfigMenuVideo() {
        maximize();
        _title = new UIGraphicsElement(AssetManager.loadTexture("engine:terasology"));
        _title.setVisible(true);
        _title.setSize(new Vector2f(512f, 128f));

        _version = new UIText("Video Settings");
        _version.setVisible(true);

        _overlay = new UIImageOverlay(AssetManager.loadTexture("engine:loadingBackground"));
        _overlay.setVisible(true);

        _graphicsQualityButton = new UIStateButton(new Vector2f(256f, 32f));
        IStateButtonAction graphicsQualityStateAction = new IStateButtonAction() {
			@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.setVisible(true);

        _viewingDistanceButton = new UIStateButton(new Vector2f(256f, 32f));
        IStateButtonAction viewingDistanceStateAction = new IStateButtonAction() {
			@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.setVisible(true);

        _fovButton = new UISlider(new Vector2f(256f, 32f), 75, 120);
        _fovButton.addChangedListener(new IChangedListener() {
			@Override
			public void changed(UIDisplayElement element) {
				UISlider slider = (UISlider)element;
				slider.setText("FOV: " + String.valueOf(slider.getValue()));
				Config.getInstance().setFov(slider.getValue());
			}
		});
        _fovButton.setVisible(true);

        _animateGrassButton = new UIStateButton(new Vector2f(256f, 32f));
        IStateButtonAction animateGrassStateAction = new IStateButtonAction() {
			@Override
			public void action(UIDisplayElement element) {
				UIStateButton button = (UIStateButton)element;
				if (button.getState() == 0)
					Config.getInstance().setAnimatedGrass(false);
				else
					Config.getInstance().setAnimatedGrass(true);
			}
		};
		_animateGrassButton.addState("Animate Grass: Off", animateGrassStateAction);
        _animateGrassButton.addState("Animate Grass: On", animateGrassStateAction);
        _animateGrassButton.addClickListener(clickAction);
        _animateGrassButton.setVisible(true);

        _reflectiveWaterButton = new UIStateButton(new Vector2f(256f, 32f));
        IStateButtonAction reflectiveWaterStateAction = new IStateButtonAction() {
			@Override
			public void action(UIDisplayElement element) {
				UIStateButton button = (UIStateButton)element;
				if (button.getState() == 0)
					Config.getInstance().setComplexWater(false);
				else
					Config.getInstance().setComplexWater(true);
			}
		};
        _reflectiveWaterButton.addState("Reflective water: Off", reflectiveWaterStateAction);
		_reflectiveWaterButton.addState("Reflective water: On", reflectiveWaterStateAction);
        _reflectiveWaterButton.addClickListener(clickAction);
        _reflectiveWaterButton.setVisible(true);

        _blurIntensityButton = new UIStateButton(new Vector2f(256f, 32f));
        IStateButtonAction blurIntensityStateAction = new IStateButtonAction() {
			@Override
			public void action(UIDisplayElement element) {
				UIStateButton button = (UIStateButton)element;
				Config.getInstance().setBlurIntensity(button.getState());
			}
		};
		_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);<commit_msg>Adds that *all* changes in the graphics options correctly trigger a recompile of all shaders.<commit_after>/*
 * Copyright 2012 <NAME> <<EMAIL>>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.terasology.rendering.gui.menus;

import org.lwjgl.opengl.Display;
import org.terasology.asset.AssetManager;
import org.terasology.logic.manager.Config;
import org.terasology.logic.manager.ShaderManager;
import org.terasology.rendering.gui.components.UIButton;
import org.terasology.rendering.gui.components.UIImageOverlay;
import org.terasology.rendering.gui.components.UISlider;
import org.terasology.rendering.gui.components.UIStateButton;
import org.terasology.rendering.gui.components.UIText;
import org.terasology.rendering.gui.framework.IChangedListener;
import org.terasology.rendering.gui.framework.IClickListener;
import org.terasology.rendering.gui.framework.IStateButtonAction;
import org.terasology.rendering.gui.framework.UIDisplayElement;
import org.terasology.rendering.gui.framework.UIDisplayWindow;
import org.terasology.rendering.gui.framework.UIGraphicsElement;

import javax.vecmath.Vector2f;

/**
 * @author Overdhose
 * @author <NAME> <<EMAIL>>
 *         Date: 29/07/12
 */
public class UIConfigMenuVideo extends UIDisplayWindow {

    final UIImageOverlay _overlay;
    final UIGraphicsElement _title;

    private final UIStateButton _graphicsQualityButton;
    private final UIStateButton _viewingDistanceButton;
    private final UISlider _fovButton;
    private final UIStateButton _animateGrassButton;
    private final UIStateButton _reflectiveWaterButton;
    private final UIStateButton _blurIntensityButton;
    private final UIStateButton _bobbingButton;
    private final UIButton _backToConfigMenuButton;

    final UIText _version;
    
    private final IClickListener clickAction = new IClickListener() {
        @Override
        public void clicked(UIDisplayElement element) {
        	UIStateButton button = (UIStateButton) element;
            button.nextState();
        }
    };

    public UIConfigMenuVideo() {
        maximize();
        _title = new UIGraphicsElement(AssetManager.loadTexture("engine:terasology"));
        _title.setVisible(true);
        _title.setSize(new Vector2f(512f, 128f));

        _version = new UIText("Video Settings");
        _version.setVisible(true);

        _overlay = new UIImageOverlay(AssetManager.loadTexture("engine:loadingBackground"));
        _overlay.setVisible(true);

        _graphicsQualityButton = new UIStateButton(new Vector2f(256f, 32f));
        IStateButtonAction graphicsQualityStateAction = new IStateButtonAction() {
			@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.setVisible(true);

        _viewingDistanceButton = new UIStateButton(new Vector2f(256f, 32f));
        IStateButtonAction viewingDistanceStateAction = new IStateButtonAction() {
			@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.setVisible(true);

        _fovButton = new UISlider(new Vector2f(256f, 32f), 75, 120);
        _fovButton.addChangedListener(new IChangedListener() {
			@Override
			public void changed(UIDisplayElement element) {
				UISlider slider = (UISlider)element;
				slider.setText("FOV: " + String.valueOf(slider.getValue()));
				Config.getInstance().setFov(slider.getValue());
			}
		});
        _fovButton.setVisible(true);

        _animateGrassButton = new UIStateButton(new Vector2f(256f, 32f));
        IStateButtonAction animateGrassStateAction = new IStateButtonAction() {
			@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.setVisible(true);

        _reflectiveWaterButton = new UIStateButton(new Vector2f(256f, 32f));
        IStateButtonAction reflectiveWaterStateAction = new IStateButtonAction() {
			@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("Reflective water: Off", reflectiveWaterStateAction);
		_reflectiveWaterButton.addState("Reflective water: On", reflectiveWaterStateAction);
        _reflectiveWaterButton.addClickListener(clickAction);
        _reflectiveWaterButton.setVisible(true);

        _blurIntensityButton = new UIStateButton(new Vector2f(256f, 32f));
        IStateButtonAction blurIntensityStateAction = new IStateButtonAction() {
			@Override
			public void action(UIDisplayElement element) {
				UIStateButton button = (UIStateButton)element;
				Config.getInstance().setBlurIntensity(button.getState());
			}
		};
		_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);
{'fraction_non_alphanumeric': 0.09133289560078792, 'fraction_numerical': 0.008929743926460933, 'mean_word_length': 4.510492040520984, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7251306', 'n_tokens_mistral': 4678, 'n_tokens_neox': 4139, 'n_words': 837}