Search in sources :

Example 21 with UILabel

use of org.terasology.rendering.nui.widgets.UILabel in project Terasology by MovingBlocks.

the class InputSettingsScreen method addInputBindRow.

private void addInputBindRow(SimpleUri uri, RegisterBindButton bind, ColumnLayout layout) {
    BindsConfig bindConfig = bindsManager.getBindsConfig();
    List<Input> binds = bindConfig.getBinds(uri);
    UIButton primaryInputBind = new UIButton();
    primaryInputBind.bindText(new BindingText(binds, 0));
    primaryInputBind.subscribe(event -> {
        ChangeBindingPopup popup = getManager().pushScreen(ChangeBindingPopup.ASSET_URI, ChangeBindingPopup.class);
        popup.setBindingData(uri, bind, 0);
    });
    UIButton secondaryInputBind = new UIButton();
    secondaryInputBind.bindText(new BindingText(binds, 1));
    secondaryInputBind.subscribe(event -> {
        ChangeBindingPopup popup = getManager().pushScreen(ChangeBindingPopup.ASSET_URI, ChangeBindingPopup.class);
        popup.setBindingData(uri, bind, 1);
    });
    layout.addWidget(new RowLayout(new UILabel(translationSystem.translate(bind.description())), primaryInputBind, secondaryInputBind).setColumnRatios(0.4f).setHorizontalSpacing(horizontalSpacing));
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) Input(org.terasology.input.Input) UIButton(org.terasology.rendering.nui.widgets.UIButton) RowLayout(org.terasology.rendering.nui.layouts.RowLayout) BindsConfig(org.terasology.config.BindsConfig)

Example 22 with UILabel

use of org.terasology.rendering.nui.widgets.UILabel in project Terasology by MovingBlocks.

the class InputSettingsScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    ColumnLayout mainLayout = new ColumnLayout();
    mainLayout.setHorizontalSpacing(8);
    mainLayout.setVerticalSpacing(8);
    mainLayout.setFamily("option-grid");
    UISlider mouseSensitivity = new UISlider("mouseSensitivity");
    mouseSensitivity.bindValue(BindHelper.bindBeanProperty("mouseSensitivity", inputDeviceConfiguration, Float.TYPE));
    mouseSensitivity.setIncrement(0.025f);
    mouseSensitivity.setPrecision(3);
    UICheckbox mouseInverted = new UICheckbox("mouseYAxisInverted");
    mouseInverted.bindChecked(BindHelper.bindBeanProperty("mouseYAxisInverted", inputDeviceConfiguration, Boolean.TYPE));
    mainLayout.addWidget(new UILabel("mouseLabel", "subheading", translationSystem.translate("${engine:menu#category-mouse}")));
    mainLayout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#mouse-sensitivity}") + ":"), mouseSensitivity).setColumnRatios(0.4f).setHorizontalSpacing(horizontalSpacing));
    mainLayout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#invert-mouse}") + ":"), mouseInverted).setColumnRatios(0.4f).setHorizontalSpacing(horizontalSpacing));
    Map<String, InputCategory> inputCategories = Maps.newHashMap();
    Map<SimpleUri, RegisterBindButton> inputsById = Maps.newHashMap();
    DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
    for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
        Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleId);
        if (module.isCodeModule()) {
            ResolutionResult result = resolver.resolve(moduleId);
            if (result.isSuccess()) {
                try (ModuleEnvironment environment = moduleManager.loadEnvironment(result.getModules(), false)) {
                    for (Class<?> holdingType : environment.getTypesAnnotatedWith(InputCategory.class, new FromModule(environment, moduleId))) {
                        InputCategory inputCategory = holdingType.getAnnotation(InputCategory.class);
                        inputCategories.put(module.getId() + ":" + inputCategory.id(), inputCategory);
                    }
                    for (Class<?> bindEvent : environment.getTypesAnnotatedWith(RegisterBindButton.class, new FromModule(environment, moduleId))) {
                        if (BindButtonEvent.class.isAssignableFrom(bindEvent)) {
                            RegisterBindButton bindRegister = bindEvent.getAnnotation(RegisterBindButton.class);
                            inputsById.put(new SimpleUri(module.getId(), bindRegister.id()), bindRegister);
                        }
                    }
                }
            }
        }
    }
    addInputSection(inputCategories.remove("engine:movement"), mainLayout, inputsById);
    addInputSection(inputCategories.remove("engine:interaction"), mainLayout, inputsById);
    addInputSection(inputCategories.remove("engine:inventory"), mainLayout, inputsById);
    addInputSection(inputCategories.remove("engine:general"), mainLayout, inputsById);
    for (InputCategory category : inputCategories.values()) {
        addInputSection(category, mainLayout, inputsById);
    }
    mainLayout.addWidget(new UISpace(new Vector2i(1, 16)));
    List<String> controllers = inputSystem.getControllerDevice().getControllers();
    for (String name : controllers) {
        ControllerInfo cfg = inputDeviceConfiguration.getController(name);
        addInputSection(mainLayout, name, cfg);
    }
    ScrollableArea area = find("area", ScrollableArea.class);
    area.setContent(mainLayout);
    WidgetUtil.trySubscribe(this, "reset", button -> {
        inputDeviceConfiguration.reset();
        bindsManager.getBindsConfig().setBinds(bindsManager.getDefaultBindsConfig());
    });
    WidgetUtil.trySubscribe(this, "back", button -> triggerBackAnimation());
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) UISlider(org.terasology.rendering.nui.widgets.UISlider) RegisterBindButton(org.terasology.input.RegisterBindButton) ResolutionResult(org.terasology.module.ResolutionResult) SimpleUri(org.terasology.engine.SimpleUri) UICheckbox(org.terasology.rendering.nui.widgets.UICheckbox) DependencyResolver(org.terasology.module.DependencyResolver) Name(org.terasology.naming.Name) ModuleEnvironment(org.terasology.module.ModuleEnvironment) ScrollableArea(org.terasology.rendering.nui.layouts.ScrollableArea) ColumnLayout(org.terasology.rendering.nui.layouts.ColumnLayout) RowLayout(org.terasology.rendering.nui.layouts.RowLayout) InputCategory(org.terasology.input.InputCategory) UISpace(org.terasology.rendering.nui.widgets.UISpace) Vector2i(org.terasology.math.geom.Vector2i) FromModule(org.terasology.module.predicates.FromModule) Module(org.terasology.module.Module) FromModule(org.terasology.module.predicates.FromModule) ControllerInfo(org.terasology.config.ControllerConfig.ControllerInfo)

