added DecFormat, some cleanup

This commit is contained in:
bdew committed 2014-12-18 11:20:18 +02:00
1 parent 1618931c6d
commit 02850b9f85
6 files changed
+45 -23

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
package net.bdew.lib
import java.text.DecimalFormat
object DecFormat {
val thousandsFmt = new DecimalFormat("#,##0")
val dec2Fmt = new DecimalFormat("#,##0.00")
def round(x: Double) = thousandsFmt.format(x)
def round(x: Float) = thousandsFmt.format(x)
def round(x: Int) = thousandsFmt.format(x)
def dec2(x: Double) = dec2Fmt.format(x)
def dec2(x: Float) = dec2Fmt.format(x)
def dec2(x: Int) = dec2Fmt.format(x)
}
+8 -3
View File
@@ -55,8 +55,8 @@ object Misc {
def addRecipeOD(result: ItemStack, pattern: Seq[String], items: Map[Char, AnyRef]) =
GameRegistry.addRecipe(new ShapedOreRecipe(result, flattenRecipe(pattern, items): _*))
def min[T](vals: T*)(implicit o: Ordering[T]): T = vals.min(o)
def max[T](vals: T*)(implicit o: Ordering[T]): T = vals.max(o)
def min[T: Ordering](values: T*) = values.min
def max[T: Ordering](values: T*) = values.max
def clamp[T](value: T, min: T, max: T)(implicit o: Ordering[T]): T = if (o.gt(value, max)) max else if (o.lt(value, min)) min else value
@@ -95,7 +95,12 @@ object Misc {
Option(origin.getWorldObj.getTileEntity(origin.xCoord + dir.offsetX,
origin.yCoord + dir.offsetY, origin.zCoord + dir.offsetZ)) flatMap (asInstanceOpt(_, cls))
def applyMutator[T](f: (T) => Unit, init: T): T = {
@inline def applyMutator[T](f: (T) => Unit, init: T): T = {
f(init)
init
}
@inline def applyMutator[T](init: T)(f: (T) => Unit) = {
f(init)
init
}
@@ -9,22 +9,18 @@
package net.bdew.lib.gui.widgets
import java.text.DecimalFormat
import net.bdew.lib.Misc
import net.bdew.lib.data.DataSlotTankBase
import net.bdew.lib.gui.{Color, Point, Rect, Texture}
import net.bdew.lib.{DecFormat, Misc}
import org.lwjgl.opengl.GL11
import scala.collection.mutable
class WidgetFluidGauge(val rect: Rect, overlay: Texture, dslot: DataSlotTankBase) extends Widget {
val formater = new DecimalFormat("#,###")
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) {
if (dslot.getFluid != null) {
tip += dslot.getFluid.getFluid.getLocalizedName(dslot.getFluid)
tip += "%s/%s mB".format(formater.format(dslot.getFluidAmount), formater.format(dslot.getCapacity))
tip += "%s/%s mB".format(DecFormat.round(dslot.getFluidAmount), DecFormat.round(dslot.getCapacity))
} else {
tip += Misc.toLocal("bdlib.label.empty")
}
@@ -34,11 +30,11 @@ class WidgetFluidGauge(val rect: Rect, overlay: Texture, dslot: DataSlotTankBase
GL11.glEnable(GL11.GL_BLEND)
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
val fstack = dslot.getFluid
if (fstack != null) {
val color = Color.fromInt(Misc.getFluidColor(fstack))
val icon = Texture(Texture.BLOCKS, Misc.getFluidIcon(fstack))
var fillHeight = if (dslot.getCapacity > 0) rect.h * fstack.amount / dslot.getCapacity else 0
val fStack = dslot.getFluid
if (fStack != null) {
val color = Color.fromInt(Misc.getFluidColor(fStack))
val icon = Texture(Texture.BLOCKS, Misc.getFluidIcon(fStack))
var fillHeight = if (dslot.getCapacity > 0) rect.h * fStack.amount / dslot.getCapacity else 0
var yStart: Int = 0
while (fillHeight > 0) {
@@ -36,7 +36,10 @@ class ItemStackSerialize(var stack: ItemStack) extends Serializable {
}
object ItemStackSerialize {
implicit def ser2content(v: ItemStackSerialize) = v.stack
implicit def content2ser(v: ItemStack) = new ItemStackSerialize(v)
import scala.language.implicitConversions
implicit def ser2content(v: ItemStackSerialize): ItemStack = v.stack
implicit def content2ser(v: ItemStack): ItemStackSerialize = new ItemStackSerialize(v)
}
@@ -25,6 +25,9 @@ class NBTTagCompoundSerialize(var tag: NBTTagCompound = new NBTTagCompound) exte
}
object NBTTagCompoundSerialize {
implicit def ser2content(v: NBTTagCompoundSerialize) = v.tag
implicit def content2ser(v: NBTTagCompound) = new NBTTagCompoundSerialize(v)
import scala.language.implicitConversions
implicit def ser2content(v: NBTTagCompoundSerialize): NBTTagCompound = v.tag
implicit def content2ser(v: NBTTagCompound): NBTTagCompoundSerialize = new NBTTagCompoundSerialize(v)
}
@@ -11,20 +11,19 @@ package net.bdew.lib.power
import java.text.DecimalFormat
import net.bdew.lib.DecFormat
import net.bdew.lib.gui.widgets.Widget
import net.bdew.lib.gui.{Point, Rect, Texture}
import scala.collection.mutable
class WidgetPowerGauge(val rect: Rect, texture: Texture, dslot: DataSlotPower) extends Widget {
val formater = new DecimalFormat("#,###")
class WidgetPowerGauge(val rect: Rect, texture: Texture, dSlot: DataSlotPower) extends Widget {
val a = rect.map(_.round)
override def draw(mouse: Point) {
val fill = dslot.stored / dslot.capacity
val fill = dSlot.stored / dSlot.capacity
parent.drawTextureInterpolate(rect, texture, 0, 1 - fill, 1, 1)
}
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) = tip += formater.format(dslot.stored) + "/" + formater.format(dslot.capacity) + " MJ"
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) = tip += DecFormat.round(dSlot.stored) + "/" + DecFormat.round(dSlot.capacity) + " MJ"
}