"Awesome tooltips" for special powers

This commit is contained in:
Paul Chote
2010-04-10 21:35:10 +12:00
committed by Chris Forbes
parent ca725ae505
commit ba857835b4
4 changed files with 111 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
@@ -57,7 +57,7 @@ namespace OpenRA.Graphics
public int2 Measure(string text)
{
return new int2((int)text.Split( '\n' ).Max( s => s.Sum(a => glyphs[a].Advance)), size);
return new int2((int)text.Split( '\n' ).Max( s => s.Sum(a => glyphs[a].Advance)), text.Split('\n').Count()*size);
}
Cache<char, GlyphInfo> glyphs;

View File

@@ -113,17 +113,28 @@ namespace OpenRA.Widgets
{
var pos = drawPos.ToInt2();
var tooltipBounds = new Rectangle(pos.X-3,pos.Y-3,350,54);
WidgetUtils.DrawPanel("dialog4", tooltipBounds, null);
pos += new int2(70, 5);
var tl = new int2(pos.X-3,pos.Y-3);
var m = new int2(pos.X+64+3,pos.Y+48+3);
var br = tl + new int2(64+3+20,60);
if (sp.Info.LongDesc != null)
br += Game.chrome.renderer.RegularFont.Measure(sp.Info.LongDesc.Replace("\\n", "\n"));
else
br += new int2(300,0);
WidgetUtils.DrawRightTooltip("dialog4", tl, m, br, null);
pos += new int2(77, 5);
Game.chrome.renderer.BoldFont.DrawText(Game.chrome.rgbaRenderer, sp.Info.Description, pos, Color.White);
var timer = "Charge Time: {0}".F(FormatTime(sp.RemainingTime));
Game.chrome.renderer.BoldFont.DrawText(Game.chrome.rgbaRenderer, timer, drawPos.ToInt2() + new int2((int)tooltipBounds.Width - Game.chrome.renderer.BoldFont.Measure(timer).X - 10, 0), Color.White);
pos += new int2(0,20);
Game.chrome.renderer.BoldFont.DrawText(Game.chrome.rgbaRenderer, FormatTime(sp.RemainingTime).ToString(), pos, Color.White);
Game.chrome.renderer.BoldFont.DrawText(Game.chrome.rgbaRenderer, "/ {0}".F(FormatTime(sp.TotalTime)), pos + new int2(45,0), Color.White);
if (sp.Info.LongDesc != null)
{
pos += new int2(0, 25);
pos += new int2(0, 20);
Game.chrome.renderer.RegularFont.DrawText(Game.chrome.rgbaRenderer, sp.Info.LongDesc.Replace("\\n", "\n"), pos, Color.White);
}

View File

@@ -90,5 +90,95 @@ namespace OpenRA.Widgets
sr.Flush(); // because the scissor is changing
r.Device.DisableScissor();
}
public static void DrawRightTooltip(string collection, int2 tl, int2 m, int2 br, Action a)
{
var r = Game.chrome.renderer;
var sr = Game.chrome.rgbaRenderer;
var images = new[] { "border-t", "border-b", "border-l", "border-r", "corner-tl", "corner-tr", "corner-bl", "corner-br", "background"};
var ss = images.Select(i => ChromeProvider.GetImage(Game.chrome.renderer, collection, i)).ToArray();
// Draw the background for the left part
r.Device.EnableScissor(tl.X, tl.Y, m.X-tl.X + (int)ss[2].size.X, m.Y-tl.Y - (int)ss[1].size.Y);
for (var x = tl.X + (int)ss[2].size.X; x < m.X + (int)ss[2].size.X; x += (int)ss[8].size.X)
for (var y = tl.Y + (int)ss[0].size.Y; y < m.Y - (int)ss[1].size.Y; y += (int)ss[8].size.Y)
DrawRGBA(ss[8], new float2(x, y));
// Left border
for (var y = tl.Y + (int)ss[0].size.Y; y < m.Y - (int)ss[1].size.Y; y += (int)ss[2].size.Y)
DrawRGBA(ss[2], new float2(tl.X, y));
sr.Flush();
r.Device.EnableScissor(tl.X, tl.Y, m.X-tl.X, m.Y-tl.Y);
// bottom-left border
for (var x = tl.X + (int)ss[2].size.X; x < m.X - (int)ss[2].size.X; x += (int)ss[0].size.X)
DrawRGBA(ss[1], new float2(x, m.Y - ss[1].size.Y));
// BL corner
DrawRGBA(ss[6], new float2(tl.X,m.Y - (int)ss[2].size.X));
sr.Flush();
r.Device.EnableScissor(m.X, tl.Y, br.X - m.X - (int)ss[3].size.X, br.Y - tl.Y - (int)ss[1].size.Y);
// Background for the right part
for (var x = m.X + (int)ss[2].size.X; x < br.X - (int)ss[3].size.X; x += (int)ss[8].size.X)
for (var y = tl.Y + (int)ss[0].size.Y; y < br.Y - (int)ss[1].size.Y; y += (int)ss[8].size.Y)
DrawRGBA(ss[8], new float2(x, y));
// Top border
sr.Flush();
r.Device.EnableScissor(tl.X, tl.Y, br.X - tl.X - (int)ss[3].size.X, (int)ss[0].size.Y);
for (var x = tl.X + (int)ss[2].size.X; x < br.X - (int)ss[3].size.X; x += (int)ss[1].size.X)
DrawRGBA(ss[0], new float2(x, tl.Y));
// TL corner
DrawRGBA(ss[4], new float2(tl.X,tl.Y));
sr.Flush();
r.Device.EnableScissor(br.X - (int)ss[3].size.X, tl.Y, (int)ss[3].size.X, br.Y - tl.Y - (int)ss[1].size.Y);
// Right border
for (var y = tl.Y + (int)ss[0].size.Y; y < br.Y - (int)ss[1].size.Y; y += (int)ss[2].size.Y)
DrawRGBA(ss[3], new float2(br.X - (int)ss[3].size.X, y));
// TR corner
DrawRGBA(ss[5], new float2(br.X- (int)ss[3].size.X,tl.Y));
// Bottom border
sr.Flush();
r.Device.EnableScissor(m.X, br.Y - (int)ss[1].size.Y, br.X - m.X - (int)ss[3].size.X,(int)ss[1].size.Y);
for (var x = m.X + (int)ss[2].size.X; x < br.X - (int)ss[3].size.X; x += (int)ss[1].size.X)
DrawRGBA(ss[1], new float2(x, br.Y - (int)ss[1].size.Y));
// BR corner
sr.Flush();
r.Device.DisableScissor();
DrawRGBA(ss[7], new float2(br.X - (int)ss[7].size.X, br.Y - (int)ss[7].size.Y));
// Left border
sr.Flush();
r.Device.EnableScissor(m.X, m.Y-1, (int)ss[2].size.X, br.Y - m.Y - (int)ss[1].size.Y+1);
for (var y = m.Y-1; y < br.Y - (int)ss[1].size.Y; y += (int)ss[2].size.Y)
DrawRGBA(ss[2], new float2(m.X, y));
// BL corner
sr.Flush();
r.Device.DisableScissor();
DrawRGBA(ss[6], new float2(m.X,br.Y - (int)ss[7].size.Y));
// Patch the hole
sr.Flush();
r.Device.EnableScissor(m.X, m.Y-(int)ss[1].size.Y, (int)ss[2].size.X, (int)ss[1].size.Y-1);
for (var x = m.X; x < m.X + (int)ss[2].size.X; x += (int)ss[8].size.X)
for (var y = m.Y-(int)ss[1].size.Y; y < m.Y-1; y += (int)ss[8].size.Y)
DrawRGBA(ss[8], new float2(x, y));
if (a != null) a();
sr.Flush(); // because the scissor is changing
r.Device.DisableScissor();
}
}
}

View File

@@ -41,7 +41,7 @@ Player:
Image: pinficon
ChargeTime: 6
Description: Paratroopers
LongDesc: A Badger drops a squad of Riflemen \n anywhere on the map
LongDesc: A Badger drops a squad of Riflemen \nanywhere on the map
Prerequisites: AFLD
TechLevel: 5
DropItems: E1,E1,E1,E3,E3