Search in sources :

Example 1 with Constraint

use of me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint in project iChunUtil by iChun.

the class ViewValues method addControlFor.

public void addControlFor(final WorkspaceConfigs.ConfigInfo.ValueWrapperLocalised value, ElementList.Item<?> item) {
    Field field = value.value.field;
    field.setAccessible(true);
    String fieldName = field.getName();
    Class clz = field.getType();
    // should always exist
    Prop props;
    if (field.isAnnotationPresent(Prop.class)) {
        props = field.getAnnotation(Prop.class);
    } else {
        props = ConfigBase.class.getDeclaredFields()[0].getAnnotation(Prop.class);
    }
    Object o;
    try {
        o = field.get(value.value.parent);
    } catch (IllegalAccessException e) {
        return;
    }
    boolean handled = false;
    if (!props.guiElementOverride().isEmpty()) {
        BiFunction<WorkspaceConfigs.ConfigInfo.ValueWrapperLocalised, ElementList.Item<?>, Boolean> valueWrapperLocalisedItemBiFunction = ConfigBase.GUI_ELEMENT_OVERRIDES.get(props.guiElementOverride());
        if (valueWrapperLocalisedItemBiFunction != null && valueWrapperLocalisedItemBiFunction.apply(value, item)) {
            handled = true;
        }
    }
    if (!handled) {
        if (clz == int.class) {
            ElementNumberInput input = new ElementNumberInput(item, false);
            input.setMin(props.min() == Double.MIN_VALUE ? Integer.MIN_VALUE : (int) props.min());
            input.setMax(props.max() == Double.MAX_VALUE ? Integer.MAX_VALUE : (int) props.max());
            input.setDefaultText(o.toString());
            input.setSize(80, 14);
            input.setConstraint(new Constraint(input).top(item, Constraint.Property.Type.TOP, 3).bottom(item, Constraint.Property.Type.BOTTOM, 3).right(item, Constraint.Property.Type.RIGHT, 8));
            item.addElement(input);
        } else if (clz == double.class) {
            ElementNumberInput input = new ElementNumberInput(item, true);
            input.setMin(props.min());
            input.setMax(props.max());
            input.setMaxDec(2);
            input.setDefaultText(o.toString());
            input.setSize(80, 14);
            input.setConstraint(new Constraint(input).top(item, Constraint.Property.Type.TOP, 3).bottom(item, Constraint.Property.Type.BOTTOM, 3).right(item, Constraint.Property.Type.RIGHT, 8));
            item.addElement(input);
        } else if (clz == boolean.class) {
            ElementToggleTextable<?> toggle = new ElementToggleTextable<>(item, value.name, elementClickable -> {
            }).setToggled((boolean) o);
            toggle.setSize(80, 14);
            toggle.setConstraint(new Constraint(toggle).top(item, Constraint.Property.Type.TOP, 3).bottom(item, Constraint.Property.Type.BOTTOM, 3).right(item, Constraint.Property.Type.RIGHT, 8));
            item.addElement(toggle);
        } else if (clz == String.class) {
            ElementTextField input = new ElementTextField(item);
            input.setDefaultText(o.toString());
            input.setSize(80, 14);
            input.setConstraint(new Constraint(input).top(item, Constraint.Property.Type.TOP, 3).bottom(item, Constraint.Property.Type.BOTTOM, 3).right(item, Constraint.Property.Type.RIGHT, 8));
            item.addElement(input);
        } else if (// enum!
        clz.isEnum()) {
            ElementDropdownContextMenu<?> input = new ElementDropdownContextMenu<>(item, o.toString(), Arrays.asList(clz.getEnumConstants()), (menu, listItem) -> {
                if (listItem.selected) {
                    ElementDropdownContextMenu<?> contextMenu = (ElementDropdownContextMenu<?>) menu;
                    contextMenu.text = listItem.getObject().toString();
                }
            });
            input.setSize(80, 14);
            input.setConstraint(new Constraint(input).top(item, Constraint.Property.Type.TOP, 3).bottom(item, Constraint.Property.Type.BOTTOM, 3).right(item, Constraint.Property.Type.RIGHT, 8));
            item.addElement(input);
        } else if (// lists
        o instanceof List) {
            StringBuilder sb = new StringBuilder();
            final List list = (List) o;
            for (int i = 0; i < list.size(); i++) {
                Object o1 = list.get(i);
                sb.append(o1);
                if (i < list.size() - 1) {
                    sb.append("\n");
                }
            }
            ElementButton<?> button = new ElementButton<>(item, "selectWorld.edit", btn -> {
                value.value.field.setAccessible(true);
                Type typefield = value.value.field.getGenericType();
                if (typefield instanceof ParameterizedType) {
                    ParameterizedType type = (ParameterizedType) typefield;
                    Type[] types = type.getActualTypeArguments();
                    if (types.length == 1) {
                        // get which kind of validator we should use
                        Predicate<String> validator = null;
                        if (types[0] == String.class) {
                            validator = str -> true;
                        } else if (types[0] == Double.class) {
                            validator = ElementTextField.NUMBERS;
                        } else if (types[0] == Integer.class) {
                            validator = ElementTextField.INTEGERS;
                        }
                        if (validator != null) {
                            if (!(props.values().length == 1 && props.values()[0].isEmpty())) {
                                String[] values = props.values();
                                validator = validator.and(s -> {
                                    for (String value1 : values) {
                                        if (value1.startsWith(s)) {
                                            return true;
                                        }
                                    }
                                    return false;
                                });
                            }
                            WindowEditList<?> window = new WindowEditList<>(getWorkspace(), value.name, list, validator, list1 -> {
                                try {
                                    List listToUse = list;
                                    if (list instanceof ArrayList) {
                                        listToUse = (List) ((ArrayList) list).clone();
                                    }
                                    listToUse.clear();
                                    for (ElementList.Item<?> item1 : list1.items) {
                                        ElementTextField oriText = (ElementTextField) item1.elements.get(0);
                                        if (!oriText.getText().isEmpty()) {
                                            if (types[0] == String.class) {
                                                listToUse.add(oriText.getText());
                                            } else if (types[0] == Double.class) {
                                                listToUse.add(Double.parseDouble(oriText.getText()));
                                            } else if (types[0] == Integer.class) {
                                                listToUse.add(Integer.parseInt(oriText.getText()));
                                            }
                                        }
                                    }
                                    value.value.field.set(value.value.parent, listToUse);
                                    value.value.parent.save();
                                } catch (IllegalAccessException ignored) {
                                }
                            });
                            getWorkspace().openWindowInCenter(window, 0.6D, 0.8D);
                            // reinit cause we're using lists and they're weird
                            window.init();
                        }
                    }
                }
            });
            button.setTooltip(sb.toString());
            button.setSize(80, 14);
            button.setConstraint(new Constraint(button).top(item, Constraint.Property.Type.TOP, 3).bottom(item, Constraint.Property.Type.BOTTOM, 3).right(item, Constraint.Property.Type.RIGHT, 8));
            item.addElement(button);
        }
    }
}
Also used : Arrays(java.util.Arrays) me.ichun.mods.ichunutil.client.gui.bns.window.view.element(me.ichun.mods.ichunutil.client.gui.bns.window.view.element) Predicate(java.util.function.Predicate) BiFunction(java.util.function.BiFunction) WorkspaceConfigs(me.ichun.mods.ichunutil.client.gui.config.WorkspaceConfigs) Field(java.lang.reflect.Field) View(me.ichun.mods.ichunutil.client.gui.bns.window.view.View) TreeSet(java.util.TreeSet) Prop(me.ichun.mods.ichunutil.common.config.annotations.Prop) ArrayList(java.util.ArrayList) Constraint(me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint) List(java.util.List) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) WindowValues(me.ichun.mods.ichunutil.client.gui.config.window.WindowValues) WindowEditList(me.ichun.mods.ichunutil.client.gui.bns.window.WindowEditList) ConfigBase(me.ichun.mods.ichunutil.common.config.ConfigBase) Nonnull(javax.annotation.Nonnull) Constraint(me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint) ArrayList(java.util.ArrayList) ConfigBase(me.ichun.mods.ichunutil.common.config.ConfigBase) Predicate(java.util.function.Predicate) ParameterizedType(java.lang.reflect.ParameterizedType) Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) List(java.util.List) WindowEditList(me.ichun.mods.ichunutil.client.gui.bns.window.WindowEditList) WorkspaceConfigs(me.ichun.mods.ichunutil.client.gui.config.WorkspaceConfigs) Prop(me.ichun.mods.ichunutil.common.config.annotations.Prop) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) WindowEditList(me.ichun.mods.ichunutil.client.gui.bns.window.WindowEditList)

