2011-09-28 17:55:01 +00:00
|
|
|
/**
|
2009-12-29 13:44:16 +00:00
|
|
|
HUD Adapter
|
2011-09-28 17:55:01 +00:00
|
|
|
|
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
|
2016-11-26 17:57:31 +00:00
|
|
|
_inherited(...); if they overload one of the callbacks used here.
|
2009-12-29 13:44:16 +00:00
|
|
|
|
2011-09-28 17:55:01 +00:00
|
|
|
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.
|
2011-09-28 17:55:01 +00:00
|
|
|
|
|
|
|
@authors Newton
|
2009-12-29 13:44:16 +00:00
|
|
|
*/
|
|
|
|
|
2015-06-06 13:40:17 +00:00
|
|
|
local HUDcontroller;
|
2009-12-29 13:44:16 +00:00
|
|
|
|
2015-06-06 13:40:17 +00:00
|
|
|
public func IsHUDAdapter()
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-30 08:11:43 +00:00
|
|
|
// Either returns the current HUD controller or creates one.
|
|
|
|
// But only if owner is a human otherwise returns nil.
|
|
|
|
private func GetHUDController()
|
|
|
|
{
|
|
|
|
var plr = GetOwner();
|
2017-11-05 12:24:47 +00:00
|
|
|
// During runtime join, plr isn't a valid player in the joining client yet
|
|
|
|
// when this function is called from OnSynchronized(). This code previously
|
|
|
|
// checked player validity before returning a cached HUD object which would
|
|
|
|
// cause a desync.
|
2015-09-30 08:11:43 +00:00
|
|
|
if (HUDcontroller) return HUDcontroller;
|
2017-11-05 12:24:47 +00:00
|
|
|
if (GetPlayerType(plr) != C4PT_User) return nil;
|
2016-11-22 05:55:47 +00:00
|
|
|
var controllerDef = Library_HUDController->GetGUIControllerID();
|
|
|
|
HUDcontroller = FindObject(Find_ID(controllerDef), Find_Owner(plr));
|
2015-09-30 08:11:43 +00:00
|
|
|
if (!HUDcontroller)
|
2016-11-22 05:55:47 +00:00
|
|
|
HUDcontroller = CreateObject(controllerDef, AbsX(0), AbsY(0), plr);
|
2015-09-30 08:11:43 +00:00
|
|
|
return HUDcontroller;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update HUD controller e.g. when it was reinitialized
|
|
|
|
public func SetHUDController(object new_controller)
|
|
|
|
{
|
|
|
|
HUDcontroller = new_controller;
|
|
|
|
return true;
|
|
|
|
}
|
2009-12-29 13:44:16 +00:00
|
|
|
|
2015-06-06 13:40:17 +00:00
|
|
|
/*-- Engine callbacks --*/
|
2009-12-29 13:44:16 +00:00
|
|
|
|
2015-06-06 13:40:17 +00:00
|
|
|
// Bootstrap the HUD on the recruitement of a crew member.
|
2015-09-30 08:11:43 +00:00
|
|
|
private func Recruitment(int plr)
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
2015-09-30 08:11:43 +00:00
|
|
|
if (GetHUDController())
|
2015-09-10 22:10:23 +00:00
|
|
|
{
|
|
|
|
HUDcontroller->~OnCrewRecruitment(this, plr, ...);
|
|
|
|
HUDcontroller->~ScheduleUpdateInventory();
|
|
|
|
}
|
2010-09-13 15:27:48 +00:00
|
|
|
return _inherited(plr, ...);
|
2009-12-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2015-09-10 22:10:23 +00:00
|
|
|
// On savegame load or after section change, ensure that there's a HUD adapter
|
|
|
|
public func OnSynchronized(...)
|
2015-09-09 03:18:53 +00:00
|
|
|
{
|
2015-09-30 08:11:43 +00:00
|
|
|
if (GetHUDController())
|
2015-09-10 22:10:23 +00:00
|
|
|
HUDcontroller->~ScheduleUpdateInventory();
|
|
|
|
return _inherited(...);
|
|
|
|
}
|
|
|
|
|
2015-09-30 08:11:43 +00:00
|
|
|
private func DeRecruitment(int plr)
|
2015-09-10 22:10:23 +00:00
|
|
|
{
|
2015-09-30 08:11:43 +00:00
|
|
|
if (HUDcontroller)
|
2015-06-06 13:40:17 +00:00
|
|
|
HUDcontroller->~OnCrewDeRecruitment(this, plr, ...);
|
2014-01-04 13:21:44 +00:00
|
|
|
return _inherited(plr, ...);
|
|
|
|
}
|
|
|
|
|
2015-09-30 08:11:43 +00:00
|
|
|
private func Death(int killed_by)
|
2014-01-04 13:21:44 +00:00
|
|
|
{
|
2015-09-30 08:11:43 +00:00
|
|
|
if (HUDcontroller)
|
2015-06-06 13:40:17 +00:00
|
|
|
HUDcontroller->~OnCrewDeath(this, killed_by, ...);
|
|
|
|
return _inherited(killed_by, ...);
|
2014-01-04 13:21:44 +00:00
|
|
|
}
|
|
|
|
|
2015-09-30 08:11:43 +00:00
|
|
|
private func Destruction()
|
2014-01-04 13:21:44 +00:00
|
|
|
{
|
2015-09-30 08:11:43 +00:00
|
|
|
if (HUDcontroller)
|
2015-06-06 13:40:17 +00:00
|
|
|
HUDcontroller->~OnCrewDestruction(this, ...);
|
2014-01-04 13:21:44 +00:00
|
|
|
return _inherited(...);
|
|
|
|
}
|
|
|
|
|
2015-06-06 13:40:17 +00:00
|
|
|
public func ControlHotkey(int hotindex)
|
|
|
|
{
|
|
|
|
if (HUDcontroller)
|
|
|
|
return HUDcontroller->~ControlHotkey(hotindex);
|
|
|
|
}
|
|
|
|
|
2015-09-30 08:11:43 +00:00
|
|
|
private func OnPromotion()
|
2011-09-28 17:55:01 +00:00
|
|
|
{
|
2015-06-06 13:40:17 +00:00
|
|
|
if (HUDcontroller)
|
|
|
|
HUDcontroller->~OnCrewRankChange(this);
|
2011-09-28 17:55:01 +00:00
|
|
|
return _inherited(...);
|
|
|
|
}
|
|
|
|
|
2015-09-30 08:11:43 +00:00
|
|
|
private func OnEnergyChange(int change, int cause, int caused_by)
|
2011-09-28 17:55:01 +00:00
|
|
|
{
|
2015-06-06 13:40:17 +00:00
|
|
|
if (HUDcontroller)
|
2015-09-30 08:11:43 +00:00
|
|
|
HUDcontroller->~OnCrewHealthChange(this, change, cause, caused_by);
|
2016-11-26 16:56:41 +00:00
|
|
|
return _inherited(change, cause, caused_by, ...);
|
2011-09-28 17:55:01 +00:00
|
|
|
|
|
|
|
}
|
2015-09-30 08:11:43 +00:00
|
|
|
private func OnBreathChange(int change)
|
2015-06-06 13:40:17 +00:00
|
|
|
{
|
|
|
|
if (HUDcontroller)
|
2015-09-30 08:11:43 +00:00
|
|
|
HUDcontroller->~OnCrewBreathChange(this, change);
|
2011-09-28 17:55:01 +00:00
|
|
|
return _inherited(...);
|
|
|
|
}
|
|
|
|
|
2015-09-30 08:20:20 +00:00
|
|
|
private func OnMagicEnergyChange(int change)
|
|
|
|
{
|
|
|
|
if (HUDcontroller)
|
|
|
|
HUDcontroller->~OnCrewMagicChange(this, change);
|
|
|
|
return _inherited(...);
|
|
|
|
}
|
|
|
|
|
2015-09-30 08:11:43 +00:00
|
|
|
private func OnNameChanged()
|
2011-09-28 17:55:01 +00:00
|
|
|
{
|
2015-06-06 13:40:17 +00:00
|
|
|
if (HUDcontroller)
|
|
|
|
HUDcontroller->~OnCrewNameChange(this);
|
2011-09-28 17:55:01 +00:00
|
|
|
return _inherited(...);
|
|
|
|
}
|
2009-12-29 13:44:16 +00:00
|
|
|
|
2015-09-30 08:11:43 +00:00
|
|
|
private func OnPhysicalChange(string physical, int change)
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
2015-06-06 13:40:17 +00:00
|
|
|
if (HUDcontroller)
|
|
|
|
{
|
2010-05-04 16:10:42 +00:00
|
|
|
if (!physical)
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
2015-09-30 08:11:43 +00:00
|
|
|
HUDcontroller->~OnCrewHealthChange(this, change);
|
|
|
|
HUDcontroller->~OnCrewBreathChange(this, change);
|
2009-12-29 13:44:16 +00:00
|
|
|
}
|
2015-09-30 08:11:43 +00:00
|
|
|
else if (physical == "Energy") HUDcontroller->~OnCrewHealthChange(this, change);
|
|
|
|
else if (physical == "Breath") HUDcontroller->~OnCrewBreathChange(this, change);
|
2009-12-29 13:44:16 +00:00
|
|
|
}
|
2010-12-10 00:06:38 +00:00
|
|
|
return _inherited(physical, change, ...);
|
2009-12-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2015-09-30 08:11:43 +00:00
|
|
|
private func CrewSelection(bool unselect)
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
2010-09-13 15:27:48 +00:00
|
|
|
if (HUDcontroller)
|
2015-06-06 13:40:17 +00:00
|
|
|
HUDcontroller->~OnCrewSelection(this, unselect);
|
2010-09-13 15:27:48 +00:00
|
|
|
return _inherited(unselect, ...);
|
2009-12-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2015-09-30 08:11:43 +00:00
|
|
|
private func OnCrewEnabled()
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
2010-09-13 15:27:48 +00:00
|
|
|
if (HUDcontroller)
|
2015-06-06 13:40:17 +00:00
|
|
|
HUDcontroller->~OnCrewEnabled(this);
|
2009-12-29 13:44:16 +00:00
|
|
|
return _inherited(...);
|
|
|
|
}
|
|
|
|
|
2015-09-30 08:11:43 +00:00
|
|
|
private func OnCrewDisabled()
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
2010-09-13 15:27:48 +00:00
|
|
|
if (HUDcontroller)
|
2015-06-06 13:40:17 +00:00
|
|
|
HUDcontroller->~OnCrewDisabled(this);
|
2009-12-29 13:44:16 +00:00
|
|
|
return _inherited(...);
|
|
|
|
}
|
|
|
|
|
2011-03-13 15:55:00 +00:00
|
|
|
// from ClonkControl.ocd
|
2015-09-30 08:11:43 +00:00
|
|
|
private func OnSlotFull(int slot)
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
2010-05-04 16:10:42 +00:00
|
|
|
if (HUDcontroller)
|
2015-06-06 13:40:17 +00:00
|
|
|
HUDcontroller->~OnSlotObjectChanged(slot);
|
2010-05-04 16:10:42 +00:00
|
|
|
return _inherited(slot, ...);
|
2009-12-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2015-09-30 08:11:43 +00:00
|
|
|
private func OnSlotEmpty(int slot)
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
2010-05-04 16:10:42 +00:00
|
|
|
if (HUDcontroller)
|
2015-06-06 13:40:17 +00:00
|
|
|
HUDcontroller->~OnSlotObjectChanged(slot);
|
2010-05-04 16:10:42 +00:00
|
|
|
return _inherited(slot, ...);
|
|
|
|
}
|
2011-09-18 17:15:31 +00:00
|
|
|
|
2013-05-26 01:24:46 +00:00
|
|
|
// 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(...);
|
|
|
|
}
|
|
|
|
|
2015-09-30 08:11:43 +00:00
|
|
|
private func OnInventoryHotkeyPress(int slot)
|
2012-02-26 15:19:52 +00:00
|
|
|
{
|
|
|
|
if (HUDcontroller)
|
2015-06-06 13:40:17 +00:00
|
|
|
HUDcontroller->~OnInventoryHotkeyPress(slot);
|
2012-02-26 15:19:52 +00:00
|
|
|
return _inherited(slot, ...);
|
|
|
|
}
|
|
|
|
|
2015-09-30 08:11:43 +00:00
|
|
|
private func OnInventoryHotkeyRelease(int slot)
|
2012-02-26 15:19:52 +00:00
|
|
|
{
|
|
|
|
if (HUDcontroller)
|
2015-06-06 13:40:17 +00:00
|
|
|
HUDcontroller->~OnInventoryHotkeyRelease(slot);
|
2012-02-26 15:19:52 +00:00
|
|
|
return _inherited(slot, ...);
|
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:34 +00:00
|
|
|
// when something in the inventory changed
|
2015-09-30 08:11:43 +00:00
|
|
|
private func OnInventoryChange()
|
2012-02-26 00:48:58 +00:00
|
|
|
{
|
|
|
|
if (HUDcontroller)
|
2015-06-06 13:40:17 +00:00
|
|
|
HUDcontroller->~ScheduleUpdateInventory();
|
2012-03-21 20:55:34 +00:00
|
|
|
return _inherited(...);
|
2012-02-26 00:48:58 +00:00
|
|
|
}
|
|
|
|
|
2015-06-06 13:40:17 +00:00
|
|
|
public func Collection2()
|
2011-09-18 17:15:31 +00:00
|
|
|
{
|
2011-09-18 20:03:08 +00:00
|
|
|
if (HUDcontroller)
|
2015-06-06 13:40:17 +00:00
|
|
|
HUDcontroller->~ScheduleUpdateInventory();
|
2011-09-18 17:15:31 +00:00
|
|
|
return _inherited(...);
|
|
|
|
}
|
|
|
|
|
2015-06-06 13:40:17 +00:00
|
|
|
public func Ejection()
|
2011-09-18 17:15:31 +00:00
|
|
|
{
|
2011-09-18 20:03:08 +00:00
|
|
|
if (HUDcontroller)
|
2015-06-06 13:40:17 +00:00
|
|
|
HUDcontroller->~ScheduleUpdateInventory();
|
2011-09-18 17:15:31 +00:00
|
|
|
return _inherited(...);
|
|
|
|
}
|
|
|
|
|
2015-06-06 13:40:17 +00:00
|
|
|
public func ControlContents()
|
2011-09-18 17:15:31 +00:00
|
|
|
{
|
2011-09-18 20:03:08 +00:00
|
|
|
if (HUDcontroller)
|
2015-06-06 13:40:17 +00:00
|
|
|
HUDcontroller->~ScheduleUpdateInventory();
|
2011-09-18 17:15:31 +00:00
|
|
|
return _inherited(...);
|
2017-11-05 12:24:47 +00:00
|
|
|
}
|