implement chat (lobby) and fix marble sounds

This commit is contained in:
RandomityGuy 2024-07-03 00:36:08 +05:30
parent 5220b8909c
commit 41f041f3f9
6 changed files with 116 additions and 20 deletions

View file

@ -717,14 +717,22 @@ class Marble extends GameObject {
for (contact in contacts) {
if (contact.force != 0 && !forceObjects.contains(contact.otherObject)) {
if (contact.otherObject is RoundBumper) {
if (!playedSounds.contains("data/sound/bumperding1.wav")) {
if (!playedSounds.contains("data/sound/bumperding1.wav") && !this.isNetUpdate) {
if (level.marble == cast this)
AudioManager.playSound(ResourceLoader.getResource("data/sound/bumperding1.wav", ResourceLoader.getAudio, this.soundResources));
else
AudioManager.playSound(ResourceLoader.getResource("data/sound/bumperding1.wav", ResourceLoader.getAudio, this.soundResources),
this.getAbsPos().getPosition());
playedSounds.push("data/sound/bumperding1.wav");
}
}
if (contact.otherObject is TriangleBumper) {
if (!playedSounds.contains("data/sound/bumper1.wav")) {
if (!playedSounds.contains("data/sound/bumper1.wav") && !this.isNetUpdate) {
if (level.marble == cast this)
AudioManager.playSound(ResourceLoader.getResource("data/sound/bumper1.wav", ResourceLoader.getAudio, this.soundResources));
else
AudioManager.playSound(ResourceLoader.getResource("data/sound/bumper1.wav", ResourceLoader.getAudio, this.soundResources),
this.getAbsPos().getPosition());
playedSounds.push("data/sound/bumper1.wav");
}
}
@ -1099,7 +1107,10 @@ class Marble extends GameObject {
if (minVelocityBounceSoft <= contactVel) {
var hardBounceSpeed = minVelocityBounceHard;
var bounceSoundNum = Math.floor(Math.random() * 4);
var sndList = (time - this.megaMarbleEnableTime < 10) ? [
var sndList = ((time - this.megaMarbleEnableTime < 10)
|| (this.megaMarbleUseTick > 0
&& ((Net.isHost && (this.level.timeState.ticks - this.megaMarbleUseTick) <= 312)
|| (Net.isClient && (this.serverTicks - this.megaMarbleUseTick) <= 312)))) ? [
"data/sound/mega_bouncehard1.wav",
"data/sound/mega_bouncehard2.wav",
"data/sound/mega_bouncehard3.wav",
@ -1120,6 +1131,9 @@ class Marble extends GameObject {
// else
// gain = (contactVel - minVelocityBounceSoft) / (hardBounceSpeed - minVelocityBounceSoft) * (1.0 - gain) + gain;
if (!this.controllable)
AudioManager.playSound(snd, this.getAbsPos().getPosition());
else
snd.play(false, Settings.optionsSettings.soundVolume * gain);
}
}
@ -1159,7 +1173,10 @@ class Marble extends GameObject {
if (slipVolume < 0)
slipVolume = 0;
if (time.currentAttemptTime - this.megaMarbleEnableTime < 10) {
if (time.currentAttemptTime - this.megaMarbleEnableTime < 10
|| (this.megaMarbleUseTick > 0
&& ((Net.isHost && (this.level.timeState.ticks - this.megaMarbleUseTick) <= 312)
|| (Net.isClient && (this.serverTicks - this.megaMarbleUseTick) <= 312)))) {
if (this.rollMegaSound != null) {
rollMegaSound.volume = rollVolume;
rollSound.volume = 0;
@ -2378,7 +2395,7 @@ class Marble extends GameObject {
var blastAmt = this.blastTicks / (25000 >> 5);
var impulse = this.currentUp.multiply(Math.max(Math.sqrt(blastAmt), blastAmt) * 10);
this.applyImpulse(impulse);
if (!isNetUpdate && level.marble == cast this)
if (!isNetUpdate && this.controllable)
AudioManager.playSound(ResourceLoader.getResource('data/sound/blast.wav', ResourceLoader.getAudio, this.soundResources));
if (!isNetUpdate)
this.level.particleManager.createEmitter(blastAmt > 1 ? blastMaxParticleOptions : blastParticleOptions,

View file

@ -87,7 +87,7 @@ class ChatCtrl extends GuiControl {
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))}';
sendText = '<font color="#F29515">${StringTools.htmlEscape(Settings.highscoreName.substr(0, 20))}:</font> ${StringTools.htmlEscape(this.chatHudInput.text.text.substr(0, 150))}';
if (Net.isClient) {
NetCommands.sendChatMessage(StringTools.htmlEscape(sendText));
}

View file

@ -16,6 +16,7 @@ class GuiScrollCtrl extends GuiControl {
public var enabled:Bool = true;
public var childrenHandleScroll:Bool = false;
public var scrollSpeed = 500;
public var scrollToBottom:Bool = false;
var maxScrollY:Float;
@ -96,7 +97,13 @@ class GuiScrollCtrl extends GuiControl {
}
public function setScrollMax(max:Float) {
var renderRect = this.getRenderRectangle();
if (scrollToBottom) {
var scrollBarYSize = renderRect.extent.y * renderRect.extent.y / (max * Settings.uiScale);
this.scrollY = renderRect.extent.y - scrollBarYSize * Settings.uiScale;
} else {
this.scrollY = 0;
}
this.maxScrollY = max;
this.dirty = true;
this.updateScrollVisual();

View file

@ -24,6 +24,8 @@ class MPPlayMissionGui extends GuiImage {
static var currentSelectionStatic:Int = -1;
static var currentCategoryStatic:String = "beginner";
public static var allChats:Array<String> = [];
static var setLevelFn:(String, Int) -> Void;
static var playSelectedLevel:(String, Int) -> Void;
static var setLevelStr:String->Void;
@ -47,6 +49,9 @@ class MPPlayMissionGui extends GuiImage {
#end
var playerListCtrl:GuiTextListCtrl;
var chatInput:GuiTextInput;
var chatScroll:GuiScrollCtrl;
var chatBox:GuiMLText;
public function new(isHost:Bool = true) {
MissionList.buildMissionList();
@ -362,6 +367,50 @@ class MPPlayMissionGui extends GuiImage {
};
playersBox.addChild(playerListTitle);
chatScroll = new GuiScrollCtrl(ResourceLoader.getResource("data/ui/common/philscroll.png", ResourceLoader.getImage, this.imageResources).toTile());
chatScroll.position = new Vector(47, 282);
chatScroll.extent = new Vector(407, 193);
chatScroll.childrenHandleScroll = true;
chatScroll.scrollToBottom = true;
window.addChild(chatScroll);
chatBox = new GuiMLText(markerFelt18, mlFontLoader);
chatBox.text.textColor = 0x000000;
chatBox.horizSizing = Width;
chatBox.position = new Vector(0, 0);
chatBox.extent = new Vector(396, 1184);
chatScroll.addChild(chatBox);
var chatInputContainer = new GuiControl();
chatInputContainer.position = new Vector(50, 476);
chatInputContainer.extent = new Vector(402, 30);
window.addChild(chatInputContainer);
chatInput = new GuiTextInput(markerFelt18);
chatInput.text.textColor = 0x000000;
chatInput.horizSizing = Width;
chatInput.position = new Vector(0, 0);
chatInput.extent = new Vector(402, 30);
chatInputContainer.addChild(chatInput);
@:privateAccess chatInput.text.interactive.forceAnywherefocus = true;
chatInput.text.onKeyDown = (e) -> {
if (e.keyCode == Key.ENTER) {
if (StringTools.trim(chatInput.text.text) != "") {
var sendText = '<font color="#F29515">${StringTools.htmlEscape(Settings.highscoreName.substr(0, 20))}:</font> ${StringTools.htmlEscape(chatInput.text.text.substr(0, 100))}';
if (Net.isClient) {
NetCommands.sendChatMessage(StringTools.htmlEscape(sendText));
}
if (Net.isHost) {
NetCommands.sendServerChatMessage(StringTools.htmlEscape(sendText));
}
}
chatInput.text.text = "";
haxe.Timer.delay(() -> chatInput.text.focus(), 10);
}
@:privateAccess Key.keyPressed[e.keyCode] = 0; // consume keys
}
this.addChild(window);
buttonHoldFunc = (dt:Float, mouseState:MouseState) -> {
@ -570,6 +619,7 @@ class MPPlayMissionGui extends GuiImage {
setCategoryFunc(currentCategoryStatic, null, false);
updateLobbyNames();
redrawChat();
}
public override function render(scene2d:Scene, ?parent:h2d.Flow) {
@ -629,4 +679,23 @@ class MPPlayMissionGui extends GuiImage {
// return '<img src="${player.state ? "ready" : "notready"}"></img><img src="${platformToString(player.platform)}"></img>${player.name}';
// }));
}
public static function addChatMessage(s:String) {
var realText = StringTools.htmlUnescape(s);
allChats.push(realText);
if (allChats.length > 100) {
allChats = allChats.slice(allChats.length - 100);
}
if (MarbleGame.canvas.content is MPPlayMissionGui) {
var mpp = cast(MarbleGame.canvas.content, MPPlayMissionGui);
mpp.redrawChat();
}
}
public function redrawChat() {
var joined = allChats.join("<br/>");
this.chatBox.text.text = StringTools.replace(joined, '#F29515', '#000000');
this.chatScroll.setScrollMax(chatBox.text.textHeight);
this.chatScroll.updateScrollVisual();
}
}

View file

@ -379,6 +379,7 @@ class Net {
Net.hostReady = false;
Net.hostSpectate = false;
Net.clientSpectate = false;
MPPlayMissionGui.allChats = [];
// MultiplayerLevelSelectGui.custSelected = false;
}
if (Net.isHost) {
@ -402,6 +403,7 @@ class Net {
Net.hostReady = false;
Net.hostSpectate = false;
Net.clientSpectate = false;
MPPlayMissionGui.allChats = [];
// MultiplayerLevelSelectGui.custSelected = false;
}
}

View file

@ -445,5 +445,6 @@ class NetCommands {
// cast(MarbleGame.canvas.content, MultiplayerLevelSelectGui).addChatMessage(msg);
// }
}
MPPlayMissionGui.addChatMessage(msg);
}
}