drag and drop for the HUD (non-functional)

Tobias Zwick 2009-12-30 16:50:25 +01:00
parent f0e361e302
commit b566bea377
3 changed files with 158 additions and 7 deletions

View File

@ -10,7 +10,6 @@
<rtype>bool</rtype>
<params>
<param><type>object</type><name>pItem</name><desc>Objekt, das aufgesammelt werden soll</desc></param>
<param><type>object</type><name>pTarget</name><desc>Objekt, das pItem aufsammeln soll. 0 bei lokalem Aufruf.</desc><optional /></param>
</params>
</syntax>
<desc>Sammelt ein Objekt auf. Der Befehl führt dieselben Funktionen aus, als wäre das Objekt durch den normalen Collection-Bereich des Objekts eingesammelt worden (z.B. RejectCollect, Prüfung auf Flagge/Flagge abnehmbar, Hit-Aufruf bei OCF_HitSpeed2, usw.). Die einzigen Unterschiede sind, dass keine Prüfung der Position von pItem auf den Entrance-Bereich von pTarget/this() gemacht wird, und dass pItem nicht auf OCF_Carryable geprüft wird.<br />Mit diesem Befehl lässt sich beispielsweise das Aufnehmen von Objekten aus Containern heraus realisieren. Wenn die Aufnahme fehlschlug (Beispielsweise durch den RejectCollect-Aufruf oder weil der Container voll war), gibt die Funktion 0 zurück. Ansonsten 1.</desc>
@ -19,7 +18,7 @@
<code>protected func ControlDig (pClonk)
{
var obj; if (!(obj = <funclink>Contents</funclink>())) <funclink>return</funclink>(1);
if (!Collect(obj, pClonk)) <funclink>Message</funclink>("Herausnehmen nicht möglich", pClonk);
if (!pClonk->Collect(obj)) <funclink>Message</funclink>("Herausnehmen nicht möglich", pClonk);
<funclink>return</funclink>(1);
}
</code>

View File

@ -130,6 +130,99 @@ public func MouseSelection(int plr)
// TODO: more script choices... Selection-Callbacks for all objects
}
public func MouseDragDone(obj, object target)
{
// not on landscape
if(target) return;
if(obj->GetType() != C4V_C4Object) return;
if(!crew) return false;
var container;
if(container = obj->Contained())
{
if(obj->GetOCF() & OCF_Collectible)
{
container->SetCommand("Drop",obj);
}
else if(obj->GetOCF() & OCF_Grab)
{
if(crew->Contained() == container)
crew->SetCommand("Activate",obj);
}
}
}
public func MouseDrag(int plr)
{
if(plr != GetOwner()) return false;
if(actiontype == ACTIONTYPE_INVENTORY || actiontype == ACTIONTYPE_VEHICLE)
return myobject;
return false;
}
public func MouseDrop(int plr, obj)
{
if(plr != GetOwner()) return false;
if(obj->GetType() != C4V_C4Object) return false;
if(!myobject) return false;
if(!crew) return false;
// a collectible object
if(obj->GetOCF() & OCF_Collectible)
{
if(actiontype == ACTIONTYPE_INVENTORY)
{
// slot is already full: switch places with other object
if(myobject != nil)
{
var objcontainer = obj->Contained();
// object container is the clonk too? Just switch
if(objcontainer == crew)
{
crew->Switch2Items(hotkey-1, crew->GetItemPos(obj));
return true;
}
else
{
var myoldobject = myobject;
// 1. exit my old object
myoldobject->Exit();
// 2. enter the other object in my slot (myobject is now nil)
obj->Collect(crew,hotkey-1);
// 3. enter my old object into other object
objcontainer->Collect(myoldobject);
}
}
// otherwise, just collect
else
{
obj->Collect(crew,hotkey-1);
}
}
else if(actiontype == ACTIONTYPE_VEHICLE)
{
// collect if possible
if(myobject->Collect(item)) return true;
// otherwise (lorry is full?): fail
return false;
}
}
else if(obj->GetOCF() & OCF_Grab)
{
if(actiontype == ACTIONTYPE_STRUCTURE)
{
// respect no push enter
if (obj->GetDefCoreVal("NoPushEnter","DefCore")) return false;
// enter vehicle into structure
PlayerObjectCommand(plr, false, "PushTo", obj, 0, 0, myobject);
return true;
}
}
}
public func Clear()
{
myobject = nil;
@ -158,10 +251,12 @@ public func SetObject(object obj, int type, int pos)
{
SetGraphics(nil,nil,1);
SetName(Format("$TxtSlot$",hotkey));
this["MouseDragImage"] = nil;
}
else
{
SetGraphics(nil,myobject->GetID(),1,GFXOV_MODE_IngamePicture);
this["MouseDragImage"] = myobject;
if(actiontype == nil)
{
if(myobject->Contained() == crew) actiontype = ACTIONTYPE_INVENTORY;

View File

@ -41,6 +41,7 @@ local using;
local alt;
local inventory;
local mlastx, mlasty;
local disableautosort;
/* ++++++++ Item controls ++++++++++ */
@ -95,7 +96,7 @@ public func SelectItem(selection, bool second)
}
}
public func ShiftItem(int dir, bool second)
public func ShiftSelectedItem(int dir, bool second)
{
var sel = selected;
if (second) sel = selected2;
@ -130,6 +131,60 @@ public func GetItem(int i)
return inventory[i];
}
public func GetItemPos(object item)
{
if(item)
if(item->Contained() == this)
{
var i = 0;
for(var obj in inventory)
{
if(obj == item) return i;
++i;
}
}
return nil;
}
public func Switch2Items(int one, int two)
{
var temp = inventory[one];
inventory[one] = inventory[two];
inventory[two] = temp;
if(inventory[one])
this->~OnSlotFull(one);
else
this->~OnSlotEmpty(one);
if(inventory[two])
this->~OnSlotFull(two);
else
this->~OnSlotEmpty(two);
}
public func Collect(object item, int pos)
{
if(pos == nil) return _inherited(item);
// fail if the specified slot is full
if(GetItem(pos) != nil) return false;
if(!item) return false;
pos = BoundBy(pos,0,MaxContentsCount()-1);
disableautosort = true;
// collect but do not sort in
var success = _inherited(item);
disableautosort = false;
if(success)
{
inventory[pos] = item;
this->~OnSlotFull(pos);
}
return success;
}
// disable ShiftContents for objects with ClonkControl.c4d
global func ShiftContents()
@ -156,6 +211,8 @@ protected func Collection2(object obj)
{
var sel;
if(disableautosort) return _inherited(obj,...);
// into selected area if empty
if (!inventory[selected])
{
@ -324,10 +381,10 @@ public func ObjectControl(int plr, int ctrl, int x, int y, int strength, bool re
// Inventory control
var inv_control = true;
if (ctrl == CON_NextItem) { ShiftItem(+1); }
else if (ctrl == CON_PreviousItem) { ShiftItem(-1); }
else if (ctrl == CON_NextAltItem) { ShiftItem(+1,true); }
else if (ctrl == CON_PreviousAltItem) { ShiftItem(-1,true); }
if (ctrl == CON_NextItem) { ShiftSelectedItem(+1); }
else if (ctrl == CON_PreviousItem) { ShiftSelectedItem(-1); }
else if (ctrl == CON_NextAltItem) { ShiftSelectedItem(+1,true); }
else if (ctrl == CON_PreviousAltItem) { ShiftSelectedItem(-1,true); }
else { inv_control = false; }
if (inv_control) return true;