Search in sources :

Example 1 with ListElement

use of micdoodle8.mods.galacticraft.core.client.gui.element.GuiElementGradientList.ListElement in project Galacticraft by micdoodle8.

the class GuiNewSpaceRace method actionPerformed.

@Override
protected void actionPerformed(GuiButton buttonClicked) {
    switch(buttonClicked.id) {
        case 0:
            if (this.currentState == EnumSpaceRaceGui.CHANGE_TEAM_COLOR) {
                this.markDirty();
            }
            this.exitCurrentScreen(true);
            break;
        case 1:
            break;
        case 2:
            if (this.currentState == EnumSpaceRaceGui.MAIN && this.canEdit) {
                this.currentState = EnumSpaceRaceGui.ADD_PLAYER;
                this.initGui();
            } else if (this.currentState == EnumSpaceRaceGui.ADD_PLAYER) {
                ListElement playerToInvite = this.gradientListAddPlayers.getSelectedElement();
                if (playerToInvite != null && !this.recentlyInvited.containsKey(playerToInvite.value)) {
                    SpaceRace race = SpaceRaceManager.getSpaceRaceFromPlayer(PlayerUtil.getName(this.thePlayer));
                    if (race != null) {
                        GalacticraftCore.packetPipeline.sendToServer(new PacketSimple(EnumSimplePacket.S_INVITE_RACE_PLAYER, GCCoreUtil.getDimensionID(mc.theWorld), new Object[] { playerToInvite.value, race.getSpaceRaceID() }));
                        this.recentlyInvited.put(playerToInvite.value, 20 * 60);
                    }
                }
            } else if (this.currentState == EnumSpaceRaceGui.REMOVE_PLAYER) {
                ListElement playerToRemove = this.gradientListRemovePlayers.getSelectedElement();
                if (playerToRemove != null) {
                    SpaceRace race = SpaceRaceManager.getSpaceRaceFromPlayer(PlayerUtil.getName(this.thePlayer));
                    if (race != null) {
                        GalacticraftCore.packetPipeline.sendToServer(new PacketSimple(EnumSimplePacket.S_REMOVE_RACE_PLAYER, GCCoreUtil.getDimensionID(mc.theWorld), new Object[] { playerToRemove.value, race.getSpaceRaceID() }));
                    }
                }
            }
            break;
        case 3:
            if (this.currentState == EnumSpaceRaceGui.MAIN && this.canEdit) {
                this.currentState = EnumSpaceRaceGui.REMOVE_PLAYER;
                this.initGui();
            }
            break;
        default:
            break;
    }
}
Also used : SpaceRace(micdoodle8.mods.galacticraft.core.dimension.SpaceRace) ListElement(micdoodle8.mods.galacticraft.core.client.gui.element.GuiElementGradientList.ListElement) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple)

Example 2 with ListElement

use of micdoodle8.mods.galacticraft.core.client.gui.element.GuiElementGradientList.ListElement in project Galacticraft by micdoodle8.

the class GuiNewSpaceRace method updateScreen.

