Fixing bug with switching between split and play views

Change-Id: Ib547eff57b0815f32ee0b83f09434a13410be3fc
diff --git a/go/src/hearts/assets/Restart.png b/go/src/hearts/assets/Restart.png
new file mode 100644
index 0000000..b934780
--- /dev/null
+++ b/go/src/hearts/assets/Restart.png
Binary files differ
diff --git a/go/src/hearts/assets/Visibility.png b/go/src/hearts/assets/Visibility.png
new file mode 100644
index 0000000..786e55e
--- /dev/null
+++ b/go/src/hearts/assets/Visibility.png
Binary files differ
diff --git a/go/src/hearts/assets/VisibilityOff.png b/go/src/hearts/assets/VisibilityOff.png
new file mode 100644
index 0000000..d72ae18
--- /dev/null
+++ b/go/src/hearts/assets/VisibilityOff.png
Binary files differ
diff --git a/go/src/hearts/img/reposition/reposition.go b/go/src/hearts/img/reposition/reposition.go
index cd72e9c..f037498 100644
--- a/go/src/hearts/img/reposition/reposition.go
+++ b/go/src/hearts/img/reposition/reposition.go
@@ -277,8 +277,7 @@
 	SwitchOnChan(ch, quit, func() {}, u)
 }
 
-func AnimateInSplit(u *uistate.UIState) {
-	ResetAnims(u)
+func AnimateInSplit(ch chan bool, u *uistate.UIState) {
 	topOfBanner := u.WindowSize.Y - 4*u.CardDim.Y - 5*u.Padding - u.BottomPadding - 40
 	tableImgs := make([]*staticimg.StaticImg, 0)
 	bannerImgs := make([]*staticimg.StaticImg, 0)
@@ -315,7 +314,7 @@
 			oldDim := img.GetDimensions()
 			newDim := coords.MakeVec(oldDim.X, oldDim.Y-10)
 			newTo := coords.MakeVec(to.X, to.Y+10)
-			AnimateImageNoChannel(img, newTo, newDim, u)
+			animateImageMovement(ch, img, newTo, newDim, u)
 		} else {
 			AnimateImageNoChannel(img, to, img.GetDimensions(), u)
 		}
@@ -323,7 +322,6 @@
 }
 
 func AnimateOutSplit(ch chan bool, u *uistate.UIState) {
-	ResetAnims(u)
 	topOfBanner := u.WindowSize.Y - 4*u.CardDim.Y - 5*u.Padding - u.BottomPadding - 40
 	tableImgs := make([]*staticimg.StaticImg, 0)
 	bannerImgs := make([]*staticimg.StaticImg, 0)
@@ -577,5 +575,6 @@
 	for _, ch := range u.AnimChans {
 		ch <- true
 	}
+	u.SwitchingViews = false
 	u.AnimChans = make([]chan bool, 0)
 }
diff --git a/go/src/hearts/img/texture/texture.go b/go/src/hearts/img/texture/texture.go
index 12d65cd..2bec090 100644
--- a/go/src/hearts/img/texture/texture.go
+++ b/go/src/hearts/img/texture/texture.go
@@ -272,7 +272,7 @@
 		"U-Lower-Gray.png", "V-Lower-Gray.png", "W-Lower-Gray.png", "X-Lower-Gray.png", "Y-Lower-Gray.png", "Z-Lower-Gray.png",
 		"Space-Gray.png", "RoundedRectangle-DBlue.png", "RoundedRectangle-LBlue.png", "RoundedRectangle-Gray.png", "Rectangle-LBlue.png",
 		"Rectangle-DBlue.png", "HorizontalPullTab.png", "VerticalPullTab.png", "NewGame.png", "NewRound.png", "JoinGame.png", "Period.png",
