Skip to content

Commit

Permalink
implemented quick pickup from corpse inventory (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhnb committed Oct 27, 2019
1 parent ea9d57e commit 1168441
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
4 changes: 4 additions & 0 deletions srcjs/stendhal.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ div.itemSlot {
font-size:10px;
text-shadow: -1px 0 #000, 0 1px #000, 1px 0 #000, 0 -1px #000;
}
div.quickPickup div.itemSlot {
cursor: url(/data/sprites/cursor/itempickupfromslot.png) 1 3, auto;
}

.equipment {position:relative; height:160px; border: 1px solid black}
#head0 {position:absolute; top:0px; left:40px}
#lhand0 {position:absolute; top:50px; left:80px}
Expand Down
2 changes: 1 addition & 1 deletion srcjs/stendhal/entity/chest.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ marauroa.rpobjectFactory["chest"] = marauroa.util.fromProto(marauroa.rpobjectFac

openInventoryWindow: function() {
if (!this.inventory || !this.inventory.popupdiv.parentNode) {
this.inventory = stendhal.ui.equip.createInventoryWindow("content", 5, 6, this, "Chest");
this.inventory = stendhal.ui.equip.createInventoryWindow("content", 5, 6, this, "Chest", false);
}
},

Expand Down
4 changes: 2 additions & 2 deletions srcjs/stendhal/entity/corpse.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ marauroa.rpobjectFactory["corpse"] = marauroa.util.fromProto(marauroa.rpobjectFa

openCorpseInventory: function() {
if (!this.inventory || !this.inventory.popupdiv.parentNode) {
this.inventory = stendhal.ui.equip.createInventoryWindow("content", 2, 2, this, "Corpse");
this.inventory = stendhal.ui.equip.createInventoryWindow("content", 2, 2, this, "Corpse", true);
}
},

Expand All @@ -74,7 +74,7 @@ marauroa.rpobjectFactory["corpse"] = marauroa.util.fromProto(marauroa.rpobjectFa
this.autoOpenedAlready = true;
if (marauroa.me && (this["corpse_owner"] == marauroa.me["_name"])) {

// TODO: for unknown reason, /data/sprites/items/undefined/undefined.png is requires without this delay
// TODO: for unknown reason, /data/sprites/items/undefined/undefined.png is requested without this delay
var that = this;
window.setTimeout(function() {
that.openCorpseInventory();
Expand Down
24 changes: 19 additions & 5 deletions srcjs/stendhal/ui/itemcontainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ stendhal.ui = stendhal.ui || {};
*
* @constructor
*/
stendhal.ui.ItemContainerWindow = function(slot, size, object, suffix) {
stendhal.ui.ItemContainerWindow = function(slot, size, object, suffix, quickPickup) {
this.update = function() {
render();
};
Expand Down Expand Up @@ -115,6 +115,16 @@ stendhal.ui.ItemContainerWindow = function(slot, size, object, suffix) {

function onMouseUp(e) {
if (e.target.dataItem) {
if (quickPickup) {
marauroa.clientFramework.sendAction({
type: "equip",
"source_path": e.target.dataItem.getIdPath(),
"target_path": "[" + marauroa.me["id"] + "\tbag]",
"zone": marauroa.currentZoneName
});
return;
}

if (isRightClick(e)) {
new stendhal.ui.Menu(e.target.dataItem, e.pageX - 50, e.pageY - 5);
} else {
Expand Down Expand Up @@ -150,7 +160,7 @@ stendhal.ui.equip = {
for (var i in this.slotNames) {
stendhal.ui.equip.inventory.push(
new stendhal.ui.ItemContainerWindow(
this.slotNames[i], this.slotSizes[i], null, ""));
this.slotNames[i], this.slotSizes[i], null, "", false));
}
},

Expand All @@ -160,17 +170,21 @@ stendhal.ui.equip = {
}
},

createInventoryWindow: function(slot, sizeX, sizeY, object, title) {
createInventoryWindow: function(slot, sizeX, sizeY, object, title, quickPickup) {
stendhal.ui.equip.counter++;
var suffix = "." + stendhal.ui.equip.counter + ".";
var html = "<div class=\"inventorypopup inventorypopup_" + sizeX + "\">";
var html = "<div class=\"inventorypopup inventorypopup_" + sizeX;
if (quickPickup) {
html += " quickPickup";
}
html += "\">";
for (var i = 0; i < sizeX * sizeY; i++) {
html += "<div id='" + slot + suffix + i + "' class='itemSlot'></div>";
}
html += "</div>";

var popup = new stendhal.ui.Popup(title, html, 160, 370);
var itemContainer = new stendhal.ui.ItemContainerWindow(slot, sizeX * sizeY, object, suffix);
var itemContainer = new stendhal.ui.ItemContainerWindow(slot, sizeX * sizeY, object, suffix, quickPickup);
stendhal.ui.equip.inventory.push(itemContainer);
itemContainer.update();
popup.onClose = function() {
Expand Down

0 comments on commit 1168441

Please sign in to comment.