public TextKeyTranslateView(TextKey sourcekey, TextKey translatekey) { this.SourceKey = sourcekey; this.TranslateKey = translatekey; ColumnDefinitions.Add(1, GridUnitType.Star); ColumnDefinitions.Add(1, GridUnitType.Star); _LblSource = new Label() { Column = 0, Text = SourceKey.Value }; _LblTranslate = new Label() { Column = 1, Text = TranslateKey.Value }; _TxtTranslate = new UI.PasteTextField() { Column = 1, Visibility = Skill.Framework.UI.Visibility.Hidden }; _TxtTranslate.TextField.Text = TranslateKey.Value; this.Controls.Add(_LblSource); this.Controls.Add(_LblTranslate); this.Controls.Add(_TxtTranslate); _TxtTranslate.TextField.TextChanged += _TxtTranslate_TextChanged; this.Margin = new Thickness(0, 0, 17, 0); }
private void Save() { if (_Translate != null && _IsChanged) { if (_SelectedView != null) { _SelectedView.Selected = false; } TextKey[] keys = new TextKey[_ListBox.Controls.Count]; for (int i = 0; i < _ListBox.Controls.Count; i++) { keys[i] = ((TextKeyTranslateView)_ListBox.Controls[i]).TranslateKey; } _Translate.SetKeys(keys); UnityEditor.EditorUtility.SetDirty(_Translate); if (_SelectedView != null) { _SelectedView.Selected = true; } SetChanged(false); } }
public bool IsLicensed() { if (TextKey.Equals(OriginKey) && !Expire) { return(true); } return(false); }
public static string GetText(TextKey textKey, params object[] args) { if (!TryGetTerm(CurrentLanguage, textKey, out var term)) { TryGetTerm(FallBackLang, textKey, out term); } return(string.Format(term, args)); }
private bool ViewExist(TextKey k) { foreach (var item in _List) { if (k == item.Key) { return(true); } } return(false); }
private void Save() { if (_Dictionary != null && _IsChanged) { TextKey[] keys = new TextKey[_ListBox.Controls.Count]; for (int i = 0; i < _ListBox.Controls.Count; i++) { keys[i] = ((TextKeyView)_ListBox.Controls[i]).Key; } _Dictionary.SetKeys(keys); UnityEditor.EditorUtility.SetDirty(_Dictionary); SetChanged(false); } }
public string GetText(TextKey textKey) { switch (CurrentLanguage) { case Language.English: return(_textsEN[textKey]); case Language.German: return(_textsDE[textKey]); default: throw new ArgumentOutOfRangeException(nameof(CurrentLanguage), CurrentLanguage, null); } }
public static string GetText(TextKey key) { try { if ((int)key < maxLength) { return(ListText[(int)key]); } } catch (Exception e) { Debug.LogError($"Text not exits key: {key} => err: {e}"); } return(key.ToString()); }
/// <summary> /// 绘制包含中文字的文字 /// </summary> /// <param name="text">要绘制的文字</param> /// <param name="scrnPos">绘制的屏幕位置</param> /// <param name="rota">旋转角</param> /// <param name="scale">缩放比</param> /// <param name="color">颜色</param> /// <param name="layerDepth">绘制深度</param> /// <param name="fontName">字体名称</param> public void WriteText(string text, Vector2 scrnPos, float rota, float scale, Color color, float layerDepth, string fontName) { Texture2D texture; TextKey key = new TextKey(text, fontName); if (cache.ContainsKey(key)) { texture = cache[key]; } else { texture = BuildTexture(text, fontName); } engine.SpriteMgr.alphaSprite.Draw(texture, scrnPos, null, color, rota, new Vector2(0, 0), scale, SpriteEffects.None, layerDepth); }
public Texture GetTextTexture(string text, Font font, TextAlignment textAlignment, RgbaFloat color, Vector2 size) { var key = new TextKey { Text = text, Font = font, Alignment = textAlignment, Color = color, Size = size }; if (!_cache.TryGetValue(key, out var result)) { _cache.Add(key, result = AddDisposable(CreateTexture(key))); } return(result); }
/// <summary> /// 建立贴图并添加到缓冲中。 /// 尽量在第一次绘制之前调用该函数,这样可以避免建立贴图的过程造成游戏的停滞 /// </summary> /// <param name="text">要创建的字符串</param> /// <param name="fontName">字体</param> /// <returns></returns> public Texture2D BuildTexture(string text, string fontName) { TextKey key = new TextKey(text, fontName); if (cache.ContainsKey(key)) { return(null); } if (!fonts.ContainsKey(fontName)) { Log.Write("error fontName used in BuildTexture"); return(null); } System.Drawing.Font font = fonts[fontName]; System.Drawing.SizeF size = mesureGraphics.MeasureString(text, font); int texWidth = (int)size.Width; int texHeight = (int)size.Height; System.Drawing.Bitmap textMap = new System.Drawing.Bitmap(texWidth, texHeight); System.Drawing.Graphics curGraphics = System.Drawing.Graphics.FromImage(textMap); curGraphics.DrawString(text, font, System.Drawing.Brushes.White, new System.Drawing.PointF()); Texture2D texture = new Texture2D(engine.Device, texWidth, texHeight, 1, TextureUsage.None, SurfaceFormat.Color); Microsoft.Xna.Framework.Graphics.Color[] data = new Microsoft.Xna.Framework.Graphics.Color[texWidth * texHeight]; for (int y = 0; y < texHeight; y++) { for (int x = 0; x < texWidth; x++) { data[y * texWidth + x] = ConvertHelper.SysColorToXNAColor(textMap.GetPixel(x, y)); } } texture.SetData <Microsoft.Xna.Framework.Graphics.Color>(data); cache.Add(key, texture); curGraphics.Dispose(); return(texture); }
/// <summary> /// Replaces the text key's prefix with a different value, also for all children. /// </summary> /// <param name="oldKey">Old text key prefix to delete.</param> /// <param name="newKey">New text key prefix to insert.</param> /// <param name="textKeys">Text keys dictionary to update.</param> /// <returns>Number of affected keys.</returns> private int ReplaceKeyRecursive(string oldKey, string newKey, Dictionary <string, TextKeyViewModel> textKeys) { string oldTextKey = TextKey; TextKey = TextKey.ReplaceStart(oldKey, newKey); OnPropertyChanged("TextKey"); if (textKeys.ContainsKey(oldTextKey)) { textKeys.Remove(oldTextKey); textKeys.Add(TextKey, this); } int affectedKeys = IsFullKey ? 1 : 0; foreach (TextKeyViewModel child in Children) { affectedKeys += child.ReplaceKeyRecursive(oldKey, newKey, textKeys); } return(affectedKeys); }
public TextKeyView(TextKey key, DictionaryEditorWindow owner) { this._OwnerEditor = owner; this.Key = key; ColumnDefinitions.Add(1, GridUnitType.Star); ColumnDefinitions.Add(2, GridUnitType.Star); _LblName = new Label() { Column = 0 }; _LblValue = new Label() { Column = 1 }; this.Controls.Add(_LblName); this.Controls.Add(_LblValue); UpdateTexts(); }
private void Rebuild() { Clear(); if (_Source != null && _Translate != null) { if (_Source.Keys != null) { foreach (var sKey in _Source.Keys) { TextKey tKey = GetKeyInTranslate(sKey.Key); if (tKey != null) { TextKeyTranslateView view = new TextKeyTranslateView(sKey, tKey); view.Changed += view_Changed; _ListBox.Controls.Add(view); } } } } SetChanged(false); _ListBox.SelectedIndex = -1; }
private void CopyKeys() { bool change = false; if (_Translate != null && _Source != null) { List <TextKey> textList = new List <TextKey>(); if (_Translate.Keys != null) { foreach (var tKey in _Translate.Keys) { textList.Add(tKey); } } if (_Source.Keys != null) { foreach (var sKey in _Source.Keys) { TextKey tKey = GetKeyInTranslate(sKey.Key); if (tKey == null) { tKey = new TextKey() { Key = sKey.Key, Comment = sKey.Comment, Value = string.Empty }; textList.Add(tKey); change = true; } } } _Translate.SetKeys(textList.ToArray()); Rebuild(); if (change) { SetChanged(true); } } }
public MessageBoxResult Show(TextKey message, TextKey title, MessageBoxAction action = MessageBoxAction.Confirm, MessageBoxIcon icon = MessageBoxIcon.Information, IWindow parent = null) { return(Show(text.Get(message), text.Get(title), action, icon, parent)); }
public static string RetornaFraseDoIdioma(TextKey chave) { return(falacoesComChave[linguaChave][chave][0]); }
public static List <string> RetornaListaDeTextoDoIdioma(TextKey chave) { return(falacoesComChave[linguaChave][chave]); }
public void ChangeTalkKey(TextKey chave) { conversa = TextBank.RetornaListaDeTextoDoIdioma(chave).ToArray(); }
public void Pick(TextKey pickedKey) { Subtitle.TitleKey = pickedKey.Key; _LblTitle.Text = pickedKey.Value; Editor.Editor.SetDirty2(); }
private unsafe Texture CreateTexture(TextKey key) { var size = key.Size; var actualFont = key.Font; var image = _textImagePool.Acquire(new ImageKey { Width = (int)Math.Ceiling(size.X), Height = (int)Math.Ceiling(size.Y) }); // Clear image to transparent. // TODO: Don't need to do this for a newly created image. fixed(void *pin = &image.DangerousGetPinnableReferenceToPixelBuffer()) { Unsafe.InitBlock(pin, 0, (uint)(image.Width * image.Height * 4)); } image.Mutate(x => { var location = new SixLabors.Primitives.PointF(0, size.Y / 2.0f); // TODO: Vertical centering is not working properly. location.Y *= 0.8f; var color = key.Color; x.DrawText( new TextGraphicsOptions { WrapTextWidth = size.X, HorizontalAlignment = key.Alignment == TextAlignment.Center ? HorizontalAlignment.Center : HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center }, key.Text, actualFont, new Bgra32( (byte)(color.R * 255.0f), (byte)(color.G * 255.0f), (byte)(color.B * 255.0f), (byte)(color.A * 255.0f)), location); }); Texture texture; // Draw image to texture. fixed(void *pin = &image.DangerousGetPinnableReferenceToPixelBuffer()) { texture = _graphicsDevice.ResourceFactory.CreateTexture( TextureDescription.Texture2D( (uint)image.Width, (uint)image.Height, 1, 1, PixelFormat.B8_G8_R8_A8_UNorm, TextureUsage.Sampled)); _graphicsDevice.UpdateTexture( texture, new IntPtr(pin), (uint)(image.Width * image.Height * 4), 0, 0, 0, texture.Width, texture.Height, 1, 0, 0); } _textImagePool.ReleaseAll(); return(texture); }
public bool Validate() { // NOTE: All checks are performed in their decreasing order of significance. The most- // severe errors come first, proceeding to more informational problems. The first // determined error generates the visible message and quits the method so that // no other checks are performed or could overwrite the message. // First validate all children recursively and remember whether there was a problem // somewhere down the tree bool anyChildError = false; foreach (TextKeyViewModel child in Children) { if (!child.Validate()) { anyChildError = true; } } // Partial keys can only indicate problems in the subtree if (!IsFullKey) { HasOwnProblem = false; HasProblem = anyChildError; Remarks = null; return(!anyChildError); } // The Tx namespace generally has no problems if (TextKey.StartsWith("Tx:")) { HasOwnProblem = false; HasProblem = anyChildError; Remarks = null; return(!anyChildError); } HasOwnProblem = false; HasProblem = anyChildError; Remarks = null; // ----- Check for count/modulo errors ----- // Check for invalid count values in any CultureText if (CultureTextVMs.Any(ct => ct.QuantifiedTextVMs.Any(qt => qt.Count < 0 || qt.Count >= 0xFFFF))) { HasOwnProblem = true; HasProblem = true; AddRemarks(Tx.T("validation.content.invalid count")); } // Check for invalid modulo values in any CultureText if (CultureTextVMs.Any(ct => ct.QuantifiedTextVMs.Any(qt => qt.Modulo != 0 && (qt.Modulo < 2 || qt.Modulo > 1000)))) { HasOwnProblem = true; HasProblem = true; AddRemarks(Tx.T("validation.content.invalid modulo")); } // Check for duplicate count/modulo values in any CultureText if (CultureTextVMs.Any(ct => ct.QuantifiedTextVMs .GroupBy(qt => qt.Count << 16 | qt.Modulo) .Any(grp => grp.Count() > 1))) { HasOwnProblem = true; HasProblem = true; AddRemarks(Tx.T("validation.content.duplicate count modulo")); } // ----- Check referenced keys ----- if (CultureTextVMs.Any(ct => ct.TextKeyReferences != null && ct.TextKeyReferences.OfType <string>().Any(key => key == TextKey))) { HasOwnProblem = true; HasProblem = true; AddRemarks(Tx.T("validation.content.referenced key loop")); } if (CultureTextVMs.Any(ct => ct.QuantifiedTextVMs.Any(qt => qt.TextKeyReferences != null && qt.TextKeyReferences.OfType <string>().Any(key => key == TextKey)))) { HasOwnProblem = true; HasProblem = true; AddRemarks(Tx.T("validation.content.referenced key loop")); } if (CultureTextVMs.Any(ct => ct.TextKeyReferences != null && ct.TextKeyReferences.OfType <string>().Any(key => !MainWindowVM.TextKeys.ContainsKey(key)))) { HasOwnProblem = true; HasProblem = true; AddRemarks(Tx.T("validation.content.missing referenced key")); } if (CultureTextVMs.Any(ct => ct.QuantifiedTextVMs.Any(qt => qt.TextKeyReferences != null && qt.TextKeyReferences.OfType <string>().Any(key => !MainWindowVM.TextKeys.ContainsKey(key))))) { HasOwnProblem = true; HasProblem = true; AddRemarks(Tx.T("validation.content.missing referenced key")); } // ----- Check translations consistency ----- IsAccepted = false; if (CultureTextVMs.Count > 1) { string primaryText = CultureTextVMs[0].Text; for (int i = 0; i < CultureTextVMs.Count; i++) { // Skip main text of primary culture, it's what we compare everything else with if (i > 0) { string transText = CultureTextVMs[i].Text; // Ignore any empty text. If that's a problem, it'll be found as missing below. if (!String.IsNullOrEmpty(transText)) { string message; if (!CheckPlaceholdersConsistency(primaryText, transText, true, out message)) { CultureTextVMs[i].IsPlaceholdersProblem = true; if (CultureTextVMs[i].AcceptPlaceholders) { IsAccepted = true; } else { HasOwnProblem = true; HasProblem = true; AddRemarks(message); } } else { CultureTextVMs[i].IsPlaceholdersProblem = false; } if (!CheckPunctuationConsistency(primaryText, transText, out message)) { CultureTextVMs[i].IsPunctuationProblem = true; if (CultureTextVMs[i].AcceptPunctuation) { IsAccepted = true; } else { HasOwnProblem = true; HasProblem = true; AddRemarks(message); } } else { CultureTextVMs[i].IsPunctuationProblem = false; } } else { // If there's no text, and it hasn't been checked, there is no problem CultureTextVMs[i].IsPlaceholdersProblem = false; CultureTextVMs[i].IsPunctuationProblem = false; } } foreach (var qt in CultureTextVMs[i].QuantifiedTextVMs) { string transText = qt.Text; // Ignore any empty text for quantified texts. if (!String.IsNullOrEmpty(transText)) { string message; if (!CheckPlaceholdersConsistency(primaryText, transText, false, out message)) // Ignore count placeholder here { qt.IsPlaceholdersProblem = true; if (qt.AcceptPlaceholders) { IsAccepted = true; } else { HasOwnProblem = true; HasProblem = true; AddRemarks(message); } } else { qt.IsPlaceholdersProblem = false; } if (!CheckPunctuationConsistency(primaryText, transText, out message)) { qt.IsPunctuationProblem = true; if (qt.AcceptPunctuation) { IsAccepted = true; } else { HasOwnProblem = true; HasProblem = true; AddRemarks(message); } } else { qt.IsPunctuationProblem = false; } } else { // If there's no text, and it hasn't been checked, there is no problem qt.IsPlaceholdersProblem = false; qt.IsPunctuationProblem = false; } } } } // ----- Check for missing translations ----- foreach (var ctVM in CultureTextVMs) { if (ctVM.CultureName.Length == 2) { // Check that every non-region culture has a text set if (String.IsNullOrEmpty(ctVM.Text)) { ctVM.IsMissing = true; if (ctVM.AcceptMissing) { IsAccepted = true; } else { HasOwnProblem = true; HasProblem = true; AddRemarks(Tx.T("validation.content.missing translation")); } } else { ctVM.IsMissing = false; } } else if (ctVM.CultureName.Length == 5) { // Check that every region-culture with no text has a non-region culture with a // text set (as fallback) if (String.IsNullOrEmpty(ctVM.Text) && !CultureTextVMs.Any(vm2 => vm2.CultureName == ctVM.CultureName.Substring(0, 2))) { ctVM.IsMissing = true; if (ctVM.AcceptMissing) { IsAccepted = true; } else { HasOwnProblem = true; HasProblem = true; AddRemarks(Tx.T("validation.content.missing translation")); } } else { ctVM.IsMissing = false; } } // Also check quantified texts for missing texts foreach (var qt in ctVM.QuantifiedTextVMs) { if (String.IsNullOrEmpty(qt.Text)) { qt.IsMissing = true; if (qt.AcceptMissing) { IsAccepted = true; } else { HasOwnProblem = true; HasProblem = true; AddRemarks(Tx.T("validation.content.missing translation")); } } else { qt.IsMissing = false; } } } return(!HasProblem); }
/// <summary> /// 建立贴图并添加到缓冲中。 /// 尽量在第一次绘制之前调用该函数,这样可以避免建立贴图的过程造成游戏的停滞 /// </summary> /// <param name="text">要创建的字符串</param> /// <param name="fontName">字体</param> /// <returns></returns> public Texture2D BuildTexture( string text, string fontName ) { TextKey key = new TextKey( text, fontName ); if (cache.ContainsKey( key )) return null; if (!fonts.ContainsKey( fontName )) { Log.Write( "error fontName used in BuildTexture" ); return null; } System.Drawing.Font font = fonts[fontName]; System.Drawing.SizeF size = mesureGraphics.MeasureString( text, font ); int texWidth = (int)size.Width; int texHeight = (int)size.Height; System.Drawing.Bitmap textMap = new System.Drawing.Bitmap( texWidth, texHeight ); System.Drawing.Graphics curGraphics = System.Drawing.Graphics.FromImage( textMap ); curGraphics.DrawString( text, font, System.Drawing.Brushes.White, new System.Drawing.PointF() ); Texture2D texture = new Texture2D( engine.Device, texWidth, texHeight, 1, TextureUsage.None, SurfaceFormat.Color ); Microsoft.Xna.Framework.Graphics.Color[] data = new Microsoft.Xna.Framework.Graphics.Color[texWidth * texHeight]; for (int y = 0; y < texHeight; y++) { for (int x = 0; x < texWidth; x++) { data[y * texWidth + x] = ConvertHelper.SysColorToXNAColor( textMap.GetPixel( x, y ) ); } } texture.SetData<Microsoft.Xna.Framework.Graphics.Color>( data ); cache.Add( key, texture ); curGraphics.Dispose(); return texture; }
/// <summary> /// 绘制包含中文字的文字 /// </summary> /// <param name="text">要绘制的文字</param> /// <param name="scrnPos">绘制的屏幕位置</param> /// <param name="rota">旋转角</param> /// <param name="scale">缩放比</param> /// <param name="color">颜色</param> /// <param name="layerDepth">绘制深度</param> /// <param name="fontName">字体名称</param> public void WriteText( string text, Vector2 scrnPos, float rota, float scale, Color color, float layerDepth, string fontName ) { Texture2D texture; TextKey key = new TextKey( text, fontName ); if (cache.ContainsKey( key )) { texture = cache[key]; } else { texture = BuildTexture( text, fontName ); } engine.SpriteMgr.alphaSprite.Draw( texture, scrnPos, null, color, rota, new Vector2( 0, 0 ), scale, SpriteEffects.None, layerDepth ); }
private void CheckNumber(IPatient patient, ILanguage language, string displayName, string dayOfWeek, int number, TextKey key) { // arrange var fears = new Katas.FearOfNumbers.FearOfNumbers(displayName); fears.AddPatient(patient); // act var actual = fears.CheckNumber(patient.Name, dayOfWeek, number); // assert Assert.Equal(language.GetText(key), actual); }
public IPasswordDialog CreatePasswordDialog(TextKey message, TextKey title) { return(new PasswordDialog(text.Get(message), text.Get(title), text)); }
private void BootstrapSequence_StatusChanged(TextKey status) { splashScreen.UpdateStatus(status, true); }
public string Get(TextKey key) { return(text.ContainsKey(key) ? text[key] : $"Could not find text for key '{key}'!"); }
public void UpdateStatus(TextKey key, bool busyIndication = false) { model.Status = text.Get(key); model.BusyIndication = busyIndication; }
private void Operations_StatusChanged(TextKey status) { splashScreen.UpdateStatus(status, true); }
public string GetText(TextKey key) { return Messages[key]; }
public IPasswordDialog CreatePasswordDialog(TextKey message, TextKey title) { return(Application.Current.Dispatcher.Invoke(() => new PasswordDialog(text.Get(message), text.Get(title), text))); }
public string Get(TextKey key) { return(cache.ContainsKey(key) ? cache[key] : $"Could not find string for key '{key}'!"); }
private void SessionSequence_StatusChanged(TextKey status) { runtimeWindow?.UpdateStatus(status, true); }
public void CheckNumber_with_Upper_Lower_Strings_English(string dayOfWeek, int number, TextKey key) { CheckNumber(GetKarl(), new EnglishLanguage(), EnglishLanguage.DisplayName, dayOfWeek, number, key); }