Display owner name in place info

master
Skylar Ittner 8 years ago
parent dec08dbef4
commit 68caf33c45

@ -15,175 +15,184 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<div class="scrollable-box">
<div class="h4" id="place-name"></div>
<div id="place-info-div">
Type: <span id="team-label"></span><br />
<!-- Life: <span id="life-label"></span><br /> -->
Place life: <div class="progress" id="place-health-place"><div id="place-health-place-bar" class="progress-bar" role="progressbar" ></div></div>
<div class="btn btn-success btn-wide" id="capturebtn" onclick="attempttake()"></div>
My life: <div class="progress" id="user-health-place"><div id="user-health-place-bar" class="progress-bar" role="progressbar" ></div></div>
</div>
<div class="well well-sm place-log" id="place-log">
</div>
</div>
<script>
var thisplace = null;
var placeteam = 0;
var capturebtndisabled = false;
function resetcapturebtn() {
capturebtndisabled = false;
$('#capturebtn').removeClass('btn-warning');
$('#capturebtn').addClass('btn-primary');
$('#capturebtn').removeClass('disabled');
if (placeteam == 0) {
$('#capturebtn').text("Claim");
} else if (placeteam == userteamid) {
$('#capturebtn').css('visibility', 'hidden');
} else {
$('#capturebtn').text("Challenge");
}
$('#capturebtn').prop('disabled', false);
}
function resyncstats() {
$.getJSON(mkApiUrl('getstats', 'gs'), {
user: username
}, function (data) {
if (data.status === 'OK') {
maxenergy = data.stats.maxenergy;
energy = data.stats.energy;
level = data.stats.level;
energypercent = (energy * 1.0 / maxenergy * 1.0) * 100.0;
$('#user-health-place-bar').css('width', String(energypercent) + '%');
refreshStats();
}
});
$.getJSON(mkApiUrl('placestats', 'gs'), {
locationid: thisplace.properties.gameinfo.locationid
}, function (data) {
if (data.status === 'OK') {
placeteam = data.stats.teamid;
var placepercent;
if (data.stats.currentlife > 0) {
placepercent = (Math.round(data.stats.currentlife) * 1.0 / Math.round(data.stats.maxlife) * 1.0) * 100.0;
} else {
placepercent = 0;
}
$('#place-health-place-bar').css('width', String(placepercent) + '%');
loadTeamSwag();
} else {
//
}
}).fail(function () {
});
}
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));
} else {
$("#capturebtn").css("background-color", "#" + getTeamColorFromId(placeteam));
}
$("#place-health-place-bar").css("background-color", "#" + getTeamColorFromId(placeteam));
$("#team-label").css("color", "#" + getTeamColorFromId(placeteam));
$("#team-label").text(getTeamNameFromId(placeteam));
}
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();
}
function attemptcapture() {
capturebtndisabled = true;
$('#capturebtn').prop('disabled', true);
$('#capturebtn').addClass('disabled');
$.getJSON(mkApiUrl('attackplace', 'gs'), {
locationid: thisplace.properties.gameinfo.locationid
}, function (data) {
if (data.status === 'OK') {
$('#capturebtn').text(data.message);
switch (Math.round(Math.random() * (3 - 1) + 1)) {
case 1:
$('#place-log').prepend("Attacking...<br />");
break;
case 2:
$('#place-log').prepend("Attacking..<br />");
break;
case 3:
$('#place-log').prepend("Attacking....<br />");
}
resetafteraction();
} else {
$('#capturebtn').text(data.message);
$('#capturebtn').removeClass('btn-primary');
$('#capturebtn').addClass('btn-warning');
$('#place-log').prepend(data.message + "<br />");
resetafteraction();
}
//alert(data.message);
}).fail(function () {
$('#capturebtn').text("Try that again.");
$('#capturebtn').removeClass('btn-primary');
$('#capturebtn').addClass('btn-warning');
resetafteraction();
});
}
function attemptclaim() {
capturebtndisabled = true;
$('#capturebtn').prop('disabled', true);
$('#capturebtn').addClass('disabled');
$.getJSON(mkApiUrl('claimplace', 'gs'), {
locationid: thisplace.properties.gameinfo.locationid
}, function (data) {
if (data.status === 'OK') {
$('#capturebtn').text(data.message);
$('#place-log').prepend("Claimed!<br />");
resetafteraction();
} else {
$('#capturebtn').text(data.message);
$('#capturebtn').removeClass('btn-primary');
$('#capturebtn').addClass('btn-warning');
$('#place-log').prepend(data.message + "<br />");
resetafteraction();
}
//alert(data.message);
}).fail(function () {
$('#capturebtn').text("Try that again.");
$('#capturebtn').removeClass('btn-primary');
$('#capturebtn').addClass('btn-warning');
});
}
function attempttake() {
if (capturebtndisabled) {
return;
}
if (placeteam == 0) {
attemptclaim();
} else if (placeteam == userteamid) {
} else {
attemptcapture();
}
}
<div class="scrollable-box">
<div class="h4" id="place-name"></div>
<div id="place-info-div">
Type: <span id="team-label"></span><br />
Owner: <span id="owner-label"></span><br />
<!-- Life: <span id="life-label"></span><br /> -->
Place life: <div class="progress" id="place-health-place"><div id="place-health-place-bar" class="progress-bar" role="progressbar" ></div></div>
<div class="btn btn-success btn-wide" id="capturebtn" onclick="attempttake()"></div>
My life: <div class="progress" id="user-health-place"><div id="user-health-place-bar" class="progress-bar" role="progressbar" ></div></div>
</div>
<div class="well well-sm place-log" id="place-log">
</div>
</div>
<script>
var thisplace = null;
var placeteam = 0;
var capturebtndisabled = false;
function resetcapturebtn() {
capturebtndisabled = false;
$('#capturebtn').removeClass('btn-warning');
$('#capturebtn').addClass('btn-primary');
$('#capturebtn').removeClass('disabled');
if (placeteam == 0) {
$('#capturebtn').text("Claim");
} else if (placeteam == userteamid) {
$('#capturebtn').css('visibility', 'hidden');
} else {
$('#capturebtn').text("Challenge");
}
$('#capturebtn').prop('disabled', false);
}
function resyncstats() {
$.getJSON(mkApiUrl('getstats', 'gs'), {
user: username
}, function (data) {
if (data.status === 'OK') {
maxenergy = data.stats.maxenergy;
energy = data.stats.energy;
level = data.stats.level;
energypercent = (energy * 1.0 / maxenergy * 1.0) * 100.0;
$('#user-health-place-bar').css('width', String(energypercent) + '%');
refreshStats();
}
});
$.getJSON(mkApiUrl('placestats', 'gs'), {
locationid: thisplace.properties.gameinfo.locationid
}, function (data) {
if (data.status === 'OK') {
placeteam = data.stats.teamid;
var placepercent;
if (data.stats.currentlife > 0) {
placepercent = (Math.round(data.stats.currentlife) * 1.0 / Math.round(data.stats.maxlife) * 1.0) * 100.0;
} else {
placepercent = 0;
}
if (data.stats.nickname == null) {
$('#owner-label').text("Nobody");
} else {
$('#owner-label').on('click', function() {
openProfile(data.stats.nickname);
});
$('#owner-label').text(data.stats.nickname);
}
$('#place-health-place-bar').css('width', String(placepercent) + '%');
loadTeamSwag();
} else {
//
}
}).fail(function () {
});
}
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));
} else {
$("#capturebtn").css("background-color", "#" + getTeamColorFromId(placeteam));
}
$("#place-health-place-bar").css("background-color", "#" + getTeamColorFromId(placeteam));
$("#team-label").css("color", "#" + getTeamColorFromId(placeteam));
$("#team-label").text(getTeamNameFromId(placeteam));
}
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();
}
function attemptcapture() {
capturebtndisabled = true;
$('#capturebtn').prop('disabled', true);
$('#capturebtn').addClass('disabled');
$.getJSON(mkApiUrl('attackplace', 'gs'), {
locationid: thisplace.properties.gameinfo.locationid
}, function (data) {
if (data.status === 'OK') {
$('#capturebtn').text(data.message);
switch (Math.round(Math.random() * (3 - 1) + 1)) {
case 1:
$('#place-log').prepend("Attacking...<br />");
break;
case 2:
$('#place-log').prepend("Attacking..<br />");
break;
case 3:
$('#place-log').prepend("Attacking....<br />");
}
resetafteraction();
} else {
$('#capturebtn').text(data.message);
$('#capturebtn').removeClass('btn-primary');
$('#capturebtn').addClass('btn-warning');
$('#place-log').prepend(data.message + "<br />");
resetafteraction();
}
//alert(data.message);
}).fail(function () {
$('#capturebtn').text("Try that again.");
$('#capturebtn').removeClass('btn-primary');
$('#capturebtn').addClass('btn-warning');
resetafteraction();
});
}
function attemptclaim() {
capturebtndisabled = true;
$('#capturebtn').prop('disabled', true);
$('#capturebtn').addClass('disabled');
$.getJSON(mkApiUrl('claimplace', 'gs'), {
locationid: thisplace.properties.gameinfo.locationid
}, function (data) {
if (data.status === 'OK') {
$('#capturebtn').text(data.message);
$('#place-log').prepend("Claimed!<br />");
resetafteraction();
} else {
$('#capturebtn').text(data.message);
$('#capturebtn').removeClass('btn-primary');
$('#capturebtn').addClass('btn-warning');
$('#place-log').prepend(data.message + "<br />");
resetafteraction();
}
//alert(data.message);
}).fail(function () {
$('#capturebtn').text("Try that again.");
$('#capturebtn').removeClass('btn-primary');
$('#capturebtn').addClass('btn-warning');
});
}
function attempttake() {
if (capturebtndisabled) {
return;
}
if (placeteam == 0) {
attemptclaim();
} else if (placeteam == userteamid) {
} else {
attemptcapture();
}
}
</script>