-		"SitSpot.png", "WatchSpot.png", "StartBlue.png", "StartGray.png",
+		"SitSpot.png", "WatchSpot.png", "StartBlue.png", "StartGray.png", "Restart.png", "Visibility.png", "VisibilityOff.png",
 	}
 	for _, f := range boundedImgs {
 		a, err := asset.Open(f)
diff --git a/go/src/hearts/img/uistate/uistate.go b/go/src/hearts/img/uistate/uistate.go
index 392a00f..9cfae3d 100644
--- a/go/src/hearts/img/uistate/uistate.go
+++ b/go/src/hearts/img/uistate/uistate.go
@@ -93,6 +93,7 @@
 	Service          syncbase.Service
 	Debug            bool                           // true if debugging, adds extra functionality to switch between players
 	SequentialPhases bool                           // true if trying to match Croupier Flutter Pass -> Take -> Play phase system
+	SwitchingViews   bool                           // true if currently animating between play and split views
 	Shutdown         func()                         // used to shut down a v23.Init()
 	GameID           int                            // used to differentiate between concurrent games
 	IsOwner          bool                           // true if this player is the game creator
@@ -131,6 +132,7 @@
 		Done:             false,
 		Debug:            false,
 		SequentialPhases: true,
+		SwitchingViews:   false,
 		UserData:         make(map[int]map[string]interface{}),
 		PlayerData:       make(map[int]int),
 		AnimChans:        make([]chan bool, 0),
diff --git a/go/src/hearts/img/view/view.go b/go/src/hearts/img/view/view.go
index a325a4c..99f9cba 100644
--- a/go/src/hearts/img/view/view.go
+++ b/go/src/hearts/img/view/view.go
@@ -425,7 +425,15 @@
 	}
 	reposition.SetSplitDropColors(u)
 	if !reloading {
-		reposition.AnimateInSplit(u)
+		ch := make(chan bool)
+		quit := make(chan bool)
+		u.AnimChans = append(u.AnimChans, quit)
+		u.SwitchingViews = true
+		reposition.AnimateInSplit(ch, u)
+		go func() {
+			onDone := func() { u.SwitchingViews = false }
+			reposition.SwitchOnChan(ch, quit, onDone, u)
+		}()
 	}
 }
 
@@ -617,11 +625,12 @@
 	u.Other = append(u.Other,
 		texture.MakeImgWithoutAlt(headerImage, headerPos, headerDimensions, u))
 	// adding pull tab
-	pullTabImage := u.Texs["HorizontalPullTab.png"]
+	pullTabImage := u.Texs["Visibility.png"]
+	pullTabAlt := u.Texs["VisibilityOff.png"]
 	pullTabDim := u.CardDim.DividedBy(2)
 	pullTabPos := headerPos.PlusVec(headerDimensions).MinusVec(pullTabDim).Minus(u.Padding)
 	u.Buttons = append(u.Buttons,
-		texture.MakeImgWithoutAlt(pullTabImage, pullTabPos, pullTabDim, u))
+		texture.MakeImgWithAlt(pullTabImage, pullTabAlt, pullTabPos, pullTabDim, !beforeSplitAnimation, u))
 	// adding text
 	color := "DBlue"
 	scaler := float32(4)
diff --git a/go/src/hearts/sync/watch.go b/go/src/hearts/sync/watch.go
index 9cc2e87..0184ec4 100644
--- a/go/src/hearts/sync/watch.go
+++ b/go/src/hearts/sync/watch.go
@@ -101,33 +101,7 @@
 				if err := c.Value(&value); err != nil {
 					fmt.Println("Value error:", err)
 				}
-				valueStr := string(value)
-				fmt.Println(key, valueStr)
-				keyType := strings.Split(key, "/")[1]
-				switch keyType {
-				case "log":
-					updateType := strings.Split(valueStr, "|")[0]
-					switch updateType {
-					case Deal:
-						onDeal(valueStr, u)
-					case Pass:
-						onPass(valueStr, u)
-					case Take:
-						onTake(valueStr, u)
-					case Play:
-						onPlay(valueStr, u)
-					case Ready:
-						onReady(valueStr, u)
-					}
-				case "players":
-					switch strings.Split(key, "/")[3] {
-					case "player_number":
-						onPlayerNum(key, valueStr, u)
-					case "settings_sg":
-						onSettings(key, valueStr, u)
-					}
-
-				}
+				handleGameUpdate(key, value, u)
 			} else {
 				fmt.Println("Unexpected ChangeType: ", c.ChangeType)
 			}
