mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-12-25 19:46:50 -05:00
code cleanup
This commit is contained in:
parent
708ee12182
commit
ed89d91ae4
63
d2common/d2enum/quests.go
Normal file
63
d2common/d2enum/quests.go
Normal file
@ -0,0 +1,63 @@
|
||||
package d2enum
|
||||
|
||||
const (
|
||||
// NormalActQuestsNumber is number of quests in standard act
|
||||
NormalActQuestsNumber = 6
|
||||
// HalfQuestsNumber is number of quests in act 4
|
||||
HalfQuestsNumber = 3
|
||||
)
|
||||
|
||||
// ActsNumber is number of acts in game
|
||||
const ActsNumber = 5
|
||||
|
||||
const (
|
||||
// Act1 is act 1 in game
|
||||
Act1 = iota + 1
|
||||
// Act2 is act 2 in game
|
||||
Act2
|
||||
// Act3 is act 3 in game
|
||||
Act3
|
||||
// Act4 is act 4 in game
|
||||
Act4
|
||||
// Act5 is act 4 in game
|
||||
Act5
|
||||
)
|
||||
|
||||
// ActsWithHalfQuestNumber is act, where is half quest number (act4)
|
||||
const ActsWithHalfQuestNumber = Act4
|
||||
|
||||
/* I think, It should looks like that:
|
||||
each quest has its own position in questStatus map
|
||||
which should come from save file.
|
||||
quests status values:
|
||||
- -2 - done
|
||||
- -1 - done, need to play animation
|
||||
- 0 - not started yet
|
||||
- and after that we have "in progress status"
|
||||
so for status (from 1 to n) we have appropriate
|
||||
quest descriptions and we'll have appropriate
|
||||
actions
|
||||
*/
|
||||
const (
|
||||
QuestStatusCompleted = iota - 2 // quest completed
|
||||
QuestStatusCompleting // quest completed (need to play animation)
|
||||
QuestStatusNotStarted // quest not started yet
|
||||
QuestStatusInProgress // quest is in progress
|
||||
)
|
||||
|
||||
const (
|
||||
// QuestNone describes "no selected quest" status
|
||||
QuestNone = iota
|
||||
// Quest1 describes quest field 1
|
||||
Quest1
|
||||
// Quest2 describes quest field 2
|
||||
Quest2
|
||||
// Quest3 describes quest field 3
|
||||
Quest3
|
||||
// Quest4 describes quest field 4
|
||||
Quest4
|
||||
// Quest5 describes quest field 5
|
||||
Quest5
|
||||
// Quest6 describes quest field 6
|
||||
Quest6
|
||||
)
|
@ -5,6 +5,7 @@ import (
|
||||
"image/color"
|
||||
"strings"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
||||
@ -14,14 +15,6 @@ import (
|
||||
|
||||
const white = 0xffffffff
|
||||
|
||||
const (
|
||||
act1 = iota + 1
|
||||
act2
|
||||
act3
|
||||
act4
|
||||
act5
|
||||
)
|
||||
|
||||
const ( // for the dc6 frames
|
||||
questLogTopLeft = iota
|
||||
questLogTopRight
|
||||
@ -29,19 +22,6 @@ const ( // for the dc6 frames
|
||||
questLogBottomRight
|
||||
)
|
||||
|
||||
const (
|
||||
questStatusCompleted = iota - 2 // quest completed
|
||||
questStatusCompleting // quest completed (need to play animation)
|
||||
questStatusNotStarted // quest not started yet
|
||||
// nolint:deadcode,varcheck // if will not be used, just remove
|
||||
questStatusInProgress // quest is in progress
|
||||
)
|
||||
|
||||
const (
|
||||
normalActQuestsNumber = 6
|
||||
act4QuestsNumber = 3
|
||||
)
|
||||
|
||||
const (
|
||||
questLogOffsetX, questLogOffsetY = 80, 64
|
||||
)
|
||||
@ -83,10 +63,6 @@ const (
|
||||
questLogNumTabs
|
||||
)
|
||||
|
||||
const (
|
||||
questNone = 0
|
||||
)
|
||||
|
||||
func (s *QuestLog) getPositionForSocket(number int) (x, y int) {
|
||||
pos := []struct {
|
||||
x int
|
||||
@ -142,6 +118,11 @@ func NewQuestLog(asset *d2asset.AssetManager,
|
||||
26: 0,
|
||||
}
|
||||
|
||||
var quests [d2enum.ActsNumber]*d2ui.WidgetGroup
|
||||
for i := 0; i < d2enum.ActsNumber; i++ {
|
||||
quests[i] = ui.NewWidgetGroup(d2ui.RenderPriorityQuestLog)
|
||||
}
|
||||
|
||||
ql := &QuestLog{
|
||||
asset: asset,
|
||||
uiManager: ui,
|
||||
@ -155,6 +136,7 @@ func NewQuestLog(asset *d2asset.AssetManager,
|
||||
{},
|
||||
{},
|
||||
},
|
||||
quests: quests,
|
||||
questStatus: qs,
|
||||
}
|
||||
|
||||
@ -179,24 +161,7 @@ type QuestLog struct {
|
||||
|
||||
questName *d2ui.Label
|
||||
questDescr *d2ui.Label
|
||||
questsa1 *d2ui.WidgetGroup
|
||||
questsa2 *d2ui.WidgetGroup
|
||||
questsa3 *d2ui.WidgetGroup
|
||||
questsa4 *d2ui.WidgetGroup
|
||||
questsa5 *d2ui.WidgetGroup
|
||||
|
||||
/* I think, It should looks like that:
|
||||
each quest has its own position in questStatus map
|
||||
which should come from save file.
|
||||
quests status values:
|
||||
- -2 - done
|
||||
- -1 - done, need to play animation
|
||||
- 0 - not started yet
|
||||
- and after that we have "in progress status"
|
||||
so for status (from 1 to n) we have appropriate
|
||||
quest descriptions and we'll have appropriate
|
||||
actions
|
||||
*/
|
||||
quests [5]*d2ui.WidgetGroup
|
||||
questStatus map[int]int
|
||||
|
||||
originX int
|
||||
@ -238,11 +203,6 @@ func (q *questLogTab) newTab(ui *d2ui.UIManager, tabType d2ui.ButtonType, x int)
|
||||
func (s *QuestLog) Load() {
|
||||
var err error
|
||||
|
||||
s.questsa1 = s.uiManager.NewWidgetGroup(d2ui.RenderPriorityQuestLog)
|
||||
s.questsa2 = s.uiManager.NewWidgetGroup(d2ui.RenderPriorityQuestLog)
|
||||
s.questsa3 = s.uiManager.NewWidgetGroup(d2ui.RenderPriorityQuestLog)
|
||||
s.questsa4 = s.uiManager.NewWidgetGroup(d2ui.RenderPriorityQuestLog)
|
||||
s.questsa5 = s.uiManager.NewWidgetGroup(d2ui.RenderPriorityQuestLog)
|
||||
s.panelGroup = s.uiManager.NewWidgetGroup(d2ui.RenderPriorityQuestLog)
|
||||
|
||||
frame := d2ui.NewUIFrame(s.asset, s.uiManager, d2ui.FrameLeft)
|
||||
@ -282,7 +242,10 @@ func (s *QuestLog) Load() {
|
||||
s.panelGroup.AddWidget(s.questDescr)
|
||||
|
||||
s.loadTabs()
|
||||
s.loadQuestIcons()
|
||||
|
||||
for i := 0; i < 5; i++ {
|
||||
s.quests[i] = s.loadQuestIconsForAct(i + 1)
|
||||
}
|
||||
|
||||
s.panelGroup.SetVisible(false)
|
||||
}
|
||||
@ -316,22 +279,14 @@ func (s *QuestLog) loadTabs() {
|
||||
s.setTab(s.act - 1)
|
||||
}
|
||||
|
||||
func (s *QuestLog) loadQuestIcons() {
|
||||
s.questsa1 = s.loadQuestIconsForAct(act1)
|
||||
s.questsa2 = s.loadQuestIconsForAct(act2)
|
||||
s.questsa3 = s.loadQuestIconsForAct(act3)
|
||||
s.questsa4 = s.loadQuestIconsForAct(act4)
|
||||
s.questsa5 = s.loadQuestIconsForAct(act5)
|
||||
}
|
||||
|
||||
func (s *QuestLog) loadQuestIconsForAct(act int) *d2ui.WidgetGroup {
|
||||
wg := s.uiManager.NewWidgetGroup(d2ui.RenderPriorityQuestLog)
|
||||
|
||||
var questsInAct int
|
||||
if act == act4 {
|
||||
questsInAct = act4QuestsNumber
|
||||
if act == d2enum.Act4 {
|
||||
questsInAct = d2enum.HalfQuestsNumber
|
||||
} else {
|
||||
questsInAct = normalActQuestsNumber
|
||||
questsInAct = d2enum.NormalActQuestsNumber
|
||||
}
|
||||
|
||||
var sockets []*d2ui.Sprite
|
||||
@ -361,9 +316,9 @@ func (s *QuestLog) loadQuestIconsForAct(act int) *d2ui.WidgetGroup {
|
||||
}
|
||||
|
||||
switch s.questStatus[s.cordsToQuestID(act, n)] {
|
||||
case questStatusCompleted:
|
||||
case d2enum.QuestStatusCompleted:
|
||||
err = icon.SetCurrentFrame(completedFrame)
|
||||
case questStatusCompleting:
|
||||
case d2enum.QuestStatusCompleting:
|
||||
// that's not complet now
|
||||
err = icon.SetCurrentFrame(0)
|
||||
if err != nil {
|
||||
@ -371,9 +326,10 @@ func (s *QuestLog) loadQuestIconsForAct(act int) *d2ui.WidgetGroup {
|
||||
}
|
||||
|
||||
icon.PlayForward()
|
||||
icon.SetPlayLoop(false)
|
||||
err = icon.SetCurrentFrame(completedFrame)
|
||||
s.questStatus[s.cordsToQuestID(act, n)] = questStatusCompleted
|
||||
case questStatusNotStarted:
|
||||
s.questStatus[s.cordsToQuestID(act, n)] = d2enum.QuestStatusCompleted
|
||||
case d2enum.QuestStatusNotStarted:
|
||||
err = icon.SetCurrentFrame(notStartedFrame)
|
||||
default:
|
||||
err = icon.SetCurrentFrame(inProgresFrame)
|
||||
@ -432,7 +388,7 @@ func (s *QuestLog) setQuestLabel() {
|
||||
|
||||
status := s.questStatus[s.cordsToQuestID(s.selectedTab+1, s.selectedQuest)]
|
||||
switch status {
|
||||
case questStatusCompleted, questStatusCompleting:
|
||||
case d2enum.QuestStatusCompleted:
|
||||
s.questDescr.SetText(
|
||||
strings.Join(
|
||||
d2util.SplitIntoLinesWithMaxWidth(
|
||||
@ -440,7 +396,7 @@ func (s *QuestLog) setQuestLabel() {
|
||||
questDescriptionLenght),
|
||||
"\n"),
|
||||
)
|
||||
case questStatusNotStarted:
|
||||
case d2enum.QuestStatusNotStarted:
|
||||
s.questDescr.SetText("")
|
||||
default:
|
||||
s.questDescr.SetText(strings.Join(
|
||||
@ -456,14 +412,12 @@ func (s *QuestLog) setQuestLabel() {
|
||||
|
||||
func (s *QuestLog) setTab(tab int) {
|
||||
s.selectedTab = tab
|
||||
s.selectedQuest = questNone
|
||||
s.selectedQuest = d2enum.QuestNone
|
||||
s.setQuestLabel()
|
||||
|
||||
s.questsa1.SetVisible(tab == questLogTab1)
|
||||
s.questsa2.SetVisible(tab == questLogTab2)
|
||||
s.questsa3.SetVisible(tab == questLogTab3)
|
||||
s.questsa4.SetVisible(tab == questLogTab4)
|
||||
s.questsa5.SetVisible(tab == questLogTab5)
|
||||
for i := 0; i < d2enum.ActsNumber; i++ {
|
||||
s.quests[i].SetVisible(tab == i)
|
||||
}
|
||||
|
||||
for i := 0; i < questLogNumTabs; i++ {
|
||||
s.tab[i].button.SetEnabled(i == tab)
|
||||
@ -505,11 +459,11 @@ func (s *QuestLog) Open() {
|
||||
func (s *QuestLog) Close() {
|
||||
s.isOpen = false
|
||||
s.panelGroup.SetVisible(false)
|
||||
s.questsa1.SetVisible(false)
|
||||
s.questsa2.SetVisible(false)
|
||||
s.questsa3.SetVisible(false)
|
||||
s.questsa4.SetVisible(false)
|
||||
s.questsa5.SetVisible(false)
|
||||
|
||||
for i := 0; i < d2enum.ActsNumber; i++ {
|
||||
s.quests[i].SetVisible(false)
|
||||
}
|
||||
|
||||
s.onCloseCb()
|
||||
}
|
||||
|
||||
@ -590,9 +544,9 @@ func rgbaColor(rgba uint32) color.RGBA {
|
||||
}
|
||||
|
||||
func (s *QuestLog) cordsToQuestID(act, number int) int {
|
||||
key := (act-1)*normalActQuestsNumber + number
|
||||
if act > act4 {
|
||||
key -= act4QuestsNumber
|
||||
key := (act-1)*d2enum.NormalActQuestsNumber + number
|
||||
if act > d2enum.Act4 {
|
||||
key -= d2enum.HalfQuestsNumber
|
||||
}
|
||||
|
||||
return key
|
||||
@ -600,21 +554,21 @@ func (s *QuestLog) cordsToQuestID(act, number int) int {
|
||||
|
||||
//nolint:deadcode,unused // I think, it will be used, if not, we can just remove it
|
||||
func (s *QuestLog) questIDToCords(id int) (act, number int) {
|
||||
act = act1
|
||||
act = 1
|
||||
|
||||
for i := 0; i < normalActQuestsNumber; i++ {
|
||||
if id < normalActQuestsNumber {
|
||||
for i := 0; i < d2enum.ActsNumber; i++ {
|
||||
if id < d2enum.NormalActQuestsNumber {
|
||||
break
|
||||
}
|
||||
|
||||
act++
|
||||
|
||||
id -= normalActQuestsNumber
|
||||
id -= d2enum.NormalActQuestsNumber
|
||||
}
|
||||
|
||||
number = id
|
||||
if act > act4 {
|
||||
number -= act4QuestsNumber
|
||||
if act > d2enum.Act4 {
|
||||
number -= d2enum.HalfQuestsNumber
|
||||
}
|
||||
|
||||
return act, number
|
||||
|
Loading…
Reference in New Issue
Block a user