You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
5.7 KiB
HTML
158 lines
5.7 KiB
HTML
<!--
|
|
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.
|
|
-->
|
|
<div class="scrollable-box">
|
|
<div class="list-group" id="inventory-list">
|
|
<div class="list-group-item">
|
|
<i class="fa fa-spinner fa-pulse fa-fw"></i> Loading...
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="menumessage" id="giveitemmessage">
|
|
<div class="menumessagecontent" id="giveitemmessagecontent">
|
|
Give one <span id="giveitemname">item</span> to: <br />
|
|
<select class="form-control" id="nearby-players-dropdown"></select>
|
|
</div>
|
|
<div style="margin-bottom: 5px;" class="btn btn-wide btn-success" onclick="giveitem($('#giveitem-uuid').text(), $('#nearby-players-dropdown').val())">
|
|
Give
|
|
</div>
|
|
<div class="btn btn-wide btn-danger" onclick="$('#giveitemmessage').css('display', 'none')">
|
|
Cancel
|
|
</div>
|
|
<span style="display: none;" id="giveitem-uuid"></span>
|
|
</div>
|
|
|
|
<script>
|
|
function askgiveitem(uuid) {
|
|
$('#invitem-' + uuid).prop('onclick', null).off('click');
|
|
$('#giveitem-uuid').text(uuid);
|
|
$("#giveitemname").html($('#item-' + uuid).find(".itemname").text());
|
|
|
|
// Load the list of nearby players
|
|
$.getJSON(mkApiUrl('nearby'), {
|
|
lat: latitude,
|
|
long: longitude,
|
|
lang: USER_LANGUAGE
|
|
}, function (data) {
|
|
var content = "";
|
|
if (data.status === 'OK') {
|
|
var people = data.people;
|
|
people.forEach(function (person) {
|
|
if (person.name !== username) {
|
|
content += "<option name='" + person.name + "'>" + person.name + "</option>\n";
|
|
}
|
|
});
|
|
} else {
|
|
content = "";
|
|
}
|
|
if (content == '') {
|
|
playSound("error");
|
|
showErrorMessage("There is nobody nearby to give an item to.");
|
|
} else {
|
|
$('#nearby-players-dropdown').html(content);
|
|
$('#giveitemmessage').css('display', 'block');
|
|
}
|
|
});
|
|
}
|
|
|
|
function giveitem(uuid, playername) {
|
|
$('#giveitemmessage').css('display', 'none');
|
|
if (playername === '') {
|
|
return;
|
|
}
|
|
$.getJSON(mkApiUrl('giveitem', 'gs'), {
|
|
giveto: playername,
|
|
itemuuid: uuid,
|
|
lang: USER_LANGUAGE
|
|
}, function (data) {
|
|
if (data.status === 'OK') {
|
|
loadinventory();
|
|
syncStats();
|
|
showSuccessMessage("Transferred!");
|
|
} else {
|
|
playSound("error");
|
|
showErrorMessage(data.message);
|
|
}
|
|
}).fail(function () {
|
|
showErrorMessage("Cannot give item. Try again.");
|
|
});
|
|
}
|
|
|
|
function useitem(uuid) {
|
|
$('#invitem-' + uuid).prop('onclick', null).off('click');
|
|
$.getJSON(mkApiUrl('useitem', 'gs'), {
|
|
itemuuid: uuid,
|
|
lang: USER_LANGUAGE
|
|
}, function (data) {
|
|
if (data.status === 'OK') {
|
|
loadinventory();
|
|
syncStats();
|
|
} else {
|
|
playSound("error");
|
|
showErrorMessage(data.message);
|
|
}
|
|
}).fail(function () {
|
|
showErrorMessage("Something went wrong. Try again.");
|
|
});
|
|
}
|
|
|
|
function getitemhtmlfromjson(item) {
|
|
var itemhtml = "<div class='list-group-item inventory-item' id='item-" + item.itemuuid + "'>"
|
|
+ "<h4 class='itemname'>" + item.itemname + "</h4>"
|
|
+ "<p class='itemdesc'>" + item.itemdesc + "</p>";
|
|
if (item.classname == "healmagic") {
|
|
itemhtml += "<span class='btn btn-success' id='invitem-" + item.itemuuid + "' onclick=\"useitem('" + item.itemuuid + "')\">"
|
|
+ "Use Item"
|
|
+ "</span>";
|
|
}
|
|
|
|
if (item.itemid < 9000) {
|
|
// only allow item gifting for non-promo/paid items,
|
|
// so Apple doesn't get upset
|
|
itemhtml += "<span class='btn btn-info' style='margin-left: 5px;' onclick=\"askgiveitem('" + item.itemuuid + "')\">"
|
|
+ "Give Item"
|
|
+ "</span>";
|
|
}
|
|
|
|
itemhtml += "<span class='itemid' style='display: none;'>" + item.itemid + "</span>"
|
|
+ "<span class='itemclassid' style='display: none;'>" + item.classid + "</span>"
|
|
+ "<span class='itemjson' style='display: none;'>" + item.itemjson + "</span>"
|
|
+ "</div>";
|
|
return itemhtml;
|
|
}
|
|
|
|
function loadinventory() {
|
|
$.getJSON(mkApiUrl('inventory'), {
|
|
user: username,
|
|
lang: USER_LANGUAGE
|
|
}, function (data) {
|
|
var content = "";
|
|
if (data.status == 'OK') {
|
|
var items = data.items;
|
|
items.forEach(function (item) {
|
|
content += getitemhtmlfromjson(item);
|
|
});
|
|
} else {
|
|
content = "<div class='list-group-item'>An error occurred.</div>";
|
|
}
|
|
$('#inventory-list').html(content);
|
|
});
|
|
}
|
|
|
|
loadinventory();
|
|
</script> |