Skip to content

Commit

Permalink
add discord image support in invites, powered by HTTPObject and VFS
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomityGuy committed Mar 5, 2024
1 parent dd7fbb9 commit 048af91
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 15 deletions.
11 changes: 5 additions & 6 deletions engine/source/game/net/httpObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "core/fileStream.h"
#include "console/simBase.h"
#include "console/consoleInternal.h"
#include "core/resManager.h"
#include <string.h>

IMPLEMENT_CONOBJECT(HTTPObject);
Expand Down Expand Up @@ -201,20 +202,18 @@ void HTTPObject::processLines()
}

//Write to the output file
FileStream *stream = new FileStream();
Stream* stream;

if (!stream->open(path, FileStream::Write)) {
Con::errorf("Could not download %s: error opening stream.");
if (!ResourceManager->openFileForWrite(stream, path, FileStream::Write)) {
Con::errorf("Could not download %s: error opening stream.", path);
onDownloadFailed(path);
return;
}

stream->write(mBufferUsed, mBuffer);
stream->close();
ResourceManager->closeStream(stream);

onDownload(path);

delete stream;
} else {

//Pull all the lines out of mBuffer
Expand Down
83 changes: 74 additions & 9 deletions game/marble/client/ui/JoinGameInviteDlg.gui
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,47 @@ new GuiControl(JoinGameInviteDlg) {
horizSizing = "center";
vertSizing = "top";
position = "0 350";
extent = "507 116";
extent = "627 136";
//minExtent = "48 92";
visible = "1";
icon = "";
wrap = "0";

new GuiBitmapCtrl(JoinGameInviteFrameAvatar) {
profile = "GuiDefaultProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "75 35";
extent = "64 64";
minExtent = "8 2";
visible = "1";
bitmap = "./xbox/demoLock";
wrap = "0";
};

new GuiBitmapCtrl(JoinGameInviteFrameAvatarMask) {
profile = "GuiDefaultProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "75 35";
extent = "64 64";
minExtent = "8 2";
visible = "1";
bitmap = "./xbox/circlemask";
wrap = "0";
};

new GuiTextCtrl(JoinGameInviteTitle)
{
profile = JoinGameInviteDlgProfile;
horizSizing = "right";
vertSizing = "bottom";
position = "80 39";
extent = "500 80";
minExtent = "8 8";
visible = "1";
text = "GUI TITLE GOES HERE";
};
};

};
Expand All @@ -28,10 +64,6 @@ function JoinGameInviteDlg::onWake(%this)
{
enableGamepad();
moveMap.push();
//AchievementFrame.setPosition("70", "0");
AchievementFrame.setHeader($Text::AchievementUnlocked);
AchievementFrame.setIcon("./achievement/" @ $AchievementId);
AchievementFrame.setTitle(%title);
}

function JoinGameInviteDlg::show(%userId, %username, %avatar)
Expand All @@ -40,25 +72,28 @@ function JoinGameInviteDlg::show(%userId, %username, %avatar)
Canvas.pushDialog(JoinGameInviteDlg);
JoinGameInviteDlg.isShowing = true;
}
serverplay2d(HelpDingSfx);
JoinGameInviteDlg.responded = false;
JoinGameInviteDlg.userId = %userId;
JoinGameInviteDlg.username = %username;
JoinGameInviteDlg.animState = 0;
JoinGameInviteFrame.setHeader("Join Request");
JoinGameInviteFrame.setTitle(%username SPC "wants to join");
JoinGameInviteTitle.setText(%username SPC "wants to join");
cancel(JoinGameInviteDlg.closeSchedule);
JoinGameInviteDlg.closeSchedule = JoinGameInviteDlg.schedule(5000, "close");
cancel(JoinGameInviteDlg.animSchedule);
JoinGameInviteDlg.animSchedule = JoinGameInviteDlg.schedule(1000, "animate");
JoinGameInviteDlg.dlToken++;
downloadAvatar(%userId, %avatar, JoinGameInviteDlg.dlToken);
}

function JoinGameInviteDlg::animate(%this)
{
%this.animState = !%this.animState;
if (%this.animState)
JoinGameInviteFrame.setTitle("Press Y to accept");
JoinGameInviteTitle.setText("Press Y to accept");
else
JoinGameInviteFrame.setTitle(%this.username SPC "wants to join");
JoinGameInviteTitle.setText(%this.username SPC "wants to join");
%this.animSchedule = %this.schedule(1000, "animate");
}

Expand All @@ -67,7 +102,7 @@ function JoinGameInviteDlg::onY(%this)
if (%this.responded) return;
%this.responded = true;
XBLiveRespondJoinRequest(%this.userId, 1);
JoinGameInviteFrame.setTitle("Accepted join request");
JoinGameInviteTitle.setText("Accepted join request");
cancel(%this.animSchedule);
cancel(%this.closeSchedule);
%this.closeSchedule = %this.schedule(2000, "close");
Expand All @@ -78,4 +113,34 @@ function JoinGameInviteDlg::close(%this)
cancel(%this.animSchedule);
Canvas.popDialog(%this);
%this.isShowing = false;
}

function downloadAvatar(%userId, %avatarHash, %token)
{
JoinGameInviteFrameAvatar.setBitmap("");
%baseURL = "https://cdn.discordapp.com";
%basePath = %userId @ %avatarHash @ ".png";
%downloadPath = "/avatars/" @ %userId @ "/" @ %avatarHash @ ".png";
if (isObject(DiscordAvatarDownload))
DiscordAvatarDownload.delete(); // Stop
new HTTPObject(DiscordAvatarDownload);
DiscordAvatarDownload.setDownloadPath("mem/" @ %basePath);
DiscordAvatarDownload.token = %token;
DiscordAvatarDownload.get(%baseURL, %downloadPath, "size=64");
}

function DiscordAvatarDownload::onDownload(%this, %path)
{
if (%this.token == JoinGameInviteDlg.dlToken)
JoinGameInviteFrameAvatar.setBitmap(%path);
}

function DiscordAvatarDownload::downloadFailed(%this, %path)
{
%this.delete();
}

function DiscordAvatarDownload::onDisconnect(%this)
{
%this.delete();
}
8 changes: 8 additions & 0 deletions game/marble/client/ui/defaultGameProfiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,11 @@
fontSize2 = 28;
justify = center;
};

new GuiControlProfile("JoinGameInviteDlgProfile")
{
fontType = "Arial Bold";
fontColor = "16 16 16";
fontSize = 24;
justify = center;
};
Binary file added game/marble/client/ui/xbox/circlemask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 048af91

Please sign in to comment.