More sensor changes

This commit is contained in:
bdew committed 2015-03-23 17:42:36 +02:00
1 parent d3952b69d0
commit bae688c366
7 files changed
+60 -19

No files matched your search

@@ -11,13 +11,18 @@ package net.bdew.lib.sensors
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.bdew.lib.Misc
import net.bdew.lib.gui.{Color, Texture}
import net.bdew.lib.gui._
abstract class GenericSensorParameter(system: SensorSystem[_, _]) {
val uid: String
def localizedName = Misc.toLocal(system.localizationPrefix + ".param." + uid)
@SideOnly(Side.CLIENT)
def drawParam(rect: Rect, target: DrawTarget): Unit = {
target.drawTexture(rect, texture, textureColor)
}
@SideOnly(Side.CLIENT)
def texture: Texture
@@ -11,7 +11,7 @@ package net.bdew.lib.sensors
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.bdew.lib.Misc
import net.bdew.lib.gui.{Color, Texture}
import net.bdew.lib.gui.{Color, DrawTarget, Rect, Texture}
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
@@ -29,6 +29,11 @@ abstract class GenericSensorType[-T, +R](system: SensorSystem[T, R]) {
def getResult(param: GenericSensorParameter, obj: T): R
@SideOnly(Side.CLIENT)
def drawSensor(rect: Rect, target: DrawTarget): Unit = {
target.drawTexture(rect, texture, textureColor)
}
@SideOnly(Side.CLIENT)
def texture: Texture
@@ -0,0 +1,35 @@
/*
* Copyright (c) bdew, 2013 - 2015
* https://github.com/bdew/bdlib
*
* 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
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.sensors
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.bdew.lib.Misc
import net.bdew.lib.gui.{DrawTarget, IconWrapper, Rect, Texture}
import net.minecraft.init.Blocks
abstract class RedstoneSensors[T] extends SensorSystem[T, Boolean](false) {
lazy val rsOn = new IconWrapper(Texture.BLOCKS, Blocks.redstone_torch.getIcon(0, 0))
lazy val rsOff = new IconWrapper(Texture.BLOCKS, Blocks.unlit_redstone_torch.getIcon(0, 0))
@SideOnly(Side.CLIENT)
override def drawResult(result: Boolean, rect: Rect, target: DrawTarget): Unit = {
if (result)
target.drawTexture(rect, rsOn)
else
target.drawTexture(rect, rsOff)
}
@SideOnly(Side.CLIENT)
override def getLocalizedResultText(result: Boolean): String =
if (result)
Misc.toLocal(localizationPrefix + ".on")
else
Misc.toLocal(localizationPrefix + ".off")
}
+7 -1
View File
@@ -10,7 +10,7 @@
package net.bdew.lib.sensors
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.bdew.lib.gui.Texture
import net.bdew.lib.gui._
import net.bdew.lib.{BdLib, Misc}
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
@@ -31,6 +31,12 @@ abstract class SensorSystem[T, R](defaultResult: R) {
def localizationPrefix: String
@SideOnly(Side.CLIENT)
def drawResult(result: R, rect: Rect, target: DrawTarget): Unit
@SideOnly(Side.CLIENT)
def getLocalizedResultText(result: R): String
abstract class SensorType extends GenericSensorType(this)
abstract class SimpleSensor extends SimpleGenericSensor(this)
@@ -18,5 +18,5 @@ import scala.collection.mutable
class WidgetSensorParam(val p: Point, param: => GenericSensorParameter) extends Widget {
override val rect = new Rect(p, 16, 16)
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) = tip += param.localizedName
override def draw(mouse: Point) = parent.drawTexture(rect, param.texture, param.textureColor)
override def draw(mouse: Point) = param.drawParam(rect, parent)
}
@@ -9,28 +9,18 @@
package net.bdew.lib.sensors.widgets
import net.bdew.lib.Misc
import net.bdew.lib.gui._
import net.bdew.lib.gui.widgets.Widget
import net.minecraft.init.Blocks
import net.bdew.lib.sensors.SensorSystem
import scala.collection.mutable
class WidgetSensorBooleanResult(val p: Point, state: => Boolean, stringPrefix: String) extends Widget {
val rsOn = new IconWrapper(Texture.BLOCKS, Blocks.redstone_torch.getIcon(0, 0))
val rsOff = new IconWrapper(Texture.BLOCKS, Blocks.unlit_redstone_torch.getIcon(0, 0))
class WidgetSensorResult[T](val p: Point, state: => T, system: SensorSystem[_, T]) extends Widget {
override val rect = new Rect(p, 16, 16)
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) =
if (state)
tip += Misc.toLocal(stringPrefix + ".on")
else
tip += Misc.toLocal(stringPrefix + ".off")
tip += system.getLocalizedResultText(state)
override def draw(mouse: Point) =
if (state)
parent.drawTexture(rect, rsOn)
else
parent.drawTexture(rect, rsOff)
system.drawResult(state, rect, parent)
}
@@ -18,7 +18,7 @@ import scala.collection.mutable
class WidgetSensorType[T, R](val p: Point, sensor: => GenericSensorType[T, R]) extends Widget {
override val rect = new Rect(p, 16, 16)
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) = tip += sensor.localizedName
override def draw(mouse: Point) = parent.drawTexture(rect, sensor.texture, sensor.textureColor)
override def draw(mouse: Point) = sensor.drawSensor(rect, parent)
}