Commit a3b8b093 authored by 140bpmdubstep's avatar 140bpmdubstep 📻
Browse files

Fixed tooltip performance degradation, and added EEPROM text labels

parent b8c4450a
Pipeline #588011660 passed with stage
in 4 minutes and 4 seconds
......@@ -3,6 +3,8 @@ package ocelot.desktop.color
object Color {
val White: RGBAColorNorm = RGBAColorNorm(1, 1, 1)
val Black: RGBAColorNorm = RGBAColorNorm(0, 0, 0)
val Yellow: RGBAColorNorm = RGBAColorNorm(1.0f, 1.0f, 0.33f)
val Cyan: RGBAColorNorm = RGBAColorNorm(0.33f, 1.0f, 1.0f)
val Transparent: RGBAColorNorm = RGBAColorNorm(0, 0, 0, 0)
}
......
......@@ -13,12 +13,12 @@ class SlotTooltip[T <: Entity](item: T) extends Tooltip {
override val layout = new LinearLayout(this, orientation = Orientation.Vertical)
}
def tier: (String, Color) = item match {
def tierDisplay: (String, Color) = item match {
case dev: Tiered =>
val (locTier, color) = if (dev.tier == 1) {
("(Tier " + (dev.tier + 1) + ")", RGBAColorNorm(1.0f, 1.0f, 0.33333333333333f))
("(Tier " + (dev.tier + 1) + ")", Color.Yellow)
} else if (dev.tier >= 2) {
("(Tier " + (dev.tier + 1) + ")", RGBAColorNorm(0.33333333333333f, 1.0f, 1.0f))
("(Tier " + (dev.tier + 1) + ")", Color.Cyan)
} else {
("(Tier " + (dev.tier + 1) + ")", Color.White)
}
......@@ -27,17 +27,17 @@ class SlotTooltip[T <: Entity](item: T) extends Tooltip {
}
item match {
case (dev: DeviceInfo with Environment) =>
case dev: DeviceInfo with Environment =>
val inner: Widget = new Widget {
override val layout = new LinearLayout(this, orientation = Orientation.Vertical)
}
inner.children :+= new Label {
override def text: String = {
dev.getDeviceInfo(DeviceInfo.DeviceAttribute.Description) + " " + tier._1
dev.getDeviceInfo(DeviceInfo.DeviceAttribute.Description) + " " + tierDisplay._1
}
override def color: Color = tier._2
override def color: Color = tierDisplay._2
}
inner.children :+= new Label {
......
package ocelot.desktop.ui.widget.slot
import ocelot.desktop.color.Color
import ocelot.desktop.graphics.IconDef
import ocelot.desktop.node.nodes.ComputerNode
import ocelot.desktop.ui.widget.SlotTooltip
import ocelot.desktop.ui.widget.contextmenu.{ContextMenu, ContextMenuEntry}
import totoro.ocelot.brain.entity.EEPROM
import totoro.ocelot.brain.entity.traits.Inventory
......@@ -21,7 +23,17 @@ class EEPROMSlot(owner: Inventory#Slot) extends InventorySlot[EEPROM](owner) {
menu.addEntry(new ContextMenuEntry("Empty",
() => item = new EEPROM,
icon = Some(new IconDef("items/EEPROM"))))
}
override def onHoverEnter(): Unit = {
item match {
case Some(item: EEPROM) => root.get.tooltipPool.pushTooltip(new SlotTooltip(item) {
override def tierDisplay: (String, Color) = {
("(" + item.label + ")", Color.White)
}
})
case _ =>
}
}
override def lmbMenuEnabled: Boolean = true
......
package ocelot.desktop.ui.widget.slot
import ocelot.desktop.color.Color
import ocelot.desktop.graphics.IconDef
import ocelot.desktop.node.nodes.ComputerNode
import ocelot.desktop.ui.widget.LabelTooltip
import ocelot.desktop.ui.widget.{LabelTooltip, SlotTooltip}
import ocelot.desktop.ui.widget.contextmenu.{ContextMenu, ContextMenuEntry}
import totoro.ocelot.brain.entity.Memory
import totoro.ocelot.brain.entity.traits.Inventory
import totoro.ocelot.brain.entity.traits.{Inventory, Tiered}
import totoro.ocelot.brain.util.Tier
class MemorySlot(owner: Inventory#Slot, val tier: Int) extends InventorySlot[Memory](owner) {
......@@ -14,6 +15,7 @@ class MemorySlot(owner: Inventory#Slot, val tier: Int) extends InventorySlot[Mem
override def icon: IconDef = new IconDef("icons/Memory")
override def tierIcon: Option[IconDef] = Some(new IconDef("icons/Tier" + tier))
override def fillLmbMenu(menu: ContextMenu): Unit = {
menu.addEntry(new ContextMenuEntry("RAM (Tier 1)",
() => item = new Memory(Tier.One),
......@@ -44,5 +46,25 @@ class MemorySlot(owner: Inventory#Slot, val tier: Int) extends InventorySlot[Mem
}
}
override def onHoverEnter(): Unit = {
item match {
case Some(item: Tiered) => root.get.tooltipPool.pushTooltip(new SlotTooltip(item) {
override def tierDisplay: (String, Color) = {
item.tier match {
case 0 => ("(Tier 1)", Color.White)
case 1 => ("(Tier 1.5)", Color.White)
case 2 => ("(Tier 2)", Color.Yellow)
case 3 => ("(Tier 2.5)", Color.Yellow)
case 4 => ("(Tier 3)", Color.Cyan)
case 5 => ("(Tier 3.5)", Color.Cyan)
}
}
})
case _ =>
}
}
override def lmbMenuEnabled: Boolean = true
}
......@@ -10,6 +10,7 @@ import ocelot.desktop.util.animation.{UnitAnimation, ValueAnimation}
class TooltipPool extends Widget {
val offset: Vector2D = Vector2D(5, 5)
val latency = 0.1f
override protected val layout: Layout = new Layout(this) {
override def relayout(): Unit = {
......@@ -27,7 +28,7 @@ class TooltipPool extends Widget {
def isVisible: Boolean = tooltips.nonEmpty
def pushTooltip(tooltip: Tooltip): Unit = {
timer.jump(0.1f)
timer.jump(latency)
children :+= tooltip
tooltip.open()
}
......@@ -48,8 +49,13 @@ class TooltipPool extends Widget {
super.update()
timer.update()
if (tooltips.nonEmpty & timer.isAt(0.1f))
if (tooltips.nonEmpty & timer.isAt(latency)) {
timer.goto(0.0f)
}
if (tooltips.length == tooltips.count(t => t.isClosed)) {
children = Array()
}
}
override def draw(g: Graphics): Unit = {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment