One Card! - Multiplayer Card Game
import Felgo 3.0
import QtQuick 2.2
EntityBase {
id: playerTag
width: 120
height: canvas.height + name.contentHeight + name.anchors.topMargin
property var player: MultiplayerUser{}
property int level: 1
property string activeColor: "#f9c336"
property string inactiveColor: "#28a3c1"
property string facebookImage: ""
property alias canvas: canvas
property alias avatar: avatar
property alias avatarSource: avatar.source
property alias name: name.text
property alias nameColor: name.color
property alias infoButton: infoButton
property bool menu: false
property int highscore
property int rank
property bool friendRequested: player && player.isFriend ? true : false
Rectangle {
id: leaderMarker
width: name.font.pixelSize * 0.75
height: width
radius: width * 0.5
color: name.color
visible: player && player.leader && !menu && name != ""
anchors.top: canvas.bottom
anchors.topMargin: 6
x: (parent.width - name.implicitWidth) * 0.5 - leaderMarker.width - 6
}
Text {
id: name
text: player && player.name ? player.name : ""
anchors.top: canvas.bottom
anchors.topMargin: 3
anchors.horizontalCenter: canvas.horizontalCenter
font.pixelSize: 12
font.bold: true
font.family: standardFont.name
color: player && player.isFriend ? activeColor : "white"
width: playerTag.width - (leaderMarker.visible ? (leaderMarker.width + 6) : 0)
wrapMode: Text.WrapAnywhere
horizontalAlignment: Text.AlignHCenter
}
Canvas {
id: canvas
width: 92
height: 92
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
onPaint: {
var ctx = getContext("2d")
ctx.reset()
if (multiplayer.activePlayer === player){
var centreX = canvas.width / 2
var centreY = canvas.height / 2
var step = 360 / gameLogic.userInterval - 1
ctx.beginPath()
ctx.fillStyle = player.connected ? activeColor : inactiveColor
ctx.moveTo(centreX, centreY)
ctx.arc(centreX, centreY, 46, 315 * Math.PI / 180, (gameLogic.userInterval - 1 - gameLogic.remainingTime) * step * Math.PI / 180, true)
ctx.lineTo(centreX, centreY)
ctx.fill()
}
}
}
UserImage {
id: avatar
width: 80
height: 80
anchors.centerIn: canvas
source: getAvatar()
locale: player && player.locale ? player.locale : ""
}
Image {
height: 38
fillMode: Image.PreserveAspectFit
visible: ((player && player.connected) || menu) && level > 10
anchors.top: canvas.top
anchors.left: canvas.left
source: {
if (level >= 500){
return "../../assets/img/PlatinumBadge.png"
} else if (level >= 100){
return "../../assets/img/GoldBadge.png"
} else if (level >= 50){
return "../../assets/img/SilverBadge.png"
} else {
return "../../assets/img/BronzeBadge.png"
}
}
}
Rectangle {
width: 38
height: 38
color: player && player.connected || menu ? activeColor : inactiveColor
radius: width / 2
anchors.top: canvas.top
anchors.right: canvas.right
visible: player && player.connected || menu ? true : false
Rectangle {
visible: false
width: 15
height: 15
border.width: 2
border.color: "white"
color: inactiveColor
radius: width / 2
anchors.centerIn: parent
}
Text {
id: levelText
text: player && player.connected || menu ? level : ""
font.bold: true
anchors.fill: parent
anchors.topMargin: 4
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
font.pixelSize: 14
font.family: standardFont.name
color: "white"
}
}
MouseArea {
id: infoButton
anchors.fill: parent
enabled: player && player.connected ? true: false
onClicked: {
ga.logEvent("User", "Show PlayerInfo")
flurry.logEvent("User.ShowPlayerInfo")
gameScene.playerInfoPopup.visible = true
gameScene.playerInfoPopup.refTag = playerTag
}
}
function getAvatar(){
var tmpAvatar = player && player.connected ? "../../assets/img/User.png" : "../../assets/img/Auto.png"
if (player && player.connected && player.profileImageUrl.length > 0){
tmpAvatar = player.profileImageUrl
}
return tmpAvatar
}
function initTag(){
canvas.requestPaint()
}
function getPlayerData(sendToOthers){
gameNetwork.sync()
var highScore = gameNetwork.userHighscoreForLeaderboard()
var level = 1
if (highScore > 0){
level = Math.floor(highScore / 300)
level = Math.max(1, Math.min(level, 999))
playerTag.level = level
}
highscore = gameNetwork.userHighscoreForCurrentActiveLeaderboard
rank = gameNetwork.userPositionForCurrentActiveLeaderboard
if (sendToOthers){
multiplayer.sendMessage(gameLogic.messageSetPlayerInfo, {userId: multiplayer.localPlayer.userId, level: level, highscore: highscore, rank: rank})