private void Callback_AddSleeper(LockedSet <ulong> sleepers, ulong unitID) { GameObject elementButton = Instantiate(ElementButtonPrefab); Transform elementButtonTr = elementButton.transform; Transform selectUnitButton = elementButtonTr.Find(ElementButtonPrefab_ButtonName_SelectUnit); selectUnitButton.GetComponent <UnityEngine.UI.Button>().onClick.AddListener( () => { ContentUI.Instance.CreateUnitWindow(Target.TheMap.GetUnit(unitID)); }); selectUnitButton.GetComponentInChildren <UnityEngine.UI.Text>().text = Target.TheMap.GetUnit(unitID).DisplayName; elementButtonTr.Find(ElementButtonPrefab_ButtonName_StopSleeping) .GetComponent <UnityEngine.UI.Button>() .onClick.AddListener( () => { //End the sleeper's "Sleep" job. var sleepingUnit = UnityLogic.EtMGame.Instance.Map.GetUnit(unitID); ((GameLogic.Units.PlayerChar)sleepingUnit).StopDoingJob(null, true); }); elementButton.transform.SetParent(ContentParent, false); }
//Note: if you're confused about the web of callbacks here, // there is a flowchart in Billy's Dropbox called "Job Life Cycle.bmp". private void Callback_GroupRemoved(LockedSet <Group> groups, Group theGroup) { if (theGroup == Owner) { //Remove all outstanding jobs. while (outstandingJobs.Count > 0) { RemoveJob(outstandingJobs.First()); } Owner.TheMap.Groups.OnElementRemoved -= Callback_GroupRemoved; } }
private void Callback_NewUnit(LockedSet <ulong> ownerUnitIDs, ulong newUnitID) { Unit unit = Owner.TheMap.GetUnit(newUnitID); if (unit is PlayerChar) { PlayerChar playerChar = (PlayerChar)unit; playerChar.OnAddCustomJob += Callback_NewUnitJob; playerChar.OnRemoveCustomJob += Callback_DestroyUnitJob; //Call the "Job created" callbacks for every job this PlayerChar already has. foreach (Job job in playerChar.CustomJobs) { Callback_NewUnitJob(playerChar, job); } if (playerChar.CurrentJob != null) { Callback_NewUnitJob(playerChar, playerChar.CurrentJob); } } }
private void Callback_NewGroup(LockedSet <GameLogic.Group> groups, GameLogic.Group newGroup) { if (newGroup is GameLogic.Groups.PlayerGroup) { var pGroup = (GameLogic.Groups.PlayerGroup)newGroup; pGroup.JobQueries.OnJobCreated += Callback_NewJob; //Call the "New Job" callback on any existing jobs. foreach (var job in pGroup.NormalJobs.Concat(pGroup.EmergencyJobs)) { Callback_NewJob(pGroup, job); } //If the map is in the middle of loading, we have to defer this part. Game.DoAfterMapLoaded(() => { foreach (ulong unitID in pGroup.UnitsByID) { var unit = Game.Map.GetUnit(unitID); if (unit is GameLogic.Units.PlayerChar) { var pChar = (GameLogic.Units.PlayerChar)unit; foreach (var job in pChar.CustomJobs) { Callback_NewJob(pGroup, job); } if (pChar.CurrentJob != null) { Callback_NewJob(pGroup, pChar.CurrentJob); } } } }); } }
private void Callback_RemoveUnit(LockedSet <ulong> ownerUnitIDs, ulong removedUnitID) { Unit unit = Owner.TheMap.GetUnit(removedUnitID); if (unit is PlayerChar) { PlayerChar playerChar = (PlayerChar)unit; //Raise "Callback_DestroyUnitJob" for all outstanding jobs, // then remove all callbacks. foreach (Job job in playerChar.CustomJobs) { Callback_DestroyUnitJob(playerChar, job); } if (playerChar.CurrentJob != null) { Callback_DestroyUnitJob(playerChar, playerChar.CurrentJob); } playerChar.OnAddCustomJob -= Callback_NewUnitJob; playerChar.OnRemoveCustomJob -= Callback_DestroyUnitJob; } }
private void Callback_RemoveSleeper(LockedSet <ulong> sleepers, ulong unitID) { Destroy(idToContent[unitID]); idToContent.Remove(unitID); }