예제 #1
0
    public void RenameSymbol(string before, string after)
    {
        BMSymbol symbol = this.GetSymbol(before, false);

        if (symbol != null)
        {
            symbol.sequence = after;
        }
        this.MarkAsDirty();
    }
예제 #2
0
    /// <summary>
    /// Remove the specified symbol from the font.
    /// </summary>

    public void RemoveSymbol(string sequence)
    {
        BMSymbol symbol = GetSymbol(sequence, false);

        if (symbol != null)
        {
            symbols.Remove(symbol);
        }
        MarkAsChanged();
    }
예제 #3
0
    public void RemoveSymbol(string sequence)
    {
        BMSymbol item = this.GetSymbol(sequence, false);

        if (item != null)
        {
            this.symbols.Remove(item);
        }
        this.MarkAsDirty();
    }
예제 #4
0
    public void RenameSymbol(string before, string after)
    {
        BMSymbol symbol = GetSymbol(before, createIfMissing: false);

        if (symbol != null)
        {
            symbol.sequence = after;
        }
        MarkAsDirty();
    }
예제 #5
0
    /// <summary>
    /// Change an existing symbol's sequence to the specified value.
    /// </summary>

    public void RenameSymbol(string before, string after)
    {
        BMSymbol symbol = GetSymbol(before, false);

        if (symbol != null)
        {
            symbol.sequence = after;
        }
        MarkAsChanged();
    }
예제 #6
0
    public void RemoveSymbol(string sequence)
    {
        BMSymbol symbol = GetSymbol(sequence, createIfMissing: false);

        if (symbol != null)
        {
            symbols.Remove(symbol);
        }
        MarkAsDirty();
    }
예제 #7
0
    public void RemoveSymbol(String sequence)
    {
        BMSymbol symbol = this.GetSymbol(sequence, false);

        if (symbol != null)
        {
            this.symbols.Remove(symbol);
        }
        this.MarkAsChanged();
    }
예제 #8
0
    // Token: 0x06001DE8 RID: 7656 RVA: 0x000C5C74 File Offset: 0x000C3E74
    public void KOCGFIELFNJ(string KJMHINNELJJ)
    {
        BMSymbol bmsymbol = this.CHLPMCCFDPP(KJMHINNELJJ, false);

        if (bmsymbol != null)
        {
            this.OMIDEBFBQBQ.Remove(bmsymbol);
        }
        this.NPCECPIOPCB();
    }
예제 #9
0
    // Token: 0x06001DB1 RID: 7601 RVA: 0x000C4F40 File Offset: 0x000C3140
    public void HNQQNLCLMHP(string NLFQGDGEPFO, string JIDIKNLLDOO)
    {
        BMSymbol bmsymbol = this.CHLPMCCFDPP(NLFQGDGEPFO, false);

        if (bmsymbol != null)
        {
            bmsymbol.sequence = JIDIKNLLDOO;
        }
        this.NPCECPIOPCB();
    }
예제 #10
0
파일: UIFont.cs 프로젝트: midgithub/notes
    /// <summary>
    /// Add a new symbol to the font.
    /// </summary>

    public void AddSymbol(string sequence, string spriteName)
    {
        BMSymbol symbol = GetSymbol(sequence, true);

        if (symbol == null)
        {
            return;
        }
        symbol.spriteName = spriteName;
        MarkAsChanged();
    }
예제 #11
0
    static int GetSymbol(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 3);
        string   arg0 = LuaScriptMgr.GetLuaString(L, 1);
        int      arg1 = (int)LuaScriptMgr.GetNumber(L, 2);
        int      arg2 = (int)LuaScriptMgr.GetNumber(L, 3);
        BMSymbol o    = NGUIText.GetSymbol(arg0, arg1, arg2);

        LuaScriptMgr.PushObject(L, o);
        return(1);
    }
예제 #12
0
    /// <summary>
    /// Calculate the character index offset required to print the end of the specified text.
    /// </summary>

    static public int CalculateOffsetToFit(string text)
    {
        if (string.IsNullOrEmpty(text) || lineWidth < 1)
        {
            return(0);
        }

        Prepare(text);

        int textLength = text.Length, ch = 0, prev = 0;

        for (int i = 0, imax = text.Length; i < imax; ++i)
        {
            // See if there is a symbol matching this text
            BMSymbol symbol = useSymbols ? GetSymbol(text, i, textLength) : null;

            if (symbol == null)
            {
                ch = text[i];
                float w = GetGlyphWidth(ch, prev);
                if (w != 0f)
                {
                    mSizes.Add(spacingX + w);
                }
                prev = ch;
            }
            else
            {
                mSizes.Add(spacingX + symbol.advance);
                for (int b = 0, bmax = symbol.sequence.Length - 1; b < bmax; ++b)
                {
                    mSizes.Add(0);
                }
                i   += symbol.sequence.Length - 1;
                prev = 0;
            }
        }

        float remainingWidth        = NGUIText.lineWidth;
        int   currentCharacterIndex = mSizes.size;

        while (currentCharacterIndex > 0 && remainingWidth > 0)
        {
            remainingWidth -= mSizes[--currentCharacterIndex];
        }

        mSizes.Clear();

        if (remainingWidth < 0)
        {
            ++currentCharacterIndex;
        }
        return(currentCharacterIndex);
    }
