Added stack splitting and merging to inventory

This commit is contained in:
Thaum
2015-03-25 12:09:24 +00:00
parent 6b14b820a6
commit cb2d1ab958
6 changed files with 124 additions and 20 deletions

View File

@@ -151,8 +151,20 @@ Template.layout.events({
},
"drop .itemContainer": function(event, instacne){
var item = Items.findOne(Session.get("inventory.dragItemId"));
//move item to the container
item.moveToContainer(this._id);
if(event.ctrlKey){
//split the stack to the container
GlobalUI.showDialog({
template: "splitStackDialog",
data: {
id: item._id,
parentCollection: "Containers",
parentId: this._id
}
});
} else{
//move item to the container
item.moveToContainer(this._id);
}
resetInvetorySession();
},
"drop .equipmentContainer": function(event, instance){
@@ -164,7 +176,20 @@ Template.layout.events({
"drop .carriedContainer": function(event, instance){
var charId = Session.get("inventory.dragItemOriginalCharacter");
var item = Items.findOne(Session.get("inventory.dragItemId"));
item.moveToCharacter(this._id);
if(event.ctrlKey){
//split the stack to the container
GlobalUI.showDialog({
template: "splitStackDialog",
data: {
id: item._id,
parentCollection: "Characters",
parentId: this._id
}
});
} else{
//move item to the character
item.moveToCharacter(this._id);
}
resetInvetorySession();
}
});

View File

@@ -0,0 +1,13 @@
<!-- data needs to include id of item, parentCollection, parentId -->
<template name="splitStackDialog">
<div style="width: 300px; height: 110px;">
<paper-input-decorator label="Quantity" floatinglabel>
<input id="quantityInput" type="number" value={{quantity}}>
</paper-input-decorator>
<paper-button id="oneButton"> One </paper-button>
<paper-button id="halfButton"> Half </paper-button>
<paper-button id="allButton"> All </paper-button>
</div>
<paper-button id="cancelButton" affirmative> Cancel </paper-button>
<paper-button id="moveButton" affirmative> Move </paper-button>
</template>

View File

@@ -0,0 +1,27 @@
Template.splitStackDialog.helpers({
quantity: function(){
var item = Items.findOne(this.id);
if(item) return Math.round(item.quantity/2);
}
});
Template.splitStackDialog.events({
'tap #moveButton': function(event, instance){
var item = Items.findOne(this.id);
if(item){
item.splitToParent(
{collection: this.parentCollection , id: this.parentId},
+instance.find('#quantityInput').value
);
}
},
'tap #oneButton':function(event, instance){
instance.find('#quantityInput').value = 1;
},
'tap #halfButton':function(event, instance){
instance.find('#quantityInput').value = Math.round(Items.findOne(this.id).quantity/2);
},
'tap #allButton':function(event, instance){
instance.find('#quantityInput').value = Items.findOne(this.id).quantity;
}
});