forked from Mirrors/openclonk
fixed/adjusted ShiftContents for objects that use Library_Inventory
parent
299cc7e478
commit
6ba993bc37
|
@ -1,15 +0,0 @@
|
|||
/*--
|
||||
Global functions used in correlation to Objects.ocd\Libraries.ocd\ClonkControl.ocd
|
||||
|
||||
Authors: Newton
|
||||
--*/
|
||||
|
||||
// disable ShiftContents for objects with ClonkControl.ocd
|
||||
|
||||
global func ShiftContents()
|
||||
{
|
||||
if (this)
|
||||
if (this->~HandObjects() != nil)
|
||||
return false;
|
||||
return _inherited(...);
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
global functions that belong to Libraries.ocd/Inventory.ocd
|
||||
*/
|
||||
|
||||
// overload function for objects with Inventory.ocd
|
||||
global func ShiftContents(bool shift_back, id target_id)
|
||||
{
|
||||
if (this && (this->~HandObjects() > 0))
|
||||
{
|
||||
// special handling for only one hand: just move the hand to next item
|
||||
// always move hand 0
|
||||
|
||||
// move to target ID?
|
||||
if(target_id)
|
||||
{
|
||||
for(var pos = 0; pos < this->MaxContentsCount(); ++pos)
|
||||
{
|
||||
var obj = this.inventory.objects[pos];
|
||||
if(!obj) continue;
|
||||
if(obj->GetID() == target_id)
|
||||
{
|
||||
this->SetHandItemPos(0, pos);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// otherwise, move in direction
|
||||
var move_dir = 1;
|
||||
if(shift_back) move_dir = -1;
|
||||
var current_pos = this->GetHandItemPos(0);
|
||||
for(var i = this->MaxContentsCount(); i > 0; --i)
|
||||
{
|
||||
current_pos += move_dir;
|
||||
if(current_pos < 0) current_pos = this->MaxContentsCount() + current_pos;
|
||||
else current_pos = current_pos % this->MaxContentsCount();
|
||||
|
||||
// is there an object at the slot?
|
||||
if(!this.inventory.objects[current_pos]) continue;
|
||||
this->SetHandItemPos(0, current_pos);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return _inherited(shift_back, target_id, ...);
|
||||
}
|
Loading…
Reference in New Issue