From d8f88bbcba2c6357332d96f6677341bc03911427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= Date: Fri, 6 Sep 2019 20:02:50 +0300 Subject: [PATCH] Shell: Showing the map outline --- .../libs/doomsdaygui/src/mapoutlinewidget.cpp | 16 +++- doomsday/tools/shell/src/linkwindow.cpp | 90 ++++++++++++------- doomsday/tools/shell/src/statuswidget.cpp | 48 +++++++--- 3 files changed, 105 insertions(+), 49 deletions(-) diff --git a/doomsday/libs/doomsdaygui/src/mapoutlinewidget.cpp b/doomsday/libs/doomsdaygui/src/mapoutlinewidget.cpp index 13e84df63f..164a646a3d 100644 --- a/doomsday/libs/doomsdaygui/src/mapoutlinewidget.cpp +++ b/doomsday/libs/doomsdaygui/src/mapoutlinewidget.cpp @@ -26,6 +26,8 @@ using namespace de; DE_GUI_PIMPL(MapOutlineWidget) { ProgressWidget *progress; // shown initially, before outline received + DotPath oneSidedColorId{"inverted.altaccent"}; + DotPath twoSidedColorId{"altaccent"}; // Outline. Rectanglei mapBounds; @@ -61,7 +63,7 @@ DE_GUI_PIMPL(MapOutlineWidget) vbuf = nullptr; } - void makeOutline(network::MapOutlinePacket const &mapOutline) + void makeOutline(const network::MapOutlinePacket &mapOutline) { if (!vbuf) return; @@ -74,8 +76,8 @@ DE_GUI_PIMPL(MapOutlineWidget) mapBounds = Rectanglei(); - Vec4f const oneSidedColor = style().colors().colorf("inverted.altaccent"); - Vec4f const twoSidedColor = style().colors().colorf("altaccent"); + const Vec4f oneSidedColor = style().colors().colorf(oneSidedColorId); + const Vec4f twoSidedColor = style().colors().colorf(twoSidedColorId); DefaultVertexBuf::Builder verts; DefaultVertexBuf::Type vtx; @@ -96,7 +98,7 @@ DE_GUI_PIMPL(MapOutlineWidget) } else { - mapBounds = Rectanglei(line.start, line.start); + mapBounds = {line.start, line.start}; // initialize } mapBounds.include(line.end); } @@ -130,6 +132,12 @@ MapOutlineWidget::MapOutlineWidget(String const &name) , d(new Impl(this)) {} +void MapOutlineWidget::setColors(const DotPath &oneSidedLine, const DotPath &twoSidedLine) +{ + d->oneSidedColorId = oneSidedLine; + d->twoSidedColorId = twoSidedLine; +} + void MapOutlineWidget::setOutline(network::MapOutlinePacket const &mapOutline) { d->makeOutline(mapOutline); diff --git a/doomsday/tools/shell/src/linkwindow.cpp b/doomsday/tools/shell/src/linkwindow.cpp index d836114d59..09de3dc991 100644 --- a/doomsday/tools/shell/src/linkwindow.cpp +++ b/doomsday/tools/shell/src/linkwindow.cpp @@ -53,10 +53,16 @@ using namespace de; //#endif //} +DE_STATIC_STRING(PROMPT_ID, "prompt") + struct ServerCommandWidget : public CommandWidget { DE_DEFINE_AUDIENCE(Command, void commandSubmitted(const String &)) + ServerCommandWidget() + : CommandWidget(PROMPT_ID()) + {} + bool isAcceptedAsCommand(const String &) override { return true; } void executeCommand(const String &cmd) override { @@ -84,8 +90,8 @@ DE_PIMPL(LinkWindow) GuiWidget *newLocalServerPage = nullptr; GuiWidget *consolePage = nullptr; List pages; - StatusWidget *status = nullptr; - OptionsPage *options = nullptr; + StatusWidget *statusPage = nullptr; + OptionsPage *optionsPage = nullptr; StyledLogSinkFormatter logFormatter{LogEntry::Styled | LogEntry::OmitLevel}; LogWidget *logWidget = nullptr; ServerCommandWidget *commandWidget = nullptr; @@ -98,6 +104,8 @@ DE_PIMPL(LinkWindow) // QAction *disconnectAction; #endif + enum Tab { NewServer, Status, Options, Console }; + Impl(Public &i) : Base(i) , root(&i) @@ -156,10 +164,10 @@ DE_PIMPL(LinkWindow) GuiWidget *page = nullptr; switch (pageTabs->current()) { - case 0: page = newLocalServerPage; break; - case 1: page = status; break; - case 2: page = options; break; - case 3: page = consolePage; break; + case Tab::NewServer: page = newLocalServerPage; break; + case Tab::Status: page = statusPage; break; + case Tab::Options: page = optionsPage; break; + case Tab::Console: page = consolePage; break; default: break; } setCurrentPage(page); @@ -174,18 +182,18 @@ DE_PIMPL(LinkWindow) // Status page. { - status = new StatusWidget; - root.add(status); - pages << status; + statusPage = new StatusWidget; + root.add(statusPage); + pages << statusPage; } // Game options page. { - options = new OptionsPage; - root.add(options); - pages << options; + optionsPage = new OptionsPage; + root.add(optionsPage); + pages << optionsPage; - options->audienceForCommands() += this; + optionsPage->audienceForCommands() += this; } // Console page. @@ -225,7 +233,7 @@ DE_PIMPL(LinkWindow) root.add(newLocalServerPage); pages << newLocalServerPage; - auto *newButton = new ButtonWidget; + auto *newButton = new ButtonWidget("newserverbutton"); newLocalServerPage->add(newButton); newButton->setSizePolicy(ui::Expand, ui::Expand); newButton->setText("New Local Server..."); @@ -317,6 +325,17 @@ DE_PIMPL(LinkWindow) for (size_t i = 0; i < pages.size(); ++i) { pages[i]->show(pages[i] == page); + pages[i]->enable(pages[i] == page); + } + + // Focus on the appropriate widget. + if (page == newLocalServerPage) + { + root.setFocus(root.guiFind("newserverbutton")); + } + else if (page == consolePage) + { + root.setFocus(root.guiFind(PROMPT_ID())); } } @@ -723,7 +742,7 @@ void LinkWindow::openConnection(network::Link *link, const String &name) d->statusMessage->setText("Looking up host..."); d->link->connectLink(); - d->status->linkConnected(d->link); + d->statusPage->linkConnected(d->link); // d->checkCurrentTab(true); d->updateStyle(); } @@ -761,13 +780,17 @@ void LinkWindow::closeConnection() void LinkWindow::switchToStatus() { + d->pageTabs->setCurrent(Impl::Tab::Status); + // d->optionsButton->setChecked(false); // d->consoleButton->setChecked(false); // d->stack->setCurrentWidget(d->link? d->status : d->newLocalServerPage); } void LinkWindow::switchToOptions() -{ +{ + d->pageTabs->setCurrent(Impl::Tab::Options); + // d->statusButton->setChecked(false); // d->consoleButton->setChecked(false); // d->stack->setCurrentWidget(d->options); @@ -775,6 +798,8 @@ void LinkWindow::switchToOptions() void LinkWindow::switchToConsole() { + d->pageTabs->setCurrent(Impl::Tab::Console); + // d->statusButton->setChecked(false); // d->optionsButton->setChecked(false); // d->stack->setCurrentWidget(d->console); @@ -836,28 +861,29 @@ void LinkWindow::handleIncomingPackets() debug("TODO: received console lexicon"); break; - case Protocol::GameState: { - Record &rec = static_cast(packet.get())->record(); - const String rules = rec["rules"]; - String gameType = rules.containsWord("dm") ? "Deathmatch" : - rules.containsWord("dm2") ? "Deathmatch II" : - "Co-op"; + case Protocol::GameState: + { + Record & rec = static_cast(packet.get())->record(); + const String rules = rec["rules"]; + String gameType = rules.containsWord("dm") ? "Deathmatch" + : rules.containsWord("dm2") ? "Deathmatch II" : "Co-op"; - d->status->setGameState(rec["mode"].value().asText(), - gameType, - rec["mapId"].value().asText(), - rec["mapTitle"].value().asText()); + d->statusPage->setGameState(rec["mode"].value().asText(), + gameType, + rec["mapId"].value().asText(), + rec["mapTitle"].value().asText()); d->updateStatusBarWithGameState(rec); -// d->options->updateWithGameState(rec); - break; } + d->optionsPage->updateWithGameState(rec); + break; + } case Protocol::MapOutline: - d->status->setMapOutline(*static_cast(packet.get())); + d->statusPage->setMapOutline(*static_cast(packet.get())); break; case Protocol::PlayerInfo: - d->status->setPlayerInfo(*static_cast(packet.get())); + d->statusPage->setPlayerInfo(*static_cast(packet.get())); break; default: @@ -905,7 +931,7 @@ void LinkWindow::connected() setTitle(d->linkName); d->updateCurrentHost(); // d->console->root().setOverlaidMessage(""); - d->status->linkConnected(d->link); + d->statusPage->linkConnected(d->link); d->statusMessage->setText(""); updateWhenConnected(); @@ -914,7 +940,7 @@ void LinkWindow::connected() // d->disconnectAction->setEnabled(true); //#endif // d->checkCurrentTab(true); - + switchToStatus(); // emit linkOpened(this); } diff --git a/doomsday/tools/shell/src/statuswidget.cpp b/doomsday/tools/shell/src/statuswidget.cpp index 095a9ca1c2..41d25682c4 100644 --- a/doomsday/tools/shell/src/statuswidget.cpp +++ b/doomsday/tools/shell/src/statuswidget.cpp @@ -17,18 +17,15 @@ */ #include "statuswidget.h" -//#include "utils.h" #include +#include #include #include -//#include -//#include -//#include -//#include +#include using namespace de; -DE_PIMPL(StatusWidget) +DE_GUI_PIMPL(StatusWidget) { using Player = network::PlayerInfoPacket::Player; using Players = network::PlayerInfoPacket::Players; @@ -41,19 +38,42 @@ DE_PIMPL(StatusWidget) String gameMode; String map; // QPicture mapOutline; + MapOutlineWidget *mapOutline; + LabelWidget * stateLabel; + LabelWidget * titleLabel; Rectangled mapBounds; Players players; Map oldPlayerPositions; Impl(Public &i) : Base(i), link(0) - {} + { + auto &rect = i.rule(); + + mapOutline = &i.addNew("map"); + mapOutline->setColors("accent", "inverted.accent"); + mapOutline->rule().setRect(rect); + + stateLabel = &i.addNew("gamestate"); + stateLabel->setSizePolicy(ui::Expand, ui::Expand); + stateLabel->setFont("heading"); + stateLabel->margins().setTop(rule("gap") * 2); + stateLabel->rule().setMidAnchorX(rect.midX()).setInput(Rule::Top, rect.top()); + + titleLabel = &i.addNew("title"); + titleLabel->setSizePolicy(ui::Expand, ui::Expand); + titleLabel->margins().setTop(Const(0)); + titleLabel->setFont("title"); + titleLabel->rule() + .setMidAnchorX(rect.midX()) + .setInput(Rule::Top, stateLabel->rule().bottom()); + } void clear() - { + { gameMode.clear(); map.clear(); mapBounds = {}; -// mapOutline = QPicture(); + mapOutline->setOutline({}); oldPlayerPositions.clear(); players.clear(); } @@ -80,11 +100,16 @@ void StatusWidget::setGameState(String mode, String rules, String mapId, String d->map += " (" + mapId + ")"; } - update(); + d->stateLabel->setText(d->gameMode); + d->titleLabel->setText(d->map); } void StatusWidget::setMapOutline(const network::MapOutlinePacket &outline) { + d->mapOutline->setOutline(outline); + + // Draw player positions. + // d->mapBounds = QRect(); // d->mapOutline = QPicture(); @@ -123,7 +148,6 @@ void StatusWidget::setPlayerInfo(network::PlayerInfoPacket const &plrInfo) } d->players = plrInfo.players(); - update(); } #if 0 @@ -261,12 +285,10 @@ void StatusWidget::updateWhenConnected() void StatusWidget::linkConnected(network::Link *link) { d->link = link; - update(); } void StatusWidget::linkDisconnected() { d->link = nullptr; d->clear(); - update(); }