diff --git a/www/css/main.css b/www/css/main.css index c280adc..dcc0a86 100644 --- a/www/css/main.css +++ b/www/css/main.css @@ -349,6 +349,12 @@ body { overflow-y: hidden; } +#place-refresh { + position: fixed; + right: 20px; + margin-top: 2px; +} + #user-health-place-bar { background-color: green; } @@ -369,6 +375,10 @@ body { color: black; } +#refillbtn { + color: black; +} + .found-box { position: absolute; z-index: 9001; diff --git a/www/screens/place.html b/www/screens/place.html index 2ddd212..28cb09f 100644 --- a/www/screens/place.html +++ b/www/screens/place.html @@ -18,11 +18,20 @@
+ Type:
Owner:
Place life:
-
+
+
+
+
+
+
+
+
+
My life:
@@ -34,24 +43,49 @@ var thisplace = null; var placeteam = 0; var capturebtndisabled = false; + var refillbtndisabled = false; + // Enforced time between actions, in ms + var actioninterval = 1000; function resetcapturebtn() { capturebtndisabled = false; $('#capturebtn').removeClass('btn-warning'); $('#capturebtn').addClass('btn-primary'); $('#capturebtn').removeClass('disabled'); + $('#capturebtn').prop('disabled', false); if (placeteam == 0) { $('#capturebtn').text("Claim"); } else if (placeteam == userteamid) { - $('#capturebtn').css('visibility', 'hidden'); + $('#capturebtn').addClass('disabled'); + $('#capturebtn').text("Challenge"); + $('#capturebtn').prop('disabled', true); } else { $('#capturebtn').text("Challenge"); } - $('#capturebtn').prop('disabled', false); } - function resyncstats() { + function resetrefillbtn() { + refillbtndisabled = false; + $('#refillbtn').removeClass('btn-warning'); + $('#refillbtn').addClass('btn-primary'); + $('#refillbtn').removeClass('disabled'); + $('#refillbtn').prop('disabled', false); + if (placeteam == 0) { + $('#refillbtn').addClass('disabled'); + $('#refillbtn').text("Refill"); + $('#refillbtn').prop('disabled', true); + } else if (placeteam == userteamid) { + $('#refillbtn').text("Refill"); + } else { + $('#refillbtn').addClass('disabled'); + $('#refillbtn').text("Refill"); + $('#refillbtn').prop('disabled', true); + } + } + + function resync(firstload) { + $('#place-refresh').addClass('fa-spin'); $.getJSON(mkApiUrl('getstats', 'gs'), { user: username }, function (data) { @@ -78,33 +112,40 @@ if (data.stats.nickname == null) { $('#owner-label').text("Nobody"); } else { - $('#owner-label').on('click', function() { + $('#owner-label').on('click', function () { openProfile(data.stats.nickname); }); $('#owner-label').text(data.stats.nickname); } $('#place-health-place-bar').css('width', String(placepercent) + '%'); loadTeamSwag(); + if (firstload === true) { + resetcapturebtn(); + resetrefillbtn(); + } else { + setTimeout(resetcapturebtn, actioninterval); + setTimeout(resetrefillbtn, actioninterval); + } } else { - // + $('#place-log').prepend("An error occurred.
"); } + $('#place-refresh').removeClass('fa-spin'); }).fail(function () { + $('#place-log').prepend("An error occurred.
"); + $('#place-refresh').removeClass('fa-spin'); }); } - function resetafteraction() { - resyncstats(); - setTimeout(resetcapturebtn, 2 * 1000); - } - function loadTeamSwag() { $("#place-name").css("border-color", "#" + getTeamColorFromId(placeteam)); $("#place-info-div").css("border-color", "#" + getTeamColorFromId(placeteam)); $("#place-log").css("border-color", "#" + getTeamColorFromId(placeteam)); if (placeteam == 0) { $("#capturebtn").css("background-color", "#" + getTeamColorFromId(userteamid)); + $("#refillbtn").css("background-color", "#" + getTeamColorFromId(userteamid)); } else { $("#capturebtn").css("background-color", "#" + getTeamColorFromId(placeteam)); + $("#refillbtn").css("background-color", "#" + getTeamColorFromId(placeteam)); } $("#place-health-place-bar").css("background-color", "#" + getTeamColorFromId(placeteam)); $("#team-label").css("color", "#" + getTeamColorFromId(placeteam)); @@ -114,11 +155,9 @@ function loadPlace(feature) { thisplace = feature; placeteam = feature.properties.gameinfo.teamid; - loadTeamSwag(); $("#place-name").text(feature.properties.name); $("#life-label").text(Math.round(feature.properties.gameinfo.currentlife) + " / " + Math.round(feature.properties.gameinfo.maxlife)); - resetcapturebtn(); - resyncstats(); + resync(true); } function attemptcapture() { @@ -142,20 +181,56 @@ case 3: $('#place-log').prepend("Attacking....
"); } - resetafteraction(); + resync(); } else { $('#capturebtn').text(data.message); $('#capturebtn').removeClass('btn-primary'); $('#capturebtn').addClass('btn-warning'); $('#place-log').prepend(data.message + "
"); - resetafteraction(); + resync(); } //alert(data.message); }).fail(function () { $('#capturebtn').text("Try that again."); $('#capturebtn').removeClass('btn-primary'); $('#capturebtn').addClass('btn-warning'); - resetafteraction(); + resync(); + }); + } + + function attemptrefill() { + refillbtndisabled = true; + $('#refillbtn').prop('disabled', true); + $('#refillbtn').addClass('disabled'); + $.getJSON(mkApiUrl('refillplace', 'gs'), { + locationid: thisplace.properties.gameinfo.locationid, + lat: latitude, + long: longitude + }, function (data) { + if (data.status === 'OK') { + $('#refillbtn').text(data.message); + switch (Math.round(Math.random() * (3 - 1) + 1)) { + case 1: + $('#place-log').prepend("Refilling...
"); + break; + case 2: + $('#place-log').prepend("Refilling..
"); + break; + case 3: + $('#place-log').prepend("Refilling....
"); + } + } else { + $('#refillbtn').text(data.message); + $('#refillbtn').removeClass('btn-primary'); + $('#refillbtn').addClass('btn-warning'); + $('#place-log').prepend(data.message + "
"); + } + resync(); + }).fail(function () { + $('#refillbtn').text("Try that again."); + $('#refillbtn').removeClass('btn-primary'); + $('#refillbtn').addClass('btn-warning'); + resync(); }); } @@ -171,19 +246,20 @@ if (data.status === 'OK') { $('#capturebtn').text(data.message); $('#place-log').prepend("Claimed!
"); - resetafteraction(); + resync(); } else { $('#capturebtn').text(data.message); $('#capturebtn').removeClass('btn-primary'); $('#capturebtn').addClass('btn-warning'); $('#place-log').prepend(data.message + "
"); - resetafteraction(); + resync(); } //alert(data.message); }).fail(function () { $('#capturebtn').text("Try that again."); $('#capturebtn').removeClass('btn-primary'); $('#capturebtn').addClass('btn-warning'); + resync(); }); }