private void addHorizontalGroup(Table table, Element element) { Table horizontalGroup = new Table(); ScrollPane scrollPane = new ScrollPane(horizontalGroup, skin); Cell<ScrollPane> cell = table.add(scrollPane); ObjectMap<String, String> atrributes = element.getAttributes(); if (atrributes == null) { atrributes = new ObjectMap<String, String>(); } for (String key : atrributes.keys()) { if (key.equalsIgnoreCase("name")) { horizontalGroup.setName(atrributes.get(key)); } } cellPrepare(cell, atrributes); addChildrens(element, horizontalGroup); actorsMap.put(horizontalGroup.getName(), horizontalGroup); }
private void addVerticalGroup(Table table, Element element) { VerticalGroup verticalGroup = new VerticalGroup(); ScrollPane scrollPane = new ScrollPane(verticalGroup, skin); Cell<ScrollPane> cell = table.add(scrollPane); ObjectMap<String, String> atrributes = element.getAttributes(); if (atrributes == null) { atrributes = new ObjectMap<String, String>(); } for (String key : atrributes.keys()) { if (key.equalsIgnoreCase("name")) { verticalGroup.setName(atrributes.get(key)); } } cellPrepare(cell, atrributes); // addChildrens(element, horizontalGroup); actorsMap.put(verticalGroup.getName(), verticalGroup); }
private void addScrollPanel(Table table, Element element) { Table tableScroll = new Table(skin); ScrollPane scrollPane = new ScrollPane(tableScroll, skin); Cell<ScrollPane> cell = table.add(scrollPane); ObjectMap<String, String> atrributes = element.getAttributes(); if (atrributes == null) { atrributes = new ObjectMap<String, String>(); } for (String key : atrributes.keys()) { if (key.equalsIgnoreCase("name")) { tableScroll.setName(atrributes.get(key)); } } cellPrepare(cell, atrributes); addChildrens(element, tableScroll); actorsMap.put(tableScroll.getName(), tableScroll); }
private void addTable(Table table, Element element) { Table newTable = new Table(skin); parseTable(element, newTable); Cell<Table> cell = table.add(newTable); ObjectMap<String, String> atrributes = element.getAttributes(); if (atrributes == null) { atrributes = new ObjectMap<String, String>(); } for (String key : atrributes.keys()) { if (key.equalsIgnoreCase("name")) { newTable.setName(atrributes.get(key)); } } cellPrepare(cell, atrributes); addChildrens(element, newTable); actorsMap.put(newTable.getName(), newTable); }
private void addList(Table table, Element element) { Gdx.app.log("JXmlUi", "addList"); ObjectMap<String, String> atrributes = element.getAttributes(); if (atrributes == null) atrributes = new ObjectMap<String, String>(); List<String> list = new List<String>(skin); list.getSelection().setMultiple(false); ScrollPane scrollPane = new ScrollPane(list, skin); Cell<ScrollPane> cell = table.add(scrollPane); for (String key : atrributes.keys()) { if (key.equalsIgnoreCase("name")) { list.setName(atrributes.get(key)); scrollPane.setName(atrributes.get(key) + "-scroll-panel"); } } cellPrepare(cell, atrributes); actorsMap.put(list.getName(), list); actorsMap.put(scrollPane.getName(), scrollPane); addElementsInList(element, list); }
private void addButton(Table table, Element element) { TextButton button = new TextButton("", skin); Cell<TextButton> cell = table.add(button); ObjectMap<String, String> atrributes = element.getAttributes(); for (String key : atrributes.keys()) { if (key.equalsIgnoreCase("text")) { button.setText(atrributes.get(key)); } else if (key.equalsIgnoreCase("checked")) { button.setChecked(Boolean.parseBoolean(atrributes.get(key))); } else if (key.equalsIgnoreCase("visible")) { button.setVisible(Boolean.parseBoolean(atrributes.get(key))); } else if (key.equalsIgnoreCase("enable")) { button.setDisabled(!Boolean.parseBoolean(atrributes.get(key))); } else if (key.equalsIgnoreCase("name")) { button.setName(atrributes.get(key)); } } cellPrepare(cell, atrributes); // System.out.println("Dodaje button: " + button.getName()); actorsMap.put(button.getName(), button); }
@Override protected void initialize() { Table table = new Table(Config.skin); table.setBackground(Config.skin.getDrawable("ui-tutorial-window-background")); label = new LocLabel("", DieMessageWindow.ACTIVE); label.setWrap(true); label.setAlignment(Align.center); table.setTouchable(Touchable.disabled); Label tapToContinue = new LocLabel("tap-to-continue", DieMessageWindow.INACTIVE); tapToContinue.setWrap(true); tapToContinue.setAlignment(Align.center); if (image != null) { image.setTouchable(Touchable.disabled); table.add(image).padTop(-15 - dy).row(); } final Cell<LocLabel> cell = table.add(label).width(100); if (forceLabelHeight) cell.height(labelHeight); cell.row(); table.add(new Image(Config.skin, "ui-tutorial-window-line")).padTop(4).row(); table.add(tapToContinue).width(80).row(); this.table.add(table); }
public static Array<InventoryItemLocation> getInventory(Table targetTable){ Array<Cell> cells = targetTable.getCells(); Array<InventoryItemLocation> items = new Array<InventoryItemLocation>(); for(int i = 0; i < cells.size; i++){ InventorySlot inventorySlot = ((InventorySlot)cells.get(i).getActor()); if( inventorySlot == null ) continue; int numItems = inventorySlot.getNumItems(); if( numItems > 0 ){ items.add(new InventoryItemLocation( i, inventorySlot.getTopInventoryItem().getItemTypeID().toString(), numItems, inventorySlot.getTopInventoryItem().getName())); } } return items; }
public static Array<InventoryItemLocation> getInventoryFiltered(Table targetTable, String filterOutName){ Array<Cell> cells = targetTable.getCells(); Array<InventoryItemLocation> items = new Array<InventoryItemLocation>(); for(int i = 0; i < cells.size; i++){ InventorySlot inventorySlot = ((InventorySlot)cells.get(i).getActor()); if( inventorySlot == null ) continue; int numItems = inventorySlot.getNumItems(); if( numItems > 0 ){ String topItemName = inventorySlot.getTopInventoryItem().getName(); if( topItemName.equalsIgnoreCase(filterOutName)) continue; //System.out.println("[i] " + i + " itemtype: " + inventorySlot.getTopInventoryItem().getItemTypeID().toString() + " numItems " + numItems); items.add(new InventoryItemLocation( i, inventorySlot.getTopInventoryItem().getItemTypeID().toString(), numItems, inventorySlot.getTopInventoryItem().getName())); } } return items; }
public static Array<InventoryItemLocation> getInventory(Table targetTable, String name){ Array<Cell> cells = targetTable.getCells(); Array<InventoryItemLocation> items = new Array<InventoryItemLocation>(); for(int i = 0; i < cells.size; i++){ InventorySlot inventorySlot = ((InventorySlot)cells.get(i).getActor()); if( inventorySlot == null ) continue; int numItems = inventorySlot.getNumItems(name); if( numItems > 0 ){ //System.out.println("[i] " + i + " itemtype: " + inventorySlot.getTopInventoryItem().getItemTypeID().toString() + " numItems " + numItems); items.add(new InventoryItemLocation( i, inventorySlot.getTopInventoryItem().getItemTypeID().toString(), numItems, name)); } } return items; }
public static Array<InventoryItemLocation> getInventoryFiltered(Table sourceTable, Table targetTable, String filterOutName){ Array<InventoryItemLocation> items = getInventoryFiltered(targetTable, filterOutName); Array<Cell> sourceCells = sourceTable.getCells(); int index = 0; for( InventoryItemLocation item : items ) { for (; index < sourceCells.size; index++) { InventorySlot inventorySlot = ((InventorySlot) sourceCells.get(index).getActor()); if (inventorySlot == null) continue; int numItems = inventorySlot.getNumItems(); if (numItems == 0) { item.setLocationIndex(index); Gdx.app.debug(TAG,"[index] " + index + " itemtype: " + item.getItemTypeAtLocation() + " numItems " + numItems); index++; break; } } if( index == sourceCells.size ){ Gdx.app.debug(TAG,"[index] " + index + " itemtype: " + item.getItemTypeAtLocation() + " numItems " + item.getNumberItemsAtLocation()); item.setLocationIndex(index-1); } } return items; }
public boolean doesInventoryHaveSpace(){ Array<Cell> sourceCells = inventorySlotTable.getCells(); int index = 0; for (; index < sourceCells.size; index++) { InventorySlot inventorySlot = ((InventorySlot) sourceCells.get(index).getActor()); if (inventorySlot == null) continue; int numItems = inventorySlot.getNumItems(); if (numItems == 0) { return true; }else{ index++; } } return false; }
public void addEntityToInventory(Role entity, String itemName){ Array<Cell> sourceCells = inventorySlotTable.getCells(); int index = 0; for (; index < sourceCells.size; index++) { InventorySlot inventorySlot = ((InventorySlot) sourceCells.get(index).getActor()); if (inventorySlot == null) continue; int numItems = inventorySlot.getNumItems(); if (numItems == 0) { InventoryItem inventoryItem = InventoryItemFactory.getInstance().getInventoryItem(InventoryItem.ItemTypeID.valueOf(entity.getItemTypeID())); inventoryItem.setName(itemName); inventorySlot.add(inventoryItem); dragAndDrop.addSource(new InventorySlotSource(inventorySlot, dragAndDrop)); break; } } }
/** * Adds a new line of text to the tooltip. * * This will create a new label, add it as new row * to the tooltip and then return it. * * The created label will use the supplied style. * * If the supplied text is empty or null, this will return null; * * @param newText * @return */ public Label addLine(CharSequence newText, LabelStyle style) { if (newText == null || newText.length() < 1) { return null; } Label label = newLabel(newText, style); Cell<?> cell = add(label).prefWidth(this.style.width).fill().align(Align.left).padLeft(this.style.padLeft).padRight(this.style.padRight).padTop(getRows() == 0 ? this.style.padTop : 0).padBottom(this.style.padBottom); row(); if (getRows() > 1) { getCells().get(getRows()-2).padBottom(0); } pack(); cell.width(label.getGlyphLayout().width); invalidateHierarchy(); this.pack(); return label; }
/** * Adds a new line of text to the log panel. * * This will create a new label and add it as new row * to the log panel. * * The created label will use the supplied color. * * @param newText * @return */ public void logMessage(String text, Color color, boolean logTime) { Label label = newLabel(text, "logLabel"); if (!logTime) { messages.add(label).fillX().expandX().align(Align.left).padLeft(10).top(); } else { Table table = new Table(); table.add(new Label(GameState.getCurrentGameDate().toString(false), style.textStyle)).top(); table.add(label).padLeft(10).fillX().expandX().top(); messages.add(table).fillX().expandX().align(Align.left).padLeft(10).top(); } messages.row(); label.setColor(color); srollPane.layout(); srollPane.setScrollY(srollPane.getMaxY()); if (messages.getCells().size > Configuration.getMaxMessagesInLog()) { @SuppressWarnings("rawtypes") Cell cell = messages.getCells().removeIndex(0); if (cell.getActor() != null) { messages.removeActor((Actor) cell.getActor()); } cell.clearActor(); } }
private void populateCraftableItems(ItemCategory category) { craftingTable.clear(); currentCategory = category; itemNameLabel.setText(""); itemInfoLabel.setText(""); Array<CraftingRecipe> recipes = CraftingRecipes.getInstance().getCraftableItems(category); int y = 0; for (int i = 0; i < recipes.size; i++) { ItemStack stack = recipes.get(i).getCraftedItemStack(); ItemBox box = new ItemBox(stack, String.valueOf(i)); Cell<Table> cell = craftingTable.add((Table) box).width(60).height(60).padRight(10).padBottom(10); if (i % MAX_TABLE_WIDTH == 0) { cell.padLeft(10); } if (y == 0) { cell.padTop(10); } if ((i + 1) % MAX_TABLE_WIDTH == 0) { craftingTable.row(); y++; } } }
@Override public void process(final LmlParser parser, final LmlTag tag, final Actor actor, final String rawAttributeData) { VisLabel lblText = new VisLabel(parser.parseString(rawAttributeData, actor)); lblText.setAlignment(Align.center); boolean needLineWrap = lblText.getPrefWidth() > LINE_WRAP_THRESHOLD; if (needLineWrap) { lblText.setWrap(true); } final Tooltip tooltip = new Tooltip(); tooltip.clearChildren(); // Removing empty cell with predefined paddings. Cell<VisLabel> tooltipCell = tooltip.add(lblText).center().pad(0f, 4f, 2f, 4f); if (needLineWrap) { tooltipCell.width(LINE_WRAP_THRESHOLD); } tooltip.pack(); tooltip.setTarget(actor); }
public ProgressTable(ShipProgressBar.ProgressType progressType) { this.progressType = progressType; String texturePrefix; if (progressType == ShipProgressBar.ProgressType.SHIELD) { texturePrefix = "ShieldProgressBar0"; } else { texturePrefix = "progressBar0"; } left().bottom(); images = new Image[8]; for (int i = 0; i < images.length; i++) { int imageIndex = progressType == ShipProgressBar.ProgressType.SHIELD ? images.length - i - 1: i; Image tmpImage = new Image(App.TEXTURES.findRegion(texturePrefix + ((imageIndex / 2) + 1))); Cell<Image> imageCell = add(tmpImage).padLeft(5).padBottom(5); images[i] = imageCell.getActor(); } pack(); }
/** This is meant to handle cell attributes that will modify the extracted cell. * * @param attributes named attributes of the macro. * @param processedAttributes already processed attributes. Should be ignored. * @param table owner of the cell. * @param cell cell of the row. Should have its defaults set. */ protected void processCellAttributes(final ObjectMap<String, String> attributes, final ObjectSet<String> processedAttributes, final Table table, final Cell<?> cell) { final LmlSyntax syntax = getParser().getSyntax(); for (final Entry<String, String> attribute : attributes) { if (processedAttributes.contains(attribute.key)) { continue; } final LmlAttribute<?> cellAttribute = syntax.getAttributeProcessor(table, attribute.key); if (cellAttribute instanceof AbstractCellLmlAttribute) { ((AbstractCellLmlAttribute) cellAttribute).process(getParser(), getParent(), table, cell, attribute.value); } else { if (!isInternalMacroAttribute(attribute.key)) { getParser().throwErrorIfStrict(getTagName() + " macro can process only cell attributes. Found unknown or invalid attribute: " + attribute.key); } } } }
private void addWindow(Table table, Element element) { Gdx.app.log("JXmlUi", "addWindow"); String title = element.get("title", ""); Table newTable = new Window(title, skin); Cell<Table> cell = table.add(newTable); ObjectMap<String, String> atrributes = element.getAttributes(); if (atrributes == null) { atrributes = new ObjectMap<String, String>(); } cellPrepare(cell, atrributes); addChildrens(element, newTable); }
private void addImage(Table table, Element element) { Image image = new Image(new Texture(element.get("path"))); Cell<Image> cell = table.add(image); ObjectMap<String, String> atrributes = element.getAttributes(); for (String key : atrributes.keys()) { if (key.equalsIgnoreCase("name")) { image.setName(atrributes.get(key)); } } cellPrepare(cell, atrributes); actorsMap.put(image.getName(), image); }
private void addLabel(Table table, Element element) { ObjectMap<String, String> atrributes = element.getAttributes(); Label label = new Label(element.get("text", ""), skin); Cell<Label> cell = table.add(label); for (String key : atrributes.keys()) { if (key.equalsIgnoreCase("name")) { label.setName(atrributes.get(key)); } } cellPrepare(cell, atrributes); actorsMap.put(label.getName(), label); }
private void addTextArea(Table table, Element element) { ObjectMap<String, String> atrributes = element.getAttributes(); TextArea textArea = new TextArea(element.get("text", ""), skin); Cell<TextArea> cell = table.add(textArea); for (String key : atrributes.keys()) { if (key.equalsIgnoreCase("name")) { textArea.setName(atrributes.get(key)); } } cellPrepare(cell, atrributes); actorsMap.put(textArea.getName(), textArea); }
private void addTextField(Table table, Element element) { ObjectMap<String, String> atrributes = element.getAttributes(); TextField textField = new TextField(element.get("text", ""), skin); Cell<TextField> cell = table.add(textField); for (String key : atrributes.keys()) { if (key.equalsIgnoreCase("name")) { textField.setName(atrributes.get(key)); } } cellPrepare(cell, atrributes); actorsMap.put(textField.getName(), textField); }
private Cell createValues() { this.row(); Group group = new Group(); group.addActor(decValues); float height = (CB.scaledSizes.BUTTON_HEIGHT * 2) + CB.scaledSizes.MARGIN * 4; return this.add(group).height(new Value.Fixed(height)); }
public static void clearInventoryItems(Table targetTable){ Array<Cell> cells = targetTable.getCells(); for( int i = 0; i < cells.size; i++){ InventorySlot inventorySlot = (InventorySlot)cells.get(i).getActor(); if( inventorySlot == null ) continue; inventorySlot.clearAllInventoryItems(false); } }
public static Array<InventoryItemLocation> removeInventoryItems(String name, Table inventoryTable){ Array<Cell> cells = inventoryTable.getCells(); Array<InventoryItemLocation> items = new Array<InventoryItemLocation>(); for(int i = 0; i < cells.size; i++){ InventorySlot inventorySlot = ((InventorySlot)cells.get(i).getActor()); if( inventorySlot == null ) continue; inventorySlot.removeAllInventoryItemsWithName(name); } return items; }
public static void populateInventory(Table targetTable, Array<InventoryItemLocation> inventoryItems, DragAndDrop draganddrop, String defaultName, boolean disableNonDefaultItems){ clearInventoryItems(targetTable); Array<Cell> cells = targetTable.getCells(); for(int i = 0; i < inventoryItems.size; i++){ InventoryItemLocation itemLocation = inventoryItems.get(i); InventoryItem.ItemTypeID itemTypeID = InventoryItem.ItemTypeID.valueOf(itemLocation.getItemTypeAtLocation()); InventorySlot inventorySlot = ((InventorySlot)cells.get(itemLocation.getLocationIndex()).getActor()); for( int index = 0; index < itemLocation.getNumberItemsAtLocation(); index++ ){ InventoryItem item = InventoryItemFactory.getInstance().getInventoryItem(itemTypeID); String itemName = itemLocation.getItemNameProperty(); if( itemName == null || "".equals(itemName.trim())){ item.setName(defaultName); }else{ item.setName(itemName); } inventorySlot.add(item); if( item.getName().equalsIgnoreCase(defaultName) ){ draganddrop.addSource(new InventorySlotSource(inventorySlot, draganddrop)); }else if( disableNonDefaultItems == false ){ draganddrop.addSource(new InventorySlotSource(inventorySlot, draganddrop)); } } } }
public static void setInventoryItemNames(Table targetTable, String name){ Array<Cell> cells = targetTable.getCells(); for(int i = 0; i < cells.size; i++){ InventorySlot inventorySlot = ((InventorySlot)cells.get(i).getActor()); if( inventorySlot == null ) continue; inventorySlot.updateAllInventoryItemNames(name); } }
public void removeQuestItemFromInventory(String questID){ Array<Cell> sourceCells = inventorySlotTable.getCells(); for (int index = 0; index < sourceCells.size; index++) { InventorySlot inventorySlot = ((InventorySlot) sourceCells.get(index).getActor()); if (inventorySlot == null) continue; InventoryItem item = inventorySlot.getTopInventoryItem(); if( item == null ) continue; String inventoryItemName = item.getName(); if (inventoryItemName != null && inventoryItemName.equals(questID) ) { inventorySlot.clearAllInventoryItems(false); } } }
@Override public void dragStart(InputEvent event, float x, float y, int pointer) { draggedPCPortrait = getPCPortrait(hit(x, y, true)); if (draggedPCPortrait != null) { draggedPCPortrait.setTouchable(Touchable.disabled); Cell<?> cell = getCell(draggedPCPortrait); cell.setActor(null); cell.width(draggedPCPortrait.getWidth()); cell.height(draggedPCPortrait.getHeight()); addActor(draggedPCPortrait); setPositionWithinStage(draggedPCPortrait, x, y); } }
/** Null-safe method that clears a Cell of a Table. * * @param tableCell can be null. Will have its actor removed and will be reset. */ public static void clearCell(final Cell<?> tableCell) { if (tableCell != null) { tableCell.clearActor(); tableCell.reset(); } }
@Override public <T extends Actor> Cell<T> add(final T actor) { if (actor instanceof VisValidatableTextField) { formValidator.add((VisValidatableTextField) actor); } return super.add(actor); }
private void initialize () { setTouchable(Touchable.enabled); tabTitleTable = new Table(); tabBodyStack = new Stack(); selectedIndex = -1; // Create 1st row Cell<?> leftCell = add(new Image(style.titleBegin)); Cell<?> midCell = add(tabTitleTable); Cell<?> rightCell = add(new Image(style.titleEnd)); switch (tabTitleAlign) { case Align.left: leftCell.width(((Image)leftCell.getActor()).getWidth()).bottom(); midCell.left(); rightCell.expandX().fillX().bottom(); break; case Align.right: leftCell.expandX().fillX().bottom(); midCell.right(); rightCell.width(((Image)rightCell.getActor()).getWidth()).bottom(); break; case Align.center: leftCell.expandX().fillX().bottom(); midCell.center(); rightCell.expandX().fillX().bottom(); break; default: throw new IllegalArgumentException("TabbedPane align must be one of left, center, right"); } // Create 2nd row row(); Table t = new Table(); t.setBackground(style.bodyBackground); t.add(tabBodyStack).expand().fill(); add(t).colspan(3).expand().fill(); }
@Override public void process(final LmlParser parser, final LmlTag tag, final Actor actor, final Cell<?> cell, final String rawAttributeData) { if (parser.parseBoolean(rawAttributeData, actor)) { cell.growY(); } }
@Override public void process(final LmlParser parser, final LmlTag tag, final Actor actor, final Cell<?> cell, final String rawAttributeData) { final Value horizontalValue = LmlUtilities.parseHorizontalValue(parser, tag.getParent(), actor, rawAttributeData); final Value verticalValue = LmlUtilities.parseVerticalValue(parser, tag.getParent(), actor, rawAttributeData); cell.prefSize(horizontalValue, verticalValue); }
@Override public void process(final LmlParser parser, final LmlTag tag, final Actor actor, final Cell<?> cell, final String rawAttributeData) { final Value horizontalValue = LmlUtilities.parseHorizontalValue(parser, tag.getParent(), actor, rawAttributeData); cell.maxWidth(horizontalValue); }
@Override public final void process(final LmlParser parser, final LmlTag tag, final Actor actor, final String rawAttributeData) { if (tag.isAttachable()) { parser.throwErrorIfStrict(tag.getTagName() + " is an attachable tag and cannot be stored in a table, even if its direct parent is a table tag. Attachable actors, like tooltips, are usually autonomic: they cannot be added to a table or honor cell settings."); return; } final Cell<?> cell = LmlUtilities.getCell(actor, tag.getParent()); if (cell == null) { processForActor(parser, tag, actor, rawAttributeData); } else { process(parser, tag, actor, cell, rawAttributeData); } }
@Override public void process(final LmlParser parser, final LmlTag tag, final Actor actor, final Cell<?> cell, final String rawAttributeData) { final Value horizontalValue = LmlUtilities.parseHorizontalValue(parser, tag.getParent(), actor, rawAttributeData); cell.padLeft(horizontalValue); }