| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- /*
- * GlobalLobbyWidget.cpp, part of VCMI engine
- *
- * Authors: listed in file AUTHORS in main folder
- *
- * License: GNU General Public License v2.0 or later
- * Full text of license available in license.txt file, in main folder
- *
- */
- #include "StdInc.h"
- #include "GlobalLobbyWidget.h"
- #include "GlobalLobbyClient.h"
- #include "GlobalLobbyWindow.h"
- #include "../CServerHandler.h"
- #include "../gui/CGuiHandler.h"
- #include "../gui/WindowHandler.h"
- #include "../widgets/Buttons.h"
- #include "../widgets/MiscWidgets.h"
- #include "../widgets/ObjectLists.h"
- #include "../widgets/TextControls.h"
- #include "../../lib/MetaString.h"
- GlobalLobbyWidget::GlobalLobbyWidget(GlobalLobbyWindow * window)
- : window(window)
- {
- addCallback("closeWindow", [](int) { GH.windows().popWindows(1); });
- addCallback("sendMessage", [this](int) { this->window->doSendChatMessage(); });
- addCallback("createGameRoom", [this](int) { this->window->doCreateGameRoom(); });
- REGISTER_BUILDER("accountList", &GlobalLobbyWidget::buildAccountList);
- REGISTER_BUILDER("roomList", &GlobalLobbyWidget::buildRoomList);
- const JsonNode config(JsonPath::builtin("config/widgets/lobbyWindow.json"));
- build(config);
- }
- std::shared_ptr<CIntObject> GlobalLobbyWidget::buildAccountList(const JsonNode & config) const
- {
- const auto & createCallback = [this](size_t index) -> std::shared_ptr<CIntObject>
- {
- const auto & accounts = CSH->getGlobalLobby().getActiveAccounts();
- if(index < accounts.size())
- return std::make_shared<GlobalLobbyAccountCard>(this->window, accounts[index]);
- return std::make_shared<CIntObject>();
- };
- auto position = readPosition(config["position"]);
- auto itemOffset = readPosition(config["itemOffset"]);
- auto sliderPosition = readPosition(config["sliderPosition"]);
- auto sliderSize = readPosition(config["sliderSize"]);
- size_t visibleSize = 4; // FIXME: how many items can fit into UI?
- size_t totalSize = 4; //FIXME: how many items are there in total
- int sliderMode = 1 | 4; // present, vertical, blue
- int initialPos = 0;
- return std::make_shared<CListBox>(createCallback, position, itemOffset, visibleSize, totalSize, initialPos, sliderMode, Rect(sliderPosition, sliderSize) );
- }
- std::shared_ptr<CIntObject> GlobalLobbyWidget::buildRoomList(const JsonNode & config) const
- {
- const auto & createCallback = [this](size_t index) -> std::shared_ptr<CIntObject>
- {
- const auto & rooms = CSH->getGlobalLobby().getActiveRooms();
- if(index < rooms.size())
- return std::make_shared<GlobalLobbyRoomCard>(this->window, rooms[index]);
- return std::make_shared<CIntObject>();
- };
- auto position = readPosition(config["position"]);
- auto itemOffset = readPosition(config["itemOffset"]);
- auto sliderPosition = readPosition(config["sliderPosition"]);
- auto sliderSize = readPosition(config["sliderSize"]);
- size_t visibleSize = 4; // FIXME: how many items can fit into UI?
- size_t totalSize = 4; //FIXME: how many items are there in total
- int sliderMode = 1 | 4; // present, vertical, blue
- int initialPos = 0;
- return std::make_shared<CListBox>(createCallback, position, itemOffset, visibleSize, totalSize, initialPos, sliderMode, Rect(sliderPosition, sliderSize) );
- }
- std::shared_ptr<CLabel> GlobalLobbyWidget::getAccountNameLabel()
- {
- return widget<CLabel>("accountNameLabel");
- }
- std::shared_ptr<CTextInput> GlobalLobbyWidget::getMessageInput()
- {
- return widget<CTextInput>("messageInput");
- }
- std::shared_ptr<CTextBox> GlobalLobbyWidget::getGameChat()
- {
- return widget<CTextBox>("gameChat");
- }
- std::shared_ptr<CListBox> GlobalLobbyWidget::getAccountList()
- {
- return widget<CListBox>("accountList");
- }
- std::shared_ptr<CListBox> GlobalLobbyWidget::getRoomList()
- {
- return widget<CListBox>("roomList");
- }
- GlobalLobbyAccountCard::GlobalLobbyAccountCard(GlobalLobbyWindow * window, const GlobalLobbyAccount & accountDescription)
- {
- OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
- const auto & onInviteClicked = [window, accountID=accountDescription.accountID]()
- {
- window->doInviteAccount(accountID);
- };
- pos.w = 130;
- pos.h = 40;
- backgroundOverlay = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, pos.w, pos.h), ColorRGBA(0,0,0,128), ColorRGBA(64,64,64,64));
- labelName = std::make_shared<CLabel>( 5, 2, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, accountDescription.displayName);
- labelStatus = std::make_shared<CLabel>( 5, 20, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, accountDescription.status);
- buttonInvite = std::make_shared<CButton>(Point(95, 8), AnimationPath::builtin("settingsWindow/button32"), CButton::tooltip(), onInviteClicked);
- }
- GlobalLobbyRoomCard::GlobalLobbyRoomCard(GlobalLobbyWindow * window, const GlobalLobbyRoom & roomDescription)
- {
- OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
- const auto & onJoinClicked = [window, roomID=roomDescription.gameRoomID]()
- {
- window->doJoinRoom(roomID);
- };
- auto roomSizeText = MetaString::createFromRawString("%d/%d");
- roomSizeText.replaceNumber(roomDescription.playersCount);
- roomSizeText.replaceNumber(roomDescription.playersLimit);
- pos.w = 230;
- pos.h = 40;
- backgroundOverlay = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, pos.w, pos.h), ColorRGBA(0,0,0,128), ColorRGBA(64,64,64,64));
- labelName = std::make_shared<CLabel>( 5, 2, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, roomDescription.hostAccountDisplayName);
- labelStatus = std::make_shared<CLabel>( 5, 20, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, roomDescription.description);
- labelRoomSize = std::make_shared<CLabel>( 160, 2, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, roomSizeText.toString());
- buttonJoin = std::make_shared<CButton>(Point(195, 8), AnimationPath::builtin("settingsWindow/button32"), CButton::tooltip(), onJoinClicked);
- }
|