[245] | 1 | var ITEMICONBASEURL = "../itemicons/";
|
---|
| 2 |
|
---|
| 3 | var BAG_COLS = 8;
|
---|
| 4 | var BAG_ROWS = 4;
|
---|
| 5 | var BELT_COLS = 8;
|
---|
| 6 | var INV_ITEM_WIDTH = 58;
|
---|
| 7 | var INV_ITEM_HEIGHT = 40;
|
---|
| 8 |
|
---|
| 9 | function ShowInventoryDialog (steamid) {
|
---|
| 10 | var SetCellItem = function (containerTypeName, cellIdent, itemdata) {
|
---|
| 11 | var cell = $("#" + containerTypeName + "Field"+cellIdent);
|
---|
| 12 | var text = $("#" + containerTypeName + "FieldText"+cellIdent);
|
---|
| 13 | if (itemdata.count > 0) {
|
---|
| 14 | cell.attr("style", "background-image: url(" + ITEMICONBASEURL + itemdata.name + ".png);");
|
---|
| 15 | cell.attr("title", itemdata.name);
|
---|
| 16 | text.text(itemdata.count);
|
---|
| 17 | } else {
|
---|
| 18 | cell.attr("style", "background-image: none;");
|
---|
| 19 | cell.removeAttr("title");
|
---|
| 20 | text.text("");
|
---|
| 21 | }
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | var SetEquipmentItem = function (data, name, cellIdent) {
|
---|
| 25 | if (data.equipment [name] == false) {
|
---|
| 26 | SetCellItem ("equipment", cellIdent, { count: 0, name: "" });
|
---|
| 27 | } else {
|
---|
| 28 | SetCellItem ("equipment", cellIdent, { count: 1, name: data.equipment [name] });
|
---|
| 29 | }
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | $.getJSON( "../api/getplayerinventory", { steamid: steamid })
|
---|
| 33 | .done(function(data) {
|
---|
| 34 | $("#invPlayerName").text(data.playername);
|
---|
| 35 |
|
---|
| 36 | for (var y = 0; y < BAG_ROWS; y++) {
|
---|
| 37 | for (var x = 0; x < BAG_COLS; x++) {
|
---|
| 38 | SetCellItem ("bag", x + "_" + y, data.bag[y*BAG_COLS+x]);
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | for (var x = 0; x < BELT_COLS; x++) {
|
---|
| 43 | SetCellItem ("belt", x, data.belt[x]);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | SetEquipmentItem (data, "head", "0_0");
|
---|
| 47 | SetEquipmentItem (data, "eyes", "0_1");
|
---|
| 48 | SetEquipmentItem (data, "face", "0_2");
|
---|
| 49 | SetEquipmentItem (data, "armor", "1_0");
|
---|
| 50 | SetEquipmentItem (data, "jacket", "1_1");
|
---|
| 51 | SetEquipmentItem (data, "shirt", "1_2");
|
---|
| 52 | SetEquipmentItem (data, "legarmor", "2_0");
|
---|
| 53 | SetEquipmentItem (data, "pants", "2_1");
|
---|
| 54 | SetEquipmentItem (data, "boots", "2_2");
|
---|
| 55 | SetEquipmentItem (data, "gloves", "0_4");
|
---|
| 56 | SetEquipmentItem (data, "backpack", "2_4");
|
---|
| 57 |
|
---|
| 58 | $( "#playerInventoryDialog" ).css("z-index", "1010").dialog({
|
---|
| 59 | modal: true,
|
---|
| 60 | width: BAG_COLS*(INV_ITEM_WIDTH+14) + 3*(INV_ITEM_WIDTH+14) + 20,
|
---|
| 61 | buttons: {
|
---|
| 62 | Ok: function() {
|
---|
| 63 | $( this ).dialog( "close" );
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 | });
|
---|
| 67 | })
|
---|
| 68 | .fail(function(jqxhr, textStatus, error) {
|
---|
| 69 | console.log("Error fetching player inventory");
|
---|
| 70 | })
|
---|
| 71 | .always(function() {
|
---|
| 72 | });
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | function SetupInventoryDialog () {
|
---|
| 76 | var CreateInvCell = function (containerTypeName, cellIdent) {
|
---|
| 77 | return "<td class=\"invField\" id=\"" + containerTypeName + "Field"+cellIdent+"\">" +
|
---|
| 78 | "<span class=\"invFieldText\" id=\"" + containerTypeName + "FieldText"+cellIdent+"\"></span>" +
|
---|
| 79 | "</td>";
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | for (var y = 0; y < BAG_ROWS; y++) {
|
---|
| 83 | $("#bagTable").append("<tr id=\"bagRow"+y+"\"></tr>");
|
---|
| 84 | for (var x = 0; x < BAG_COLS; x++) {
|
---|
| 85 | $("#bagRow"+y).append(CreateInvCell ("bag", x + "_" + y));
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | $("#beltTable").append("<tr id=\"beltRow0\"></tr>");
|
---|
| 90 | for (var x = 0; x < BELT_COLS; x++) {
|
---|
| 91 | $("#beltRow0").append(CreateInvCell ("belt", x));
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | for (var y = 0; y < 5; y++) {
|
---|
| 95 | $("#equipmentTable").append("<tr id=\"equipmentRow"+y+"\"></tr>");
|
---|
| 96 | if (y == 3) {
|
---|
| 97 | $("#equipmentRow"+y).append("<td colspan=\"3\"></td>");
|
---|
| 98 | } else {
|
---|
| 99 | for (var x = 0; x < 3; x++) {
|
---|
| 100 | if (y == 4 && x == 1) {
|
---|
| 101 | $("#equipmentRow"+y).append("<td></td>");
|
---|
| 102 | } else {
|
---|
| 103 | $("#equipmentRow"+y).append(CreateInvCell ("equipment", x + "_" + y));
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 | }
|
---|
| 109 |
|
---|