mirror of
https://gitlab.com/cc-ru/ocelot/ocelot-desktop.git
synced 2025-12-20 02:59:19 +01:00
Added OpenFM radio support
This commit is contained in:
parent
03e22974bc
commit
276e66a266
@ -1 +1 @@
|
||||
Subproject commit f40c686e2a012807f23662f987b90f3f73df21a0
|
||||
Subproject commit bfe67ec9e4f13673f6178e1e29d7781910ef102e
|
||||
BIN
sprites/nodes/OpenFMRadio.png
Normal file
BIN
sprites/nodes/OpenFMRadio.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 370 B |
38
src/main/scala/ocelot/desktop/entity/OpenFMRadio.scala
Normal file
38
src/main/scala/ocelot/desktop/entity/OpenFMRadio.scala
Normal file
@ -0,0 +1,38 @@
|
||||
package ocelot.desktop.entity
|
||||
|
||||
import ocelot.desktop.util.WebcamCapture
|
||||
import totoro.ocelot.brain.Constants
|
||||
import totoro.ocelot.brain.entity.machine.{Arguments, Context}
|
||||
import totoro.ocelot.brain.entity.traits.DeviceInfo.{DeviceAttribute, DeviceClass}
|
||||
import totoro.ocelot.brain.entity.traits.{DeviceInfo, Entity, OpenFMRadio}
|
||||
import totoro.ocelot.brain.nbt.NBTTagCompound
|
||||
import totoro.ocelot.brain.workspace.Workspace
|
||||
|
||||
class OpenFMRadio extends Entity with totoro.ocelot.brain.entity.traits.OpenFMRadio with DeviceInfo {
|
||||
|
||||
override def setURL(context: Context, args: Arguments): Array[AnyRef]
|
||||
|
||||
private lazy val deviceInfo: Map[String, String] = Map(
|
||||
DeviceAttribute.Class -> DeviceClass.Multimedia,
|
||||
DeviceAttribute.Description -> "OpenFM Radio",
|
||||
DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor,
|
||||
DeviceAttribute.Product -> "cool radio player"
|
||||
)
|
||||
override def getDeviceInfo: Map[String, String] = deviceInfo
|
||||
|
||||
override def load(nbt: NBTTagCompound, workspace: Workspace): Unit = {
|
||||
super.load(nbt, workspace)
|
||||
|
||||
// if (nbt.hasKey("device"))
|
||||
// webcamCapture = WebcamCapture.getInstance(nbt.getString("device"))
|
||||
|
||||
|
||||
}
|
||||
|
||||
override def save(nbt: NBTTagCompound): Unit = {
|
||||
super.save(nbt)
|
||||
|
||||
// nbt.setString("device", webcamCapture.name)
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
package ocelot.desktop.node.nodes.openfmradio
|
||||
|
||||
import ocelot.desktop.entity.{Camera, OpenFMRadio}
|
||||
import ocelot.desktop.node.Node
|
||||
|
||||
class OpenFMRadioNode(val radioEntity: OpenFMRadio) extends Node(radioEntity) {
|
||||
override def icon: String = "nodes/OpenFMRadio"
|
||||
|
||||
private lazy val currentWindow: Option[OpenFMRadioWindow] = Option(new OpenFMRadioWindow(this))
|
||||
|
||||
override def window: Option[OpenFMRadioWindow] = currentWindow
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
package ocelot.desktop.node.nodes.openfmradio
|
||||
|
||||
import com.github.sarxos.webcam.Webcam
|
||||
import ocelot.desktop.entity.Camera
|
||||
import ocelot.desktop.geometry.{Padding2D, Size2D, Vector2D}
|
||||
import ocelot.desktop.graphics.Graphics
|
||||
import ocelot.desktop.ui.layout.{Layout, LinearLayout}
|
||||
import ocelot.desktop.ui.widget.contextmenu.{ContextMenu, ContextMenuEntry}
|
||||
import ocelot.desktop.ui.widget.window.BasicWindow
|
||||
import ocelot.desktop.ui.widget._
|
||||
import ocelot.desktop.util.{DrawUtils, Orientation, WebcamCapture}
|
||||
|
||||
import scala.jdk.CollectionConverters.CollectionHasAsScala
|
||||
|
||||
class OpenFMRadioWindow(node: OpenFMRadioNode) extends BasicWindow {
|
||||
def camera: Camera = node.radioEntity
|
||||
|
||||
children :+= new PaddingBox(new Widget {
|
||||
override protected val layout: Layout = new LinearLayout(this, orientation = Orientation.Vertical)
|
||||
|
||||
val label = new Label {
|
||||
override def text: String = s"Camera — ${node.labelOrAddress}"
|
||||
override val isSmall: Boolean = true
|
||||
}
|
||||
|
||||
children :+= new PaddingBox(label, Padding2D.equal(4))
|
||||
children :+= new PaddingBox(new Button {
|
||||
override def minimumSize: Size2D = Size2D(256, 24)
|
||||
override def maximumSize: Size2D = Size2D(512, 24)
|
||||
override def size: Size2D = Size2D(label.size.width - 8, 24)
|
||||
override def text: String = camera.webcamCapture.name
|
||||
|
||||
override def onClick(): Unit = {
|
||||
val menu = new ContextMenu
|
||||
for (webcam <- Webcam.getWebcams().asScala)
|
||||
menu.addEntry(new ContextMenuEntry(webcam.getName, () => node.radioEntity.webcamCapture = WebcamCapture.getInstance(webcam)))
|
||||
|
||||
root.get.contextMenus.open(menu, Vector2D(position.x, position.y + size.height))
|
||||
}
|
||||
}, Padding2D.equal(8))
|
||||
|
||||
children :+= new PaddingBox(new Checkbox("Flip image horizontally",
|
||||
initialValue = camera.flipHorizontally) {
|
||||
override def onValueChanged(newValue: Boolean): Unit = camera.flipHorizontally = newValue
|
||||
}, Padding2D.equal(8))
|
||||
|
||||
children :+= new PaddingBox(new Checkbox("Flip image vertically",
|
||||
initialValue = camera.flipVertically) {
|
||||
override def onValueChanged(newValue: Boolean): Unit = camera.flipVertically = newValue
|
||||
}, Padding2D.equal(8))
|
||||
|
||||
children :+= new PaddingBox(new Checkbox("Unlimit call budget",
|
||||
initialValue = camera.directCalls) {
|
||||
override def onValueChanged(newValue: Boolean): Unit = camera.directCalls = newValue
|
||||
}, Padding2D.equal(8))
|
||||
}, Padding2D.equal(8))
|
||||
|
||||
override def draw(g: Graphics): Unit = {
|
||||
beginDraw(g)
|
||||
DrawUtils.windowWithShadow(g, position.x, position.y, size.width, size.height, 1f, 0.5f)
|
||||
drawChildren(g)
|
||||
endDraw(g)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user