예제 #13
0
 static public int MarkAsChanged(IntPtr l)
 {
     try {
         BMSymbol self = (BMSymbol)checkSelf(l);
         self.MarkAsChanged();
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #14
0
 static public int get_spriteName(IntPtr l)
 {
     try {
         BMSymbol self = (BMSymbol)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.spriteName);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #15
0
    public bool MatchSymbol(string text, int offset, int textLength, out BMSymbol symbol)
    {
        int num;
        int count = this.mSymbols.Count;

        if (count > 0)
        {
            textLength = textLength - offset;
            if (textLength > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    BMSymbol item   = this.mSymbols[i];
                    int      length = item.sequence.Length;
                    if (length != 0 && textLength >= length)
                    {
                        if (string.Compare(item.sequence, 0, text, offset, length) == 0)
                        {
                            symbol = item;
                            if (length < textLength)
                            {
                                int num1 = i + 1;
                                i = num1;
                                if (num1 < count)
                                {
                                    int num2 = length;
                                    do
                                    {
                                        item   = this.mSymbols[i];
                                        length = item.sequence.Length;
                                        if (textLength >= length && length > num2)
                                        {
                                            if (string.Compare(item.sequence, 0, text, offset, length) == 0)
                                            {
                                                num2   = length;
                                                symbol = item;
                                            }
                                        }
                                        num = i + 1;
                                        i   = num;
                                    }while (num < count);
                                }
                            }
                            return(true);
                        }
                    }
                }
            }
        }
        symbol = null;
        return(false);
    }
예제 #16
0
 static public int constructor(IntPtr l)
 {
     try {
         BMSymbol o;
         o = new BMSymbol();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #17
0
    public static LitJson.JsonData Export(BMSymbol symbol)
    {
        var data = new LitJson.JsonData();

        data["q"]  = symbol.sequence;
        data["s"]  = symbol.spriteName;
        data["ox"] = symbol.offsetX;
        data["oy"] = symbol.offsetY;
        data["w"]  = symbol.width;
        data["h"]  = symbol.height;
        data["a"]  = symbol.advance;
        return(data);
    }
예제 #18
0
파일: NGUIFont.cs 프로젝트: HMu0510/NGUIP
    /// <summary>
    /// Add a new symbol to the font.
    /// </summary>

    public void AddSymbol(string sequence, string spriteName)
    {
        var rep = replacement;

        if (rep != null)
        {
            rep.AddSymbol(sequence, spriteName); return;
        }
        BMSymbol symbol = GetSymbol(sequence, true);

        symbol.spriteName = spriteName;
        MarkAsChanged();
    }
    /// <summary>
    /// Different line wrapping functionality -- contributed by MightyM.
    /// http://www.tasharen.com/forum/index.php?topic=1049.0
    /// </summary>

    public string GetEndOfLineThatFits(string text, float maxWidth, bool encoding, SymbolStyle symbolStyle)
    {
        int lineWidth = Mathf.RoundToInt(maxWidth * size);

        if (lineWidth < 1)
        {
            return(text);
        }

        int     textLength            = text.Length;
        int     remainingWidth        = lineWidth;
        BMGlyph followingGlyph        = null;
        int     currentCharacterIndex = textLength;

        while (currentCharacterIndex > 0 && remainingWidth > 0)
        {
            char currentCharacter = text[--currentCharacterIndex];

            // See if there is a symbol matching this text
            BMSymbol symbol = (encoding && symbolStyle != SymbolStyle.None) ? mFont.MatchSymbol(text, currentCharacterIndex, textLength) : null;

            // Find the glyph for this character
            BMGlyph glyph = (symbol == null) ? mFont.GetGlyph(currentCharacter) : null;

            // Calculate how wide this symbol or character is going to be
            int glyphWidth = mSpacingX;

            if (symbol != null)
            {
                glyphWidth += symbol.width;
            }
            else if (glyph != null)
            {
                glyphWidth    += glyph.advance + ((followingGlyph == null) ? 0 : followingGlyph.GetKerning(currentCharacter));
                followingGlyph = glyph;
            }
            else
            {
                followingGlyph = null;
                continue;
            }

            // Remaining width after this glyph gets printed
            remainingWidth -= glyphWidth;
        }
        if (remainingWidth < 0)
        {
            ++currentCharacterIndex;
        }
        return(text.Substring(currentCharacterIndex, textLength - currentCharacterIndex));
    }
예제 #20
0
 static public int set_spriteName(IntPtr l)
 {
     try {
         BMSymbol      self = (BMSymbol)checkSelf(l);
         System.String v;
         checkType(l, 2, out v);
         self.spriteName = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #21
0
 static public int Validate(IntPtr l)
 {
     try {
         BMSymbol self = (BMSymbol)checkSelf(l);
         UIAtlas  a1;
         checkType(l, 2, out a1);
         var ret = self.Validate(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #22
0
파일: NGUIFont.cs 프로젝트: HMu0510/NGUIP
    /// <summary>
    /// Remove the specified symbol from the font.
    /// </summary>

    public void RemoveSymbol(string sequence)
    {
        var rep = replacement;

        if (rep != null)
        {
            rep.RemoveSymbol(sequence); return;
        }
        BMSymbol symbol = GetSymbol(sequence, false);

        if (symbol != null)
        {
            symbols.Remove(symbol);
        }
        MarkAsChanged();
    }
예제 #23
0
파일: NGUIFont.cs 프로젝트: HMu0510/NGUIP
    /// <summary>
    /// Change an existing symbol's sequence to the specified value.
    /// </summary>

    public void RenameSymbol(string before, string after)
    {
        var rep = replacement;

        if (rep != null)
        {
            rep.RenameSymbol(before, after); return;
        }
        BMSymbol symbol = GetSymbol(before, false);

        if (symbol != null)
        {
            symbol.sequence = after;
        }
        MarkAsChanged();
    }
예제 #24
0
    // Token: 0x060006C8 RID: 1736 RVA: 0x00037B54 File Offset: 0x00035D54
    public void RenameSymbol(string before, string after)
    {
        INGUIFont replacement = this.replacement;

        if (replacement != null)
        {
            replacement.RenameSymbol(before, after);
            return;
        }
        BMSymbol symbol = this.GetSymbol(before, false);

        if (symbol != null)
        {
            symbol.sequence = after;
        }
        this.MarkAsChanged();
    }
예제 #25
0
    // Token: 0x060006C7 RID: 1735 RVA: 0x00037B14 File Offset: 0x00035D14
    public void RemoveSymbol(string sequence)
    {
        INGUIFont replacement = this.replacement;

        if (replacement != null)
        {
            replacement.RemoveSymbol(sequence);
            return;
        }
        BMSymbol symbol = this.GetSymbol(sequence, false);

        if (symbol != null)
        {
            this.symbols.Remove(symbol);
        }
        this.MarkAsChanged();
    }
예제 #26
0
 static int GetSymbol(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         string   arg0 = ToLua.CheckString(L, 1);
         int      arg1 = (int)LuaDLL.luaL_checknumber(L, 2);
         int      arg2 = (int)LuaDLL.luaL_checknumber(L, 3);
         BMSymbol o    = NGUIText.GetSymbol(arg0, arg1, arg2);
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
예제 #27
0
 public override void Unity_Deserialize(int depth)
 {
     if (depth <= 7)
     {
         this.mMat = (SerializedStateReader.Instance.ReadUnityEngineObject() as Material);
     }
     if (depth <= 7)
     {
         this.mUVRect.Unity_Deserialize(depth + 1);
     }
     SerializedStateReader.Instance.Align();
     if (depth <= 7)
     {
         if (this.mFont == null)
         {
             this.mFont = new BMFont();
         }
         this.mFont.Unity_Deserialize(depth + 1);
     }
     if (depth <= 7)
     {
         this.mAtlas = (SerializedStateReader.Instance.ReadUnityEngineObject() as UIAtlas);
     }
     if (depth <= 7)
     {
         this.mReplacement = (SerializedStateReader.Instance.ReadUnityEngineObject() as UIFont);
     }
     if (depth <= 7)
     {
         int num = SerializedStateReader.Instance.ReadInt32();
         this.mSymbols = new List <BMSymbol>(num);
         for (int i = 0; i < num; i++)
         {
             BMSymbol bMSymbol = new BMSymbol();
             bMSymbol.Unity_Deserialize(depth + 1);
             this.mSymbols.Add(bMSymbol);
         }
     }
     if (depth <= 7)
     {
         this.mDynamicFont = (SerializedStateReader.Instance.ReadUnityEngineObject() as Font);
     }
     this.mDynamicFontSize  = SerializedStateReader.Instance.ReadInt32();
     this.mDynamicFontStyle = (FontStyle)SerializedStateReader.Instance.ReadInt32();
 }
예제 #28
0
 static int MatchSymbol(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 4);
         UIFont   obj  = (UIFont)ToLua.CheckObject <UIFont>(L, 1);
         string   arg0 = ToLua.CheckString(L, 2);
         int      arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
         int      arg2 = (int)LuaDLL.luaL_checknumber(L, 4);
         BMSymbol o    = obj.MatchSymbol(arg0, arg1, arg2);
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
예제 #29
0
    private void LoadEmojis()
    {
        if (mAtlas == null || Utils.IsNullOrEmpty(mAtlas.spriteList))
        {
            return;
        }

        mEmojis.Clear();
        var spriteList = mAtlas.spriteList;

        for (int i = 0; i < spriteList.Count; i++)
        {
            BMSymbol sym = new BMSymbol()
            {
                sequence = "[#" + spriteList[i].name + "]", spriteName = spriteList[i].name
            };
            mEmojis.Add(new EmojiVO(sym));
        }
    }
예제 #30
0
    /// <summary>
    /// Retrieve the symbol at the beginning of the specified sequence, if a match is found.
    /// </summary>

    public BMSymbol MatchSymbol(string text, int offset, int textLength)
    {
        // No symbols present
        int count = mSymbols.Count;

        if (count == 0)
        {
            return(null);
        }
        textLength -= offset;

        // Run through all symbols
        for (int i = 0; i < count; ++i)
        {
            BMSymbol sym = mSymbols[i];

            // If the symbol's length is longer, move on
            int symbolLength = sym.length;
            if (symbolLength == 0 || textLength < symbolLength)
            {
                continue;
            }

            bool match = true;

            // Match the characters
            for (int c = 0; c < symbolLength; ++c)
            {
                if (text[offset + c] != sym.sequence[c])
                {
                    match = false;
                    break;
                }
            }

            // Match found
            if (match && sym.Validate(atlas))
            {
                return(sym);
            }
        }
        return(null);
    }
예제 #31
0
	public override void OnInspectorGUI ()
	{
		mFont = target as UIFont;
		NGUIEditorTools.SetLabelWidth(80f);

		GUILayout.Space(6f);

		if (mFont.replacement != null)
		{
			mType = FontType.Reference;
			mReplacement = mFont.replacement;
		}
		else if (mFont.dynamicFont != null)
		{
			mType = FontType.Dynamic;
		}

		GUI.changed = false;
		GUILayout.BeginHorizontal();
		mType = (FontType)EditorGUILayout.EnumPopup("Font Type", mType);
		NGUIEditorTools.DrawPadding();
		GUILayout.EndHorizontal();

		if (GUI.changed)
		{
			if (mType == FontType.Bitmap)
				OnSelectFont(null);

			if (mType != FontType.Dynamic && mFont.dynamicFont != null)
				mFont.dynamicFont = null;
		}

		if (mType == FontType.Reference)
		{
			ComponentSelector.Draw<UIFont>(mFont.replacement, OnSelectFont, true);

			GUILayout.Space(6f);
			EditorGUILayout.HelpBox("You can have one font simply point to " +
				"another one. This is useful if you want to be " +
				"able to quickly replace the contents of one " +
				"font with another one, for example for " +
				"swapping an SD font with an HD one, or " +
				"replacing an English font with a Chinese " +
				"one. All the labels referencing this font " +
				"will update their references to the new one.", MessageType.Info);

			if (mReplacement != mFont && mFont.replacement != mReplacement)
			{
				NGUIEditorTools.RegisterUndo("Font Change", mFont);
				mFont.replacement = mReplacement;
				NGUITools.SetDirty(mFont);
			}
			return;
		}
		else if (mType == FontType.Dynamic)
		{
#if UNITY_3_5
			EditorGUILayout.HelpBox("Dynamic fonts require Unity 4.0 or higher.", MessageType.Error);
#else
			Font fnt = EditorGUILayout.ObjectField("TTF Font", mFont.dynamicFont, typeof(Font), false) as Font;
			
			if (fnt != mFont.dynamicFont)
			{
				NGUIEditorTools.RegisterUndo("Font change", mFont);
				mFont.dynamicFont = fnt;
			}

			Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material;

			if (mFont.material != mat)
			{
				NGUIEditorTools.RegisterUndo("Font Material", mFont);
				mFont.material = mat;
			}

			GUILayout.BeginHorizontal();
			int size = EditorGUILayout.IntField("Default Size", mFont.defaultSize, GUILayout.Width(120f));
			FontStyle style = (FontStyle)EditorGUILayout.EnumPopup(mFont.dynamicFontStyle);
			NGUIEditorTools.DrawPadding();
			GUILayout.EndHorizontal();

			if (size != mFont.defaultSize)
			{
				NGUIEditorTools.RegisterUndo("Font change", mFont);
				mFont.defaultSize = size;
			}

			if (style != mFont.dynamicFontStyle)
			{
				NGUIEditorTools.RegisterUndo("Font change", mFont);
				mFont.dynamicFontStyle = style;
			}
#endif
		}
		else
		{
			ComponentSelector.Draw<UIAtlas>(mFont.atlas, OnSelectAtlas, true);

			if (mFont.atlas != null)
			{
				if (mFont.bmFont.isValid)
				{
					NGUIEditorTools.DrawAdvancedSpriteField(mFont.atlas, mFont.spriteName, SelectSprite, false);
				}
				EditorGUILayout.Space();
			}
			else
			{
				// No atlas specified -- set the material and texture rectangle directly
				Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material;

				if (mFont.material != mat)
				{
					NGUIEditorTools.RegisterUndo("Font Material", mFont);
					mFont.material = mat;
				}
			}

			// For updating the font's data when importing from an external source, such as the texture packer
			bool resetWidthHeight = false;

			if (mFont.atlas != null || mFont.material != null)
			{
				TextAsset data = EditorGUILayout.ObjectField("Import Data", null, typeof(TextAsset), false) as TextAsset;

				if (data != null)
				{
					NGUIEditorTools.RegisterUndo("Import Font Data", mFont);
					BMFontReader.Load(mFont.bmFont, NGUITools.GetHierarchy(mFont.gameObject), data.bytes);
					mFont.MarkAsChanged();
					resetWidthHeight = true;
					Debug.Log("Imported " + mFont.bmFont.glyphCount + " characters");
				}
			}

			if (mFont.bmFont.isValid)
			{
				Texture2D tex = mFont.texture;

				if (tex != null && mFont.atlas == null)
				{
					// Pixels are easier to work with than UVs
					Rect pixels = NGUIMath.ConvertToPixels(mFont.uvRect, tex.width, tex.height, false);

					// Automatically set the width and height of the rectangle to be the original font texture's dimensions
					if (resetWidthHeight)
					{
						pixels.width = mFont.texWidth;
						pixels.height = mFont.texHeight;
					}

					// Font sprite rectangle
					pixels = EditorGUILayout.RectField("Pixel Rect", pixels);

					// Convert the pixel coordinates back to UV coordinates
					Rect uvRect = NGUIMath.ConvertToTexCoords(pixels, tex.width, tex.height);

					if (mFont.uvRect != uvRect)
					{
						NGUIEditorTools.RegisterUndo("Font Pixel Rect", mFont);
						mFont.uvRect = uvRect;
					}
					//NGUIEditorTools.DrawSeparator();
					EditorGUILayout.Space();
				}
			}
		}

		// Dynamic fonts don't support emoticons
		if (!mFont.isDynamic && mFont.bmFont.isValid)
		{
			if (mFont.atlas != null)
			{
				if (NGUIEditorTools.DrawHeader("Symbols and Emoticons"))
				{
					NGUIEditorTools.BeginContents();

					List<BMSymbol> symbols = mFont.symbols;

					for (int i = 0; i < symbols.Count; )
					{
						BMSymbol sym = symbols[i];

						GUILayout.BeginHorizontal();
						GUILayout.Label(sym.sequence, GUILayout.Width(40f));
						if (NGUIEditorTools.DrawSpriteField(mFont.atlas, sym.spriteName, ChangeSymbolSprite, GUILayout.MinWidth(100f)))
							mSelectedSymbol = sym;

						if (GUILayout.Button("Edit", GUILayout.Width(40f)))
						{
							if (mFont.atlas != null)
							{
								NGUISettings.atlas = mFont.atlas;
								NGUISettings.selectedSprite = sym.spriteName;
								NGUIEditorTools.Select(mFont.atlas.gameObject);
							}
						}

						GUI.backgroundColor = Color.red;

						if (GUILayout.Button("X", GUILayout.Width(22f)))
						{
							NGUIEditorTools.RegisterUndo("Remove symbol", mFont);
							mSymbolSequence = sym.sequence;
							mSymbolSprite = sym.spriteName;
							symbols.Remove(sym);
							mFont.MarkAsChanged();
						}
						GUI.backgroundColor = Color.white;
						GUILayout.EndHorizontal();
						GUILayout.Space(4f);
						++i;
					}

					if (symbols.Count > 0)
					{
						GUILayout.Space(6f);
					}

					GUILayout.BeginHorizontal();
					mSymbolSequence = EditorGUILayout.TextField(mSymbolSequence, GUILayout.Width(40f));
					NGUIEditorTools.DrawSpriteField(mFont.atlas, mSymbolSprite, SelectSymbolSprite);

					bool isValid = !string.IsNullOrEmpty(mSymbolSequence) && !string.IsNullOrEmpty(mSymbolSprite);
					GUI.backgroundColor = isValid ? Color.green : Color.grey;

					if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid)
					{
						NGUIEditorTools.RegisterUndo("Add symbol", mFont);
						mFont.AddSymbol(mSymbolSequence, mSymbolSprite);
						mFont.MarkAsChanged();
						mSymbolSequence = "";
						mSymbolSprite = "";
					}
					GUI.backgroundColor = Color.white;
					GUILayout.EndHorizontal();

					if (symbols.Count == 0)
					{
						EditorGUILayout.HelpBox("Want to add an emoticon to your font? In the field above type ':)', choose a sprite, then hit the Add button.", MessageType.Info);
					}
					else GUILayout.Space(4f);

					NGUIEditorTools.EndContents();
				}
			}
		}

		if (mFont.bmFont != null && mFont.bmFont.isValid)
		{
			if (NGUIEditorTools.DrawHeader("Modify"))
			{
				NGUIEditorTools.BeginContents();

				UISpriteData sd = mFont.sprite;

				bool disable = (sd != null && (sd.paddingLeft != 0 || sd.paddingBottom != 0));
				EditorGUI.BeginDisabledGroup(disable || mFont.packedFontShader);

				EditorGUILayout.BeginHorizontal();
				GUILayout.Space(20f);
				EditorGUILayout.BeginVertical();

				GUILayout.BeginHorizontal();
				GUILayout.BeginVertical();
				NGUISettings.foregroundColor = EditorGUILayout.ColorField("Foreground", NGUISettings.foregroundColor);
				NGUISettings.backgroundColor = EditorGUILayout.ColorField("Background", NGUISettings.backgroundColor);
				GUILayout.EndVertical();
				mCurve = EditorGUILayout.CurveField("", mCurve, GUILayout.Width(40f), GUILayout.Height(40f));
				GUILayout.EndHorizontal();

				if (GUILayout.Button("Add a Shadow")) ApplyEffect(Effect.Shadow, NGUISettings.foregroundColor, NGUISettings.backgroundColor);
				if (GUILayout.Button("Add a Soft Outline")) ApplyEffect(Effect.Outline, NGUISettings.foregroundColor, NGUISettings.backgroundColor);
				if (GUILayout.Button("Rebalance Colors")) ApplyEffect(Effect.Rebalance, NGUISettings.foregroundColor, NGUISettings.backgroundColor);
				if (GUILayout.Button("Apply Curve to Alpha")) ApplyEffect(Effect.AlphaCurve, NGUISettings.foregroundColor, NGUISettings.backgroundColor);
				if (GUILayout.Button("Apply Curve to Foreground")) ApplyEffect(Effect.ForegroundCurve, NGUISettings.foregroundColor, NGUISettings.backgroundColor);
				if (GUILayout.Button("Apply Curve to Background")) ApplyEffect(Effect.BackgroundCurve, NGUISettings.foregroundColor, NGUISettings.backgroundColor);

				GUILayout.Space(10f);
				if (GUILayout.Button("Add Transparent Border (+1)")) ApplyEffect(Effect.Border, NGUISettings.foregroundColor, NGUISettings.backgroundColor);
				if (GUILayout.Button("Remove Border (-1)")) ApplyEffect(Effect.Crop, NGUISettings.foregroundColor, NGUISettings.backgroundColor);

				EditorGUILayout.EndVertical();
				GUILayout.Space(20f);
				EditorGUILayout.EndHorizontal();

				EditorGUI.EndDisabledGroup();

				if (disable)
				{
					GUILayout.Space(3f);
					EditorGUILayout.HelpBox("The sprite used by this font has been trimmed and is not suitable for modification. " +
						"Try re-adding this sprite with 'Trim Alpha' disabled.", MessageType.Warning);
				}

				NGUIEditorTools.EndContents();
			}
		}

		// The font must be valid at this point for the rest of the options to show up
		if (mFont.isDynamic || mFont.bmFont.isValid)
		{
			if (mFont.atlas == null)
			{
				mView = View.Font;
				mUseShader = false;
			}
		}

		// Preview option
		if (!mFont.isDynamic && mFont.atlas != null)
		{
			GUILayout.BeginHorizontal();
			{
				mView = (View)EditorGUILayout.EnumPopup("Preview", mView);
				GUILayout.Label("Shader", GUILayout.Width(45f));
				mUseShader = EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f));
			}
			GUILayout.EndHorizontal();
		}
	}
예제 #32
0
    public override void OnInspectorGUI()
    {
        mFont = target as UIFont;
        NGUIEditorTools.SetLabelWidth(80f);

        GUILayout.Space(6f);

        if (mFont.replacement != null)
        {
            mType = FontType.Reference;
            mReplacement = mFont.replacement;
        }
        else if (mFont.dynamicFont != null)
        {
            mType = FontType.Dynamic;
        }

        GUILayout.BeginHorizontal();
        FontType fontType = (FontType)EditorGUILayout.EnumPopup("Font Type", mType);
        GUILayout.Space(18f);
        GUILayout.EndHorizontal();

        if (mType != fontType)
        {
            if (fontType == FontType.Normal)
            {
                OnSelectFont(null);
            }
            else
            {
                mType = fontType;
            }

            if (mType != FontType.Dynamic && mFont.dynamicFont != null)
                mFont.dynamicFont = null;
        }

        if (mType == FontType.Reference)
        {
            ComponentSelector.Draw<UIFont>(mFont.replacement, OnSelectFont);

            GUILayout.Space(6f);
            EditorGUILayout.HelpBox("You can have one font simply point to " +
                "another one. This is useful if you want to be " +
                "able to quickly replace the contents of one " +
                "font with another one, for example for " +
                "swapping an SD font with an HD one, or " +
                "replacing an English font with a Chinese " +
                "one. All the labels referencing this font " +
                "will update their references to the new one.", MessageType.Info);

            if (mReplacement != mFont && mFont.replacement != mReplacement)
            {
                NGUIEditorTools.RegisterUndo("Font Change", mFont);
                mFont.replacement = mReplacement;
                UnityEditor.EditorUtility.SetDirty(mFont);
            }
            return;
        }
        else if (mType == FontType.Dynamic)
        {
        #if UNITY_3_5
            EditorGUILayout.HelpBox("Dynamic fonts require Unity 4.0 or higher.", MessageType.Error);
        #else
            Font fnt = EditorGUILayout.ObjectField("TTF Font", mFont.dynamicFont, typeof(Font), false) as Font;

            if (fnt != mFont.dynamicFont)
            {
                NGUIEditorTools.RegisterUndo("Font change", mFont);
                mFont.dynamicFont = fnt;
            }

            Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material;

            if (mFont.material != mat)
            {
                NGUIEditorTools.RegisterUndo("Font Material", mFont);
                mFont.material = mat;
            }

            GUILayout.BeginHorizontal();
            int size = EditorGUILayout.IntField("Size", mFont.dynamicFontSize, GUILayout.Width(120f));
            FontStyle style = (FontStyle)EditorGUILayout.EnumPopup(mFont.dynamicFontStyle);
            GUILayout.Space(18f);
            GUILayout.EndHorizontal();

            if (size != mFont.dynamicFontSize)
            {
                NGUIEditorTools.RegisterUndo("Font change", mFont);
                mFont.dynamicFontSize = size;
            }

            if (style != mFont.dynamicFontStyle)
            {
                NGUIEditorTools.RegisterUndo("Font change", mFont);
                mFont.dynamicFontStyle = style;
            }
        #endif
        }
        else
        {
            NGUIEditorTools.DrawSeparator();

            ComponentSelector.Draw<UIAtlas>(mFont.atlas, OnSelectAtlas);

            if (mFont.atlas != null)
            {
                if (mFont.bmFont.isValid)
                {
                    NGUIEditorTools.AdvancedSpriteField(mFont.atlas, mFont.spriteName, SelectSprite, false);
                }
                EditorGUILayout.Space();
            }
            else
            {
                // No atlas specified -- set the material and texture rectangle directly
                Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material;

                if (mFont.material != mat)
                {
                    NGUIEditorTools.RegisterUndo("Font Material", mFont);
                    mFont.material = mat;
                }
            }

            // For updating the font's data when importing from an external source, such as the texture packer
            bool resetWidthHeight = false;

            if (mFont.atlas != null || mFont.material != null)
            {
                TextAsset data = EditorGUILayout.ObjectField("Import Data", null, typeof(TextAsset), false) as TextAsset;

                if (data != null)
                {
                    NGUIEditorTools.RegisterUndo("Import Font Data", mFont);
                    BMFontReader.Load(mFont.bmFont, NGUITools.GetHierarchy(mFont.gameObject), data.bytes);
                    mFont.MarkAsDirty();
                    resetWidthHeight = true;
                    Debug.Log("Imported " + mFont.bmFont.glyphCount + " characters");
                }
            }

            if (mFont.bmFont.isValid)
            {
                Color green = new Color(0.4f, 1f, 0f, 1f);
                Texture2D tex = mFont.texture;

                if (tex != null)
                {
                    if (mFont.atlas == null)
                    {
                        // Pixels are easier to work with than UVs
                        Rect pixels = NGUIMath.ConvertToPixels(mFont.uvRect, tex.width, tex.height, false);

                        // Automatically set the width and height of the rectangle to be the original font texture's dimensions
                        if (resetWidthHeight)
                        {
                            pixels.width = mFont.texWidth;
                            pixels.height = mFont.texHeight;
                        }

                        // Font sprite rectangle
                        GUI.backgroundColor = green;
                        pixels = EditorGUILayout.RectField("Pixel Rect", pixels);
                        GUI.backgroundColor = Color.white;

                        // Create a button that can make the coordinates pixel-perfect on click
                        GUILayout.BeginHorizontal();
                        {
                            Rect corrected = NGUIMath.MakePixelPerfect(pixels);

                            if (corrected == pixels)
                            {
                                GUI.color = Color.grey;
                                GUILayout.Button("Make Pixel-Perfect");
                                GUI.color = Color.white;
                            }
                            else if (GUILayout.Button("Make Pixel-Perfect"))
                            {
                                pixels = corrected;
                                GUI.changed = true;
                            }
                        }
                        GUILayout.EndHorizontal();

                        // Convert the pixel coordinates back to UV coordinates
                        Rect uvRect = NGUIMath.ConvertToTexCoords(pixels, tex.width, tex.height);

                        if (mFont.uvRect != uvRect)
                        {
                            NGUIEditorTools.RegisterUndo("Font Pixel Rect", mFont);
                            mFont.uvRect = uvRect;
                        }
                        //NGUIEditorTools.DrawSeparator();
                        EditorGUILayout.Space();
                    }
                }
            }
        }

        // The font must be valid at this point for the rest of the options to show up
        if (mFont.isDynamic || mFont.bmFont.isValid)
        {
            // Font spacing
            GUILayout.BeginHorizontal();
            {
                NGUIEditorTools.SetLabelWidth(0f);
                GUILayout.Label("Spacing", GUILayout.Width(60f));
                GUILayout.Label("X", GUILayout.Width(12f));
                int x = EditorGUILayout.IntField(mFont.horizontalSpacing);
                GUILayout.Label("Y", GUILayout.Width(12f));
                int y = EditorGUILayout.IntField(mFont.verticalSpacing);
                GUILayout.Space(18f);
                NGUIEditorTools.SetLabelWidth(80f);

                if (mFont.horizontalSpacing != x || mFont.verticalSpacing != y)
                {
                    NGUIEditorTools.RegisterUndo("Font Spacing", mFont);
                    mFont.horizontalSpacing = x;
                    mFont.verticalSpacing = y;
                }
            }
            GUILayout.EndHorizontal();

            if (mFont.atlas == null)
            {
                mView = View.Font;
                mUseShader = false;

                float pixelSize = EditorGUILayout.FloatField("Pixel Size", mFont.pixelSize, GUILayout.Width(120f));

                if (pixelSize != mFont.pixelSize)
                {
                    NGUIEditorTools.RegisterUndo("Font Change", mFont);
                    mFont.pixelSize = pixelSize;
                }
            }
            EditorGUILayout.Space();
        }

        // Preview option
        if (!mFont.isDynamic && mFont.atlas != null)
        {
            GUILayout.BeginHorizontal();
            {
                mView = (View)EditorGUILayout.EnumPopup("Preview", mView);
                GUILayout.Label("Shader", GUILayout.Width(45f));
                mUseShader = EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f));
            }
            GUILayout.EndHorizontal();
        }

        // Dynamic fonts don't support emoticons
        if (!mFont.isDynamic && mFont.bmFont.isValid)
        {
            if (mFont.atlas != null)
            {
                if (NGUIEditorTools.DrawHeader("Symbols and Emoticons"))
                {
                    NGUIEditorTools.BeginContents();

                    List<BMSymbol> symbols = mFont.symbols;

                    for (int i = 0; i < symbols.Count; )
                    {
                        BMSymbol sym = symbols[i];

                        GUILayout.BeginHorizontal();
                        GUILayout.Label(sym.sequence, GUILayout.Width(40f));
                        if (NGUIEditorTools.SimpleSpriteField(mFont.atlas, sym.spriteName, ChangeSymbolSprite))
                            mSelectedSymbol = sym;

                        if (GUILayout.Button("Edit", GUILayout.Width(40f)))
                        {
                            if (mFont.atlas != null)
                            {
                                NGUISettings.selectedSprite = sym.spriteName;
                                NGUIEditorTools.Select(mFont.atlas.gameObject);
                            }
                        }

                        GUI.backgroundColor = Color.red;

                        if (GUILayout.Button("X", GUILayout.Width(22f)))
                        {
                            NGUIEditorTools.RegisterUndo("Remove symbol", mFont);
                            mSymbolSequence = sym.sequence;
                            mSymbolSprite = sym.spriteName;
                            symbols.Remove(sym);
                            mFont.MarkAsDirty();
                        }
                        GUI.backgroundColor = Color.white;
                        GUILayout.EndHorizontal();
                        GUILayout.Space(4f);
                        ++i;
                    }

                    if (symbols.Count > 0)
                    {
                        GUILayout.Space(6f);
                    }

                    GUILayout.BeginHorizontal();
                    mSymbolSequence = EditorGUILayout.TextField(mSymbolSequence, GUILayout.Width(40f));
                    NGUIEditorTools.SimpleSpriteField(mFont.atlas, mSymbolSprite, SelectSymbolSprite);

                    bool isValid = !string.IsNullOrEmpty(mSymbolSequence) && !string.IsNullOrEmpty(mSymbolSprite);
                    GUI.backgroundColor = isValid ? Color.green : Color.grey;

                    if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid)
                    {
                        NGUIEditorTools.RegisterUndo("Add symbol", mFont);
                        mFont.AddSymbol(mSymbolSequence, mSymbolSprite);
                        mFont.MarkAsDirty();
                        mSymbolSequence = "";
                        mSymbolSprite = "";
                    }
                    GUI.backgroundColor = Color.white;
                    GUILayout.EndHorizontal();

                    if (symbols.Count == 0)
                    {
                        EditorGUILayout.HelpBox("Want to add an emoticon to your font? In the field above type ':)', choose a sprite, then hit the Add button.", MessageType.Info);
                    }
                    else GUILayout.Space(4f);

                    NGUIEditorTools.EndContents();
                }
            }
        }
    }
예제 #33
0
	override public void OnInspectorGUI ()
	{
		mFont = target as UIFont;
		EditorGUIUtility.LookLikeControls(80f);

		NGUIEditorTools.DrawSeparator();

        //UNISIP
        if (mFont.dynamicFont != null)
        {
            mType = FontType.Dynamic;
        }

        if (mFont.replacement != null)
        {
            mType = FontType.Reference;
            mReplacement = mFont.replacement;
        }

		FontType after = (FontType)EditorGUILayout.EnumPopup("Font Type", mType);

        if (mType != after)
        {
            if (after == FontType.Normal)
            {
                OnSelectFont(null);
            }
            else
            {
                mType = after;
            }

            //UNISIP
            if (mType != FontType.Dynamic && mFont.dynamicFont != null)
                mFont.dynamicFont = null;
        }

        //UNISIP
        if (mType == FontType.Dynamic)
        {
            //UNISIP - Draw settings for dynamic font
            bool changed = false;
            Font f = EditorGUILayout.ObjectField("Font", mFont.dynamicFont, typeof(Font), false) as Font;
            if (f != mFont.dynamicFont)
            {
                mFont.dynamicFont = f;
                changed = true;
            }

            Material mat = EditorGUILayout.ObjectField("Material", mFont.dynamicFontMaterial, typeof(Material), false) as Material;
            if (mat != mFont.dynamicFontMaterial)
            {
                mFont.dynamicFontMaterial = mat;
                changed = true;
            }
            if (mFont.dynamicFontMaterial == null)
                GUILayout.Label("Warning: no coloring or clipping when using default font material");

            int i = EditorGUILayout.IntField("Size", mFont.dynamicFontSize);
            if (i != mFont.dynamicFontSize)
            {
                mFont.dynamicFontSize = i;
                changed = true;
            }

            FontStyle style = (FontStyle)EditorGUILayout.EnumPopup("Style", mFont.dynamicFontStyle);
            if (style != mFont.dynamicFontStyle)
            {
                mFont.dynamicFontStyle = style;
                changed = true;
            }

            if (changed)
            {
                //force access to material property as it refreshes the texture assignment
                Mogo.Util.LoggerHelper.Debug("font changed...");
                Material fontMat = mFont.material;
                if (fontMat.mainTexture == null)
                    Mogo.Util.LoggerHelper.Debug("font material texture issue...");
                UIFont.OnFontRebuilt(mFont);
            }

            NGUIEditorTools.DrawSeparator();

            // Font spacing
            GUILayout.BeginHorizontal();
            {
                EditorGUIUtility.LookLikeControls(0f);
                GUILayout.Label("Spacing", GUILayout.Width(60f));
                GUILayout.Label("X", GUILayout.Width(12f));
                int x = EditorGUILayout.IntField(mFont.horizontalSpacing);
                GUILayout.Label("Y", GUILayout.Width(12f));
                int y = EditorGUILayout.IntField(mFont.verticalSpacing);
                EditorGUIUtility.LookLikeControls(80f);

                if (mFont.horizontalSpacing != x || mFont.verticalSpacing != y)
                {
                    NGUIEditorTools.RegisterUndo("Font Spacing", mFont);
                    mFont.horizontalSpacing = x;
                    mFont.verticalSpacing = y;
                }
            }
            GUILayout.EndHorizontal();
        }

		if (mType == FontType.Reference)
		{
			ComponentSelector.Draw<UIFont>(mFont.replacement, OnSelectFont);

			NGUIEditorTools.DrawSeparator();
			GUILayout.Label("You can have one font simply point to\n" +
				"another one. This is useful if you want to be\n" +
				"able to quickly replace the contents of one\n" +
				"font with another one, for example for\n" +
				"swapping an SD font with an HD one, or\n" +
				"replacing an English font with a Chinese\n" +
				"one. All the labels referencing this font\n" +
				"will update their references to the new one.");

			if (mReplacement != mFont && mFont.replacement != mReplacement)
			{
				NGUIEditorTools.RegisterUndo("Font Change", mFont);
				mFont.replacement = mReplacement;
				UnityEditor.EditorUtility.SetDirty(mFont);
			}
			return;
		}

        if (mType != FontType.Dynamic)
        {
            NGUIEditorTools.DrawSeparator();
            ComponentSelector.Draw<UIAtlas>(mFont.atlas, OnSelectAtlas);

            if (mFont.atlas != null)
            {
                //if (mFont.bmFont.LegacyCheck())
                //{
                //    Mogo.Util.LoggerHelper.Debug(mFont.name + " uses a legacy font data structure. Upgrading, please save.");
                //    EditorUtility.SetDirty(mFont);
                //}

                if (mFont.bmFont.isValid)
                {
                    NGUIEditorTools.AdvancedSpriteField(mFont.atlas, mFont.spriteName, SelectSprite, false);
                }
            }
            else
            {
                // No atlas specified -- set the material and texture rectangle directly
                Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material;

                if (mFont.material != mat)
                {
                    NGUIEditorTools.RegisterUndo("Font Material", mFont);
                    mFont.material = mat;
                }
            }

            bool resetWidthHeight = false;

            if (mFont.atlas != null || mFont.material != null)
            {
                TextAsset data = EditorGUILayout.ObjectField("Import Font", null, typeof(TextAsset), false) as TextAsset;

                if (data != null)
                {
                    NGUIEditorTools.RegisterUndo("Import Font Data", mFont);
                    BMFontReader.Load(mFont.bmFont, NGUITools.GetHierarchy(mFont.gameObject), data.bytes);
                    mFont.MarkAsDirty();
                    resetWidthHeight = true;
                    Mogo.Util.LoggerHelper.Debug("Imported " + mFont.bmFont.glyphCount + " characters");
                }
            }

            if (mFont.bmFont.isValid)
            {
                Color green = new Color(0.4f, 1f, 0f, 1f);
                Texture2D tex = mFont.texture;

                if (tex != null)
                {
                    if (mFont.atlas == null)
                    {
                        // Pixels are easier to work with than UVs
                        Rect pixels = NGUIMath.ConvertToPixels(mFont.uvRect, tex.width, tex.height, false);

                        // Automatically set the width and height of the rectangle to be the original font texture's dimensions
                        if (resetWidthHeight)
                        {
                            pixels.width = mFont.texWidth;
                            pixels.height = mFont.texHeight;
                        }

                        // Font sprite rectangle
                        GUI.backgroundColor = green;
                        pixels = EditorGUILayout.RectField("Pixel Rect", pixels);
                        GUI.backgroundColor = Color.white;

                        // Create a button that can make the coordinates pixel-perfect on click
                        GUILayout.BeginHorizontal();
                        {
                            GUILayout.Label("Correction", GUILayout.Width(75f));

                            Rect corrected = NGUIMath.MakePixelPerfect(pixels);

                            if (corrected == pixels)
                            {
                                GUI.color = Color.grey;
                                GUILayout.Button("Make Pixel-Perfect");
                                GUI.color = Color.white;
                            }
                            else if (GUILayout.Button("Make Pixel-Perfect"))
                            {
                                pixels = corrected;
                                GUI.changed = true;
                            }
                        }
                        GUILayout.EndHorizontal();

                        // Convert the pixel coordinates back to UV coordinates
                        Rect uvRect = NGUIMath.ConvertToTexCoords(pixels, tex.width, tex.height);

                        if (mFont.uvRect != uvRect)
                        {
                            NGUIEditorTools.RegisterUndo("Font Pixel Rect", mFont);
                            mFont.uvRect = uvRect;
                        }
                    }

                    // Font spacing
                    GUILayout.BeginHorizontal();
                    {
                        EditorGUIUtility.LookLikeControls(0f);
                        GUILayout.Label("Spacing", GUILayout.Width(60f));
                        GUILayout.Label("X", GUILayout.Width(12f));
                        int x = EditorGUILayout.IntField(mFont.horizontalSpacing);
                        GUILayout.Label("Y", GUILayout.Width(12f));
                        int y = EditorGUILayout.IntField(mFont.verticalSpacing);
                        GUILayout.Space(62f);
                        EditorGUIUtility.LookLikeControls(80f);

                        if (mFont.horizontalSpacing != x || mFont.verticalSpacing != y)
                        {
                            NGUIEditorTools.RegisterUndo("Font Spacing", mFont);
                            mFont.horizontalSpacing = x;
                            mFont.verticalSpacing = y;
                        }
                    }
                    GUILayout.EndHorizontal();

                    if (mFont.atlas == null)
                    {
                        mView = View.Font;
                        mUseShader = false;

                        float pixelSize = EditorGUILayout.FloatField("Pixel Size", mFont.pixelSize, GUILayout.Width(120f));

                        if (pixelSize != mFont.pixelSize)
                        {
                            NGUIEditorTools.RegisterUndo("Font Change", mFont);
                            mFont.pixelSize = pixelSize;
                        }
                    }
                    else
                    {
                        GUILayout.Space(4f);
                        GUILayout.BeginHorizontal();
                        {
                            mView = (View)EditorGUILayout.EnumPopup("Preview", mView);
                            GUILayout.Label("Shader", GUILayout.Width(45f));
                            mUseShader = EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f));
                        }
                        GUILayout.EndHorizontal();
                    }
                }

                if (mFont.atlas != null)
                {
                    NGUIEditorTools.DrawHeader("Symbols and Emoticons");

                    List<BMSymbol> symbols = mFont.symbols;

                    for (int i = 0; i < symbols.Count; )
                    {
                        BMSymbol sym = symbols[i];

                        GUILayout.BeginHorizontal();
                        GUILayout.Label(sym.sequence, GUILayout.Width(40f));
                        if (NGUIEditorTools.SimpleSpriteField(mFont.atlas, sym.spriteName, ChangeSymbolSprite))
                            mSelectedSymbol = sym;

                        if (GUILayout.Button("Edit", GUILayout.Width(40f)))
                        {
                            if (mFont.atlas != null)
                            {
                                EditorPrefs.SetString("NGUI Selected Sprite", sym.spriteName);
                                NGUIEditorTools.Select(mFont.atlas.gameObject);
                            }
                        }

                        GUI.backgroundColor = Color.red;

                        if (GUILayout.Button("X", GUILayout.Width(22f)))
                        {
                            NGUIEditorTools.RegisterUndo("Remove symbol", mFont);
                            mSymbolSequence = sym.sequence;
                            mSymbolSprite = sym.spriteName;
                            symbols.Remove(sym);
                            mFont.MarkAsDirty();
                        }
                        GUI.backgroundColor = Color.white;
                        GUILayout.EndHorizontal();
                        GUILayout.Space(4f);
                        ++i;
                    }

                    if (symbols.Count > 0)
                    {
                        NGUIEditorTools.DrawSeparator();
                    }

                    GUILayout.BeginHorizontal();
                    mSymbolSequence = EditorGUILayout.TextField(mSymbolSequence, GUILayout.Width(40f));
                    NGUIEditorTools.SimpleSpriteField(mFont.atlas, mSymbolSprite, SelectSymbolSprite);

                    bool isValid = !string.IsNullOrEmpty(mSymbolSequence) && !string.IsNullOrEmpty(mSymbolSprite);
                    GUI.backgroundColor = isValid ? Color.green : Color.grey;

                    if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid)
                    {
                        NGUIEditorTools.RegisterUndo("Add symbol", mFont);
                        mFont.AddSymbol(mSymbolSequence, mSymbolSprite);
                        mFont.MarkAsDirty();
                        mSymbolSequence = "";
                        mSymbolSprite = "";
                    }
                    GUI.backgroundColor = Color.white;
                    GUILayout.EndHorizontal();

                    if (symbols.Count == 0)
                    {
                        EditorGUILayout.HelpBox("Want to add an emoticon to your font? In the field above type ':)', choose a sprite, then hit the Add button.", MessageType.Info);
                    }
                    else GUILayout.Space(4f);
                }
            }
        }
	}
예제 #34
0
 private BMSymbol GetSymbol(string sequence, bool createIfMissing)
 {
     int num = 0;
     int count = this.mSymbols.Count;
     while (num < count)
     {
         BMSymbol symbol = this.mSymbols[num];
         if (symbol.sequence == sequence)
         {
             return symbol;
         }
         num++;
     }
     if (createIfMissing)
     {
         BMSymbol item = new BMSymbol();
         item.sequence = sequence;
         this.mSymbols.Add(item);
         return item;
     }
     return null;
 }
예제 #35
0
 public bool MatchSymbol(string text, int offset, int textLength, out BMSymbol symbol)
 {
     int num;
     int count = this.mSymbols.Count;
     if (count > 0)
     {
         textLength = textLength - offset;
         if (textLength > 0)
         {
             for (int i = 0; i < count; i++)
             {
                 BMSymbol item = this.mSymbols[i];
                 int length = item.sequence.Length;
                 if (length != 0 && textLength >= length)
                 {
                     if (string.Compare(item.sequence, 0, text, offset, length) == 0)
                     {
                         symbol = item;
                         if (length < textLength)
                         {
                             int num1 = i + 1;
                             i = num1;
                             if (num1 < count)
                             {
                                 int num2 = length;
                                 do
                                 {
                                     item = this.mSymbols[i];
                                     length = item.sequence.Length;
                                     if (textLength >= length && length > num2)
                                     {
                                         if (string.Compare(item.sequence, 0, text, offset, length) == 0)
                                         {
                                             num2 = length;
                                             symbol = item;
                                         }
                                     }
                                     num = i + 1;
                                     i = num;
                                 }
                                 while (num < count);
                             }
                         }
                         return true;
                     }
                 }
             }
         }
     }
     symbol = null;
     return false;
 }
예제 #36
0
 private BMSymbol GetSymbol(string sequence, bool createIfMissing)
 {
     int i = 0;
     int count = this.mSymbols.Count;
     while (i < count)
     {
         BMSymbol bMSymbol = this.mSymbols[i];
         if (bMSymbol.sequence == sequence)
         {
             return bMSymbol;
         }
         i++;
     }
     if (createIfMissing)
     {
         BMSymbol bMSymbol2 = new BMSymbol();
         bMSymbol2.sequence = sequence;
         this.mSymbols.Add(bMSymbol2);
         return bMSymbol2;
     }
     return null;
 }
예제 #37
0
	/// <summary>
	/// Retrieve the specified symbol, optionally creating it if it's missing.
	/// </summary>

	BMSymbol GetSymbol (string sequence, bool createIfMissing)
	{
		for (int i = 0, imax = mSymbols.Count; i < imax; ++i)
		{
			BMSymbol sym = mSymbols[i];
			if (sym.sequence == sequence) return sym;
		}

		if (createIfMissing)
		{
			BMSymbol sym = new BMSymbol();
			sym.sequence = sequence;
			mSymbols.Add(sym);
			return sym;
		}
		return null;
	}
예제 #38
0
 public BMSymbol GetSymbol(string sequence, bool createIfMissing)
 {
     int num = 0;
     int count = this.mSymbols.Count;
     while (num < count)
     {
         BMSymbol item = this.mSymbols[num];
         if (item.sequence == sequence)
         {
             return item;
         }
         num++;
     }
     if (!createIfMissing)
     {
         return null;
     }
     BMSymbol bMSymbol = new BMSymbol()
     {
         sequence = sequence
     };
     this.mSymbols.Add(bMSymbol);
     return bMSymbol;
 }