mirror of
https://gitlab.com/cc-ru/ocelot/ocelot-desktop.git
synced 2026-03-25 17:02:46 +01:00
add: turn on and off on left shift lmb
This commit is contained in:
@@ -3,6 +3,7 @@ package ocelot.desktop.node
|
||||
import ocelot.desktop.color.{Color, RGBAColor}
|
||||
import ocelot.desktop.geometry.{Rect2D, Size2D, Vector2D}
|
||||
import ocelot.desktop.graphics.Graphics
|
||||
import ocelot.desktop.node.nodes.ComputerNode
|
||||
import ocelot.desktop.ui.UiHandler
|
||||
import ocelot.desktop.ui.event.handlers.{ClickHandler, DragHandler, HoverHandler}
|
||||
import ocelot.desktop.ui.event.{ClickEvent, DragEvent, HoverEvent, MouseEvent}
|
||||
@@ -63,13 +64,8 @@ trait Node extends Widget with DragHandler with ClickHandler with HoverHandler {
|
||||
override def receiveMouseEvents = true
|
||||
|
||||
eventHandlers += {
|
||||
case ClickEvent(MouseEvent.Button.Left, _) =>
|
||||
window.foreach(window => workspaceView.windowPool.openWindow(window))
|
||||
|
||||
case ClickEvent(MouseEvent.Button.Right, _) =>
|
||||
val menu = new ContextMenu
|
||||
setupContextMenu(menu)
|
||||
root.get.contextMenus.open(menu)
|
||||
case event: ClickEvent =>
|
||||
onClick(event)
|
||||
|
||||
case DragEvent(DragEvent.State.Start, MouseEvent.Button.Left, pos) =>
|
||||
startMoving(pos)
|
||||
@@ -177,6 +173,17 @@ trait Node extends Widget with DragHandler with ClickHandler with HoverHandler {
|
||||
getNodeByPort(portA).disconnect(node.getNodeByPort(portB))
|
||||
}
|
||||
|
||||
def onClick(event: ClickEvent): Unit = {
|
||||
event match {
|
||||
case ClickEvent(MouseEvent.Button.Left, _) =>
|
||||
window.foreach(window => workspaceView.windowPool.openWindow(window))
|
||||
case ClickEvent(MouseEvent.Button.Right, _) =>
|
||||
val menu = new ContextMenu
|
||||
setupContextMenu(menu)
|
||||
root.get.contextMenus.open(menu)
|
||||
}
|
||||
}
|
||||
|
||||
def portsBounds: Iterator[(NodePort, Array[Rect2D])] = {
|
||||
val length = -4
|
||||
val thickness = 4
|
||||
|
||||
@@ -5,9 +5,12 @@ import ocelot.desktop.audio.{Audio, SoundSource}
|
||||
import ocelot.desktop.color.Color
|
||||
import ocelot.desktop.graphics.Graphics
|
||||
import ocelot.desktop.node.Node
|
||||
import ocelot.desktop.ui.event.sources.KeyEvents
|
||||
import ocelot.desktop.ui.event.{ClickEvent, MouseEvent}
|
||||
import ocelot.desktop.ui.widget.contextmenu.{ContextMenu, ContextMenuEntry, ContextMenuSubmenu}
|
||||
import ocelot.desktop.ui.widget.slot._
|
||||
import ocelot.desktop.util.{ResourceManager, TierColor}
|
||||
import org.lwjgl.input.Keyboard
|
||||
import totoro.ocelot.brain.entity.traits.{Computer, Entity, GenericCPU}
|
||||
import totoro.ocelot.brain.entity.{CPU, Case, EEPROM, FloppyManaged, GraphicsCard, HDDManaged, Memory}
|
||||
import totoro.ocelot.brain.loot.Loot
|
||||
@@ -71,8 +74,10 @@ class ComputerNode(val computer: Case, setup: Boolean = true) extends Node {
|
||||
soundComputerRunning.stop()
|
||||
}
|
||||
|
||||
def isRunning: Boolean = computer.machine.isRunning
|
||||
|
||||
override def setupContextMenu(menu: ContextMenu): Unit = {
|
||||
if (computer.machine.isRunning) {
|
||||
if (isRunning) {
|
||||
menu.addEntry(new ContextMenuEntry("Turn off", () => turnOff()))
|
||||
menu.addEntry(new ContextMenuEntry("Reboot", () => {
|
||||
computer.turnOff()
|
||||
@@ -92,6 +97,20 @@ class ComputerNode(val computer: Case, setup: Boolean = true) extends Node {
|
||||
super.setupContextMenu(menu)
|
||||
}
|
||||
|
||||
override def onClick(event: ClickEvent): Unit = {
|
||||
event match {
|
||||
case ClickEvent(MouseEvent.Button.Left, _) =>
|
||||
if (KeyEvents.isDown(Keyboard.KEY_LSHIFT))
|
||||
if (isRunning)
|
||||
turnOff()
|
||||
else
|
||||
turnOn()
|
||||
else
|
||||
super.onClick(event)
|
||||
case event => super.onClick(event)
|
||||
}
|
||||
}
|
||||
|
||||
private def changeTier(n: Int): Unit = {
|
||||
computer.tier = n
|
||||
setupSlots()
|
||||
@@ -160,7 +179,6 @@ class ComputerNode(val computer: Case, setup: Boolean = true) extends Node {
|
||||
override def draw(g: Graphics): Unit = {
|
||||
super.draw(g)
|
||||
|
||||
val isRunning = computer.machine.isRunning
|
||||
val hasErrored = computer.machine.lastError != null
|
||||
|
||||
if (isRunning && !hasErrored)
|
||||
@@ -175,7 +193,7 @@ class ComputerNode(val computer: Case, setup: Boolean = true) extends Node {
|
||||
|
||||
override def update(): Unit = {
|
||||
super.update()
|
||||
if (!computer.machine.isRunning && soundComputerRunning.isPlaying)
|
||||
if (!isRunning && soundComputerRunning.isPlaying)
|
||||
soundComputerRunning.stop()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user