Added smaller button. Fixed UI bugs.

This commit is contained in:
Tim Sarbin 2019-10-26 00:06:54 -04:00
parent 054329cf1f
commit c0f5460d6c
5 changed files with 20 additions and 12 deletions

View File

@ -179,7 +179,7 @@ func (v *Sprite) Draw(target *ebiten.Image) {
float64((int32(v.Y) - int32(frame.Height) + frame.OffsetY)),
)
if v.Blend {
opts.CompositeMode = ebiten.CompositeModeSourceOver
opts.CompositeMode = ebiten.CompositeModeLighter
} else {
opts.CompositeMode = ebiten.CompositeModeSourceOver
}

View File

@ -25,6 +25,7 @@ type MainMenu struct {
diabloLogoLeftBack *Common.Sprite
diabloLogoRightBack *Common.Sprite
exitDiabloButton *UI.Button
creditsButton *UI.Button
copyrightLabel *UI.Label
copyrightLabel2 *UI.Label
showTrademarkScreen bool
@ -95,6 +96,12 @@ func (v *MainMenu) Load() []func() {
v.exitDiabloButton.OnActivated(func() { v.onExitButtonClicked() })
v.uiManager.AddWidget(v.exitDiabloButton)
},
func() {
v.creditsButton = UI.CreateButton(UI.ButtonTypeShort, v.fileProvider, "CREDITS")
v.creditsButton.MoveTo(264, 505)
v.creditsButton.SetVisible(false)
v.uiManager.AddWidget(v.creditsButton)
},
}
}
@ -134,6 +141,7 @@ func (v *MainMenu) Update() {
v.leftButtonHeld = true
v.showTrademarkScreen = false
v.exitDiabloButton.SetVisible(true)
v.creditsButton.SetVisible(true)
}
return
}

View File

@ -109,8 +109,8 @@ func CreateButton(buttonType ButtonType, fileProvider Common.FileProvider, text
pressed: false,
}
buttonLayout := ButtonLayouts[buttonType]
font := GetFont(buttonLayout.FontPath, buttonLayout.PaletteName, fileProvider)
buttonSprite := fileProvider.LoadSprite(ResourcePaths.WideButtonBlank, Palettes.Units)
font := GetFont(buttonLayout.FontPath, Palettes.Units, fileProvider)
buttonSprite := fileProvider.LoadSprite(buttonLayout.ResourceName, buttonLayout.PaletteName)
totalButtonTypes := buttonSprite.GetTotalFrames() / (buttonLayout.XSegments * buttonLayout.YSegments)
for i := 0; i < buttonLayout.XSegments; i++ {
w, _ := buttonSprite.GetFrameSize(i)
@ -125,26 +125,26 @@ func CreateButton(buttonType ButtonType, fileProvider Common.FileProvider, text
result.pressedImage, _ = ebiten.NewImage(int(result.width), int(result.height), ebiten.FilterNearest)
textWidth, textHeight := font.GetTextMetrics(text)
textX := (result.width / 2) - (textWidth / 2)
textY := (result.height / 2) - (textHeight / 2) + 5
textY := (result.height / 2) - (textHeight / 2) + 1
buttonSprite.MoveTo(0, 0)
buttonSprite.Blend = true
buttonSprite.DrawSegments(result.normalImage, 2, 1, buttonLayout.BaseFrame)
buttonSprite.DrawSegments(result.normalImage, buttonLayout.XSegments, buttonLayout.YSegments, buttonLayout.BaseFrame)
font.Draw(int(textX), int(textY), text, color.RGBA{100, 100, 100, 255}, result.normalImage)
if buttonLayout.AllowFrameChange {
if totalButtonTypes > 1 {
buttonSprite.DrawSegments(result.pressedImage, 2, 1, buttonLayout.BaseFrame+1)
buttonSprite.DrawSegments(result.pressedImage, buttonLayout.XSegments, buttonLayout.YSegments, buttonLayout.BaseFrame+1)
font.Draw(int(textX-2), int(textY+2), text, color.RGBA{100, 100, 100, 255}, result.pressedImage)
}
if totalButtonTypes > 2 {
buttonSprite.DrawSegments(result.toggledImage, 2, 1, buttonLayout.BaseFrame+2)
buttonSprite.DrawSegments(result.toggledImage, buttonLayout.XSegments, buttonLayout.YSegments, buttonLayout.BaseFrame+2)
font.Draw(int(textX), int(textY), text, color.RGBA{100, 100, 100, 255}, result.toggledImage)
}
if totalButtonTypes > 3 {
buttonSprite.DrawSegments(result.pressedToggledImage, 2, 1, buttonLayout.BaseFrame+3)
buttonSprite.DrawSegments(result.pressedToggledImage, buttonLayout.XSegments, buttonLayout.YSegments, buttonLayout.BaseFrame+3)
font.Draw(int(textX), int(textY), text, color.RGBA{100, 100, 100, 255}, result.pressedToggledImage)
}
if buttonLayout.DisabledFrame != -1 {
buttonSprite.DrawSegments(result.disabledImage, 2, 1, buttonLayout.DisabledFrame)
buttonSprite.DrawSegments(result.disabledImage, buttonLayout.XSegments, buttonLayout.YSegments, buttonLayout.DisabledFrame)
font.Draw(int(textX), int(textY), text, color.RGBA{100, 100, 100, 255}, result.disabledImage)
}
}

View File

@ -61,7 +61,8 @@ func (v *Font) GetTextMetrics(text string) (width, height uint32) {
for _, ch := range text {
metric := v.metrics[uint8(ch)]
width += uint32(metric.Width)
height = Common.Max(height, uint32(metric.Height))
_, h := v.fontSprite.GetFrameSize(int(ch))
height = Common.Max(height, h)
}
return
}
@ -69,7 +70,7 @@ func (v *Font) GetTextMetrics(text string) (width, height uint32) {
// Draw draws the font on the target surface
func (v *Font) Draw(x, y int, text string, color color.Color, target *ebiten.Image) {
v.fontSprite.ColorMod = color
v.fontSprite.Blend = true
v.fontSprite.Blend = false
_, height := v.GetTextMetrics(text)
for _, ch := range text {
char := uint8(ch)

View File

@ -91,7 +91,6 @@ func (v *Manager) Update() {
v.widgets[i].SetPressed(true)
found = true
}
break
} else {
widget.SetPressed(false)
}