public void UpdateBuilderTasks(Unit sourceUnit, Builder builderComp) { if (sourceUnit == null || builderComp == null) { return; } int buildingID = -1; foreach (Building building in gameMgr.PlacementMgr.GetBuildings()) //go through all the placeable buildings { buildingID++; if (!builderComp.CanBuild(building)) //if the next building can't be constructed by the selected builders { continue; //move to then next one } TaskUI taskUI = Add(new TaskUIAttributes { ID = buildingID, icon = building.GetIcon(), source = sourceUnit, type = TaskTypes.placeBuilding }, building.GetTaskPanelCategory()); //if the building type has reached its faction limit then show it with the color red taskUI.GetComponent <Image>().color = sourceUnit.FactionMgr.HasReachedLimit(building.GetCode(), building.GetCategory()) ? Color.red : Color.white; } }
public void UpdateTaskLauncherTasks(FactionEntity sourceEntity, TaskLauncher taskLauncher) { if (taskLauncher == null || taskLauncher.Initiated == false || taskLauncher.GetTasksCount() == 0) //if the task launcher is invalid or the source can't manage a task { return; } for (int taskID = 0; taskID < taskLauncher.GetTasksCount(); taskID++) //go through all tasks { FactionEntityTask task = taskLauncher.GetTask(taskID); if (task.IsEnabled() == true) { TaskUI taskUI = Add(new TaskUIAttributes { ID = taskID, type = task.GetTaskType(), icon = task.GetIcon(), source = sourceEntity, taskLauncher = taskLauncher }, task.GetTaskPanelCategory()); if (task.GetTaskType() == TaskTypes.createUnit) //if this is a unit creation task, check if it has reached its limit and change task ui image color accordinly { taskUI.GetComponent <Image>().color = sourceEntity.FactionMgr.HasReachedLimit(task.UnitCode, task.UnitCategory) == true ? Color.red : Color.white; } } } UpdateInProgressTasks(taskLauncher); //show the in progress tasks }
public void UpdateMultipleAttackTasks(FactionEntity sourceEntity, MultipleAttackManager multipleAttackComp) { if (multipleAttackComp == null) { return; } for (int attackID = 0; attackID < multipleAttackComp.AttackEntities.Length; attackID++) //go through all the attack entities { AttackEntity attackComp = multipleAttackComp.AttackEntities[attackID]; if (!attackComp.IsLocked && !attackComp.IsActive()) //as long as the attack entity is not active and not locked, show a task to activate it: { TaskUI taskUI = Add(new TaskUIAttributes { ID = attackID, type = TaskTypes.attackTypeSelection, icon = attackComp.GetIcon(), source = sourceEntity }, multipleAttackComp.GetTaskPanelCategory()); if (attackComp.CoolDownActive == true) //if the attack type is in cool down mode { Color nextColor = taskUI.GetComponent <Image>().color; nextColor.a = 0.5f; //make it semi-transparent to indicate cooldown to player taskUI.GetComponent <Image>().color = nextColor; } } } }
public TaskUI Add(TaskUIAttributes attributes, int categoryIndex, TaskUI.Types type = TaskUI.Types.idle) { //if the task type is multiple selection, get the last element in the tasks list array, else get the task lists category index. TaskList currTaskList = (type == TaskUI.Types.multipleSelectionIndiv || type == TaskUI.Types.multipleSelectionMul) ? taskLists[taskLists.Length - 1] : ((type == TaskUI.Types.inProgress) ? taskLists[taskLists.Length - 2] : taskLists[categoryIndex]); TaskUI nextTask = (currTaskList.used < currTaskList.capacity) ? currTaskList.list[currTaskList.used] : null; if (nextTask == null) //if all tasks are used and none is available { nextTask = Object.Instantiate(taskUIPrefab.gameObject).GetComponent <TaskUI>(); //create and init new task UI nextTask.Init(gameMgr); nextTask.transform.SetParent(currTaskList.parent, true); //set its parent nextTask.transform.localScale = Vector3.one; currTaskList.list.Add(nextTask); //add a new task to the list currTaskList.capacity++; //increment capacity } currTaskList.used++; //increment amount of used tasks. nextTask.Reload(attributes, type); //initialize the task. return(nextTask); }