GUI
This commit is contained in:
parent
b3d06906ff
commit
b0d5226915
7 changed files with 317 additions and 52 deletions
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
#include "NewPlacement.hpp"
|
||||
|
||||
#include "Chat.hpp"
|
||||
|
||||
#include "Graphics.hpp"
|
||||
|
|
@ -14,5 +16,36 @@ bool ChatAPI::isLogged() const {
|
|||
}
|
||||
|
||||
void ChatAPI::login(const Credentials& credentials) {
|
||||
mLogged = String::Logic::isEqualLogic(credentials.name, "111");
|
||||
}
|
||||
mLogged = String::Logic::isEqualLogic(credentials.pass, "1812") && String::Logic::isEqualLogic(credentials.name, "Igor");
|
||||
mChatsList = { "Serg", "Friends" };
|
||||
mChatHistories.put("Serg", { { "Serg", "Hello wanna some coke-cola?" }, { "Serg", "Will be in 5 mins" } });
|
||||
mChatHistories.put("Friends", { { "Artem", "Whos is that Serg?" }, { "Erog", "idunno" } });
|
||||
}
|
||||
|
||||
void ChatAPI::logout() {
|
||||
mLogged = false;
|
||||
mChatsList.removeAll();
|
||||
mChatHistories.removeAll();
|
||||
}
|
||||
|
||||
const ChatAPI::ChatsList* ChatAPI::getChatsList() const {
|
||||
return mLogged ? &mChatsList : nullptr;
|
||||
}
|
||||
|
||||
const ChatAPI::ChatHistory* ChatAPI::getChatHistory(const String& chatName) const {
|
||||
if (!mLogged) return nullptr;
|
||||
|
||||
auto history = mChatHistories.presents(chatName);
|
||||
return history ? &mChatHistories.getSlotVal(history) : nullptr;
|
||||
}
|
||||
|
||||
void ChatAPI::send(const String& chatName, const Message& message) {
|
||||
if (!mLogged) return;
|
||||
|
||||
auto iter = mChatHistories.presents(chatName);
|
||||
auto history = iter ? &mChatHistories.getSlotVal(iter) : nullptr;
|
||||
|
||||
if (!history) return;
|
||||
|
||||
history->pushBack(message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,46 +1,89 @@
|
|||
|
||||
#include "ClientGui.hpp"
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h"
|
||||
|
||||
using namespace tp;
|
||||
using namespace ImGui;
|
||||
|
||||
void ClientGUI::draw(ChatAPI& api) {
|
||||
DockSpaceOverViewport(GetWindowViewport());
|
||||
|
||||
if (Begin("window_name")) {
|
||||
if (api.isLogged()) {
|
||||
drawChat(api);
|
||||
|
||||
if (api.isLogged()) {
|
||||
} else {
|
||||
if (Begin("Authentication")) {
|
||||
InputText("Name", mCredentials.name, ChatAPI::Credentials::SIZE);
|
||||
InputText("Pass", mCredentials.pass, ChatAPI::Credentials::SIZE);
|
||||
|
||||
static int item_current1 = 0;
|
||||
const char *items1[] = {"Never", "Gonna", "Give", "You", "Up"};
|
||||
Combo("User", &item_current1, items1, IM_ARRAYSIZE(items1));
|
||||
if (mInvalidCredentials) {
|
||||
Text("Invalid Credentials");
|
||||
}
|
||||
|
||||
BeginListBox("History");
|
||||
Text("as");
|
||||
Text("asa");
|
||||
EndListBox();
|
||||
if (Button("Login")) {
|
||||
api.login(mCredentials);
|
||||
mInvalidCredentials = !api.isLogged();
|
||||
}
|
||||
}
|
||||
End();
|
||||
}
|
||||
}
|
||||
|
||||
static char buff[1000];
|
||||
InputTextMultiline("Message", buff, 1000);
|
||||
void ClientGUI::drawChat(tp::ChatAPI& api) {
|
||||
if (Begin("Chats")) {
|
||||
if (Button("Logout", {GetContentRegionAvail().x, 0})) {
|
||||
api.logout();
|
||||
mCredentials.pass[0] = 0;
|
||||
mActiveChatName = "Not Selected";
|
||||
}
|
||||
|
||||
if (Button("Send")) {
|
||||
if (BeginListBox("##chats", GetContentRegionAvail())) {
|
||||
auto chats = api.getChatsList();
|
||||
if (chats) {
|
||||
for (auto user : *chats) {
|
||||
if (Selectable(user->read())) {
|
||||
mActiveChatName = user.data();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Text("Error");
|
||||
}
|
||||
|
||||
}
|
||||
EndListBox();
|
||||
}
|
||||
}
|
||||
End();
|
||||
|
||||
} else {
|
||||
if (Begin("History")) {
|
||||
Text("%s", mActiveChatName.read());
|
||||
|
||||
InputText("Name", mCredentials.name, ChatAPI::Credentials::SIZE);
|
||||
InputText("Pass", mCredentials.pass, ChatAPI::Credentials::SIZE);
|
||||
auto history = api.getChatHistory(mActiveChatName);
|
||||
|
||||
if (mInvalidCredentials) {
|
||||
Text("Invalid Credentials");
|
||||
}
|
||||
if (history) {
|
||||
if (BeginListBox("##History", GetContentRegionAvail())) {
|
||||
for (auto message : *history) {
|
||||
Text("%s : %s", message->user.read(), message->text.read());
|
||||
Separator();
|
||||
}
|
||||
}
|
||||
|
||||
if (Button("Login")) {
|
||||
api.login(mCredentials);
|
||||
mInvalidCredentials = !api.isLogged();
|
||||
}
|
||||
}
|
||||
EndListBox();
|
||||
} else {
|
||||
Text("No History");
|
||||
}
|
||||
}
|
||||
End();
|
||||
|
||||
} End();
|
||||
}
|
||||
if (Begin("Message")) {
|
||||
if (Button("Send")) {
|
||||
if (String::Logic::calcLength(mMessageBuff) > 0) {
|
||||
api.send(mActiveChatName, {mCredentials.name, mMessageBuff});
|
||||
}
|
||||
mMessageBuff[0] = 0;
|
||||
}
|
||||
|
||||
InputTextMultiline("##Message", mMessageBuff, MESSAGE_SIZE, GetContentRegionAvail());
|
||||
}
|
||||
End();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue