@Override public void show() { ready = false; if (!VisUI.isLoaded()) VisUI.load(VisUI.SkinScale.X1); multiplexer = new InputMultiplexer(); screenSize = new Vector2(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); midpoint = new Vector2(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2); stage2d = new Stage(new ScreenViewport(new OrthographicCamera(screenSize.x, screenSize.y))); setActiveCamera(); }
/** * Creates integer number selector * * @param name may be null */ public NumberSelector( String styleName, String name, float initialValue, float min, float max, float step) { this( VisUI.getSkin().get(styleName, NumberSelectorStyle.class), VisUI.getSizes(), name, initialValue, min, max, step, 0); }
/** * Creates integer or float number selector depending on precision, see {@link #setPrecision(int)} * * @param name may be null */ public NumberSelector( String name, float initialValue, float min, float max, float step, int precision) { this( VisUI.getSkin().get("default", NumberSelectorStyle.class), VisUI.getSizes(), name, initialValue, min, max, step, precision); }
public static VisTextField createTextField(String style, boolean textCursor) { VisTextField visTextField = new VisTextField(); Skin skin = VisUI.getSkin(); visTextField.setStyle(skin.get(style, VisTextField.VisTextFieldStyle.class)); if (textCursor) visTextField.addListener(new CursorListener(CursorManager.TEXT)); return visTextField; }
private void init(String text, Image image, MenuItemStyle style) { this.style = style; this.image = image; setSkin(VisUI.getSkin()); Sizes sizes = getSkin().get(Sizes.class); defaults().space(3); if (image != null) image.setScaling(Scaling.fit); add(image).size(sizes.menuItemIconSize); label = new Label(text, new LabelStyle(style.font, style.fontColor)); label.setAlignment(Align.left); add(label).expand().fill(); add(shortcutLabel = new VisLabel("", "menuitem-shortcut")).padLeft(10).right(); shortcutLabelColor = shortcutLabel.getStyle().fontColor; subMenuIconCell = add(subMenuImage = new Image(style.subMenu)) .padLeft(3) .padRight(3) .size(style.subMenu.getMinWidth(), style.subMenu.getMinHeight()); subMenuIconCell.setActor(null); addListener( new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { // makes submenu item not clickable if (subMenu != null) event.stop(); } }); addListener( new InputListener() { @Override public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) { if (subMenu == null || isDisabled()) { // hides last visible submenu (if any) PopupMenu parent = (PopupMenu) getParent(); parent.setSubMenu(null); } else { Stage stage = getStage(); Vector2 pos = localToStageCoordinates(new Vector2(0, 0)); subMenu.setPosition( pos.x + getWidth() - 1, pos.y - subMenu.getHeight() + getHeight()); if (subMenu.getY() < 0) { subMenu.setY(subMenu.getY() + subMenu.getHeight() - getHeight()); } stage.addActor(subMenu); PopupMenu parent = (PopupMenu) getParent(); parent.setSubMenu(subMenu); } } }); }
public ComponentSelectDialog( EntityProperties properties, ComponentSelectDialogListener listener) { super(false); this.properties = properties; this.listener = listener; setBackground(VisUI.getSkin().getDrawable("tooltip-bg")); // TODO: [plugin] plugin entry point componentClasses.add(ShaderComponent.class); componentClasses.add(PolygonComponent.class); componentClasses.add(PhysicsPropertiesComponent.class); componentClasses.add(VariablesComponent.class); buttonStyle = new VisTextButtonStyle(VisUI.getSkin().get(VisTextButtonStyle.class)); scrollPaneTable = new VisTable(false); scrollPaneTable.top(); VisScrollPane scrollPane = new VisScrollPane(scrollPaneTable); scrollPane.setScrollingDisabled(false, true); scrollPane.setFlickScroll(false); scrollPane.setFadeScrollBars(false); VisImageButton closeButton = new VisImageButton("close"); add(new VisLabel("Select component")); add(closeButton).right().row(); addSeparator().colspan(2); add(scrollPane).colspan(2).expand().fill().padLeft(3).padRight(3); setSize(220, 200); closeButton.addListener(new VisChangeListener((event, actor) -> remove())); inputListener = new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { if (contains(event.getStageX(), event.getStageY()) == false) { remove(); return true; } return false; } }; }
public static VisValidableTextField createValidableTextField( String style, InputValidator inputValidator) { VisValidableTextField visTextField = new VisValidableTextField(inputValidator); Skin skin = VisUI.getSkin(); visTextField.setStyle(skin.get(style, VisTextField.VisTextFieldStyle.class)); visTextField.addListener(new CursorListener(CursorManager.TEXT)); return visTextField; }
public AlignmentToolsDialog(ModuleInjector injector, Array<EntityProxy> selectedEntities) { injector.injectModules(this); this.selectedEntities = selectedEntities; setBackground(VisUI.getSkin().getDrawable("window-bg")); setTouchable(Touchable.enabled); setVisible(false); addListener(new EventStopper()); top().left(); defaults().left(); TableUtils.setSpacingDefaults(this); VisTable horizontalAlign = new VisTable(true); VisImageButton alignLeft = new VisImageButton(Icons.ALIGN_LEFT.drawable(), "Align entities at left edge"); VisImageButton alignRight = new VisImageButton(Icons.ALIGN_RIGHT.drawable(), "Align entities at right edge"); VisImageButton alignCenterX = new VisImageButton(Icons.ALIGN_CENTER_X.drawable(), "Center entities at x axis"); VisImageButton alignTop = new VisImageButton(Icons.ALIGN_BOTTOM.drawable(), "Align entities at top edge"); VisImageButton alignBottom = new VisImageButton(Icons.ALIGN_TOP.drawable(), "Align entities at bottom edge"); VisImageButton alignCenterY = new VisImageButton(Icons.ALIGN_CENTER_Y.drawable(), "Center entities at y axis"); VisImageButton closeButton = new VisImageButton("close-window"); horizontalAlign.add("Horizontal").width(70); horizontalAlign.add(alignLeft); horizontalAlign.add(alignRight); horizontalAlign.add(alignCenterX); VisTable verticalAlign = new VisTable(true); verticalAlign.add("Vertical").width(70); verticalAlign.add(alignTop); verticalAlign.add(alignBottom); verticalAlign.add(alignCenterY); add(new VisLabel("Alignment", Align.center)).expandX().fillX().top(); add(closeButton).right().row(); add(horizontalAlign).padLeft(3).colspan(2).row(); add(verticalAlign).padLeft(3).colspan(2); pack(); alignLeft.addListener(new VisChangeListener((event, actor) -> alignSelected(Align.left))); alignRight.addListener(new VisChangeListener((event, actor) -> alignSelected(Align.right))); alignCenterX.addListener(new VisChangeListener((event, actor) -> alignSelectedCenter(false))); alignTop.addListener(new VisChangeListener((event, actor) -> alignSelected(Align.top))); alignBottom.addListener(new VisChangeListener((event, actor) -> alignSelected(Align.bottom))); alignCenterY.addListener(new VisChangeListener((event, actor) -> alignSelectedCenter(true))); closeButton.addListener(new VisChangeListener((event, actor) -> setVisible(false))); }
private void init() { VisLabel lbl = new VisLabel("Grid Size:"); add(lbl).padRight(4); gridSizeTextField = new VisValidableTextField(new Validators.IntegerValidator()); gridSizeTextField.setStyle(VisUI.getSkin().get("light", VisTextField.VisTextFieldStyle.class)); // gridSizeTextField.setRightAligned(true); gridSizeTextField.addListener(new KeyboardListener(GRID_SIZE_TEXT_FIELD_UPDATED)); add(gridSizeTextField).width(60); }
public DeleteMultipleFilesTab(ModuleInjector injector, Array<FileItem> items) { super(false, true); this.injector = injector; this.items = items; injector.injectModules(this); table = new VisTable(); table.setBackground(VisUI.getSkin().getDrawable("window-bg")); table.defaults().left(); usagesTable = new VisTable(true); rebuildUsagesTable(); VisScrollPane scrollPane = new VisScrollPane(usagesTable); scrollPane.setFadeScrollBars(false); table.add(scrollPane).expandX().fillX().pad(3).row(); table.add().expand().fill().row(); table.addSeparator(); table.add(createButtonPane()).pad(3); }
public LayersDialog( SceneTab sceneTab, EntityEngineConfiguration engineConfig, ModuleInjector sceneMC) { super(true); this.sceneTab = sceneTab; this.scene = sceneTab.getScene(); sceneMC.injectModules(this); layerManipulatorManager = engineConfig.getManager(LayerManipulatorManager.class); setBackground(VisUI.getSkin().getDrawable("window-bg")); setTouchable(Touchable.enabled); VisImageButton layerAddButton = new VisImageButton(Icons.LAYER_ADD.drawable(), "Add new layer"); layerUpButton = new VisImageButton(Icons.LAYER_UP.drawable(), "Move layer up"); layerDownButton = new VisImageButton(Icons.LAYER_DOWN.drawable(), "Move layer down"); layerSettingsButton = new VisImageButton(Icons.SETTINGS.drawable(), "Show layer settings"); layerRemoveButton = new VisImageButton(Icons.LAYER_REMOVE.drawable(), "Delete layer"); layerUpButton.setGenerateDisabledImage(true); layerDownButton.setGenerateDisabledImage(true); layerRemoveButton.setGenerateDisabledImage(true); layerAddButton.addListener( new VisChangeListener( (event, actor) -> DialogUtils.showInputDialog( getStage(), "New Layer", "Name:", true, input -> scene.getLayerByName(input) == null, (DefaultInputDialogListener) input -> undoModule.execute(new LayerAddedAction(input))))); layerUpButton.addListener( new VisChangeListener((event, actor) -> undoModule.execute(new LayerMovedAction(true)))); layerDownButton.addListener( new VisChangeListener((event, actor) -> undoModule.execute(new LayerMovedAction(false)))); layerSettingsButton.addListener( new VisChangeListener( (event1, actor1) -> getStage().addActor(new LayerSettingsDialog(sceneMC, scene).fadeIn()))); layerRemoveButton.addListener( new VisChangeListener( (event, actor) -> DialogUtils.showOptionDialog( getStage(), "Delete Layer", "Are you sure you want to delete layer '" + scene.getActiveLayer().name + "'?", OptionDialogType.YES_NO, new OptionDialogAdapter() { @Override public void yes() { UndoableActionGroup layerRemovedGroup = new UndoableActionGroup("Delete Layer"); layerRemovedGroup.add( new EntitiesRemovedAction( sceneMC, sceneTab.getEntityEngine(), VisBagUtils.toSet( layerManipulatorManager.getEntitiesWithLayer( scene.getActiveLayerId())))); layerRemovedGroup.add(new LayerRemovedAction(scene.getActiveLayer())); layerRemovedGroup.finalizeGroup(); undoModule.execute(layerRemovedGroup); } }))); layersTable = new VisTable(); VisScrollPane layersScrollPane = new VisScrollPane(layersTable); layersScrollPane.setScrollingDisabled(true, false); layersScrollPane.setFadeScrollBars(false); top(); left(); defaults().left(); defaults().padLeft(5).padRight(5); add(new VisLabel("Layers")).center().row(); add(layersScrollPane).expandX().fillX().row(); addSeparator(); add(TableBuilder.build( layerAddButton, layerUpButton, layerDownButton, layerSettingsButton, layerRemoveButton)) .padBottom(8); addListener(new EventStopper()); rebuildLayersTable(); sceneObservable = nid -> { if (nid == EditorScene.LAYER_ADDED || nid == EditorScene.LAYER_INSERTED || nid == EditorScene.LAYER_REMOVED || nid == EditorScene.LAYERS_SORTED || nid == EditorScene.ACTIVE_LAYER_CHANGED || nid == EditorScene.LAYER_DATA_CHANGED) { rebuildLayersTable(); sceneTab.dirty(); } }; scene.addObservable(sceneObservable); }
/** * Dialog displayed in scene tab, allows to manipulate layers * * @author Kotcrab */ public class LayersDialog extends VisTable implements Disposable { private static final Drawable SELECTION = VisUI.getSkin().getDrawable("list-selection"); private static final VisImageButtonStyle BUTTON_STYLE = VisUI.getSkin().get("default", VisImageButtonStyle.class); private static final VisImageButtonStyle BUTTON_BLUE_STYLE = VisUI.getSkin().get("blue", VisImageButtonStyle.class); @InjectModule private UndoModule undoModule; @InjectModule private EntityManipulatorModule entityManipulator; private LayerManipulatorManager layerManipulatorManager; private SceneTab sceneTab; private EditorScene scene; private VisTable layersTable; private VisImageButton layerUpButton; private VisImageButton layerDownButton; private VisImageButton layerSettingsButton; private VisImageButton layerRemoveButton; private ObservableListener sceneObservable; public LayersDialog( SceneTab sceneTab, EntityEngineConfiguration engineConfig, ModuleInjector sceneMC) { super(true); this.sceneTab = sceneTab; this.scene = sceneTab.getScene(); sceneMC.injectModules(this); layerManipulatorManager = engineConfig.getManager(LayerManipulatorManager.class); setBackground(VisUI.getSkin().getDrawable("window-bg")); setTouchable(Touchable.enabled); VisImageButton layerAddButton = new VisImageButton(Icons.LAYER_ADD.drawable(), "Add new layer"); layerUpButton = new VisImageButton(Icons.LAYER_UP.drawable(), "Move layer up"); layerDownButton = new VisImageButton(Icons.LAYER_DOWN.drawable(), "Move layer down"); layerSettingsButton = new VisImageButton(Icons.SETTINGS.drawable(), "Show layer settings"); layerRemoveButton = new VisImageButton(Icons.LAYER_REMOVE.drawable(), "Delete layer"); layerUpButton.setGenerateDisabledImage(true); layerDownButton.setGenerateDisabledImage(true); layerRemoveButton.setGenerateDisabledImage(true); layerAddButton.addListener( new VisChangeListener( (event, actor) -> DialogUtils.showInputDialog( getStage(), "New Layer", "Name:", true, input -> scene.getLayerByName(input) == null, (DefaultInputDialogListener) input -> undoModule.execute(new LayerAddedAction(input))))); layerUpButton.addListener( new VisChangeListener((event, actor) -> undoModule.execute(new LayerMovedAction(true)))); layerDownButton.addListener( new VisChangeListener((event, actor) -> undoModule.execute(new LayerMovedAction(false)))); layerSettingsButton.addListener( new VisChangeListener( (event1, actor1) -> getStage().addActor(new LayerSettingsDialog(sceneMC, scene).fadeIn()))); layerRemoveButton.addListener( new VisChangeListener( (event, actor) -> DialogUtils.showOptionDialog( getStage(), "Delete Layer", "Are you sure you want to delete layer '" + scene.getActiveLayer().name + "'?", OptionDialogType.YES_NO, new OptionDialogAdapter() { @Override public void yes() { UndoableActionGroup layerRemovedGroup = new UndoableActionGroup("Delete Layer"); layerRemovedGroup.add( new EntitiesRemovedAction( sceneMC, sceneTab.getEntityEngine(), VisBagUtils.toSet( layerManipulatorManager.getEntitiesWithLayer( scene.getActiveLayerId())))); layerRemovedGroup.add(new LayerRemovedAction(scene.getActiveLayer())); layerRemovedGroup.finalizeGroup(); undoModule.execute(layerRemovedGroup); } }))); layersTable = new VisTable(); VisScrollPane layersScrollPane = new VisScrollPane(layersTable); layersScrollPane.setScrollingDisabled(true, false); layersScrollPane.setFadeScrollBars(false); top(); left(); defaults().left(); defaults().padLeft(5).padRight(5); add(new VisLabel("Layers")).center().row(); add(layersScrollPane).expandX().fillX().row(); addSeparator(); add(TableBuilder.build( layerAddButton, layerUpButton, layerDownButton, layerSettingsButton, layerRemoveButton)) .padBottom(8); addListener(new EventStopper()); rebuildLayersTable(); sceneObservable = nid -> { if (nid == EditorScene.LAYER_ADDED || nid == EditorScene.LAYER_INSERTED || nid == EditorScene.LAYER_REMOVED || nid == EditorScene.LAYERS_SORTED || nid == EditorScene.ACTIVE_LAYER_CHANGED || nid == EditorScene.LAYER_DATA_CHANGED) { rebuildLayersTable(); sceneTab.dirty(); } }; scene.addObservable(sceneObservable); } private void selectedLayer(Layer layer) { scene.setActiveLayer(layer.id); layerUpButton.setDisabled(false); layerDownButton.setDisabled(false); ImmutableArray<Layer> layers = scene.getLayers(); int index = layers.indexOf(layer, true); if (index == 0) layerUpButton.setDisabled(true); if (index == layers.size() - 1) layerDownButton.setDisabled(true); } private void rebuildLayersTable() { deselectAll(); Array<Actor> actors = new Array<>(layersTable.getChildren()); layersTable.clearChildren(); for (Layer layer : scene.getLayers()) { LayerItem item = getItemForLayer(actors, layer); if (item == null) item = new LayerItem(layer); item.update(); layersTable.add(item).expandX().fillX().row(); if (layer == scene.getActiveLayer()) item.select(); } if (scene.getLayers().size() == 1) { layerDownButton.setDisabled(true); layerUpButton.setDisabled(true); layerRemoveButton.setDisabled(true); } else layerRemoveButton.setDisabled(false); } private LayerItem getItemForLayer(Array<Actor> actors, Layer layer) { for (Actor a : actors) { if (a instanceof LayerItem) { LayerItem item = (LayerItem) a; if (item.layer == layer) { return item; } } } return null; } private void deselectAll() { for (Actor a : layersTable.getChildren()) { if (a instanceof LayerItem) { LayerItem item = (LayerItem) a; item.deselect(); } } } private void selectFirstLayer() { selectLayer(scene.getLayers().first()); } private void selectLayer(Layer layer) { LayerItem item = getItemForLayer(layersTable.getChildren(), layer); if (item == null) throw new IllegalStateException("Layer not found"); // selectedLayer would by already called from item.select item.select(); } @Override public void dispose() { scene.removeObservable(sceneObservable); } private class LayerAddedAction implements UndoableAction { private String name; private Layer layer; public LayerAddedAction(String name) { this.name = name; } @Override public void execute() { layer = scene.addLayer(name); selectLayer(layer); } @Override public void undo() { scene.removeLayer(layer); } @Override public String getActionName() { return "Add Layer"; } } private class LayerRemovedAction implements UndoableAction { private Layer layer; public LayerRemovedAction(Layer layer) { this.layer = layer; } @Override public void execute() { scene.removeLayer(layer); } @Override public void undo() { scene.insertLayer(layer); selectLayer(layer); } @Override public String getActionName() { return "Remove Layer"; } } private class LayerMovedAction extends MonoUndoableAction { Layer currentLayer; Layer targetLayer; public LayerMovedAction(boolean moveUp) { int currentIndex = scene.getLayers().indexOf(scene.getActiveLayer(), true); int targetIndex; if (moveUp) targetIndex = currentIndex - 1; else targetIndex = currentIndex + 1; currentLayer = scene.getLayers().get(currentIndex); targetLayer = scene.getLayers().get(targetIndex); } @Override public void doAction() { layerManipulatorManager.swapLayers(currentLayer.id, targetLayer.id); int oldCurrentId = currentLayer.id; currentLayer.id = targetLayer.id; targetLayer.id = oldCurrentId; scene.forceSortLayers(); selectLayer(currentLayer); } @Override public String getActionName() { return "Move Layer"; } } private class LayerItem extends VisTable { private Layer layer; private VisLabel nameLabel; private VisImageButton eyeButton; private VisImageButton lockButton; public LayerItem(Layer layer) { super(true); this.layer = layer; setTouchable(Touchable.enabled); eyeButton = new VisImageButton("default"); lockButton = new VisImageButton("default"); updateButtonsImages(); eyeButton.addListener( new VisChangeListener( (event, actor) -> undoModule.execute( new MonoUndoableAction() { @Override public String getActionName() { return "Hide/Show Layer"; } @Override public void doAction() { changeVisibility(); } }))); lockButton.addListener( new VisChangeListener( (event, actor) -> undoModule.execute( new MonoUndoableAction() { @Override public String getActionName() { return "Lock/Unlock Layer"; } @Override public void doAction() { changeLocked(); } }))); pad(3); add(eyeButton); add(lockButton); add(nameLabel = new VisLabel(layer.name)) .expandX() .fillX(); // TODO: show id in layers dialog, don't forget about updating it when layer was // moved addListener( new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { select(); return true; } }); } public void update() { nameLabel.setText(layer.name); } void changeVisibility() { layer.visible = !layer.visible; layerManipulatorManager.changeLayerVisibility(layer.id, layer.visible); updateButtonsImages(); sceneTab.dirty(); } void changeLocked() { layer.locked = !layer.locked; updateButtonsImages(); if (layer.locked) entityManipulator.resetSelection(); sceneTab.dirty(); } private void updateButtonsImages() { eyeButton.getStyle().imageUp = layer.visible ? Icons.EYE.drawable() : Icons.EYE_DISABLED.drawable(); lockButton.getStyle().imageUp = layer.locked ? Icons.LOCKED.drawable() : Icons.UNLOCKED.drawable(); } public void select() { deselectAll(); eyeButton.getStyle().over = BUTTON_BLUE_STYLE.over; lockButton.getStyle().over = BUTTON_BLUE_STYLE.over; eyeButton.getStyle().up = BUTTON_BLUE_STYLE.up; lockButton.getStyle().up = BUTTON_BLUE_STYLE.up; eyeButton.getStyle().down = BUTTON_BLUE_STYLE.down; lockButton.getStyle().down = BUTTON_BLUE_STYLE.down; setBackground(SELECTION); selectedLayer(layer); } public void deselect() { setBackground((Drawable) null); eyeButton.getStyle().over = BUTTON_STYLE.over; lockButton.getStyle().over = BUTTON_STYLE.over; eyeButton.getStyle().up = BUTTON_STYLE.up; lockButton.getStyle().up = BUTTON_STYLE.up; eyeButton.getStyle().down = BUTTON_STYLE.down; lockButton.getStyle().down = BUTTON_STYLE.down; } } }
public MenuItem(String text, Image image, ChangeListener changeListener) { this(text, image, VisUI.getSkin().get(MenuItemStyle.class)); addListener(changeListener); }
public MenuItem(String text, Image image) { this(text, image, VisUI.getSkin().get(MenuItemStyle.class)); }
public MenuItem(String text, Drawable drawable, ChangeListener changeListener) { this(text, drawable, VisUI.getSkin().get(MenuItemStyle.class)); addListener(changeListener); }
public MenuItem(String text, Drawable drawable) { this(text, drawable, VisUI.getSkin().get(MenuItemStyle.class)); }
public MenuItem(String text) { this(text, (Image) null, VisUI.getSkin().get(MenuItemStyle.class)); }
public MenuBar(String styleName) { this(VisUI.getSkin().get(styleName, MenuBarStyle.class)); }
public static VisLabel createLabel(String text, int alignment) { Skin skin = VisUI.getSkin(); VisLabel visLabel = new VisLabel(text, alignment); visLabel.setStyle(skin.get("small", Label.LabelStyle.class)); return visLabel; }
public UIItemProperties() { skin = VisUI.getSkin(); }
@Override public String get() { return VisUI.getFileChooserBundle().get(getName()); }