|
|
|
@ -2,6 +2,7 @@ package game
@@ -2,6 +2,7 @@ package game
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"fmt" |
|
|
|
|
"image" |
|
|
|
|
"image/color" |
|
|
|
|
"math" |
|
|
|
|
"sort" |
|
|
|
@ -36,6 +37,8 @@ type lobby struct {
@@ -36,6 +37,8 @@ type lobby struct {
|
|
|
|
|
x, y int |
|
|
|
|
w, h int |
|
|
|
|
|
|
|
|
|
fullscreen bool |
|
|
|
|
|
|
|
|
|
padding float64 |
|
|
|
|
entryH float64 |
|
|
|
|
buttonBarHeight int |
|
|
|
@ -102,9 +105,9 @@ func (l *lobby) _drawBufferButtons() {
@@ -102,9 +105,9 @@ func (l *lobby) _drawBufferButtons() {
|
|
|
|
|
l.bufferButtons.Fill(frameColor) |
|
|
|
|
|
|
|
|
|
// Draw border
|
|
|
|
|
for ly := 0; ly < 2; ly++ { |
|
|
|
|
for ly := 0; ly < 1; ly++ { |
|
|
|
|
for lx := 0; lx < l.w; lx++ { |
|
|
|
|
l.bufferButtons.Set(lx, ly, triangleA) |
|
|
|
|
l.bufferButtons.Set(lx, ly, borderColor) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -115,20 +118,20 @@ func (l *lobby) _drawBufferButtons() {
@@ -115,20 +118,20 @@ func (l *lobby) _drawBufferButtons() {
|
|
|
|
|
// Draw border
|
|
|
|
|
if i > 0 { |
|
|
|
|
for ly := 0; ly < l.buttonBarHeight; ly++ { |
|
|
|
|
for lx := buttonWidth * i; lx < (buttonWidth*i)+2; lx++ { |
|
|
|
|
l.bufferButtons.Set(lx, ly, triangleA) |
|
|
|
|
for lx := buttonWidth * i; lx < (buttonWidth*i)+1; lx++ { |
|
|
|
|
l.bufferButtons.Set(lx, ly, borderColor) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
bounds := text.BoundString(mediumFont, button.label) |
|
|
|
|
|
|
|
|
|
labelColor := triangleA |
|
|
|
|
labelColor := lightCheckerColor |
|
|
|
|
|
|
|
|
|
img := ebiten.NewImage(bounds.Dx()*2, bounds.Dy()*2) |
|
|
|
|
text.Draw(img, button.label, mediumFont, 0, bounds.Dy(), labelColor) |
|
|
|
|
text.Draw(img, button.label, mediumFont, 0, standardLineHeight, labelColor) |
|
|
|
|
|
|
|
|
|
l.op.GeoM.Reset() |
|
|
|
|
l.op.GeoM.Translate(float64(buttonWidth*i)+float64((buttonWidth-bounds.Dx())/2), float64(l.buttonBarHeight-bounds.Dy())/2-float64(bounds.Dy()/2)) |
|
|
|
|
l.op.GeoM.Translate(float64(buttonWidth*i)+float64((buttonWidth-bounds.Dx())/2), float64(l.buttonBarHeight-standardLineHeight*1.5)/2) |
|
|
|
|
l.bufferButtons.DrawImage(img, l.op) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -159,53 +162,55 @@ func (l *lobby) drawBuffer() {
@@ -159,53 +162,55 @@ func (l *lobby) drawBuffer() {
|
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
var img *ebiten.Image |
|
|
|
|
drawEntry := func(cx float64, cy float64, colA string, colB string, colC string, highlight bool) { |
|
|
|
|
boundsA := text.BoundString(mediumFont, colA) |
|
|
|
|
boundsB := text.BoundString(mediumFont, colB) |
|
|
|
|
boundsC := text.BoundString(mediumFont, colC) |
|
|
|
|
y := (boundsA.Dy() + boundsB.Dy() + boundsC.Dy()) / 3 // TODO this isn't correct
|
|
|
|
|
|
|
|
|
|
drawEntry := func(cx float64, cy float64, colA string, colB string, colC string, highlight bool, title bool) { |
|
|
|
|
labelColor := triangleA |
|
|
|
|
if highlight { |
|
|
|
|
labelColor = color.RGBA{200, 200, 60, 255} |
|
|
|
|
labelColor = lightCheckerColor |
|
|
|
|
} else if title { |
|
|
|
|
labelColor = lightCheckerColor |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
selectedBorderColor := triangleB |
|
|
|
|
|
|
|
|
|
img = ebiten.NewImage(l.w-int(l.padding*2), int(l.entryH)) |
|
|
|
|
if highlight { |
|
|
|
|
highlightColor := color.RGBA{triangleA.R, triangleA.G, triangleA.B, 15} |
|
|
|
|
img.SubImage(image.Rect(0, 0, l.w, int(l.entryH))).(*ebiten.Image).Fill(highlightColor) |
|
|
|
|
|
|
|
|
|
div := 1.75 |
|
|
|
|
highlightBorderColor := color.RGBA{uint8(float64(frameColor.R) / div), uint8(float64(frameColor.G) / div), uint8(float64(frameColor.B) / div), 200} |
|
|
|
|
for x := 0; x < l.w; x++ { |
|
|
|
|
img.Set(x, 0, selectedBorderColor) |
|
|
|
|
img.Set(x, int(l.entryH)-1, selectedBorderColor) |
|
|
|
|
img.Set(x, 0, highlightBorderColor) |
|
|
|
|
img.Set(x, int(l.entryH)-1, highlightBorderColor) |
|
|
|
|
} |
|
|
|
|
for by := 0; by < int(l.entryH)-1; by++ { |
|
|
|
|
img.Set(0, by, selectedBorderColor) |
|
|
|
|
img.Set(l.w-(int(l.padding)*2)-1, by, selectedBorderColor) |
|
|
|
|
img.Set(0, by, highlightBorderColor) |
|
|
|
|
img.Set(l.w-(int(l.padding)*2)-1, by, highlightBorderColor) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
text.Draw(img, colA, mediumFont, 4, y+2, labelColor) |
|
|
|
|
text.Draw(img, colB, mediumFont, int(250*ebiten.DeviceScaleFactor()), y+2, labelColor) |
|
|
|
|
text.Draw(img, colC, mediumFont, int(500*ebiten.DeviceScaleFactor()), y+2, labelColor) |
|
|
|
|
text.Draw(img, colA, mediumFont, 4, standardLineHeight, labelColor) |
|
|
|
|
text.Draw(img, colB, mediumFont, int(250*ebiten.DeviceScaleFactor()), standardLineHeight, labelColor) |
|
|
|
|
text.Draw(img, colC, mediumFont, int(500*ebiten.DeviceScaleFactor()), standardLineHeight, labelColor) |
|
|
|
|
|
|
|
|
|
l.op.GeoM.Reset() |
|
|
|
|
l.op.GeoM.Translate(cx, cy) |
|
|
|
|
l.buffer.DrawImage(img, l.op) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
titleOffset := 2.0 |
|
|
|
|
|
|
|
|
|
if len(l.who) == 0 { |
|
|
|
|
drawEntry(l.padding, l.padding, "Loading...", "Please wait...", "Loading...", false) |
|
|
|
|
drawEntry(l.padding, l.padding-titleOffset, "Loading...", "Please wait...", "Loading...", false, true) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for ly := -3; ly < -1; ly++ { |
|
|
|
|
for lx := 0; lx < l.w-int(l.padding*2); lx++ { |
|
|
|
|
l.buffer.Set(int(l.padding)+lx, int(l.padding)+int(l.entryH)+ly, triangleA) |
|
|
|
|
for ly := -2; ly < -1; ly++ { |
|
|
|
|
for lx := 0; lx < l.w; lx++ { |
|
|
|
|
l.buffer.Set(lx, int(l.padding)+int(l.entryH)+ly, borderColor) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cx, cy := 0.0, 0.0 // Cursor
|
|
|
|
|
drawEntry(cx+l.padding, cy+l.padding, "Username", "Rating (Experience)", "Status", false) |
|
|
|
|
drawEntry(cx+l.padding, cy+l.padding-titleOffset, "Username", "Rating (Experience)", "Status", false, true) |
|
|
|
|
cy += l.entryH |
|
|
|
|
i := 0 |
|
|
|
|
for _, who := range l.who { |
|
|
|
@ -219,7 +224,7 @@ func (l *lobby) drawBuffer() {
@@ -219,7 +224,7 @@ func (l *lobby) drawBuffer() {
|
|
|
|
|
status = "Ready to play" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
drawEntry(cx+l.padding, cy+l.padding, who.Username, details, status, i == l.selected) |
|
|
|
|
drawEntry(cx+l.padding, cy+l.padding, who.Username, details, status, i == l.selected, false) |
|
|
|
|
|
|
|
|
|
cy += l.entryH |
|
|
|
|
} |
|
|
|
@ -274,7 +279,6 @@ func (l *lobby) setRect(x, y, w, h int) {
@@ -274,7 +279,6 @@ func (l *lobby) setRect(x, y, w, h int) {
|
|
|
|
|
s := ebiten.DeviceScaleFactor() |
|
|
|
|
l.padding = 4 * s |
|
|
|
|
l.entryH = 32 * s |
|
|
|
|
l.buttonBarHeight = int(200 * s) |
|
|
|
|
|
|
|
|
|
if l.w != w || l.h != h { |
|
|
|
|
l.buffer = ebiten.NewImage(w, h) |
|
|
|
|