mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 11:15:12 -04:00
added setting whether to pass the username along with input events (touch, key_x, walk); passing along the mouse button as a parameter for mouse events
This commit is contained in:
parent
6ff3ffe95e
commit
d1ac04a7b4
@ -153,6 +153,7 @@ class Settings(config: Config) {
|
||||
// misc
|
||||
val maxScreenWidth = config.getInt("misc.maxScreenWidth") max 1
|
||||
val maxScreenHeight = config.getInt("misc.maxScreenHeight") max 1
|
||||
val inputUsername = config.getBoolean("inputUsername")
|
||||
val maxClipboard = config.getInt("misc.maxClipboard") max 0
|
||||
val commandUser = config.getString("misc.commandUser").trim
|
||||
val maxNetworkPacketSize = config.getInt("misc.maxNetworkPacketSize") max 0
|
||||
|
@ -68,7 +68,7 @@ object PacketSender {
|
||||
}
|
||||
}
|
||||
|
||||
def sendMouseClick(b: component.Buffer, x: Int, y: Int, drag: Boolean) {
|
||||
def sendMouseClick(b: component.Buffer, x: Int, y: Int, drag: Boolean, button: Int) {
|
||||
val pb = new PacketBuilder(PacketType.MouseClickOrDrag)
|
||||
|
||||
b.owner match {
|
||||
@ -82,6 +82,7 @@ object PacketSender {
|
||||
pb.writeInt(x)
|
||||
pb.writeInt(y)
|
||||
pb.writeBoolean(drag)
|
||||
pb.writeByte(button.toByte)
|
||||
|
||||
pb.sendToServer()
|
||||
}
|
||||
|
@ -33,8 +33,8 @@ class Screen(val buffer: common.component.Buffer, val hasMouse: Boolean, val has
|
||||
override protected def mouseClicked(mouseX: Int, mouseY: Int, button: Int) {
|
||||
super.mouseClicked(mouseX, mouseY, button)
|
||||
if (hasMouse) {
|
||||
if (button == 0) {
|
||||
clickOrDrag(mouseX, mouseY)
|
||||
if (button == 0 || button == 1) {
|
||||
clickOrDrag(mouseX, mouseY, button)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -42,8 +42,8 @@ class Screen(val buffer: common.component.Buffer, val hasMouse: Boolean, val has
|
||||
protected override def mouseClickMove(mouseX: Int, mouseY: Int, button: Int, timeSinceLast: Long) {
|
||||
super.mouseClickMove(mouseX, mouseY, button, timeSinceLast)
|
||||
if (hasMouse && timeSinceLast > 10) {
|
||||
if (button == 0) {
|
||||
clickOrDrag(mouseX, mouseY)
|
||||
if (button == 0 || button == 1) {
|
||||
clickOrDrag(mouseX, mouseY, button)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -56,13 +56,13 @@ class Screen(val buffer: common.component.Buffer, val hasMouse: Boolean, val has
|
||||
}
|
||||
}
|
||||
|
||||
private def clickOrDrag(mouseX: Int, mouseY: Int) {
|
||||
private def clickOrDrag(mouseX: Int, mouseY: Int, button: Int) {
|
||||
val bx = ((mouseX - x - bufferMargin) / scale / MonospaceFontRenderer.fontWidth).toInt + 1
|
||||
val by = ((mouseY - y - bufferMargin) / scale / MonospaceFontRenderer.fontHeight).toInt + 1
|
||||
val (bw, bh) = buffer.resolution
|
||||
if (bx > 0 && by > 0 && bx <= bw && by <= bh) {
|
||||
if (bx != mx || by != my) {
|
||||
PacketSender.sendMouseClick(buffer, bx, by, mx > 0 && my > 0)
|
||||
PacketSender.sendMouseClick(buffer, bx, by, mx > 0 && my > 0, button)
|
||||
mx = bx
|
||||
my = by
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ class Screen(var tier: Int) extends Buffer with SidedEnvironment with Rotatable
|
||||
|
||||
// Convert to absolute coordinates and send the packet to the server.
|
||||
if (world.isRemote) {
|
||||
ClientPacketSender.sendMouseClick(this.buffer, (brx * bw).toInt + 1, (bry * bh).toInt + 1, drag = false)
|
||||
ClientPacketSender.sendMouseClick(this.buffer, (brx * bw).toInt + 1, (bry * bh).toInt + 1, drag = false, 0)
|
||||
}
|
||||
true
|
||||
}
|
||||
@ -164,7 +164,7 @@ class Screen(var tier: Int) extends Buffer with SidedEnvironment with Rotatable
|
||||
def walk(entity: Entity) {
|
||||
val (x, y) = localPosition
|
||||
entity match {
|
||||
case player: EntityPlayer =>
|
||||
case player: EntityPlayer if Settings.get.inputUsername =>
|
||||
origin.node.sendToReachable("computer.signal", "walk", Int.box(x + 1), Int.box(height - y), player.getCommandSenderName)
|
||||
case _ =>
|
||||
origin.node.sendToReachable("computer.signal", "walk", Int.box(x + 1), Int.box(height - y))
|
||||
|
@ -102,7 +102,13 @@ class PacketHandler extends CommonPacketHandler {
|
||||
val x = p.readInt()
|
||||
val y = p.readInt()
|
||||
val what = if (p.readBoolean()) "drag" else "touch"
|
||||
node.sendToReachable("computer.checked_signal", player, what, Int.box(x), Int.box(y), player.getCommandSenderName)
|
||||
val button = p.readByte()
|
||||
if (Settings.get.inputUsername) {
|
||||
node.sendToReachable("computer.checked_signal", player, what, Int.box(x), Int.box(y), Int.box(button), player.getCommandSenderName)
|
||||
}
|
||||
else {
|
||||
node.sendToReachable("computer.checked_signal", player, what, Int.box(x), Int.box(y), Int.box(button))
|
||||
}
|
||||
case _ => // Invalid packet.
|
||||
}
|
||||
}
|
||||
@ -118,7 +124,12 @@ class PacketHandler extends CommonPacketHandler {
|
||||
val x = p.readInt()
|
||||
val y = p.readInt()
|
||||
val scroll = p.readByte()
|
||||
node.sendToReachable("computer.checked_signal", player, "scroll", Int.box(x), Int.box(y), Int.box(scroll), player.getCommandSenderName)
|
||||
if (Settings.get.inputUsername) {
|
||||
node.sendToReachable("computer.checked_signal", player, "scroll", Int.box(x), Int.box(y), Int.box(scroll), player.getCommandSenderName)
|
||||
}
|
||||
else {
|
||||
node.sendToReachable("computer.checked_signal", player, "scroll", Int.box(x), Int.box(y), Int.box(scroll))
|
||||
}
|
||||
case _ => // Invalid packet.
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package li.cil.oc.server.component
|
||||
|
||||
import cpw.mods.fml.common.IPlayerTracker
|
||||
import li.cil.oc.Settings
|
||||
import li.cil.oc.api.Network
|
||||
import li.cil.oc.api.network.{Node, Visibility, Message}
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
@ -23,8 +24,14 @@ abstract class Keyboard extends ManagedComponent {
|
||||
@ForgeSubscribe
|
||||
def onReleasePressedKeys(e: Keyboard.ReleasePressedKeys) {
|
||||
pressedKeys.get(e.player) match {
|
||||
case Some(keys) => for ((code, char) <- keys)
|
||||
signal(e.player, "key_up", char, code, e.player.getCommandSenderName)
|
||||
case Some(keys) => for ((code, char) <- keys) {
|
||||
if (Settings.get.inputUsername) {
|
||||
signal(e.player, "key_up", char, code, e.player.getCommandSenderName)
|
||||
}
|
||||
else {
|
||||
signal(e.player, "key_up", char, code)
|
||||
}
|
||||
}
|
||||
case _ =>
|
||||
}
|
||||
pressedKeys.remove(e.player)
|
||||
@ -49,19 +56,34 @@ abstract class Keyboard extends ManagedComponent {
|
||||
case Array(p: EntityPlayer, char: Character, code: Integer) if message.name == "keyboard.keyDown" =>
|
||||
if (isUseableByPlayer(p)) {
|
||||
pressedKeys.getOrElseUpdate(p, mutable.Map.empty[Integer, Character]) += code -> char
|
||||
signal(p, "key_down", char, code, p.getCommandSenderName)
|
||||
if (Settings.get.inputUsername) {
|
||||
signal(p, "key_down", char, code, p.getCommandSenderName)
|
||||
}
|
||||
else {
|
||||
signal(p, "key_down", char, code)
|
||||
}
|
||||
}
|
||||
case Array(p: EntityPlayer, char: Character, code: Integer) if message.name == "keyboard.keyUp" =>
|
||||
pressedKeys.get(p) match {
|
||||
case Some(keys) if keys.contains(code) =>
|
||||
keys -= code
|
||||
signal(p, "key_up", char, code, p.getCommandSenderName)
|
||||
if (Settings.get.inputUsername) {
|
||||
signal(p, "key_up", char, code, p.getCommandSenderName)
|
||||
}
|
||||
else {
|
||||
signal(p, "key_up", char, code)
|
||||
}
|
||||
case _ =>
|
||||
}
|
||||
case Array(p: EntityPlayer, value: String) if message.name == "keyboard.clipboard" =>
|
||||
if (isUseableByPlayer(p)) {
|
||||
for (line <- value.linesWithSeparators) {
|
||||
signal(p, "clipboard", line, p.getCommandSenderName)
|
||||
if (Settings.get.inputUsername) {
|
||||
signal(p, "clipboard", line, p.getCommandSenderName)
|
||||
}
|
||||
else {
|
||||
signal(p, "clipboard", line)
|
||||
}
|
||||
}
|
||||
}
|
||||
case _ =>
|
||||
|
@ -636,6 +636,11 @@ opencomputers {
|
||||
# efficient (i.e. when adding/removing a single screen).
|
||||
maxScreenHeight: 6
|
||||
|
||||
# Whether to pass along the name of the user that caused an input signals
|
||||
# to the computer (mouse and keyboard signals). If you feel this breaks
|
||||
# the game's immersion, disable it.
|
||||
inputUsername: true
|
||||
|
||||
# The maximum length of a string that may be pasted. This is used to limit
|
||||
# the size of the data sent to the server when the user tries to paste a
|
||||
# string from the clipboard (Shift+Ins on a screen with a keyboard).
|
||||
|
Loading…
x
Reference in New Issue
Block a user