## XIDInterf
Class XIIIEditCtrl

source: C:\XIII\XIDInterf\Classes\XIIIEditCtrl.uc

    Core.Object
       |
       +--GUI.GUI
          |
          +--GUI.GUIComponent
             |
             +--GUI.GUILabel
                |
                +--XIDInterf.XIIIGUIBaseButton
                   |
                   +--XIDInterf.XIIIEditCtrl

Direct Known Subclasses:None

class XIIIEditCtrl
extends XIDInterf.XIIIGUIBaseButton

    //----------------------------------------------------------------------
    //----------------------------------------------------------------------
    //class XIIIEditCtrl extends XIIIButton;

Variables
`string` | `AllowedKeyBoardCharSet[102]` to modify size of two boxes
`float` | `FirstBoxWidth` to modify size of two boxes
`int` | `IdxInCharList` idx in the AllowedCharSet string
`TextX2,` | `TextY` to modify size of two boxes
`string` | `TitleText` to modify size of two boxes
`bool` | `bCalculateSize` to modify size of two boxes
`bool` | `bInEditMode` true if entering text, false otherwise
`bLTrimmed,` | `bRTrimmed` to modify size of two boxes

Function Summary
`void` | `BeforePaint(Canvas C, float X, float Y)`
`string` | `ConvertToStars(string S)`
`void` | `Created()`
    //----------------------------------------------------------------------
`void` | `DeleteChar()`
`bool` | `InternalOnKeyEvent(out byte, out byte, float delta)`
`void` | `Paint(Canvas C, float X, float Y)`

