Skip to content

Commit

Permalink
Shell: Showing the map outline
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 6, 2019
1 parent d0683a6 commit d8f88bb
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 49 deletions.
16 changes: 12 additions & 4 deletions doomsday/libs/doomsdaygui/src/mapoutlinewidget.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
90 changes: 58 additions & 32 deletions doomsday/tools/shell/src/linkwindow.cpp
Expand Up @@ -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
{
Expand Down Expand Up @@ -84,8 +90,8 @@ DE_PIMPL(LinkWindow)
GuiWidget *newLocalServerPage = nullptr;
GuiWidget *consolePage = nullptr;
List<GuiWidget *> 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;
Expand All @@ -98,6 +104,8 @@ DE_PIMPL(LinkWindow)
// QAction *disconnectAction;
#endif

enum Tab { NewServer, Status, Options, Console };

Impl(Public &i)
: Base(i)
, root(&i)
Expand Down Expand Up @@ -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);
Expand All @@ -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.
Expand Down Expand Up @@ -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...");
Expand Down Expand Up @@ -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()));
}
}

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -761,20 +780,26 @@ 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);
}

void LinkWindow::switchToConsole()
{
d->pageTabs->setCurrent(Impl::Tab::Console);

// d->statusButton->setChecked(false);
// d->optionsButton->setChecked(false);
// d->stack->setCurrentWidget(d->console);
Expand Down Expand Up @@ -836,28 +861,29 @@ void LinkWindow::handleIncomingPackets()
debug("TODO: received console lexicon");
break;

case Protocol::GameState: {
Record &rec = static_cast<RecordPacket *>(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<RecordPacket *>(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<MapOutlinePacket *>(packet.get()));
d->statusPage->setMapOutline(*static_cast<MapOutlinePacket *>(packet.get()));
break;

case Protocol::PlayerInfo:
d->status->setPlayerInfo(*static_cast<PlayerInfoPacket *>(packet.get()));
d->statusPage->setPlayerInfo(*static_cast<PlayerInfoPacket *>(packet.get()));
break;

default:
Expand Down Expand Up @@ -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();
Expand All @@ -914,7 +940,7 @@ void LinkWindow::connected()
// d->disconnectAction->setEnabled(true);
//#endif
// d->checkCurrentTab(true);

switchToStatus();
// emit linkOpened(this);
}

Expand Down
48 changes: 35 additions & 13 deletions doomsday/tools/shell/src/statuswidget.cpp
Expand Up @@ -17,18 +17,15 @@
*/

#include "statuswidget.h"
//#include "utils.h"
#include <de/String>
#include <de/LabelWidget>
#include <de/Map>
#include <doomsday/DoomsdayInfo>
//#include <QPainter>
//#include <QPicture>
//#include <QTimer>
//#include <QMap>
#include <doomsday/MapOutlineWidget>

using namespace de;

DE_PIMPL(StatusWidget)
DE_GUI_PIMPL(StatusWidget)
{
using Player = network::PlayerInfoPacket::Player;
using Players = network::PlayerInfoPacket::Players;
Expand All @@ -41,19 +38,42 @@ DE_PIMPL(StatusWidget)
String gameMode;
String map;
// QPicture mapOutline;
MapOutlineWidget *mapOutline;
LabelWidget * stateLabel;
LabelWidget * titleLabel;
Rectangled mapBounds;
Players players;
Map<int, Vec2i> oldPlayerPositions;

Impl(Public &i) : Base(i), link(0)
{}
{
auto &rect = i.rule();

mapOutline = &i.addNew<MapOutlineWidget>("map");
mapOutline->setColors("accent", "inverted.accent");
mapOutline->rule().setRect(rect);

stateLabel = &i.addNew<LabelWidget>("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<LabelWidget>("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();
}
Expand All @@ -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();

Expand Down Expand Up @@ -123,7 +148,6 @@ void StatusWidget::setPlayerInfo(network::PlayerInfoPacket const &plrInfo)
}

d->players = plrInfo.players();
update();
}

#if 0
Expand Down Expand Up @@ -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();
}

0 comments on commit d8f88bb

Please sign in to comment.