Cleaned up views for phone and tablet
Change-Id: I2d82691396e5cecf9706304c426b05a2cb545289
diff --git a/go/src/hearts/AndroidManifest.xml b/go/src/hearts/AndroidManifest.xml
index 1e434ff..dab00e2 100644
--- a/go/src/hearts/AndroidManifest.xml
+++ b/go/src/hearts/AndroidManifest.xml
@@ -6,7 +6,7 @@
-->
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
- package="io.v.go.examples.aaavolley"
+ package="io.v.go.examples.Croupier"
android:versionCode="1"
android:versionName="1.0">
@@ -19,10 +19,10 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
- <application android:label="aaavolley" android:debuggable="true">
+ <application android:label="Croupier" android:debuggable="true">
<activity android:name="org.golang.app.GoNativeActivity"
- android:label="aaavolley"
+ android:label="Croupier"
android:configChanges="orientation|keyboardHidden">
<meta-data android:name="android.app.lib_name" android:value="network" />
<intent-filter>
diff --git a/go/src/hearts/assets/NewGame.png b/go/src/hearts/assets/NewGame.png
new file mode 100644
index 0000000..f809373
--- /dev/null
+++ b/go/src/hearts/assets/NewGame.png
Binary files differ
diff --git a/go/src/hearts/assets/NewRound.png b/go/src/hearts/assets/NewRound.png
new file mode 100644
index 0000000..acdeebc
--- /dev/null
+++ b/go/src/hearts/assets/NewRound.png
Binary files differ
diff --git a/go/src/hearts/img/reposition/reposition.go b/go/src/hearts/img/reposition/reposition.go
index e7ae256..790b2b0 100644
--- a/go/src/hearts/img/reposition/reposition.go
+++ b/go/src/hearts/img/reposition/reposition.go
@@ -21,7 +21,7 @@
const (
// animationFrameCount is the number of frames it will take to complete any animation
- animationFrameCount = 100
+ animationFrameCount = 60
// animRotationScaler is the speed at which an image rotates, if rotation is involved in an animation
animRotationScaler = .15
)
@@ -58,6 +58,19 @@
}
}
+func SetTableDropColors(u *uistate.UIState) {
+ blueTargetIndex := u.CurTable.WhoseTurn()
+ for i, d := range u.DropTargets {
+ if i == blueTargetIndex {
+ u.Eng.SetSubTex(d.GetNode(), d.GetAlt())
+ d.SetDisplayingImage(false)
+ } else {
+ u.Eng.SetSubTex(d.GetNode(), d.GetImage())
+ d.SetDisplayingImage(true)
+ }
+ }
+}
+
// Drags card curCard along with the mouse
func DragCard(t touch.Event, u *uistate.UIState) {
tVec := coords.MakeVec(t.X, t.Y)
@@ -79,44 +92,56 @@
}
// Animation for the 'pass' action, when app is in the table view
-func AnimateTableCardPass(animCard *card.Card, toPlayer, cardNum int, u *uistate.UIState) {
- cardDim := animCard.GetDimensions()
- dropTargetXY := u.DropTargets[toPlayer].GetCurrent()
- dropTargetDim := u.DropTargets[toPlayer].GetDimensions()
- targetCenter := dropTargetXY.PlusVec(dropTargetDim.DividedBy(2))
- distFromTargetX := u.WindowSize.X / 4
- distFromTargetY := u.WindowSize.Y / 5
- blockEdge := targetCenter.MinusVec(cardDim.Times(3).Plus(2 * u.Padding))
- var destination *coords.Vec
- switch toPlayer {
- case 0:
- destination = coords.MakeVec(
- blockEdge.X+float32(cardNum)*(u.Padding+cardDim.X),
- targetCenter.Y+distFromTargetY-cardDim.Y/2)
- case 1:
- destination = coords.MakeVec(
- targetCenter.X-distFromTargetX-cardDim.X/2,
- blockEdge.Y+float32(cardNum)*(u.Padding+cardDim.Y))
- case 2:
- destination = coords.MakeVec(
- blockEdge.X+float32(cardNum)*(u.Padding+cardDim.X),
- targetCenter.Y-distFromTargetY-cardDim.Y/2)
- case 3:
- destination = coords.MakeVec(
- targetCenter.X+distFromTargetX-cardDim.X/2,
- blockEdge.Y+float32(cardNum)*(u.Padding+cardDim.Y))
+func AnimateTableCardPass(cards []*card.Card, toPlayer int, u *uistate.UIState) {
+ for cardNum, animCard := range cards {
+ cardDim := animCard.GetDimensions()
+ dropTargetXY := u.DropTargets[toPlayer].GetCurrent()
+ dropTargetDim := u.DropTargets[toPlayer].GetDimensions()
+ targetCenter := dropTargetXY.PlusVec(dropTargetDim.DividedBy(2))
+ xPlayerBlockSize := 2*u.PlayerIconDim.X + u.Padding
+ yPlayerBlockSize := u.TopPadding + 2*u.TableCardDim.Y + 3*u.Padding + u.PlayerIconDim.Y
+ blockEdge := targetCenter.MinusVec(cardDim.Times(1.5).Plus(u.Padding))
+ var destination *coords.Vec
+ switch toPlayer {
+ case 0:
+ destination = coords.MakeVec(
+ blockEdge.X+float32(cardNum)*(u.Padding+cardDim.X),
+ u.WindowSize.Y-yPlayerBlockSize-u.TableCardDim.Y)
+ case 1:
+ destination = coords.MakeVec(
+ xPlayerBlockSize,
+ blockEdge.Y+float32(cardNum)*(u.Padding+cardDim.Y))
+ case 2:
+ destination = coords.MakeVec(
+ blockEdge.X+float32(cardNum)*(u.Padding+cardDim.X),
+ yPlayerBlockSize)
+ case 3:
+ destination = coords.MakeVec(
+ u.WindowSize.X-xPlayerBlockSize-u.TableCardDim.X,
+ blockEdge.Y+float32(cardNum)*(u.Padding+cardDim.Y))
+ }
+ if cardNum < len(cards)-1 {
+ animateCardNoChannel(animCard, destination, cardDim, u)
+ } else {
+ c := make(chan bool)
+ animateCardMovement(c, animCard, destination, cardDim, u)
+ <-c
+ }
}
- c := make(chan bool)
- animateCardMovement(c, animCard, destination, cardDim)
- <-c
}
// Animation for the 'take' action, when app is in the table view
-func AnimateTableCardTake(animCard *card.Card, cardNum int, p *player.Player) {
- destinationPos := p.GetPassedFrom()[cardNum].GetInitial()
- c := make(chan bool)
- animateCardMovement(c, animCard, destinationPos, animCard.GetDimensions())
- <-c
+func AnimateTableCardTake(cards []*card.Card, p *player.Player, u *uistate.UIState) {
+ for cardNum, animCard := range cards {
+ destinationPos := p.GetPassedFrom()[cardNum].GetInitial()
+ if cardNum < len(cards)-1 {
+ animateCardNoChannel(animCard, destinationPos, animCard.GetDimensions(), u)
+ } else {
+ c := make(chan bool)
+ animateCardMovement(c, animCard, destinationPos, animCard.GetDimensions(), u)
+ <-c
+ }
+ }
}
// Animation for the 'play' action, when app is in the table view
@@ -125,7 +150,7 @@
destinationPos := destination.GetCurrent()
destinationDim := destination.GetDimensions()
ch := make(chan bool)
- animateCardMovement(ch, animCard, destinationPos, destinationDim)
+ animateCardMovement(ch, animCard, destinationPos, destinationDim, u)
<-ch
animCard.SetFrontDisplay(u.Eng)
}
@@ -135,15 +160,15 @@
for _, i := range animImages {
dims := i.GetDimensions()
to := coords.MakeVec(i.GetCurrent().X, i.GetCurrent().Y-u.WindowSize.Y)
- AnimateImageNoChannel(i, to, dims)
+ AnimateImageNoChannel(i, to, dims, u)
}
for i, c := range animCards {
dims := c.GetDimensions()
to := coords.MakeVec(c.GetCurrent().X, c.GetCurrent().Y-u.WindowSize.Y)
if i < len(animCards)-1 {
- animateCardNoChannel(c, to, dims)
+ animateCardNoChannel(c, to, dims, u)
} else {
- animateCardMovement(ch, c, to, dims)
+ animateCardMovement(ch, c, to, dims, u)
}
}
}
@@ -153,9 +178,9 @@
for i, image := range animImages {
destination := coords.MakeVec(image.GetCurrent().X, image.GetCurrent().Y-u.WindowSize.Y)
if i < len(animImages)-1 {
- AnimateImageNoChannel(image, destination, image.GetDimensions())
+ AnimateImageNoChannel(image, destination, image.GetDimensions(), u)
} else {
- animateImageMovement(ch, image, destination, image.GetDimensions())
+ animateImageMovement(ch, image, destination, image.GetDimensions(), u)
}
}
}
@@ -168,16 +193,16 @@
dims := i.GetDimensions()
var to *coords.Vec
if passedCards == nil {
- to = coords.MakeVec(i.GetCurrent().X, i.GetCurrent().Y+u.WindowSize.Y/5)
+ to = coords.MakeVec(i.GetCurrent().X, i.GetCurrent().Y+u.WindowSize.Y)
} else {
- to = coords.MakeVec(i.GetCurrent().X, i.GetCurrent().Y+u.WindowSize.Y/2)
+ to = coords.MakeVec(i.GetCurrent().X, i.GetCurrent().Y+u.WindowSize.Y)
}
- AnimateImageNoChannel(i, to, dims)
+ AnimateImageNoChannel(i, to, dims, u)
}
for _, c := range passedCards {
dims := c.GetDimensions()
- to := coords.MakeVec(c.GetCurrent().X, c.GetCurrent().Y+u.WindowSize.Y/2)
- animateCardNoChannel(c, to, dims)
+ to := coords.MakeVec(c.GetCurrent().X, c.GetCurrent().Y+u.WindowSize.Y)
+ animateCardNoChannel(c, to, dims, u)
}
}
@@ -187,10 +212,10 @@
for _, i := range imgs {
dims := i.GetDimensions()
to := coords.MakeVec(i.GetCurrent().X, i.GetCurrent().Y-u.WindowSize.Y)
- AnimateImageNoChannel(i, to, dims)
+ AnimateImageNoChannel(i, to, dims, u)
}
to := coords.MakeVec(animCard.GetCurrent().X, animCard.GetCurrent().Y-u.WindowSize.Y)
- animateCardMovement(ch, animCard, to, animCard.GetDimensions())
+ animateCardMovement(ch, animCard, to, animCard.GetDimensions(), u)
}
// Animation to bring in the play slot when app is in the hand view and it is the player's turn
@@ -198,8 +223,8 @@
imgs := []*staticimg.StaticImg{u.Other[0], u.DropTargets[0]}
for _, i := range imgs {
dims := i.GetDimensions()
- to := coords.MakeVec(i.GetCurrent().X, i.GetCurrent().Y+u.WindowSize.Y/3)
- AnimateImageNoChannel(i, to, dims)
+ to := coords.MakeVec(i.GetCurrent().X, i.GetCurrent().Y+u.WindowSize.Y/3+u.TopPadding)
+ AnimateImageNoChannel(i, to, dims, u)
}
}
@@ -220,14 +245,20 @@
}
// Animation for when a trick is taken, when app is in the table view
-func AnimateTableCardTakeTrick(animCard *card.Card, dir direction.Direction, u *uistate.UIState) {
- destination := determineDestination(animCard, dir, u.WindowSize)
- c := make(chan bool)
- animateCardMovement(c, animCard, destination, animCard.GetDimensions())
- <-c
+func AnimateTableCardTakeTrick(cards []*card.Card, dir direction.Direction, u *uistate.UIState) {
+ for i, animCard := range cards {
+ destination := determineDestination(animCard, dir, u.WindowSize)
+ if i < len(cards)-1 {
+ animateCardNoChannel(animCard, destination, animCard.GetDimensions(), u)
+ } else {
+ c := make(chan bool)
+ animateCardMovement(c, animCard, destination, animCard.GetDimensions(), u)
+ <-c
+ }
+ }
}
-func animateImageMovement(c chan bool, animImage *staticimg.StaticImg, endPos, endDim *coords.Vec) {
+func animateImageMovement(c chan bool, animImage *staticimg.StaticImg, endPos, endDim *coords.Vec, u *uistate.UIState) {
node := animImage.GetNode()
startPos := animImage.GetCurrent()
startDim := animImage.GetDimensions()
@@ -249,7 +280,7 @@
})
}
-func AnimateImageNoChannel(animImage *staticimg.StaticImg, endPos, endDim *coords.Vec) {
+func AnimateImageNoChannel(animImage *staticimg.StaticImg, endPos, endDim *coords.Vec, u *uistate.UIState) {
node := animImage.GetNode()
startPos := animImage.GetCurrent()
startDim := animImage.GetDimensions()
@@ -270,7 +301,7 @@
})
}
-func animateCardMovement(c chan bool, animCard *card.Card, endPos, endDim *coords.Vec) {
+func animateCardMovement(c chan bool, animCard *card.Card, endPos, endDim *coords.Vec, u *uistate.UIState) {
node := animCard.GetNode()
startPos := animCard.GetCurrent()
startDim := animCard.GetDimensions()
@@ -292,7 +323,7 @@
})
}
-func animateCardNoChannel(animCard *card.Card, endPos, endDim *coords.Vec) {
+func animateCardNoChannel(animCard *card.Card, endPos, endDim *coords.Vec, u *uistate.UIState) {
node := animCard.GetNode()
startPos := animCard.GetCurrent()
startDim := animCard.GetDimensions()
diff --git a/go/src/hearts/img/texture/texture.go b/go/src/hearts/img/texture/texture.go
index 78763c0..7c28d2d 100644
--- a/go/src/hearts/img/texture/texture.go
+++ b/go/src/hearts/img/texture/texture.go
@@ -173,16 +173,18 @@
u *uistate.UIState) []*staticimg.StaticImg {
textures := getStringImgs(input, color, u.Texs)
totalWidth := float32(0)
+ newScaler := scaler
for _, img := range textures {
totalWidth += float32(img.R.Max.X) / scaler
}
if totalWidth > maxWidth {
- scaler = totalWidth * scaler / maxWidth
+ newScaler = totalWidth * scaler / maxWidth
totalWidth = maxWidth
}
startX := center.X - totalWidth/2
- start := coords.MakeVec(startX, center.Y)
- return MakeStringImgLeftAlign(input, color, altColor, displayColor, start, scaler, maxWidth, u)
+ startY := center.Y + (float32(textures[0].R.Max.Y)/scaler-float32(textures[0].R.Max.Y)/newScaler)/2
+ start := coords.MakeVec(startX, startY)
+ return MakeStringImgLeftAlign(input, color, altColor, displayColor, start, newScaler, maxWidth, u)
}
// Returns a new StaticImg instance with desired image and dimensions
@@ -274,7 +276,7 @@
"R-Lower-Gray.png", "S-Lower-Gray.png", "T-Lower-Gray.png", "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",
+ "VerticalPullTab.png", "NewGame.png", "NewRound.png",
}
for _, f := range boundedImgs {
a, err := asset.Open(f)
diff --git a/go/src/hearts/img/view/view.go b/go/src/hearts/img/view/view.go
index 0155c51..1d97c8b 100644
--- a/go/src/hearts/img/view/view.go
+++ b/go/src/hearts/img/view/view.go
@@ -48,6 +48,7 @@
maxWidth := 4 * u.TableCardDim.X
// adding four drop targets for trick
dropTargetImage := u.Texs["trickDrop.png"]
+ dropTargetAlt := u.Texs["trickDropBlue.png"]
dropTargetDimensions := u.CardDim
dropTargetX := (u.WindowSize.X - u.CardDim.X) / 2
var dropTargetY float32
@@ -58,7 +59,7 @@
}
dropTargetPos := coords.MakeVec(dropTargetX, dropTargetY)
u.DropTargets = append(u.DropTargets,
- texture.MakeImgWithoutAlt(dropTargetImage, dropTargetPos, dropTargetDimensions, u.Eng, u.Scene))
+ texture.MakeImgWithAlt(dropTargetImage, dropTargetAlt, dropTargetPos, dropTargetDimensions, true, u.Eng, u.Scene))
// card on top of first drop target
dropCard := u.CurTable.GetTrick()[0]
if dropCard != nil {
@@ -75,7 +76,7 @@
}
dropTargetPos = coords.MakeVec(dropTargetX, dropTargetY)
u.DropTargets = append(u.DropTargets,
- texture.MakeImgWithoutAlt(dropTargetImage, dropTargetPos, dropTargetDimensions, u.Eng, u.Scene))
+ texture.MakeImgWithAlt(dropTargetImage, dropTargetAlt, dropTargetPos, dropTargetDimensions, true, u.Eng, u.Scene))
// card on top of second drop target
dropCard = u.CurTable.GetTrick()[1]
if dropCard != nil {
@@ -92,7 +93,7 @@
}
dropTargetPos = coords.MakeVec(dropTargetX, dropTargetY)
u.DropTargets = append(u.DropTargets,
- texture.MakeImgWithoutAlt(dropTargetImage, dropTargetPos, dropTargetDimensions, u.Eng, u.Scene))
+ texture.MakeImgWithAlt(dropTargetImage, dropTargetAlt, dropTargetPos, dropTargetDimensions, true, u.Eng, u.Scene))
// card on top of third drop target
dropCard = u.CurTable.GetTrick()[2]
if dropCard != nil {
@@ -109,7 +110,7 @@
}
dropTargetPos = coords.MakeVec(dropTargetX, dropTargetY)
u.DropTargets = append(u.DropTargets,
- texture.MakeImgWithoutAlt(dropTargetImage, dropTargetPos, dropTargetDimensions, u.Eng, u.Scene))
+ texture.MakeImgWithAlt(dropTargetImage, dropTargetAlt, dropTargetPos, dropTargetDimensions, true, u.Eng, u.Scene))
// card on top of fourth drop target
dropCard = u.CurTable.GetTrick()[3]
if dropCard != nil {
@@ -216,7 +217,7 @@
deviceIconPos = coords.MakeVec(playerIconPos.X-deviceIconDim.X, playerIconPos.Y+u.PlayerIconDim.Y-deviceIconDim.Y)
u.BackgroundImgs = append(u.BackgroundImgs,
texture.MakeImgWithoutAlt(deviceIconImage, deviceIconPos, deviceIconDim, u.Eng, u.Scene))
- // adding cards
+ //adding cards
for _, p := range u.CurTable.GetPlayers() {
hand := p.GetHand()
for i, c := range hand {
@@ -237,7 +238,7 @@
func LoadPassOrTakeOrPlay(u *uistate.UIState) {
p := u.CurTable.GetPlayers()[u.CurPlayerIndex]
if p.GetDoneTaking() || u.CurTable.GetDir() == direction.None {
- LoadPlayView("", u)
+ LoadPlayView(u)
} else if p.GetDonePassing() {
LoadTakeView(u)
} else {
@@ -253,7 +254,12 @@
addHeader(u)
addScoreViewHeaderText(u)
addPlayerScores(roundScores, u)
- addScoreButton(u)
+ if len(winners) > 0 {
+ addScoreButton(true, u)
+ } else {
+ addScoreButton(false, u)
+ }
+
}
// Pass View: Shows player's hand and allows them to pass cards
@@ -287,44 +293,54 @@
}
// Play View: Shows player's hand and allows them to play cards
-func LoadPlayView(err string, u *uistate.UIState) {
+func LoadPlayView(u *uistate.UIState) {
u.CurView = uistate.Play
- if err == "" {
- resetImgs(u)
- resetScene(u)
- addPlaySlot(u)
- addHand(u)
- addPlayHeader(err, u)
- if u.Debug {
- addDebugBar(u)
- }
- // animate in play slot if relevant
- if u.CurTable.WhoseTurn() == u.CurPlayerIndex && u.CurTable.AllDonePassing() {
- reposition.AnimateInPlay(u)
- }
+ resetImgs(u)
+ resetScene(u)
+ addPlaySlot(u)
+ addHand(u)
+ var turnText string
+ playerTurnNum := u.CurTable.WhoseTurn()
+ if playerTurnNum == -1 || !u.CurTable.AllDonePassing() {
+ turnText = "Waiting for other players"
+ } else if playerTurnNum == u.CurPlayerIndex {
+ turnText = "Your turn"
} else {
- // remove text and replace with err
- var emptyTex sprite.SubTex
- for i := u.NumSuits; i < len(u.BackgroundImgs); i++ {
- u.Eng.SetSubTex(u.BackgroundImgs[i].GetNode(), emptyTex)
- }
- u.BackgroundImgs = u.BackgroundImgs[:u.NumSuits]
- u.Eng.SetSubTex(u.Buttons[0].GetNode(), emptyTex)
- u.Buttons = make([]*staticimg.StaticImg, 0)
- addPlayHeader(err, u)
+ name := u.CurTable.GetPlayers()[playerTurnNum].GetName()
+ turnText = name + "'s turn"
}
+ addPlayHeader(turnText, u)
+ if u.Debug {
+ addDebugBar(u)
+ }
+ // animate in play slot if relevant
+ if u.CurTable.WhoseTurn() == u.CurPlayerIndex && u.CurTable.AllDonePassing() {
+ reposition.AnimateInPlay(u)
+ }
+}
+
+func ChangePlayMessage(message string, u *uistate.UIState) {
+ // remove text and replace with message
+ var emptyTex sprite.SubTex
+ for i := u.NumSuits; i < len(u.BackgroundImgs); i++ {
+ u.Eng.SetSubTex(u.BackgroundImgs[i].GetNode(), emptyTex)
+ }
+ u.BackgroundImgs = u.BackgroundImgs[:u.NumSuits]
+ u.Eng.SetSubTex(u.Buttons[0].GetNode(), emptyTex)
+ u.Buttons = make([]*staticimg.StaticImg, 0)
+ addPlayHeader(message, u)
}
func addHeader(u *uistate.UIState) {
// adding blue banner
headerImage := u.Texs["RoundedRectangle-DBlue.png"]
headerPos := coords.MakeVec(0, -10)
- headerDimensions := coords.MakeVec(u.WindowSize.X, float32(20))
+ headerDimensions := coords.MakeVec(u.WindowSize.X, u.TopPadding+float32(20))
u.BackgroundImgs = append(u.BackgroundImgs,
texture.MakeImgWithoutAlt(headerImage, headerPos, headerDimensions, u.Eng, u.Scene))
}
-func addPlayHeader(err string, u *uistate.UIState) {
+func addPlayHeader(message string, u *uistate.UIState) {
// adding blue banner
headerImage := u.Texs["Rectangle-DBlue.png"]
headerPos := coords.MakeVec(0, 0)
@@ -338,38 +354,25 @@
u.Buttons = append(u.Buttons,
texture.MakeImgWithoutAlt(pullTabImage, pullTabPos, pullTabDim, u.Eng, u.Scene))
// adding text
- var turnText string
- if err != "" {
- turnText = err
- } else {
- playerTurnNum := u.CurTable.WhoseTurn()
- if playerTurnNum == -1 || !u.CurTable.AllDonePassing() {
- turnText = "Waiting for other players"
- } else if playerTurnNum == u.CurPlayerIndex {
- turnText = "Your turn"
- } else {
- name := u.CurTable.GetPlayers()[playerTurnNum].GetName()
- turnText = name + "'s turn"
- }
- }
color := "DBlue"
scaler := float32(4)
center := coords.MakeVec(u.WindowSize.X/2, 20)
- maxWidth := u.WindowSize.X - pullTabDim.X/2
+ maxWidth := u.WindowSize.X - pullTabDim.X*2 - u.Padding*4
u.BackgroundImgs = append(u.BackgroundImgs,
- texture.MakeStringImgCenterAlign(turnText, color, color, true, center, scaler, maxWidth, u)...)
+ texture.MakeStringImgCenterAlign(message, color, color, true, center, scaler, maxWidth, u)...)
}
func addPlaySlot(u *uistate.UIState) {
+ topOfHand := u.WindowSize.Y - 5*(u.CardDim.Y+u.Padding) - (2 * u.Padding / 5) - u.BottomPadding
// adding blue rectangle
blueRectImg := u.Texs["RoundedRectangle-LBlue.png"]
- blueRectPos := coords.MakeVec(2*u.BottomPadding, 40-u.WindowSize.Y+4*u.BottomPadding)
- blueRectDim := u.WindowSize.Minus(4 * u.BottomPadding)
+ blueRectDim := coords.MakeVec(u.WindowSize.X-4*u.BottomPadding, topOfHand+u.CardDim.Y)
+ blueRectPos := coords.MakeVec(2*u.BottomPadding, -blueRectDim.Y)
u.Other = append(u.Other,
texture.MakeImgWithoutAlt(blueRectImg, blueRectPos, blueRectDim, u.Eng, u.Scene))
// adding drop target
dropTargetImg := u.Texs["trickDrop.png"]
- dropTargetPos := coords.MakeVec(u.WindowSize.X/2-u.CardDim.X/2, -u.Padding)
+ dropTargetPos := coords.MakeVec(u.WindowSize.X/2-u.CardDim.X/2, -u.CardDim.Y-3*u.Padding)
u.DropTargets = append(u.DropTargets,
texture.MakeImgWithoutAlt(dropTargetImg, dropTargetPos, u.CardDim, u.Eng, u.Scene))
}
@@ -378,8 +381,8 @@
// adding gray bar
grayBarImg := u.Texs["RoundedRectangle-Gray.png"]
blueBarImg := u.Texs["RoundedRectangle-LBlue.png"]
- grayBarPos := coords.MakeVec(2*u.BottomPadding, 40-u.WindowSize.Y+4*u.BottomPadding)
grayBarDim := u.WindowSize.Minus(4 * u.BottomPadding)
+ grayBarPos := coords.MakeVec(2*u.BottomPadding, 40-grayBarDim.Y+u.TopPadding)
u.Other = append(u.Other,
texture.MakeImgWithAlt(grayBarImg, blueBarImg, grayBarPos, grayBarDim, true, u.Eng, u.Scene))
// adding name
@@ -395,7 +398,7 @@
name := u.CurTable.GetPlayers()[receivingPlayer].GetName()
color := "Gray"
altColor := "LBlue"
- center := coords.MakeVec(u.WindowSize.X/2, 5)
+ center := coords.MakeVec(u.WindowSize.X/2, u.TopPadding+5)
scaler := float32(3)
maxWidth := u.WindowSize.X
nameImgs := texture.MakeStringImgCenterAlign(name, color, altColor, true, center, scaler, maxWidth, u)
@@ -416,7 +419,7 @@
grayBarHeight = topOfHand + u.CardDim.Y
}
grayBarDim := coords.MakeVec(u.WindowSize.X-4*u.BottomPadding, grayBarHeight)
- grayBarPos := coords.MakeVec(2*u.BottomPadding, -grayBarDim.Y)
+ grayBarPos := coords.MakeVec(2*u.BottomPadding, -u.WindowSize.Y-20)
u.Other = append(u.Other,
texture.MakeImgWithAlt(grayBarImg, grayBarAlt, grayBarPos, grayBarDim, display, u.Eng, u.Scene))
// adding name
@@ -433,15 +436,15 @@
color := "Gray"
nameAltColor := "LBlue"
awaitingAltColor := "None"
- center := coords.MakeVec(u.WindowSize.X/2, 30-grayBarDim.Y)
+ center := coords.MakeVec(u.WindowSize.X/2, 20-u.WindowSize.Y)
scaler := float32(3)
maxWidth := u.WindowSize.X
- nameImgs := texture.MakeStringImgCenterAlign(name, color, nameAltColor, display, center, scaler, maxWidth, u)
- u.Other = append(u.Other, nameImgs...)
- center = coords.MakeVec(center.X, center.Y+40)
+ u.Other = append(u.Other,
+ texture.MakeStringImgCenterAlign(name, color, nameAltColor, display, center, scaler, maxWidth, u)...)
+ center = coords.MakeVec(center.X, center.Y+30)
scaler = float32(5)
- awaitingImgs := texture.MakeStringImgCenterAlign("Awaiting pass", color, awaitingAltColor, display, center, scaler, maxWidth, u)
- u.Other = append(u.Other, awaitingImgs...)
+ u.Other = append(u.Other,
+ texture.MakeStringImgCenterAlign("Awaiting pass", color, awaitingAltColor, display, center, scaler, maxWidth, u)...)
// adding cards to take, if cards have been passed
if !display {
u.Cards = append(u.Cards, passedCards...)
@@ -456,7 +459,7 @@
cardXStart := (u.WindowSize.X - (numCards*u.CardDim.X + (numCards-1)*u.Padding)) / 2
for i, c := range passedCards {
cardX := cardXStart + float32(i)*(u.Padding+u.CardDim.X)
- cardPos := coords.MakeVec(cardX, topOfHand-2*u.CardDim.Y-u.WindowSize.Y/2)
+ cardPos := coords.MakeVec(cardX, topOfHand-u.Padding-u.WindowSize.Y-20)
c.Move(cardPos, u.CardDim, u.Eng)
reposition.RealignSuit(c.GetSuit(), c.GetInitial().Y, u)
// invisible drop target holding card
@@ -587,7 +590,7 @@
func addScoreViewHeaderText(u *uistate.UIState) {
top := u.CardDim.Y
scaler := float32(4)
- maxWidth := u.WindowSize.X / 4
+ maxWidth := u.WindowSize.X / 5
// adding score text
scoreCenter := coords.MakeVec(u.WindowSize.X/4, top)
u.BackgroundImgs = append(u.BackgroundImgs,
@@ -610,7 +613,7 @@
maxRoundScore := maxInt(roundScores)
maxTotalScore := maxInt(totalScores)
top := u.CardDim.Y
- scaler := float32(4)
+ scaler := float32(5)
maxWidth := u.WindowSize.X / 4
rowHeight := u.WindowSize.Y / 6
for i, p := range u.CurTable.GetPlayers() {
@@ -624,7 +627,7 @@
// player icon
playerIconImage := p.GetImage()
playerIconDim := coords.MakeVec(rowHeight/2, rowHeight/2)
- playerIconPos := coords.MakeVec(u.WindowSize.X/4-playerIconDim.X/2, top+(float32(i)+.5)*rowHeight+2*u.Padding)
+ playerIconPos := coords.MakeVec(u.WindowSize.X/4-playerIconDim.X/2, top+(float32(i)+.5)*rowHeight+rowHeight/7)
u.BackgroundImgs = append(u.BackgroundImgs,
texture.MakeImgWithoutAlt(playerIconImage, playerIconPos, playerIconDim, u.Eng, u.Scene))
// player name
@@ -653,12 +656,23 @@
u.BackgroundImgs = append(u.BackgroundImgs,
texture.MakeStringImgCenterAlign(strconv.Itoa(totalScore), color, color, true, totalCenter, scaler, maxWidth, u)...)
}
+ // final blue divider
+ dividerImage := u.Texs["blue.png"]
+ dividerDim := coords.MakeVec(u.WindowSize.X, u.Padding/2)
+ dividerPos := coords.MakeVec(0, top+(float32(len(u.CurTable.GetPlayers()))+.5)*rowHeight)
+ u.BackgroundImgs = append(u.BackgroundImgs,
+ texture.MakeImgWithoutAlt(dividerImage, dividerPos, dividerDim, u.Eng, u.Scene))
}
-func addScoreButton(u *uistate.UIState) {
- buttonImg := u.Texs["playUnpressed.png"]
- buttonDim := coords.MakeVec(2*u.CardDim.X, u.CardDim.Y)
- buttonPos := coords.MakeVec((u.WindowSize.X-u.CardDim.X)/2, u.WindowSize.Y-u.CardDim.Y-u.BottomPadding)
+func addScoreButton(gameOver bool, u *uistate.UIState) {
+ var buttonImg sprite.SubTex
+ if gameOver {
+ buttonImg = u.Texs["NewGame.png"]
+ } else {
+ buttonImg = u.Texs["NewRound.png"]
+ }
+ buttonDim := coords.MakeVec(2*u.CardDim.X, 3*u.CardDim.Y/4)
+ buttonPos := coords.MakeVec((u.WindowSize.X-buttonDim.X)/2, u.WindowSize.Y-buttonDim.Y-u.BottomPadding)
u.Buttons = append(u.Buttons,
texture.MakeImgWithoutAlt(buttonImg, buttonPos, buttonDim, u.Eng, u.Scene))
}
diff --git a/go/src/hearts/main.go b/go/src/hearts/main.go
index a8da7ff..65066d4 100644
--- a/go/src/hearts/main.go
+++ b/go/src/hearts/main.go
@@ -33,13 +33,17 @@
"golang.org/x/mobile/event/paint"
"golang.org/x/mobile/event/size"
"golang.org/x/mobile/event/touch"
-
+ "golang.org/x/mobile/exp/app/debug"
"golang.org/x/mobile/exp/gl/glutil"
"golang.org/x/mobile/exp/sprite/clock"
"golang.org/x/mobile/exp/sprite/glsprite"
"golang.org/x/mobile/gl"
)
+var (
+ fps *debug.FPS
+)
+
func main() {
app.Main(func(a app.App) {
var glctx gl.Context
@@ -102,6 +106,7 @@
namespace.SetPermissions(u.Ctx, "users/emshack@google.com/croupier", permissions, "")
u.Service.SetPermissions(u.Ctx, permissions, "")
u.Images = glutil.NewImages(glctx)
+ fps = debug.NewFPS(u.Images)
u.Eng = glsprite.Engine(u.Images)
u.Texs = texture.LoadTextures(u.Eng)
u.CurTable = table.InitializeGame(u.NumPlayers, u.Texs)
@@ -113,6 +118,7 @@
func onStop(u *uistate.UIState) {
u.Eng.Release()
+ fps.Release()
u.Images.Release()
u.Done = true
}
@@ -125,6 +131,7 @@
glctx.Clear(gl.COLOR_BUFFER_BIT)
now := clock.Time(time.Since(u.StartTime) * 60 / time.Second)
u.Eng.Render(u.Scene, now, sz)
+ fps.Draw(sz)
}
func makeServerClient(contextChan chan *context.T, serviceChan chan syncbase.Service) {
diff --git a/go/src/hearts/syncbase/watch/watch.go b/go/src/hearts/syncbase/watch/watch.go
index df303ce..7979459 100644
--- a/go/src/hearts/syncbase/watch/watch.go
+++ b/go/src/hearts/syncbase/watch/watch.go
@@ -20,6 +20,7 @@
"hearts/syncbase/gamelog"
"strconv"
"strings"
+ "time"
"v.io/v23/syncbase/nosql"
)
@@ -88,13 +89,12 @@
u.CurTable.GetPlayers()[playerInt].SetDonePassing(true)
// UI
if u.CurView == uistate.Table {
- for i, c := range curCards {
- reposition.AnimateTableCardPass(c, receivingPlayer, i, u)
- }
+ reposition.AnimateTableCardPass(curCards, receivingPlayer, u)
+ reposition.SetTableDropColors(u)
} else if u.CurView == uistate.Take && u.CurPlayerIndex == receivingPlayer {
view.LoadTakeView(u)
} else if u.CurView == uistate.Play && u.CurTable.AllDonePassing() {
- view.LoadPlayView("", u)
+ view.LoadPlayView(u)
}
}
@@ -114,14 +114,13 @@
u.CurTable.SetFirstPlayer(p.GetPlayerIndex())
// UI
if u.CurView == uistate.Play && u.CurPlayerIndex != playerInt {
- view.LoadPlayView("", u)
+ view.LoadPlayView(u)
}
}
// UI
if u.CurView == uistate.Table {
- for i, c := range passed {
- reposition.AnimateTableCardTake(c, i, u.CurTable.GetPlayers()[playerInt])
- }
+ reposition.AnimateTableCardTake(passed, u.CurTable.GetPlayers()[playerInt], u)
+ reposition.SetTableDropColors(u)
}
}
@@ -155,6 +154,7 @@
// UI
if u.CurView == uistate.Table {
reposition.AnimateTableCardPlay(playedCard, playerInt, u)
+ reposition.SetTableDropColors(u)
if trickOver {
var trickDir direction.Direction
switch recipient {
@@ -167,15 +167,24 @@
case 3:
trickDir = direction.Right
}
- for _, c := range trickCards {
- reposition.AnimateTableCardTakeTrick(c, trickDir, u)
- }
+ reposition.AnimateTableCardTakeTrick(trickCards, trickDir, u)
}
} else if u.CurView == uistate.Play {
if roundOver {
view.LoadScoreView(roundScores, winners, u)
+ } else if trickOver {
+ if u.CurPlayerIndex != recipient {
+ message := u.CurTable.GetPlayers()[recipient].GetName() + "'s trick"
+ view.ChangePlayMessage(message, u)
+ <-time.After(1 * time.Second)
+ view.LoadPlayView(u)
+ } else {
+ view.ChangePlayMessage("Your trick", u)
+ <-time.After(1 * time.Second)
+ view.LoadPlayView(u)
+ }
} else if u.CurPlayerIndex != playerInt {
- view.LoadPlayView("", u)
+ view.LoadPlayView(u)
}
}
// logic
diff --git a/go/src/hearts/touchhandler/touchhandler.go b/go/src/hearts/touchhandler/touchhandler.go
index 768b5c6..645e3a0 100644
--- a/go/src/hearts/touchhandler/touchhandler.go
+++ b/go/src/hearts/touchhandler/touchhandler.go
@@ -122,7 +122,7 @@
finalX := blueBanner.GetInitial().X
finalY := pullTab.GetInitial().Y + pullTab.GetDimensions().Y - blueBanner.GetDimensions().Y
finalPos := coords.MakeVec(finalX, finalY)
- reposition.AnimateImageNoChannel(blueBanner, finalPos, blueBanner.GetDimensions())
+ reposition.AnimateImageNoChannel(blueBanner, finalPos, blueBanner.GetDimensions(), u)
}
}
} else if u.Buttons[1] == buttonList[0] {
@@ -246,7 +246,7 @@
if !success {
fmt.Println("Invalid take")
} else {
- view.LoadPlayView("", u)
+ view.LoadPlayView(u)
}
}()
}
@@ -286,13 +286,12 @@
reposition.RealignSuit(u.CurCard.GetSuit(), u.CurCard.GetInitial().Y, u)
} else {
ch := make(chan bool)
- err := playCard(ch, u.CurPlayerIndex, u)
- if err != "" {
- view.LoadPlayView(err, u)
+ if err := playCard(ch, u.CurPlayerIndex, u); err != "" {
+ view.ChangePlayMessage(err, u)
}
go func() {
<-ch
- view.LoadPlayView("", u)
+ view.LoadPlayView(u)
}()
}
}