mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-02 22:57:04 -05:00
party panel: colored labels; d2ui improvement: SwitchableButton.SetState() method; lintfix
This commit is contained in:
parent
6e82942b1f
commit
71e4470c25
@ -1,8 +1,11 @@
|
||||
package d2enum
|
||||
|
||||
// PlayersRelationships represents players relationships
|
||||
type PlayersRelationships int
|
||||
|
||||
// Players relationships
|
||||
const (
|
||||
PlayerRelationNeutral = iota
|
||||
PlayerRelationNeutral PlayersRelationships = iota
|
||||
PlayerRelationFriend
|
||||
PlayerRelationEnemy
|
||||
)
|
||||
|
@ -82,6 +82,12 @@ func (sbtn *SwitchableButton) Deactivate() {
|
||||
sbtn.onDeactivate()
|
||||
}
|
||||
|
||||
// SetState sets button's state
|
||||
func (sbtn *SwitchableButton) SetState(state bool) {
|
||||
sbtn.state = state
|
||||
sbtn.SetVisible(sbtn.GetVisible())
|
||||
}
|
||||
|
||||
// SetPosition sets widget's position
|
||||
func (sbtn *SwitchableButton) SetPosition(x, y int) {
|
||||
sbtn.BaseWidget.SetPosition(x, y)
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
|
||||
)
|
||||
@ -64,10 +65,11 @@ type partyIndex struct {
|
||||
relationshipSwitcher *d2ui.SwitchableButton
|
||||
seeingSwitcher *d2ui.SwitchableButton
|
||||
listeningSwitcher *d2ui.SwitchableButton
|
||||
relationships d2enum.PlayersRelationships
|
||||
}
|
||||
|
||||
// newPartyIndex creates new party index
|
||||
func (s *PartyPanel) newPartyIndex(name string, class d2enum.Hero, level, idx int) *partyIndex {
|
||||
func (s *PartyPanel) newPartyIndex(name string, class d2enum.Hero, level, idx int, relations d2enum.PlayersRelationships) *partyIndex {
|
||||
result := &partyIndex{}
|
||||
|
||||
nameLabel := s.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteSky)
|
||||
@ -95,9 +97,30 @@ func (s *PartyPanel) newPartyIndex(name string, class d2enum.Hero, level, idx in
|
||||
listening := s.createSwitcher(listeningButtonFrame, listeningSwitcherX, baseListeningSwitcherY+nextBar*idx)
|
||||
result.listeningSwitcher = listening
|
||||
|
||||
result.relationships = relations
|
||||
|
||||
result.setColor(relations)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (pi *partyIndex) setColor(relations d2enum.PlayersRelationships) {
|
||||
var color = d2util.Color(d2gui.ColorWhite)
|
||||
|
||||
switch relations {
|
||||
case d2enum.PlayerRelationEnemy:
|
||||
color = d2util.Color(d2gui.ColorRed)
|
||||
|
||||
pi.relationshipSwitcher.SetState(false)
|
||||
case d2enum.PlayerRelationFriend:
|
||||
color = d2util.Color(d2gui.ColorGreen)
|
||||
}
|
||||
|
||||
pi.name.Color[0] = color
|
||||
pi.class.Color[0] = color
|
||||
pi.level.Color[0] = color
|
||||
}
|
||||
|
||||
// NewPartyPanel creates a new party panel
|
||||
func NewPartyPanel(asset *d2asset.AssetManager,
|
||||
ui *d2ui.UIManager,
|
||||
@ -189,14 +212,16 @@ func (s *PartyPanel) Load() {
|
||||
s.Error(err.Error())
|
||||
}
|
||||
|
||||
s.barX, s.barY = barX, baseBarY+1*nextBar
|
||||
// nolint:gomnd // test data
|
||||
s.barX, s.barY = barX, baseBarY+2*nextBar
|
||||
w, h = s.bar.GetCurrentFrameSize()
|
||||
v := s.uiManager.NewCustomWidget(s.renderBar, w, h)
|
||||
s.panelGroup.AddWidget(v)
|
||||
|
||||
// example data
|
||||
s.partyIndexes[0] = s.newPartyIndex("PartyMember", d2enum.HeroPaladin, 5, 0)
|
||||
s.partyIndexes[1] = s.newPartyIndex("gameMember1", d2enum.HeroPaladin, 99, 1)
|
||||
s.partyIndexes[0] = s.newPartyIndex("PartyMember", d2enum.HeroPaladin, 5, 0, d2enum.PlayerRelationEnemy)
|
||||
s.partyIndexes[1] = s.newPartyIndex("gameMember1", d2enum.HeroPaladin, 99, 1, d2enum.PlayerRelationFriend)
|
||||
|
||||
for _, i := range s.partyIndexes {
|
||||
// needed for "developing time" to avoit panic
|
||||
if i.name != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user