diff --git a/resources/assets/gendustry/lang/en_US.lang b/resources/assets/gendustry/lang/en_US.lang index e4bef82..90a81da 100644 --- a/resources/assets/gendustry/lang/en_US.lang +++ b/resources/assets/gendustry/lang/en_US.lang @@ -110,6 +110,7 @@ gendustry.label.mod.temperature=* Temperature gendustry.label.mod.humidity=* Humidity gendustry.error.power=Not enough power +gendustry.error.disabled=Disabled by settings gendustry.label.sample.rootBees=Taken from a Bee gendustry.label.sample.rootTrees=Taken from a Sapling diff --git a/resources/assets/gendustry/textures/gui/widgets.png b/resources/assets/gendustry/textures/gui/widgets.png index f6316aa..84f0624 100644 Binary files a/resources/assets/gendustry/textures/gui/widgets.png and b/resources/assets/gendustry/textures/gui/widgets.png differ diff --git a/resources/assets/gendustry/textures/gui/widgets.psd b/resources/assets/gendustry/textures/gui/widgets.psd index 3f0197a..ff0b58c 100644 Binary files a/resources/assets/gendustry/textures/gui/widgets.psd and b/resources/assets/gendustry/textures/gui/widgets.psd differ diff --git a/src/net/bdew/gendustry/gui/Textures.scala b/src/net/bdew/gendustry/gui/Textures.scala index fd1bae2..87ec079 100644 --- a/src/net/bdew/gendustry/gui/Textures.scala +++ b/src/net/bdew/gendustry/gui/Textures.scala @@ -11,13 +11,31 @@ package net.bdew.gendustry.gui import net.bdew.lib.gui._ import net.bdew.gendustry.Gendustry +import net.bdew.gendustry.gui.rscontrol.RSMode object Textures { val texture = new ScaledResourceLocation(Gendustry.modId, "textures/gui/widgets.png", 256) val tankOverlay = Texture(texture, 16, 0, 16, 58) val powerFill = Texture(texture, 0, 0, 16, 58) - val texturePowerError = Texture(texture, 32, 0, 16, 16) - val slotSelect = Texture(texture, 48, 0, 18, 18) + val slotSelect = Texture(texture, 64, 0, 18, 18) def greenProgress(width: Float) = Texture(texture, 136 - width, 58, width, 15) def whiteProgress(width: Float) = Texture(texture, 136 - width, 73, width, 15) + + object errors { + val noPower = Texture(texture, 32, 0, 16, 16) + val disabled = Texture(texture, 48, 0, 16, 16) + } + + object button16 { + val base = Texture(texture, 32, 18, 16, 16) + val hover = Texture(texture, 48, 18, 16, 16) + + val iconRSMode = Map( + RSMode.ALWAYS -> Texture(texture, 65, 35, 14, 14), + RSMode.NEVER -> Texture(texture, 81, 35, 14, 14), + RSMode.RS_ON -> Texture(texture, 49, 35, 14, 14), + RSMode.RS_OFF -> Texture(texture, 33, 35, 14, 14) + ) + } + } diff --git a/src/net/bdew/gendustry/gui/rscontrol/ContainerRSControllable.scala b/src/net/bdew/gendustry/gui/rscontrol/ContainerRSControllable.scala new file mode 100644 index 0000000..54437ce --- /dev/null +++ b/src/net/bdew/gendustry/gui/rscontrol/ContainerRSControllable.scala @@ -0,0 +1,31 @@ +/* + * Copyright (c) bdew, 2013 - 2014 + * https://github.com/bdew/gendustry + * + * This mod is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt + */ + +package net.bdew.gendustry.gui.rscontrol + +import net.minecraft.entity.player.EntityPlayer +import net.bdew.lib.data.base.ContainerDataSlots + +trait ContainerRSControllable extends ContainerDataSlots { + val dataSource: TileRSContollable + + /** + * This implementation is piggybacking on vanilla Packet102WindowClick + * This is the fake slot number, and shouldn't be used by anything else + */ + final val RSMODE_SLOT_NUM = 1000 + + override def slotClick(slotnum: Int, button: Int, modifiers: Int, player: EntityPlayer) = + if (slotnum == RSMODE_SLOT_NUM) { + dataSource.rsmode := RSMode(button) + null + } else { + super.slotClick(slotnum, button, modifiers, player) + } +} diff --git a/src/net/bdew/gendustry/gui/rscontrol/DataslotRSMode.scala b/src/net/bdew/gendustry/gui/rscontrol/DataslotRSMode.scala new file mode 100644 index 0000000..d492b30 --- /dev/null +++ b/src/net/bdew/gendustry/gui/rscontrol/DataslotRSMode.scala @@ -0,0 +1,19 @@ +/* + * Copyright (c) bdew, 2013 - 2014 + * https://github.com/bdew/gendustry + * + * This mod is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt + */ + +package net.bdew.gendustry.gui.rscontrol + +import net.bdew.lib.data.base.{UpdateKind, DataSlotVal, TileDataSlots} +import net.minecraft.nbt.NBTTagCompound + +case class DataslotRSMode(name: String, parent: TileDataSlots) extends DataSlotVal[RSMode.Value] { + var cval: RSMode.Value = RSMode.ALWAYS + def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setByte(name, cval.id.toByte) + def load(t: NBTTagCompound, kind: UpdateKind.Value) = cval = RSMode(t.getByte(name)) +} diff --git a/src/net/bdew/gendustry/gui/rscontrol/RSMode.scala b/src/net/bdew/gendustry/gui/rscontrol/RSMode.scala new file mode 100644 index 0000000..a3417b4 --- /dev/null +++ b/src/net/bdew/gendustry/gui/rscontrol/RSMode.scala @@ -0,0 +1,26 @@ +/* + * Copyright (c) bdew, 2013 - 2014 + * https://github.com/bdew/gendustry + * + * This mod is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt + */ + +package net.bdew.gendustry.gui.rscontrol + +object RSMode extends Enumeration { + val ALWAYS = Value(0, "ALWAYS") + val RS_ON = Value(1, "RS_ON") + val RS_OFF = Value(2, "RS_OFF") + val NEVER = Value(3, "NEVER") + + final val RSMODE_SLOT_NUM = 1000 + + val next = Map( + RSMode.ALWAYS -> RSMode.RS_ON, + RSMode.RS_ON -> RSMode.RS_OFF, + RSMode.RS_OFF -> RSMode.NEVER, + RSMode.NEVER -> RSMode.ALWAYS + ) +} diff --git a/src/net/bdew/gendustry/gui/rscontrol/TileRSContollable.scala b/src/net/bdew/gendustry/gui/rscontrol/TileRSContollable.scala new file mode 100644 index 0000000..2a3803a --- /dev/null +++ b/src/net/bdew/gendustry/gui/rscontrol/TileRSContollable.scala @@ -0,0 +1,23 @@ +/* + * Copyright (c) bdew, 2013 - 2014 + * https://github.com/bdew/gendustry + * + * This mod is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt + */ + +package net.bdew.gendustry.gui.rscontrol + +import net.bdew.lib.data.base.{UpdateKind, TileDataSlots} + +trait TileRSContollable extends TileDataSlots { + val rsmode = DataslotRSMode("rsmode", this).setUpdate(UpdateKind.SAVE, UpdateKind.GUI, UpdateKind.WORLD) + + def canWork = { + val powered = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord) + (rsmode :== RSMode.ALWAYS) || + ((rsmode :== RSMode.RS_ON) && powered) || + ((rsmode :== RSMode.RS_OFF) && !powered) + } +} diff --git a/src/net/bdew/gendustry/gui/rscontrol/WidgetRSModeButton.scala b/src/net/bdew/gendustry/gui/rscontrol/WidgetRSModeButton.scala new file mode 100644 index 0000000..86710b6 --- /dev/null +++ b/src/net/bdew/gendustry/gui/rscontrol/WidgetRSModeButton.scala @@ -0,0 +1,42 @@ +/* + * Copyright (c) bdew, 2013 - 2014 + * https://github.com/bdew/gendustry + * + * This mod is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt + */ + +package net.bdew.gendustry.gui.rscontrol + +import net.bdew.lib.gui.{Texture, Rect, Point} +import net.bdew.lib.gui.widgets.Widget +import net.bdew.gendustry.gui.Textures +import scala.collection.mutable +import net.bdew.lib.{Misc, Client} + +class WidgetRSModeButton(p: Point, te: TileRSContollable, container: ContainerRSControllable) extends Widget { + val rect = new Rect(p, 16, 16) + val iconRect = new Rect(p +(1, 1), 14, 14) + + var icon: Texture = null + var hover: String = null + + override def draw(mouse: Point) { + if (rect.contains(mouse)) + parent.drawTexture(rect, Textures.button16.hover) + else + parent.drawTexture(rect, Textures.button16.base) + + parent.drawTexture(iconRect, Textures.button16.iconRSMode(te.rsmode)) + } + + override def handleTooltip(p: Point, tip: mutable.MutableList[String]) { + tip += Misc.toLocal("gendustry.rsmode." + te.rsmode.cval.toString.toLowerCase) + } + + override def mouseClicked(p: Point, button: Int) { + Client.minecraft.sndManager.playSoundFX("random.click", 1.0F, 1.0F) + Client.minecraft.playerController.windowClick(container.windowId, container.RSMODE_SLOT_NUM, RSMode.next(te.rsmode).id, 0, Client.player) + } +} diff --git a/src/net/bdew/gendustry/machines/apiary/ContainerApiary.scala b/src/net/bdew/gendustry/machines/apiary/ContainerApiary.scala index 68cdea8..9e6b746 100644 --- a/src/net/bdew/gendustry/machines/apiary/ContainerApiary.scala +++ b/src/net/bdew/gendustry/machines/apiary/ContainerApiary.scala @@ -16,8 +16,9 @@ import net.minecraft.inventory.{IInventory, Slot} import net.bdew.lib.items.ItemUtils import net.bdew.lib.data.base.ContainerDataSlots import net.bdew.lib.Misc +import net.bdew.gendustry.gui.rscontrol.ContainerRSControllable -class ContainerApiary(val te: TileApiary, player: EntityPlayer) extends BaseContainer(te) with ContainerDataSlots { +class ContainerApiary(val te: TileApiary, player: EntityPlayer) extends BaseContainer(te) with ContainerDataSlots with ContainerRSControllable { lazy val dataSource = te addSlotToContainer(new SlotValidating(te, 0, 39, 29)) diff --git a/src/net/bdew/gendustry/machines/apiary/GuiApiary.scala b/src/net/bdew/gendustry/machines/apiary/GuiApiary.scala index 7af5011..a1e2b96 100644 --- a/src/net/bdew/gendustry/machines/apiary/GuiApiary.scala +++ b/src/net/bdew/gendustry/machines/apiary/GuiApiary.scala @@ -11,12 +11,13 @@ package net.bdew.gendustry.machines.apiary import net.bdew.gendustry.Gendustry import net.minecraft.entity.player.EntityPlayer -import net.bdew.lib.gui.{Texture, Color, Rect, BaseScreen} +import net.bdew.lib.gui.{Texture, Color, Rect, BaseScreen, Point} import net.bdew.lib.gui.widgets.WidgetLabel import net.bdew.gendustry.gui.{HintIcons, WidgetPowerCustom, Textures} import net.bdew.lib.Misc +import net.bdew.gendustry.gui.rscontrol.WidgetRSModeButton -class GuiApiary(val te: TileApiary, player: EntityPlayer) extends BaseScreen(new ContainerApiary(te, player), 176, 166) { +class GuiApiary(val te: TileApiary, player: EntityPlayer, cont: ContainerApiary) extends BaseScreen(cont, 176, 166) { val background = Texture(Gendustry.modId, "textures/gui/apiary.png", rect) override def initGui() { super.initGui() @@ -24,6 +25,7 @@ class GuiApiary(val te: TileApiary, player: EntityPlayer) extends BaseScreen(new widgets.add(new WidgetPowerCustom(new Rect(8, 19, 16, 58), Textures.powerFill, te.power)) widgets.add(new WidgetApiaryProgress(new Rect(69, 22, 36, 15), te.guiBreeding, te.guiProgress)) widgets.add(new WidgetLabel(Misc.toLocal("tile.gendustry.apiary.name"), 8, 6, Color.darkgray)) + widgets.add(new WidgetRSModeButton(Point(137, 5), te, cont)) te.slots.upgrades.foreach(inventorySlots.getSlot(_).setBackgroundIcon(HintIcons.upgrade)) inventorySlots.getSlotFromInventory(te, te.slots.drone).setBackgroundIcon(HintIcons.drone) diff --git a/src/net/bdew/gendustry/machines/apiary/MachineApiary.scala b/src/net/bdew/gendustry/machines/apiary/MachineApiary.scala index b9f11b6..2ad1f8d 100644 --- a/src/net/bdew/gendustry/machines/apiary/MachineApiary.scala +++ b/src/net/bdew/gendustry/machines/apiary/MachineApiary.scala @@ -21,6 +21,6 @@ class MachineApiary extends Machine("IndustrialApiary", new BlockApiary(_)) with lazy val baseMjPerTick = tuning.getInt("BaseMjPerTick") @SideOnly(Side.CLIENT) - def getGui(te: TileApiary, player: EntityPlayer) = new GuiApiary(te, player) + def getGui(te: TileApiary, player: EntityPlayer) = new GuiApiary(te, player, new ContainerApiary(te, player)) def getContainer(te: TileApiary, player: EntityPlayer) = new ContainerApiary(te, player) } diff --git a/src/net/bdew/gendustry/machines/apiary/TileApiary.scala b/src/net/bdew/gendustry/machines/apiary/TileApiary.scala index 7d8f369..d1e1ef5 100644 --- a/src/net/bdew/gendustry/machines/apiary/TileApiary.scala +++ b/src/net/bdew/gendustry/machines/apiary/TileApiary.scala @@ -32,6 +32,7 @@ import net.bdew.lib.data.DataSlotBoolean import net.bdew.gendustry.power.TilePowered import net.bdew.lib.power.DataSlotPower import net.bdew.gendustry.compat.triggers.ForestryErrorSource +import net.bdew.gendustry.gui.rscontrol.TileRSContollable class TileApiary extends TileExtended with TileDataSlots @@ -40,6 +41,7 @@ with SidedInventory with BreakableInventoryTile with TilePowered with ForestryErrorSource +with TileRSContollable with IBeeHousing { object slots { @@ -71,7 +73,7 @@ with IBeeHousing { persistLoad.listen(x => { updateModifiers() - queen := getStackInSlot(slots.drone) + queen := getStackInSlot(slots.queen) }) def updateModifiers() { @@ -108,7 +110,9 @@ with IBeeHousing { serverTick.listen(() => { movePrincess = false - if (power.stored >= cfg.baseMjPerTick * mods.energy) { + if (!canWork) { + setErrorState(-2) + } else if (power.stored >= cfg.baseMjPerTick * mods.energy) { logic.update() if ((logic.getQueen != null || logic.getBreedingTime > 0) && (errorState :== 1)) power.extract(cfg.baseMjPerTick * mods.energy, false) diff --git a/src/net/bdew/gendustry/machines/apiary/WidgetError.scala b/src/net/bdew/gendustry/machines/apiary/WidgetError.scala index 5204d3a..576d297 100644 --- a/src/net/bdew/gendustry/machines/apiary/WidgetError.scala +++ b/src/net/bdew/gendustry/machines/apiary/WidgetError.scala @@ -21,19 +21,22 @@ class WidgetError(x: Int, y: Int, apiary: TileApiary) extends Widget { override def draw(mouse: Point) { val err = apiary.errorState.cval if (err == -1) { - parent.drawTexture(rect, Textures.texturePowerError) + parent.drawTexture(rect, Textures.errors.noPower) + } else if (err == -2) { + parent.drawTexture(rect, Textures.errors.disabled) + } else if (ErrorCodes.isValid(err)) { + parent.drawTexture(rect, ErrorCodes.getIcon(err)) } else { - if (ErrorCodes.isValid(err)) { - parent.drawTexture(rect, ErrorCodes.getIcon(err)) - } else { - parent.drawTexture(rect, ErrorCodes.getIcon(0)) - } + parent.drawTexture(rect, ErrorCodes.getIcon(0)) } } + override def handleTooltip(p: Point, tip: mutable.MutableList[String]) { val err = apiary.errorState.cval if (err == -1) { tip += Misc.toLocal(Gendustry.modId + ".error.power") + } else if (err == -2) { + tip += Misc.toLocal(Gendustry.modId + ".error.disabled") } else if (ErrorCodes.isValid(err)) { tip += ErrorCodes.getDescription(err) } else {