mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
implement chat (lobby) and fix marble sounds
This commit is contained in:
parent
5220b8909c
commit
41f041f3f9
6 changed files with 116 additions and 20 deletions
|
|
@ -717,14 +717,22 @@ class Marble extends GameObject {
|
||||||
for (contact in contacts) {
|
for (contact in contacts) {
|
||||||
if (contact.force != 0 && !forceObjects.contains(contact.otherObject)) {
|
if (contact.force != 0 && !forceObjects.contains(contact.otherObject)) {
|
||||||
if (contact.otherObject is RoundBumper) {
|
if (contact.otherObject is RoundBumper) {
|
||||||
if (!playedSounds.contains("data/sound/bumperding1.wav")) {
|
if (!playedSounds.contains("data/sound/bumperding1.wav") && !this.isNetUpdate) {
|
||||||
AudioManager.playSound(ResourceLoader.getResource("data/sound/bumperding1.wav", ResourceLoader.getAudio, this.soundResources));
|
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");
|
playedSounds.push("data/sound/bumperding1.wav");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (contact.otherObject is TriangleBumper) {
|
if (contact.otherObject is TriangleBumper) {
|
||||||
if (!playedSounds.contains("data/sound/bumper1.wav")) {
|
if (!playedSounds.contains("data/sound/bumper1.wav") && !this.isNetUpdate) {
|
||||||
AudioManager.playSound(ResourceLoader.getResource("data/sound/bumper1.wav", ResourceLoader.getAudio, this.soundResources));
|
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");
|
playedSounds.push("data/sound/bumper1.wav");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1099,17 +1107,20 @@ class Marble extends GameObject {
|
||||||
if (minVelocityBounceSoft <= contactVel) {
|
if (minVelocityBounceSoft <= contactVel) {
|
||||||
var hardBounceSpeed = minVelocityBounceHard;
|
var hardBounceSpeed = minVelocityBounceHard;
|
||||||
var bounceSoundNum = Math.floor(Math.random() * 4);
|
var bounceSoundNum = Math.floor(Math.random() * 4);
|
||||||
var sndList = (time - this.megaMarbleEnableTime < 10) ? [
|
var sndList = ((time - this.megaMarbleEnableTime < 10)
|
||||||
"data/sound/mega_bouncehard1.wav",
|
|| (this.megaMarbleUseTick > 0
|
||||||
"data/sound/mega_bouncehard2.wav",
|
&& ((Net.isHost && (this.level.timeState.ticks - this.megaMarbleUseTick) <= 312)
|
||||||
"data/sound/mega_bouncehard3.wav",
|
|| (Net.isClient && (this.serverTicks - this.megaMarbleUseTick) <= 312)))) ? [
|
||||||
"data/sound/mega_bouncehard4.wav"
|
"data/sound/mega_bouncehard1.wav",
|
||||||
] : [
|
"data/sound/mega_bouncehard2.wav",
|
||||||
"data/sound/bouncehard1.wav",
|
"data/sound/mega_bouncehard3.wav",
|
||||||
"data/sound/bouncehard2.wav",
|
"data/sound/mega_bouncehard4.wav"
|
||||||
"data/sound/bouncehard3.wav",
|
] : [
|
||||||
"data/sound/bouncehard4.wav"
|
"data/sound/bouncehard1.wav",
|
||||||
];
|
"data/sound/bouncehard2.wav",
|
||||||
|
"data/sound/bouncehard3.wav",
|
||||||
|
"data/sound/bouncehard4.wav"
|
||||||
|
];
|
||||||
|
|
||||||
var snd = ResourceLoader.getResource(sndList[bounceSoundNum], ResourceLoader.getAudio, this.soundResources);
|
var snd = ResourceLoader.getResource(sndList[bounceSoundNum], ResourceLoader.getAudio, this.soundResources);
|
||||||
var gain = bounceMinGain;
|
var gain = bounceMinGain;
|
||||||
|
|
@ -1120,7 +1131,10 @@ class Marble extends GameObject {
|
||||||
// else
|
// else
|
||||||
// gain = (contactVel - minVelocityBounceSoft) / (hardBounceSpeed - minVelocityBounceSoft) * (1.0 - gain) + gain;
|
// gain = (contactVel - minVelocityBounceSoft) / (hardBounceSpeed - minVelocityBounceSoft) * (1.0 - gain) + gain;
|
||||||
|
|
||||||
snd.play(false, Settings.optionsSettings.soundVolume * 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)
|
if (slipVolume < 0)
|
||||||
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) {
|
if (this.rollMegaSound != null) {
|
||||||
rollMegaSound.volume = rollVolume;
|
rollMegaSound.volume = rollVolume;
|
||||||
rollSound.volume = 0;
|
rollSound.volume = 0;
|
||||||
|
|
@ -2378,7 +2395,7 @@ class Marble extends GameObject {
|
||||||
var blastAmt = this.blastTicks / (25000 >> 5);
|
var blastAmt = this.blastTicks / (25000 >> 5);
|
||||||
var impulse = this.currentUp.multiply(Math.max(Math.sqrt(blastAmt), blastAmt) * 10);
|
var impulse = this.currentUp.multiply(Math.max(Math.sqrt(blastAmt), blastAmt) * 10);
|
||||||
this.applyImpulse(impulse);
|
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));
|
AudioManager.playSound(ResourceLoader.getResource('data/sound/blast.wav', ResourceLoader.getAudio, this.soundResources));
|
||||||
if (!isNetUpdate)
|
if (!isNetUpdate)
|
||||||
this.level.particleManager.createEmitter(blastAmt > 1 ? blastMaxParticleOptions : blastParticleOptions,
|
this.level.particleManager.createEmitter(blastAmt > 1 ? blastMaxParticleOptions : blastParticleOptions,
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ class ChatCtrl extends GuiControl {
|
||||||
this.chatHudInput.text.onKeyDown = (e) -> {
|
this.chatHudInput.text.onKeyDown = (e) -> {
|
||||||
if (e.keyCode == Key.ENTER) {
|
if (e.keyCode == Key.ENTER) {
|
||||||
if (StringTools.trim(this.chatHudInput.text.text) != "") {
|
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) {
|
if (Net.isClient) {
|
||||||
NetCommands.sendChatMessage(StringTools.htmlEscape(sendText));
|
NetCommands.sendChatMessage(StringTools.htmlEscape(sendText));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ class GuiScrollCtrl extends GuiControl {
|
||||||
public var enabled:Bool = true;
|
public var enabled:Bool = true;
|
||||||
public var childrenHandleScroll:Bool = false;
|
public var childrenHandleScroll:Bool = false;
|
||||||
public var scrollSpeed = 500;
|
public var scrollSpeed = 500;
|
||||||
|
public var scrollToBottom:Bool = false;
|
||||||
|
|
||||||
var maxScrollY:Float;
|
var maxScrollY:Float;
|
||||||
|
|
||||||
|
|
@ -96,7 +97,13 @@ class GuiScrollCtrl extends GuiControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setScrollMax(max:Float) {
|
public function setScrollMax(max:Float) {
|
||||||
this.scrollY = 0;
|
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.maxScrollY = max;
|
||||||
this.dirty = true;
|
this.dirty = true;
|
||||||
this.updateScrollVisual();
|
this.updateScrollVisual();
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ class MPPlayMissionGui extends GuiImage {
|
||||||
static var currentSelectionStatic:Int = -1;
|
static var currentSelectionStatic:Int = -1;
|
||||||
static var currentCategoryStatic:String = "beginner";
|
static var currentCategoryStatic:String = "beginner";
|
||||||
|
|
||||||
|
public static var allChats:Array<String> = [];
|
||||||
|
|
||||||
static var setLevelFn:(String, Int) -> Void;
|
static var setLevelFn:(String, Int) -> Void;
|
||||||
static var playSelectedLevel:(String, Int) -> Void;
|
static var playSelectedLevel:(String, Int) -> Void;
|
||||||
static var setLevelStr:String->Void;
|
static var setLevelStr:String->Void;
|
||||||
|
|
@ -47,6 +49,9 @@ class MPPlayMissionGui extends GuiImage {
|
||||||
#end
|
#end
|
||||||
|
|
||||||
var playerListCtrl:GuiTextListCtrl;
|
var playerListCtrl:GuiTextListCtrl;
|
||||||
|
var chatInput:GuiTextInput;
|
||||||
|
var chatScroll:GuiScrollCtrl;
|
||||||
|
var chatBox:GuiMLText;
|
||||||
|
|
||||||
public function new(isHost:Bool = true) {
|
public function new(isHost:Bool = true) {
|
||||||
MissionList.buildMissionList();
|
MissionList.buildMissionList();
|
||||||
|
|
@ -362,6 +367,50 @@ class MPPlayMissionGui extends GuiImage {
|
||||||
};
|
};
|
||||||
playersBox.addChild(playerListTitle);
|
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);
|
this.addChild(window);
|
||||||
|
|
||||||
buttonHoldFunc = (dt:Float, mouseState:MouseState) -> {
|
buttonHoldFunc = (dt:Float, mouseState:MouseState) -> {
|
||||||
|
|
@ -570,6 +619,7 @@ class MPPlayMissionGui extends GuiImage {
|
||||||
|
|
||||||
setCategoryFunc(currentCategoryStatic, null, false);
|
setCategoryFunc(currentCategoryStatic, null, false);
|
||||||
updateLobbyNames();
|
updateLobbyNames();
|
||||||
|
redrawChat();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override function render(scene2d:Scene, ?parent:h2d.Flow) {
|
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}';
|
// 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -379,6 +379,7 @@ class Net {
|
||||||
Net.hostReady = false;
|
Net.hostReady = false;
|
||||||
Net.hostSpectate = false;
|
Net.hostSpectate = false;
|
||||||
Net.clientSpectate = false;
|
Net.clientSpectate = false;
|
||||||
|
MPPlayMissionGui.allChats = [];
|
||||||
// MultiplayerLevelSelectGui.custSelected = false;
|
// MultiplayerLevelSelectGui.custSelected = false;
|
||||||
}
|
}
|
||||||
if (Net.isHost) {
|
if (Net.isHost) {
|
||||||
|
|
@ -402,6 +403,7 @@ class Net {
|
||||||
Net.hostReady = false;
|
Net.hostReady = false;
|
||||||
Net.hostSpectate = false;
|
Net.hostSpectate = false;
|
||||||
Net.clientSpectate = false;
|
Net.clientSpectate = false;
|
||||||
|
MPPlayMissionGui.allChats = [];
|
||||||
// MultiplayerLevelSelectGui.custSelected = false;
|
// MultiplayerLevelSelectGui.custSelected = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -445,5 +445,6 @@ class NetCommands {
|
||||||
// cast(MarbleGame.canvas.content, MultiplayerLevelSelectGui).addChatMessage(msg);
|
// cast(MarbleGame.canvas.content, MultiplayerLevelSelectGui).addChatMessage(msg);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
MPPlayMissionGui.addChatMessage(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue