Search in sources :

Example 1 with PacketToggleHelmetFeature

use of pneumaticCraft.common.network.PacketToggleHelmetFeature in project PneumaticCraft by MineMaarten.

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 {
            Config.config.get("pneumatic_helmet_widgetDefaults", keyBindingName, true).set(checked);
            Config.config.save();
            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(pneumaticCraft.api.client.pneumaticHelmet.IUpgradeRenderHandler) PacketToggleHelmetFeature(pneumaticCraft.common.network.PacketToggleHelmetFeature)

Example 2 with PacketToggleHelmetFeature

use of pneumaticCraft.common.network.PacketToggleHelmetFeature in project PneumaticCraft by MineMaarten.

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.worldObj.playSound(player.posX, player.posY, player.posZ, Sounds.HUD_INIT, 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.worldObj.playSound(player.posX, player.posY, player.posZ, Sounds.HUD_INIT, 0.1F, 0.5F, true);
        addMessage(new ArmorMessage("Initializing head-up display...", new ArrayList<String>(), 50, 0x7000AA00));
    }
    if (comHudHandler.ticksExisted == comHudHandler.getStartupTime()) {
        player.worldObj.playSound(player.posX, player.posY, player.posZ, Sounds.HUD_INIT_COMPLETE, 0.1F, 1.0F, true);
        addMessage(new ArmorMessage("Initialization complete!", new ArrayList<String>(), 50, 0x7000AA00));
    }
}
Also used : IUpgradeRenderHandler(pneumaticCraft.api.client.pneumaticHelmet.IUpgradeRenderHandler) CommonHUDHandler(pneumaticCraft.common.CommonHUDHandler) ArrayList(java.util.ArrayList) PacketToggleHelmetFeature(pneumaticCraft.common.network.PacketToggleHelmetFeature) IGuiAnimatedStat(pneumaticCraft.api.client.IGuiAnimatedStat)

Aggregations

IUpgradeRenderHandler (pneumaticCraft.api.client.pneumaticHelmet.IUpgradeRenderHandler)2 PacketToggleHelmetFeature (pneumaticCraft.common.network.PacketToggleHelmetFeature)2 ArrayList (java.util.ArrayList)1 IGuiAnimatedStat (pneumaticCraft.api.client.IGuiAnimatedStat)1 CommonHUDHandler (pneumaticCraft.common.CommonHUDHandler)1