From c6ab79c388b904abb4d4f25809c7c926e65947d6 Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Mon, 14 Dec 2020 11:25:37 +0100 Subject: [PATCH] quest log disabled icon --- d2core/d2ui/button.go | 9 ++++-- d2core/d2ui/sprite.go | 2 +- d2game/d2gamescreen/character_select.go | 32 ++------------------- d2game/d2gamescreen/cinematics.go | 2 +- d2game/d2gamescreen/main_menu.go | 16 +++++------ d2game/d2player/quest_log.go | 37 +++++-------------------- 6 files changed, 26 insertions(+), 72 deletions(-) diff --git a/d2core/d2ui/button.go b/d2core/d2ui/button.go index af2dc51f..92cd6ee2 100644 --- a/d2core/d2ui/button.go +++ b/d2core/d2ui/button.go @@ -180,7 +180,7 @@ const ( blankQuestButtonXSegments = 1 blankQuestButtonYSegments = 1 - blankQuestButtonDisabledFrames = -1 + blankQuestButtonDisabledFrames = 0 buttonMinipanelCharacterBaseFrame = 0 buttonMinipanelInventoryBaseFrame = 2 @@ -900,7 +900,7 @@ func (v *Button) prerenderStates(btnSprite *Sprite, btnLayout *ButtonLayout, lab label.SetPosition(xOffset, textY) label.Render(v.normalSurface) - if !btnLayout.HasImage || !btnLayout.AllowFrameChange { + if !btnLayout.AllowFrameChange { return } @@ -1003,7 +1003,10 @@ func (v *Button) Render(target d2interface.Surface) { if v.toggled { target.Render(v.toggledSurface) } else { - target.Render(v.disabledSurface) + // it allows to use SetEnabled(false) for non-image budons + if v.buttonLayout.HasImage { + target.Render(v.disabledSurface) + } } case v.toggled && v.pressed: target.Render(v.pressedToggledSurface) diff --git a/d2core/d2ui/sprite.go b/d2core/d2ui/sprite.go index 91988891..7c66e1fd 100644 --- a/d2core/d2ui/sprite.go +++ b/d2core/d2ui/sprite.go @@ -74,7 +74,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 { - s.Error("SetCurrentFrame error" + err.Error()) + s.Errorf("Error while setting frame (%d): %s", idx, err) } target.PushTranslation(s.x+currentX, s.y+currentY) diff --git a/d2game/d2gamescreen/character_select.go b/d2game/d2gamescreen/character_select.go index 552ea523..feecc61a 100644 --- a/d2game/d2gamescreen/character_select.go +++ b/d2game/d2gamescreen/character_select.go @@ -1,7 +1,6 @@ package d2gamescreen import ( - "image/color" "math" "os" "strconv" @@ -190,7 +189,7 @@ func (v *CharacterSelect) OnLoad(loading d2screen.LoadingState) { v.characterNameLabel[i] = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits) v.characterNameLabel[i].SetPosition(offsetX, offsetY) - v.characterNameLabel[i].Color[0] = rgbaColor(lightBrown) + v.characterNameLabel[i].Color[0] = d2util.Color(lightBrown) offsetY += labelHeight @@ -201,7 +200,7 @@ func (v *CharacterSelect) OnLoad(loading d2screen.LoadingState) { v.characterExpLabel[i] = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteStatic) v.characterExpLabel[i].SetPosition(offsetX, offsetY) - v.characterExpLabel[i].Color[0] = rgbaColor(lightGreen) + v.characterExpLabel[i].Color[0] = d2util.Color(lightGreen) } v.refreshGameStates() @@ -267,31 +266,6 @@ func (v *CharacterSelect) loadCharScrollbar() { v.charScrollbar.OnActivated(func() { v.onScrollUpdate() }) } -func rgbaColor(rgba uint32) color.RGBA { - result := color.RGBA{} - a, b, g, r := 0, 1, 2, 3 - byteWidth := 8 - byteMask := 0xff - - for idx := 0; idx < 4; idx++ { - shift := idx * byteWidth - component := uint8(rgba>>shift) & uint8(byteMask) - - switch idx { - case a: - result.A = component - case b: - result.B = component - case g: - result.G = component - case r: - result.R = component - } - } - - return result -} - func (v *CharacterSelect) createButtons(loading d2screen.LoadingState) { v.newCharButton = v.uiManager.NewButton(d2ui.ButtonTypeTall, strings.Join( d2util.SplitIntoLinesWithMaxWidth(v.asset.TranslateString("#831"), 13), "\n")) @@ -411,7 +385,7 @@ func (v *CharacterSelect) Render(screen d2interface.Surface) { } if v.showDeleteConfirmation { - screen.DrawRect(screenWidth, screenHeight, rgbaColor(blackHalfOpacity)) + screen.DrawRect(screenWidth, screenHeight, d2util.Color(blackHalfOpacity)) v.okCancelBox.RenderSegmented(screen, 2, 1, 0) v.deleteCharConfirmLabel.Render(screen) } diff --git a/d2game/d2gamescreen/cinematics.go b/d2game/d2gamescreen/cinematics.go index f1aa9a41..ee3171e3 100644 --- a/d2game/d2gamescreen/cinematics.go +++ b/d2game/d2gamescreen/cinematics.go @@ -98,7 +98,7 @@ func (v *Cinematics) OnLoad(_ d2screen.LoadingState) { v.cinematicsLabel = v.uiManager.NewLabel(d2resource.Font30, d2resource.PaletteStatic) v.cinematicsLabel.Alignment = d2ui.HorizontalAlignCenter v.cinematicsLabel.SetText(v.asset.TranslateLabel(d2enum.SelectCinematicLabel)) - v.cinematicsLabel.Color[0] = rgbaColor(lightBrown) + v.cinematicsLabel.Color[0] = d2util.Color(lightBrown) v.cinematicsLabel.SetPosition(cinematicsLabelX, cinematicsLabelY) } diff --git a/d2game/d2gamescreen/main_menu.go b/d2game/d2gamescreen/main_menu.go index 6a96355d..8330973e 100644 --- a/d2game/d2gamescreen/main_menu.go +++ b/d2game/d2gamescreen/main_menu.go @@ -239,32 +239,32 @@ func (v *MainMenu) createLabels(loading d2screen.LoadingState) { v.versionLabel = v.uiManager.NewLabel(d2resource.FontFormal12, d2resource.PaletteStatic) v.versionLabel.Alignment = d2ui.HorizontalAlignRight v.versionLabel.SetText("OpenDiablo2 - " + v.buildInfo.Branch) - v.versionLabel.Color[0] = rgbaColor(white) + v.versionLabel.Color[0] = d2util.Color(white) v.versionLabel.SetPosition(versionLabelX, versionLabelY) v.commitLabel = v.uiManager.NewLabel(d2resource.FontFormal10, d2resource.PaletteStatic) v.commitLabel.Alignment = d2ui.HorizontalAlignLeft v.commitLabel.SetText(v.buildInfo.Commit) - v.commitLabel.Color[0] = rgbaColor(white) + v.commitLabel.Color[0] = d2util.Color(white) v.commitLabel.SetPosition(commitLabelX, commitLabelY) v.copyrightLabel = v.uiManager.NewLabel(d2resource.FontFormal12, d2resource.PaletteStatic) v.copyrightLabel.Alignment = d2ui.HorizontalAlignCenter v.copyrightLabel.SetText(v.asset.TranslateLabel(d2enum.CopyrightLabel)) - v.copyrightLabel.Color[0] = rgbaColor(lightBrown) + v.copyrightLabel.Color[0] = d2util.Color(lightBrown) v.copyrightLabel.SetPosition(copyrightX, copyrightY) loading.Progress(thirtyPercent) v.copyrightLabel2 = v.uiManager.NewLabel(d2resource.FontFormal12, d2resource.PaletteStatic) v.copyrightLabel2.Alignment = d2ui.HorizontalAlignCenter v.copyrightLabel2.SetText(v.asset.TranslateLabel(d2enum.AllRightsReservedLabel)) - v.copyrightLabel2.Color[0] = rgbaColor(lightBrown) + v.copyrightLabel2.Color[0] = d2util.Color(lightBrown) v.copyrightLabel2.SetPosition(copyright2X, copyright2Y) v.openDiabloLabel = v.uiManager.NewLabel(d2resource.FontFormal10, d2resource.PaletteStatic) v.openDiabloLabel.Alignment = d2ui.HorizontalAlignCenter v.openDiabloLabel.SetText("OpenDiablo2 is neither developed by, nor endorsed by Blizzard or its parent company Activision") - v.openDiabloLabel.Color[0] = rgbaColor(lightYellow) + v.openDiabloLabel.Color[0] = d2util.Color(lightYellow) v.openDiabloLabel.SetPosition(od2LabelX, od2LabelY) loading.Progress(fiftyPercent) @@ -276,19 +276,19 @@ func (v *MainMenu) createLabels(loading d2screen.LoadingState) { v.tcpJoinGameLabel = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits) v.tcpJoinGameLabel.Alignment = d2ui.HorizontalAlignCenter v.tcpJoinGameLabel.SetText(strings.Join(d2util.SplitIntoLinesWithMaxWidth(v.asset.TranslateLabel(d2enum.TCPIPEnterHostIPLabel), 27), "\n")) - v.tcpJoinGameLabel.Color[0] = rgbaColor(gold) + v.tcpJoinGameLabel.Color[0] = d2util.Color(gold) v.tcpJoinGameLabel.SetPosition(joinGameX, joinGameY) v.machineIP = v.uiManager.NewLabel(d2resource.Font24, d2resource.PaletteUnits) v.machineIP.Alignment = d2ui.HorizontalAlignCenter v.machineIP.SetText(v.asset.TranslateLabel(d2enum.TCPIPYourIPLabel) + "\n" + v.getLocalIP()) - v.machineIP.Color[0] = rgbaColor(lightYellow) + v.machineIP.Color[0] = d2util.Color(lightYellow) v.machineIP.SetPosition(machineIPX, machineIPY) if v.errorLabel != nil { v.errorLabel.SetPosition(errorLabelX, errorLabelY) v.errorLabel.Alignment = d2ui.HorizontalAlignCenter - v.errorLabel.Color[0] = rgbaColor(red) + v.errorLabel.Color[0] = d2util.Color(red) } } diff --git a/d2game/d2player/quest_log.go b/d2game/d2player/quest_log.go index d395be25..529edb2d 100644 --- a/d2game/d2player/quest_log.go +++ b/d2game/d2player/quest_log.go @@ -2,7 +2,6 @@ package d2player import ( "fmt" - "image/color" "strings" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" @@ -216,13 +215,13 @@ func (s *QuestLog) Load() { s.questName = s.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteStatic) s.questName.Alignment = d2ui.HorizontalAlignCenter - s.questName.Color[0] = rgbaColor(white) + s.questName.Color[0] = d2util.Color(white) s.questName.SetPosition(questNameLabelX, questNameLabelY) s.panelGroup.AddWidget(s.questName) s.questDescr = s.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteStatic) s.questDescr.Alignment = d2ui.HorizontalAlignLeft - s.questDescr.Color[0] = rgbaColor(white) + s.questDescr.Color[0] = d2util.Color(white) s.questDescr.SetPosition(questDescrLabelX, questDescrLabelY) s.panelGroup.AddWidget(s.questDescr) @@ -298,6 +297,8 @@ func (s *QuestLog) loadQuestIconsForAct(act int) *d2ui.WidgetGroup { button := s.uiManager.NewButton(d2ui.ButtonTypeBlankQuestBtn, "") button.SetPosition(x+questOffsetX, y+questOffsetY) + cw := n + button.SetEnabled(!(s.questStatus[s.cordsToQuestID(act, cw)] == d2enum.QuestStatusNotStarted)) buttons = append(buttons, button) icon, err = s.makeQuestIconForAct(act, n) @@ -383,7 +384,7 @@ func (s *QuestLog) setQuestLabel() { s.questName.SetText(s.asset.TranslateString(fmt.Sprintf("qstsa%dq%d", s.selectedTab+1, s.selectedQuest))) - status := s.questStatus[s.cordsToQuestID(s.selectedTab+1, s.selectedQuest)] + status := s.questStatus[s.cordsToQuestID(s.selectedTab+1, s.selectedQuest)-1] switch status { case d2enum.QuestStatusCompleted: s.questDescr.SetText( @@ -393,6 +394,8 @@ func (s *QuestLog) setQuestLabel() { questDescriptionLenght), "\n"), ) + case d2enum.QuestStatusCompleting: + s.questDescr.SetText("") case d2enum.QuestStatusNotStarted: s.questDescr.SetText("") default: @@ -527,32 +530,6 @@ func (s *QuestLog) renderStaticPanelFrames(target d2interface.Surface) { } } -// copy from character select (github.com/OpenDiablo2/OpenDiablo2/d2game/d2gamescreen/character_select.go) -func rgbaColor(rgba uint32) color.RGBA { - result := color.RGBA{} - a, b, g, r := 0, 1, 2, 3 - byteWidth := 8 - byteMask := 0xff - - for idx := 0; idx < 4; idx++ { - shift := idx * byteWidth - component := uint8(rgba>>shift) & uint8(byteMask) - - switch idx { - case a: - result.A = component - case b: - result.B = component - case g: - result.G = component - case r: - result.R = component - } - } - - return result -} - func (s *QuestLog) cordsToQuestID(act, number int) int { key := (act-1)*d2enum.NormalActQuestsNumber + number if act > d2enum.Act4 {