source: binary-improvements/webserver_legacy/js/inventory_dialog.js@ 464

Last change on this file since 464 was 369, checked in by alloc, 3 years ago

Preparations for A20 release
Changes usage of "SteamID" to "UserID" in console commands
Also changes a bunch of the WebAPI stuff to show / use UserIDs

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