Search in sources :

Example 1 with G_ListPanel

use of main.swing.generic.components.panels.G_ListPanel in project Eidolons by IDemiurge.

the class UnitGroupMaster method chooseUnit.

private static ObjType chooseUnit(ObjType factionType, int power, int max_power) {
    Map<ObjType, Integer> pool = initPool(factionType);
    List<ObjType> available = new ArrayList<>();
    for (ObjType l : pool.keySet()) {
        if (getUnitCost(l, factionType) > power) {
            continue;
        }
        if (l.getIntParam(PARAMS.POWER) > max_power) {
            continue;
        }
        available.add(l);
    }
    if (available.isEmpty()) {
        return null;
    }
    // chooseUnit();
    Map<String, String> map = new HashMap<>();
    for (ObjType type : pool.keySet()) {
        map.put(type.getName(), "Cost: " + pool.get(type) + "; Power: " + type.getIntParam(PARAMS.POWER));
    }
    ListChooser.setDecorator(new Decorator() {

        @Override
        public void addComponents(G_Panel panel) {
            G_ListPanel<ObjType> list = // new CustomList<>(getUnitList());
            new G_ListPanel<ObjType>(getUnitList()) {

                @Override
                public void setInts() {
                    wrap = 1;
                    minItems = max;
                    rowsVisible = 1;
                    layoutOrientation = JList.HORIZONTAL_WRAP;
                }

                @Override
                public boolean isVertical() {
                    return false;
                }
            };
            list.setPanelSize(new Dimension(300, 120));
            panel.add(list, "pos tp.x decor_info.y2");
            WrappedTextComp textComp = new WrappedTextComp(null) {

                @Override
                protected Color getColor() {
                    return Color.black;
                }

                @Override
                public synchronized List<String> getTextLines() {
                    List<String> list = new ArrayList<>();
                    list.add(UnitGroupMaster.getRemainingPower() + " points remaining");
                    list.add("Size contraints: between " + min + " and " + max);
                    return list;
                }
            };
            textComp.setDefaultSize(new Dimension(300, 120));
            panel.add(textComp, "id decor_info, pos tp.x tp.y2");
        }
    });
    ListChooser.setTooltipMapForComponent(map);
    ListChooser.setSortingDisabled(true);
    return ListChooser.chooseType_(available, DC_TYPE.UNITS);
// gui - a list per ally
}
Also used : G_ListPanel(main.swing.generic.components.panels.G_ListPanel) HashMap(java.util.HashMap) G_Panel(main.swing.generic.components.G_Panel) ArrayList(java.util.ArrayList) Decorator(main.swing.generic.Decorator) ObjType(main.entity.type.ObjType) WrappedTextComp(eidolons.swing.components.panels.page.log.WrappedTextComp) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

WrappedTextComp (eidolons.swing.components.panels.page.log.WrappedTextComp)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ObjType (main.entity.type.ObjType)1 Decorator (main.swing.generic.Decorator)1 G_Panel (main.swing.generic.components.G_Panel)1 G_ListPanel (main.swing.generic.components.panels.G_ListPanel)1