Example 23 with UILabel

use of org.terasology.rendering.nui.widgets.UILabel in project Terasology by MovingBlocks.

the class PropertyLayout method addProperties.

/**
 * Adds a provider for properties to this layout. All properties appears in a list that may be collapsed/expanded.
 * Initially the list is expanded.
 */
public void addProperties(String groupLabel, final Collection<Property<?, ?>> properties) {
    if (properties.size() > 0) {
        final UIButton expand = new UIButton("", "-");
        expand.setTooltip("Click to collapse");
        final UILabel headline = new UILabel(groupLabel);
        final MigLayout layout = new MigLayout();
        layout.setColConstraints("[min][fill]");
        layout.setRowConstraints("[min]");
        expand.subscribe(widget -> {
            UIButton button = (UIButton) widget;
            if ("-".equals(button.getText())) {
                layout.clear();
                invalidate();
                button.setText("+");
                button.setTooltip("Click to expand");
            } else {
                expand(properties, layout);
                button.setText("-");
                button.setTooltip("Click to collapse");
            }
        });
        addWidget(expand, new CCHint("newline, w 45!, h 22!"));
        addWidget(headline, new CCHint());
        addWidget(layout, new CCHint("newline, spanx 2"));
        expand(properties, layout);
    }
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) UIButton(org.terasology.rendering.nui.widgets.UIButton) MigLayout(org.terasology.rendering.nui.layouts.miglayout.MigLayout)

Aggregations

UILabel (org.terasology.rendering.nui.widgets.UILabel)23 UIButton (org.terasology.rendering.nui.widgets.UIButton)6 RowLayout (org.terasology.rendering.nui.layouts.RowLayout)5 UICheckbox (org.terasology.rendering.nui.widgets.UICheckbox)5 Vector2i (org.terasology.math.geom.Vector2i)4 UIWidget (org.terasology.rendering.nui.UIWidget)4 ReadOnlyBinding (org.terasology.rendering.nui.databinding.ReadOnlyBinding)4 UISpace (org.terasology.rendering.nui.widgets.UISpace)4 List (java.util.List)3 DependencyResolver (org.terasology.module.DependencyResolver)3 Module (org.terasology.module.Module)3 Name (org.terasology.naming.Name)3 JsonElement (com.google.gson.JsonElement)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ServerInfo (org.terasology.config.ServerInfo)2 SimpleUri (org.terasology.engine.SimpleUri)2 RegisterBindButton (org.terasology.input.RegisterBindButton)2 ResolutionResult (org.terasology.module.ResolutionResult)2 Canvas (org.terasology.rendering.nui.Canvas)2