mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
impl chat finally
This commit is contained in:
parent
74c5cf391e
commit
86b62d4801
7 changed files with 209 additions and 72 deletions
|
|
@ -2111,6 +2111,7 @@ class Marble extends GameObject {
|
|||
move.d = new Vector();
|
||||
move.d.x = Gamepad.getAxis(Settings.gamepadSettings.moveYAxis);
|
||||
move.d.y = -Gamepad.getAxis(Settings.gamepadSettings.moveXAxis);
|
||||
if (@:privateAccess !MarbleGame.instance.world.playGui.isChatFocused()) {
|
||||
if (Key.isDown(Settings.controlsSettings.forward)) {
|
||||
move.d.x -= 1;
|
||||
}
|
||||
|
|
@ -2143,6 +2144,7 @@ class Marble extends GameObject {
|
|||
move.d.y = -MarbleGame.instance.touchInput.movementInput.value.x;
|
||||
move.d.x = MarbleGame.instance.touchInput.movementInput.value.y;
|
||||
}
|
||||
}
|
||||
return move;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ typedef ControlsSettings = {
|
|||
var respawn:Int;
|
||||
var blast:Int;
|
||||
var rewind:Int;
|
||||
var chat:Int;
|
||||
}
|
||||
|
||||
typedef TouchSettings = {
|
||||
|
|
@ -161,6 +162,7 @@ class Settings {
|
|||
respawn: Key.BACKSPACE,
|
||||
blast: Key.MOUSE_RIGHT,
|
||||
rewind: Key.R,
|
||||
chat: Key.T
|
||||
};
|
||||
|
||||
public static var touchSettings:TouchSettings = {
|
||||
|
|
@ -387,6 +389,9 @@ class Settings {
|
|||
if (controlsSettings.rewind == 0) {
|
||||
controlsSettings.rewind = Key.R;
|
||||
}
|
||||
if (controlsSettings.chat == 0) {
|
||||
controlsSettings.chat = Key.T;
|
||||
}
|
||||
if (touchSettings.blastButtonPos == null) {
|
||||
touchSettings.blastButtonPos = [300, 240];
|
||||
touchSettings.blastButtonSize = 60;
|
||||
|
|
@ -450,6 +455,9 @@ class Settings {
|
|||
if (controlsSettings.rewind == null) {
|
||||
controlsSettings.rewind = Key.R;
|
||||
}
|
||||
if (controlsSettings.chat == null) {
|
||||
controlsSettings.chat = Key.T;
|
||||
}
|
||||
if (optionsSettings.rewindEnabled == null) {
|
||||
optionsSettings.rewindEnabled = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@ class KeyBindingsGui extends GuiImage {
|
|||
return "Free Look";
|
||||
if (Settings.controlsSettings.rewind == key && bindingName != "Rewind")
|
||||
return "Rewind";
|
||||
if (Settings.controlsSettings.chat == key && bindingName != "Chat")
|
||||
return "Chat";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
@ -179,6 +181,10 @@ class KeyBindingsGui extends GuiImage {
|
|||
b12.pressedAction = (e) -> {
|
||||
remapFunc("Rewind", (key) -> Settings.controlsSettings.rewind = key, b12);
|
||||
}
|
||||
var b13 = btnListLeft.addButton(0, 'Chat: ${Util.getKeyForButton2(Settings.controlsSettings.chat)}', (e) -> {});
|
||||
b13.pressedAction = (e) -> {
|
||||
remapFunc("Chat", (key) -> Settings.controlsSettings.chat = key, b13);
|
||||
}
|
||||
|
||||
var bottomBar = new GuiControl();
|
||||
bottomBar.position = new Vector(0, 590);
|
||||
|
|
@ -226,6 +232,8 @@ class KeyBindingsGui extends GuiImage {
|
|||
}
|
||||
if (prevSelected == 1 && selectedColumn == 0) {
|
||||
btnListRight.selected = btnListLeft.selected;
|
||||
if (btnListRight.selected > btnListRight.buttons.length - 1)
|
||||
btnListRight.selected = btnListRight.buttons.length - 1;
|
||||
}
|
||||
if (_prevMousePosition == null || !_prevMousePosition.equals(mouseState.position)) {
|
||||
for (i in 0...btnListLeft.buttons.length) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package gui;
|
||||
|
||||
import net.NetCommands;
|
||||
import hxd.Key;
|
||||
import net.NetPacket.ScoreboardPacket;
|
||||
import net.Net;
|
||||
import h3d.Matrix;
|
||||
|
|
@ -46,13 +48,20 @@ class MiddleMessage {
|
|||
|
||||
@:publicFields
|
||||
@:structInit
|
||||
typedef PlayerInfo = {
|
||||
class PlayerInfo {
|
||||
var id:Int;
|
||||
var name:String;
|
||||
var us:Bool;
|
||||
var score:Int;
|
||||
}
|
||||
|
||||
@:publicFields
|
||||
@:structInit
|
||||
class ChatMessage {
|
||||
var text:String;
|
||||
var sendTime:Float;
|
||||
}
|
||||
|
||||
class PlayGui {
|
||||
var scene2d:h2d.Scene;
|
||||
|
||||
|
|
@ -108,7 +117,10 @@ class PlayGui {
|
|||
|
||||
var chatHudCtrl:GuiControl;
|
||||
var chatHud:GuiMLText;
|
||||
var chats:Array<String>;
|
||||
var chatHudBg:GuiMLText;
|
||||
var chatHudInput:GuiTextInput;
|
||||
var chats:Array<ChatMessage>;
|
||||
var chatFocused:Bool = false;
|
||||
|
||||
public function dispose() {
|
||||
if (_init) {
|
||||
|
|
@ -664,21 +676,101 @@ class PlayGui {
|
|||
var arial14fontdata = ResourceLoader.getFileEntry("data/font/Arial Bold.fnt");
|
||||
var arial14b = new BitmapFont(arial14fontdata.entry);
|
||||
@:privateAccess arial14b.loader = ResourceLoader.loader;
|
||||
var arial14 = arial14b.toSdfFont(cast 16 * Settings.uiScale, MultiChannel);
|
||||
var arial14 = arial14b.toSdfFont(cast 15 * Settings.uiScale, MultiChannel);
|
||||
|
||||
this.chatHudCtrl = new GuiControl();
|
||||
this.chatHudCtrl.position = new Vector(playGuiCtrl.extent.x - 201, 150);
|
||||
this.chatHudCtrl.extent = new Vector(150, 200);
|
||||
this.chatHudCtrl.extent = new Vector(200, 250);
|
||||
this.chatHudCtrl.horizSizing = Left;
|
||||
this.playGuiCtrl.addChild(chatHudCtrl);
|
||||
|
||||
this.chats = [];
|
||||
|
||||
this.chatHudBg = new GuiMLText(arial14, (s) -> arial14);
|
||||
this.chatHudBg.position = new Vector(1, 21);
|
||||
this.chatHudBg.extent = new Vector(200, 250);
|
||||
this.chatHudBg.text.textColor = 0;
|
||||
this.chatHudCtrl.addChild(chatHudBg);
|
||||
|
||||
this.chatHud = new GuiMLText(arial14, (s) -> arial14);
|
||||
this.chatHud.position = new Vector(0, 0);
|
||||
this.chatHud.extent = new Vector(150, 200);
|
||||
this.chatHud.position = new Vector(0, 20);
|
||||
this.chatHud.extent = new Vector(200, 250);
|
||||
this.chatHudCtrl.addChild(chatHud);
|
||||
|
||||
this.chatHud.text.text = "User 1: Hi<br/>User 2: Hello<br/>User 3: Hey";
|
||||
this.chatHudInput = new GuiTextInput(arial14);
|
||||
this.chatHudInput.position = new Vector(0, 0);
|
||||
this.chatHudInput.extent = new Vector(200, 20);
|
||||
@:privateAccess this.chatHudInput.text.interactive.forceAnywherefocus = true;
|
||||
this.chatHudCtrl.addChild(chatHudInput);
|
||||
|
||||
var sendText = "";
|
||||
|
||||
this.chatHudInput.text.onFocus = (e) -> {
|
||||
chatFocused = true;
|
||||
}
|
||||
|
||||
this.chatHudInput.text.onFocusLost = (e) -> {
|
||||
sendText = "";
|
||||
chatFocused = false;
|
||||
}
|
||||
|
||||
this.chatHudInput.text.onKeyDown = (e) -> {
|
||||
if (e.keyCode == Key.ENTER) {
|
||||
sendText = '<font color="#F29515">${StringTools.htmlEscape(Settings.highscoreName.substr(0, 20))}:</font> ${StringTools.htmlEscape(this.chatHudInput.text.text.substr(0, 50))}';
|
||||
if (Net.isClient) {
|
||||
NetCommands.sendChatMessage(StringTools.htmlEscape(sendText));
|
||||
}
|
||||
if (Net.isHost) {
|
||||
NetCommands.sendServerChatMessage(StringTools.htmlEscape(sendText));
|
||||
}
|
||||
this.chatHudInput.text.text = "";
|
||||
chatFocused = false;
|
||||
}
|
||||
if (e.keyCode == Key.ESCAPE) {
|
||||
this.chatHudInput.text.text = "";
|
||||
chatFocused = false;
|
||||
@:privateAccess Key.keyPressed[Key.ESCAPE] = 0; // consume escape
|
||||
}
|
||||
}
|
||||
|
||||
this.chatHud.text.text = "";
|
||||
}
|
||||
|
||||
public inline function isChatFocused() {
|
||||
return chatFocused;
|
||||
}
|
||||
|
||||
public function addChatMessage(text:String) {
|
||||
var realText = StringTools.htmlUnescape(text);
|
||||
this.chats.push({
|
||||
text: realText,
|
||||
sendTime: MarbleGame.instance.world.timeState.timeSinceLoad
|
||||
});
|
||||
if (this.chats.length > 10) {
|
||||
this.chats = this.chats.slice(this.chats.length - 10);
|
||||
}
|
||||
redrawChatMessages();
|
||||
}
|
||||
|
||||
function redrawChatMessages() {
|
||||
var joined = this.chats.map(x -> x.text).join("<br/>");
|
||||
this.chatHud.text.text = joined;
|
||||
this.chatHudBg.text.text = StringTools.replace(joined, '#F29515', '#000000');
|
||||
}
|
||||
|
||||
function tickChats(timeState:TimeState) {
|
||||
var needsRedraw = false;
|
||||
while (this.chats.length > 0) {
|
||||
if (this.chats[0].sendTime + 10 < timeState.timeSinceLoad) {
|
||||
this.chats.shift();
|
||||
needsRedraw = true;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (needsRedraw) {
|
||||
redrawChatMessages();
|
||||
}
|
||||
}
|
||||
|
||||
var blastValue:Float = 0;
|
||||
|
|
@ -1141,6 +1233,17 @@ class PlayGui {
|
|||
this.fpsMeter.text.text = '${Math.floor(ProfilerUI.instance.fps)} fps';
|
||||
}
|
||||
this.updateMiddleMessages(timeState.dt);
|
||||
if (Net.isMP) {
|
||||
if (!chatFocused) {
|
||||
if (Key.isPressed(Settings.controlsSettings.chat)) {
|
||||
if (this.chatHudCtrl != null) {
|
||||
this.chatHudInput.text.focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tickChats(timeState);
|
||||
}
|
||||
}
|
||||
|
||||
function updateMiddleMessages(dt:Float) {
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class InputBitStream {
|
|||
}
|
||||
|
||||
public function readString() {
|
||||
var length = readByte();
|
||||
var length = readUInt16();
|
||||
var str = "";
|
||||
for (i in 0...length) {
|
||||
str += String.fromCharCode(readByte());
|
||||
|
|
@ -146,7 +146,7 @@ class OutputBitStream {
|
|||
}
|
||||
|
||||
public function writeString(value:String) {
|
||||
writeByte(value.length);
|
||||
writeUInt16(value.length);
|
||||
for (i in 0...value.length) {
|
||||
writeByte(StringTools.fastCodeAt(value, i));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ class MoveManager {
|
|||
if (!MarbleGame.instance.paused) {
|
||||
move.d.x = Gamepad.getAxis(Settings.gamepadSettings.moveYAxis);
|
||||
move.d.y = -Gamepad.getAxis(Settings.gamepadSettings.moveXAxis);
|
||||
if (@:privateAccess !MarbleGame.instance.world.playGui.isChatFocused()) {
|
||||
if (Key.isDown(Settings.controlsSettings.forward)) {
|
||||
move.d.x -= 1;
|
||||
}
|
||||
|
|
@ -108,6 +109,7 @@ class MoveManager {
|
|||
move.d.y = -MarbleGame.instance.touchInput.movementInput.value.x;
|
||||
move.d.x = MarbleGame.instance.touchInput.movementInput.value.y;
|
||||
}
|
||||
}
|
||||
|
||||
// quantize moves for client
|
||||
var qx = Std.int((move.d.x * 16) + 16);
|
||||
|
|
@ -214,12 +216,12 @@ class MoveManager {
|
|||
if (queuedMoves.length > serverMaxMoveListSize
|
||||
|| (serverAvgMoveListSize > serverTargetMoveListSize + serverMoveListSizeSlack
|
||||
&& queuedMoves.length > serverTargetMoveListSize)) {
|
||||
if (queuedMoves.length > serverMaxMoveListSize) {
|
||||
// if (queuedMoves.length > serverMaxMoveListSize) {
|
||||
var dropAmt = queuedMoves.length - serverTargetMoveListSize;
|
||||
while (dropAmt-- > 0) {
|
||||
queuedMoves.pop();
|
||||
}
|
||||
}
|
||||
// }
|
||||
serverAvgMoveListSize = serverTargetMoveListSize;
|
||||
// serverAbnormalMoveCount++;
|
||||
// if (serverAbnormalMoveCount > 3) {
|
||||
|
|
|
|||
|
|
@ -326,4 +326,18 @@ class NetCommands {
|
|||
ping(Console.time());
|
||||
}
|
||||
}
|
||||
|
||||
@:rpc(client) public static function sendChatMessage(msg:String) {
|
||||
if (Net.isHost) {
|
||||
sendServerChatMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@:rpc(server) public static function sendServerChatMessage(msg:String) {
|
||||
if (MarbleGame.instance.world != null) {
|
||||
if (MarbleGame.instance.world._ready) {
|
||||
@:privateAccess MarbleGame.instance.world.playGui.addChatMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue