From c0f5460d6c8b45696039c5f327c7203394c36f3e Mon Sep 17 00:00:00 2001 From: Tim Sarbin Date: Sat, 26 Oct 2019 00:06:54 -0400 Subject: [PATCH] Added smaller button. Fixed UI bugs. --- Common/Sprite.go | 2 +- Scenes/SceneMainMenu.go | 8 ++++++++ UI/Button.go | 16 ++++++++-------- UI/Font.go | 5 +++-- UI/Manager.go | 1 - 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Common/Sprite.go b/Common/Sprite.go index 011065b8..b6789366 100644 --- a/Common/Sprite.go +++ b/Common/Sprite.go @@ -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 } diff --git a/Scenes/SceneMainMenu.go b/Scenes/SceneMainMenu.go index 0223a00d..100fdf9b 100644 --- a/Scenes/SceneMainMenu.go +++ b/Scenes/SceneMainMenu.go @@ -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 } diff --git a/UI/Button.go b/UI/Button.go index 2e058ba5..c78f2a7a 100644 --- a/UI/Button.go +++ b/UI/Button.go @@ -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) } } diff --git a/UI/Font.go b/UI/Font.go index 0f94dadc..6b678f44 100644 --- a/UI/Font.go +++ b/UI/Font.go @@ -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) diff --git a/UI/Manager.go b/UI/Manager.go index 5fbee60d..af834be4 100644 --- a/UI/Manager.go +++ b/UI/Manager.go @@ -91,7 +91,6 @@ func (v *Manager) Update() { v.widgets[i].SetPressed(true) found = true } - break } else { widget.SetPressed(false) }