@@ -135,6 +109,36 @@
 	}
 }
 
+func handleGameUpdate(key string, value []byte, u *uistate.UIState) {
+	valueStr := string(value)
+	fmt.Println(key, valueStr)
+	keyType := strings.Split(key, "/")[1]
+	switch keyType {
+	case "log":
+		updateType := strings.Split(valueStr, "|")[0]
+		switch updateType {
+		case Deal:
+			go onDeal(valueStr, u)
+		case Pass:
+			go onPass(valueStr, u)
+		case Take:
+			go onTake(valueStr, u)
+		case Play:
+			go onPlay(valueStr, u)
+		case Ready:
+			go onReady(valueStr, u)
+		}
+	case "players":
+		switch strings.Split(key, "/")[3] {
+		case "player_number":
+			onPlayerNum(key, valueStr, u)
+		case "settings_sg":
+			onSettings(key, valueStr, u)
+		}
+
+	}
+}
+
 func onPlayerNum(key, value string, u *uistate.UIState) {
 	userID, _ := strconv.Atoi(strings.Split(key, "/")[2])
 	playerNum, _ := strconv.Atoi(value)
diff --git a/go/src/hearts/touchhandler/touchhandler.go b/go/src/hearts/touchhandler/touchhandler.go
index 9283e23..12dce44 100644
--- a/go/src/hearts/touchhandler/touchhandler.go
+++ b/go/src/hearts/touchhandler/touchhandler.go
@@ -375,14 +375,14 @@
 	buttonList := findClickedButton(t, u)
 	if len(buttonList) > 0 {
 		if u.Debug {
-			if u.Buttons[0] == buttonList[0] {
+			if u.Buttons[0] == buttonList[0] && !u.SwitchingViews {
 				view.LoadSplitView(false, u)
 			} else if u.Buttons[1] == buttonList[0] {
 				view.LoadTableView(u)
 			} else if u.Buttons[2] == buttonList[0] {
 				view.LoadPassOrTakeOrPlay(u)
 			}
-		} else {
+		} else if !u.SwitchingViews {
 			view.LoadSplitView(false, u)
 		}
 	}
@@ -425,13 +425,17 @@
 	buttonList := findClickedButton(t, u)
 	if len(buttonList) > 0 {
 		if u.Debug {
-			if u.Buttons[0] == buttonList[0] {
+			if u.Buttons[0] == buttonList[0] && !u.SwitchingViews {
 				ch := make(chan bool)
+				u.SwitchingViews = true
 				reposition.AnimateOutSplit(ch, u)
 				quit := make(chan bool)
 				u.AnimChans = append(u.AnimChans, quit)
 				go func() {
-					onDone := func() { view.LoadPlayView(u) }
+					onDone := func() {
+						u.SwitchingViews = false
+						view.LoadPlayView(u)
+					}
 					reposition.SwitchOnChan(ch, quit, onDone, u)
 				}()
 			} else if u.Buttons[1] == buttonList[0] {
@@ -439,13 +443,17 @@
 			} else if u.Buttons[2] == buttonList[0] {
 				view.LoadPassOrTakeOrPlay(u)
 			}
-		} else {
+		} else if !u.SwitchingViews {
 			ch := make(chan bool)
+			u.SwitchingViews = true
 			reposition.AnimateOutSplit(ch, u)
 			quit := make(chan bool)
 			u.AnimChans = append(u.AnimChans, quit)
 			go func() {
-				onDone := func() { view.LoadPlayView(u) }
+				onDone := func() {
+					u.SwitchingViews = false
+					view.LoadPlayView(u)
+				}
 				reposition.SwitchOnChan(ch, quit, onDone, u)
 			}()
 		}