Skip to content

Commit

Permalink
Scoreboard|Fixed: Resolved all alignment issues
Browse files Browse the repository at this point in the history
However the map metadata bar may still extend off the right edge of
the table. We could use a scissor and/or mask and then scroll it if
its too long to fit...
  • Loading branch information
danij-deng committed Feb 13, 2012
1 parent ff34e0f commit 9e3e14f
Showing 1 changed file with 64 additions and 88 deletions.
152 changes: 64 additions & 88 deletions doomsday/plugins/common/src/hu_stuff.c
Expand Up @@ -351,21 +351,28 @@ static void drawQuad(float x, float y, float w, float h, float s, float t,
void HU_DrawText(const char* str, float x, float y, float scale,
float r, float g, float b, float a, int alignFlags, short textFlags)
{
if(!str || !str[0])
return;
const boolean applyScale = !FEQUAL(scale, 1.0f);

DGL_MatrixMode(DGL_MODELVIEW);
DGL_PushMatrix();
if(!str || !str[0]) return;

if(applyScale)
{
DGL_MatrixMode(DGL_MODELVIEW);
DGL_PushMatrix();

DGL_Translatef(x, y, 0);
DGL_Scalef(scale, scale, 1);
DGL_Translatef(-x, -y, 0);
DGL_Translatef(x, y, 0);
DGL_Scalef(scale, scale, 1);
DGL_Translatef(-x, -y, 0);
}

FR_SetColorAndAlpha(r, g, b, a);
FR_DrawTextXY3(str, x, y, alignFlags, textFlags);

DGL_MatrixMode(DGL_MODELVIEW);
DGL_PopMatrix();
if(applyScale)
{
DGL_MatrixMode(DGL_MODELVIEW);
DGL_PopMatrix();
}
}

typedef struct {
Expand Down Expand Up @@ -515,49 +522,38 @@ static void drawTable(float x, float ly, float width, float height,
#define CELL_PADDING (1)

int i, n, numCols, numStretchCols;
float cX, cY, fixedWidth, lineHeight, fontScale, fontHeight, fontOffsetY;
float* colX, *colW;

if(!columns)
return;
int cX, cY, fixedWidth, lineHeight, fontHeight, fontOffsetY;
float fontScale, *colX, *colW;

if(!(alpha > 0))
return;
if(!columns) return;
if(!(alpha > 0)) return;

numStretchCols = 0;
numCols = 0;
for(n = 0; columns[n].label; n++)
{
numCols++;

if(columns[n].flags & CF_HIDE)
continue;
if(columns[n].flags & CF_HIDE) continue;

if(!(columns[n].flags & CF_FIXEDWIDTH))
numStretchCols++;
}

if(!numCols)
return;
if(!numCols) return;

colX = calloc(1, sizeof(*colX) * numCols);
colW = calloc(1, sizeof(*colW) * numCols);

lineHeight = height / (MAXPLAYERS + 1);
lineHeight = .5f + height / (MAXPLAYERS + 1);
fontHeight = FR_CharHeight('A');
fontScale = (lineHeight - CELL_PADDING * 2) / fontHeight;
fontScale = (float)lineHeight / (fontHeight + CELL_PADDING * 2);
fontOffsetY = 0;
if(fontScale > 1)
{
fontScale = 1;
fontOffsetY = (lineHeight - CELL_PADDING * 2 - fontHeight) / 2;
}

fixedWidth = 0;
for(n = 0; n < numCols; ++n)
{
if(columns[n].flags & CF_HIDE)
continue;
if(columns[n].flags & CF_HIDE) continue;

if(columns[n].flags & CF_FIXEDWIDTH)
{
Expand All @@ -568,8 +564,7 @@ static void drawTable(float x, float ly, float width, float height,

for(n = 0; n < numCols; ++n)
{
if(columns[n].flags & CF_HIDE)
continue;
if(columns[n].flags & CF_HIDE) continue;

if(!(columns[n].flags & CF_FIXEDWIDTH))
colW[n] = (width - fixedWidth) / numStretchCols;
Expand All @@ -588,20 +583,18 @@ static void drawTable(float x, float ly, float width, float height,
DGL_Enable(DGL_TEXTURE_2D);
for(n = 0; n < numCols; ++n)
{
if(columns[n].flags & CF_HIDE)
continue;
if(columns[n].flags & CF_HIDE) continue;

cX = colX[n];
cY = ly + fontOffsetY;
cY = ly + lineHeight - CELL_PADDING + fontOffsetY;

cY += CELL_PADDING;
if(columns[n].alignRight)
cX += colW[n] - CELL_PADDING;
else
cX += CELL_PADDING;

HU_DrawText(columns[n].label, cX, cY, fontScale, 1.f, 1.f, 1.f, alpha,
ALIGN_TOP|(columns[n].alignRight? ALIGN_RIGHT : 0), DTF_ONLY_SHADOW);
ALIGN_BOTTOM|(columns[n].alignRight? ALIGN_RIGHT : ALIGN_LEFT), DTF_ONLY_SHADOW);
}
ly += lineHeight;
DGL_Disable(DGL_TEXTURE_2D);
Expand All @@ -614,13 +607,12 @@ static void drawTable(float x, float ly, float width, float height,
char buf[5];

if(info->player == player)
{ // Draw a background to make *me* stand out.
{
// Draw a background to make *me* stand out.
float val = (info->color[0] + info->color[1] + info->color[2]) / 3;

if(val < .5f)
val = .2f;
else
val = .8f;
if(val < .5f) val = .2f;
else val = .8f;

DGL_DrawRectf2Color(x, ly, width, lineHeight, val + .2f, val + .2f, val, .5f * alpha);
}
Expand All @@ -630,21 +622,11 @@ static void drawTable(float x, float ly, float width, float height,

for(n = 0; n < numCols; ++n)
{
if(columns[n].flags & CF_HIDE)
continue;
if(columns[n].flags & CF_HIDE) continue;

cX = colX[n];
cY = ly;

/*#if _DEBUG
DGL_Disable(DGL_TEXTURE_2D);
GL_DrawRectf2Color(cX + CELL_PADDING, cY + CELL_PADDING,
colW[n] - CELL_PADDING * 2,
lineHeight - CELL_PADDING * 2,
1, 1, 1, .1f * alpha);
DGL_Enable(DGL_TEXTURE_2D);
#endif*/

cY += CELL_PADDING;
if(columns[n].alignRight)
cX += colW[n] - CELL_PADDING;
Expand Down Expand Up @@ -680,16 +662,16 @@ DGL_Enable(DGL_TEXTURE_2D);
h = sprInfo.geometry.size.height;

if(h > w)
scale = (lineHeight - CELL_PADDING * 2) / h;
scale = (float) (lineHeight - CELL_PADDING * 2) / h;
else
scale = (colW[n] - CELL_PADDING * 2) / w;
scale = (float) (colW[n] - CELL_PADDING * 2) / w;

w *= scale;
h *= scale;

// Align to center on both X+Y axes.
cX += ((colW[n] - CELL_PADDING * 2) - w) / 2;
cY += ((lineHeight - CELL_PADDING * 2) - h) / 2;
cX += ((colW[n] - CELL_PADDING * 2) - w) / 2.0f;
cY += ((lineHeight - CELL_PADDING * 2) - h) / 2.0f;

DGL_SetMaterialUI(sprInfo.material, DGL_CLAMP_TO_EDGE, DGL_CLAMP_TO_EDGE);

Expand All @@ -702,21 +684,24 @@ DGL_Enable(DGL_TEXTURE_2D);
case 1: // Name.
HU_DrawText(name, cX, cY + fontOffsetY, fontScale,
info->color[0], info->color[1], info->color[2],
alpha, ALIGN_TOPLEFT, DTF_ONLY_SHADOW);
alpha, ALIGN_TOP|(columns[n].alignRight? ALIGN_RIGHT : ALIGN_LEFT),
DTF_ONLY_SHADOW);
break;

case 2: // #Suicides.
sprintf(buf, "%4i", info->suicides);
HU_DrawText(buf, cX, cY + fontOffsetY, fontScale,
info->color[0], info->color[1], info->color[2],
alpha, ALIGN_TOPLEFT, DTF_ONLY_SHADOW);
alpha, ALIGN_TOP|(columns[n].alignRight? ALIGN_RIGHT : ALIGN_LEFT),
DTF_ONLY_SHADOW);
break;

case 3: // #Kills.
sprintf(buf, "%4i", info->kills);
HU_DrawText(buf, cX, cY + fontOffsetY, fontScale,
info->color[0], info->color[1], info->color[2],
alpha, ALIGN_TOPLEFT, DTF_ONLY_SHADOW);
alpha, ALIGN_TOP|(columns[n].alignRight? ALIGN_RIGHT : ALIGN_LEFT),
DTF_ONLY_SHADOW);
break;
}
}
Expand All @@ -735,68 +720,59 @@ const char* P_GetGameModeName(void)
static const char* dm = "deathmatch";
static const char* coop = "cooperative";
static const char* sp = "singleplayer";

if(IS_NETGAME)
{
if(deathmatch)
return dm;

if(deathmatch) return dm;
return coop;
}

return sp;
}

static void drawMapMetaData(float x, float y, float alpha)
{
static const char* unnamed = "unnamed";
#define BORDER 2

static const char* unnamed = "Unnamed";

const char* lname = P_GetMapNiceName();
char buf[256];

if(!lname)
lname = unnamed;

FR_SetColorAndAlpha(1, 1, 1, alpha);

// Map name:
FR_DrawTextXY("map: ", x, y + 16);
FR_DrawTextXY(lname, x += FR_TextWidth("map: "), y + 16);
dd_snprintf(buf, 256, "map: %s gamemode: %s", lname, P_GetGameModeName());

x += 8;
FR_SetColorAndAlpha(1, 1, 1, alpha);
FR_DrawTextXY2(buf, x + BORDER, y - BORDER, ALIGN_BOTTOMLEFT);

// Game mode:
FR_DrawTextXY("gamemode: ", x += FR_TextWidth(lname), y + 16);
FR_DrawTextXY(P_GetGameModeName(), x += FR_TextWidth("gamemode: "), y + 16);
#undef BORDER
}

/**
* Draws a sorted frags list in the lower right corner of the screen.
*/
void HU_DrawScoreBoard(int player)
{
#define LINE_BORDER 4
#define LINE_BORDER 4

column_t columns[] = {
{"cl", 0, CF_FIXEDWIDTH, false},
{"name", 1, 0, false},
{"suicides", 2, CF_FIXEDWIDTH, true},
{"frags", 3, CF_FIXEDWIDTH, true},
{NULL, 0, 0}
{ "cl", 0, CF_FIXEDWIDTH },
{ "name", 1 },
{ "suicides", 2, CF_FIXEDWIDTH, true },
{ "frags", 3, CF_FIXEDWIDTH, true },
{ NULL }
};

scoreinfo_t scoreBoard[MAXPLAYERS];
int x, y, width, height, inCount;
scoreboardstate_t* ss;

if(!IS_NETGAME)
return;

if(player < 0 || player >= MAXPLAYERS)
return;
if(!IS_NETGAME) return;

if(player < 0 || player >= MAXPLAYERS) return;
ss = &scoreStates[player];

if(!(ss->alpha > 0))
return;
if(!(ss->alpha > 0)) return;

// Set up the fixed 320x200 projection.
DGL_MatrixMode(DGL_PROJECTION);
Expand Down Expand Up @@ -834,7 +810,7 @@ void HU_DrawScoreBoard(int player)
FR_DrawTextXY3("ranking", x + width / 2, y + LINE_BORDER, ALIGN_TOP, DTF_ONLY_SHADOW);

FR_SetFont(FID(GF_FONTA));
drawMapMetaData(x, y + 16, ss->alpha);
drawMapMetaData(x, y + height, ss->alpha);
drawTable(x, y + 20, width, height - 20, columns, scoreBoard, inCount, ss->alpha, player);

DGL_Disable(DGL_TEXTURE_2D);
Expand Down

0 comments on commit 9e3e14f

Please sign in to comment.