@Override
public void updateScreen() {
    super.updateScreen();
    if (this.ticksPassed % 100 == 0) {
        if (this.isDirty || this.ticksPassed == 0) {
            this.sendSpaceRaceData();
            this.isDirty = false;
        } else {
            this.updateSpaceRaceData();
        }
    }
    ++this.ticksPassed;
    for (Entry<String, Integer> e : new HashSet<Entry<String, Integer>>(this.recentlyInvited.entrySet())) {
        int timeLeft = e.getValue();
        if (--timeLeft < 0) {
            this.recentlyInvited.remove(e.getKey());
        } else {
            this.recentlyInvited.put(e.getKey(), timeLeft);
        }
    }
    if (this.currentState == EnumSpaceRaceGui.ADD_PLAYER && this.gradientListAddPlayers != null && this.ticksPassed % 20 == 0) {
        List<ListElement> playerNames = new ArrayList<ListElement>();
        for (int i = 0; i < this.thePlayer.worldObj.playerEntities.size(); i++) {
            EntityPlayer player = (EntityPlayer) this.thePlayer.worldObj.playerEntities.get(i);
            if (player.getDistanceSqToEntity(this.thePlayer) <= 25 * 25) {
                String username = PlayerUtil.getName(player);
                if (!this.spaceRaceData.getPlayerNames().contains(username)) {
                    playerNames.add(new ListElement(username, this.recentlyInvited.containsKey(username) ? ColorUtil.to32BitColor(255, 250, 120, 0) : ColorUtil.to32BitColor(255, 190, 190, 190)));
                }
            }
        }
        this.gradientListAddPlayers.updateListContents(playerNames);
        if (this.buttonList.size() >= 2) {
            ((GuiElementGradientButton) this.buttonList.get(1)).enabled = this.gradientListAddPlayers.getSelectedElement() != null;
        }
    }
    if (this.currentState == EnumSpaceRaceGui.REMOVE_PLAYER && this.gradientListRemovePlayers != null && this.ticksPassed % 20 == 0) {
        List<ListElement> playerNames = new ArrayList<ListElement>();
        for (int i = 1; i < this.spaceRaceData.getPlayerNames().size(); i++) {
            String playerName = this.spaceRaceData.getPlayerNames().get(i);
            playerNames.add(new ListElement(playerName, ColorUtil.to32BitColor(255, 190, 190, 190)));
        }
        this.gradientListRemovePlayers.updateListContents(playerNames);
        if (this.buttonList.size() >= 2) {
            ((GuiElementGradientButton) this.buttonList.get(1)).enabled = this.gradientListRemovePlayers.getSelectedElement() != null;
        }
    }
    if (this.currentState == EnumSpaceRaceGui.ADD_PLAYER && this.gradientListAddPlayers != null) {
        this.gradientListAddPlayers.update();
    }
    if (this.currentState == EnumSpaceRaceGui.REMOVE_PLAYER && this.gradientListRemovePlayers != null) {
        this.gradientListRemovePlayers.update();
    }
    if (!this.initialized) {
        return;
    }
    if (this.currentState == EnumSpaceRaceGui.DESIGN_FLAG) {
        int x = Mouse.getEventX() * this.width / this.mc.displayWidth;
        int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
        if (this.canEdit && x >= this.flagDesignerMinX && y >= this.flagDesignerMinY && x <= this.flagDesignerMinX + this.flagDesignerWidth && y <= this.flagDesignerMinY + this.flagDesignerHeight) {
            int unScaledX = (int) Math.floor((x - this.flagDesignerMinX) / this.flagDesignerScale.x);
            int unScaledY = (int) Math.floor((y - this.flagDesignerMinY) / this.flagDesignerScale.y);
            if (Mouse.isButtonDown(0)) {
                if (this.checkboxEraser.isSelected != null && this.checkboxEraser.isSelected) {
                    this.setColorWithBrushSize(unScaledX, unScaledY, new Vector3(255, 255, 255), (int) Math.floor(this.sliderEraserSize.getNormalizedValue() * 10) + 1);
                } else if (this.checkboxColorSelector.isSelected != null && this.checkboxColorSelector.isSelected) {
                    Vector3 colorAt = this.spaceRaceData.getFlagData().getColorAt(unScaledX, unScaledY);
                    this.sliderColorR.setSliderPos(colorAt.floatX());
                    this.sliderColorG.setSliderPos(colorAt.floatY());
                    this.sliderColorB.setSliderPos(colorAt.floatZ());
                } else if (this.checkboxPaintbrush.isSelected != null && this.checkboxPaintbrush.isSelected) {
                    this.setColorWithBrushSize(unScaledX, unScaledY, new Vector3(this.sliderColorR.getColorValueD(), this.sliderColorG.getColorValueD(), this.sliderColorB.getColorValueD()), (int) Math.floor(this.sliderBrushSize.getNormalizedValue() * 10) + 1);
                }
            }
        }
        if (this.checkboxSelector != null) {
            if (!this.lastMousePressed && Mouse.isButtonDown(0) && this.checkboxSelector.isSelected != null && this.checkboxSelector.isSelected) {
                if (x >= this.flagDesignerMinX && y >= this.flagDesignerMinY && x <= this.flagDesignerMinX + this.flagDesignerWidth && y <= this.flagDesignerMinY + this.flagDesignerHeight) {
                    int unScaledX = (int) Math.floor((x - this.flagDesignerMinX) / this.flagDesignerScale.x);
                    int unScaledY = (int) Math.floor((y - this.flagDesignerMinY) / this.flagDesignerScale.y);
                    this.selectionMinX = unScaledX;
                    this.selectionMinY = unScaledY;
                } else {
                    this.selectionMinX = this.selectionMinY = -1;
                }
            } else if (this.lastMousePressed && !Mouse.isButtonDown(0) && this.checkboxSelector.isSelected != null && this.checkboxSelector.isSelected) {
                if (this.selectionMinX != -1 && this.selectionMinY != -1 && x >= this.flagDesignerMinX && y >= this.flagDesignerMinY && x <= this.flagDesignerMinX + this.flagDesignerWidth && y <= this.flagDesignerMinY + this.flagDesignerHeight) {
                    int unScaledX = (int) Math.floor((x - this.flagDesignerMinX) / this.flagDesignerScale.x);
                    int unScaledY = (int) Math.floor((y - this.flagDesignerMinY) / this.flagDesignerScale.y);
                    this.selectionMaxX = Math.min(unScaledX + 1, this.spaceRaceData.getFlagData().getWidth());
                    this.selectionMaxY = Math.min(unScaledY + 1, this.spaceRaceData.getFlagData().getHeight());
                    if (this.selectionMinX > this.selectionMaxX) {
                        int temp = this.selectionMaxX - 1;
                        this.selectionMaxX = this.selectionMinX + 1;
                        this.selectionMinX = temp;
                    }
                    if (this.selectionMinY > this.selectionMaxY) {
                        int temp = this.selectionMaxY - 1;
                        this.selectionMaxY = this.selectionMinY + 1;
                        this.selectionMinY = temp;
                    }
                } else {
                    this.selectionMaxX = this.selectionMaxY = -1;
                }
            }
        }
        if (this.sliderBrushSize != null && this.sliderBrushSize.visible) {
            this.sliderBrushSize.displayString = GCCoreUtil.translate("gui.space_race.create.brush_radius.name") + ": " + ((int) Math.floor(this.sliderBrushSize.getNormalizedValue() * 10) + 1);
        }
        if (this.sliderEraserSize != null && this.sliderEraserSize.visible) {
            this.sliderEraserSize.displayString = GCCoreUtil.translate("gui.space_race.create.eraser_radius.name") + ": " + ((int) Math.floor(this.sliderEraserSize.getNormalizedValue() * 10) + 1);
        }
        if (this.sliderColorR != null && this.sliderColorR.visible) {
            this.sliderColorR.displayString = String.valueOf((int) Math.floor(this.sliderColorR.getColorValueD()));
        }
        if (this.sliderColorG != null && this.sliderColorG.visible) {
            this.sliderColorG.displayString = String.valueOf((int) Math.floor(this.sliderColorG.getColorValueD()));
        }
        if (this.sliderColorB != null && this.sliderColorB.visible) {
            this.sliderColorB.displayString = String.valueOf((int) Math.floor(this.sliderColorB.getColorValueD()));
        }
    } else if (this.currentState == EnumSpaceRaceGui.MAIN) {
        if (this.lastMousePressed && !Mouse.isButtonDown(0)) {
            if (this.buttonFlag_hover) {
                this.currentState = EnumSpaceRaceGui.DESIGN_FLAG;
                this.initGui();
            }
            if (this.buttonTeamColor_hover) {
                this.currentState = EnumSpaceRaceGui.CHANGE_TEAM_COLOR;
                this.initGui();
            }
        }
    }
    this.lastMousePressed = Mouse.isButtonDown(0);
}
Also used : ListElement(micdoodle8.mods.galacticraft.core.client.gui.element.GuiElementGradientList.ListElement) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3)

Aggregations

ListElement (micdoodle8.mods.galacticraft.core.client.gui.element.GuiElementGradientList.ListElement)2 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)1 SpaceRace (micdoodle8.mods.galacticraft.core.dimension.SpaceRace)1 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1