private void DrawActions(string[] actions) { GUIStyle buttons = new GUIStyle(); buttons.hover.background = buttonHover; buttons.active.background = buttonClick; GUI.skin.button = buttons; int numActions = actions.Length; //define the area to draw the actions inside GUI.BeginGroup(new Rect(BUILD_IMAGE_WIDTH, 0, ORDERS_BAR_WIDTH, buildAreaHeight)); //draw scroll bar for the list of actions if need be if (numActions >= MaxNumRows(buildAreaHeight)) { DrawSlider(buildAreaHeight, numActions / 2.0f); } //display possible actions as buttons and handle the button click for each for (int i = 0; i < numActions; i++) { int column = i % 2; int row = i / 2; Rect pos = GetButtonPos(row, column); Texture2D action = GameResourceManager.GetBuildImage(actions[i]); if (action) { //create the button and handle the click of that button if (GUI.Button(pos, action)) { RTSAgent agent = Selector.MainSelectedAgent as RTSAgent; if (agent) { PlayClick(); if (agent.MyAgentType == AgentType.Unit && agent.GetAbility <Construct>() && !ConstructionHandler.IsFindingBuildingLocation()) { ConstructionHandler.CreateStructure(actions[i], agent, agent.GetPlayerArea()); } else if (agent.MyAgentType == AgentType.Building && !agent.GetAbility <Structure>().NeedsConstruction && agent.GetAbility <Spawner>()) { // send spawn command Command spawnCom = new Command(AbilityDataItem.FindInterfacer("Spawner").ListenInputID); spawnCom.Add <DefaultData>(new DefaultData(DataType.String, actions[i])); UserInputHelper.SendCommand(spawnCom); } } } } } GUI.EndGroup(); }
private void DrawOrdersBar() { if (Selector.MainSelectedAgent.GetAbility <Structure>() && Selector.MainSelectedAgent.GetAbility <Structure>().UnderConstruction()) { return; } GUI.skin = ordersSkin; GUI.BeginGroup(new Rect(Screen.width - ORDERS_BAR_WIDTH - BUILD_IMAGE_WIDTH, RESOURCE_BAR_HEIGHT, ORDERS_BAR_WIDTH + BUILD_IMAGE_WIDTH, Screen.height - RESOURCE_BAR_HEIGHT)); GUI.Box(new Rect(BUILD_IMAGE_WIDTH + SCROLL_BAR_WIDTH, 0, ORDERS_BAR_WIDTH, Screen.height - RESOURCE_BAR_HEIGHT), ""); string selectionName = ""; RTSAgent selectedAgent = Selector.MainSelectedAgent as RTSAgent; selectionName = selectedAgent.GetComponent <RTSAgent>().objectName; if (selectedAgent.IsOwnedBy(cachedCommander.CachedController)) { // reset slider value if the selected object has changed if (lastSelection && lastSelection != Selector.MainSelectedAgent) { sliderValue = 0.0f; } if (selectedAgent.MyAgentType == AgentType.Unit && selectedAgent.GetAbility <Construct>()) { DrawActions(selectedAgent.GetAbility <Construct>().GetBuildActions()); } else if (selectedAgent.MyAgentType == AgentType.Building && selectedAgent.GetAbility <Spawner>()) { DrawActions(selectedAgent.GetAbility <Spawner>().GetSpawnActions()); } // store the current selection lastSelection = selectedAgent; if (lastSelection.MyAgentType == AgentType.Building) { if (lastSelection.GetAbility <Spawner>()) { DrawBuildQueue(lastSelection.GetAbility <Spawner>().getBuildQueueValues(), lastSelection.GetAbility <Spawner>().getBuildPercentage()); } DrawStandardBuildingOptions(lastSelection as RTSAgent); } } if (!selectionName.Equals("")) { int leftPos = BUILD_IMAGE_WIDTH + SCROLL_BAR_WIDTH / 2; int topPos = buildAreaHeight + BUTTON_SPACING; GUI.Label(new Rect(leftPos, topPos, ORDERS_BAR_WIDTH, SELECTION_NAME_HEIGHT), selectionName); } GUI.EndGroup(); }
private void DrawStandardOptions(RTSAgent agent) { GUIStyle buttons = new GUIStyle(); buttons.hover.background = smallButtonHover; buttons.active.background = smallButtonClick; GUI.skin.button = buttons; int leftPos = BUILD_IMAGE_WIDTH + SCROLL_BAR_WIDTH + BUTTON_SPACING; int topPos = buildAreaHeight - BUILD_IMAGE_HEIGHT / 2; int width = BUILD_IMAGE_WIDTH / 2; int height = BUILD_IMAGE_HEIGHT / 2; if (cachedCommander.GetController().SelectedAgents.Count == 1 && GUI.Button(new Rect(leftPos, topPos, width, height), agent.destroyImage)) { PlayClick(); agent.Die(); } if (agent.GetAbility <Rally>() && agent.GetAbility <Rally>().hasSpawnPoint() && !agent.GetAbility <Structure>().NeedsConstruction) { leftPos += width + BUTTON_SPACING; if (GUI.Button(new Rect(leftPos, topPos, width, height), agent.GetAbility <Rally>().rallyPointImage)) { PlayClick(); if (activeCursorState != CursorState.RallyPoint) { agent.GetAbility <Rally>().SetFlagState(FlagState.SettingFlag); SetCursorState(CursorState.RallyPoint); SetCursorLock(true); } else { agent.GetAbility <Rally>().SetFlagState(FlagState.FlagSet); SetCursorLock(false); SetCursorState(CursorState.Select); } } } }
// move to build ability? public void StartConstruction() { findingPlacement = false; Vector2d buildPoint = new Vector2d(tempBuilding.transform.position.x, tempBuilding.transform.position.z); RTSAgent newBuilding = cachedCommander.CachedController.CreateAgent(tempBuilding.gameObject.name, buildPoint, Vector2d.right) as RTSAgent; Destroy(tempBuilding.gameObject); newBuilding.SetState(AnimState.Building); newBuilding.RestoreMaterials(); newBuilding.SetPlayingArea(tempCreator.GetPlayerArea()); newBuilding.GetAbility <Health>().HealthAmount = FixedMath.Create(0); newBuilding.SetCommander(); // send build command Command buildCom = new Command(AbilityDataItem.FindInterfacer("Construct").ListenInputID); buildCom.Add <DefaultData>(new DefaultData(DataType.UShort, newBuilding.GlobalID)); UserInputHelper.SendCommand(buildCom); newBuilding.GetAbility <Structure>().StartConstruction(); // check that the Player has the resources available before allowing them to create a new Unit / Building cachedCommander.RemoveResource(ResourceType.Gold, newBuilding.cost); }
private void LoadRTSAgents(JsonTextReader reader) { if (reader == null) { return; } RTSAgents agents = GetComponentInChildren <RTSAgents>(); string currValue = "", type = ""; while (reader.Read()) { if (reader.Value != null) { if (reader.TokenType == JsonToken.PropertyName) { currValue = (string)reader.Value; } else if (currValue == "Type") { type = (string)reader.Value; // need to create unit via commander controller... GameObject newObject = Instantiate(ResourceManager.GetAgentTemplate(type).gameObject); RTSAgent agent = newObject.GetComponent <RTSAgent>(); agent.name = agent.name.Replace("(Clone)", "").Trim(); agent.LoadDetails(reader); agent.transform.parent = agents.transform; agent.SetCommander(); agent.SetTeamColor(); if (agent.GetAbility <Structure>().UnderConstruction()) { agent.SetTransparentMaterial(CachedBuilderManager.allowedMaterial, true); } } } else if (reader.TokenType == JsonToken.EndArray) { return; } } }
private void DrawStandardBuildingOptions(RTSAgent building) { GUIStyle buttons = new GUIStyle(); buttons.hover.background = smallButtonHover; buttons.active.background = smallButtonClick; GUI.skin.button = buttons; int leftPos = BUILD_IMAGE_WIDTH + SCROLL_BAR_WIDTH + BUTTON_SPACING; int topPos = buildAreaHeight - BUILD_IMAGE_HEIGHT / 2; int width = BUILD_IMAGE_WIDTH / 2; int height = BUILD_IMAGE_HEIGHT / 2; if (GUI.Button(new Rect(leftPos, topPos, width, height), building.GetAbility <Structure>().sellImage)) { PlayClick(); building.GetAbility <Structure>().Sell(); } if (building.GetAbility <Spawner>() != null && building.GetAbility <Spawner>().hasSpawnPoint()) { leftPos += width + BUTTON_SPACING; if (GUI.Button(new Rect(leftPos, topPos, width, height), building.GetAbility <Spawner>().rallyPointImage)) { PlayClick(); if (activeCursorState != CursorState.RallyPoint && previousCursorState != CursorState.RallyPoint) { building.GetAbility <Spawner>().SetFlagState(FlagState.SettingFlag); SetCursorState(CursorState.RallyPoint); } else { // dirty hack to ensure toggle between RallyPoint and not works ... building.GetAbility <Spawner>().SetFlagState(FlagState.FlagSet); SetCursorState(CursorState.PanRight); SetCursorState(CursorState.Select); } } } }