Search in sources :

Example 1 with PacketToggleHelmetFeature

use of me.desht.pneumaticcraft.common.network.PacketToggleHelmetFeature in project pnc-repressurized by TeamPneumatic.

the class HUDHandler method update.

private void update(EntityPlayer player) {
    for (ArmorMessage message : messageList) {
        message.getStat().update();
    }
    CommonHUDHandler comHudHandler = CommonHUDHandler.getHandlerForPlayer(player);
    boolean helmetEnabled = GuiKeybindCheckBox.trackedCheckboxes.get("pneumaticHelmet.upgrade.coreComponents").checked;
    if (comHudHandler.ticksExisted == 1) {
        for (IUpgradeRenderHandler handler : UpgradeRenderHandlerList.instance().upgradeRenderers) {
            handler.reset();
        }
        for (int i = 0; i < comHudHandler.upgradeRenderersEnabled.length; i++) {
            NetworkHandler.sendToServer(new PacketToggleHelmetFeature((byte) i, helmetEnabled && GuiKeybindCheckBox.trackedCheckboxes.get("pneumaticHelmet.upgrade." + UpgradeRenderHandlerList.instance().upgradeRenderers.get(i).getUpgradeName()).checked));
        }
    }
    if (comHudHandler.ticksExisted > comHudHandler.getStartupTime() && helmetEnabled) {
        for (int i = 0; i < UpgradeRenderHandlerList.instance().upgradeRenderers.size(); i++) {
            IUpgradeRenderHandler upgradeRenderHandler = UpgradeRenderHandlerList.instance().upgradeRenderers.get(i);
            if (comHudHandler.upgradeRenderersInserted[i] && GuiKeybindCheckBox.trackedCheckboxes.get("pneumaticHelmet.upgrade." + upgradeRenderHandler.getUpgradeName()).checked) {
                IGuiAnimatedStat stat = upgradeRenderHandler.getAnimatedStat();
                if (stat != null) {
                    if (comHudHandler.helmetPressure > 0F) {
                        stat.openWindow();
                    } else {
                        stat.closeWindow();
                    }
                    stat.update();
                }
                upgradeRenderHandler.update(player, comHudHandler.rangeUpgradesInstalled);
            }
        }
    }
    // clean the list
    for (int i = 0; i < messageList.size(); i++) {
        ArmorMessage message = messageList.get(i);
        if (message == null || --message.lifeSpan <= 0) {
            messageList.remove(i);
            i--;
        }
    }
    for (int i = 0; i < UpgradeRenderHandlerList.instance().upgradeRenderers.size(); i++) {
        if (comHudHandler.ticksExisted == comHudHandler.getStartupTime() / (UpgradeRenderHandlerList.instance().upgradeRenderers.size() + 2) * (i + 1)) {
            player.world.playSound(player.posX, player.posY, player.posZ, Sounds.HUD_INIT, SoundCategory.PLAYERS, 0.1F, 0.5F + (float) (i + 1) / (UpgradeRenderHandlerList.instance().upgradeRenderers.size() + 2) * 0.5F, true);
            boolean upgradeEnabled = comHudHandler.upgradeRenderersInserted[i];
            addMessage(new ArmorMessage(I18n.format("pneumaticHelmet.upgrade." + UpgradeRenderHandlerList.instance().upgradeRenderers.get(i).getUpgradeName()) + " " + (upgradeEnabled ? "found" : "not installed"), new ArrayList<String>(), 50, upgradeEnabled ? 0x7000AA00 : 0x70FF0000));
        }
    }
    if (comHudHandler.ticksExisted == 1) {
        player.world.playSound(player.posX, player.posY, player.posZ, Sounds.HUD_INIT, SoundCategory.PLAYERS, 0.1F, 0.5F, true);
        addMessage(new ArmorMessage("Initializing head-up display...", Collections.emptyList(), 50, 0x7000AA00));
    }
    if (comHudHandler.ticksExisted == comHudHandler.getStartupTime()) {
        player.world.playSound(player.posX, player.posY, player.posZ, Sounds.HUD_INIT_COMPLETE, SoundCategory.PLAYERS, 0.1F, 1.0F, true);
        addMessage(new ArmorMessage("Initialization complete!", Collections.emptyList(), 50, 0x7000AA00));
    }
}
Also used : IUpgradeRenderHandler(me.desht.pneumaticcraft.api.client.pneumaticHelmet.IUpgradeRenderHandler) CommonHUDHandler(me.desht.pneumaticcraft.common.CommonHUDHandler) ArrayList(java.util.ArrayList) PacketToggleHelmetFeature(me.desht.pneumaticcraft.common.network.PacketToggleHelmetFeature) IGuiAnimatedStat(me.desht.pneumaticcraft.api.client.IGuiAnimatedStat)

