| 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 |                         dialogClass: "playerInventoryDialog",
 | 
|---|
| 60 |                         modal: true,
 | 
|---|
| 61 |                         width: BAG_COLS*(INV_ITEM_WIDTH+14) + 3*(INV_ITEM_WIDTH+14) + 20,
 | 
|---|
| 62 |                         buttons: {
 | 
|---|
| 63 |                                 Ok: function() {
 | 
|---|
| 64 |                                         $( this ).dialog( "close" );
 | 
|---|
| 65 |                                 }
 | 
|---|
| 66 |                         }
 | 
|---|
| 67 |                 });
 | 
|---|
| 68 |         })
 | 
|---|
| 69 |         .fail(function(jqxhr, textStatus, error) {
 | 
|---|
| 70 |                 console.log("Error fetching player inventory");
 | 
|---|
| 71 |         })
 | 
|---|
| 72 |         .always(function() {
 | 
|---|
| 73 |         });
 | 
|---|
| 74 | }
 | 
|---|
| 75 | 
 | 
|---|
| 76 | function SetupInventoryDialog () {
 | 
|---|
| 77 |         var CreateInvCell = function (containerTypeName, cellIdent) {
 | 
|---|
| 78 |                 return "<td class=\"invField\" id=\"" + containerTypeName + "Field"+cellIdent+"\">" +
 | 
|---|
| 79 |                         "<span class=\"invFieldText\" id=\"" + containerTypeName + "FieldText"+cellIdent+"\"></span>" +
 | 
|---|
| 80 |                         "</td>";
 | 
|---|
| 81 |         }
 | 
|---|
| 82 | 
 | 
|---|
| 83 |         for (var y = 0; y < BAG_ROWS; y++) {
 | 
|---|
| 84 |                 $("#bagTable").append("<tr id=\"bagRow"+y+"\"></tr>");
 | 
|---|
| 85 |                 for (var x = 0; x < BAG_COLS; x++) {
 | 
|---|
| 86 |                         $("#bagRow"+y).append(CreateInvCell ("bag", x + "_" + y));
 | 
|---|
| 87 |                 }
 | 
|---|
| 88 |         }
 | 
|---|
| 89 | 
 | 
|---|
| 90 |         $("#beltTable").append("<tr id=\"beltRow0\"></tr>");
 | 
|---|
| 91 |         for (var x = 0; x < BELT_COLS; x++) {
 | 
|---|
| 92 |                 $("#beltRow0").append(CreateInvCell ("belt", x));
 | 
|---|
| 93 |         }
 | 
|---|
| 94 |         
 | 
|---|
| 95 |         for (var y = 0; y < 5; y++) {
 | 
|---|
| 96 |                 $("#equipmentTable").append("<tr id=\"equipmentRow"+y+"\"></tr>");
 | 
|---|
| 97 |                 if (y == 3) {
 | 
|---|
| 98 |                         $("#equipmentRow"+y).append("<td colspan=\"3\"></td>");
 | 
|---|
| 99 |                 } else {
 | 
|---|
| 100 |                         for (var x = 0; x < 3; x++) {
 | 
|---|
| 101 |                                 if (y == 4 && x == 1) {
 | 
|---|
| 102 |                                         $("#equipmentRow"+y).append("<td></td>");
 | 
|---|
| 103 |                                 } else {
 | 
|---|
| 104 |                                         $("#equipmentRow"+y).append(CreateInvCell ("equipment", x + "_" + y));
 | 
|---|
| 105 |                                 }
 | 
|---|
| 106 |                         }
 | 
|---|
| 107 |                 }
 | 
|---|
| 108 |         }
 | 
|---|
| 109 | }
 | 
|---|
| 110 | 
 | 
|---|