mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-10 14:26:15 -05:00
Merge pull request #914 from juander-ux/drawable-refactor
d2ui/drawable refactor
This commit is contained in:
commit
2035a62ec6
@ -1,7 +1,6 @@
|
|||||||
package d2ui
|
package d2ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"image"
|
"image"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
@ -332,11 +331,8 @@ func (v *Button) prerenderStates(btnSprite *Sprite, btnLayout *ButtonLayout, lab
|
|||||||
|
|
||||||
// buttons always have a base image
|
// buttons always have a base image
|
||||||
if v.buttonLayout.HasImage {
|
if v.buttonLayout.HasImage {
|
||||||
err := btnSprite.RenderSegmented(v.normalSurface, btnLayout.XSegments,
|
btnSprite.RenderSegmented(v.normalSurface, btnLayout.XSegments,
|
||||||
btnLayout.YSegments, btnLayout.BaseFrame)
|
btnLayout.YSegments, btnLayout.BaseFrame)
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("failed to render button normalSurface, err: %v\n", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, labelHeight := label.GetSize()
|
_, labelHeight := label.GetSize()
|
||||||
@ -344,7 +340,7 @@ func (v *Button) prerenderStates(btnSprite *Sprite, btnLayout *ButtonLayout, lab
|
|||||||
xOffset := half(v.width)
|
xOffset := half(v.width)
|
||||||
|
|
||||||
label.SetPosition(xOffset, textY)
|
label.SetPosition(xOffset, textY)
|
||||||
label.RenderNoError(v.normalSurface)
|
label.Render(v.normalSurface)
|
||||||
|
|
||||||
if !btnLayout.HasImage || !btnLayout.AllowFrameChange {
|
if !btnLayout.HasImage || !btnLayout.AllowFrameChange {
|
||||||
return
|
return
|
||||||
@ -412,13 +408,10 @@ func (v *Button) prerenderStates(btnSprite *Sprite, btnLayout *ButtonLayout, lab
|
|||||||
|
|
||||||
*state.prerenderdestination = surface
|
*state.prerenderdestination = surface
|
||||||
|
|
||||||
err := btnSprite.RenderSegmented(*state.prerenderdestination, xSeg, ySeg, state.baseFrame)
|
btnSprite.RenderSegmented(*state.prerenderdestination, xSeg, ySeg, state.baseFrame)
|
||||||
if err != nil {
|
|
||||||
fmt.Printf(state.fmtErr, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
label.SetPosition(state.offsetX, state.offsetY)
|
label.SetPosition(state.offsetX, state.offsetY)
|
||||||
label.RenderNoError(*state.prerenderdestination)
|
label.Render(*state.prerenderdestination)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,7 +430,7 @@ func (v *Button) Activate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Render renders the button
|
// Render renders the button
|
||||||
func (v *Button) Render(target d2interface.Surface) error {
|
func (v *Button) Render(target d2interface.Surface) {
|
||||||
target.PushFilter(d2enum.FilterNearest)
|
target.PushFilter(d2enum.FilterNearest)
|
||||||
defer target.Pop()
|
defer target.Pop()
|
||||||
|
|
||||||
@ -462,8 +455,6 @@ func (v *Button) Render(target d2interface.Surface) error {
|
|||||||
default:
|
default:
|
||||||
target.Render(v.normalSurface)
|
target.Render(v.normalSurface)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Toggle negates the toggled state of the button
|
// Toggle negates the toggled state of the button
|
||||||
|
@ -49,19 +49,11 @@ func (ui *UIManager) NewCheckbox(checkState bool) *Checkbox {
|
|||||||
|
|
||||||
result.Image = ui.renderer.NewSurface(result.width, result.height)
|
result.Image = ui.renderer.NewSurface(result.width, result.height)
|
||||||
|
|
||||||
err = checkboxSprite.RenderSegmented(result.Image, 1, 1, 0)
|
checkboxSprite.RenderSegmented(result.Image, 1, 1, 0)
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
result.checkedImage = ui.renderer.NewSurface(result.width, result.height)
|
result.checkedImage = ui.renderer.NewSurface(result.width, result.height)
|
||||||
|
|
||||||
err = checkboxSprite.RenderSegmented(result.checkedImage, 1, 1, 1)
|
checkboxSprite.RenderSegmented(result.checkedImage, 1, 1, 1)
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.addWidget(result)
|
ui.addWidget(result)
|
||||||
|
|
||||||
@ -69,7 +61,7 @@ func (ui *UIManager) NewCheckbox(checkState bool) *Checkbox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Render renders the checkbox
|
// Render renders the checkbox
|
||||||
func (v *Checkbox) Render(target d2interface.Surface) error {
|
func (v *Checkbox) Render(target d2interface.Surface) {
|
||||||
target.PushTranslation(v.x, v.y)
|
target.PushTranslation(v.x, v.y)
|
||||||
defer target.Pop()
|
defer target.Pop()
|
||||||
|
|
||||||
@ -81,8 +73,6 @@ func (v *Checkbox) Render(target d2interface.Surface) error {
|
|||||||
} else {
|
} else {
|
||||||
target.Render(v.Image)
|
target.Render(v.Image)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Advance does nothing for checkboxes
|
// Advance does nothing for checkboxes
|
||||||
|
@ -8,11 +8,11 @@ var _ Widget = &CustomWidget{}
|
|||||||
// CustomWidget is a widget with a fully custom render function
|
// CustomWidget is a widget with a fully custom render function
|
||||||
type CustomWidget struct {
|
type CustomWidget struct {
|
||||||
*BaseWidget
|
*BaseWidget
|
||||||
renderFunc func(target d2interface.Surface) error
|
renderFunc func(target d2interface.Surface)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCustomWidget creates a new widget with custom render function
|
// NewCustomWidget creates a new widget with custom render function
|
||||||
func (ui *UIManager) NewCustomWidget(renderFunc func(target d2interface.Surface) error) *CustomWidget {
|
func (ui *UIManager) NewCustomWidget(renderFunc func(target d2interface.Surface)) *CustomWidget {
|
||||||
base := NewBaseWidget(ui)
|
base := NewBaseWidget(ui)
|
||||||
|
|
||||||
return &CustomWidget{
|
return &CustomWidget{
|
||||||
@ -22,8 +22,8 @@ func (ui *UIManager) NewCustomWidget(renderFunc func(target d2interface.Surface)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Render draws the custom widget
|
// Render draws the custom widget
|
||||||
func (c *CustomWidget) Render(target d2interface.Surface) error {
|
func (c *CustomWidget) Render(target d2interface.Surface) {
|
||||||
return c.renderFunc(target)
|
c.renderFunc(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Advance is a no-op
|
// Advance is a no-op
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
|
|
||||||
// Drawable represents an instance that can be drawn
|
// Drawable represents an instance that can be drawn
|
||||||
type Drawable interface {
|
type Drawable interface {
|
||||||
Render(target d2interface.Surface) error
|
Render(target d2interface.Surface)
|
||||||
Advance(elapsed float64) error
|
Advance(elapsed float64) error
|
||||||
GetSize() (width, height int)
|
GetSize() (width, height int)
|
||||||
SetPosition(x, y int)
|
SetPosition(x, y int)
|
||||||
|
@ -83,15 +83,17 @@ func (u *UIFrame) Load() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Render the frame to the target surface
|
// Render the frame to the target surface
|
||||||
func (u *UIFrame) Render(target d2interface.Surface) error {
|
func (u *UIFrame) Render(target d2interface.Surface) {
|
||||||
switch u.frameOrientation {
|
switch u.frameOrientation {
|
||||||
case FrameLeft:
|
case FrameLeft:
|
||||||
return u.renderLeft(target)
|
if err := u.renderLeft(target); err != nil {
|
||||||
|
log.Printf("Render error %e", err)
|
||||||
|
}
|
||||||
case FrameRight:
|
case FrameRight:
|
||||||
return u.renderRight(target)
|
if err := u.renderRight(target); err != nil {
|
||||||
|
log.Printf("Render error %e", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UIFrame) renderLeft(target d2interface.Surface) error {
|
func (u *UIFrame) renderLeft(target d2interface.Surface) error {
|
||||||
@ -227,7 +229,7 @@ func (u *UIFrame) renderFramePiece(sfc d2interface.Surface, x, y, idx int) error
|
|||||||
|
|
||||||
u.frame.SetPosition(x, y)
|
u.frame.SetPosition(x, y)
|
||||||
|
|
||||||
u.frame.RenderNoError(sfc)
|
u.frame.Render(sfc)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,6 @@ import (
|
|||||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui"
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui"
|
||||||
)
|
)
|
||||||
|
|
||||||
// static check that UIFrame implements Widget
|
|
||||||
var _ Widget = &Label{}
|
|
||||||
|
|
||||||
// Label represents a user interface label
|
// Label represents a user interface label
|
||||||
type Label struct {
|
type Label struct {
|
||||||
*BaseWidget
|
*BaseWidget
|
||||||
@ -48,14 +45,8 @@ func (ui *UIManager) NewLabel(fontPath, palettePath string) *Label {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render draws the label on the screen
|
// Render draws the label on the screen, respliting the lines to allow for other alignments.
|
||||||
func (v *Label) Render(target d2interface.Surface) error {
|
func (v *Label) Render(target d2interface.Surface) {
|
||||||
v.RenderNoError(target)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// RenderNoError draws the label on the screen, respliting the lines to allow for other alignments.
|
|
||||||
func (v *Label) RenderNoError(target d2interface.Surface) {
|
|
||||||
target.PushTranslation(v.GetPosition())
|
target.PushTranslation(v.GetPosition())
|
||||||
|
|
||||||
lines := strings.Split(v.text, "\n")
|
lines := strings.Split(v.text, "\n")
|
||||||
|
@ -106,9 +106,9 @@ func (v *Scrollbar) GetLastDirChange() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Render renders the scrollbar to the given surface
|
// Render renders the scrollbar to the given surface
|
||||||
func (v *Scrollbar) Render(target d2interface.Surface) error {
|
func (v *Scrollbar) Render(target d2interface.Surface) {
|
||||||
if !v.visible || v.maxOffset == 0 {
|
if !v.visible || v.maxOffset == 0 {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
offset := 0
|
offset := 0
|
||||||
@ -119,18 +119,14 @@ func (v *Scrollbar) Render(target d2interface.Surface) error {
|
|||||||
|
|
||||||
v.scrollbarSprite.SetPosition(v.x, v.y)
|
v.scrollbarSprite.SetPosition(v.x, v.y)
|
||||||
|
|
||||||
if err := v.scrollbarSprite.RenderSegmented(target, 1, 1, 0+offset); err != nil {
|
v.scrollbarSprite.RenderSegmented(target, 1, 1, 0+offset)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
v.scrollbarSprite.SetPosition(v.x, v.y+v.height-scrollbarSpriteOffsetY) // what is the magic?
|
v.scrollbarSprite.SetPosition(v.x, v.y+v.height-scrollbarSpriteOffsetY) // what is the magic?
|
||||||
|
|
||||||
if err := v.scrollbarSprite.RenderSegmented(target, 1, 1, 1+offset); err != nil {
|
v.scrollbarSprite.RenderSegmented(target, 1, 1, 1+offset)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if v.maxOffset == 0 || v.currentOffset < 0 || v.currentOffset > v.maxOffset {
|
if v.maxOffset == 0 || v.currentOffset < 0 || v.currentOffset > v.maxOffset {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
v.scrollbarSprite.SetPosition(v.x, v.y+10+v.getBarPosition())
|
v.scrollbarSprite.SetPosition(v.x, v.y+10+v.getBarPosition())
|
||||||
@ -141,11 +137,7 @@ func (v *Scrollbar) Render(target d2interface.Surface) error {
|
|||||||
offset++
|
offset++
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := v.scrollbarSprite.RenderSegmented(target, 1, 1, offset); err != nil {
|
v.scrollbarSprite.RenderSegmented(target, 1, 1, offset)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Advance advances the scrollbar sprite
|
// Advance advances the scrollbar sprite
|
||||||
|
@ -11,9 +11,6 @@ import (
|
|||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
|
||||||
)
|
)
|
||||||
|
|
||||||
// static check that Sprite implements Widget
|
|
||||||
var _ Widget = &Sprite{}
|
|
||||||
|
|
||||||
// Sprite is a positioned visual object.
|
// Sprite is a positioned visual object.
|
||||||
type Sprite struct {
|
type Sprite struct {
|
||||||
*BaseWidget
|
*BaseWidget
|
||||||
@ -41,13 +38,7 @@ func (ui *UIManager) NewSprite(animationPath, palettePath string) (*Sprite, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Render renders the sprite on the given surface
|
// Render renders the sprite on the given surface
|
||||||
func (s *Sprite) Render(target d2interface.Surface) error {
|
func (s *Sprite) Render(target d2interface.Surface) {
|
||||||
s.RenderNoError(target)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// RenderNoError renders the sprite on the given surface
|
|
||||||
func (s *Sprite) RenderNoError(target d2interface.Surface) {
|
|
||||||
_, frameHeight := s.animation.GetCurrentFrameSize()
|
_, frameHeight := s.animation.GetCurrentFrameSize()
|
||||||
|
|
||||||
target.PushTranslation(s.x, s.y-frameHeight)
|
target.PushTranslation(s.x, s.y-frameHeight)
|
||||||
@ -65,7 +56,7 @@ func (s *Sprite) RenderSection(sfc d2interface.Surface, bound image.Rectangle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RenderSegmented renders a sprite that is internally segmented as frames
|
// RenderSegmented renders a sprite that is internally segmented as frames
|
||||||
func (s *Sprite) RenderSegmented(target d2interface.Surface, segmentsX, segmentsY, frameOffset int) error {
|
func (s *Sprite) RenderSegmented(target d2interface.Surface, segmentsX, segmentsY, frameOffset int) {
|
||||||
var currentY int
|
var currentY int
|
||||||
|
|
||||||
for y := 0; y < segmentsY; y++ {
|
for y := 0; y < segmentsY; y++ {
|
||||||
@ -74,7 +65,7 @@ func (s *Sprite) RenderSegmented(target d2interface.Surface, segmentsX, segments
|
|||||||
for x := 0; x < segmentsX; x++ {
|
for x := 0; x < segmentsX; x++ {
|
||||||
idx := x + y*segmentsX + frameOffset*segmentsX*segmentsY
|
idx := x + y*segmentsX + frameOffset*segmentsX*segmentsY
|
||||||
if err := s.animation.SetCurrentFrame(idx); err != nil {
|
if err := s.animation.SetCurrentFrame(idx); err != nil {
|
||||||
return err
|
log.Printf("SetCurrentFrame error %e", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
target.PushTranslation(s.x+currentX, s.y+currentY)
|
target.PushTranslation(s.x+currentX, s.y+currentY)
|
||||||
@ -88,8 +79,6 @@ func (s *Sprite) RenderSegmented(target d2interface.Surface, segmentsX, segments
|
|||||||
|
|
||||||
currentY += maxFrameHeight
|
currentY += maxFrameHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSize returns the size of the current frame
|
// GetSize returns the size of the current frame
|
||||||
|
@ -56,19 +56,17 @@ func (v *TextBox) SetFilter(filter string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Render renders the text box
|
// Render renders the text box
|
||||||
func (v *TextBox) Render(target d2interface.Surface) error {
|
func (v *TextBox) Render(target d2interface.Surface) {
|
||||||
if !v.visible {
|
if !v.visible {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
v.bgSprite.RenderNoError(target)
|
v.bgSprite.Render(target)
|
||||||
v.textLabel.RenderNoError(target)
|
v.textLabel.Render(target)
|
||||||
|
|
||||||
if (time.Now().UnixNano()/1e6)&(1<<8) > 0 {
|
if (time.Now().UnixNano()/1e6)&(1<<8) > 0 {
|
||||||
v.lineBar.RenderNoError(target)
|
v.lineBar.Render(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnKeyChars handles key character events
|
// OnKeyChars handles key character events
|
||||||
|
@ -140,7 +140,7 @@ func (t *Tooltip) GetSize() (sx, sy int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Render draws the tooltip
|
// Render draws the tooltip
|
||||||
func (t *Tooltip) Render(target d2interface.Surface) error {
|
func (t *Tooltip) Render(target d2interface.Surface) {
|
||||||
maxW, maxH := t.GetSize()
|
maxW, maxH := t.GetSize()
|
||||||
|
|
||||||
// nolint:gomnd // no magic numbers, their meaning is obvious
|
// nolint:gomnd // no magic numbers, their meaning is obvious
|
||||||
@ -187,13 +187,11 @@ func (t *Tooltip) Render(target d2interface.Surface) error {
|
|||||||
for i := range t.lines {
|
for i := range t.lines {
|
||||||
t.label.SetText(t.lines[i])
|
t.label.SetText(t.lines[i])
|
||||||
_, h := t.label.GetTextMetrics(t.lines[i])
|
_, h := t.label.GetTextMetrics(t.lines[i])
|
||||||
t.label.RenderNoError(target)
|
t.label.Render(target)
|
||||||
target.PushTranslation(0, h)
|
target.PushTranslation(0, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
target.PopN(len(t.lines))
|
target.PopN(len(t.lines))
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Advance is a no-op
|
// Advance is a no-op
|
||||||
|
@ -124,19 +124,13 @@ func (ui *UIManager) OnMouseButtonDown(event d2interface.MouseEvent) bool {
|
|||||||
func (ui *UIManager) Render(target d2interface.Surface) {
|
func (ui *UIManager) Render(target d2interface.Surface) {
|
||||||
for _, widget := range ui.widgets {
|
for _, widget := range ui.widgets {
|
||||||
if widget.GetVisible() {
|
if widget.GetVisible() {
|
||||||
err := widget.Render(target)
|
widget.Render(target)
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, widgetGroup := range ui.widgetsGroups {
|
for _, widgetGroup := range ui.widgetsGroups {
|
||||||
if widgetGroup.GetVisible() {
|
if widgetGroup.GetVisible() {
|
||||||
err := widgetGroup.Render(target)
|
widgetGroup.Render(target)
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,17 +71,12 @@ func (wg *WidgetGroup) Advance(elapsed float64) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Render draw the widgets to the screen
|
// Render draw the widgets to the screen
|
||||||
func (wg *WidgetGroup) Render(target d2interface.Surface) error {
|
func (wg *WidgetGroup) Render(target d2interface.Surface) {
|
||||||
for _, entry := range wg.entries {
|
for _, entry := range wg.entries {
|
||||||
if entry.GetVisible() {
|
if entry.GetVisible() {
|
||||||
err := entry.Render(target)
|
entry.Render(target)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetVisible sets the visibility of all widgets in the group
|
// SetVisible sets the visibility of all widgets in the group
|
||||||
|
@ -369,17 +369,13 @@ func (v *CharacterSelect) onExitButtonClicked() {
|
|||||||
|
|
||||||
// Render renders the Character Select screen
|
// Render renders the Character Select screen
|
||||||
func (v *CharacterSelect) Render(screen d2interface.Surface) {
|
func (v *CharacterSelect) Render(screen d2interface.Surface) {
|
||||||
if err := v.background.RenderSegmented(screen, 4, 3, 0); err != nil {
|
v.background.RenderSegmented(screen, 4, 3, 0)
|
||||||
return
|
v.d2HeroTitle.Render(screen)
|
||||||
}
|
|
||||||
|
|
||||||
v.d2HeroTitle.RenderNoError(screen)
|
|
||||||
actualSelectionIndex := v.selectedCharacter - (v.charScrollbar.GetCurrentOffset() * 2)
|
actualSelectionIndex := v.selectedCharacter - (v.charScrollbar.GetCurrentOffset() * 2)
|
||||||
|
|
||||||
if v.selectedCharacter > -1 && actualSelectionIndex >= 0 && actualSelectionIndex < 8 {
|
if v.selectedCharacter > -1 && actualSelectionIndex >= 0 && actualSelectionIndex < 8 {
|
||||||
if err := v.selectionBox.RenderSegmented(screen, 2, 1, 0); err != nil {
|
v.selectionBox.RenderSegmented(screen, 2, 1, 0)
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < 8; i++ {
|
for i := 0; i < 8; i++ {
|
||||||
@ -388,9 +384,9 @@ func (v *CharacterSelect) Render(screen d2interface.Surface) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
v.characterNameLabel[i].RenderNoError(screen)
|
v.characterNameLabel[i].Render(screen)
|
||||||
v.characterStatsLabel[i].RenderNoError(screen)
|
v.characterStatsLabel[i].Render(screen)
|
||||||
v.characterExpLabel[i].RenderNoError(screen)
|
v.characterExpLabel[i].Render(screen)
|
||||||
|
|
||||||
x, y := v.characterNameLabel[i].GetPosition()
|
x, y := v.characterNameLabel[i].GetPosition()
|
||||||
charImgX := x - selectionBoxImageOffsetX
|
charImgX := x - selectionBoxImageOffsetX
|
||||||
@ -402,12 +398,8 @@ func (v *CharacterSelect) Render(screen d2interface.Surface) {
|
|||||||
|
|
||||||
if v.showDeleteConfirmation {
|
if v.showDeleteConfirmation {
|
||||||
screen.DrawRect(screenWidth, screenHeight, rgbaColor(blackHalfOpacity))
|
screen.DrawRect(screenWidth, screenHeight, rgbaColor(blackHalfOpacity))
|
||||||
|
v.okCancelBox.RenderSegmented(screen, 2, 1, 0)
|
||||||
if err := v.okCancelBox.RenderSegmented(screen, 2, 1, 0); err != nil {
|
v.deleteCharConfirmLabel.Render(screen)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
v.deleteCharConfirmLabel.RenderNoError(screen)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,21 +183,7 @@ func (v *Cinematics) playVideo(path string) {
|
|||||||
|
|
||||||
// Render renders the credits screen
|
// Render renders the credits screen
|
||||||
func (v *Cinematics) Render(screen d2interface.Surface) {
|
func (v *Cinematics) Render(screen d2interface.Surface) {
|
||||||
err := v.background.RenderSegmented(screen, 4, 3, 0)
|
v.background.RenderSegmented(screen, 4, 3, 0)
|
||||||
|
v.cinematicsBackground.RenderSegmented(screen, 2, 2, 0)
|
||||||
if err != nil {
|
v.cinematicsLabel.Render(screen)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = v.cinematicsBackground.RenderSegmented(screen, 2, 2, 0)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = v.cinematicsLabel.Render(screen)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -129,17 +129,14 @@ func (v *Credits) OnLoad(loading d2screen.LoadingState) {
|
|||||||
|
|
||||||
// Render renders the credits screen
|
// Render renders the credits screen
|
||||||
func (v *Credits) Render(screen d2interface.Surface) {
|
func (v *Credits) Render(screen d2interface.Surface) {
|
||||||
err := v.creditsBackground.RenderSegmented(screen, 4, 3, 0)
|
v.creditsBackground.RenderSegmented(screen, 4, 3, 0)
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, label := range v.labels {
|
for _, label := range v.labels {
|
||||||
if label.Available {
|
if label.Available {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
label.Label.RenderNoError(screen)
|
label.Label.Render(screen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,56 +436,45 @@ func (v *MainMenu) Render(screen d2interface.Surface) {
|
|||||||
func (v *MainMenu) renderBackgrounds(screen d2interface.Surface) {
|
func (v *MainMenu) renderBackgrounds(screen d2interface.Surface) {
|
||||||
switch v.screenMode {
|
switch v.screenMode {
|
||||||
case ScreenModeTrademark:
|
case ScreenModeTrademark:
|
||||||
if err := v.trademarkBackground.RenderSegmented(screen, 4, 3, 0); err != nil {
|
v.trademarkBackground.RenderSegmented(screen, 4, 3, 0)
|
||||||
return
|
|
||||||
}
|
|
||||||
case ScreenModeServerIP:
|
case ScreenModeServerIP:
|
||||||
if err := v.tcpIPBackground.RenderSegmented(screen, 4, 3, 0); err != nil {
|
v.tcpIPBackground.RenderSegmented(screen, 4, 3, 0)
|
||||||
return
|
v.serverIPBackground.RenderSegmented(screen, 2, 1, 0)
|
||||||
}
|
|
||||||
|
|
||||||
if err := v.serverIPBackground.RenderSegmented(screen, 2, 1, 0); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
case ScreenModeTCPIP:
|
case ScreenModeTCPIP:
|
||||||
if err := v.tcpIPBackground.RenderSegmented(screen, 4, 3, 0); err != nil {
|
v.tcpIPBackground.RenderSegmented(screen, 4, 3, 0)
|
||||||
return
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
if err := v.background.RenderSegmented(screen, 4, 3, 0); err != nil {
|
v.background.RenderSegmented(screen, 4, 3, 0)
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *MainMenu) renderLogos(screen d2interface.Surface) {
|
func (v *MainMenu) renderLogos(screen d2interface.Surface) {
|
||||||
switch v.screenMode {
|
switch v.screenMode {
|
||||||
case ScreenModeTrademark, ScreenModeMainMenu, ScreenModeMultiplayer:
|
case ScreenModeTrademark, ScreenModeMainMenu, ScreenModeMultiplayer:
|
||||||
v.diabloLogoLeftBack.RenderNoError(screen)
|
v.diabloLogoLeftBack.Render(screen)
|
||||||
v.diabloLogoRightBack.RenderNoError(screen)
|
v.diabloLogoRightBack.Render(screen)
|
||||||
v.diabloLogoLeft.RenderNoError(screen)
|
v.diabloLogoLeft.Render(screen)
|
||||||
v.diabloLogoRight.RenderNoError(screen)
|
v.diabloLogoRight.Render(screen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *MainMenu) renderLabels(screen d2interface.Surface) {
|
func (v *MainMenu) renderLabels(screen d2interface.Surface) {
|
||||||
switch v.screenMode {
|
switch v.screenMode {
|
||||||
case ScreenModeServerIP:
|
case ScreenModeServerIP:
|
||||||
v.tcpIPOptionsLabel.RenderNoError(screen)
|
v.tcpIPOptionsLabel.Render(screen)
|
||||||
v.tcpJoinGameLabel.RenderNoError(screen)
|
v.tcpJoinGameLabel.Render(screen)
|
||||||
case ScreenModeTCPIP:
|
case ScreenModeTCPIP:
|
||||||
v.tcpIPOptionsLabel.RenderNoError(screen)
|
v.tcpIPOptionsLabel.Render(screen)
|
||||||
case ScreenModeTrademark:
|
case ScreenModeTrademark:
|
||||||
v.copyrightLabel.RenderNoError(screen)
|
v.copyrightLabel.Render(screen)
|
||||||
v.copyrightLabel2.RenderNoError(screen)
|
v.copyrightLabel2.Render(screen)
|
||||||
|
|
||||||
if v.errorLabel != nil {
|
if v.errorLabel != nil {
|
||||||
v.errorLabel.RenderNoError(screen)
|
v.errorLabel.Render(screen)
|
||||||
}
|
}
|
||||||
case ScreenModeMainMenu:
|
case ScreenModeMainMenu:
|
||||||
v.openDiabloLabel.RenderNoError(screen)
|
v.openDiabloLabel.Render(screen)
|
||||||
v.versionLabel.RenderNoError(screen)
|
v.versionLabel.Render(screen)
|
||||||
v.commitLabel.RenderNoError(screen)
|
v.commitLabel.Render(screen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -511,17 +511,14 @@ func (v *SelectHeroClass) onOkButtonClicked() {
|
|||||||
|
|
||||||
// Render renders the Select Hero Class screen
|
// Render renders the Select Hero Class screen
|
||||||
func (v *SelectHeroClass) Render(screen d2interface.Surface) {
|
func (v *SelectHeroClass) Render(screen d2interface.Surface) {
|
||||||
if err := v.bgImage.RenderSegmented(screen, 4, 3, 0); err != nil {
|
v.bgImage.RenderSegmented(screen, 4, 3, 0)
|
||||||
return
|
v.headingLabel.Render(screen)
|
||||||
}
|
|
||||||
|
|
||||||
v.headingLabel.RenderNoError(screen)
|
|
||||||
|
|
||||||
if v.selectedHero != d2enum.HeroNone {
|
if v.selectedHero != d2enum.HeroNone {
|
||||||
v.heroClassLabel.RenderNoError(screen)
|
v.heroClassLabel.Render(screen)
|
||||||
v.heroDesc1Label.RenderNoError(screen)
|
v.heroDesc1Label.Render(screen)
|
||||||
v.heroDesc2Label.RenderNoError(screen)
|
v.heroDesc2Label.Render(screen)
|
||||||
v.heroDesc3Label.RenderNoError(screen)
|
v.heroDesc3Label.Render(screen)
|
||||||
}
|
}
|
||||||
|
|
||||||
for heroClass, heroInfo := range v.heroRenderInfo {
|
for heroClass, heroInfo := range v.heroRenderInfo {
|
||||||
@ -536,12 +533,12 @@ func (v *SelectHeroClass) Render(screen d2interface.Surface) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
v.campfire.RenderNoError(screen)
|
v.campfire.Render(screen)
|
||||||
|
|
||||||
if v.heroNameTextbox.GetVisible() {
|
if v.heroNameTextbox.GetVisible() {
|
||||||
v.heroNameLabel.RenderNoError(screen)
|
v.heroNameLabel.Render(screen)
|
||||||
v.expansionCharLabel.RenderNoError(screen)
|
v.expansionCharLabel.Render(screen)
|
||||||
v.hardcoreCharLabel.RenderNoError(screen)
|
v.hardcoreCharLabel.Render(screen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -739,7 +736,7 @@ func setSpriteToFirstFrame(sprite *d2ui.Sprite) {
|
|||||||
|
|
||||||
func drawSprite(sprite *d2ui.Sprite, target d2interface.Surface) {
|
func drawSprite(sprite *d2ui.Sprite, target d2interface.Surface) {
|
||||||
if sprite != nil {
|
if sprite != nil {
|
||||||
sprite.RenderNoError(target)
|
sprite.Render(target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -620,11 +620,11 @@ func (h *HelpOverlay) Render(target d2interface.Surface) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range h.frames {
|
for _, f := range h.frames {
|
||||||
f.RenderNoError(target)
|
f.Render(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, t := range h.text {
|
for _, t := range h.text {
|
||||||
t.RenderNoError(target)
|
t.Render(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, l := range h.lines {
|
for _, l := range h.lines {
|
||||||
|
@ -208,9 +208,7 @@ func (s *HeroStatsPanel) renderStaticMenu(target d2interface.Surface) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *HeroStatsPanel) renderStaticPanelFrames(target d2interface.Surface) error {
|
func (s *HeroStatsPanel) renderStaticPanelFrames(target d2interface.Surface) error {
|
||||||
if err := s.frame.Render(target); err != nil {
|
s.frame.Render(target)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
frames := []int{
|
frames := []int{
|
||||||
statsPanelTopLeft,
|
statsPanelTopLeft,
|
||||||
@ -242,7 +240,7 @@ func (s *HeroStatsPanel) renderStaticPanelFrames(target d2interface.Surface) err
|
|||||||
s.panel.SetPosition(currentX-w, currentY+h)
|
s.panel.SetPosition(currentX-w, currentY+h)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.panel.RenderNoError(target)
|
s.panel.Render(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -295,7 +293,7 @@ func (s *HeroStatsPanel) renderStaticLabels(target d2interface.Surface) {
|
|||||||
cfg.centerAlign,
|
cfg.centerAlign,
|
||||||
})
|
})
|
||||||
|
|
||||||
label.RenderNoError(target)
|
label.Render(target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -348,7 +346,7 @@ func (s *HeroStatsPanel) renderStatValues(target d2interface.Surface) {
|
|||||||
func (s *HeroStatsPanel) renderStatValueNum(label *d2ui.Label, value int,
|
func (s *HeroStatsPanel) renderStatValueNum(label *d2ui.Label, value int,
|
||||||
target d2interface.Surface) {
|
target d2interface.Surface) {
|
||||||
label.SetText(strconv.Itoa(value))
|
label.SetText(strconv.Itoa(value))
|
||||||
label.RenderNoError(target)
|
label.Render(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *HeroStatsPanel) createStatValueLabel(stat, x, y int) *d2ui.Label {
|
func (s *HeroStatsPanel) createStatValueLabel(stat, x, y int) *d2ui.Label {
|
||||||
|
@ -391,7 +391,7 @@ func (h *HUD) renderManaGlobe(x, _ int, target d2interface.Surface) error {
|
|||||||
|
|
||||||
h.mainPanel.SetPosition(x, height)
|
h.mainPanel.SetPosition(x, height)
|
||||||
|
|
||||||
h.mainPanel.RenderNoError(target)
|
h.mainPanel.Render(target)
|
||||||
|
|
||||||
// Mana status bar
|
// Mana status bar
|
||||||
manaPercent := float64(h.hero.Stats.Mana) / float64(h.hero.Stats.MaxMana)
|
manaPercent := float64(h.hero.Stats.Mana) / float64(h.hero.Stats.MaxMana)
|
||||||
@ -413,8 +413,8 @@ func (h *HUD) renderManaGlobe(x, _ int, target d2interface.Surface) error {
|
|||||||
|
|
||||||
h.globeSprite.SetPosition(x+rightGlobeOffsetX, height+rightGlobeOffsetY)
|
h.globeSprite.SetPosition(x+rightGlobeOffsetX, height+rightGlobeOffsetY)
|
||||||
|
|
||||||
h.globeSprite.RenderNoError(target)
|
h.globeSprite.Render(target)
|
||||||
h.globeSprite.RenderNoError(target)
|
h.globeSprite.Render(target)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -438,7 +438,7 @@ func (h *HUD) renderHealthGlobe(x, y int, target d2interface.Surface) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.globeSprite.SetPosition(x+globeSpriteOffsetX, y+globeSpriteOffsetY)
|
h.globeSprite.SetPosition(x+globeSpriteOffsetX, y+globeSpriteOffsetY)
|
||||||
h.globeSprite.RenderNoError(target)
|
h.globeSprite.Render(target)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -449,7 +449,7 @@ func (h *HUD) renderPanel(x, y int, target d2interface.Surface) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.mainPanel.SetPosition(x, y)
|
h.mainPanel.SetPosition(x, y)
|
||||||
h.mainPanel.RenderNoError(target)
|
h.mainPanel.Render(target)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -466,7 +466,7 @@ func (h *HUD) renderLeftSkill(x, y int, target d2interface.Surface) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.leftSkillResource.SkillIcon.SetPosition(x, y)
|
h.leftSkillResource.SkillIcon.SetPosition(x, y)
|
||||||
h.leftSkillResource.SkillIcon.RenderNoError(target)
|
h.leftSkillResource.SkillIcon.Render(target)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -485,7 +485,7 @@ func (h *HUD) renderRightSkill(x, _ int, target d2interface.Surface) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.rightSkillResource.SkillIcon.SetPosition(x, height)
|
h.rightSkillResource.SkillIcon.SetPosition(x, height)
|
||||||
h.rightSkillResource.SkillIcon.RenderNoError(target)
|
h.rightSkillResource.SkillIcon.Render(target)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -496,7 +496,7 @@ func (h *HUD) renderNewStatsButton(x, y int, target d2interface.Surface) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.mainPanel.SetPosition(x, y)
|
h.mainPanel.SetPosition(x, y)
|
||||||
h.mainPanel.RenderNoError(target)
|
h.mainPanel.Render(target)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -507,7 +507,7 @@ func (h *HUD) renderStamina(x, y int, target d2interface.Surface) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.mainPanel.SetPosition(x, y)
|
h.mainPanel.SetPosition(x, y)
|
||||||
h.mainPanel.RenderNoError(target)
|
h.mainPanel.Render(target)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -558,7 +558,7 @@ func (h *HUD) renderMiniPanel(target d2interface.Surface) error {
|
|||||||
buttonX, buttonY := (width>>1)+miniPanelButtonOffsetX, height+miniPanelButtonOffsetY
|
buttonX, buttonY := (width>>1)+miniPanelButtonOffsetX, height+miniPanelButtonOffsetY
|
||||||
|
|
||||||
h.menuButton.SetPosition(buttonX, buttonY)
|
h.menuButton.SetPosition(buttonX, buttonY)
|
||||||
h.menuButton.RenderNoError(target)
|
h.menuButton.Render(target)
|
||||||
h.miniPanel.Render(target)
|
h.miniPanel.Render(target)
|
||||||
|
|
||||||
miniPanelButtons := map[actionableType]string{
|
miniPanelButtons := map[actionableType]string{
|
||||||
@ -595,10 +595,7 @@ func (h *HUD) renderMiniPanel(target d2interface.Surface) error {
|
|||||||
labelY := centerY - halfButtonHeight - labelHeight
|
labelY := centerY - halfButtonHeight - labelHeight
|
||||||
|
|
||||||
h.miniPanelTooltip.SetPosition(labelX, labelY)
|
h.miniPanelTooltip.SetPosition(labelX, labelY)
|
||||||
|
h.miniPanelTooltip.Render(target)
|
||||||
if err := h.miniPanelTooltip.Render(target); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -612,7 +609,7 @@ func (h *HUD) renderPotions(x, _ int, target d2interface.Surface) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.mainPanel.SetPosition(x, height)
|
h.mainPanel.SetPosition(x, height)
|
||||||
h.mainPanel.RenderNoError(target)
|
h.mainPanel.Render(target)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -625,7 +622,7 @@ func (h *HUD) renderNewSkillsButton(x, _ int, target d2interface.Surface) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.mainPanel.SetPosition(x, height)
|
h.mainPanel.SetPosition(x, height)
|
||||||
h.mainPanel.RenderNoError(target)
|
h.mainPanel.Render(target)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -645,10 +642,7 @@ func (h *HUD) renderHealthTooltip(target d2interface.Surface) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.healthTooltip.SetText(strPanelHealth)
|
h.healthTooltip.SetText(strPanelHealth)
|
||||||
|
h.healthTooltip.Render(target)
|
||||||
if err := h.healthTooltip.Render(target); err != nil {
|
|
||||||
log.Printf("Cannot render tooltip, %e", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:golint,dupl // we clean this up later
|
//nolint:golint,dupl // we clean this up later
|
||||||
@ -665,10 +659,7 @@ func (h *HUD) renderManaTooltip(target d2interface.Surface) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.manaTooltip.SetText(strPanelMana)
|
h.manaTooltip.SetText(strPanelMana)
|
||||||
|
h.manaTooltip.Render(target)
|
||||||
if err := h.manaTooltip.Render(target); err != nil {
|
|
||||||
log.Printf("Cannot render tooltip, %e", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HUD) renderRunWalkTooltip(target d2interface.Surface) {
|
func (h *HUD) renderRunWalkTooltip(target d2interface.Surface) {
|
||||||
@ -689,10 +680,7 @@ func (h *HUD) renderRunWalkTooltip(target d2interface.Surface) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.runWalkTooltip.SetText(h.asset.TranslateString(stringTableKey))
|
h.runWalkTooltip.SetText(h.asset.TranslateString(stringTableKey))
|
||||||
|
h.runWalkTooltip.Render(target)
|
||||||
if err := h.runWalkTooltip.Render(target); err != nil {
|
|
||||||
log.Printf("Cannot render tooltip, %e", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HUD) renderStaminaTooltip(target d2interface.Surface) {
|
func (h *HUD) renderStaminaTooltip(target d2interface.Surface) {
|
||||||
@ -709,10 +697,7 @@ func (h *HUD) renderStaminaTooltip(target d2interface.Surface) {
|
|||||||
strPanelStamina := fmt.Sprintf(fmtStamina, staminaCurr, staminaMax)
|
strPanelStamina := fmt.Sprintf(fmtStamina, staminaCurr, staminaMax)
|
||||||
|
|
||||||
h.staminaTooltip.SetText(strPanelStamina)
|
h.staminaTooltip.SetText(strPanelStamina)
|
||||||
|
h.staminaTooltip.Render(target)
|
||||||
if err := h.staminaTooltip.Render(target); err != nil {
|
|
||||||
log.Printf("Cannot render tooltip, %e", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HUD) renderExperienceTooltip(target d2interface.Surface) {
|
func (h *HUD) renderExperienceTooltip(target d2interface.Surface) {
|
||||||
@ -736,10 +721,7 @@ func (h *HUD) renderExperienceTooltip(target d2interface.Surface) {
|
|||||||
strPanelExp := fmt.Sprintf(fmtExp, expCurr, expMax)
|
strPanelExp := fmt.Sprintf(fmtExp, expCurr, expMax)
|
||||||
|
|
||||||
h.experienceTooltip.SetText(strPanelExp)
|
h.experienceTooltip.SetText(strPanelExp)
|
||||||
|
h.experienceTooltip.Render(target)
|
||||||
if err := h.experienceTooltip.Render(target); err != nil {
|
|
||||||
log.Printf("Cannot render tooltip, %e", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HUD) renderForSelectableEntitiesHovered(target d2interface.Surface) {
|
func (h *HUD) renderForSelectableEntitiesHovered(target d2interface.Surface) {
|
||||||
@ -772,7 +754,7 @@ func (h *HUD) renderForSelectableEntitiesHovered(target d2interface.Surface) {
|
|||||||
xLabel, yLabel := entScreenX-xOff, entScreenY-yOff-entityHeight-hoverLabelOuterPad
|
xLabel, yLabel := entScreenX-xOff, entScreenY-yOff-entityHeight-hoverLabelOuterPad
|
||||||
h.nameLabel.SetPosition(xLabel, yLabel)
|
h.nameLabel.SetPosition(xLabel, yLabel)
|
||||||
|
|
||||||
h.nameLabel.RenderNoError(target)
|
h.nameLabel.Render(target)
|
||||||
entity.Highlight()
|
entity.Highlight()
|
||||||
|
|
||||||
break
|
break
|
||||||
@ -794,7 +776,7 @@ func (h *HUD) Render(target d2interface.Surface) error {
|
|||||||
|
|
||||||
if h.isZoneTextShown {
|
if h.isZoneTextShown {
|
||||||
h.zoneChangeText.SetPosition(zoneChangeTextX, zoneChangeTextY)
|
h.zoneChangeText.SetPosition(zoneChangeTextX, zoneChangeTextY)
|
||||||
h.zoneChangeText.RenderNoError(target)
|
h.zoneChangeText.Render(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
h.renderHealthTooltip(target)
|
h.renderHealthTooltip(target)
|
||||||
|
@ -174,9 +174,7 @@ func (g *Inventory) Render(target d2interface.Surface) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *Inventory) renderFrame(target d2interface.Surface) error {
|
func (g *Inventory) renderFrame(target d2interface.Surface) error {
|
||||||
if err := g.frame.Render(target); err != nil {
|
g.frame.Render(target)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
frames := []int{
|
frames := []int{
|
||||||
frameInventoryTopLeft,
|
frameInventoryTopLeft,
|
||||||
@ -196,7 +194,7 @@ func (g *Inventory) renderFrame(target d2interface.Surface) error {
|
|||||||
w, h := g.panel.GetCurrentFrameSize()
|
w, h := g.panel.GetCurrentFrameSize()
|
||||||
|
|
||||||
g.panel.SetPosition(x, y+h)
|
g.panel.SetPosition(x, y+h)
|
||||||
g.panel.RenderNoError(target)
|
g.panel.Render(target)
|
||||||
|
|
||||||
switch frame {
|
switch frame {
|
||||||
case frameInventoryTopLeft:
|
case frameInventoryTopLeft:
|
||||||
@ -241,9 +239,7 @@ func (g *Inventory) renderItemDescription(target d2interface.Surface, i Inventor
|
|||||||
lines := i.GetItemDescription()
|
lines := i.GetItemDescription()
|
||||||
g.itemTooltip.SetTextLines(lines)
|
g.itemTooltip.SetTextLines(lines)
|
||||||
_, y := g.grid.SlotToScreen(i.InventoryGridSlot())
|
_, y := g.grid.SlotToScreen(i.InventoryGridSlot())
|
||||||
g.itemTooltip.SetPosition(g.hoverX, y)
|
|
||||||
|
|
||||||
if err := g.itemTooltip.Render(target); err != nil {
|
g.itemTooltip.SetPosition(g.hoverX, y)
|
||||||
log.Printf("Cannot render tooltip, %e", err)
|
g.itemTooltip.Render(target)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,7 @@ func (g *ItemGrid) renderItem(item InventoryItem, target d2interface.Surface, x,
|
|||||||
if itemSprite != nil {
|
if itemSprite != nil {
|
||||||
itemSprite.SetPosition(x, y)
|
itemSprite.SetPosition(x, y)
|
||||||
itemSprite.GetCurrentFrameSize()
|
itemSprite.GetCurrentFrameSize()
|
||||||
itemSprite.RenderNoError(target)
|
itemSprite.Render(target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ func (m *miniPanel) Render(target d2interface.Surface) {
|
|||||||
|
|
||||||
m.container.SetPosition(x, y)
|
m.container.SetPosition(x, y)
|
||||||
|
|
||||||
m.container.RenderNoError(target)
|
m.container.Render(target)
|
||||||
|
|
||||||
buttonWidth, _ := m.button.GetCurrentFrameSize()
|
buttonWidth, _ := m.button.GetCurrentFrameSize()
|
||||||
buttonWidth++
|
buttonWidth++
|
||||||
@ -122,7 +122,7 @@ func (m *miniPanel) Render(target d2interface.Surface) {
|
|||||||
x, y := halfW+offsetX, height+buttonOffsetY
|
x, y := halfW+offsetX, height+buttonOffsetY
|
||||||
|
|
||||||
m.button.SetPosition(x, y)
|
m.button.SetPosition(x, y)
|
||||||
m.button.RenderNoError(target)
|
m.button.Render(target)
|
||||||
|
|
||||||
j += 2
|
j += 2
|
||||||
}
|
}
|
||||||
|
@ -129,9 +129,7 @@ func (s *SkillPanel) Render(target d2interface.Surface) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if s.hoveredSkill != nil {
|
if s.hoveredSkill != nil {
|
||||||
if err := s.hoverTooltip.Render(target); err != nil {
|
s.hoverTooltip.Render(target)
|
||||||
log.Printf("Cannot render tooltip, %e", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -242,7 +240,7 @@ func (s *SkillPanel) createSkillListImage(skillsListRow *SkillListRow) (d2interf
|
|||||||
}
|
}
|
||||||
|
|
||||||
surface.PushTranslation(idx*skillIconWidth, 50)
|
surface.PushTranslation(idx*skillIconWidth, 50)
|
||||||
skillSprite.RenderNoError(surface)
|
skillSprite.Render(surface)
|
||||||
surface.Pop()
|
surface.Pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package d2player
|
package d2player
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||||
@ -50,11 +51,12 @@ func (si *skillIcon) SetVisible(visible bool) {
|
|||||||
si.lvlLabel.SetVisible(visible)
|
si.lvlLabel.SetVisible(visible)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (si *skillIcon) renderSprite(target d2interface.Surface) error {
|
func (si *skillIcon) renderSprite(target d2interface.Surface) {
|
||||||
x, y := si.GetPosition()
|
x, y := si.GetPosition()
|
||||||
|
|
||||||
if err := si.sprite.SetCurrentFrame(si.skill.IconCel); err != nil {
|
if err := si.sprite.SetCurrentFrame(si.skill.IconCel); err != nil {
|
||||||
return err
|
log.Printf("Cannot set Frame %e", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if si.skill.SkillPoints == 0 {
|
if si.skill.SkillPoints == 0 {
|
||||||
@ -66,32 +68,23 @@ func (si *skillIcon) renderSprite(target d2interface.Surface) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
si.sprite.SetPosition(x, y)
|
si.sprite.SetPosition(x, y)
|
||||||
|
si.sprite.Render(target)
|
||||||
if err := si.sprite.Render(target); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (si *skillIcon) renderSpriteLabel(target d2interface.Surface) error {
|
func (si *skillIcon) renderSpriteLabel(target d2interface.Surface) {
|
||||||
if si.skill.SkillPoints == 0 {
|
if si.skill.SkillPoints == 0 {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
x, y := si.GetPosition()
|
x, y := si.GetPosition()
|
||||||
si.lvlLabel.SetText(strconv.Itoa(si.skill.SkillPoints))
|
si.lvlLabel.SetText(strconv.Itoa(si.skill.SkillPoints))
|
||||||
si.lvlLabel.SetPosition(x+skillLabelXOffset, y+skillLabelYOffset)
|
si.lvlLabel.SetPosition(x+skillLabelXOffset, y+skillLabelYOffset)
|
||||||
|
si.lvlLabel.Render(target)
|
||||||
return si.lvlLabel.Render(target)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (si *skillIcon) Render(target d2interface.Surface) error {
|
func (si *skillIcon) Render(target d2interface.Surface) {
|
||||||
if err := si.renderSprite(target); err != nil {
|
si.renderSprite(target)
|
||||||
return err
|
si.renderSpriteLabel(target)
|
||||||
}
|
|
||||||
|
|
||||||
return si.renderSpriteLabel(target)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (si *skillIcon) Advance(elapsed float64) error {
|
func (si *skillIcon) Advance(elapsed float64) error {
|
||||||
|
@ -383,71 +383,54 @@ func (s *skillTree) setTab(tab int) {
|
|||||||
|
|
||||||
func (s *skillTree) renderPanelSegment(
|
func (s *skillTree) renderPanelSegment(
|
||||||
target d2interface.Surface,
|
target d2interface.Surface,
|
||||||
frame int) error {
|
frame int) {
|
||||||
if err := s.resources.skillPanel.SetCurrentFrame(frame); err != nil {
|
if err := s.resources.skillPanel.SetCurrentFrame(frame); err != nil {
|
||||||
return err
|
log.Printf("%e", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
s.resources.skillPanel.RenderNoError(target)
|
s.resources.skillPanel.Render(target)
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *skillTree) renderTabCommon(target d2interface.Surface) error {
|
func (s *skillTree) renderTabCommon(target d2interface.Surface) {
|
||||||
skillPanel := s.resources.skillPanel
|
skillPanel := s.resources.skillPanel
|
||||||
x, y := s.originX, s.originY
|
x, y := s.originX, s.originY
|
||||||
|
|
||||||
// top
|
// top
|
||||||
w, h, err := skillPanel.GetFrameSize(frameCommonTabTopLeft)
|
w, h, err := skillPanel.GetFrameSize(frameCommonTabTopLeft)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
log.Printf("%e", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
y += h
|
y += h
|
||||||
|
|
||||||
skillPanel.SetPosition(x, y)
|
skillPanel.SetPosition(x, y)
|
||||||
|
s.renderPanelSegment(target, frameCommonTabTopLeft)
|
||||||
err = s.renderPanelSegment(target, frameCommonTabTopLeft)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
skillPanel.SetPosition(x+w, y)
|
skillPanel.SetPosition(x+w, y)
|
||||||
|
s.renderPanelSegment(target, frameCommonTabTopRight)
|
||||||
err = s.renderPanelSegment(target, frameCommonTabTopRight)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// bottom
|
// bottom
|
||||||
_, h, err = skillPanel.GetFrameSize(frameCommonTabBottomLeft)
|
_, h, err = skillPanel.GetFrameSize(frameCommonTabBottomLeft)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
log.Printf("%e", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
y += h
|
y += h
|
||||||
|
|
||||||
skillPanel.SetPosition(x, y)
|
skillPanel.SetPosition(x, y)
|
||||||
|
s.renderPanelSegment(target, frameCommonTabBottomLeft)
|
||||||
err = s.renderPanelSegment(target, frameCommonTabBottomLeft)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
skillPanel.SetPosition(x+w, y)
|
skillPanel.SetPosition(x+w, y)
|
||||||
|
s.renderPanelSegment(target, frameCommonTabBottomRight)
|
||||||
err = s.renderPanelSegment(target, frameCommonTabBottomRight)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// available skill points label
|
// available skill points label
|
||||||
s.availSPLabel.RenderNoError(target)
|
s.availSPLabel.Render(target)
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *skillTree) renderTab(target d2interface.Surface, tab int) error {
|
func (s *skillTree) renderTab(target d2interface.Surface, tab int) {
|
||||||
topFrame := frameOffsetTop + (tabIndexOffset * tab)
|
topFrame := frameOffsetTop + (tabIndexOffset * tab)
|
||||||
bottomFrame := frameOffsetBottom + (tabIndexOffset * tab)
|
bottomFrame := frameOffsetBottom + (tabIndexOffset * tab)
|
||||||
|
|
||||||
@ -457,71 +440,46 @@ func (s *skillTree) renderTab(target d2interface.Surface, tab int) error {
|
|||||||
// top
|
// top
|
||||||
_, h0, err := skillPanel.GetFrameSize(topFrame)
|
_, h0, err := skillPanel.GetFrameSize(topFrame)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
log.Printf("%e", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
y += h0
|
y += h0
|
||||||
|
|
||||||
skillPanel.SetPosition(x, y)
|
skillPanel.SetPosition(x, y)
|
||||||
|
s.renderPanelSegment(target, topFrame)
|
||||||
err = s.renderPanelSegment(target, topFrame)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// bottom
|
// bottom
|
||||||
w, h1, err := skillPanel.GetFrameSize(bottomFrame)
|
w, h1, err := skillPanel.GetFrameSize(bottomFrame)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
log.Printf("%e", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
skillPanel.SetPosition(x, y+h1)
|
skillPanel.SetPosition(x, y+h1)
|
||||||
|
|
||||||
if err := s.renderPanelSegment(target, bottomFrame); err != nil {
|
s.renderPanelSegment(target, bottomFrame)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// tab button highlighted
|
// tab button highlighted
|
||||||
switch tab {
|
switch tab {
|
||||||
case firstTab:
|
case firstTab:
|
||||||
skillPanel.SetPosition(x+w, y+h1)
|
skillPanel.SetPosition(x+w, y+h1)
|
||||||
|
s.renderPanelSegment(target, frameSelectedTab1Full)
|
||||||
if err := s.renderPanelSegment(target, frameSelectedTab1Full); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case secondTab:
|
case secondTab:
|
||||||
x += w
|
x += w
|
||||||
skillPanel.SetPosition(x, s.originY+h0)
|
skillPanel.SetPosition(x, s.originY+h0)
|
||||||
|
s.renderPanelSegment(target, frameSelectedTab2Top)
|
||||||
if err := s.renderPanelSegment(target, frameSelectedTab2Top); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
skillPanel.SetPosition(x, y+h1)
|
skillPanel.SetPosition(x, y+h1)
|
||||||
|
s.renderPanelSegment(target, frameSelectedTab2Bottom)
|
||||||
if err := s.renderPanelSegment(target, frameSelectedTab2Bottom); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case thirdTab:
|
case thirdTab:
|
||||||
skillPanel.SetPosition(x+w, y)
|
skillPanel.SetPosition(x+w, y)
|
||||||
|
s.renderPanelSegment(target, frameSelectedTab3Full)
|
||||||
if err := s.renderPanelSegment(target, frameSelectedTab3Full); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the skill tree panel
|
// Render the skill tree panel
|
||||||
func (s *skillTree) Render(target d2interface.Surface) error {
|
func (s *skillTree) Render(target d2interface.Surface) {
|
||||||
if err := s.renderTabCommon(target); err != nil {
|
s.renderTabCommon(target)
|
||||||
return err
|
s.renderTab(target, s.selectedTab)
|
||||||
}
|
|
||||||
|
|
||||||
if err := s.renderTab(target, s.selectedTab); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user