public void Start() { try { comp = RasterPropMonitorComputer.Instantiate(internalProp); textObjTransform = internalProp.FindModelTransform(labelTransform); textObj = InternalComponents.Instance.CreateText(fontName, fontSize, textObjTransform, string.Empty); activeLabel = 0; SmarterButton.CreateButton(internalProp, switchTransform, Click); ConfigNode moduleConfig = null; foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("PROP")) { if (node.GetValue("name") == internalProp.propName) { moduleConfig = node.GetNodes("MODULE")[moduleID]; ConfigNode[] variableNodes = moduleConfig.GetNodes("VARIABLESET"); for (int i = 0; i < variableNodes.Length; i++) { try { labelsEx.Add(new VariableLabelSet(variableNodes[i])); } catch (ArgumentException e) { JUtil.LogMessage(this, "Error in building prop number {1} - {0}", e.Message, internalProp.propID); } } break; } } // Fallback: If there are no VARIABLESET blocks, we treat the module configuration itself as a variableset block. if (labelsEx.Count < 1 && moduleConfig != null) { try { labelsEx.Add(new VariableLabelSet(moduleConfig)); } catch (ArgumentException e) { JUtil.LogMessage(this, "Error in building prop number {1} - {0}", e.Message, internalProp.propID); } } if (labelsEx.Count == 0) { JUtil.LogMessage(this, "No labels defined."); throw new ArgumentException("No labels defined"); } colorShiftRenderer = internalProp.FindModelComponent<Renderer>(coloredObject); if (labelsEx[activeLabel].hasColor) { colorShiftRenderer.material.SetColor(colorName, labelsEx[activeLabel].color); } if (labelsEx[activeLabel].hasText) { textObj.text.Text = StringProcessor.ProcessString(labelsEx[activeLabel].labelText, comp); } audioOutput = JUtil.SetupIVASound(internalProp, switchSound, switchSoundVolume, false); JUtil.LogMessage(this, "Configuration complete in prop {1}, supporting {0} variable indicators.", labelsEx.Count, internalProp.propID); } catch { JUtil.AnnoyUser(this); enabled = false; throw; } }
public void Start() { comp = RasterPropMonitorComputer.Instantiate(internalProp); textObjTransform = internalProp.FindModelTransform(transformName); textObj = InternalComponents.Instance.CreateText(fontName, fontSize, textObjTransform, string.Empty); // Force oneshot if there's no variables: oneshot |= !labelText.Contains("$&$"); sourceString = labelText.UnMangleConfigText(); }
protected override void Layout() { base.Layout(); float margin = (Height - InternalText.BaseLine()) / 2; InternalText.X = PixelScene.Align(PixelScene.uiCamera, X + margin); InternalText.Y = PixelScene.Align(PixelScene.uiCamera, Y + margin); InternalIcon.X = PixelScene.Align(PixelScene.uiCamera, X + Width - margin - InternalIcon.Width); InternalIcon.Y = PixelScene.Align(PixelScene.uiCamera, Y + (Height - InternalIcon.Height) / 2); }
public void Start() { textObjTransform = internalProp.FindModelTransform(transformName); textObj = InternalComponents.Instance.CreateText(fontName, fontSize, textObjTransform, string.Empty); // Force oneshot if there's no variables: oneshot |= !labelText.Contains("$&$"); sourceString = labelText.UnMangleConfigText(); if (!oneshot) { RPMVesselComputer comp = RPMVesselComputer.Instance(vessel); comp.UpdateDataRefreshRate(refreshRate); } }
public void Start() { if (HighLogic.LoadedSceneIsEditor) { return; } try { rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true); Transform textObjTransform = internalProp.FindModelTransform(transformName); textObj = InternalComponents.Instance.CreateText("Arial", fontSize * 15.5f, textObjTransform, "", Color.green, false, "TopLeft"); // Force oneshot if there's no variables: oneshot |= !labelText.Contains("$&$"); string sourceString = labelText.UnMangleConfigText(); if (!string.IsNullOrEmpty(sourceString) && sourceString.Length > 1) { // Alow a " character to escape leading whitespace if (sourceString[0] == '"') { sourceString = sourceString.Substring(1); } } spf = new StringProcessorFormatter(sourceString, rpmComp); if (!oneshot) { rpmComp.UpdateDataRefreshRate(refreshRate); } if (!(string.IsNullOrEmpty(variableName) || string.IsNullOrEmpty(positiveColor) || string.IsNullOrEmpty(negativeColor) || string.IsNullOrEmpty(zeroColor))) { positiveColorValue = JUtil.ParseColor32(positiveColor, part, ref rpmComp); negativeColorValue = JUtil.ParseColor32(negativeColor, part, ref rpmComp); zeroColorValue = JUtil.ParseColor32(zeroColor, part, ref rpmComp); del = (Action <float>)Delegate.CreateDelegate(typeof(Action <float>), this, "OnCallback"); rpmComp.RegisterVariableCallback(variableName, del); registeredVessel = vessel.id; // Initialize the text color. Actually, callback registration took care of that } } catch (Exception e) { JUtil.LogErrorMessage(this, "Start failed with exception {0}", e); spf = new StringProcessorFormatter("x", rpmComp); } }
public void Start() { comp = RasterPropMonitorComputer.Instantiate(internalProp); textObjTransform = internalProp.FindModelTransform(labelTransform); textObj = InternalComponents.Instance.CreateText(fontName, fontSize, textObjTransform, string.Empty); activeLabel = 0; SmarterButton.CreateButton(internalProp, switchTransform, Click); ConfigNode moduleConfig = null; foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("PROP")) { if (node.GetValue("name") == internalProp.propName) { moduleConfig = node.GetNodes("MODULE")[moduleID]; ConfigNode[] variableNodes = moduleConfig.GetNodes("VARIABLESET"); for (int i = 0; i < variableNodes.Length; i++) { try { labelsEx.Add(new VariableLabelSet(variableNodes[i])); } catch (ArgumentException e) { JUtil.LogMessage(this, "Error in building prop number {1} - {0}", e.Message, internalProp.propID); } } break; } } // Fallback: If there are no VARIABLESET blocks, we treat the module configuration itself as a variableset block. if (labelsEx.Count < 1 && moduleConfig != null) { try { labelsEx.Add(new VariableLabelSet(moduleConfig)); } catch (ArgumentException e) { JUtil.LogMessage(this, "Error in building prop number {1} - {0}", e.Message, internalProp.propID); } } colorShiftRenderer = internalProp.FindModelComponent <Renderer>(coloredObject); if (labelsEx[activeLabel].hasColor) { colorShiftRenderer.material.SetColor(colorName, labelsEx[activeLabel].color); } textObj.text.Text = StringProcessor.ProcessString(labelsEx[activeLabel].labelText, comp); audioOutput = JUtil.SetupIVASound(internalProp, switchSound, switchSoundVolume, false); JUtil.LogMessage(this, "Configuration complete in prop {1}, supporting {0} variable indicators.", labelsEx.Count, internalProp.propID); }
private bool removeCharacterOrSelection(bool sound = true) { if (InternalText.Length == 0) { return(false); } if (selectionLength == 0 && selectionLeft == 0) { return(false); } int count = MathHelper.Clamp(selectionLength, 1, InternalText.Length); int start = MathHelper.Clamp(selectionLength > 0 ? selectionLeft : selectionLeft - 1, 0, InternalText.Length - count); if (count == 0) { return(false); } if (sound) { audio.Sample.Get(@"Keyboard/key-delete")?.Play(); } foreach (var d in textFlow.Children.Skip(start).Take(count).ToArray()) //ToArray since we are removing items from the children in this block. { textFlow.Remove(d); textContainer.Add(d); d.FadeOut(200); d.MoveToY(d.DrawSize.Y, 200, EasingTypes.InExpo); d.Expire(); } InternalText = InternalText.Remove(start, count); if (selectionLength > 0) { selectionStart = selectionEnd = selectionLeft; } else { selectionStart = selectionEnd = selectionLeft - 1; } cursorAndLayout.Invalidate(); return(true); }
protected override void Layout() { base.Layout(); if (_secondary.Text().Length > 0) { InternalText.Y = PixelScene.Align(Y + (Height - InternalText.Height - _secondary.BaseLine()) / 2); _secondary.X = PixelScene.Align(X + (Width - _secondary.Width) / 2); _secondary.Y = PixelScene.Align(InternalText.Y + InternalText.Height); } else { InternalText.Y = PixelScene.Align(Y + (Height - InternalText.BaseLine()) / 2); } }
public void Start() { RPMVesselComputer comp = RPMVesselComputer.Instance(vessel); Transform textObjTransform = internalProp.FindModelTransform(transformName); textObj = InternalComponents.Instance.CreateText(fontName, fontSize, textObjTransform, string.Empty); // Force oneshot if there's no variables: oneshot |= !labelText.Contains("$&$"); string sourceString = labelText.UnMangleConfigText(); // Alow a " character to escape leading whitespace if (sourceString[0] == '"') { sourceString = sourceString.Substring(1); } spf = new StringProcessorFormatter(sourceString); if (!oneshot) { comp.UpdateDataRefreshRate(refreshRate); } if (!(string.IsNullOrEmpty(variableName) || string.IsNullOrEmpty(positiveColor) || string.IsNullOrEmpty(negativeColor) || string.IsNullOrEmpty(zeroColor))) { positiveColorValue = ConfigNode.ParseColor32(positiveColor); negativeColorValue = ConfigNode.ParseColor32(negativeColor); zeroColorValue = ConfigNode.ParseColor32(zeroColor); del = (Action <RPMVesselComputer, float>)Delegate.CreateDelegate(typeof(Action <RPMVesselComputer, float>), this, "OnCallback"); comp.RegisterCallback(variableName, del); // Initialize the text color. float value = comp.ProcessVariable(variableName).MassageToFloat(); if (value < 0.0f) { textObj.text.Color = negativeColorValue; } else if (value > 0.0f) { textObj.text.Color = positiveColorValue; } else { textObj.text.Color = zeroColorValue; } } }
public void OnDestroy() { if (del != null) { try { rpmComp.UnregisterVariableCallback(variableName, del); } catch { //JUtil.LogMessage(this, "Trapped exception unregistering JSIVariableLabel (you can ignore this)"); } } //JUtil.LogMessage(this, "OnDestroy()"); Destroy(textObj); textObj = null; }
public void OnDestroy() { if (del != null) { try { RPMVesselComputer comp = null; if (RPMVesselComputer.TryGetInstance(vessel, ref comp)) { comp.UnregisterCallback(variableName, del); } } catch { //JUtil.LogMessage(this, "Trapped exception unregistering JSIVariableLabel (you can ignore this)"); } } //JUtil.LogMessage(this, "OnDestroy()"); Destroy(textObj); textObj = null; }
private Drawable addCharacter(char c) { if (char.IsControl(c)) { return(null); } if (selectionLength > 0) { removeCharacterOrSelection(); } if (InternalText.Length + 1 > LengthLimit) { if (background.Alpha > 0) { background.FlashColour(Color4.Red, 200); } else { textFlow.FlashColour(Color4.Red, 200); } return(null); } Drawable ch = AddCharacterToFlow(c); ch.Position = new Vector2(0, DrawSize.Y); ch.MoveToY(0, 200, EasingTypes.OutExpo); InternalText = InternalText.Insert(selectionLeft, c.ToString()); selectionStart = selectionEnd = selectionLeft + 1; cursorAndLayout.Invalidate(); return(ch); }
public void Start() { try { rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true); Transform textObjTransform = internalProp.FindModelTransform(transformName); textObj = InternalComponents.Instance.CreateText("Arial", fontSize * 15.5f, textObjTransform, string.Empty); // Force oneshot if there's no variables: oneshot |= !labelText.Contains("$&$"); string sourceString = labelText.UnMangleConfigText(); if (!string.IsNullOrEmpty(sourceString) && sourceString.Length > 1) { // Alow a " character to escape leading whitespace if (sourceString[0] == '"') { sourceString = sourceString.Substring(1); } } spf = new StringProcessorFormatter(sourceString, rpmComp); if (!oneshot) { rpmComp.UpdateDataRefreshRate(refreshRate); } if (!(string.IsNullOrEmpty(variableName) || string.IsNullOrEmpty(positiveColor) || string.IsNullOrEmpty(negativeColor) || string.IsNullOrEmpty(zeroColor))) { positiveColorValue = JUtil.ParseColor32(positiveColor, part, ref rpmComp); negativeColorValue = JUtil.ParseColor32(negativeColor, part, ref rpmComp); zeroColorValue = JUtil.ParseColor32(zeroColor, part, ref rpmComp); del = (Action<float>)Delegate.CreateDelegate(typeof(Action<float>), this, "OnCallback"); rpmComp.RegisterVariableCallback(variableName, del); registeredVessel = vessel.id; // Initialize the text color. Actually, callback registration took care of that } } catch(Exception e) { JUtil.LogErrorMessage(this, "Start failed with exception {0}", e); spf = new StringProcessorFormatter("x", rpmComp); } }
public void Draw(RenderTarget target, RenderStates states) { states.Transform *= Transform; InternalText.Origin = new Vector2f(0, InternalText.CharacterSize / 2); InternalText.Position = new Vector2f(0, Bar.Size.Y / 2); target.Draw(Utilities.ApplyTexture(InternalText, InternalText.GetGlobalBounds(), TextImage, InternalText.GetBorderColor().MakeTransparent()), states); var tr = Transform.Identity; tr.Translate(InternalText.GetGlobalBounds().Width + 5, 0); states.Transform *= tr; target.Draw(new RectangleShape { Size = (Vector2f)Bar.Size, Texture = Back }, states); var scale = ImgHeight / Bar.Size.Y; if ((Style & Template.Gauge.VERTICAL) == 0) { var rect = new RectangleShape(new Vector2f(Bar.Size.X * Value / Max, Bar.Size.Y)) { Scale = new Vector2f(scale, scale) }; rect.Texture = Bar; if ((Style & Template.Gauge.LEFT) != 0) { rect.TextureRect = new IntRect(0, 0, (int)(Bar.Size.X * Value / Max), (int)Bar.Size.Y); } else if ((Style & Template.Gauge.RIGHT) != 0) { rect.TextureRect = new IntRect((int)(Bar.Size.X * (Max - Value) / Max), 0, (int)(Bar.Size.X * Value / Max), (int)Bar.Size.Y); rect.Position = new Vector2f(Back.Size.X, 0); rect.Origin = new Vector2f(rect.Size.X, 0); } else { rect.TextureRect = new IntRect((int)(Bar.Size.X / 2 - Bar.Size.X * Value / Max / 2), 0, (int)(Bar.Size.X * Value / Max), (int)Bar.Size.Y); rect.Position = new Vector2f(Back.Size.X / 2, 0); rect.Origin = new Vector2f(rect.Size.X / 2, 0); } target.Draw(rect, states); } else { var rect = new RectangleShape(new Vector2f(Bar.Size.X, Bar.Size.Y * Value / Max)) { Scale = new Vector2f(scale, scale) }; rect.Texture = Bar; if ((Style & Template.Gauge.LEFT) != 0) { rect.TextureRect = new IntRect(0, 0, (int)Bar.Size.X, (int)(Bar.Size.Y * Value / Max)); } else if ((Style & Template.Gauge.RIGHT) != 0) { rect.TextureRect = new IntRect(0, (int)(Bar.Size.Y * (Max - Value) / Max), (int)Bar.Size.X, (int)(Bar.Size.Y * Value / Max)); rect.Position = new Vector2f(0, Back.Size.Y); rect.Origin = new Vector2f(0, rect.Size.Y); } else { rect.TextureRect = new IntRect(0, (int)(Bar.Size.Y / 2 - Bar.Size.Y * Value / Max / 2), (int)Bar.Size.X, (int)(Bar.Size.Y * Value / Max)); rect.Position = new Vector2f(0, Back.Size.Y / 2); rect.Origin = new Vector2f(0, rect.Size.Y / 2); } target.Draw(rect, states); if (drawOutline) { target.Draw(new RectangleShape(new Vector2f(Bounds.Width, Bounds.Height)) { OutlineColor = Color.Green, OutlineThickness = -1, FillColor = Color.Transparent }, states); } } }
public void Draw(RenderTarget target, RenderStates states) { int Hspace = (int)(Icons.First().Size.Y *(float)Icons.First().Size.X / Icons.First().Size.Y + 4); int Vspace = (int)Icons.First().Size.Y + 4; InternalText.Origin = new Vector2f(0, InternalText.CharacterSize / 2); if ((Style & Template.Counter.VERTICAL) == 0) { InternalText.Position = new Vector2f(0, (int)Math.Max(InternalText.CharacterSize, (Style & (Template.Counter.ALT1 | Template.Counter.ALT2)) != 0 ? Icons.First().Size.Y * 1.5f : Icons.First().Size.Y) / 2); } else { InternalText.Position = new Vector2f(0, (int)Math.Max(InternalText.CharacterSize, (Style & (Template.Counter.ALT1 | Template.Counter.ALT2)) != 0 ? Vspace * .5f * (Max - 1) : Vspace * (Max - 1)) / 2); } states.Transform *= Transform; var initialStates = states; target.Draw(Utilities.ApplyTexture(InternalText, InternalText.GetGlobalBounds(), TextImage, InternalText.GetBorderColor().MakeTransparent()), states); var tr = Transform.Identity; tr.Translate(InternalText.GetGlobalBounds().Width + 5, 0); states.Transform *= tr; if ((Style & Template.Counter.STACKED) != 0) { Texture toDraw = null; var index = Math.Min(Value - 1, Icons.Count); if (index == 0 && Back.Count > 0) { toDraw = Back.First(); } else if (index > 0) { toDraw = Icons[index]; } var ratio = (float)toDraw.Size.X / toDraw.Size.Y; var scale = ImgHeight / toDraw.Size.Y; var rect = new Sprite(toDraw) { Scale = new Vector2f(scale, scale) }; target.Draw(rect, states); } else { void disp(Texture toDraw, Vector2f whereToDraw) { var scale = ImgHeight / toDraw.Size.Y; target.Draw(new Sprite { Position = whereToDraw, Texture = toDraw, Scale = new Vector2f(scale, scale) }, states); } for (int i = 1; i <= Max; i++) { Vector2f position; if ((Style & Template.Counter.VERTICAL) != 0) { if ((Style & Template.Counter.ALT1) != 0) { position = new Vector2f(Hspace / 2 * ((i + 1) % 2), (i - 1) * Vspace / 2); } else if ((Style & Template.Counter.ALT2) != 0) { position = new Vector2f(Hspace / 2 * (i % 2), (i - 1) * Vspace / 2); } else { position = new Vector2f(0, (i - 1) * Vspace); } if ((Style & Template.Counter.RIGHT) != 0) { position.Y = (Max - 1) * Vspace * ((Style & (Template.Counter.ALT1 | Template.Counter.ALT2)) != 0 ? .5f : 1) - position.Y; } } else { if ((Style & Template.Counter.ALT1) != 0) { position = new Vector2f((i - 1) * Hspace / 2, Vspace / 2 * ((i + 1) % 2)); } else if ((Style & Template.Counter.ALT2) != 0) { position = new Vector2f((i - 1) * Hspace / 2, Vspace / 2 * (i % 2)); } else { position = new Vector2f((i - 1) * Hspace, 0); } if ((Style & Template.Counter.RIGHT) != 0) { position.X = (Max - 1) * Hspace * ((Style & (Template.Counter.ALT1 | Template.Counter.ALT2)) != 0 ? .5f : 1) - position.X; } } if (Value >= i) { disp(Icons[Math.Min(Icons.Count - 1, i - 1)], position); } else if (Back.Count > 0) { disp(Back[Math.Min(Back.Count - 1, i - 1)], position); } } } if (drawOutline) { target.Draw(new RectangleShape(new Vector2f(Bounds.Width, Bounds.Height)) { OutlineColor = Color.Green, OutlineThickness = -1, FillColor = Color.Transparent }, initialStates); } }
public void Start() { if (HighLogic.LoadedSceneIsEditor) { return; } try { textObjTransform = internalProp.FindModelTransform(labelTransform); textObj = InternalComponents.Instance.CreateText(fontName, fontSize, textObjTransform, string.Empty); activeLabel = 0; SmarterButton.CreateButton(internalProp, switchTransform, Click); ConfigNode moduleConfig = null; foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("PROP")) { if (node.GetValue("name") == internalProp.propName) { moduleConfig = node.GetNodes("MODULE")[moduleID]; ConfigNode[] variableNodes = moduleConfig.GetNodes("VARIABLESET"); for (int i = 0; i < variableNodes.Length; i++) { try { labelsEx.Add(new VariableLabelSet(variableNodes[i])); } catch (ArgumentException e) { JUtil.LogErrorMessage(this, "Error in building prop number {1} - {0}", e.Message, internalProp.propID); } } break; } } // Fallback: If there are no VARIABLESET blocks, we treat the module configuration itself as a variableset block. if (labelsEx.Count < 1 && moduleConfig != null) { try { labelsEx.Add(new VariableLabelSet(moduleConfig)); } catch (ArgumentException e) { JUtil.LogErrorMessage(this, "Error in building prop number {1} - {0}", e.Message, internalProp.propID); } } if (labelsEx.Count == 0) { JUtil.LogErrorMessage(this, "No labels defined."); throw new ArgumentException("No labels defined"); } colorShiftRenderer = internalProp.FindModelComponent <Renderer>(coloredObject); if (labelsEx[activeLabel].hasColor) { colorShiftRenderer.material.SetColor(colorName, labelsEx[activeLabel].color); } if (labelsEx[activeLabel].hasText) { if (labelsEx[activeLabel].oneShot) { // Fetching formatString directly is notionally bad // because there may be formatting stuff, but if // oneShot is true, we already know that this is a // constant string with no formatting. textObj.text.Text = labelsEx[activeLabel].label.formatString; } else { textObj.text.Text = ""; } } audioOutput = JUtil.SetupIVASound(internalProp, switchSound, switchSoundVolume, false); JUtil.LogMessage(this, "Configuration complete in prop {1}, supporting {0} variable indicators.", labelsEx.Count, internalProp.propID); } catch { JUtil.AnnoyUser(this); enabled = false; throw; } }
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) { if (!HasFocus) { return(false); } if (textInput?.ImeActive == true) { return(true); } switch (args.Key) { case Key.Tab: return(false); case Key.End: moveSelection(InternalText.Length, state.Keyboard.ShiftPressed); return(true); case Key.Home: moveSelection(-InternalText.Length, state.Keyboard.ShiftPressed); return(true); case Key.Left: { if (!HandleLeftRightArrows) { return(false); } if (selectionEnd == 0) { //we only clear if you aren't holding shift if (!state.Keyboard.ShiftPressed) { resetSelection(); } return(true); } int amount = 1; if (state.Keyboard.ControlPressed) { int lastSpace = InternalText.LastIndexOf(' ', Math.Max(0, selectionEnd - 2)); if (lastSpace >= 0) { //if you have something selected and shift is not held down //A selection reset is required to select a word inside the current selection if (!state.Keyboard.ShiftPressed) { resetSelection(); } amount = selectionEnd - lastSpace - 1; } else { amount = selectionEnd; } } moveSelection(-amount, state.Keyboard.ShiftPressed); return(true); } case Key.Right: { if (!HandleLeftRightArrows) { return(false); } if (selectionEnd == InternalText.Length) { if (!state.Keyboard.ShiftPressed) { resetSelection(); } return(true); } int amount = 1; if (state.Keyboard.ControlPressed) { int nextSpace = InternalText.IndexOf(' ', selectionEnd + 1); if (nextSpace >= 0) { if (!state.Keyboard.ShiftPressed) { resetSelection(); } amount = nextSpace - selectionEnd; } else { amount = InternalText.Length - selectionEnd; } } moveSelection(amount, state.Keyboard.ShiftPressed); return(true); } case Key.Enter: selectionStart = selectionEnd = 0; TriggerFocusLost(state); return(true); case Key.Delete: if (selectionLength == 0) { if (InternalText.Length == selectionStart) { return(true); } if (state.Keyboard.ControlPressed) { int spacePos = selectionStart; while (InternalText[spacePos] == ' ' && spacePos < InternalText.Length) { spacePos++; } spacePos = MathHelper.Clamp(InternalText.IndexOf(' ', spacePos), 0, InternalText.Length); selectionEnd = spacePos; if (selectionStart == 0 && spacePos == 0) { selectionEnd = InternalText.Length; } if (selectionLength == 0) { return(true); } } else { //we're deleting in front of the cursor, so move the cursor forward once first selectionStart = selectionEnd = selectionStart + 1; } } removeCharacterOrSelection(); return(true); case Key.Back: if (selectionLength == 0 && state.Keyboard.ControlPressed) { int spacePos = selectionLeft >= 2 ? Math.Max(0, InternalText.LastIndexOf(' ', selectionLeft - 2) + 1) : 0; selectionStart = spacePos; } removeCharacterOrSelection(); return(true); } if (state.Keyboard.ControlPressed) { //handling of function keys switch (args.Key) { case Key.A: selectionStart = 0; selectionEnd = InternalText.Length; cursorAndLayout.Invalidate(); return(true); case Key.C: if (string.IsNullOrEmpty(SelectedText) || !AllowClipboardExport) { return(true); } //System.Windows.Forms.Clipboard.SetText(SelectedText); return(true); case Key.X: if (string.IsNullOrEmpty(SelectedText)) { return(true); } //if (AllowClipboardExport) // System.Windows.Forms.Clipboard.SetText(SelectedText); removeCharacterOrSelection(); return(true); case Key.V: //the text is pasted into the hidden textbox, so we don't need any direct clipboard interaction here. insertString(textInput?.GetPendingText()); return(true); } return(false); } string str = textInput?.GetPendingText(); if (!string.IsNullOrEmpty(str)) { if (state.Keyboard.ShiftPressed) { audio.Sample.Get(@"Keyboard/key-caps")?.Play(); } else { audio.Sample.Get($@"Keyboard/key-press-{RNG.Next(1, 5)}")?.Play(); } insertString(str); } return(true); }
internal MASComponentInternalText(ConfigNode config, InternalProp prop, MASFlightComputer comp) : base(config, prop, comp) { string transform = string.Empty; if (!config.TryGetValue("transform", ref transform)) { throw new ArgumentException("Missing 'transform' in INTERNAL_TEXT " + name); } string text = string.Empty; if (!config.TryGetValue("text", ref text)) { throw new ArgumentException("Invalid or missing 'text' in INTERNAL_TEXT " + name); } Color passiveColor = Color.white; string passiveColorStr = string.Empty; if (!config.TryGetValue("passiveColor", ref passiveColorStr)) { throw new ArgumentException("Invalid or missing 'passiveColor' in INTERNAL_TEXT " + name); } else { Color32 namedColor; if (comp.TryGetNamedColor(passiveColorStr, out namedColor)) { passiveColor = namedColor; } else { string[] startColors = Utility.SplitVariableList(passiveColorStr); if (startColors.Length < 3 || startColors.Length > 4) { throw new ArgumentException("passiveColor does not contain 3 or 4 values in INTERNAL_TEXT " + name); } float x; if (!float.TryParse(startColors[0], out x)) { throw new ArgumentException("Unable to parse passiveColor red value in INTERNAL_TEXT " + name); } passiveColor.r = Mathf.Clamp01(x * (1.0f / 255.0f)); if (!float.TryParse(startColors[1], out x)) { throw new ArgumentException("Unable to parse passiveColor green value in INTERNAL_TEXT " + name); } passiveColor.g = Mathf.Clamp01(x * (1.0f / 255.0f)); if (!float.TryParse(startColors[2], out x)) { throw new ArgumentException("Unable to parse passiveColor blue value in INTERNAL_TEXT " + name); } passiveColor.b = Mathf.Clamp01(x * (1.0f / 255.0f)); if (startColors.Length == 4) { if (!float.TryParse(startColors[3], out x)) { throw new ArgumentException("Unable to parse passiveColor alpha value in INTERNAL_TEXT " + name); } passiveColor.a = Mathf.Clamp01(x * (1.0f / 255.0f)); } } } text = MdVTextMesh.UnmangleText(text); // See if this is a single-line text, or multi-line. The latter is not supported here. string[] textRows = text.Split(Utility.LineSeparator, StringSplitOptions.RemoveEmptyEntries); if (textRows.Length > 1) { throw new ArgumentException("Multi-line text is not supported in INTERNAL_TEXT " + name); } text = textRows[0]; bool mutable = false; if (text.Contains(MdVTextMesh.VariableListSeparator[0]) || text.Contains(MdVTextMesh.VariableListSeparator[1])) { mutable = true; } Transform textObjTransform = prop.FindModelTransform(transform); // TODO: Allow variable fontSize? float fontSize = 0.15f; textObj = InternalComponents.Instance.CreateText("Arial", fontSize, textObjTransform, (mutable) ? "-" : text, passiveColor, false, "TopLeft"); try { Transform q = textObj.text.transform; q.Translate(0.0f, 0.0048f, 0.0f); } catch (Exception) { } if (mutable) { string[] sections = text.Split(MdVTextMesh.VariableListSeparator, StringSplitOptions.RemoveEmptyEntries); if (sections.Length != 2) { throw new ArgumentException("Error parsing text in INTERNAL_TEXT " + name); } MdVTextMesh.TextRow tr = new MdVTextMesh.TextRow(); tr.formatString = sections[0]; // See if this text contains formatted rich text nudges if (tr.formatString.Contains("[")) { throw new ArgumentException("Formatted rich text is not supported in INTERNAL_TEXT " + name); } string[] variables = sections[1].Split(';'); tr.variable = new Variable[variables.Length]; tr.evals = new object[variables.Length]; tr.callback = (double dontCare) => { tr.rowInvalidated = true; }; for (int var = 0; var < tr.variable.Length; ++var) { try { tr.variable[var] = variableRegistrar.RegisterVariableChangeCallback(variables[var], tr.callback); } catch (Exception e) { Utility.LogError(this, "Variable {0} threw an exception", variables[var]); throw e; } } tr.rowInvalidated = true; tr.EvaluateVariables(); textObj.text.text = tr.formattedData; textRow = tr; coroutineEnabled = true; comp.StartCoroutine(StringUpdateCoroutine()); } }