One Card! - Multiplayer Card Game
import QtQuick 2.0
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import Felgo 3.0
import "../common"
Item {
id: feedback
width: 400
height: content.height + content.anchors.topMargin * 2
z: 110
property string originalHintText: feedbackInput.visible ?
"Your feedback helps us to improve " + gameTitle
: "You can also add your email address so we can reply to you."
Rectangle {
anchors.centerIn: parent
width: gameScene.width * 2
height: gameScene.height * 2
color: "black"
opacity: 0.3
MouseArea {
anchors.fill: parent
onClicked: {
emailInput.focus = false
feedbackInput.focus = false
}
}
}
Rectangle {
radius: 30
anchors.fill: parent
color: "white"
border.color: "#28a3c1"
border.width: 5
}
Column {
id: content
width: parent.width
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.margins: 40
spacing: 20
Text {
id: headerText
horizontalAlignment: Text.AlignHCenter
anchors.horizontalCenter: parent.horizontalCenter
text: "Send Feedback"
font.family: standardFont.name
color: "black"
font.pixelSize: 36
width: parent.width * 0.8
wrapMode: Text.Wrap
}
Text {
id: hintText
horizontalAlignment: Text.AlignHCenter
anchors.horizontalCenter: parent.horizontalCenter
text: originalHintText
font.family: standardFont.name
color: "black"
font.pixelSize: 18
width: parent.width * 0.8
wrapMode: Text.Wrap
}
TextField {
id: emailInput
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width * 0.8
visible: !feedbackInput.visible
horizontalAlignment: Text.AlignHCenter
font.pixelSize: 20
maximumLength: 200
placeholderText: focus ? "" : "Your email (optional)"
inputMethodHints: Qt.ImhNoPredictiveText
validator: RegExpValidator{regExp: /^[a-zA-Z0-9äöüßÄÖÜ;,:._'#+*~@€<>|?ß=()/&%!°^" -]+$/}
style: TextFieldStyle {
textColor: "black"
background: Rectangle {
radius: height
color: "#3028a3c1"
anchors.margins: -4
}
}
onVisibleChanged: {
readOnly = visible ? false : true
if (!visible) focus = false
text = ""
}
onAccepted: {
checkEmail()
}
function checkEmail(){
if (!text || (text.match(/[@]/i) && text.length >= 4)){
hintText.text = originalHintText
return true
} else {
hintText.text = "Invalid email address!"
return false
}
}
}
TextArea {
id: feedbackInput
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width * 0.8
height: emailInput.height * 3
wrapMode: Text.WrapAnywhere
text: placeHolder
horizontalAlignment: Text.AlignHCenter
font.pixelSize: 20
inputMethodHints: Qt.ImhNoPredictiveText
style: TextAreaStyle {backgroundColor: "transparent"; textColor: "black" }
focus: false
property string placeHolder: "Click here to add your feedback!"
onVisibleChanged: {
readOnly = visible ? false : true
if (!visible) {
focus = false
}
}
onFocusChanged: {
console.debug("Focus changed: " + focus + ", Text: " + text)
if (focus && text == placeHolder){
feedbackInput.remove(0, text.length)
} else if (!focus && text == ""){
feedbackInput.append(placeHolder)
}
}
function checkFeedback(){
if (text && actualInput(text) && text != placeHolder){
hintText.text = originalHintText
return true
} else {
hintText.text = "Please enter your feedback!"
return false
}
}
function actualInput(inputString){
var trimmedString = inputString.replace(/^\s*/, "").replace(/\s*$/, "")
if (trimmedString.length >= 3){
return true
} else {
return false
}
}
}
}
ButtonBase {
anchors.left: parent.left
anchors.top: parent.bottom
anchors.topMargin: 10
width: parent.width / 2 - anchors.topMargin / 2
height: (20 + buttonText.height + paddingVertical * 2)
paddingHorizontal: 8
paddingVertical: 4
box.border.width: 5
box.radius: 30
textSize: 28
text: "Close"
onClicked: {
feedback.visible = false
}
}
ButtonBase {
anchors.right: parent.right
anchors.top: parent.bottom
anchors.topMargin: 10
width: parent.width / 2 - anchors.topMargin / 2
height: (20 + buttonText.height + paddingVertical * 2)
paddingHorizontal: 8
paddingVertical: 4
box.border.width: 5
box.radius: 30
textSize: 28
text: "Send"
onClicked: {
if (!emailInput.checkEmail() || !feedbackInput.checkFeedback()){
return
}
if (feedbackInput.visible){
feedbackInput.visible = false
hintText.text = originalHintText
}
else if (feedbackInput.text){
ga.logEvent("User", "Send Feedback")
flurry.logEvent("User.SendFeedback")
var feedbackContent = feedbackInput.text + "\n\n" +
"\nApp Starts: " + appStarts +
"\nGames Played: " + gamesPlayed +
"\nApp VersionCode: " + system.appVersionCode +
"\nPlatform: " + Qt.platform.os +
"\nosType: " + system.osType +
"\nosVersion: " + system.osVersion +
"\nDeviceModel: " + nativeUtils.deviceModel() +
"\nFelgo Version: " + system.vplayVersion +
"\nUDID: " + system.UDID +
"\nGameNetwork UserId: " + gameNetwork.user.userId +
"\nGameNetwork Username: " + gameNetwork.userName
console.debug("Feedback: " + feedbackContent + "; email: " + emailInput.text)
sendFeedback(feedbackContent, emailInput.text)
localStorage.setValue("feedbackSent", true)
feedback.visible = false
} else {
hintText.text = "Please enter your opinion!"
}
}
}
onVisibleChanged: {
feedbackInput.visible = true
feedbackInput.text = feedbackInput.placeHolder
}
function sendFeedback(feedback, email) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
console.debug("Successfully sent feedback to Felgo, response:", xhr.responseText)
}
}
xhr.open("POST", "https://felgo.com/terminal/creator/support.php", true)
xhr.setRequestHeader("Content-Type", "application/json")
xhr.setRequestHeader("Accept", "application/json")
var send = { "shared_secret": Constants.feedbackSecret, "subject": gameTitle + " Feedback", "message": feedback, "name": "", "from": email }
console.debug("sending this feedback request:", JSON.stringify(send))