Skip to content

Commit

Permalink
UI|Home: Show map outline and other server info in ServerInfoDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 1, 2017
1 parent 6000493 commit 486ef37
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 30 deletions.
1 change: 0 additions & 1 deletion doomsday/apps/client/include/ui/widgets/mapoutlinewidget.h
Expand Up @@ -33,7 +33,6 @@ class MapOutlineWidget : public de::GuiWidget
void setOutline(de::shell::MapOutlinePacket const &mapOutline);

// Events.
void viewResized() override;
void drawContent() override;

protected:
Expand Down
Expand Up @@ -121,7 +121,7 @@ home {

item.background {
color selected.inverted {
rgb $= gui.colorMix(background.rgb, altaccent.rgb, 0.333)
rgb $= gui.colorMix(accent.rgb, text.rgb, 0.35)
}
}
}
47 changes: 39 additions & 8 deletions doomsday/apps/client/src/ui/dialogs/serverinfodialog.cpp
Expand Up @@ -23,6 +23,9 @@
#include "ui/widgets/mapoutlinewidget.h"
#include "network/serverlink.h"

#include <doomsday/Games>

#include <de/charsymbols.h>
#include <de/ButtonWidget>
#include <de/SequentialLayout>
#include <de/ui/SubwidgetItem>
Expand Down Expand Up @@ -59,6 +62,7 @@ DENG_GUI_PIMPL(ServerInfoDialog)
LabelWidget *description;
PackagesWidget *packages = nullptr;
MapOutlineWidget *mapOutline;
LabelWidget *gameState;
ui::ListData packageActions;

Impl(Public *i, shell::ServerInfo const &sv)
Expand Down Expand Up @@ -115,8 +119,13 @@ DENG_GUI_PIMPL(ServerInfoDialog)
description->setTextLineAlignment(ui::AlignLeft);

mapOutline = new MapOutlineWidget;
mapOutline->rule().setInput(Rule::Width, Const(2*4*90));
area.add(mapOutline);
mapOutline->rule().setInput(Rule::Width, Const(2*4*90));

gameState = LabelWidget::newWithText("", &area);
gameState->setFont("small");
gameState->setSizePolicy(ui::Filled, ui::Expand);
gameState->setTextColor("inverted.altaccent");

updateLayout();
}
Expand All @@ -140,26 +149,30 @@ DENG_GUI_PIMPL(ServerInfoDialog)
rightLayout << *mapOutline;*/

mapOutline->rule()
.setInput(Rule::Height, layout.height())
.setInput(Rule::Height, layout.height() - gameState->rule().height())
.setLeftTop(title->rule().right(), title->rule().top());

gameState->rule()
.setInput(Rule::Width, mapOutline->rule().width())
.setInput(Rule::Left, mapOutline->rule().left())
.setInput(Rule::Bottom, area.contentRule().bottom());

area.setContentSize(layout.width() + mapOutline->rule().width(),
layout.height());
//OperatorRule::maximum(layout.height());
//rightLayout.height()));
}

