mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-12-31 12:22:18 +00:00
start chat
This commit is contained in:
parent
7dc09c06e3
commit
9b31427fe6
6 changed files with 289 additions and 90 deletions
|
|
@ -2150,46 +2150,46 @@ 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;
|
||||
}
|
||||
if (Key.isDown(Settings.controlsSettings.backward)) {
|
||||
move.d.x += 1;
|
||||
}
|
||||
if (Key.isDown(Settings.controlsSettings.left)) {
|
||||
move.d.y += 1;
|
||||
}
|
||||
if (Key.isDown(Settings.controlsSettings.right)) {
|
||||
move.d.y -= 1;
|
||||
}
|
||||
if (Key.isDown(Settings.controlsSettings.jump)
|
||||
|| MarbleGame.instance.touchInput.jumpButton.pressed
|
||||
|| Gamepad.isDown(Settings.gamepadSettings.jump)) {
|
||||
move.jump = true;
|
||||
}
|
||||
if ((!Util.isTouchDevice() && Key.isDown(Settings.controlsSettings.powerup))
|
||||
|| (Util.isTouchDevice() && MarbleGame.instance.touchInput.powerupButton.pressed)
|
||||
|| Gamepad.isDown(Settings.gamepadSettings.powerup)) {
|
||||
move.powerup = true;
|
||||
}
|
||||
if (@:privateAccess !MarbleGame.instance.world.playGui.isChatFocused()) {
|
||||
if (Key.isDown(Settings.controlsSettings.forward)) {
|
||||
move.d.x -= 1;
|
||||
}
|
||||
if (Key.isDown(Settings.controlsSettings.backward)) {
|
||||
move.d.x += 1;
|
||||
}
|
||||
if (Key.isDown(Settings.controlsSettings.left)) {
|
||||
move.d.y += 1;
|
||||
}
|
||||
if (Key.isDown(Settings.controlsSettings.right)) {
|
||||
move.d.y -= 1;
|
||||
}
|
||||
if (Key.isDown(Settings.controlsSettings.jump)
|
||||
|| MarbleGame.instance.touchInput.jumpButton.pressed
|
||||
|| Gamepad.isDown(Settings.gamepadSettings.jump)) {
|
||||
move.jump = true;
|
||||
}
|
||||
if ((!Util.isTouchDevice() && Key.isDown(Settings.controlsSettings.powerup))
|
||||
|| (Util.isTouchDevice() && MarbleGame.instance.touchInput.powerupButton.pressed)
|
||||
|| Gamepad.isDown(Settings.gamepadSettings.powerup)) {
|
||||
move.powerup = true;
|
||||
}
|
||||
|
||||
if (Key.isDown(Settings.controlsSettings.blast)
|
||||
|| (MarbleGame.instance.touchInput.blastbutton.pressed)
|
||||
|| Gamepad.isDown(Settings.gamepadSettings.blast))
|
||||
move.blast = true;
|
||||
if (Key.isDown(Settings.controlsSettings.blast)
|
||||
|| (MarbleGame.instance.touchInput.blastbutton.pressed)
|
||||
|| Gamepad.isDown(Settings.gamepadSettings.blast))
|
||||
move.blast = true;
|
||||
|
||||
if (Key.isDown(Settings.controlsSettings.respawn) || Gamepad.isDown(Settings.gamepadSettings.respawn)) {
|
||||
move.respawn = true;
|
||||
@:privateAccess Key.keyPressed[Settings.controlsSettings.respawn] = 0;
|
||||
Gamepad.releaseKey(Settings.gamepadSettings.respawn);
|
||||
}
|
||||
if (Key.isDown(Settings.controlsSettings.respawn) || Gamepad.isDown(Settings.gamepadSettings.respawn)) {
|
||||
move.respawn = true;
|
||||
@:privateAccess Key.keyPressed[Settings.controlsSettings.respawn] = 0;
|
||||
Gamepad.releaseKey(Settings.gamepadSettings.respawn);
|
||||
}
|
||||
|
||||
if (MarbleGame.instance.touchInput.movementInput.pressed) {
|
||||
move.d.y = -MarbleGame.instance.touchInput.movementInput.value.x;
|
||||
move.d.x = MarbleGame.instance.touchInput.movementInput.value.y;
|
||||
if (MarbleGame.instance.touchInput.movementInput.pressed) {
|
||||
move.d.y = -MarbleGame.instance.touchInput.movementInput.value.x;
|
||||
move.d.x = MarbleGame.instance.touchInput.movementInput.value.y;
|
||||
}
|
||||
}
|
||||
// }
|
||||
return move;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ class MarbleGame {
|
|||
|
||||
js.Browser.document.addEventListener('pointerlockchange', () -> {
|
||||
if (!paused && world != null) {
|
||||
if (world.finishTime == null && world._ready) {
|
||||
if (world.finishTime == null && world._ready && @:privateAccess !world.playGui.isChatFocused()) {
|
||||
if (js.Browser.document.pointerLockElement != @:privateAccess Window.getInstance().canvas) {
|
||||
paused = true;
|
||||
handlePauseGame();
|
||||
|
|
|
|||
166
src/gui/ChatCtrl.hx
Normal file
166
src/gui/ChatCtrl.hx
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
package gui;
|
||||
|
||||
import gui.GuiControl.MouseState;
|
||||
import src.Settings;
|
||||
import hxd.res.BitmapFont;
|
||||
import hxd.Key;
|
||||
import h3d.Vector;
|
||||
import src.ResourceLoader;
|
||||
import net.NetCommands;
|
||||
import net.Net;
|
||||
import src.MarbleGame;
|
||||
|
||||
@:publicFields
|
||||
@:structInit
|
||||
class ChatMessage {
|
||||
var text:String;
|
||||
var age:Float;
|
||||
}
|
||||
|
||||
class ChatCtrl extends GuiControl {
|
||||
var chatHud:GuiMLText;
|
||||
var chatHudBg:GuiMLText;
|
||||
var chatHudInput:GuiTextInput;
|
||||
var chatInputBg:GuiImage;
|
||||
var chatInputBgText:GuiText;
|
||||
var chats:Array<ChatMessage>;
|
||||
var chatFocused:Bool = false;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
|
||||
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 15 * Settings.uiScale, MultiChannel);
|
||||
|
||||
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.addChild(chatHudBg);
|
||||
|
||||
this.chatHud = new GuiMLText(arial14, (s) -> arial14);
|
||||
this.chatHud.position = new Vector(0, 20);
|
||||
this.chatHud.extent = new Vector(200, 250);
|
||||
this.addChild(chatHud);
|
||||
|
||||
this.chatInputBg = new GuiImage(ResourceLoader.getResource('data/ui/exit/black.png', ResourceLoader.getImage, this.imageResources).toTile());
|
||||
this.chatInputBg.position = new Vector(0, 0);
|
||||
this.chatInputBg.extent = new Vector(200, 20);
|
||||
this.addChild(chatInputBg);
|
||||
|
||||
this.chatInputBgText = new GuiText(arial14);
|
||||
this.chatInputBgText.position = new Vector(0, 0);
|
||||
this.chatInputBgText.extent = new Vector(200, 20);
|
||||
this.chatInputBg.addChild(chatInputBgText);
|
||||
this.chatInputBgText.text.textColor = 0xF29515;
|
||||
this.chatInputBgText.text.text = "Chat:";
|
||||
|
||||
this.chatHudInput = new GuiTextInput(arial14);
|
||||
this.chatHudInput.position = new Vector(40, 0);
|
||||
this.chatHudInput.extent = new Vector(160, 20);
|
||||
@:privateAccess this.chatHudInput.text.interactive.forceAnywherefocus = true;
|
||||
this.addChild(chatHudInput);
|
||||
|
||||
this.chatInputBgText.text.visible = false;
|
||||
this.chatInputBg.bmp.visible = false;
|
||||
|
||||
var sendText = "";
|
||||
|
||||
this.chatHudInput.text.onFocus = (e) -> {
|
||||
this.chatInputBgText.text.visible = true;
|
||||
this.chatInputBg.bmp.visible = true;
|
||||
chatFocused = true;
|
||||
}
|
||||
|
||||
this.chatHudInput.text.onFocusLost = (e) -> {
|
||||
this.chatInputBgText.text.visible = false;
|
||||
this.chatInputBg.bmp.visible = false;
|
||||
this.chatHudInput.text.text = "";
|
||||
sendText = "";
|
||||
chatFocused = false;
|
||||
}
|
||||
|
||||
this.chatHudInput.text.onKeyDown = (e) -> {
|
||||
if (e.keyCode == Key.ENTER) {
|
||||
if (StringTools.trim(this.chatHudInput.text.text) != "") {
|
||||
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 = "";
|
||||
this.chatInputBgText.text.visible = false;
|
||||
this.chatInputBg.bmp.visible = false;
|
||||
chatFocused = false;
|
||||
}
|
||||
if (e.keyCode == Key.ESCAPE) {
|
||||
this.chatHudInput.text.text = "";
|
||||
this.chatInputBgText.text.visible = false;
|
||||
this.chatInputBg.bmp.visible = false;
|
||||
chatFocused = false;
|
||||
@:privateAccess Key.keyPressed[Key.ESCAPE] = 0; // consume escape
|
||||
}
|
||||
@:privateAccess Key.keyPressed[e.keyCode] = 0; // consume keys
|
||||
}
|
||||
|
||||
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,
|
||||
age: 10.0
|
||||
});
|
||||
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(dt:Float) {
|
||||
var needsRedraw = false;
|
||||
var chatsToRemove = [];
|
||||
for (chat in this.chats) {
|
||||
chat.age -= dt;
|
||||
if (chat.age < 0) {
|
||||
chatsToRemove.push(chat);
|
||||
}
|
||||
}
|
||||
while (chatsToRemove.length > 0) {
|
||||
this.chats.remove(chatsToRemove[0]);
|
||||
needsRedraw = true;
|
||||
chatsToRemove.shift();
|
||||
}
|
||||
if (needsRedraw) {
|
||||
redrawChatMessages();
|
||||
}
|
||||
}
|
||||
|
||||
public function updateChat(dt:Float) {
|
||||
if (!chatFocused) {
|
||||
if (Key.isPressed(Key.T /*Settings.controlsSettings.chat*/)) {
|
||||
this.chatHudInput.text.focus();
|
||||
}
|
||||
}
|
||||
|
||||
tickChats(dt);
|
||||
}
|
||||
}
|
||||
|
|
@ -96,6 +96,7 @@ class PlayGui {
|
|||
var soundResources:Array<Resource<Sound>> = [];
|
||||
|
||||
var playGuiCtrl:GuiControl;
|
||||
var chatCtrl:ChatCtrl;
|
||||
|
||||
var resizeEv:Void->Void;
|
||||
|
||||
|
|
@ -118,6 +119,11 @@ class PlayGui {
|
|||
playerListScoresCtrl = null;
|
||||
}
|
||||
|
||||
if (chatCtrl != null) {
|
||||
chatCtrl.dispose();
|
||||
chatCtrl = null;
|
||||
}
|
||||
|
||||
gemImageScene.dispose();
|
||||
gemImageSceneTarget.dispose();
|
||||
gemImageSceneTargetBitmap.remove();
|
||||
|
|
@ -192,7 +198,7 @@ class PlayGui {
|
|||
|
||||
if (MarbleGame.instance.world.isMultiplayer) {
|
||||
initPlayerList();
|
||||
// initChatHud();
|
||||
initChatHud();
|
||||
}
|
||||
|
||||
if (Util.isTouchDevice()) {
|
||||
|
|
@ -483,6 +489,22 @@ class PlayGui {
|
|||
playGuiCtrl.addChild(fpsMeterCtrl);
|
||||
}
|
||||
|
||||
public function initChatHud() {
|
||||
this.chatCtrl = new ChatCtrl();
|
||||
this.chatCtrl.position = new Vector(playGuiCtrl.extent.x - 201, 150);
|
||||
this.chatCtrl.extent = new Vector(200, 250);
|
||||
this.chatCtrl.horizSizing = Left;
|
||||
this.playGuiCtrl.addChild(chatCtrl);
|
||||
}
|
||||
|
||||
public inline function isChatFocused() {
|
||||
return this.chatCtrl?.chatFocused;
|
||||
}
|
||||
|
||||
public inline function addChatMessage(str:String) {
|
||||
this.chatCtrl.addChatMessage(str);
|
||||
}
|
||||
|
||||
function initBlastBar() {
|
||||
blastBar = new GuiControl();
|
||||
blastBar.position = new Vector(6, 445);
|
||||
|
|
|
|||
|
|
@ -76,46 +76,46 @@ 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;
|
||||
}
|
||||
if (Key.isDown(Settings.controlsSettings.backward)) {
|
||||
move.d.x += 1;
|
||||
}
|
||||
if (Key.isDown(Settings.controlsSettings.left)) {
|
||||
move.d.y += 1;
|
||||
}
|
||||
if (Key.isDown(Settings.controlsSettings.right)) {
|
||||
move.d.y -= 1;
|
||||
}
|
||||
if (Key.isDown(Settings.controlsSettings.jump)
|
||||
|| MarbleGame.instance.touchInput.jumpButton.pressed
|
||||
|| Gamepad.isDown(Settings.gamepadSettings.jump)) {
|
||||
move.jump = true;
|
||||
}
|
||||
if ((!Util.isTouchDevice() && Key.isDown(Settings.controlsSettings.powerup))
|
||||
|| (Util.isTouchDevice() && MarbleGame.instance.touchInput.powerupButton.pressed)
|
||||
|| Gamepad.isDown(Settings.gamepadSettings.powerup)) {
|
||||
move.powerup = true;
|
||||
}
|
||||
if (@:privateAccess !MarbleGame.instance.world.playGui.isChatFocused()) {
|
||||
if (Key.isDown(Settings.controlsSettings.forward)) {
|
||||
move.d.x -= 1;
|
||||
}
|
||||
if (Key.isDown(Settings.controlsSettings.backward)) {
|
||||
move.d.x += 1;
|
||||
}
|
||||
if (Key.isDown(Settings.controlsSettings.left)) {
|
||||
move.d.y += 1;
|
||||
}
|
||||
if (Key.isDown(Settings.controlsSettings.right)) {
|
||||
move.d.y -= 1;
|
||||
}
|
||||
if (Key.isDown(Settings.controlsSettings.jump)
|
||||
|| MarbleGame.instance.touchInput.jumpButton.pressed
|
||||
|| Gamepad.isDown(Settings.gamepadSettings.jump)) {
|
||||
move.jump = true;
|
||||
}
|
||||
if ((!Util.isTouchDevice() && Key.isDown(Settings.controlsSettings.powerup))
|
||||
|| (Util.isTouchDevice() && MarbleGame.instance.touchInput.powerupButton.pressed)
|
||||
|| Gamepad.isDown(Settings.gamepadSettings.powerup)) {
|
||||
move.powerup = true;
|
||||
}
|
||||
|
||||
if (Key.isDown(Settings.controlsSettings.blast)
|
||||
|| (MarbleGame.instance.touchInput.blastbutton.pressed)
|
||||
|| Gamepad.isDown(Settings.gamepadSettings.blast))
|
||||
move.blast = true;
|
||||
if (Key.isDown(Settings.controlsSettings.blast)
|
||||
|| (MarbleGame.instance.touchInput.blastbutton.pressed)
|
||||
|| Gamepad.isDown(Settings.gamepadSettings.blast))
|
||||
move.blast = true;
|
||||
|
||||
if (Key.isDown(Settings.controlsSettings.respawn) || Gamepad.isDown(Settings.gamepadSettings.respawn)) {
|
||||
move.respawn = true;
|
||||
@:privateAccess Key.keyPressed[Settings.controlsSettings.respawn] = 0;
|
||||
Gamepad.releaseKey(Settings.gamepadSettings.respawn);
|
||||
}
|
||||
if (Key.isDown(Settings.controlsSettings.respawn) || Gamepad.isDown(Settings.gamepadSettings.respawn)) {
|
||||
move.respawn = true;
|
||||
@:privateAccess Key.keyPressed[Settings.controlsSettings.respawn] = 0;
|
||||
Gamepad.releaseKey(Settings.gamepadSettings.respawn);
|
||||
}
|
||||
|
||||
if (MarbleGame.instance.touchInput.movementInput.pressed) {
|
||||
move.d.y = -MarbleGame.instance.touchInput.movementInput.value.x;
|
||||
move.d.x = MarbleGame.instance.touchInput.movementInput.value.y;
|
||||
if (MarbleGame.instance.touchInput.movementInput.pressed) {
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import src.MarbleGame;
|
|||
import src.MissionList;
|
||||
import src.Console;
|
||||
import src.Marbleland;
|
||||
import src.Settings;
|
||||
|
||||
@:build(net.RPCMacro.build())
|
||||
class NetCommands {
|
||||
|
|
@ -187,11 +188,20 @@ class NetCommands {
|
|||
if (MarbleGame.instance.world != null) {
|
||||
var packets = MarbleGame.instance.world.getWorldStateForClientJoin();
|
||||
var c = Net.clientIdMap[clientId];
|
||||
|
||||
for (packet in packets) {
|
||||
c.sendBytes(packet);
|
||||
}
|
||||
Net.clientIdMap[clientId].ready();
|
||||
|
||||
if (Settings.serverSettings.forceSpectators) {
|
||||
Net.clientIdMap[clientId].spectator = true;
|
||||
var b = Net.sendPlayerInfosBytes();
|
||||
for (cc in Net.clients) {
|
||||
cc.sendBytes(b);
|
||||
}
|
||||
}
|
||||
|
||||
if (MarbleGame.instance.world.serverStartTicks == 0) {
|
||||
var allReady = true;
|
||||
for (id => client in Net.clientIdMap) {
|
||||
|
|
@ -419,20 +429,21 @@ class NetCommands {
|
|||
};
|
||||
}
|
||||
|
||||
// @: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);
|
||||
// }
|
||||
// } else {
|
||||
// if (MarbleGame.canvas.content is MultiplayerLevelSelectGui) {
|
||||
// cast(MarbleGame.canvas.content, MultiplayerLevelSelectGui).addChatMessage(msg);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
@: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);
|
||||
}
|
||||
} else {
|
||||
// if (MarbleGame.canvas.content is MultiplayerLevelSelectGui) {
|
||||
// cast(MarbleGame.canvas.content, MultiplayerLevelSelectGui).addChatMessage(msg);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue