From 382cf53cb2c1bd64cca9f1968fde687d1ea14401 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Tue, 29 Nov 2016 17:23:14 -0700 Subject: [PATCH] Condense dialog code into one nice system --- www/css/main.css | 5 ++++- www/index.html | 15 +++++++++++++ www/js/auth.js | 7 +++++- www/js/dialogs.js | 45 ++++++++++++++++++++++++++++++++++++++ www/js/location.js | 2 +- www/js/main.js | 31 +++++++++++++++----------- www/js/shop.js | 34 ++++++++++------------------ www/screens/inventory.html | 39 +++++---------------------------- 8 files changed, 106 insertions(+), 72 deletions(-) create mode 100644 www/js/dialogs.js diff --git a/www/css/main.css b/www/css/main.css index 7f2e8a2..a060ac8 100644 --- a/www/css/main.css +++ b/www/css/main.css @@ -456,7 +456,7 @@ body { .menumessage { position: fixed; - z-index: 9999; + z-index: 99999; background: rgba(0, 0, 0, .85); border-radius: 10px; left: 10%; @@ -481,6 +481,9 @@ body { font-size: 120%; text-align: center; margin-bottom: 10px; + overflow-x: hidden; + overflow-y: auto; + word-wrap: break-word; } #shop-balance-bar { diff --git a/www/index.html b/www/index.html index 4c44bbe..8bebe92 100644 --- a/www/index.html +++ b/www/index.html @@ -62,11 +62,26 @@ + +
diff --git a/www/js/auth.js b/www/js/auth.js index 59f876d..74be051 100644 --- a/www/js/auth.js +++ b/www/js/auth.js @@ -21,6 +21,7 @@ */ var authOpInProgress = false; +var logoutInProgress = false; function askLogout() { navigator.notification.confirm( @@ -36,6 +37,7 @@ function askLogout() { } function logout() { + logoutInProgress = true; $.getJSON(mkApiUrl('deletesession'), {}, function (data) { if (data.status === 'OK') { localStorage.setItem("username", ''); @@ -43,11 +45,14 @@ function logout() { username = null; password = null; openscreen('login'); + logoutInProgress = false; } else { + logoutInProgress = false; navigator.notification.alert("Server did not properly acknowledge logout. You might have problems for the next few hours if you switch accounts.", null, "Error", 'Dismiss'); } }).fail(function () { - navigator.notification.alert("Cannot connect to authentication server. Check your Internet connection and try again. If that fails, clear the app data or reinstall TerranQuest.", null, "Error", 'Dismiss'); + logoutInProgress = false; + navigator.notification.alert("Cannot connect to server. Check your Internet connection and try again. If that fails, clear the app data or reinstall TerranQuest.", null, "Error", 'Dismiss'); }); } diff --git a/www/js/dialogs.js b/www/js/dialogs.js new file mode 100644 index 0000000..dfb96e2 --- /dev/null +++ b/www/js/dialogs.js @@ -0,0 +1,45 @@ +/* + * TerranQuest - Augmented Reality fantasy game + * + * Copyright 2016 Netsyms Technologies + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function showSuccessMessage(text) { + $('#hugetimessign').css('display', 'none'); + $('#hugecheckmark').css('display', 'block'); + $('#alertmessagecontent').html(text); + $('#alertmessagebox').css('display', 'block'); +} + +function showErrorMessage(text) { + $('#hugetimessign').css('display', 'block'); + $('#hugecheckmark').css('display', 'none'); + $('#alertmessagecontent').html(text); + $('#alertmessagebox').css('display', 'block'); +} + +function dismissMessageBox() { + $('#alertmessagebox').css('display', 'none'); +} + +function serverProblemsDialog(errmsg) { + StatusBar.backgroundColorByHexString("#324150"); + window.location = "servererror.html?errmsg=" + errmsg; +} + +function clientProblemsDialog(errmsg) { + StatusBar.backgroundColorByHexString("#324150"); + window.location = "clienterror.html?errmsg=" + errmsg; +} \ No newline at end of file diff --git a/www/js/location.js b/www/js/location.js index c565628..fc83d4c 100644 --- a/www/js/location.js +++ b/www/js/location.js @@ -197,7 +197,7 @@ var updatePosition = function (position) { function pingServer() { if (lockGot && gpsaccuracy < requiredaccuracy) { $.getJSON(mkApiUrl('ping') + "?user=" + username + "&lat=" + latitude + "&long=" + longitude, function (data) { - if (data.status == "ERROR") { + if (data.status == "ERROR" && logoutInProgress != true) { localStorage.setItem("no_autologin", "true"); username = null; password = null; diff --git a/www/js/main.js b/www/js/main.js index f45b653..99e9cfc 100644 --- a/www/js/main.js +++ b/www/js/main.js @@ -119,17 +119,6 @@ function compareVersions(a, b) { return segmentsA.length - segmentsB.length; } - -function serverProblemsDialog(errmsg) { - StatusBar.backgroundColorByHexString("#324150"); - window.location = "servererror.html?errmsg=" + errmsg; -} - -function clientProblemsDialog(errmsg) { - StatusBar.backgroundColorByHexString("#324150"); - window.location = "clienterror.html?errmsg=" + errmsg; -} - function mkApiUrl(action, server) { if (server === 'cs') { var chatserverurl = "http://gs.terranquest.net/"; @@ -512,6 +501,22 @@ var Konami = function (callback) { return konami; }; +var konamicounter = 0; var dev_console = new Konami(function () { - alert(eval(prompt("Enter console command: ", "$(\"#\")"))); -}); \ No newline at end of file + konamicounter++; + if (konamicounter > 2) { + alert(eval(prompt("Enter console command: ", "$(\"#\")"))); + } +}); + +/** + * Cancel all timeouts and intervals that may or may not exist. + * + * http://stackoverflow.com/a/8345814/2534036 + */ +function forceCancelAllTimers() { + var highestTimeoutId = setTimeout(";"); + for (var i = 0; i < highestTimeoutId; i++) { + clearTimeout(i); + } +} \ No newline at end of file diff --git a/www/js/shop.js b/www/js/shop.js index fe648a5..8d25bcb 100644 --- a/www/js/shop.js +++ b/www/js/shop.js @@ -30,19 +30,19 @@ function buycoins(productId) { if (result.status == 'OK') { return inAppPurchase.consume(data.type, data.receipt, data.signature); } else { - showShopMessage("Error: " + result.message, true); + showErrorMessage("Error: " + result.message); } }).fail(function () { - showShopMessage("Error: Lost connection to TerranQuest servers. If your purchase does not appear within a few hours, contact support@netsyms.com.", true); + showErrorMessage("Error: Lost connection to TerranQuest servers. If your purchase does not appear within a few hours, contact support@netsyms.com."); }); }) .then(function () { - showShopMessage("Thanks for your purchase!", false); + showSuccessMessage("Thanks for your purchase!"); refreshcoins(); }) .catch(function (err) { console.log("Error: " + err.message); - showShopMessage("Error: " + err.message, true); + showErrorMessage("Error: " + err.message); }); } else if (getPlatform() == DEVICE_IOS) { inAppPurchase @@ -58,37 +58,25 @@ function buycoins(productId) { if (result.status == 'OK') { return inAppPurchase.consume(data.type, data.receipt, data.signature); } else { - showShopMessage("Error: " + result.message, true); + showErrorMessage("Error: " + result.message); } }).fail(function () { - showShopMessage("Error: Lost connection to TerranQuest servers. If your purchase does not appear within a few hours, contact support@netsyms.com.", true); + showErrorMessage("Error: Lost connection to TerranQuest servers. If your purchase does not appear within a few hours, contact support@netsyms.com."); }); }) .then(function () { - showShopMessage("Thanks for your purchase!", false); + showSuccessMessage("Thanks for your purchase!"); refreshcoins(); }) .catch(function (err) { console.log("Error: " + err.message); - showShopMessage("Error: " + err.message, true); + showErrorMessage("Error: " + err.message); }); } else { - showShopMessage("Store not available on your device. Please go to terranquest.net to purchase coins.", true); + showErrorMessage("Store not available on your device. Please go to terranquest.net to purchase coins."); } } -function showShopMessage(msg, iserror) { - if (iserror) { - $('#hugetimessign').css('display', 'block'); - $('#hugecheckmark').css('display', 'none'); - } else { - $('#hugetimessign').css('display', 'none'); - $('#hugecheckmark').css('display', 'block'); - } - $('#shopmessagecontent').text(msg); - $('#shopmessage').css('display', 'block'); -} - function buyitem(id, cost) { $('#shopitem-' + id).prop('onclick', null).off('click'); $.getJSON(mkApiUrl('buyitem', 'gs'), { @@ -96,9 +84,9 @@ function buyitem(id, cost) { cost: cost }, function (data) { if (data.status == 'OK') { - showShopMessage(data.message, false); + showSuccessMessage(data.message); } else { - showShopMessage(data.message, true); + showErrorMessage(data.message); } loadstorefront(); }); diff --git a/www/screens/inventory.html b/www/screens/inventory.html index 3b458c1..877d295 100644 --- a/www/screens/inventory.html +++ b/www/screens/inventory.html @@ -23,21 +23,6 @@
- -