void updateContent(bool updatePackages = true)
{
title->setText(serverInfo.name());

qDebug() << serverInfo.asText();

// Title and description.
{
StringList lines;
if (!domainName.isEmpty())
{
lines << _E(b) + domainName + _E(.) +
String(" (%1)").arg(host.asText());
lines << _E(b) + domainName + _E(.) + String(" (%1)").arg(host.asText());
}
else
{
Expand All @@ -175,6 +188,8 @@ DENG_GUI_PIMPL(ServerInfoDialog)
// Additional information.
{
String msg;
msg = tr("Version: ") + serverInfo.version().asText() + "\n" +
tr("Rules: ") + serverInfo.gameConfig() + "\n";
auto const players = serverInfo.players();
if (players.isEmpty())
{
Expand All @@ -190,9 +205,25 @@ DENG_GUI_PIMPL(ServerInfoDialog)
description->setText(msg);
}

// Game state.
{
String const gameId = serverInfo.gameId();
String gameTitle = gameId;
if (Games::get().contains(gameId))
{
gameTitle = Games::get()[gameId].title();
}
String msg = String(_E(b) "%1" _E(.) "\n%2 " DENG2_CHAR_MDASH " %3")
.arg(serverInfo.map())
.arg(serverInfo.gameConfig().containsWord("coop")? tr("Co-op")
: tr("Deathmatch"))
.arg(gameTitle);
gameState->setText(msg);
}

if (updatePackages && !serverInfo.packages().isEmpty())
{
qDebug() << "updating with packages:" << serverInfo.packages();
//qDebug() << "updating with packages:" << serverInfo.packages();
if (!packages)
{
packages = new PackagesWidget(serverInfo.packages());
Expand Down Expand Up @@ -275,7 +306,7 @@ DENG_GUI_PIMPL(ServerInfoDialog)

void mapOutlineReceived(Address const &, shell::MapOutlinePacket const &packet)
{
qDebug() << "got outline," << packet.lineCount() << "lines";
mapOutline->setOutline(packet);
}
};

Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/ui/widgets/homeitemwidget.cpp
Expand Up @@ -333,7 +333,7 @@ void HomeItemWidget::useColorTheme(ColorTheme unselected, ColorTheme selected)
if (selected == Inverted)
{
d->selectedBgColor = "home.item.background.selected.inverted";
d->selectedTextColor = "text";
d->selectedTextColor = "inverted.text";
}
else
{
Expand Down
79 changes: 66 additions & 13 deletions doomsday/apps/client/src/ui/widgets/mapoutlinewidget.cpp
Expand Up @@ -31,10 +31,11 @@ DENG_GUI_PIMPL(MapOutlineWidget)
Rectanglei mapBounds;

// Drawing.
DefaultVertexBuf vbuf;
DefaultVertexBuf *vbuf = nullptr;
Drawable drawable;
GLUniform uMvpMatrix { "uMvpMatrix", GLUniform::Mat4 };
GLUniform uColor { "uColor", GLUniform::Vec4 };
Animation mapOpacity { 0, Animation::Linear };

Impl(Public *i) : Base(i)
{
Expand All @@ -47,27 +48,81 @@ DENG_GUI_PIMPL(MapOutlineWidget)

void glInit()
{
vbuf = new DefaultVertexBuf;
drawable.addBuffer(vbuf);

shaders().build(drawable.program(), "generic.color_ucolor")
<< uMvpMatrix << uColor;
}

void glDeinit()
{

drawable.clear();
vbuf = nullptr;
}

void makeOutline(shell::MapOutlinePacket const &mapOutline)
{
progress->hide();
if (!vbuf) return;

// This is likely called wherever incoming network packets are being processed,
// and thus there should be no active OpenGL context.
// and thus there should currently be no active OpenGL context.
root().window().glActivate();

vbuf.clear();
progress->setOpacity(0, 0.5);
mapOpacity.setValue(1, 0.5);

mapBounds = Rectanglei();

Vector4f const oneSidedColor = style().colors().colorf("inverted.altaccent");
Vector4f const twoSidedColor = style().colors().colorf("altaccent");

DefaultVertexBuf::Builder verts;
DefaultVertexBuf::Type vtx;

for (int i = 0; i < mapOutline.lineCount(); ++i)
{
auto const &line = mapOutline.line(i);

vtx.rgba = (line.type == shell::MapOutlinePacket::OneSidedLine? oneSidedColor : twoSidedColor);

// Two vertices per line.
vtx.pos = line.start; verts << vtx;
vtx.pos = line.end; verts << vtx;

if (i > 0)
{
mapBounds.include(line.start);
}
else
{
mapBounds = Rectanglei(line.start, line.start);
}
mapBounds.include(line.end);
}

// vtx.rgba = Vector4f(1, 0, 1, 1);
// vtx.pos = mapBounds.topLeft; verts << vtx;
// vtx.pos = mapBounds.bottomRight; verts << vtx;

vbuf->setVertices(gl::Lines, verts, gl::Static);

root().window().glDone();
}

Matrix4f modelMatrix() const
{
DENG2_ASSERT(vbuf);

if (mapBounds.isNull()) return Matrix4f();

Rectanglef const rect = self().contentRect();
float const scale = de::min(rect.width() / mapBounds.width(),
rect.height() / mapBounds.height());
return Matrix4f::translate(rect.middle()) *
Matrix4f::scale (scale) *
Matrix4f::translate(Vector2f(-mapBounds.middle()));
}
};

MapOutlineWidget::MapOutlineWidget(String const &name)
Expand All @@ -80,17 +135,15 @@ void MapOutlineWidget::setOutline(shell::MapOutlinePacket const &mapOutline)
d->makeOutline(mapOutline);
}

void MapOutlineWidget::viewResized()
{
GuiWidget::viewResized();
d->uMvpMatrix = root().projMatrix2D();
}

void MapOutlineWidget::drawContent()
{
GuiWidget::drawContent();
d->uColor = Vector4f(1, 1, 1, visibleOpacity());
d->drawable.draw();
if (d->vbuf && d->vbuf->count())
{
d->uMvpMatrix = root().projMatrix2D() * d->modelMatrix();
d->uColor = Vector4f(1, 1, 1, d->mapOpacity * visibleOpacity());
d->drawable.draw();
}
}

void MapOutlineWidget::glInit()
Expand Down
17 changes: 11 additions & 6 deletions doomsday/apps/client/src/ui/widgets/packageswidget.cpp
Expand Up @@ -282,24 +282,29 @@ DENG_GUI_PIMPL(PackagesWidget)

void updateContents()
{
String pkgId = packageId();
if (pkgId.startsWith("file."))
auto pkgIdVer = Package::split(packageId());
if (pkgIdVer.first.startsWith("file."))
{
icon().setStyleImage("file", "default");

// Local files should not be indicated to be packages.
if (NativeFile const *native = _item->file->source()->maybeAs<NativeFile>())
{
pkgId = _E(s) + native->nativePath().pretty() + _E(.);
pkgIdVer.first = native->nativePath().pretty();
}
}
else
{
icon().setStyleImage("package.icon", "default");
}
label().setText(String(_E(b) "%1\n" _E(l) "%2")
.arg(_item->label())
.arg(pkgId));
String labelText = String(_E(b) "%1\n" _E(l)_E(s) "%2")
.arg(_item->label())
.arg(pkgIdVer.first);
if (pkgIdVer.second.isValid())
{
labelText += String(_E(C) " %1" _E(.)).arg(pkgIdVer.second.asText());
}
label().setText(labelText);

bool const highlight = _owner.d->packageStatus->isPackageHighlighted(packageId());
_actions->setVariantItemsEnabled(highlight);
Expand Down

0 comments on commit 486ef37

Please sign in to comment.