From 9dcf7cefca8f89e3c1e2eb08daa10e6869176a08 Mon Sep 17 00:00:00 2001 From: leahiel <71794961+leahiel@users.noreply.github.com> Date: Fri, 25 Sep 2020 21:53:56 -0400 Subject: [PATCH] double click char select to load char (#755) * double click char select to load char * removed vestigial code * fixed out of index error --- d2game/d2gamescreen/character_select.go | 26 ++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/d2game/d2gamescreen/character_select.go b/d2game/d2gamescreen/character_select.go index 45cbc3b1..c63db55e 100644 --- a/d2game/d2gamescreen/character_select.go +++ b/d2game/d2gamescreen/character_select.go @@ -44,6 +44,8 @@ type CharacterSelect struct { characterImage [8]*d2mapentity.Player gameStates []*d2hero.HeroState selectedCharacter int + tickTimer float64 + storedTickTimer float64 showDeleteConfirmation bool connectionType d2clientconnectiontype.ClientConnectionType connectionHost string @@ -134,6 +136,10 @@ const ( okBtnX, okBtnY = 625, 537 ) +const ( + doubleClickTime = 1.25 +) + // OnLoad loads the resources for the Character Select screen func (v *CharacterSelect) OnLoad(loading d2screen.LoadingState) { var err error @@ -390,18 +396,35 @@ func (v *CharacterSelect) OnMouseButtonDown(event d2interface.MouseEvent) bool { localMouseX := mx - selectionBoxOffsetX localMouseY := my - selectionBoxOffsetY + // if Mouse is within character selection bounds. if localMouseX > 0 && localMouseX < bw*2 && localMouseY >= 0 && localMouseY < bh*4 { adjustY := localMouseY / bh + // sets current verticle index for selected character in left column. selectedIndex := adjustY * selectionBoxNumColumns + // if selected character in left column should be in right column, add 1. if localMouseX > bw { selectedIndex++ } + // Make sure selection takes the scrollbar into account to make proper selection. if (v.charScrollbar.GetCurrentOffset()*2)+selectedIndex < len(v.gameStates) { - v.selectedCharacter = (v.charScrollbar.GetCurrentOffset() * 2) + selectedIndex + selectedIndex = (v.charScrollbar.GetCurrentOffset() * 2) + selectedIndex + } + + // if the selection box didn't move, check if it was a double click, otherwise set selectedCharacter to + // selectedIndex and move selection box over both. + if v.selectedCharacter == selectedIndex { + // We clicked twice within character selection box within v.doubleClickTime seconds. + if (v.tickTimer - v.storedTickTimer) < doubleClickTime { + v.onOkButtonClicked() + } + } else if selectedIndex < len(v.gameStates) { + v.selectedCharacter = selectedIndex v.moveSelectionBox() } + // Keep track of when we last clicked so we can determine if we double clicked a character. + v.storedTickTimer = v.tickTimer } return true @@ -415,6 +438,7 @@ func (v *CharacterSelect) OnMouseButtonDown(event d2interface.MouseEvent) bool { func (v *CharacterSelect) Advance(tickTime float64) error { for _, hero := range v.characterImage { if hero != nil { + v.tickTimer += tickTime hero.Advance(tickTime) } }