private void onLeftOffsetChanged(float val) { if (loaded()) { RouteShieldConfig.Instance().routeShieldDictionary[shieldKey].leftOffset = val; } }
private void onTextColorChanged(int sel) { if (loaded()) { RouteShieldConfig.Instance().routeShieldDictionary[shieldKey].textColor = sel == 1 ? Color.white : Color.black; } }
private void onTextSizeChanged(float val) { if (loaded()) { RouteShieldConfig.Instance().routeShieldDictionary[shieldKey].textScale = val; } }
private static bool loaded() { if (RouteShieldConfig.Instance().routeShieldDictionary == null) { UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel").SetMessage("Nope!", "You have to load a game first!", false); return(false); } return(true); }
private void onShieldSelected(int sel) { if (loaded()) { shieldKey = RouteShieldConfig.Instance().routeShieldDictionary.Keys.ToList()[sel]; shieldInfo = RouteShieldConfig.Instance().routeShieldDictionary[shieldKey]; int color = shieldInfo.textColor == Color.black ? 0 : 1; MarkARouteOptions.mLeftOffsetSlider.value = shieldInfo.leftOffset; MarkARouteOptions.mUpOffsetSlider.value = shieldInfo.upOffset; MarkARouteOptions.mTextSizeSlider.value = shieldInfo.textScale; MarkARouteOptions.mTextColor.selectedIndex = color; } }
public static void update() { if (loaded()) { bool hasOption = ModSettings.Instance().settings.Contains("loadMotorwaySigns"); MarkARouteOptions.shouldLoadDefaultSign.isChecked = hasOption ? (bool)ModSettings.Instance().settings["loadMotorwaySigns"] : true; shieldKey = RouteShieldConfig.Instance().routeShieldDictionary.Keys.ToList()[0]; shieldInfo = RouteShieldConfig.Instance().routeShieldDictionary[shieldKey]; int color = shieldInfo.textColor == Color.black ? 0 : 1; MarkARouteOptions.shieldSelector.items = RouteShieldConfig.Instance().routeShieldDictionary.Keys.ToArray(); MarkARouteOptions.mLeftOffsetSlider.value = shieldInfo.leftOffset; MarkARouteOptions.mUpOffsetSlider.value = shieldInfo.upOffset; MarkARouteOptions.mTextSizeSlider.value = shieldInfo.textScale; MarkARouteOptions.mTextColor.selectedIndex = color; } }
/// <summary> /// Loads all custom sprites /// </summary> private void LoadSprites() { bool spriteSuccess = true; //TODO: Replace with a loader function( JSON mapping available ) //We probably need this before we load any displays DynamicSignConfig.LoadVmsMsgList(); RouteShieldConfig.LoadRouteShieldInfo(); String[] files = Directory.GetFiles(FileUtils.GetModPath() + Path.DirectorySeparatorChar + "Icons"); foreach (string file in files) { string[] splitValues = file[0] == Path.DirectorySeparatorChar ? file.Substring(1).Split(Path.DirectorySeparatorChar) : file.Split(Path.DirectorySeparatorChar); string fileName = splitValues[splitValues.Length - 1]; string fileKey = fileName.Split('.')[0]; spriteSuccess = SpriteUtils.AddTexture(file, fileKey) && spriteSuccess; if (!RouteShieldConfig.Instance().routeShieldDictionary.ContainsKey(fileKey)) { RouteShieldConfig.Instance().routeShieldDictionary[fileKey] = new RouteShieldInfo(fileKey); } } //TODO: When we need it, load a json descriptor file for relevant shaders here ShaderUtils.AddShader("Shaders/font", "font"); //TODO: When we need it, load a json descriptor file for relevant fonts here FontUtils.AddFonts(); if (!spriteSuccess) { LoggerUtils.LogError("Failed to load some sprites!"); } else { RouteShieldConfig.SaveRouteShieldInfo(); } }
private void CreatePanelComponents() { m_routeLabel = this.AddUIComponent <UILabel>(); m_routeLabel.textScale = 1f; m_routeLabel.size = new Vector3(m_UIPadding.left, m_panelTitle.height + m_UIPadding.bottom); m_routeLabel.textColor = new Color32(180, 180, 180, 255); m_routeLabel.relativePosition = new Vector3(m_UIPadding.left, m_panelTitle.height + m_UIPadding.bottom); m_routeLabel.textAlignment = UIHorizontalAlignment.Left; m_routeLabel.text = "Route Name"; m_routeTypeDropdown = UIUtils.CreateDropDown(this, new Vector2(((this.width - m_UIPadding.left - 2 * m_UIPadding.right)), 25)); //TODO: Replace with Random namer values foreach (RouteShieldInfo info in RouteShieldConfig.Instance().routeShieldDictionary.Values) { m_routeTypeDropdown.AddItem(info.textureName); } m_routeTypeDropdown.selectedIndex = 0; m_routeTypeDropdown.relativePosition = new Vector3(m_UIPadding.left, m_routeLabel.relativePosition.y + m_routeLabel.height + m_UIPadding.bottom); m_routeStrField = UIUtils.CreateTextField(this); m_routeStrField.relativePosition = new Vector3(m_UIPadding.left, m_routeTypeDropdown.relativePosition.y + m_routeTypeDropdown.height + m_UIPadding.bottom); m_routeStrField.height = 25; m_routeStrField.width = (this.width - m_UIPadding.left - 2 * m_UIPadding.right); m_routeStrField.processMarkup = false; //Might re-implement this eventually (needs work to stop it screwing up with markup) m_routeStrField.textColor = Color.white; m_routeStrField.maxLength = 3; UIButton nameRoadButton = UIUtils.CreateButton(this); nameRoadButton.text = "Set"; nameRoadButton.size = new Vector2(60, 30); nameRoadButton.relativePosition = new Vector3(this.width - nameRoadButton.width - m_UIPadding.right, m_routeStrField.relativePosition.y + m_routeStrField.height + m_UIPadding.bottom); nameRoadButton.eventClicked += NameRoadButton_eventClicked; nameRoadButton.tooltip = "Create the label"; this.height = nameRoadButton.relativePosition.y + nameRoadButton.height + m_UIPadding.bottom; }
private void CreatePanelComponents() { m_routeLabel = this.AddUIComponent <UILabel>(); m_routeLabel.textScale = 1f; m_routeLabel.size = new Vector3(m_UIPadding.left, m_panelTitle.height + m_UIPadding.bottom); m_routeLabel.textColor = new Color32(180, 180, 180, 255); m_routeLabel.relativePosition = new Vector3(m_UIPadding.left, m_panelTitle.height + m_UIPadding.bottom); m_routeLabel.textAlignment = UIHorizontalAlignment.Left; m_routeLabel.text = "Route Name"; m_routeTypeDropdown = UIUtils.CreateDropDown(this, new Vector2(((this.width - m_UIPadding.left - 2 * m_UIPadding.right)), 25)); //TODO: Replace with Random namer values foreach (RouteShieldInfo info in RouteShieldConfig.Instance().routeShieldDictionary.Values) { m_routeTypeDropdown.AddItem(info.textureName); } m_routeTypeDropdown.selectedIndex = 0; m_routeTypeDropdown.relativePosition = new Vector3(m_UIPadding.left, m_routeLabel.relativePosition.y + m_routeLabel.height + m_UIPadding.bottom); m_routeStrField = UIUtils.CreateTextField(this); m_routeStrField.relativePosition = new Vector3(m_UIPadding.left, m_routeTypeDropdown.relativePosition.y + m_routeTypeDropdown.height + m_UIPadding.bottom); m_routeStrField.height = 25; m_routeStrField.width = (this.width - m_UIPadding.left - 2 * m_UIPadding.right); m_routeStrField.processMarkup = false; m_routeStrField.textColor = Color.white; m_routeStrField.maxLength = 3; m_destinationLabel = this.AddUIComponent <UILabel>(); m_destinationLabel.textScale = 1f; m_destinationLabel.size = new Vector3(m_UIPadding.left, m_panelTitle.height + m_UIPadding.bottom); m_destinationLabel.textColor = new Color32(180, 180, 180, 255); m_destinationLabel.relativePosition = new Vector3(m_UIPadding.left, m_routeStrField.relativePosition.y + m_routeStrField.height + m_UIPadding.bottom); m_destinationLabel.textAlignment = UIHorizontalAlignment.Left; m_destinationLabel.text = "Destination Name"; m_destinationField[0] = UIUtils.CreateTextField(this); m_destinationField[0].relativePosition = new Vector3(m_UIPadding.left, m_destinationLabel.relativePosition.y + m_destinationLabel.height + m_UIPadding.bottom); m_destinationField[0].height = 25; m_destinationField[0].width = (this.width - m_UIPadding.left - 2 * m_UIPadding.right); m_destinationField[0].processMarkup = false; m_destinationField[0].textColor = Color.white; m_destinationField[0].maxLength = 14; m_destinationField[1] = UIUtils.CreateTextField(this); m_destinationField[1].relativePosition = new Vector3(m_UIPadding.left, m_destinationField[0].relativePosition.y + m_destinationField[0].height + m_UIPadding.bottom); m_destinationField[1].height = 25; m_destinationField[1].width = (this.width - m_UIPadding.left - 2 * m_UIPadding.right); m_destinationField[1].processMarkup = false; m_destinationField[1].textColor = Color.white; m_destinationField[1].maxLength = 14; m_propTypeLabel = this.AddUIComponent <UILabel>(); m_propTypeLabel.textScale = 1f; m_propTypeLabel.size = new Vector3(m_UIPadding.left, m_panelTitle.height + m_UIPadding.bottom); m_propTypeLabel.textColor = new Color32(180, 180, 180, 255); m_propTypeLabel.relativePosition = new Vector3(m_UIPadding.left, m_destinationField[1].relativePosition.y + m_destinationField[1].height + m_UIPadding.bottom); m_propTypeLabel.textAlignment = UIHorizontalAlignment.Left; m_propTypeLabel.text = "Sign prop type"; m_propTypeDropDown = UIUtils.CreateDropDown(this, new Vector2(((this.width - m_UIPadding.left - 2 * m_UIPadding.right)), 25)); //TODO: Replace with Random namer values var keys = RenderingManager.instance.m_signPropDict.Keys; foreach (String signPropName in RenderingManager.instance.m_signPropDict.Keys.Where(key => SignPropConfig.signPropInfoDict.ContainsKey(key))) { m_propTypeDropDown.AddItem(signPropName); } m_propTypeDropDown.selectedIndex = 0; m_propTypeDropDown.relativePosition = new Vector3(m_UIPadding.left, m_propTypeLabel.relativePosition.y + m_propTypeLabel.height + m_UIPadding.bottom); UIButton nameRoadButton = UIUtils.CreateButton(this); nameRoadButton.text = "Set"; nameRoadButton.size = new Vector2(60, 30); nameRoadButton.relativePosition = new Vector3(this.width - nameRoadButton.width - m_UIPadding.right, m_propTypeDropDown.relativePosition.y + m_propTypeDropDown.height + m_UIPadding.bottom); nameRoadButton.eventClicked += NameRoadButton_eventClicked; nameRoadButton.tooltip = "Create the label"; this.height = nameRoadButton.relativePosition.y + nameRoadButton.height + m_UIPadding.bottom; }
/// <summary> /// Redraw the text to be drawn later with a mesh. Use sparingly, as /// this is an expensive task. /// </summary> private void RenderText() { DistrictManager districtManager = DistrictManager.instance; NetManager netManager = NetManager.instance; if (districtManager.m_properties.m_areaNameFont != null) { UIFontManager.Invalidate(districtManager.m_properties.m_areaNameFont); foreach (RouteContainer route in RouteManager.Instance().m_routeDict.Values) { if (route.m_segmentId != 0) { string routeStr = route.m_route; if (routeStr != null) { NetSegment netSegment = netManager.m_segments.m_buffer[route.m_segmentId]; NetSegment.Flags segmentFlags = netSegment.m_flags; if (segmentFlags.IsFlagSet(NetSegment.Flags.Created)) { //Load a route shield type ( generic motorway shield should be default value ) RouteShieldInfo shieldInfo = RouteShieldConfig.Instance().GetRouteShieldInfo(route.m_routePrefix); NetNode startNode = netManager.m_nodes.m_buffer[netSegment.m_startNode]; NetNode endNode = netManager.m_nodes.m_buffer[netSegment.m_endNode]; Vector3 startNodePosition = startNode.m_position; if (!SpriteUtils.m_textureStore.ContainsKey(shieldInfo.textureName)) { LoggerUtils.Log("WTF, No texture found for route shield" + shieldInfo.textureName); } Material mat = SpriteUtils.m_textureStore[shieldInfo.textureName]; route.m_shieldObject.GetComponent <Renderer>().material = mat; //TODO: Make mesh size dependent on text size route.m_shieldMesh.mesh = MeshUtils.CreateRectMesh(mat.mainTexture.width, mat.mainTexture.height); route.m_shieldMesh.transform.position = startNodePosition; route.m_shieldMesh.transform.LookAt(endNode.m_position, Vector3.up); route.m_shieldMesh.transform.Rotate(90f, 0f, 90f); //TODO: Bind the elevation of the mesh to the text z offset route.m_shieldMesh.transform.position += (Vector3.up * (0.5f)); route.m_shieldMesh.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); route.m_shieldObject.GetComponent <Renderer>().sortingOrder = 1000; route.m_numMesh.anchor = TextAnchor.MiddleCenter; route.m_numMesh.font = FontUtils.m_fontStore.ContainsKey("Highway Gothic") ? FontUtils.m_fontStore["Highway Gothic"] : districtManager.m_properties.m_areaNameFont.baseFont; route.m_numMesh.GetComponent <Renderer>().material = route.m_numMesh.font.material; if (ShaderUtils.m_shaderStore.ContainsKey("font")) { route.m_numMesh.GetComponent <Renderer>().material.shader = ShaderUtils.m_shaderStore["font"]; } else { route.m_numMesh.GetComponent <Renderer>().material.shader = ShaderUtils.m_shaderStore["fallback"]; } //TODO: Tie the font size to the font size option route.m_numMesh.fontSize = 50; route.m_numMesh.transform.position = startNode.m_position; route.m_numMesh.transform.parent = route.m_shieldObject.transform; route.m_numMesh.transform.LookAt(endNode.m_position, Vector3.up); route.m_numMesh.transform.Rotate(90f, 0f, 90f); route.m_numMesh.transform.position = route.m_shieldObject.GetComponent <Renderer>().bounds.center; //Just a hack, to make sure the text actually shows up above the shield route.m_numMesh.offsetZ = 0.001f; //TODO: Definitely get a map of the texture to the required text offsets route.m_numMesh.transform.localPosition += (Vector3.up * shieldInfo.upOffset); route.m_numMesh.transform.localPosition += (Vector3.left * shieldInfo.leftOffset); //TODO: Figure out a better ratio for route markers route.m_numMesh.transform.localScale = new Vector3(shieldInfo.textScale, shieldInfo.textScale, shieldInfo.textScale); route.m_numMesh.GetComponent <Renderer>().material.color = shieldInfo.textColor; route.m_numMesh.text = route.m_route.ToString(); } } } } foreach (SignContainer sign in RouteManager.Instance().m_signList) { Vector3 position = new Vector3(sign.x, sign.y, sign.z); string signPropType = (sign.m_exitNum == null || !m_signPropDict.ContainsKey(sign.m_exitNum)) ? "hwysign" : sign.m_exitNum; SignPropInfo signPropInfo = SignPropConfig.signPropInfoDict[signPropType]; int numSignProps = signPropInfo.isDoubleGantry ? 2 : 1; sign.m_sign.GetComponent <Renderer>().material = m_signPropDict[signPropType].m_material; //TODO: Make mesh size dependent on text size sign.m_sign.mesh = m_signPropDict[signPropType].m_mesh; sign.m_sign.transform.position = position; if (sign.m_routePrefix != null) { RouteShieldInfo shieldInfo = RouteShieldConfig.Instance().GetRouteShieldInfo(sign.m_routePrefix); Material mat = SpriteUtils.m_textureStore[shieldInfo.textureName]; sign.m_shieldObject.GetComponent <Renderer>().material = mat; //TODO: Make mesh size dependent on text size sign.m_shieldMesh.mesh = MeshUtils.CreateRectMesh(mat.mainTexture.width, mat.mainTexture.height); sign.m_shieldMesh.transform.position = position; //TODO: Bind the elevation of the mesh to the text z offset sign.m_shieldMesh.transform.position += (Vector3.up * (0.5f)); sign.m_shieldMesh.transform.localScale = signPropInfo.shieldScale; sign.m_shieldObject.GetComponent <Renderer>().sortingOrder = 1000; sign.m_numMesh.anchor = TextAnchor.MiddleCenter; sign.m_numMesh.font = FontUtils.m_fontStore.ContainsKey("Highway Gothic") ? FontUtils.m_fontStore["Highway Gothic"] : districtManager.m_properties.m_areaNameFont.baseFont; sign.m_numMesh.GetComponent <Renderer>().material = sign.m_numMesh.font.material; if (ShaderUtils.m_shaderStore.ContainsKey("font")) { sign.m_numMesh.GetComponent <Renderer>().material.shader = ShaderUtils.m_shaderStore["font"]; } else { sign.m_numMesh.GetComponent <Renderer>().material.shader = ShaderUtils.m_shaderStore["fallback"]; } //TODO: Tie the font size to the font size option sign.m_numMesh.fontSize = 50; sign.m_numMesh.transform.position = position; sign.m_numMesh.transform.parent = sign.m_shieldObject.transform; sign.m_numMesh.transform.position = sign.m_shieldObject.GetComponent <Renderer>().bounds.center; //Just a hack, to make sure the text actually shows up above the shield sign.m_numMesh.offsetZ = 0.01f; //TODO: Definitely get a map of the texture to the required text offsets ds sign.m_numMesh.transform.localPosition += (Vector3.up * shieldInfo.upOffset); sign.m_numMesh.transform.localPosition += (Vector3.left * shieldInfo.leftOffset); //TODO: Figure out a better ratio for route markers sign.m_numMesh.transform.localScale = new Vector3(shieldInfo.textScale, shieldInfo.textScale, shieldInfo.textScale); sign.m_numMesh.GetComponent <Renderer>().material.color = shieldInfo.textColor; sign.m_numMesh.text = sign.m_route.ToString(); sign.m_numMesh.TE sign.m_shieldMesh.transform.parent = sign.m_sign.transform; sign.m_shieldMesh.transform.localPosition = signPropInfo.shieldOffset; } string[] destinationStrings = sign.m_destination.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); for (int i = 0; i < numSignProps; i++) { sign.m_destinationMesh[i].anchor = TextAnchor.MiddleCenter; sign.m_destinationMesh[i].font = FontUtils.m_fontStore.ContainsKey(signPropInfo.fontType) ? FontUtils.m_fontStore[signPropInfo.fontType] : districtManager.m_properties.m_areaNameFont.baseFont; sign.m_destinationMesh[i].font.material.SetColor("Text Color", Color.white); if (ShaderUtils.m_shaderStore.ContainsKey("font")) { sign.m_destinationMesh[i].font.material.shader = ShaderUtils.m_shaderStore["font"]; } else { sign.m_destinationMesh[i].font.material.shader = ShaderUtils.m_shaderStore["fallback"]; } sign.m_destinationMesh[i].GetComponent <Renderer>().material = sign.m_destinationMesh[i].font.material; //TODO: Tie the font size to the font size option sign.m_destinationMesh[i].fontSize = 50; sign.m_destinationMesh[i].transform.position = position; sign.m_destinationMesh[i].transform.parent = sign.m_sign.transform; sign.m_destinationMesh[i].transform.position = position; //Just a hack, to make sure the text actually shows up above the shield sign.m_destinationMesh[i].offsetZ = 0.001f; //TODO: Definitely get a map of the texture to the required text offsets //TODO: Figure out a better ratio for route markers sign.m_destinationMesh[i].transform.localScale = signPropInfo.textScale; sign.m_destinationMesh[i].text = signPropInfo.isDoubleGantry ? destinationStrings[i] : sign.m_destination; sign.m_destinationMesh[i].transform.localPosition = sign.m_routePrefix == null ? signPropInfo.textOffsetNoSign[i] : signPropInfo.textOffsetSign[i]; } } foreach (DynamicSignContainer sign in RouteManager.Instance().m_dynamicSignList) { Vector3 position = new Vector3(sign.x, sign.y, sign.z); sign.m_sign.GetComponent <Renderer>().material = m_signPropDict["electronic_sign_gantry"].m_material; //TODO: Make mesh size dependent on text size sign.m_sign.mesh = m_signPropDict["electronic_sign_gantry"].m_mesh; sign.m_sign.transform.position = position; sign.m_messageTextMesh.anchor = TextAnchor.MiddleLeft; sign.m_messageTextMesh.font = FontUtils.m_fontStore.ContainsKey("Electronic Highway Sign") ? FontUtils.m_fontStore["Electronic Highway Sign"] : districtManager.m_properties.m_areaNameFont.baseFont; if (ShaderUtils.m_shaderStore.ContainsKey("font")) { sign.m_messageTextMesh.font.material.shader = ShaderUtils.m_shaderStore["font"]; } else { sign.m_numMesh.GetComponent <Renderer>().material.shader = ShaderUtils.m_shaderStore["fallback"]; } sign.m_messageTextMesh.color = (new Color(1, 0.77f, 0.56f, 1f)); sign.m_messageTextMesh.font.material.SetColor("Text Color", new Color(1, 0.77f, 0.56f, 1f)); sign.m_messageTextMesh.GetComponent <Renderer>().material = sign.m_messageTextMesh.font.material; //TODO: Tie the font size to the font size option sign.m_messageTextMesh.fontSize = 50; sign.m_messageTextMesh.transform.position = position; sign.m_messageTextMesh.transform.parent = sign.m_sign.transform; sign.m_messageTextMesh.transform.position = position; //Just a hack, to make sure the text actually shows up above the shield sign.m_messageTextMesh.offsetZ = 0.001f; //TODO: Definitely get a map of the texture to the required text odffsets //TODO: Figure out a better ratio for route markers sign.m_messageTextMesh.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f); String msgText = (sign.m_route == null ? "Traffic" : (sign.m_routePrefix + '-' + sign.m_route)) + " moving smoothly"; sign.m_messageTextMesh.text = msgText; sign.m_messageTextMesh.transform.localPosition = new Vector3(0.7f, 8.4f, -19.7f); } } }