Updates to match new primary repo.
This commit is contained in:
115
asb.go
115
asb.go
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"log"
|
||||
"math"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
@@ -20,24 +19,30 @@ const (
|
||||
ASB_COLOR = 0x5d2f6a
|
||||
ASB_MARGIN = 10
|
||||
|
||||
ASB_GRAD_TOP = 0x9933cc
|
||||
ASB_GRAD_BOTTOM = 0x5d2f6a
|
||||
|
||||
ASB_FLAME_SCALE = 1.56
|
||||
ASB_FLAME_OFFSET = 15
|
||||
|
||||
ASB_MASK_WIDTH = 10
|
||||
ASB_MASK_HEIGHT = ASB_HEIGHT
|
||||
|
||||
//scales and offsets
|
||||
ASB_GRAD_TOP = 0x457cf1 //0xff887c //0x9933cc
|
||||
ASB_GRAD_BOTTOM = 0x2051bf //0xb6325f //0x5d2f6a
|
||||
ASB_FLAME_SCALE = 1.56
|
||||
ASB_FLAME_OFFSET = 15
|
||||
ASB_MASK_WIDTH = 10
|
||||
ASB_MASK_HEIGHT = ASB_HEIGHT
|
||||
ASB_STRFADE_XOFFSET = 80
|
||||
ASB_STRFADE_YOFFSET = 50
|
||||
ASB_STRFADE_VALUE = 0x50
|
||||
|
||||
//scoreboard ticker related
|
||||
ASB_TICK_PIXEL_SCALE = 2 //how many pixels per cycle for ticker animation
|
||||
ASB_TICK_MAX_ADJUST = 2 * ASB_HEIGHT
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed resources/images/barmask.png
|
||||
barmaskAsset_png []byte
|
||||
assetsBarmask *ebiten.Image
|
||||
|
||||
//go:embed resources/images/crown.png
|
||||
crownAsset_png []byte
|
||||
assetsCrown *ebiten.Image
|
||||
)
|
||||
|
||||
type AnimatedScoreBar struct {
|
||||
@@ -45,12 +50,16 @@ type AnimatedScoreBar struct {
|
||||
name string
|
||||
target float64
|
||||
value float64
|
||||
gradient *image.RGBA
|
||||
gradient *Gradient
|
||||
barcolors []color.RGBA
|
||||
character *Character
|
||||
flames *Flame
|
||||
barbuffer *ebiten.Image
|
||||
order int //ranking
|
||||
sf float64 //scaling factor
|
||||
crown *ebiten.Image
|
||||
leader bool
|
||||
cycle int
|
||||
}
|
||||
|
||||
func NewAnimatedScoreBar(t CharacterType, s string) *AnimatedScoreBar {
|
||||
@@ -61,17 +70,22 @@ func NewAnimatedScoreBar(t CharacterType, s string) *AnimatedScoreBar {
|
||||
sf: 1,
|
||||
ScoreImage: ebiten.NewImage(ASB_WIDTH, ASB_HEIGHT),
|
||||
barbuffer: ebiten.NewImage(ASB_WIDTH, ASB_HEIGHT),
|
||||
gradient: NewGradient(ASB_WIDTH, ASB_HEIGHT),
|
||||
character: NewCharacter(t),
|
||||
flames: NewFlame(),
|
||||
crown: ebiten.NewImageFromImage(assetsCrown),
|
||||
order: 0,
|
||||
leader: false,
|
||||
barcolors: []color.RGBA{HexToRGBA(ASB_GRAD_TOP), HexToRGBA(ASB_GRAD_BOTTOM)},
|
||||
}
|
||||
|
||||
a.character.RandomizeCycleStart()
|
||||
a.SetBarColors(a.barcolors[GRAD_IDX_TOP], a.barcolors[GRAD_IDX_BOTTOM])
|
||||
return a
|
||||
}
|
||||
|
||||
//fill bar gradient
|
||||
a.gradient = image.NewRGBA(image.Rect(0, 0, ASB_WIDTH, ASB_HEIGHT))
|
||||
FillGradient(a.gradient, a.barbuffer.Bounds().Dx(), a.barbuffer.Bounds().Dy(), HexToRGBA(ASB_GRAD_TOP), HexToRGBA(ASB_GRAD_BOTTOM))
|
||||
a.barbuffer.WritePixels(a.gradient.Pix)
|
||||
func (a *AnimatedScoreBar) RefreshBar() {
|
||||
a.barbuffer.DrawImage(a.gradient.Scene, nil)
|
||||
|
||||
//mask start of the bar for smooth edges
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
@@ -80,7 +94,6 @@ func NewAnimatedScoreBar(t CharacterType, s string) *AnimatedScoreBar {
|
||||
|
||||
//add name to the fill bar, which will gradually display as the value increases
|
||||
text.Draw(a.barbuffer, a.name, DashFont.TeamBarName, ASB_MARGIN, ASB_HEIGHT-ASB_MARGIN, color.White)
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *AnimatedScoreBar) GetCharacterType() CharacterType {
|
||||
@@ -103,22 +116,43 @@ func (a *AnimatedScoreBar) GetValue() float64 {
|
||||
return a.value
|
||||
}
|
||||
|
||||
func (a *AnimatedScoreBar) ResetLead() {
|
||||
a.leader = false
|
||||
}
|
||||
|
||||
func (a *AnimatedScoreBar) SetLead() {
|
||||
a.leader = true
|
||||
}
|
||||
|
||||
func (a *AnimatedScoreBar) Animate() {
|
||||
|
||||
a.ScoreImage.Clear()
|
||||
|
||||
a.AddFadedTeamName()
|
||||
//a.AddFadedTeamName() //peeps complained, so we cut this
|
||||
a.AddScoreBar()
|
||||
a.AddCharacter()
|
||||
a.AddTextScore()
|
||||
a.AdjustValue()
|
||||
a.AddLeadIndicator()
|
||||
|
||||
a.CycleUpdate()
|
||||
}
|
||||
|
||||
func (a *AnimatedScoreBar) CycleUpdate() {
|
||||
a.cycle++
|
||||
}
|
||||
|
||||
func (a *AnimatedScoreBar) AddLeadIndicator() {
|
||||
if a.leader {
|
||||
a.ScoreImage.DrawImage(a.crown, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *AnimatedScoreBar) AddFadedTeamName() {
|
||||
//alpha blended black for the team name
|
||||
c := HexToRGBA(0x000000)
|
||||
c.A = ASB_STRFADE_VALUE
|
||||
text.Draw(a.ScoreImage, a.name, DashFont.TeamBackgroundName, ASB_STRFADE_XOFFSET, ASB_STRFADE_YOFFSET, c)
|
||||
text.Draw(a.ScoreImage, a.name, DashFont.TeamBackgroundName, 1000, ASB_STRFADE_YOFFSET, c)
|
||||
}
|
||||
|
||||
func (a *AnimatedScoreBar) SetOrder(order int) {
|
||||
@@ -171,10 +205,34 @@ func (a *AnimatedScoreBar) AddCharacter() {
|
||||
}
|
||||
|
||||
func (a *AnimatedScoreBar) AddTextScore() {
|
||||
var ypos int
|
||||
M := ASB_HEIGHT
|
||||
tx := int(a.value*a.sf) + ASB_BUFFER + a.character.GetWidth()
|
||||
ty := ASB_HEIGHT
|
||||
text.Draw(a.ScoreImage, fmt.Sprintf("%0.f", a.value), DashFont.Title, tx, ty, color.White)
|
||||
text.Draw(a.ScoreImage, "POINTS", DashFont.Title, tx+ASB_BUFFER*7, ty, color.White)
|
||||
|
||||
//animate ticker movement for the team name
|
||||
adjust := ASB_TICK_MAX_ADJUST //max adjustment
|
||||
if a.cycle%adjust < M/ASB_TICK_PIXEL_SCALE {
|
||||
ypos = 2*M - ASB_TICK_PIXEL_SCALE*a.cycle%adjust
|
||||
} else if a.cycle%adjust > 2*M/ASB_TICK_PIXEL_SCALE {
|
||||
ypos = M - (ASB_TICK_PIXEL_SCALE*(a.cycle-2*M/ASB_TICK_PIXEL_SCALE))%adjust
|
||||
} else {
|
||||
ypos = M
|
||||
}
|
||||
text.Draw(a.ScoreImage, a.name, DashFont.Title, tx, ypos, color.White)
|
||||
|
||||
//now do the same for the points, offset by the height of the ticker
|
||||
bcycle := a.cycle - M/ASB_TICK_PIXEL_SCALE
|
||||
adjust = 2 * M
|
||||
if bcycle%adjust < 2*M/ASB_TICK_PIXEL_SCALE {
|
||||
ypos = 3*M - ASB_TICK_PIXEL_SCALE*bcycle%adjust
|
||||
} else if bcycle%adjust > 3*M/ASB_TICK_PIXEL_SCALE {
|
||||
ypos = M - (ASB_TICK_PIXEL_SCALE*(bcycle-3*M/ASB_TICK_PIXEL_SCALE))%adjust //M - (pixel_scale*(bcycle-2*M/pixel_scale))%ma
|
||||
} else {
|
||||
ypos = M
|
||||
}
|
||||
text.Draw(a.ScoreImage, fmt.Sprintf("%0.f", a.value), DashFont.Title, tx, ypos, color.White)
|
||||
text.Draw(a.ScoreImage, "POINTS", DashFont.Title, tx+ASB_BUFFER*7, ypos, color.White)
|
||||
|
||||
}
|
||||
|
||||
func (a *AnimatedScoreBar) AdjustValue() {
|
||||
@@ -183,6 +241,7 @@ func (a *AnimatedScoreBar) AdjustValue() {
|
||||
}
|
||||
}
|
||||
|
||||
// set our point scale factor (scalefactor = pixels per score point)
|
||||
func (a *AnimatedScoreBar) SetScaleFactor(sf float64) {
|
||||
a.sf = sf
|
||||
}
|
||||
@@ -194,7 +253,19 @@ func (a *AnimatedScoreBar) Reset() {
|
||||
func init() {
|
||||
img, _, err := image.Decode(bytes.NewReader(barmaskAsset_png))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
DashLogger.Fatal(err)
|
||||
}
|
||||
assetsBarmask = ebiten.NewImageFromImage(img)
|
||||
|
||||
img, _, err = image.Decode(bytes.NewReader(crownAsset_png))
|
||||
if err != nil {
|
||||
DashLogger.Fatal(err)
|
||||
}
|
||||
assetsCrown = ebiten.NewImageFromImage(img)
|
||||
}
|
||||
|
||||
func (a *AnimatedScoreBar) SetBarColors(top, bottom color.RGBA) {
|
||||
//fill bar gradient
|
||||
a.gradient.SetColors(top, bottom)
|
||||
a.RefreshBar()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user