mirror of
https://github.com/libretro/ppsspp.git
synced 2024-11-23 16:19:44 +00:00
PPSSPP early chat feature rebranched
This commit is contained in:
parent
5175abe1fd
commit
10e874cefd
@ -55,6 +55,11 @@ std::recursive_mutex peerlock;
|
|||||||
SceNetAdhocPdpStat * pdp[255];
|
SceNetAdhocPdpStat * pdp[255];
|
||||||
SceNetAdhocPtpStat * ptp[255];
|
SceNetAdhocPtpStat * ptp[255];
|
||||||
uint32_t localip;
|
uint32_t localip;
|
||||||
|
std::vector<std::string> chatLog;
|
||||||
|
ChatMenu* ch;
|
||||||
|
std::string name = "";
|
||||||
|
std::string incoming = "";
|
||||||
|
std::string message = "";
|
||||||
|
|
||||||
int isLocalMAC(const SceNetEtherAddr * addr) {
|
int isLocalMAC(const SceNetEtherAddr * addr) {
|
||||||
SceNetEtherAddr saddr;
|
SceNetEtherAddr saddr;
|
||||||
@ -981,6 +986,35 @@ void freeFriendsRecursive(SceNetAdhocctlPeerInfo * node) {
|
|||||||
free(node);
|
free(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setChatPointer(ChatMenu* chatmenu) {
|
||||||
|
//set chatscreen instance
|
||||||
|
ch = chatmenu;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendChat(std::string chatString) {
|
||||||
|
SceNetAdhocctlChatPacketC2S chat;
|
||||||
|
chat.base.opcode = OPCODE_CHAT;
|
||||||
|
//Send Chat Messages need to check network inited and already connected to server or not
|
||||||
|
//if (friendFinderRunning)
|
||||||
|
//{
|
||||||
|
// Send Chat to Server
|
||||||
|
//maximum char allowed is 64 character for compability with original server (pro.coldbird.net)
|
||||||
|
message = chatString.substr(0, 57); // 64 return chat variable corrupted is it out of memory?
|
||||||
|
strcpy(chat.message, message.c_str());
|
||||||
|
NOTICE_LOG(SCENET, "Send %s to Adhoc Server", chat.message);
|
||||||
|
int chatResult = send(metasocket, (const char *)&chat, sizeof(chat), 0);
|
||||||
|
//need to check if send success or not before appending to chat screen
|
||||||
|
name = g_Config.sNickName.c_str();
|
||||||
|
chatLog.push_back(name.substr(0, 8) + ": " + chat.message);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<std::string> getChatLog() {
|
||||||
|
// this log used by chat screen
|
||||||
|
return chatLog;
|
||||||
|
}
|
||||||
|
|
||||||
int friendFinder(){
|
int friendFinder(){
|
||||||
// Receive Buffer
|
// Receive Buffer
|
||||||
int rxpos = 0;
|
int rxpos = 0;
|
||||||
@ -1024,13 +1058,6 @@ int friendFinder(){
|
|||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send Chat Messages
|
|
||||||
//while(popFromOutbox(chat.message))
|
|
||||||
//{
|
|
||||||
// // Send Chat to Server
|
|
||||||
// sceNetInetSend(metasocket, (const char *)&chat, sizeof(chat), 0);
|
|
||||||
//}
|
|
||||||
|
|
||||||
// Wait for Incoming Data
|
// Wait for Incoming Data
|
||||||
int received = recv(metasocket, (char *)(rx + rxpos), sizeof(rx) - rxpos, 0);
|
int received = recv(metasocket, (char *)(rx + rxpos), sizeof(rx) - rxpos, 0);
|
||||||
|
|
||||||
@ -1084,7 +1111,19 @@ int friendFinder(){
|
|||||||
|
|
||||||
// Add Incoming Chat to HUD
|
// Add Incoming Chat to HUD
|
||||||
//printf("Receive chat message %s", packet->base.message);
|
//printf("Receive chat message %s", packet->base.message);
|
||||||
DEBUG_LOG(SCENET, "Received chat message %s", packet->base.message);
|
NOTICE_LOG(SCENET, "Received chat message %s", packet->base.message);
|
||||||
|
incoming = "";
|
||||||
|
name = (char *)packet->name.data;
|
||||||
|
incoming.append(name.substr(0, 8));
|
||||||
|
incoming.append(": ");
|
||||||
|
incoming.append((char *)packet->base.message);
|
||||||
|
chatLog.push_back(incoming);
|
||||||
|
//im new to pointer btw :( doesn't know its safe or not this should update the chat screen when data coming
|
||||||
|
if (ch) {
|
||||||
|
ch->UpdateChat();
|
||||||
|
}
|
||||||
|
// Move RX Buffer
|
||||||
|
memmove(rx, rx + sizeof(SceNetAdhocctlChatPacketS2C), sizeof(rx) - sizeof(SceNetAdhocctlChatPacketS2C));
|
||||||
|
|
||||||
// Move RX Buffer
|
// Move RX Buffer
|
||||||
memmove(rx, rx + sizeof(SceNetAdhocctlChatPacketS2C), sizeof(rx) - sizeof(SceNetAdhocctlChatPacketS2C));
|
memmove(rx, rx + sizeof(SceNetAdhocctlChatPacketS2C), sizeof(rx) - sizeof(SceNetAdhocctlChatPacketS2C));
|
||||||
@ -1107,7 +1146,16 @@ int friendFinder(){
|
|||||||
|
|
||||||
// Add User
|
// Add User
|
||||||
addFriend(packet);
|
addFriend(packet);
|
||||||
|
incoming = "";
|
||||||
|
incoming.append((char *)packet->name.data);
|
||||||
|
incoming.append(" Joined ");
|
||||||
|
//do we need ip?
|
||||||
|
//joined.append((char *)packet->ip);
|
||||||
|
chatLog.push_back(incoming);
|
||||||
|
//im new to pointer btw :( doesn't know its safe or not this should update the chat screen when data coming
|
||||||
|
if (ch) {
|
||||||
|
ch->UpdateChat();
|
||||||
|
}
|
||||||
// Update HUD User Count
|
// Update HUD User Count
|
||||||
#ifdef LOCALHOST_AS_PEER
|
#ifdef LOCALHOST_AS_PEER
|
||||||
setUserCount(getActivePeerCount());
|
setUserCount(getActivePeerCount());
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include "Core/HLE/sceKernel.h"
|
#include "Core/HLE/sceKernel.h"
|
||||||
#include "Core/HLE/sceKernelMutex.h"
|
#include "Core/HLE/sceKernelMutex.h"
|
||||||
#include "Core/HLE/sceUtility.h"
|
#include "Core/HLE/sceUtility.h"
|
||||||
|
#include "UI/ChatScreen.h"
|
||||||
|
|
||||||
class PointerWrap;
|
class PointerWrap;
|
||||||
|
|
||||||
@ -842,6 +843,14 @@ SceNetAdhocMatchingMemberInternal* addMember(SceNetAdhocMatchingContext * contex
|
|||||||
*/
|
*/
|
||||||
void addFriend(SceNetAdhocctlConnectPacketS2C * packet);
|
void addFriend(SceNetAdhocctlConnectPacketS2C * packet);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send chat or get that
|
||||||
|
* @param std::string ChatString
|
||||||
|
*/
|
||||||
|
void setChatPointer(ChatMenu* chatmenu);
|
||||||
|
void sendChat(std::string chatString);
|
||||||
|
std::vector<std::string> getChatLog();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find a Peer/Friend by MAC address
|
* Find a Peer/Friend by MAC address
|
||||||
*/
|
*/
|
||||||
|
124
UI/ChatScreen.cpp
Normal file
124
UI/ChatScreen.cpp
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
#include "ui/ui_context.h"
|
||||||
|
#include "ui/view.h"
|
||||||
|
#include "ui/viewgroup.h"
|
||||||
|
#include "ui/ui.h"
|
||||||
|
#include "ChatScreen.h"
|
||||||
|
#include "Core/Config.h"
|
||||||
|
#include "Core/System.h"
|
||||||
|
#include "Common/LogManager.h"
|
||||||
|
#include "Core/HLE/proAdhoc.h"
|
||||||
|
|
||||||
|
void ChatMenu::CreatePopupContents(UI::ViewGroup *parent) {
|
||||||
|
using namespace UI;
|
||||||
|
//tried to give instance to proAdhoc not working
|
||||||
|
//setChatPointer(this);
|
||||||
|
LinearLayout *outer = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, 400));
|
||||||
|
scroll_ = outer->Add(new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(PopupWidth(), FILL_PARENT, 1.0f)));
|
||||||
|
chatVert_ = scroll_->Add(new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(PopupWidth(), WRAP_CONTENT)));
|
||||||
|
chatVert_->SetSpacing(0);
|
||||||
|
LinearLayout *bottom = outer->Add(new LinearLayout(ORIENT_HORIZONTAL, new LayoutParams(FILL_PARENT, WRAP_CONTENT)));
|
||||||
|
chatEdit_ = bottom->Add(new TextEdit("", "Chat Here", new LinearLayoutParams(1.0)));
|
||||||
|
chatEdit_->OnEnter.Handle(this, &ChatMenu::OnSubmit);
|
||||||
|
bottom->Add(new Button("Send"))->OnClick.Handle(this, &ChatMenu::OnSubmit);
|
||||||
|
parent->Add(outer);
|
||||||
|
UpdateChat();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChatMenu::CreateViews() {
|
||||||
|
using namespace UI;
|
||||||
|
|
||||||
|
UIContext &dc = *screenManager()->getUIContext();
|
||||||
|
|
||||||
|
AnchorLayout *anchor = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));
|
||||||
|
anchor->Overflow(false);
|
||||||
|
root_ = anchor;
|
||||||
|
|
||||||
|
float yres = screenManager()->getUIContext()->GetBounds().h;
|
||||||
|
|
||||||
|
box_ = new LinearLayout(ORIENT_VERTICAL,
|
||||||
|
new AnchorLayoutParams(PopupWidth(), FillVertical() ? yres - 30 : WRAP_CONTENT, 280, NONE, NONE, 250, true));
|
||||||
|
|
||||||
|
root_->Add(box_);
|
||||||
|
box_->SetBG(UI::Drawable(0x66303030));
|
||||||
|
box_->SetHasDropShadow(false);
|
||||||
|
|
||||||
|
View *title = new PopupHeader("Chat");
|
||||||
|
box_->Add(title);
|
||||||
|
|
||||||
|
CreatePopupContents(box_);
|
||||||
|
root_->SetDefaultFocusView(box_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChatMenu::dialogFinished(const Screen *dialog, DialogResult result) {
|
||||||
|
UpdateUIState(UISTATE_INGAME);
|
||||||
|
// Close when a subscreen got closed.
|
||||||
|
// TODO: a bug in screenmanager causes this not to work here.
|
||||||
|
// screenManager()->finishDialog(this, DR_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
UI::EventReturn ChatMenu::OnSubmit(UI::EventParams &e) {
|
||||||
|
std::string chat = chatEdit_->GetText();
|
||||||
|
NOTICE_LOG(HLE, "Chat Send to socket: %s", chat.c_str());
|
||||||
|
chatEdit_->SetText("");
|
||||||
|
chatEdit_->SetFocus();
|
||||||
|
sendChat(chat);
|
||||||
|
UpdateChat();
|
||||||
|
return UI::EVENT_DONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> Split(const std::string& str, int splitLength)
|
||||||
|
{
|
||||||
|
int NumSubstrings = str.length() / splitLength;
|
||||||
|
std::vector<std::string> ret;
|
||||||
|
|
||||||
|
// TODO sub string in white space
|
||||||
|
for (auto i = 0; i < NumSubstrings; i++)
|
||||||
|
{
|
||||||
|
ret.push_back(str.substr(i * splitLength, splitLength));
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there are leftover characters, create a shorter item at the end.
|
||||||
|
if (str.length() % splitLength != 0)
|
||||||
|
{
|
||||||
|
ret.push_back(str.substr(splitLength * NumSubstrings));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChatMenu::UpdateChat() {
|
||||||
|
using namespace UI;
|
||||||
|
if (chatVert_ != NULL) {
|
||||||
|
chatVert_->Clear();
|
||||||
|
std::vector<std::string> chatLog = getChatLog();
|
||||||
|
for (auto i : chatLog) {
|
||||||
|
if (i.length() > 30) {
|
||||||
|
//split long text
|
||||||
|
std::vector<std::string> splitted = Split(i, 32);
|
||||||
|
for (auto j : splitted) {
|
||||||
|
TextView *v = chatVert_->Add(new TextView(j, FLAG_DYNAMIC_ASCII, false, new LayoutParams(PopupWidth(), WRAP_CONTENT)));
|
||||||
|
uint32_t color = 0xFFFFFF;
|
||||||
|
v->SetTextColor(0xFF000000 | color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
TextView *v = chatVert_->Add(new TextView(i, FLAG_DYNAMIC_ASCII, false, new LayoutParams(PopupWidth(), WRAP_CONTENT)));
|
||||||
|
uint32_t color = 0xFFFFFF;
|
||||||
|
v->SetTextColor(0xFF000000 | color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scroll_->ScrollToBottom();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ChatMenu::touch(const TouchInput &touch) {
|
||||||
|
if (!box_ || (touch.flags & TOUCH_DOWN) == 0 || touch.id != 0) {
|
||||||
|
return UIDialogScreen::touch(touch);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!box_->GetBounds().Contains(touch.x, touch.y))
|
||||||
|
screenManager()->finishDialog(this, DR_BACK);
|
||||||
|
|
||||||
|
return UIDialogScreen::touch(touch);
|
||||||
|
}
|
21
UI/ChatScreen.h
Normal file
21
UI/ChatScreen.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "file/file_util.h"
|
||||||
|
#include "ui/ui_screen.h"
|
||||||
|
|
||||||
|
class ChatMenu : public PopupScreen {
|
||||||
|
public:
|
||||||
|
ChatMenu() : PopupScreen("Chat") {}
|
||||||
|
void CreatePopupContents(UI::ViewGroup *parent) override;
|
||||||
|
void CreateViews() override;
|
||||||
|
void dialogFinished(const Screen *dialog, DialogResult result) override;
|
||||||
|
bool touch(const TouchInput &touch) override;
|
||||||
|
void UpdateChat();
|
||||||
|
private:
|
||||||
|
UI::EventReturn OnSubmit(UI::EventParams &e);
|
||||||
|
UI::TextEdit *chatEdit_;
|
||||||
|
UI::ScrollView *scroll_;
|
||||||
|
UI::LinearLayout *chatVert_;
|
||||||
|
UI::ViewGroup *box_;
|
||||||
|
UI::Button *defaultButton_;
|
||||||
|
bool toBottom_;
|
||||||
|
};
|
@ -54,6 +54,7 @@
|
|||||||
#include "Core/SaveState.h"
|
#include "Core/SaveState.h"
|
||||||
#include "Core/MIPS/MIPS.h"
|
#include "Core/MIPS/MIPS.h"
|
||||||
#include "Core/HLE/__sceAudio.h"
|
#include "Core/HLE/__sceAudio.h"
|
||||||
|
#include "Core/HLE/proAdhoc.h"
|
||||||
|
|
||||||
#include "UI/ui_atlas.h"
|
#include "UI/ui_atlas.h"
|
||||||
#include "UI/BackgroundAudio.h"
|
#include "UI/BackgroundAudio.h"
|
||||||
@ -70,6 +71,7 @@
|
|||||||
#include "UI/GameSettingsScreen.h"
|
#include "UI/GameSettingsScreen.h"
|
||||||
#include "UI/InstallZipScreen.h"
|
#include "UI/InstallZipScreen.h"
|
||||||
#include "UI/ProfilerDraw.h"
|
#include "UI/ProfilerDraw.h"
|
||||||
|
#include "UI/ChatScreen.h"
|
||||||
|
|
||||||
#if defined(_WIN32) && !PPSSPP_PLATFORM(UWP)
|
#if defined(_WIN32) && !PPSSPP_PLATFORM(UWP)
|
||||||
#include "Windows/MainWindow.h"
|
#include "Windows/MainWindow.h"
|
||||||
@ -776,6 +778,8 @@ void EmuScreen::CreateViews() {
|
|||||||
if (g_Config.bShowDeveloperMenu) {
|
if (g_Config.bShowDeveloperMenu) {
|
||||||
root_->Add(new Button("DevMenu"))->OnClick.Handle(this, &EmuScreen::OnDevTools);
|
root_->Add(new Button("DevMenu"))->OnClick.Handle(this, &EmuScreen::OnDevTools);
|
||||||
}
|
}
|
||||||
|
// TODO add options in networking menu checkbox enable chat
|
||||||
|
root_->Add(new Button("Chat", new AnchorLayoutParams(50, NONE, NONE, 50, true)))->OnClick.Handle(this, &EmuScreen::OnChat);
|
||||||
saveStatePreview_ = new AsyncImageFileView("", IS_FIXED, nullptr, new AnchorLayoutParams(bounds.centerX(), 100, NONE, NONE, true));
|
saveStatePreview_ = new AsyncImageFileView("", IS_FIXED, nullptr, new AnchorLayoutParams(bounds.centerX(), 100, NONE, NONE, true));
|
||||||
saveStatePreview_->SetFixedSize(160, 90);
|
saveStatePreview_->SetFixedSize(160, 90);
|
||||||
saveStatePreview_->SetColor(0x90FFFFFF);
|
saveStatePreview_->SetColor(0x90FFFFFF);
|
||||||
@ -794,7 +798,16 @@ UI::EventReturn EmuScreen::OnDevTools(UI::EventParams ¶ms) {
|
|||||||
return UI::EVENT_DONE;
|
return UI::EVENT_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UI::EventReturn EmuScreen::OnChat(UI::EventParams ¶ms) {
|
||||||
|
releaseButtons();
|
||||||
|
ChatMenu* ch = new ChatMenu();
|
||||||
|
setChatPointer(ch);
|
||||||
|
screenManager()->push(ch);
|
||||||
|
return UI::EVENT_DONE;
|
||||||
|
}
|
||||||
|
|
||||||
void EmuScreen::update() {
|
void EmuScreen::update() {
|
||||||
|
|
||||||
if (bootPending_)
|
if (bootPending_)
|
||||||
bootGame(gamePath_);
|
bootGame(gamePath_);
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void CreateViews() override;
|
void CreateViews() override;
|
||||||
UI::EventReturn OnDevTools(UI::EventParams ¶ms);
|
UI::EventReturn OnDevTools(UI::EventParams ¶ms);
|
||||||
|
UI::EventReturn OnChat(UI::EventParams ¶ms);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void bootGame(const std::string &filename);
|
void bootGame(const std::string &filename);
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="BackgroundAudio.cpp" />
|
<ClCompile Include="BackgroundAudio.cpp" />
|
||||||
|
<ClCompile Include="ChatScreen.cpp" />
|
||||||
<ClCompile Include="ComboKeyMappingScreen.cpp" />
|
<ClCompile Include="ComboKeyMappingScreen.cpp" />
|
||||||
<ClCompile Include="ControlMappingScreen.cpp" />
|
<ClCompile Include="ControlMappingScreen.cpp" />
|
||||||
<ClCompile Include="CwCheatScreen.cpp" />
|
<ClCompile Include="CwCheatScreen.cpp" />
|
||||||
@ -51,6 +52,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="BackgroundAudio.h" />
|
<ClInclude Include="BackgroundAudio.h" />
|
||||||
|
<ClInclude Include="ChatScreen.h" />
|
||||||
<ClInclude Include="ComboKeyMappingScreen.h" />
|
<ClInclude Include="ComboKeyMappingScreen.h" />
|
||||||
<ClInclude Include="ControlMappingScreen.h" />
|
<ClInclude Include="ControlMappingScreen.h" />
|
||||||
<ClInclude Include="DevScreens.h" />
|
<ClInclude Include="DevScreens.h" />
|
||||||
|
@ -70,6 +70,9 @@
|
|||||||
<Filter>Screens</Filter>
|
<Filter>Screens</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="TextureUtil.cpp" />
|
<ClCompile Include="TextureUtil.cpp" />
|
||||||
|
<ClCompile Include="ChatScreen.cpp">
|
||||||
|
<Filter>Screens</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="GameInfoCache.h" />
|
<ClInclude Include="GameInfoCache.h" />
|
||||||
@ -141,6 +144,9 @@
|
|||||||
<Filter>Screens</Filter>
|
<Filter>Screens</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="TextureUtil.h" />
|
<ClInclude Include="TextureUtil.h" />
|
||||||
|
<ClInclude Include="ChatScreen.h">
|
||||||
|
<Filter>Screens</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Filter Include="Screens">
|
<Filter Include="Screens">
|
||||||
|
Loading…
Reference in New Issue
Block a user