Example 2 with Constraint

use of me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint in project iChunUtil by iChun.

the class WindowDock method addToDocked.

public boolean addToDocked(Window<?> dockedWin, Window<?> window) {
    for (Map.Entry<ArrayListHolder, Constraint.Property.Type> e : docked.entrySet()) {
        if (e.getKey().windows.contains(dockedWin)) {
            dockedOriSize.put(window, new WindowSize(window.constraint, window.getLeft(), window.getTop(), window.getWidth(), window.getHeight()));
            Constraint.Property.Type dockType = e.getValue();
            ArrayList<Window<?>> dockStack = e.getKey().windows;
            // we stack downwards and to the right.
            Window<?> lastInStack = dockStack.get(dockStack.size() - 1);
            int maxWidth = -1;
            int maxHeight = -1;
            if (dockType.getAxis().isHorizontal()) {
                maxWidth = window.width;
                for (Window<?> window1 : dockStack) {
                    if (window1.width > maxWidth) {
                        maxWidth = window1.width;
                    }
                }
            } else if (dockType.getAxis().isVertical()) {
                maxHeight = window.height;
                for (Window<?> window1 : dockStack) {
                    if (window1.height > maxHeight) {
                        maxHeight = window1.height;
                    }
                }
            }
            Constraint constraint = new Constraint(window);
            Constraint.Property.Type[] values = Constraint.Property.Type.values();
            for (int i = values.length - 1; i >= 0; i--) {
                Constraint.Property.Type type1 = values[i];
                if (type1.equals(WIDTH) || type1.equals(HEIGHT)) {
                    continue;
                }
                IConstrainable constrainable = getWindowAnchor(lastInStack, type1);
                if (// X. if type1 == top, anchor is lastInStack, same for Y.
                dockType.getAxis().isHorizontal() && type1 == TOP || dockType.getAxis().isVertical() && type1 == LEFT) {
                    constrainable = lastInStack;
                    // we drop the constraint of lastInStack. let it free float.
                    lastInStack.constraint.type(type1.getOpposite(), null, null, 0);
                    // set the size
                    if (// if we're docked left or right, reset height
                    type1 == TOP) {
                        lastInStack.setHeight(dockedOriSize.get(lastInStack).height);
                    } else {
                        lastInStack.setWidth(dockedOriSize.get(lastInStack).width);
                    }
                }
                if (type1 != dockType.getOpposite()) {
                    if (constrainable != null && !(constrainable instanceof WindowDock)) {
                        constraint = constraint.type(type1, constrainable, type1.getOpposite(), -(Integer) window.borderSize.get() + borderSize.get());
                    } else {
                        constraint = constraint.type(type1, this, type1, -(Integer) window.borderSize.get() + borderSize.get());
                    }
                }
            }
            e.getKey().windows.add(window);
            window.setConstraint(constraint);
            for (Window<?> window1 : dockStack) {
                if (maxWidth >= 0) {
                    window1.setWidth(maxWidth);
                } else if (maxHeight >= 0) {
                    window1.setHeight(maxHeight);
                }
                window1.constraint.apply();
                if (getWorkspace().hasInit()) {
                    window1.resize(Minecraft.getInstance(), this.width, this.height);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Constraint(me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint) Constraint(me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint) Type(me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint.Property.Type) Type(me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint.Property.Type) IConstrainable(me.ichun.mods.ichunutil.client.gui.bns.window.constraint.IConstrainable)

Example 3 with Constraint

use of me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint in project iChunUtil by iChun.

the class WindowDock method removeFromDock.

public void removeFromDock(Window<?> window) {
    boolean redoConstraints = false;
    Iterator<Map.Entry<ArrayListHolder, Constraint.Property.Type>> iterator = docked.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<ArrayListHolder, Constraint.Property.Type> e = iterator.next();
        ArrayList<Window<?>> windows = e.getKey().windows;
        // redo the constraints
        EnumMap<Constraint.Property.Type, Constraint.Property> anchors = new EnumMap<>(Constraint.Property.Type.class);
        if (redoConstraints || windows.contains(window)) {
            for (Constraint.Property.Type type : Constraint.Property.Type.values()) {
                if (type.equals(WIDTH) || type.equals(HEIGHT)) {
                    continue;
                }
                Constraint.Property stackAnchor = getStackAnchor(windows, type);
                if (stackAnchor != null) {
                    anchors.put(type, stackAnchor);
                }
            }
        }
        if (// window is in this arraylist. sort it out
        windows.contains(window)) {
            redoConstraints = true;
            if (windows.size() == 1) {
                // we're using a linkedHASHmap. Empty ArrayLists aren't very friendly.
                iterator.remove();
                continue;
            } else // we're in a dock stack.
            {
                // we have the anchors of each type. remove the nonbeliever!
                windows.remove(window);
            }
        }
        if (redoConstraints) {
            Constraint.Property.Type dockType = e.getValue();
            // Update the constraints
            for (int i = 0; i < windows.size(); i++) {
                Window<?> dockWindow = windows.get(i);
                if (i == 0) {
                    Constraint constraint = new Constraint(dockWindow);
                    anchors.forEach((type, property) -> {
                        if (property.getReference() == window) {
                            IConstrainable constrainable = getAnchor(type, dockWindow);
                            if (constrainable != null && constrainable != dockWindow) {
                                constraint.type(type, constrainable, type.getOpposite(), -(Integer) dockWindow.borderSize.get() + borderSize.get());
                            } else {
                                constraint.type(type, this, type, -(Integer) dockWindow.borderSize.get() + borderSize.get());
                            }
                        } else {
                            constraint.type(type, property.getReference(), property.getType(), property.getDist());
                        }
                    });
                    dockWindow.setConstraint(constraint);
                } else {
                    // we stack downwards and to the right.
                    Window<?> lastInStack = windows.get(i - 1);
                    Constraint constraint = new Constraint(dockWindow);
                    Constraint.Property.Type[] values = Constraint.Property.Type.values();
                    for (int ii = values.length - 1; ii >= 0; ii--) {
                        Constraint.Property.Type type1 = values[ii];
                        if (type1.equals(WIDTH) || type1.equals(HEIGHT)) {
                            continue;
                        }
                        IConstrainable constrainable = getWindowAnchor(lastInStack, type1);
                        if (// X. if type1 == top, anchor is lastInStack, same for Y.
                        dockType.getAxis().isHorizontal() && type1 == TOP || dockType.getAxis().isVertical() && type1 == LEFT) {
                            constrainable = lastInStack;
                            // we drop the constraint of lastInStack. let it free float.
                            lastInStack.constraint.type(type1.getOpposite(), null, null, 0);
                            // set the size
                            if (// if we're docked left or right, reset height
                            type1 == TOP) {
                                lastInStack.setHeight(dockedOriSize.get(lastInStack).height);
                            } else {
                                lastInStack.setWidth(dockedOriSize.get(lastInStack).width);
                            }
                        }
                        if (type1 != dockType.getOpposite()) {
                            if (constrainable != null && !(constrainable instanceof WindowDock)) {
                                constraint = constraint.type(type1, constrainable, type1.getOpposite(), -(Integer) dockWindow.borderSize.get() + borderSize.get());
                            } else {
                                constraint = constraint.type(type1, this, type1, -(Integer) dockWindow.borderSize.get() + borderSize.get());
                            }
                        }
                    }
                    dockWindow.setConstraint(constraint);
                }
            }
            for (Window<?> window1 : windows) {
                window1.constraint.apply();
                if (getWorkspace().hasInit()) {
                    window1.resize(Minecraft.getInstance(), this.width, this.height);
                }
            }
        }
    }
    WindowSize size = dockedOriSize.get(window);
    window.setConstraint(size.constraint);
    if (!(size.x == 0 && size.y == 0)) {
        window.setLeft(size.x);
        window.setTop(size.y);
    }
    window.setWidth(size.width);
    window.setHeight(size.height);
    window.resize(Minecraft.getInstance(), window.parent.getWidth(), window.parent.getHeight());
    dockedOriSize.remove(window);
}
Also used : Constraint(me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint) Constraint(me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint) Type(me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint.Property.Type) Type(me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint.Property.Type) IConstrainable(me.ichun.mods.ichunutil.client.gui.bns.window.constraint.IConstrainable)

Example 4 with Constraint

use of me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint in project iChunUtil by iChun.

the class ConfigClient method init.

@Override
public <T extends ConfigBase> T init() {
    GUI_ELEMENT_OVERRIDES.put("iChunUtil:guiDefaultTheme", (value, item) -> {
        Field field = value.value.field;
        field.setAccessible(true);
        Object o;
        try {
            o = field.get(value.value.parent);
        } catch (IllegalAccessException e) {
            iChunUtil.LOGGER.error("Error accessing config field {} when creating config. Stopping config creation.", field.getName());
            e.printStackTrace();
            return true;
        }
        ArrayList<File> files = new ArrayList<>();
        File[] themes = ResourceHelper.getThemesDir().toFile().listFiles();
        if (themes != null) {
            for (File file : themes) {
                if (!file.isDirectory() && file.getName().endsWith(".json")) {
                    files.add(file);
                }
            }
        }
        Collections.sort(files);
        ElementDropdownContextMenu<?> input = new ElementDropdownContextMenu<>(item, o.toString(), files, (menu, listItem) -> {
            if (listItem.selected) {
                ElementDropdownContextMenu<?> contextMenu = (ElementDropdownContextMenu<?>) menu;
                File file = (File) listItem.getObject();
                // trim the ".json"
                contextMenu.text = file.getName().substring(0, file.getName().length() - 5);
                // update the theme here
                try {
                    InputStream con = new FileInputStream(file);
                    String data = new String(ByteStreams.toByteArray(con));
                    con.close();
                    Theme theme = (new Gson()).fromJson(data, Theme.class);
                    if (theme != null) {
                        field.set(value.value.parent, contextMenu.text);
                        Theme.loadTheme(theme);
                    }
                } catch (IOException | IllegalAccessException ignored) {
                }
            }
        }).setNameProvider(o1 -> ((File) o1).getName().substring(0, ((File) o1).getName().length() - 5));
        input.setSize(80, 14);
        input.setConstraint(new Constraint(input).top(item, Constraint.Property.Type.TOP, 3).bottom(item, Constraint.Property.Type.BOTTOM, 3).right(item, Constraint.Property.Type.RIGHT, 8));
        item.addElement(input);
        return true;
    });
    GUI_ELEMENT_OVERRIDES.put("iChunUtil:reloadHeadsButton", (value, itemOri) -> {
        ElementList.Item<?> item = itemOri.parentFragment.addItem(value).setBorderSize(0);
        item.setSelectionHandler(itemObj -> {
            if (itemObj.selected) {
                for (Element<?> element : itemObj.elements) {
                    if (element instanceof ElementTextWrapper || element instanceof ElementPadding) {
                        continue;
                    }
                    element.parentFragment.setListener(element);
                    element.mouseClicked(element.getLeft() + element.getWidth() / 2D, element.getTop() + element.getHeight() / 2D, 0);
                    element.mouseReleased(element.getLeft() + element.getWidth() / 2D, element.getTop() + element.getHeight() / 2D, 0);
                    break;
                }
            }
        });
        ElementTextWrapper wrapper = new ElementTextWrapper(item).setText(I18n.format("config.ichunutil.headTracking.reload.desc"));
        wrapper.setConstraint(new Constraint(wrapper).left(item, Constraint.Property.Type.LEFT, 3).right(item, Constraint.Property.Type.RIGHT, 90));
        wrapper.setTooltip(value.desc);
        item.addElement(wrapper);
        ElementPadding padding = new ElementPadding(item, 0, 20);
        padding.setConstraint(new Constraint(padding).right(item, Constraint.Property.Type.RIGHT, 0));
        item.addElement(padding);
        ElementButton<?> button = new ElementButton<>(item, "config.ichunutil.headTracking.reload.btn", btn -> {
            if (HeadHandler.hasInit()) {
                int count = HeadHandler.loadHeadInfos();
                WindowPopup.popup(item.getWorkspace(), 0.6D, 0.6D, null, I18n.format("config.ichunutil.headTracking.reload.count", count));
            } else {
                WindowPopup.popup(item.getWorkspace(), 0.6D, 0.6D, null, I18n.format("config.ichunutil.headTracking.notLoaded"));
            }
        });
        button.setTooltip(I18n.format("config.ichunutil.headTracking.reload.desc"));
        button.setSize(80, 14);
        button.setConstraint(new Constraint(button).top(item, Constraint.Property.Type.TOP, 3).bottom(item, Constraint.Property.Type.BOTTOM, 3).right(item, Constraint.Property.Type.RIGHT, 8));
        item.addElement(button);
        ElementButton<?> button1 = new ElementButton<>(item, "config.ichunutil.headTracking.reload.reextract", btn -> {
            try {
                if (HeadHandler.hasInit()) {
                    InputStream in = iChunUtil.class.getResourceAsStream("/heads.zip");
                    if (in != null) {
                        int extCount = IOUtil.extractFiles(HeadHandler.getHeadsDir(), in, true);
                        HeadHandler.loadHeadInfos();
                        WindowPopup.popup(item.getWorkspace(), 0.6D, 0.6D, null, I18n.format("config.ichunutil.headTracking.reload.reextract.count", extCount));
                    } else {
                        iChunUtil.LOGGER.error("Error extracting heads.zip.");
                        WindowPopup.popup(item.getWorkspace(), 0.6D, 0.6D, null, "Error!", "Error extracting heads.zip.");
                    }
                } else {
                    WindowPopup.popup(item.getWorkspace(), 0.6D, 0.6D, null, I18n.format("config.ichunutil.headTracking.notLoaded"));
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
        button1.setTooltip(I18n.format("config.ichunutil.headTracking.reload.reextract.desc"));
        button1.setSize(80, 14);
        button1.setConstraint(new Constraint(button1).top(item, Constraint.Property.Type.TOP, 3).bottom(item, Constraint.Property.Type.BOTTOM, 3).right(button, Constraint.Property.Type.LEFT, 4));
        item.addElement(button1);
        // we still want the button to generate, this is a hook in.
        return false;
    });
    return super.init();
}
Also used : me.ichun.mods.ichunutil.client.gui.bns.window.view.element(me.ichun.mods.ichunutil.client.gui.bns.window.view.element) CategoryDivider(me.ichun.mods.ichunutil.common.config.annotations.CategoryDivider) WindowPopup(me.ichun.mods.ichunutil.client.gui.bns.window.WindowPopup) HeadHandler(me.ichun.mods.ichunutil.common.head.HeadHandler) Theme(me.ichun.mods.ichunutil.client.gui.bns.Theme) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) me.ichun.mods.ichunutil.common.iChunUtil(me.ichun.mods.ichunutil.common.iChunUtil) Field(java.lang.reflect.Field) IOUtil(me.ichun.mods.ichunutil.common.util.IOUtil) File(java.io.File) Prop(me.ichun.mods.ichunutil.common.config.annotations.Prop) ArrayList(java.util.ArrayList) I18n(net.minecraft.client.resources.I18n) Constraint(me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint) Gson(com.google.gson.Gson) ByteStreams(com.google.common.io.ByteStreams) ModConfig(net.minecraftforge.fml.config.ModConfig) ConfigBase(me.ichun.mods.ichunutil.common.config.ConfigBase) Nonnull(javax.annotation.Nonnull) Collections(java.util.Collections) InputStream(java.io.InputStream) Constraint(me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) Field(java.lang.reflect.Field) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Constraint(me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint) Theme(me.ichun.mods.ichunutil.client.gui.bns.Theme) File(java.io.File)

Example 5 with Constraint

use of me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint in project iChunUtil by iChun.

the class WindowDock method addToDock.

public void addToDock(Window<?> window, Constraint.Property.Type type) {
    dockedOriSize.put(window, new WindowSize(window.constraint, window.getLeft(), window.getTop(), window.getWidth(), window.getHeight()));
    Constraint constraint = new Constraint(window);
    for (Constraint.Property.Type type1 : Constraint.Property.Type.values()) {
        if (type1.equals(WIDTH) || type1.equals(HEIGHT)) {
            continue;
        }
        IConstrainable constrainable = getAnchor(type1);
        if (type1 != type.getOpposite()) {
            if (constrainable != null) {
                constraint = constraint.type(type1, constrainable, type1.getOpposite(), -(Integer) window.borderSize.get() + borderSize.get());
            } else {
                constraint = constraint.type(type1, this, type1, -(Integer) window.borderSize.get() + borderSize.get());
            }
        }
    }
    ArrayList<Window<?>> windows = new ArrayList<>();
    windows.add(window);
    docked.put(new WindowDock.ArrayListHolder(windows), type);
    window.setConstraint(constraint);
    window.constraint.apply();
    if (getWorkspace().hasInit()) {
        window.resize(Minecraft.getInstance(), this.width, this.height);
    }
}
Also used : Constraint(me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint) IConstrainable(me.ichun.mods.ichunutil.client.gui.bns.window.constraint.IConstrainable) Type(me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint.Property.Type)

Aggregations

Constraint (me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint)5 Type (me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint.Property.Type)3 IConstrainable (me.ichun.mods.ichunutil.client.gui.bns.window.constraint.IConstrainable)3 Field (java.lang.reflect.Field)2 ArrayList (java.util.ArrayList)2 Nonnull (javax.annotation.Nonnull)2 me.ichun.mods.ichunutil.client.gui.bns.window.view.element (me.ichun.mods.ichunutil.client.gui.bns.window.view.element)2 ConfigBase (me.ichun.mods.ichunutil.common.config.ConfigBase)2 Prop (me.ichun.mods.ichunutil.common.config.annotations.Prop)2 ByteStreams (com.google.common.io.ByteStreams)1 Gson (com.google.gson.Gson)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1