mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-16 09:25:57 -05:00
d2ui/drawable: Refactor render() method to not return error
this simplifies error handling statements all over the ui code. Before we had to write: if err := foo.Render(target); err != nil { return err } which simplifies now to foo.Render(target)
This commit is contained in:
parent
437e65564f
commit
c148941194
@ -1,7 +1,6 @@
|
||||
package d2ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"log"
|
||||
|
||||
@ -332,11 +331,8 @@ func (v *Button) prerenderStates(btnSprite *Sprite, btnLayout *ButtonLayout, lab
|
||||
|
||||
// buttons always have a base image
|
||||
if v.buttonLayout.HasImage {
|
||||
err := btnSprite.RenderSegmented(v.normalSurface, btnLayout.XSegments,
|
||||
btnSprite.RenderSegmented(v.normalSurface, btnLayout.XSegments,
|
||||
btnLayout.YSegments, btnLayout.BaseFrame)
|
||||
if err != nil {
|
||||
fmt.Printf("failed to render button normalSurface, err: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
_, labelHeight := label.GetSize()
|
||||
@ -412,10 +408,7 @@ func (v *Button) prerenderStates(btnSprite *Sprite, btnLayout *ButtonLayout, lab
|
||||
|
||||
*state.prerenderdestination = surface
|
||||
|
||||
err := btnSprite.RenderSegmented(*state.prerenderdestination, xSeg, ySeg, state.baseFrame)
|
||||
if err != nil {
|
||||
fmt.Printf(state.fmtErr, err)
|
||||
}
|
||||
btnSprite.RenderSegmented(*state.prerenderdestination, xSeg, ySeg, state.baseFrame)
|
||||
|
||||
label.SetPosition(state.offsetX, state.offsetY)
|
||||
label.RenderNoError(*state.prerenderdestination)
|
||||
@ -437,7 +430,7 @@ func (v *Button) Activate() {
|
||||
}
|
||||
|
||||
// Render renders the button
|
||||
func (v *Button) Render(target d2interface.Surface) error {
|
||||
func (v *Button) Render(target d2interface.Surface) {
|
||||
target.PushFilter(d2enum.FilterNearest)
|
||||
defer target.Pop()
|
||||
|
||||
@ -462,8 +455,6 @@ func (v *Button) Render(target d2interface.Surface) error {
|
||||
default:
|
||||
target.Render(v.normalSurface)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
err = checkboxSprite.RenderSegmented(result.Image, 1, 1, 0)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
checkboxSprite.RenderSegmented(result.Image, 1, 1, 0)
|
||||
|
||||
result.checkedImage = ui.renderer.NewSurface(result.width, result.height)
|
||||
|
||||
err = checkboxSprite.RenderSegmented(result.checkedImage, 1, 1, 1)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil
|
||||
}
|
||||
checkboxSprite.RenderSegmented(result.checkedImage, 1, 1, 1)
|
||||
|
||||
ui.addWidget(result)
|
||||
|
||||
@ -69,7 +61,7 @@ func (ui *UIManager) NewCheckbox(checkState bool) *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)
|
||||
defer target.Pop()
|
||||
|
||||
@ -81,8 +73,6 @@ func (v *Checkbox) Render(target d2interface.Surface) error {
|
||||
} else {
|
||||
target.Render(v.Image)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Advance does nothing for checkboxes
|
||||
|
@ -8,11 +8,11 @@ var _ Widget = &CustomWidget{}
|
||||
// CustomWidget is a widget with a fully custom render function
|
||||
type CustomWidget struct {
|
||||
*BaseWidget
|
||||
renderFunc func(target d2interface.Surface) error
|
||||
renderFunc func(target d2interface.Surface)
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
return &CustomWidget{
|
||||
@ -22,8 +22,8 @@ func (ui *UIManager) NewCustomWidget(renderFunc func(target d2interface.Surface)
|
||||
}
|
||||
|
||||
// Render draws the custom widget
|
||||
func (c *CustomWidget) Render(target d2interface.Surface) error {
|
||||
return c.renderFunc(target)
|
||||
func (c *CustomWidget) Render(target d2interface.Surface) {
|
||||
c.renderFunc(target)
|
||||
}
|
||||
|
||||
// Advance is a no-op
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
|
||||
// Drawable represents an instance that can be drawn
|
||||
type Drawable interface {
|
||||
Render(target d2interface.Surface) error
|
||||
Render(target d2interface.Surface)
|
||||
Advance(elapsed float64) error
|
||||
GetSize() (width, height int)
|
||||
SetPosition(x, y int)
|
||||
|
@ -83,15 +83,17 @@ func (u *UIFrame) Load() {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
case FrameLeft:
|
||||
return u.renderLeft(target)
|
||||
if err := u.renderLeft(target); err != nil {
|
||||
log.Printf("Render error %e", err)
|
||||
}
|
||||
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 {
|
||||
|
@ -49,9 +49,8 @@ func (ui *UIManager) NewLabel(fontPath, palettePath string) *Label {
|
||||
}
|
||||
|
||||
// Render draws the label on the screen
|
||||
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.
|
||||
|
@ -106,9 +106,9 @@ func (v *Scrollbar) GetLastDirChange() int {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
offset := 0
|
||||
@ -119,18 +119,14 @@ func (v *Scrollbar) Render(target d2interface.Surface) error {
|
||||
|
||||
v.scrollbarSprite.SetPosition(v.x, v.y)
|
||||
|
||||
if err := v.scrollbarSprite.RenderSegmented(target, 1, 1, 0+offset); err != nil {
|
||||
return err
|
||||
}
|
||||
v.scrollbarSprite.RenderSegmented(target, 1, 1, 0+offset)
|
||||
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
v.scrollbarSprite.RenderSegmented(target, 1, 1, 1+offset)
|
||||
|
||||
if v.maxOffset == 0 || v.currentOffset < 0 || v.currentOffset > v.maxOffset {
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
v.scrollbarSprite.SetPosition(v.x, v.y+10+v.getBarPosition())
|
||||
@ -141,11 +137,7 @@ func (v *Scrollbar) Render(target d2interface.Surface) error {
|
||||
offset++
|
||||
}
|
||||
|
||||
if err := v.scrollbarSprite.RenderSegmented(target, 1, 1, offset); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
v.scrollbarSprite.RenderSegmented(target, 1, 1, offset)
|
||||
}
|
||||
|
||||
// Advance advances the scrollbar sprite
|
||||
|
@ -41,9 +41,8 @@ func (ui *UIManager) NewSprite(animationPath, palettePath string) (*Sprite, erro
|
||||
}
|
||||
|
||||
// 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
|
||||
@ -65,7 +64,7 @@ func (s *Sprite) RenderSection(sfc d2interface.Surface, bound image.Rectangle) {
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
for y := 0; y < segmentsY; y++ {
|
||||
@ -74,7 +73,7 @@ func (s *Sprite) RenderSegmented(target d2interface.Surface, segmentsX, segments
|
||||
for x := 0; x < segmentsX; x++ {
|
||||
idx := x + y*segmentsX + frameOffset*segmentsX*segmentsY
|
||||
if err := s.animation.SetCurrentFrame(idx); err != nil {
|
||||
return err
|
||||
log.Printf("SetCurrentFrame error %e", err)
|
||||
}
|
||||
|
||||
target.PushTranslation(s.x+currentX, s.y+currentY)
|
||||
@ -88,8 +87,6 @@ func (s *Sprite) RenderSegmented(target d2interface.Surface, segmentsX, segments
|
||||
|
||||
currentY += maxFrameHeight
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSize returns the size of the current frame
|
||||
|
@ -56,9 +56,9 @@ func (v *TextBox) SetFilter(filter string) {
|
||||
}
|
||||
|
||||
// Render renders the text box
|
||||
func (v *TextBox) Render(target d2interface.Surface) error {
|
||||
func (v *TextBox) Render(target d2interface.Surface) {
|
||||
if !v.visible {
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
v.bgSprite.RenderNoError(target)
|
||||
@ -67,8 +67,6 @@ func (v *TextBox) Render(target d2interface.Surface) error {
|
||||
if (time.Now().UnixNano()/1e6)&(1<<8) > 0 {
|
||||
v.lineBar.RenderNoError(target)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// OnKeyChars handles key character events
|
||||
|
@ -140,7 +140,7 @@ func (t *Tooltip) GetSize() (sx, sy int) {
|
||||
}
|
||||
|
||||
// Render draws the tooltip
|
||||
func (t *Tooltip) Render(target d2interface.Surface) error {
|
||||
func (t *Tooltip) Render(target d2interface.Surface) {
|
||||
maxW, maxH := t.GetSize()
|
||||
|
||||
// nolint:gomnd // no magic numbers, their meaning is obvious
|
||||
@ -192,8 +192,6 @@ func (t *Tooltip) Render(target d2interface.Surface) error {
|
||||
}
|
||||
|
||||
target.PopN(len(t.lines))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Advance is a no-op
|
||||
|
@ -124,19 +124,13 @@ func (ui *UIManager) OnMouseButtonDown(event d2interface.MouseEvent) bool {
|
||||
func (ui *UIManager) Render(target d2interface.Surface) {
|
||||
for _, widget := range ui.widgets {
|
||||
if widget.GetVisible() {
|
||||
err := widget.Render(target)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
widget.Render(target)
|
||||
}
|
||||
}
|
||||
|
||||
for _, widgetGroup := range ui.widgetsGroups {
|
||||
if widgetGroup.GetVisible() {
|
||||
err := widgetGroup.Render(target)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
widgetGroup.Render(target)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -71,17 +71,12 @@ func (wg *WidgetGroup) Advance(elapsed float64) error {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
if entry.GetVisible() {
|
||||
err := entry.Render(target)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
entry.Render(target)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetVisible sets the visibility of all widgets in the group
|
||||
|
@ -369,17 +369,12 @@ func (v *CharacterSelect) onExitButtonClicked() {
|
||||
|
||||
// Render renders the Character Select screen
|
||||
func (v *CharacterSelect) Render(screen d2interface.Surface) {
|
||||
if err := v.background.RenderSegmented(screen, 4, 3, 0); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
v.background.RenderSegmented(screen, 4, 3, 0)
|
||||
v.d2HeroTitle.RenderNoError(screen)
|
||||
actualSelectionIndex := v.selectedCharacter - (v.charScrollbar.GetCurrentOffset() * 2)
|
||||
|
||||
if v.selectedCharacter > -1 && actualSelectionIndex >= 0 && actualSelectionIndex < 8 {
|
||||
if err := v.selectionBox.RenderSegmented(screen, 2, 1, 0); err != nil {
|
||||
return
|
||||
}
|
||||
v.selectionBox.RenderSegmented(screen, 2, 1, 0)
|
||||
}
|
||||
|
||||
for i := 0; i < 8; i++ {
|
||||
@ -402,11 +397,7 @@ func (v *CharacterSelect) Render(screen d2interface.Surface) {
|
||||
|
||||
if v.showDeleteConfirmation {
|
||||
screen.DrawRect(screenWidth, screenHeight, rgbaColor(blackHalfOpacity))
|
||||
|
||||
if err := v.okCancelBox.RenderSegmented(screen, 2, 1, 0); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
v.okCancelBox.RenderSegmented(screen, 2, 1, 0)
|
||||
v.deleteCharConfirmLabel.RenderNoError(screen)
|
||||
}
|
||||
}
|
||||
|
@ -183,21 +183,7 @@ func (v *Cinematics) playVideo(path string) {
|
||||
|
||||
// Render renders the credits screen
|
||||
func (v *Cinematics) Render(screen d2interface.Surface) {
|
||||
err := v.background.RenderSegmented(screen, 4, 3, 0)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = v.cinematicsBackground.RenderSegmented(screen, 2, 2, 0)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = v.cinematicsLabel.Render(screen)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
v.background.RenderSegmented(screen, 4, 3, 0)
|
||||
v.cinematicsBackground.RenderSegmented(screen, 2, 2, 0)
|
||||
v.cinematicsLabel.Render(screen)
|
||||
}
|
||||
|
@ -129,10 +129,7 @@ func (v *Credits) OnLoad(loading d2screen.LoadingState) {
|
||||
|
||||
// Render renders the credits screen
|
||||
func (v *Credits) Render(screen d2interface.Surface) {
|
||||
err := v.creditsBackground.RenderSegmented(screen, 4, 3, 0)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
v.creditsBackground.RenderSegmented(screen, 4, 3, 0)
|
||||
|
||||
for _, label := range v.labels {
|
||||
if label.Available {
|
||||
|
@ -436,25 +436,14 @@ func (v *MainMenu) Render(screen d2interface.Surface) {
|
||||
func (v *MainMenu) renderBackgrounds(screen d2interface.Surface) {
|
||||
switch v.screenMode {
|
||||
case ScreenModeTrademark:
|
||||
if err := v.trademarkBackground.RenderSegmented(screen, 4, 3, 0); err != nil {
|
||||
return
|
||||
}
|
||||
v.trademarkBackground.RenderSegmented(screen, 4, 3, 0)
|
||||
case ScreenModeServerIP:
|
||||
if err := v.tcpIPBackground.RenderSegmented(screen, 4, 3, 0); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err := v.serverIPBackground.RenderSegmented(screen, 2, 1, 0); err != nil {
|
||||
return
|
||||
}
|
||||
v.tcpIPBackground.RenderSegmented(screen, 4, 3, 0)
|
||||
v.serverIPBackground.RenderSegmented(screen, 2, 1, 0)
|
||||
case ScreenModeTCPIP:
|
||||
if err := v.tcpIPBackground.RenderSegmented(screen, 4, 3, 0); err != nil {
|
||||
return
|
||||
}
|
||||
v.tcpIPBackground.RenderSegmented(screen, 4, 3, 0)
|
||||
default:
|
||||
if err := v.background.RenderSegmented(screen, 4, 3, 0); err != nil {
|
||||
return
|
||||
}
|
||||
v.background.RenderSegmented(screen, 4, 3, 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -511,10 +511,7 @@ func (v *SelectHeroClass) onOkButtonClicked() {
|
||||
|
||||
// Render renders the Select Hero Class screen
|
||||
func (v *SelectHeroClass) Render(screen d2interface.Surface) {
|
||||
if err := v.bgImage.RenderSegmented(screen, 4, 3, 0); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
v.bgImage.RenderSegmented(screen, 4, 3, 0)
|
||||
v.headingLabel.RenderNoError(screen)
|
||||
|
||||
if v.selectedHero != d2enum.HeroNone {
|
||||
|
@ -208,9 +208,7 @@ func (s *HeroStatsPanel) renderStaticMenu(target d2interface.Surface) error {
|
||||
}
|
||||
|
||||
func (s *HeroStatsPanel) renderStaticPanelFrames(target d2interface.Surface) error {
|
||||
if err := s.frame.Render(target); err != nil {
|
||||
return err
|
||||
}
|
||||
s.frame.Render(target)
|
||||
|
||||
frames := []int{
|
||||
statsPanelTopLeft,
|
||||
|
@ -595,10 +595,7 @@ func (h *HUD) renderMiniPanel(target d2interface.Surface) error {
|
||||
labelY := centerY - halfButtonHeight - labelHeight
|
||||
|
||||
h.miniPanelTooltip.SetPosition(labelX, labelY)
|
||||
|
||||
if err := h.miniPanelTooltip.Render(target); err != nil {
|
||||
return err
|
||||
}
|
||||
h.miniPanelTooltip.Render(target)
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -645,10 +642,7 @@ func (h *HUD) renderHealthTooltip(target d2interface.Surface) {
|
||||
}
|
||||
|
||||
h.healthTooltip.SetText(strPanelHealth)
|
||||
|
||||
if err := h.healthTooltip.Render(target); err != nil {
|
||||
log.Printf("Cannot render tooltip, %e", err)
|
||||
}
|
||||
h.healthTooltip.Render(target)
|
||||
}
|
||||
|
||||
//nolint:golint,dupl // we clean this up later
|
||||
@ -665,10 +659,7 @@ func (h *HUD) renderManaTooltip(target d2interface.Surface) {
|
||||
}
|
||||
|
||||
h.manaTooltip.SetText(strPanelMana)
|
||||
|
||||
if err := h.manaTooltip.Render(target); err != nil {
|
||||
log.Printf("Cannot render tooltip, %e", err)
|
||||
}
|
||||
h.manaTooltip.Render(target)
|
||||
}
|
||||
|
||||
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))
|
||||
|
||||
if err := h.runWalkTooltip.Render(target); err != nil {
|
||||
log.Printf("Cannot render tooltip, %e", err)
|
||||
}
|
||||
h.runWalkTooltip.Render(target)
|
||||
}
|
||||
|
||||
func (h *HUD) renderStaminaTooltip(target d2interface.Surface) {
|
||||
@ -709,10 +697,7 @@ func (h *HUD) renderStaminaTooltip(target d2interface.Surface) {
|
||||
strPanelStamina := fmt.Sprintf(fmtStamina, staminaCurr, staminaMax)
|
||||
|
||||
h.staminaTooltip.SetText(strPanelStamina)
|
||||
|
||||
if err := h.staminaTooltip.Render(target); err != nil {
|
||||
log.Printf("Cannot render tooltip, %e", err)
|
||||
}
|
||||
h.staminaTooltip.Render(target)
|
||||
}
|
||||
|
||||
func (h *HUD) renderExperienceTooltip(target d2interface.Surface) {
|
||||
@ -736,10 +721,7 @@ func (h *HUD) renderExperienceTooltip(target d2interface.Surface) {
|
||||
strPanelExp := fmt.Sprintf(fmtExp, expCurr, expMax)
|
||||
|
||||
h.experienceTooltip.SetText(strPanelExp)
|
||||
|
||||
if err := h.experienceTooltip.Render(target); err != nil {
|
||||
log.Printf("Cannot render tooltip, %e", err)
|
||||
}
|
||||
h.experienceTooltip.Render(target)
|
||||
}
|
||||
|
||||
func (h *HUD) renderForSelectableEntitiesHovered(target d2interface.Surface) {
|
||||
|
@ -174,9 +174,7 @@ func (g *Inventory) Render(target d2interface.Surface) {
|
||||
}
|
||||
|
||||
func (g *Inventory) renderFrame(target d2interface.Surface) error {
|
||||
if err := g.frame.Render(target); err != nil {
|
||||
return err
|
||||
}
|
||||
g.frame.Render(target)
|
||||
|
||||
frames := []int{
|
||||
frameInventoryTopLeft,
|
||||
@ -241,9 +239,7 @@ func (g *Inventory) renderItemDescription(target d2interface.Surface, i Inventor
|
||||
lines := i.GetItemDescription()
|
||||
g.itemTooltip.SetTextLines(lines)
|
||||
_, y := g.grid.SlotToScreen(i.InventoryGridSlot())
|
||||
g.itemTooltip.SetPosition(g.hoverX, y)
|
||||
|
||||
if err := g.itemTooltip.Render(target); err != nil {
|
||||
log.Printf("Cannot render tooltip, %e", err)
|
||||
}
|
||||
g.itemTooltip.SetPosition(g.hoverX, y)
|
||||
g.itemTooltip.Render(target)
|
||||
}
|
||||
|
@ -129,9 +129,7 @@ func (s *SkillPanel) Render(target d2interface.Surface) error {
|
||||
}
|
||||
|
||||
if s.hoveredSkill != nil {
|
||||
if err := s.hoverTooltip.Render(target); err != nil {
|
||||
log.Printf("Cannot render tooltip, %e", err)
|
||||
}
|
||||
s.hoverTooltip.Render(target)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -1,6 +1,7 @@
|
||||
package d2player
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strconv"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
@ -50,11 +51,12 @@ func (si *skillIcon) SetVisible(visible bool) {
|
||||
si.lvlLabel.SetVisible(visible)
|
||||
}
|
||||
|
||||
func (si *skillIcon) renderSprite(target d2interface.Surface) error {
|
||||
func (si *skillIcon) renderSprite(target d2interface.Surface) {
|
||||
x, y := si.GetPosition()
|
||||
|
||||
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 {
|
||||
@ -66,32 +68,23 @@ func (si *skillIcon) renderSprite(target d2interface.Surface) error {
|
||||
}
|
||||
|
||||
si.sprite.SetPosition(x, y)
|
||||
|
||||
if err := si.sprite.Render(target); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
si.sprite.Render(target)
|
||||
}
|
||||
|
||||
func (si *skillIcon) renderSpriteLabel(target d2interface.Surface) error {
|
||||
func (si *skillIcon) renderSpriteLabel(target d2interface.Surface) {
|
||||
if si.skill.SkillPoints == 0 {
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
x, y := si.GetPosition()
|
||||
si.lvlLabel.SetText(strconv.Itoa(si.skill.SkillPoints))
|
||||
si.lvlLabel.SetPosition(x+skillLabelXOffset, y+skillLabelYOffset)
|
||||
|
||||
return si.lvlLabel.Render(target)
|
||||
si.lvlLabel.Render(target)
|
||||
}
|
||||
|
||||
func (si *skillIcon) Render(target d2interface.Surface) error {
|
||||
if err := si.renderSprite(target); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return si.renderSpriteLabel(target)
|
||||
func (si *skillIcon) Render(target d2interface.Surface) {
|
||||
si.renderSprite(target)
|
||||
si.renderSpriteLabel(target)
|
||||
}
|
||||
|
||||
func (si *skillIcon) Advance(elapsed float64) error {
|
||||
|
@ -383,71 +383,54 @@ func (s *skillTree) setTab(tab int) {
|
||||
|
||||
func (s *skillTree) renderPanelSegment(
|
||||
target d2interface.Surface,
|
||||
frame int) error {
|
||||
frame int) {
|
||||
if err := s.resources.skillPanel.SetCurrentFrame(frame); err != nil {
|
||||
return err
|
||||
log.Printf("%e", err)
|
||||
return
|
||||
}
|
||||
|
||||
s.resources.skillPanel.RenderNoError(target)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *skillTree) renderTabCommon(target d2interface.Surface) error {
|
||||
func (s *skillTree) renderTabCommon(target d2interface.Surface) {
|
||||
skillPanel := s.resources.skillPanel
|
||||
x, y := s.originX, s.originY
|
||||
|
||||
// top
|
||||
w, h, err := skillPanel.GetFrameSize(frameCommonTabTopLeft)
|
||||
if err != nil {
|
||||
return err
|
||||
log.Printf("%e", err)
|
||||
return
|
||||
}
|
||||
|
||||
y += h
|
||||
|
||||
skillPanel.SetPosition(x, y)
|
||||
|
||||
err = s.renderPanelSegment(target, frameCommonTabTopLeft)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.renderPanelSegment(target, frameCommonTabTopLeft)
|
||||
|
||||
skillPanel.SetPosition(x+w, y)
|
||||
|
||||
err = s.renderPanelSegment(target, frameCommonTabTopRight)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.renderPanelSegment(target, frameCommonTabTopRight)
|
||||
|
||||
// bottom
|
||||
_, h, err = skillPanel.GetFrameSize(frameCommonTabBottomLeft)
|
||||
if err != nil {
|
||||
return err
|
||||
log.Printf("%e", err)
|
||||
return
|
||||
}
|
||||
|
||||
y += h
|
||||
|
||||
skillPanel.SetPosition(x, y)
|
||||
|
||||
err = s.renderPanelSegment(target, frameCommonTabBottomLeft)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.renderPanelSegment(target, frameCommonTabBottomLeft)
|
||||
|
||||
skillPanel.SetPosition(x+w, y)
|
||||
|
||||
err = s.renderPanelSegment(target, frameCommonTabBottomRight)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.renderPanelSegment(target, frameCommonTabBottomRight)
|
||||
|
||||
// available skill points label
|
||||
s.availSPLabel.RenderNoError(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)
|
||||
bottomFrame := frameOffsetBottom + (tabIndexOffset * tab)
|
||||
|
||||
@ -457,71 +440,46 @@ func (s *skillTree) renderTab(target d2interface.Surface, tab int) error {
|
||||
// top
|
||||
_, h0, err := skillPanel.GetFrameSize(topFrame)
|
||||
if err != nil {
|
||||
return err
|
||||
log.Printf("%e", err)
|
||||
return
|
||||
}
|
||||
|
||||
y += h0
|
||||
|
||||
skillPanel.SetPosition(x, y)
|
||||
|
||||
err = s.renderPanelSegment(target, topFrame)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.renderPanelSegment(target, topFrame)
|
||||
|
||||
// bottom
|
||||
w, h1, err := skillPanel.GetFrameSize(bottomFrame)
|
||||
if err != nil {
|
||||
return err
|
||||
log.Printf("%e", err)
|
||||
return
|
||||
}
|
||||
|
||||
skillPanel.SetPosition(x, y+h1)
|
||||
|
||||
if err := s.renderPanelSegment(target, bottomFrame); err != nil {
|
||||
return err
|
||||
}
|
||||
s.renderPanelSegment(target, bottomFrame)
|
||||
|
||||
// tab button highlighted
|
||||
switch tab {
|
||||
case firstTab:
|
||||
skillPanel.SetPosition(x+w, y+h1)
|
||||
|
||||
if err := s.renderPanelSegment(target, frameSelectedTab1Full); err != nil {
|
||||
return err
|
||||
}
|
||||
s.renderPanelSegment(target, frameSelectedTab1Full)
|
||||
case secondTab:
|
||||
x += w
|
||||
skillPanel.SetPosition(x, s.originY+h0)
|
||||
|
||||
if err := s.renderPanelSegment(target, frameSelectedTab2Top); err != nil {
|
||||
return err
|
||||
}
|
||||
s.renderPanelSegment(target, frameSelectedTab2Top)
|
||||
|
||||
skillPanel.SetPosition(x, y+h1)
|
||||
|
||||
if err := s.renderPanelSegment(target, frameSelectedTab2Bottom); err != nil {
|
||||
return err
|
||||
}
|
||||
s.renderPanelSegment(target, frameSelectedTab2Bottom)
|
||||
case thirdTab:
|
||||
skillPanel.SetPosition(x+w, y)
|
||||
|
||||
if err := s.renderPanelSegment(target, frameSelectedTab3Full); err != nil {
|
||||
return err
|
||||
}
|
||||
s.renderPanelSegment(target, frameSelectedTab3Full)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Render the skill tree panel
|
||||
func (s *skillTree) Render(target d2interface.Surface) error {
|
||||
if err := s.renderTabCommon(target); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := s.renderTab(target, s.selectedTab); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
func (s *skillTree) Render(target d2interface.Surface) {
|
||||
s.renderTabCommon(target)
|
||||
s.renderTab(target, s.selectedTab)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user