From 60a3e66c9521d927f537212de5fe8a080e354302 Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Mon, 14 Dec 2020 19:01:27 +0100 Subject: [PATCH 1/7] escape menu hotkeys --- d2game/d2player/escape_menu.go | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/d2game/d2player/escape_menu.go b/d2game/d2player/escape_menu.go index 2609da1f..0625add1 100644 --- a/d2game/d2player/escape_menu.go +++ b/d2game/d2player/escape_menu.go @@ -398,25 +398,15 @@ func (m *EscapeMenu) OnLoad() { // OnEscKey is called when the escape key is pressed func (m *EscapeMenu) OnEscKey() { - // note: original D2 returns straight to the game from however deep in the menu we are - switch m.currentLayout { - case optionsLayoutID: - m.setLayout(mainLayoutID) - return - case soundOptionsLayoutID, - videoOptionsLayoutID, - automapOptionsLayoutID, - configureControlsLayoutID: + if m.currentLayout == configureControlsLayoutID { m.setLayout(optionsLayoutID) if err := m.keyBindingMenu.Close(); err != nil { m.Errorf("unable to close the configure controls menu: %v", err.Error()) } - - return + } else { + m.close() } - - m.close() } // SetOnCloseCb sets the callback that is run when close() is called From 9c019afd940c065aba34789956847de3a165c49b Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Tue, 15 Dec 2020 09:16:40 +0100 Subject: [PATCH 2/7] hero save file --- d2app/app.go | 21 +++++++++++---------- d2core/d2hero/hero_stats_state.go | 31 ++++++++++++++----------------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/d2app/app.go b/d2app/app.go index f4ae128c..272af28c 100644 --- a/d2app/app.go +++ b/d2app/app.go @@ -233,11 +233,12 @@ func (a *App) parseArguments() { loggingShort = 'l' loggingDesc = "Enables verbose logging. Log levels will include those below it. " + "0 disables log messages, " + - "1 shows errors, " + - "2 shows warnings, " + - "3 shows info, " + - "4 shows debug" + - "5 uses value from config file (default)" + "1 shows fatal errors, " + + "2 shows errors, " + + "3 shows warnings, " + + "4 shows info, " + + "5 shows debug" + + "6 uses value from config file (default)" ) a.Options.profiler = kingpin.Flag(profilerArg, profilerDesc).String() @@ -315,7 +316,7 @@ func (a *App) Run() error { a.gitCommit = "build" } - fmt.Printf(fmtVersion, a.gitBranch, a.gitCommit) + a.Errorf(fmtVersion, a.gitBranch, a.gitCommit) os.Exit(0) } @@ -739,7 +740,7 @@ func (a *App) doCaptureFrame(target d2interface.Surface) error { return err } - a.Info(fmt.Sprintf("saved frame to %s", a.capturePath)) + a.Infof("saved frame to %s", a.capturePath) return nil } @@ -799,7 +800,7 @@ func (a *App) convertFramesToGif() error { return err } - a.Info(fmt.Sprintf("saved animation to %s", a.capturePath)) + a.Infof("saved animation to %s", a.capturePath) return nil } @@ -937,7 +938,7 @@ func (a *App) ToCreateGame(filePath string, connType d2clientconnectiontype.Clie if err = gameClient.Open(host, filePath); err != nil { errorMessage := fmt.Sprintf("can not connect to the host: %s", host) - fmt.Println(errorMessage) + a.Error(errorMessage) a.ToMainMenu(errorMessage) } else { game, err := d2gamescreen.CreateGame( @@ -956,7 +957,7 @@ func (a *App) ToCharacterSelect(connType d2clientconnectiontype.ClientConnection characterSelect, err := d2gamescreen.CreateCharacterSelect(a, a.asset, a.renderer, a.inputManager, a.audio, a.ui, connType, a.config.LogLevel, connHost) if err != nil { - fmt.Printf("unable to create character select screen: %s", err) + a.Errorf("unable to create character select screen: %s", err) } a.screen.SetNextScreen(characterSelect) diff --git a/d2core/d2hero/hero_stats_state.go b/d2core/d2hero/hero_stats_state.go index 04ad52a4..46c32be6 100644 --- a/d2core/d2hero/hero_stats_state.go +++ b/d2core/d2hero/hero_stats_state.go @@ -10,28 +10,23 @@ type HeroStatsState struct { Level int `json:"level"` Experience int `json:"experience"` - Vitality int `json:"vitality"` - Energy int `json:"energy"` Strength int `json:"strength"` + Energy int `json:"energy"` Dexterity int `json:"dexterity"` + Vitality int `json:"vitality"` + // there are stats and skills points remaining to add. + StatPoints int `json:"statPoints"` + SkillPoints int `json:"skillPoints"` - AttackRating int `json:"attackRating"` - DefenseRating int `json:"defenseRating"` - - MaxStamina int `json:"maxStamina"` - Health int `json:"health"` - MaxHealth int `json:"maxHealth"` - Mana int `json:"mana"` - MaxMana int `json:"maxMana"` - - FireResistance int `json:"fireResistance"` - ColdResistance int `json:"coldResistance"` - LightningResistance int `json:"lightningResistance"` - PoisonResistance int `json:"poisonResistance"` + Health int `json:"health"` + MaxHealth int `json:"maxHealth"` + Mana int `json:"mana"` + MaxMana int `json:"maxMana"` + Stamina float64 `json:"-"` // only MaxStamina is saved, Stamina gets reset on entering world + MaxStamina int `json:"maxStamina"` // values which are not saved/loaded(computed) - Stamina float64 `json:"-"` // only MaxStamina is saved, Stamina gets reset on entering world - NextLevelExp int `json:"-"` + NextLevelExp int `json:"-"` } // CreateHeroStatsState generates a running state from a hero stats. @@ -44,6 +39,8 @@ func (f *HeroStateFactory) CreateHeroStatsState(heroClass d2enum.Hero, classStat Dexterity: classStats.InitDex, Vitality: classStats.InitVit, Energy: classStats.InitEne, + StatPoints: 0, + SkillPoints: 0, MaxHealth: classStats.InitVit * classStats.LifePerVit, MaxMana: classStats.InitEne * classStats.ManaPerEne, From 7e346bd03936cb13e9909e0dfc8e89aa3192be91 Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Tue, 15 Dec 2020 11:32:34 +0100 Subject: [PATCH 3/7] add-buttons init --- d2core/d2hero/hero_stats_state.go | 4 ++-- d2core/d2ui/button.go | 14 ++++++++++++++ d2game/d2player/game_controls.go | 2 +- d2game/d2player/hud.go | 27 +++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/d2core/d2hero/hero_stats_state.go b/d2core/d2hero/hero_stats_state.go index 46c32be6..96400b2f 100644 --- a/d2core/d2hero/hero_stats_state.go +++ b/d2core/d2hero/hero_stats_state.go @@ -15,7 +15,7 @@ type HeroStatsState struct { Dexterity int `json:"dexterity"` Vitality int `json:"vitality"` // there are stats and skills points remaining to add. - StatPoints int `json:"statPoints"` + StatsPoints int `json:"statsPoints"` SkillPoints int `json:"skillPoints"` Health int `json:"health"` @@ -39,7 +39,7 @@ func (f *HeroStateFactory) CreateHeroStatsState(heroClass d2enum.Hero, classStat Dexterity: classStats.InitDex, Vitality: classStats.InitVit, Energy: classStats.InitEne, - StatPoints: 0, + StatsPoints: 0, SkillPoints: 0, MaxHealth: classStats.InitVit * classStats.LifePerVit, diff --git a/d2core/d2ui/button.go b/d2core/d2ui/button.go index cdaf9c24..fe396b07 100644 --- a/d2core/d2ui/button.go +++ b/d2core/d2ui/button.go @@ -55,6 +55,7 @@ const ( ButtonTypeSquelchChat ButtonType = 35 ButtonTypeTabBlank ButtonType = 36 ButtonTypeBlankQuestBtn ButtonType = 37 + ButtonTypeAddSkill ButtonType = 38 ButtonNoFixedWidth int = -1 ButtonNoFixedHeight int = -1 @@ -746,6 +747,19 @@ func getButtonLayouts() map[ButtonType]ButtonLayout { FixedHeight: ButtonNoFixedHeight, LabelColor: whiteAlpha100, }, + ButtonTypeAddSkill: { + XSegments: 1, + YSegments: 1, + DisabledColor: whiteAlpha100, + ResourceName: d2resource.AddSkillButton, + PaletteName: d2resource.PaletteSky, + Toggleable: true, + FontPath: d2resource.Font16, + AllowFrameChange: true, + HasImage: true, + FixedWidth: ButtonNoFixedWidth, + FixedHeight: ButtonNoFixedHeight, + }, } } diff --git a/d2game/d2player/game_controls.go b/d2game/d2player/game_controls.go index 2335cc52..451bd3d5 100644 --- a/d2game/d2player/game_controls.go +++ b/d2game/d2player/game_controls.go @@ -224,7 +224,7 @@ func NewGameControls( } helpOverlay := NewHelpOverlay(asset, ui, l, keyMap) - hud := NewHUD(asset, ui, hero, miniPanel, actionableRegions, mapEngine, l, mapRenderer) + hud := NewHUD(asset, ui, hero, miniPanel, actionableRegions, mapEngine, hero.Stats, l, mapRenderer) const blackAlpha50percent = 0x0000007f diff --git a/d2game/d2player/hud.go b/d2game/d2player/hud.go index be455a3f..632ea227 100644 --- a/d2game/d2player/hud.go +++ b/d2game/d2player/hud.go @@ -10,6 +10,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/d2hero" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapengine" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapentity" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2maprenderer" @@ -70,6 +71,11 @@ const ( whiteAlpha100 = 0xffffffff ) +const ( + addStatsButtonX, addStatsButtonY = 206, 561 + addSkillButtonX, addSkillButtonY = 563, 561 +) + // HUD represents the always visible user interface of the game type HUD struct { actionableRegions []actionableRegion @@ -77,6 +83,7 @@ type HUD struct { uiManager *d2ui.UIManager mapEngine *d2mapengine.MapEngine mapRenderer *d2maprenderer.MapRenderer + heroStats *d2hero.HeroStatsState lastMouseX int lastMouseY int hero *d2mapentity.Player @@ -103,6 +110,8 @@ type HUD struct { widgetLeftSkill *d2ui.CustomWidget widgetRightSkill *d2ui.CustomWidget panelBackground *d2ui.CustomWidget + addStatsButton *d2ui.Button + addSkillButton *d2ui.Button panelGroup *d2ui.WidgetGroup *d2util.Logger } @@ -115,6 +124,7 @@ func NewHUD( miniPanel *miniPanel, actionableRegions []actionableRegion, mapEngine *d2mapengine.MapEngine, + heroStats *d2hero.HeroStatsState, l d2util.LogLevel, mapRenderer *d2maprenderer.MapRenderer, ) *HUD { @@ -149,6 +159,7 @@ func NewHUD( zoneChangeText: zoneLabel, healthGlobe: healthGlobe, manaGlobe: manaGlobe, + heroStats: heroStats, } hud.Logger = d2util.NewLogger() @@ -177,7 +188,23 @@ func (h *HUD) Load() { h.loadCustomWidgets() h.loadUIButtons() + h.addStatsButton = h.uiManager.NewButton(d2ui.ButtonTypeAddSkill, "") + h.addStatsButton.SetPosition(addStatsButtonX, addStatsButtonY) + h.addStatsButton.SetVisible(false) + h.panelGroup.AddWidget(h.addStatsButton) + + h.addSkillButton = h.uiManager.NewButton(d2ui.ButtonTypeAddSkill, "") + h.addSkillButton.SetPosition(addSkillButtonX, addSkillButtonY) + h.addSkillButton.SetVisible(false) + h.panelGroup.AddWidget(h.addSkillButton) + h.panelGroup.SetVisible(true) + h.setAddButtonsVisible() +} + +func (h *HUD) setAddButtonsVisible() { + h.addStatsButton.SetVisible(h.heroStats.StatsPoints > 0) + h.addSkillButton.SetVisible(h.heroStats.SkillPoints > 0) } func (h *HUD) loadCustomWidgets() { From 3220cc93f4eafb434f226f5e9dc32e528db02ce0 Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Tue, 15 Dec 2020 12:37:35 +0100 Subject: [PATCH 4/7] add-buttons actions --- d2core/d2ui/button.go | 1 + d2game/d2player/game_controls.go | 24 +++++++++++++++++++----- d2game/d2player/hud.go | 14 ++++---------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/d2core/d2ui/button.go b/d2core/d2ui/button.go index fe396b07..03b46c8a 100644 --- a/d2core/d2ui/button.go +++ b/d2core/d2ui/button.go @@ -750,6 +750,7 @@ func getButtonLayouts() map[ButtonType]ButtonLayout { ButtonTypeAddSkill: { XSegments: 1, YSegments: 1, + DisabledFrame: 2, DisabledColor: whiteAlpha100, ResourceName: d2resource.AddSkillButton, PaletteName: d2resource.PaletteSky, diff --git a/d2game/d2player/game_controls.go b/d2game/d2player/game_controls.go index 451bd3d5..98fc3d83 100644 --- a/d2game/d2player/game_controls.go +++ b/d2game/d2player/game_controls.go @@ -224,13 +224,9 @@ func NewGameControls( } helpOverlay := NewHelpOverlay(asset, ui, l, keyMap) - hud := NewHUD(asset, ui, hero, miniPanel, actionableRegions, mapEngine, hero.Stats, l, mapRenderer) const blackAlpha50percent = 0x0000007f - hoverLabel := hud.nameLabel - hoverLabel.SetBackgroundColor(d2util.Color(blackAlpha50percent)) - gc := &GameControls{ asset: asset, ui: ui, @@ -246,7 +242,6 @@ func NewGameControls( questLog: questLog, HelpOverlay: helpOverlay, keyMap: keyMap, - hud: hud, bottomMenuRect: &d2geom.Rectangle{ Left: menuBottomRectX, Top: menuBottomRectY, @@ -271,6 +266,12 @@ func NewGameControls( isSinglePlayer: isSinglePlayer, } + hud := NewHUD(asset, ui, hero, miniPanel, actionableRegions, mapEngine, l, gc, mapRenderer) + gc.hud = hud + + hoverLabel := hud.nameLabel + hoverLabel.SetBackgroundColor(d2util.Color(blackAlpha50percent)) + gc.heroStatsPanel.SetOnCloseCb(gc.onCloseHeroStatsPanel) gc.questLog.SetOnCloseCb(gc.onCloseQuestLog) gc.inventory.SetOnCloseCb(gc.onCloseInventory) @@ -713,6 +714,9 @@ func (g *GameControls) Load() { g.questLog.Load() g.HelpOverlay.Load() + g.loadAddButtons() + g.SetAddButtons() + miniPanelActions := &miniPanelActions{ characterToggle: g.toggleHeroStatsPanel, inventoryToggle: g.toggleInventoryPanel, @@ -1099,3 +1103,13 @@ func (g *GameControls) bindTerminalCommands(term d2interface.Terminal) error { return nil } + +func (g *GameControls) SetAddButtons() { + g.hud.addStatsButton.SetEnabled(g.hero.Stats.StatsPoints > 0) + g.hud.addSkillButton.SetEnabled(g.hero.Stats.SkillPoints > 0) +} + +func (g *GameControls) loadAddButtons() { + g.hud.addStatsButton.OnActivated(func() { g.toggleHeroStatsPanel() }) + g.hud.addSkillButton.OnActivated(func() { g.toggleSkilltreePanel() }) +} diff --git a/d2game/d2player/hud.go b/d2game/d2player/hud.go index 632ea227..eefb3784 100644 --- a/d2game/d2player/hud.go +++ b/d2game/d2player/hud.go @@ -10,7 +10,6 @@ import ( "github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2util" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset" - "github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapengine" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapentity" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2maprenderer" @@ -83,7 +82,6 @@ type HUD struct { uiManager *d2ui.UIManager mapEngine *d2mapengine.MapEngine mapRenderer *d2maprenderer.MapRenderer - heroStats *d2hero.HeroStatsState lastMouseX int lastMouseY int hero *d2mapentity.Player @@ -113,6 +111,8 @@ type HUD struct { addStatsButton *d2ui.Button addSkillButton *d2ui.Button panelGroup *d2ui.WidgetGroup + gameControls *GameControls + *d2util.Logger } @@ -124,8 +124,8 @@ func NewHUD( miniPanel *miniPanel, actionableRegions []actionableRegion, mapEngine *d2mapengine.MapEngine, - heroStats *d2hero.HeroStatsState, l d2util.LogLevel, + gameControls *GameControls, mapRenderer *d2maprenderer.MapRenderer, ) *HUD { nameLabel := ui.NewLabel(d2resource.Font16, d2resource.PaletteStatic) @@ -159,7 +159,7 @@ func NewHUD( zoneChangeText: zoneLabel, healthGlobe: healthGlobe, manaGlobe: manaGlobe, - heroStats: heroStats, + gameControls: gameControls, } hud.Logger = d2util.NewLogger() @@ -199,12 +199,6 @@ func (h *HUD) Load() { h.panelGroup.AddWidget(h.addSkillButton) h.panelGroup.SetVisible(true) - h.setAddButtonsVisible() -} - -func (h *HUD) setAddButtonsVisible() { - h.addStatsButton.SetVisible(h.heroStats.StatsPoints > 0) - h.addSkillButton.SetVisible(h.heroStats.SkillPoints > 0) } func (h *HUD) loadCustomWidgets() { From be8b3e3157d8ea71aed10b51e9fbecea5b50c582 Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Tue, 15 Dec 2020 18:02:52 +0100 Subject: [PATCH 5/7] stats changing: hero stats panel --- d2common/d2resource/resource_paths.go | 22 ++--- d2core/d2ui/button.go | 10 ++- d2game/d2player/game_controls.go | 8 +- d2game/d2player/hero_stats_panel.go | 114 ++++++++++++++++++++++++-- 4 files changed, 130 insertions(+), 24 deletions(-) diff --git a/d2common/d2resource/resource_paths.go b/d2common/d2resource/resource_paths.go index a18a196f..dc950ebc 100644 --- a/d2common/d2resource/resource_paths.go +++ b/d2common/d2resource/resource_paths.go @@ -243,16 +243,18 @@ const ( MinipanelSmall = "/data/global/ui/PANEL/minipanel_s.dc6" MinipanelButton = "/data/global/ui/PANEL/minipanelbtn.DC6" - Frame = "/data/global/ui/PANEL/800borderframe.dc6" - InventoryCharacterPanel = "/data/global/ui/PANEL/invchar6.DC6" - InventoryWeaponsTab = "/data/global/ui/PANEL/invchar6Tab.DC6" - SkillsPanelAmazon = "/data/global/ui/SPELLS/skltree_a_back.DC6" - SkillsPanelBarbarian = "/data/global/ui/SPELLS/skltree_b_back.DC6" - SkillsPanelDruid = "/data/global/ui/SPELLS/skltree_d_back.DC6" - SkillsPanelAssassin = "/data/global/ui/SPELLS/skltree_i_back.DC6" - SkillsPanelNecromancer = "/data/global/ui/SPELLS/skltree_n_back.DC6" - SkillsPanelPaladin = "/data/global/ui/SPELLS/skltree_p_back.DC6" - SkillsPanelSorcerer = "/data/global/ui/SPELLS/skltree_s_back.DC6" + Frame = "/data/global/ui/PANEL/800borderframe.dc6" + InventoryCharacterPanel = "/data/global/ui/PANEL/invchar6.DC6" + HeroStatsPanelStatsPoints = "/data/global/ui/PANEL/skillpoints.dc6" + HeroStatsPanelSocket = "/data/global/ui/PANEL/levelsocket.dc6" + InventoryWeaponsTab = "/data/global/ui/PANEL/invchar6Tab.DC6" + SkillsPanelAmazon = "/data/global/ui/SPELLS/skltree_a_back.DC6" + SkillsPanelBarbarian = "/data/global/ui/SPELLS/skltree_b_back.DC6" + SkillsPanelDruid = "/data/global/ui/SPELLS/skltree_d_back.DC6" + SkillsPanelAssassin = "/data/global/ui/SPELLS/skltree_i_back.DC6" + SkillsPanelNecromancer = "/data/global/ui/SPELLS/skltree_n_back.DC6" + SkillsPanelPaladin = "/data/global/ui/SPELLS/skltree_p_back.DC6" + SkillsPanelSorcerer = "/data/global/ui/SPELLS/skltree_s_back.DC6" GenericSkills = "/data/global/ui/SPELLS/Skillicon.DC6" AmazonSkills = "/data/global/ui/SPELLS/AmSkillicon.DC6" diff --git a/d2core/d2ui/button.go b/d2core/d2ui/button.go index 03b46c8a..b558969a 100644 --- a/d2core/d2ui/button.go +++ b/d2core/d2ui/button.go @@ -200,6 +200,10 @@ const ( buttonGoldCoinSegmentsY = 1 buttonGoldCoinDisabledFrame = -1 + buttonAddSkillSegmentsX = 1 + buttonAddSkillSegmentsY = 1 + buttonAddSkillDisabledFrame = 2 + pressedButtonOffset = 2 ) @@ -748,9 +752,9 @@ func getButtonLayouts() map[ButtonType]ButtonLayout { LabelColor: whiteAlpha100, }, ButtonTypeAddSkill: { - XSegments: 1, - YSegments: 1, - DisabledFrame: 2, + XSegments: buttonAddSkillSegmentsX, + YSegments: buttonAddSkillSegmentsY, + DisabledFrame: buttonAddSkillDisabledFrame, DisabledColor: whiteAlpha100, ResourceName: d2resource.AddSkillButton, PaletteName: d2resource.PaletteSky, diff --git a/d2game/d2player/game_controls.go b/d2game/d2player/game_controls.go index 98fc3d83..f9556fb7 100644 --- a/d2game/d2player/game_controls.go +++ b/d2game/d2player/game_controls.go @@ -715,7 +715,7 @@ func (g *GameControls) Load() { g.HelpOverlay.Load() g.loadAddButtons() - g.SetAddButtons() + g.setAddButtons() miniPanelActions := &miniPanelActions{ characterToggle: g.toggleHeroStatsPanel, @@ -737,6 +737,10 @@ func (g *GameControls) Advance(elapsed float64) error { return err } + if g.heroStatsPanel.IsOpen() || g.skilltree.IsOpen() { + g.setAddButtons() + } + return nil } @@ -1104,7 +1108,7 @@ func (g *GameControls) bindTerminalCommands(term d2interface.Terminal) error { return nil } -func (g *GameControls) SetAddButtons() { +func (g *GameControls) setAddButtons() { g.hud.addStatsButton.SetEnabled(g.hero.Stats.StatsPoints > 0) g.hud.addSkillButton.SetEnabled(g.hero.Stats.SkillPoints > 0) } diff --git a/d2game/d2player/hero_stats_panel.go b/d2game/d2player/hero_stats_panel.go index 9f9cb5c0..8bc889aa 100644 --- a/d2game/d2player/hero_stats_panel.go +++ b/d2game/d2player/hero_stats_panel.go @@ -9,6 +9,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" ) @@ -55,6 +56,15 @@ const ( const ( heroStatsCloseButtonX, heroStatsCloseButtonY = 208, 453 + addStatSocketOffsetX, addStatSocketOffsetY = -3, 34 +) + +const ( + newStatsRemainingPointsFieldX, newStatsRemainingPointsFieldY = 83, 430 + newStatsRemainingPointsLabelX = 92 + newStatsRemainingPointsLabel1Y = 411 + newStatsRemainingPointsLabel2Y = 418 + newStatsRemainingPointsValueX, newStatsRemainingPointsValueY = 188, 411 ) // PanelText represents text on the panel @@ -113,15 +123,17 @@ func NewHeroStatsPanel(asset *d2asset.AssetManager, // HeroStatsPanel represents the hero status panel type HeroStatsPanel struct { - asset *d2asset.AssetManager - uiManager *d2ui.UIManager - panel *d2ui.Sprite - heroState *d2hero.HeroStatsState - heroName string - heroClass d2enum.Hero - labels *StatsPanelLabels - onCloseCb func() - panelGroup *d2ui.WidgetGroup + asset *d2asset.AssetManager + uiManager *d2ui.UIManager + panel *d2ui.Sprite + heroState *d2hero.HeroStatsState + heroName string + heroClass d2enum.Hero + labels *StatsPanelLabels + onCloseCb func() + panelGroup *d2ui.WidgetGroup + newStatPoints *d2ui.WidgetGroup + remainingPoints *d2ui.Label originX int originY int @@ -135,6 +147,7 @@ func (s *HeroStatsPanel) Load() { var err error s.panelGroup = s.uiManager.NewWidgetGroup(d2ui.RenderPriorityHeroStatsPanel) + s.newStatPoints = s.uiManager.NewWidgetGroup(d2ui.RenderPriorityHeroStatsPanel) frame := d2ui.NewUIFrame(s.asset, s.uiManager, d2ui.FrameLeft) s.panelGroup.AddWidget(frame) @@ -154,10 +167,91 @@ func (s *HeroStatsPanel) Load() { closeButton.OnActivated(func() { s.Close() }) s.panelGroup.AddWidget(closeButton) + s.loadNewStatPoints() + s.setLayout() + s.initStatValueLabels() s.panelGroup.SetVisible(false) } +func (s *HeroStatsPanel) loadNewStatPoints() { + field, err := s.uiManager.NewSprite(d2resource.HeroStatsPanelStatsPoints, d2resource.PaletteSky) + if err != nil { + s.Error(err.Error()) + } + + field.SetPosition(newStatsRemainingPointsFieldX, newStatsRemainingPointsFieldY) + s.newStatPoints.AddWidget(field) + + label1 := s.uiManager.NewLabel(d2resource.Font6, d2resource.PaletteSky) + label1.SetPosition(newStatsRemainingPointsLabelX, newStatsRemainingPointsLabel1Y) + label1.SetText(s.asset.TranslateString("strchrstat")) + label1.Color[0] = d2util.Color(d2gui.ColorRed) + s.newStatPoints.AddWidget(label1) + + label2 := s.uiManager.NewLabel(d2resource.Font6, d2resource.PaletteSky) + label2.SetPosition(newStatsRemainingPointsLabelX, newStatsRemainingPointsLabel2Y) + label2.SetText(s.asset.TranslateString("strchrrema")) + label2.Color[0] = d2util.Color(d2gui.ColorRed) + s.newStatPoints.AddWidget(label2) + + s.remainingPoints = s.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteSky) + s.remainingPoints.SetText(strconv.Itoa(s.heroState.StatsPoints)) + s.remainingPoints.SetPosition(newStatsRemainingPointsValueX, newStatsRemainingPointsValueY) + s.remainingPoints.Alignment = d2ui.HorizontalAlignCenter + s.newStatPoints.AddWidget(s.remainingPoints) + + buttons := []struct { + x int + y int + cb func() + }{ + {205, 140, func() { + s.heroState.Strength++ + }}, + {205, 201, func() { + s.heroState.Dexterity++ + }}, + {205, 286, func() { + s.heroState.Vitality++ + }}, + {205, 347, func() { + s.heroState.Energy++ + }}, + } + + var socket *d2ui.Sprite + + var button *d2ui.Button + + for _, i := range buttons { + currentValue := i + + socket, err = s.uiManager.NewSprite(d2resource.HeroStatsPanelSocket, d2resource.PaletteSky) + if err != nil { + s.Error(err.Error()) + } + + socket.SetPosition(i.x+addStatSocketOffsetX, i.y+addStatSocketOffsetY) + s.newStatPoints.AddWidget(socket) + + button = s.uiManager.NewButton(d2ui.ButtonTypeAddSkill, d2resource.PaletteSky) + button.SetPosition(i.x, i.y) + button.OnActivated(func() { + currentValue.cb() + s.heroState.StatsPoints-- + s.remainingPoints.SetText(strconv.Itoa(s.heroState.StatsPoints)) + s.setStatValues() + s.setLayout() + }) + s.newStatPoints.AddWidget(button) + } +} + +func (s *HeroStatsPanel) setLayout() { + s.newStatPoints.SetVisible(s.heroState.StatsPoints > 0 && s.IsOpen()) +} + // IsOpen returns true if the hero status panel is open func (s *HeroStatsPanel) IsOpen() bool { return s.isOpen @@ -176,12 +270,14 @@ func (s *HeroStatsPanel) Toggle() { func (s *HeroStatsPanel) Open() { s.isOpen = true s.panelGroup.SetVisible(true) + s.setLayout() } // Close closed the hero status panel func (s *HeroStatsPanel) Close() { s.isOpen = false s.panelGroup.SetVisible(false) + s.setLayout() s.onCloseCb() } From cf439ede2fc6cb949c2479ae2028d5743d76c62f Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Tue, 15 Dec 2020 20:03:24 +0100 Subject: [PATCH 6/7] skill tre - remaining points label --- d2game/d2player/game_controls.go | 2 +- d2game/d2player/skilltree.go | 51 +++++++++++++++++++++----------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/d2game/d2player/game_controls.go b/d2game/d2player/game_controls.go index f9556fb7..97bd2aa7 100644 --- a/d2game/d2player/game_controls.go +++ b/d2game/d2player/game_controls.go @@ -214,7 +214,7 @@ func NewGameControls( return nil, err } - skilltree := newSkillTree(hero.Skills, hero.Class, asset, l, ui) + skilltree := newSkillTree(hero.Skills, hero.Class, hero.Stats, asset, l, ui) miniPanel := newMiniPanel(asset, ui, l, isSinglePlayer) diff --git a/d2game/d2player/skilltree.go b/d2game/d2player/skilltree.go index 3f5ddae0..91bceec4 100644 --- a/d2game/d2player/skilltree.go +++ b/d2game/d2player/skilltree.go @@ -3,6 +3,7 @@ package d2player import ( "errors" "fmt" + "strconv" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" @@ -56,6 +57,10 @@ const ( frameSelectedTab3Full = 13 ) +const ( + remainingPointsLabelX, remainingPointsLabelY = 677, 128 +) + const ( skillTreePanelX = 401 skillTreePanelY = 64 @@ -87,6 +92,7 @@ type skillTreeHeroTypeResources struct { func newSkillTree( skills map[int]*d2hero.HeroSkill, heroClass d2enum.Hero, + hero *d2hero.HeroStatsState, asset *d2asset.AssetManager, l d2util.LogLevel, ui *d2ui.UIManager, @@ -98,6 +104,7 @@ func newSkillTree( uiManager: ui, originX: skillTreePanelX, originY: skillTreePanelY, + stats: hero, tab: [numTabs]*skillTreeTab{ {}, {}, @@ -114,24 +121,26 @@ func newSkillTree( } type skillTree struct { - resources *skillTreeHeroTypeResources - asset *d2asset.AssetManager - uiManager *d2ui.UIManager - skills map[int]*d2hero.HeroSkill - skillIcons []*skillIcon - heroClass d2enum.Hero - frame *d2ui.UIFrame - availSPLabel *d2ui.Label - closeButton *d2ui.Button - tab [numTabs]*skillTreeTab - isOpen bool - originX int - originY int - selectedTab int - onCloseCb func() - panelGroup *d2ui.WidgetGroup - iconGroup *d2ui.WidgetGroup - panel *d2ui.CustomWidget + resources *skillTreeHeroTypeResources + asset *d2asset.AssetManager + uiManager *d2ui.UIManager + skills map[int]*d2hero.HeroSkill + skillIcons []*skillIcon + heroClass d2enum.Hero + frame *d2ui.UIFrame + availSPLabel *d2ui.Label + closeButton *d2ui.Button + tab [numTabs]*skillTreeTab + remainingPoints *d2ui.Label + isOpen bool + originX int + originY int + selectedTab int + onCloseCb func() + panelGroup *d2ui.WidgetGroup + iconGroup *d2ui.WidgetGroup + panel *d2ui.CustomWidget + stats *d2hero.HeroStatsState *d2util.Logger l d2util.LogLevel @@ -152,6 +161,12 @@ func (s *skillTree) load() { s.closeButton.OnActivated(func() { s.Close() }) s.panelGroup.AddWidget(s.closeButton) + s.remainingPoints = s.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteSky) + s.remainingPoints.SetPosition(remainingPointsLabelX, remainingPointsLabelY) + s.remainingPoints.Alignment = d2ui.HorizontalAlignCenter + s.remainingPoints.SetText(strconv.Itoa(s.stats.SkillPoints)) + s.panelGroup.AddWidget(s.remainingPoints) + if err := s.setHeroTypeResourcePath(); err != nil { s.Error(err.Error()) } From 6c2e078b5ed04050fa39541a38f7e507da0a486f Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Wed, 16 Dec 2020 16:55:50 +0100 Subject: [PATCH 7/7] revert:hero save file (app.go) --- d2app/app.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/d2app/app.go b/d2app/app.go index 272af28c..f4ae128c 100644 --- a/d2app/app.go +++ b/d2app/app.go @@ -233,12 +233,11 @@ func (a *App) parseArguments() { loggingShort = 'l' loggingDesc = "Enables verbose logging. Log levels will include those below it. " + "0 disables log messages, " + - "1 shows fatal errors, " + - "2 shows errors, " + - "3 shows warnings, " + - "4 shows info, " + - "5 shows debug" + - "6 uses value from config file (default)" + "1 shows errors, " + + "2 shows warnings, " + + "3 shows info, " + + "4 shows debug" + + "5 uses value from config file (default)" ) a.Options.profiler = kingpin.Flag(profilerArg, profilerDesc).String() @@ -316,7 +315,7 @@ func (a *App) Run() error { a.gitCommit = "build" } - a.Errorf(fmtVersion, a.gitBranch, a.gitCommit) + fmt.Printf(fmtVersion, a.gitBranch, a.gitCommit) os.Exit(0) } @@ -740,7 +739,7 @@ func (a *App) doCaptureFrame(target d2interface.Surface) error { return err } - a.Infof("saved frame to %s", a.capturePath) + a.Info(fmt.Sprintf("saved frame to %s", a.capturePath)) return nil } @@ -800,7 +799,7 @@ func (a *App) convertFramesToGif() error { return err } - a.Infof("saved animation to %s", a.capturePath) + a.Info(fmt.Sprintf("saved animation to %s", a.capturePath)) return nil } @@ -938,7 +937,7 @@ func (a *App) ToCreateGame(filePath string, connType d2clientconnectiontype.Clie if err = gameClient.Open(host, filePath); err != nil { errorMessage := fmt.Sprintf("can not connect to the host: %s", host) - a.Error(errorMessage) + fmt.Println(errorMessage) a.ToMainMenu(errorMessage) } else { game, err := d2gamescreen.CreateGame( @@ -957,7 +956,7 @@ func (a *App) ToCharacterSelect(connType d2clientconnectiontype.ClientConnection characterSelect, err := d2gamescreen.CreateCharacterSelect(a, a.asset, a.renderer, a.inputManager, a.audio, a.ui, connType, a.config.LogLevel, connHost) if err != nil { - a.Errorf("unable to create character select screen: %s", err) + fmt.Printf("unable to create character select screen: %s", err) } a.screen.SetNextScreen(characterSelect)