private void ResetState() { if (grid.grid.ContainsKey(lastChunkPointing)) { grid.grid[lastChunkPointing].SetBatchVisible(true); } if (lastPointedTile != null) { if (lastPointedTile.terrain) { lastPointedTile.terrain.SetActive(true); } if (lastPointedTile.building) { lastPointedTile.building.SetActive(true); } if (lastPointedTile.decoration) { lastPointedTile.decoration.SetActive(true); } } brush = null; targetLayer = null; lastIcon = null; lastPointedTile = null; lastChunkPointing = new Vector2Int(int.MinValue, int.MinValue); preview.SetActive(false); constructionUI.ResetState(); constructionUI.rotationTip.text = "press " + rotationLeft.ToString() + " or " + rotationRight.ToString() + " to rotate"; constructionUI.rotationTip.gameObject.SetActive(false); }
public void OnIconPointerEnter(ConstructionIcon icon) { if (hoveredIcon != icon && hoveredIcon && hoveredIcon != selectedIcon && hoveredIcon != layerIcon) { hoveredIcon.border.color = hoveredColorCache; } if (icon != selectedIcon && icon != layerIcon) { hoveredIcon = icon; if (hoveredIcon) { hoveredColorCache = hoveredIcon.border.color; hoveredIcon.border.color = hoveredBorderColor; } } description.text = icon.description; ConstructionLayer layer = icon.gameObject.GetComponent <ConstructionLayer>(); if (!layer) { cost.text = (icon.cost.Count == 0) ? "Free" : "Cost :"; LoadCost(icon); } }
public void ResetState() { description.text = ""; cost.text = ""; foreach (ResourceIcon res in resourceIconList) { res.gameObject.SetActive(false); } foreach (ConstructionIcon ico in icons) { ico.gameObject.SetActive(false); } if (layerIcon) { layerIcon.border.color = selectedLayerColorCache; } if (selectedIcon) { selectedIcon.border.color = selectedLayerColorCache; } hoveredIcon = null; selectedIcon = null; layerIcon = null; selectedLayer = null; iconsContainer.sizeDelta = new Vector2(iconsContainer.sizeDelta.x, 122); }
private void LoadLayerIcons(ConstructionLayer layer) { if (layer.elements.Count > icons.Count) { Debug.LogWarning("Not enough prefab in ConstructionUIJuicer to assign all elements of layer " + layer.layerType.ToString()); } float s = 0; for (int i = 0; i < icons.Count; i++) { if (i < layer.elements.Count) { ConstructionData data = layer.elements[i]; icons[i].gameObject.SetActive(true); icons[i].gameObject.name = data.name; icons[i].image.sprite = data.icon; icons[i].option.sprite = data.optionalIcon; icons[i].description = data.description; icons[i].nok.enabled = false; icons[i].option.enabled = data.optionalIcon != null; icons[i].cost = data.GetTotalCost(); icons[i].data = data; if (icons[i].cost.Count == 0) { cost.text = "Free"; } else { cost.text = "Cost :"; } s += 0.2f; } else { icons[i].gameObject.SetActive(false); } } iconsContainer.sizeDelta = new Vector2(iconsContainer.sizeDelta.x, Mathf.Max((int)s, 1) * 122); }
private void ModeUpdate() { // mode update if (activated && ((Input.GetKeyDown(KeyCode.Escape) && brush == null) || Input.GetKeyDown(keyMode))) { activated = false; } else if (!activated && Input.GetKeyDown(keyMode)) { activated = true; } if (lastActivated != activated) { if (activated) { ForgeUI.instance.gameObject.SetActive(false); } else { constructionUI.helpVideo.SetActive(false); } tpsController.activated = !activated; rtsController.activated = activated; constructionUI.ResetState(); constructionUI.gameObject.SetActive(activated); RenderSettings.fog = !activated; ResetState(); } lastActivated = activated; gridRenderer.enabled = activated; if (activated && Input.GetKeyDown(KeyCode.Escape) && brush != null) { brush = null; targetLayer = null; lastIcon = null; preview.SetActive(false); constructionUI.rotationTip.gameObject.SetActive(false); constructionUI.UnselectBrush(); } }
public static List <ConstructionLayer> ConstructionLayers(this TBD.Construction construction) { List <ConstructionLayer> result = new List <ConstructionLayer>(); int index = 1; TBD.material material = construction.materials(index); while (material != null) { ConstructionLayer constructionLayer = new ConstructionLayer(material.name, construction.materialWidth[index]); result.Add(constructionLayer); index++; material = construction.materials(index); } return(result); }
public void OnIconClick(ConstructionIcon icon) { if (icon != selectedIcon && icon != layerIcon) { if (hoveredIcon != icon && hoveredIcon && hoveredIcon != layerIcon) { hoveredIcon.border.color = hoveredColorCache; } if (selectedIcon && selectedIcon != layerIcon) { selectedIcon.border.color = selectedColorCache; } if (icon) { selectedColorCache = hoveredColorCache; ConstructionLayer layer = icon.gameObject.GetComponent <ConstructionLayer>(); if (layer) { if (layerIcon && layer != selectedLayer) { layerIcon.border.color = selectedLayerColorCache; } selectedLayerColorCache = selectedColorCache; layerIcon = icon; selectedLayer = layer; LoadLayerIcons(layer); } icon.border.color = selectedBorderColor; } } hoveredIcon = icon; selectedIcon = icon; }
private void LoadBrush(ConstructionIcon icon) { if (targetLayer && targetLayer != constructionUI.selectedLayer && targetLayer.layerType == ConstructionLayer.LayerType.Terrain) { if (lastPointedTile != null && lastPointedTile.terrain) { lastPointedTile.terrain.SetActive(true); } } targetLayer = constructionUI.selectedLayer; if (icon != constructionUI.layerIcon) { brush = icon; preview.SetActive(true); previewMeshFilter.sharedMesh = brush.data.preview; foreach (MeshFilter mf in multiPreviewFilters) { mf.sharedMesh = brush.data.preview; } previewArrow.transform.localEulerAngles = new Vector3(0, 0, 0); // preview preview.transform.localEulerAngles = brush.data.previewEulerOffset; if (brush.name.Contains("RegularTree")) { preview.transform.localScale = 2f * Vector3.one; } else { preview.transform.localScale = Vector3.one; } // preview arrows if (brush.name.Contains("Tower")) { previewArrow.transform.localEulerAngles = new Vector3(0, 0, -90); } else if (brush.name.Contains("Granary") || brush.name.Contains("Windmill")) { previewArrow.transform.localEulerAngles = new Vector3(0, 0, -90); } if (targetLayer.layerType != ConstructionLayer.LayerType.Building || brush.name.Contains("Fence") || brush.name.Contains("Wall")) { previewArrow.SetActive(false); } else { previewArrow.SetActive(true); } } else if (targetLayer.layerType == ConstructionLayer.LayerType.Delete) { preview.SetActive(true); previewArrow.SetActive(false); previewMeshFilter.sharedMesh = deletionMesh; preview.transform.localEulerAngles = new Vector3(0, 0, 0); preview.transform.localScale = Vector3.one; currentPreviewMaterial.color = previewInvalid; brush = null; } else { brush = null; preview.SetActive(false); previewArrow.SetActive(false); } constructionUI.rotationTip.gameObject.SetActive(previewArrow.activeSelf); }
public static bool UpdateConstruction(this TBD.Construction construction_TBD, IEnumerable <ConstructionLayer> constructionLayers, MaterialLibrary materialLibrary) { List <ConstructionLayer> constructionLayers_TBD = construction_TBD.ConstructionLayers(); if (constructionLayers_TBD == null && constructionLayers == null) { return(false); } bool update = true; if (constructionLayers_TBD != null && constructionLayers != null && constructionLayers_TBD.Count == constructionLayers.Count()) { update = false; for (int i = 0; i < constructionLayers.Count(); i++) { if (!constructionLayers.ElementAt(i).Name.Equals(constructionLayers_TBD[i].Name) || !Core.Query.AlmostEqual(constructionLayers.ElementAt(i).Thickness, constructionLayers_TBD[i].Thickness)) { update = true; break; } } } if (update) { construction_TBD.RemoveMaterials(); if (constructionLayers != null) { for (int i = 0; i < constructionLayers.Count(); i++) { ConstructionLayer constructionLayer = constructionLayers.ElementAt(i); string name = constructionLayer.Name; if (string.IsNullOrWhiteSpace(name)) { continue; } TBD.material material_TBD = construction_TBD.AddMaterial(); material_TBD.name = name; float thickness = System.Convert.ToSingle(constructionLayer.Thickness); IMaterial material = constructionLayer.Material(materialLibrary); if (material != null) { material_TBD.UpdateMaterial(material); if (material is TransparentMaterial) { material_TBD.width = thickness; } } construction_TBD.materialWidth[i + 1] = thickness; } } } return(update); }