Source Code

    00001	//----------------------------------------------------------------------
    00002	//----------------------------------------------------------------------
    00003	//class XIIIEditCtrl extends XIIIButton;
    00004	class XIIIEditCtrl extends XIIIGUIBaseButton;
    00005
    00006	var		string		TextStr;			// Holds the current string
    00007	var		string		TextStrBeforeEdit;	// Holds the previous string
    00008	var		string		DisplayedTextStr;	// Holds the displayed string (the last char is not valid yet)
    00009	var		string		AllowedCharSet;		// Only Allow these characters
    00010	var		int			MaxWidth;			// Holds the maximum width (in chars) of the string - 0 = No Max
    00011
    00012	var		bool		bMaskText, bNoMaskWhenEdit;	// Displays the text as a *
    00013	//var		bool		bIntOnly;			// Only Allow Interger Numeric entry
    00014	var		bool		bCapsOnly;
    00015	var		bool		bReadOnly;			// Can't actually edit this box
    00016	//var     bool        bUpperCase;         // want upper case letters
    00017
    00018	var bool bInEditMode; // true if entering text, false otherwise
    00019
    00020	var int IdxInCharList; // idx in the AllowedCharSet string
    00021
    00022	var bool bCalculateSize; // to modify size of two boxes
    00023
    00024	// keyboard can be used for PC (PS2 ?), only allow these characters
    00025	var string AllowedKeyBoardCharSet[102];
    00026
    00027	var string TitleText;
    00028
    00029	var int TextX1, TextX2, TextY;
    00030
    00031	var float FirstBoxWidth;
    00032	var bool bAllowTypeIn, bLTrimmed, bRTrimmed;
    00033
    00034	//----------------------------------------------------------------------
    00035	function Created()
    00036	{
    00037	    OnKeyEvent=InternalOnKeyEvent;
    00038		OnKeyType=InternalOnKeyType;
    00039	    bInEditMode=false;
    00040	    IdxInCharList=-1;
    00041
    00042	    TextStrBeforeEdit = Text;
    00043	    SetText(TextStrBeforeEdit);
    00044	}
    00045
    00046	event SetText(string NewText)
    00047	{
    00048		TextStr = NewText;
    00049	    Text = TextStr;
    00050		OnChange(self);
    00051	}
    00052
    00053	function DeleteChar()
    00054	{
    00055		if (Len(TextStr)!=0)
    00056		{
    00057			TextStr = Left(TextStr,Len(TextStr) - 1);
    00058		}
    00059		SetText(TextStr);
    00060		OnChange(Self);
    00061	}
    00062
    00063	FUNCTION string ConvertToStars(string S)
    00064	{
    00065		LOCAL int i, l;
    00066		LOCAL string T;
    00067
    00068		if ( bMaskText )
    00069		{
    00070			l = len(s);
    00071			for ( i=0; i<l; i++ )
    00072				T = T$"*";
    00073			return T;
    00074		}
    00075		else
    00076			return S;
    00077	}
    00078
    00079	EVENT bool InternalOnKeyType(out byte Key)
    00080	{
    00081	    local int i;
    00082
    00083		if ( InStr( AllowedCharSet, Chr(Key) )!=-1 )
    00084		{
    00085			bInEditMode=true;
    00086	        if (( bAllowTypeIn ) )//|| ( MaxWidth!=default.MaxWidth && ( Len(TextStr) < MaxWidth )))
    00087			{
    00088				if ( bCapsOnly )
    00089					TextStr = TextStr$Caps(Chr(Key));
    00090				else
    00091	    			TextStr = TextStr$Chr(Key);
    00092				SetText(TextStr);
    00093				IdxInCharList=-1;
    00094			}
    00095			return true;
    00096		}
    00097
    00098		return false;
    00099	}
    00100
    00101	Delegate OnReturnPressed( )
    00102	{
    00103	}
    00104
    00105	function bool InternalOnKeyEvent(out byte Key, out byte State, float delta)
    00106	{
    00107		LOCAL XIIIMenuVirtualKeyboard msgbox;
    00108
    00109		if ((State==1) || (State==2))// IST_Press
    00110	    {
    00111	        if (bInEditMode) // Can be true only on PC
    00112	        {
    00113
    00114		        if ((Key==0x25) || (Key==0x08)) // IK_Left ou IK_Backspace
    00115	            {
    00116	                DeleteChar();
    00117	                return true;
    00118	            }
    00119	            if ( (Key==0x0D) || (Key==0x26) || (Key==0x28)/*|| ((Key==0x01))*/)//IK_Enter IK_LeftMouse
    00120		        {
    00121			        bInEditMode=false;
    00122	                SetText(TextStr);
    00123					IdxInCharList=-1;
    00124					if ( Key == 0x0D )
    00125						OnReturnPressed( );
    00126			        return (Key==0x0D);
    00127		        }
    00128		        if ((Key==0x1B))    // IK_Escape
    00129		        {
    00130			        bInEditMode=false;
    00131	                SetText(TextStrBeforeEdit);
    00132			        return false;
    00133		        }
    00134
    00135	        }
    00136	        else
    00137	        {
    00138	            if ((Key==0x0D) || ((Key==0x01)))//IK_Enter IK_LeftMouse
    00139		        {
    00140					if ( myRoot.CurrentPF!=0 )
    00141					{
    00142						myRoot.OpenMenu("XIDInterf.XIIIMenuVirtualKeyboard");
    00143						msgbox = XIIIMenuVirtualKeyboard(myRoot.ActivePage);
    00144						msgbox.InitVK( self );
    00145					}
    00146					else
    00147					{
    00148						bInEditMode=true;
    00149						TextStrBeforeEdit = Text;
    00150						SetText(Text);
    00151						if ( Key == 0x0D )
    00152							OnReturnPressed( );
    00153					}
    00154			        return true;
    00155		        }
    00156		        if ( ((Key==0x25) || (Key==0x08)) && myRoot.CurrentPF==0) // IK_Left ou IK_Backspace
    00157	            {
    00158	                DeleteChar();
    00159					bInEditMode=true;
    00160	                return true;
    00161	            }
    00162	        }
    00163		}
    00164		return false;
    00165	}
    00166
    00167	function BeforePaint(Canvas C,float X, float Y)
    00168	{
    00169		local float W, H;
    00170
    00171		if ( bCalculateSize )
    00172		{
    00173			// no resize, we use default values for boxes
    00174			FirstBoxWidth = (WinWidth*640*fRatioX - 16*fRatioX)/2;
    00175		}
    00176
    00177		if ((myRoot.bIamInMulti) && (myRoot.GetLevel().NetMode == 0))
    00178			C.Font = font'XIIIFonts.XIIIConsoleFont';
    00179		else
    00180			C.Font = font'XIIIFonts.PoliceF16';
    00181
    00182		C.TextSize(TitleText, W, H);
    00183
    00184		TextX1 = (FirstBoxWidth - W)/2;
    00185		TextX2 = FirstBoxWidth + 32*fRatioX;
    00186
    00187		TextY = (WinHeight*480*fRatioY - H)/2;
    00188
    00189		DisplayedTextStr = ConvertToStars(TextStr);
    00190	    C.TextSize(DisplayedTextStr, W, H);
    00191		bAllowTypeIn = /*(W < (FirstBoxWidth-40*fRatioX)) && (( MaxWidth==default.MaxWidth ) ||*/ (Len(TextStr)<MaxWidth) /*)*/;
    00192
    00193		bLTrimmed = false;
    00194		bRTrimmed = false;
    00195		if ( bHasFocus )
    00196		{
    00197			while( W >= (WinWidth*640 - FirstBoxWidth)*fRatioX-48 ) //(FirstBoxWidth-64*fRatioX) )
    00198			{
    00199				DisplayedTextStr = Mid( DisplayedTextStr, 1 );
    00200			    C.TextSize(DisplayedTextStr, W, H);
    00201				bLTrimmed = true;
    00202			}
    00203		}
    00204		else
    00205		{
    00206			while( W >= (WinWidth*640 - FirstBoxWidth)*fRatioX-48 ) //(FirstBoxWidth-64*fRatioX) )
    00207			{
    00208				DisplayedTextStr = Left( DisplayedTextStr, Len(DisplayedTextStr)-1 );
    00209			    C.TextSize(DisplayedTextStr, W, H);
    00210				bRTrimmed = true;
    00211			}
    00212		}
    00213	}
    00214
    00215	function Paint(Canvas C, float X, float Y)
    00216	{
    00217		LOCAL float W,H;
    00218
    00219		C.Style = 5;
    00220
    00221		C.DrawColor = BackColor;
    00222
    00223		if (bHasFocus)
    00224			C.DrawColor.A = 255;
    00225		else
    00226			C.DrawColor.A = 128;
    00227
    00228		C.bUseBorder = true;
    00229		DrawStretchedTexture(C, 0, 0, FirstBoxWidth, WinHeight*480*fRatioY, myRoot.FondMenu);
    00230
    00231		C.DrawColor.A = 128; // in edit mode, second box is colored in grey
    00232		DrawStretchedTexture(C, FirstBoxWidth + 16*fRatioX, 0, (WinWidth*640 - FirstBoxWidth)*fRatioX, WinHeight*480*fRatioY, myRoot.FondMenu);
    00233		C.bUseBorder = false;
    00234
    00235		C.DrawColor = TextColor;
    00236		C.SetPos(TextX1, TextY);
    00237		C.DrawText(TitleText, false);
    00238		C.SetPos(TextX2, TextY);
    00239		C.DrawText( DisplayedTextStr, false);
    00240
    00241		if ( DisplayedTextStr=="" )
    00242		{
    00243			C.TextSize( "M", W, H);
    00244			W = 0;
    00245
} 00246 else 00247 C.TextSize( DisplayedTextStr, W, H); 00248 if ( bHasFocus && (myRoot.GetPlayerOwner().Level.TimeSeconds-int(myRoot.GetPlayerOwner().Level.TimeSeconds)) < 0.5 ) 00249 DrawStretchedTexture(C, TextX2+W, TextY-2+H*0.75, 8, 2, myRoot.FondMenu); 00250 if ( bLTrimmed ) 00251 { 00252 DrawStretchedTexture(C, TextX2-12, TextY-2+H*0.75, 2, 2, myRoot.FondMenu); 00253 DrawStretchedTexture(C, TextX2-8, TextY-2+H*0.75, 2, 2, myRoot.FondMenu); 00254 DrawStretchedTexture(C, TextX2-4, TextY-2+H*0.75, 2, 2, myRoot.FondMenu); 00255 } 00256 else if ( bRTrimmed ) 00257 { 00258 DrawStretchedTexture(C, TextX2+W, TextY-2+H*0.75, 2, 2, myRoot.FondMenu); 00259 DrawStretchedTexture(C, TextX2+W+4, TextY-2+H*0.75, 2, 2, myRoot.FondMenu); 00260 DrawStretchedTexture(C, TextX2+W+8, TextY-2+H*0.75, 2, 2, myRoot.FondMenu); 00261 } 00262 00263 00264 C.Style = 1; 00265 } 00266 00267 event LoseFocus(GUIComponent Sender) 00268 { 00269 super.LoseFocus(Sender); 00270 bInEditMode=false; 00271 SetText(TextStr); 00272 IdxInCharList=-1; 00273 } 00274 00275 00276 00277 defaultproperties 00278 { 00279 AllowedCharSet="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'-._+" 00280 MaxWidth=16 00281 bCalculateSize=True 00282 }

End Source Code