From 18525ea523024f1cf0cc80972b0a8df1408c3733 Mon Sep 17 00:00:00 2001 From: Ade Novan Date: Mon, 24 Oct 2016 01:49:12 +0800 Subject: [PATCH] Android Chat Support --- Core/HLE/proAdhoc.cpp | 7 ++++++- UI/ChatScreen.cpp | 14 ++++++++++++-- UI/ChatScreen.h | 1 - UI/NativeApp.cpp | 3 +++ android/jni/Android.mk | 1 + 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Core/HLE/proAdhoc.cpp b/Core/HLE/proAdhoc.cpp index c8a8459d58..4289bdcc56 100644 --- a/Core/HLE/proAdhoc.cpp +++ b/Core/HLE/proAdhoc.cpp @@ -999,14 +999,19 @@ void sendChat(std::string chatString) { //if (friendFinderRunning) //need to check network inited and already connected to server or not is this correct? //{ // Send Chat to Server + if (!chatString.empty()) { //maximum char allowed is 64 character for compability with original server (pro.coldbird.net) message = chatString.substr(0, 60); // 64 return chat variable corrupted is it out of memory? strcpy(chat.message, message.c_str()); //Send Chat Messages int chatResult = send(metasocket, (const char *)&chat, sizeof(chat), 0); - NOTICE_LOG(SCENET, "Send %s to Adhoc Server", chat.message); + NOTICE_LOG(SCENET, "Send Chat %s to Adhoc Server", chat.message); name = g_Config.sNickName.c_str(); chatLog.push_back(name.substr(0, 8) + ": " + chat.message); + if (ch) { + ch->UpdateChat(); + } + } //} } diff --git a/UI/ChatScreen.cpp b/UI/ChatScreen.cpp index 2264e45e26..d42b4887e9 100644 --- a/UI/ChatScreen.cpp +++ b/UI/ChatScreen.cpp @@ -4,21 +4,28 @@ #include "ui/ui.h" #include "ChatScreen.h" #include "Core/Config.h" +#include "Core/Host.h" #include "Core/System.h" #include "Common/LogManager.h" #include "Core/HLE/proAdhoc.h" #include "i18n/i18n.h" #include + void ChatMenu::CreatePopupContents(UI::ViewGroup *parent) { using namespace UI; I18NCategory *n = GetI18NCategory("Networking"); LinearLayout *outer = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT,400)); scroll_ = outer->Add(new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(1.0))); LinearLayout *bottom = outer->Add(new LinearLayout(ORIENT_HORIZONTAL, new LayoutParams(FILL_PARENT, WRAP_CONTENT))); + +#if defined(_WIN32) || defined(USING_QT_UI) chatEdit_ = bottom->Add(new TextEdit("", n->T("Chat Here"), new LinearLayoutParams(1.0))); chatEdit_->OnEnter.Handle(this, &ChatMenu::OnSubmit); bottom->Add(new Button(n->T("Send")))->OnClick.Handle(this, &ChatMenu::OnSubmit); +#elif defined(__ANDROID__) + bottom->Add(new Button(n->T("Chat Here"),new LayoutParams(FILL_PARENT, WRAP_CONTENT)))->OnClick.Handle(this, &ChatMenu::OnSubmit); +#endif chatVert_ = scroll_->Add(new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT))); chatVert_->SetSpacing(0); parent->Add(outer); @@ -59,12 +66,15 @@ void ChatMenu::dialogFinished(const Screen *dialog, DialogResult result) { } UI::EventReturn ChatMenu::OnSubmit(UI::EventParams &e) { +#if defined(_WIN32) || defined(USING_QT_UI) std::string chat = chatEdit_->GetText(); - NOTICE_LOG(HLE, "Chat Send to socket: %s", chat.c_str()); chatEdit_->SetText(""); chatEdit_->SetFocus(); sendChat(chat); - UpdateChat(); +#elif defined(__ANDROID__) + scroll_->ScrollToBottom(); + System_SendMessage("inputbox", "Chat:"); +#endif return UI::EVENT_DONE; } diff --git a/UI/ChatScreen.h b/UI/ChatScreen.h index 47fb684f13..32ea47c49e 100644 --- a/UI/ChatScreen.h +++ b/UI/ChatScreen.h @@ -18,6 +18,5 @@ private: UI::ScrollView *scroll_; UI::LinearLayout *chatVert_; UI::ViewGroup *box_; - UI::Button *defaultButton_; bool toBottom_; }; \ No newline at end of file diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 0f293b8831..d575301016 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -80,6 +80,7 @@ #include "Core/System.h" #include "Core/HLE/__sceAudio.h" #include "Core/HLE/sceCtrl.h" +#include "Core/HLE/proAdhoc.h" #include "Core/Util/GameManager.h" #include "Core/Util/AudioFormat.h" #include "GPU/GPUInterface.h" @@ -857,6 +858,8 @@ void HandleGlobalMessage(const std::string &msg, const std::string &value) { g_Config.proAdhocServer = setString; if (inputboxValue[0] == "nickname") g_Config.sNickName = setString; + if (inputboxValue[0] == "Chat") + sendChat(setString); inputboxValue.clear(); } if (msg == "bgImage_updated") { diff --git a/android/jni/Android.mk b/android/jni/Android.mk index 58242a4527..5df2ca4326 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -398,6 +398,7 @@ LOCAL_SRC_FILES := \ $(SRC)/android/jni/native_audio.cpp \ $(SRC)/android/jni/native-audio-so.cpp \ $(SRC)/UI/BackgroundAudio.cpp \ + $(SRC)/UI/ChatScreen.cpp\ $(SRC)/UI/DevScreens.cpp \ $(SRC)/UI/DisplayLayoutEditor.cpp \ $(SRC)/UI/DisplayLayoutScreen.cpp \