Example 2 with PacketToggleHelmetFeature

use of me.desht.pneumaticcraft.common.network.PacketToggleHelmetFeature in project pnc-repressurized by TeamPneumatic.

the class GuiKeybindCheckBox method onMouseClicked.

@Override
public void onMouseClicked(int mouseX, int mouseY, int button) {
    if (button == 0) {
        super.onMouseClicked(mouseX, mouseY, button);
        GuiKeybindCheckBox trackedBox = trackedCheckboxes.get(keyBindingName);
        if (trackedBox != this) {
            trackedBox.onMouseClicked(mouseX, mouseY, button);
        } else {
            HelmetWidgetDefaults.INSTANCE.setKey(keyBindingName, checked);
            try {
                HelmetWidgetDefaults.INSTANCE.writeToFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
            for (int i = 0; i < UpgradeRenderHandlerList.instance().upgradeRenderers.size(); i++) {
                IUpgradeRenderHandler upgradeRenderHandler = UpgradeRenderHandlerList.instance().upgradeRenderers.get(i);
                if (("pneumaticHelmet.upgrade." + upgradeRenderHandler.getUpgradeName()).equals(keyBindingName)) {
                    NetworkHandler.sendToServer(new PacketToggleHelmetFeature((byte) i, GuiKeybindCheckBox.trackedCheckboxes.get("pneumaticHelmet.upgrade.coreComponents").checked && checked));
                }
            }
            if (keyBindingName.equals("pneumaticHelmet.upgrade.coreComponents")) {
                for (int i = 0; i < UpgradeRenderHandlerList.instance().upgradeRenderers.size(); i++) {
                    NetworkHandler.sendToServer(new PacketToggleHelmetFeature((byte) i, checked && GuiKeybindCheckBox.trackedCheckboxes.get("pneumaticHelmet.upgrade." + UpgradeRenderHandlerList.instance().upgradeRenderers.get(i).getUpgradeName()).checked));
                }
            }
        }
    } else {
        isAwaitingKey = !isAwaitingKey;
        if (isAwaitingKey) {
            oldCheckboxText = text;
            text = "gui.setKeybind";
        } else {
            text = oldCheckboxText;
        }
    }
}
Also used : IUpgradeRenderHandler(me.desht.pneumaticcraft.api.client.pneumaticHelmet.IUpgradeRenderHandler) PacketToggleHelmetFeature(me.desht.pneumaticcraft.common.network.PacketToggleHelmetFeature) IOException(java.io.IOException)

Aggregations

IUpgradeRenderHandler (me.desht.pneumaticcraft.api.client.pneumaticHelmet.IUpgradeRenderHandler)2 PacketToggleHelmetFeature (me.desht.pneumaticcraft.common.network.PacketToggleHelmetFeature)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 IGuiAnimatedStat (me.desht.pneumaticcraft.api.client.IGuiAnimatedStat)1 CommonHUDHandler (me.desht.pneumaticcraft.common.CommonHUDHandler)1