openclonk/planet/Objects.ocd/Libraries.ocd/HUDAdapter.ocd/Script.c

247 lines
5.2 KiB
C
Raw Normal View History

/**
2009-12-29 13:44:16 +00:00
HUD Adapter
2009-12-29 13:44:16 +00:00
Clonk-side scripts for the HUD. This object basically redirects the
engine callbacks for the clonk to the HUD. All crew members that
are to be shown in the HUD have to include this object and return
_inherited(); if they overload one of the callbacks used here.
This adapter redirects to the per player HUD controller and also
directly to the per clonk HUD selector.
2011-03-13 15:55:00 +00:00
Requires the ClonkControl.ocd to be included in the clonk too.
@authors Newton
2009-12-29 13:44:16 +00:00
*/
local HUDselector, HUDcontroller;
public func SetSelector(object sel)
{
HUDselector = sel;
// Ensure controller is set if it was created after creation of this clonk (e.g. after section change)
if (!HUDcontroller) HUDcontroller = FindObject(Find_ID(GUI_Controller), Find_Owner(GetOwner()));
return true;
}
public func GetSelector() { return HUDselector; }
2009-12-29 13:44:16 +00:00
public func HUDAdapter()
{
return true;
}
// hotkey control
public func ControlHotkey(int hotindex)
{
if (HUDcontroller)
return HUDcontroller->ControlHotkey(hotindex);
2009-12-29 13:44:16 +00:00
}
/* Engine callbacks */
// bootstrap the hud
protected func Recruitment(int plr)
2009-12-29 13:44:16 +00:00
{
HUDcontroller = FindObject(Find_ID(GUI_Controller), Find_Owner(plr));
if (!HUDcontroller)
HUDcontroller = CreateObjectAbove(GUI_Controller, 10, 10, plr);
HUDcontroller->OnCrewRecruitment(this, plr, ...);
HUDcontroller->ScheduleUpdateInventory();
return _inherited(plr, ...);
2009-12-29 13:44:16 +00:00
}
protected func DeRecruitment(int plr)
{
if (HUDcontroller) HUDcontroller->OnCrewDeRecruitment(this, plr, ...);
return _inherited(plr, ...);
}
protected func Death(int killed_by)
{
if (HUDcontroller) HUDcontroller->OnCrewDeath(this, killed_by, ...);
return _inherited(killed_by,...);
}
protected func Destruction()
{
if (HUDcontroller) HUDcontroller->OnCrewDestruction(this, ...);
return _inherited(...);
}
public func OnDisplayInfoMessage()
{
}
2009-12-29 13:44:16 +00:00
// calls to the crew selector hud
protected func OnPromotion()
{
if (HUDselector)
HUDselector->UpdateRank();
return _inherited(...);
}
protected func OnEnergyChange()
{
if (HUDselector)
HUDselector->UpdateHealthBar();
return _inherited(...);
}
protected func OnBreathChange() {
if (HUDselector)
HUDselector->UpdateBreathBar();
return _inherited(...);
}
protected func OnMagicEnergyChange() {
return _inherited(...);
}
protected func OnNameChanged()
{
if (HUDselector)
HUDselector->UpdateName();
return _inherited(...);
}
2009-12-29 13:44:16 +00:00
protected func OnPhysicalChange(string physical, int change)
2009-12-29 13:44:16 +00:00
{
if (HUDselector)
{
2009-12-29 13:44:16 +00:00
// all physicals are resetted
if (!physical)
2009-12-29 13:44:16 +00:00
{
HUDselector->UpdateHealthBar();
HUDselector->UpdateBreathBar();
HUDselector->UpdateMagicBar();
}
else if (physical == "Energy") HUDselector->UpdateHealthBar();
else if (physical == "Breath") HUDselector->UpdateBreathBar();
else if (physical == "Magic") HUDselector->UpdateMagicBar();
2009-12-29 13:44:16 +00:00
}
return _inherited(physical, change, ...);
2009-12-29 13:44:16 +00:00
}
// calls to both crew selector and controller
protected func CrewSelection(bool unselect)
{
if (HUDselector)
HUDselector->UpdateSelectionStatus();
if (HUDcontroller)
HUDcontroller->OnCrewSelection(this,unselect);
return _inherited(unselect, ...);
2009-12-29 13:44:16 +00:00
}
// calls to controller
protected func OnCrewEnabled()
{
if (HUDcontroller)
HUDcontroller->OnCrewEnabled(this);
2009-12-29 13:44:16 +00:00
return _inherited(...);
}
protected func OnCrewDisabled()
{
if (HUDcontroller)
HUDcontroller->OnCrewDisabled(this);
2009-12-29 13:44:16 +00:00
return _inherited(...);
}
2011-03-13 15:55:00 +00:00
// from ClonkControl.ocd
2009-12-29 13:44:16 +00:00
protected func OnSlotFull(int slot)
{
if (HUDcontroller)
HUDcontroller->OnSlotObjectChanged(slot);
return _inherited(slot, ...);
2009-12-29 13:44:16 +00:00
}
protected func OnSlotEmpty(int slot)
{
if (HUDcontroller)
HUDcontroller->OnSlotObjectChanged(slot);
return _inherited(slot, ...);
}
protected func OnHandSelectionChange(int old, int new, int handslot)
{
if (HUDcontroller)
HUDcontroller->OnHandSelectionChange(old, new, handslot);
return _inherited(old, new, handslot, ...);
}
// handled by GUI_Controller_ActionBars
func StartInteractionCheck(object clonk)
{
if (HUDcontroller)
return HUDcontroller->~StartInteractionCheck(clonk, ...);
}
// handled by GUI_Controller_ActionBars
func StopInteractionCheck()
{
if (HUDcontroller)
return HUDcontroller->~StopInteractionCheck(...);
}
protected func OnInventoryHotkeyPress(int slot)
{
if (HUDcontroller)
HUDcontroller->OnInventoryHotkeyPress(slot);
return _inherited(slot, ...);
}
protected func OnInventoryHotkeyRelease(int slot)
{
if (HUDcontroller)
HUDcontroller->OnInventoryHotkeyRelease(slot);
return _inherited(slot, ...);
}
// when something in the inventory changed
protected func OnInventoryChange()
{
if (HUDcontroller)
HUDcontroller->ScheduleUpdateInventory();
return _inherited(...);
}
// when a carryheavy object is picked up/dropped
2012-04-13 17:14:55 +00:00
protected func OnCarryHeavyChange(object carried)
{
if(HUDcontroller)
2012-04-13 17:14:55 +00:00
if(GetCursor(GetOwner()) == this)
HUDcontroller->OnCarryHeavyChange(carried);
return _inherited(carried, ...);
}
func Collection2()
{
if (HUDcontroller)
HUDcontroller->ScheduleUpdateInventory();
return _inherited(...);
}
func Ejection()
{
if (HUDcontroller)
HUDcontroller->ScheduleUpdateInventory();
return _inherited(...);
}
func ControlContents()
{
if (HUDcontroller)
HUDcontroller->ScheduleUpdateInventory();
return _inherited(...);
}