00001 class XIIIMenuVirtualKeyboard extends XIIIWindow;
00002
00003 VAR XIIIEditCtrl myEditCtrl;
00004 var XIIIButton LettersButton[40], OkButton;
00005 VAR XIIIPadButton CapsButton, CancelButton, DelButton;
00006 var localized string OkText, CancelText, CapsText, DelText/*, PasswordText, EnterPasswordTitleText*/;
00007
00008 var int ButtonWidth, ButtonHeight, ButtonYPos, EditBoxWidth, EditBoxHeight, EditBoxYPos;
00009 var int BackgroundPosX, BackgroundPosY, BackgroundWidth, BackgroundHeight;
00010
00011 VAR string CharSet, CapsCharSet;
00012 VAR string TextStr; // Holds the current string
00013 VAR string TextStrBeforeEdit; // Holds the previous string
00014 VAR bool bCaps, bAllowTypeIn, bGrey;
00015 VAR float WidestCharWidth;
00016
00017 delegate OnButtonClick(byte bButton);
00018
00019 FUNCTION Created()
00020 {
00021 LOCAL int y, i, j, l, SpaceBetweenButtons;
00022
00023 Super.Created();
00024
00025 l=0;
00026 y=190;
00027
00028 // init values
00029 BackgroundPosX = 110; //220;
00030 BackgroundPosY = 140;
00031 BackgroundWidth = 400; //220;
00032 BackgroundHeight = 220;
00033
00034 ButtonWidth = 70;
00035 ButtonHeight = 30;
00036 ButtonYPos = 180;
00037
00038 EditBoxWidth = 350;
00039 EditBoxHeight = 35;
00040 EditBoxYPos = 100;
00041
00042 for (j=0;j<4;j++)
00043 {
00044 for (i=0;i<10;i++)
00045 {
00046 // if (l==26) continue;
00047 LettersButton[l] = XIIIButton(CreateControl(class'XIIIButton', BackgroundPosX+44+i*32, y,24,24));
00048 LettersButton[l].Text= Mid(CharSet,l,1); //Chr(Asc("a")+l-10);
00049 LettersButton[l].bUseBorder=false;
00050 Controls[Controls.Length]=LettersButton[l];
00051 l++;
00052 }
00053 y+=32;
00054 }
00055
00056 OkButton = XIIIButton(CreateControl(class'XIIIButton', BackgroundPosX+44-1*32, y, 56+8,24));
00057 OkButton.Text= OkText;
00058 OkButton.bUseBorder=false;
00059 Controls[Controls.Length]=OkButton;
00060
00061 CapsButton = XIIIPadButton(CreateControl(class'XIIIPadButton', 8+BackgroundPosX+44+1*32, y, 56+32+32,24));
00062 CapsButton.Text= CapsText;
00063 CapsButton.bUseBorder=false;
00064 CapsButton.PadButtonIndex = 0;
00065 Controls[Controls.Length]=CapsButton;
00066
00067 DelButton = XIIIPadButton(CreateControl(class'XIIIPadButton', BackgroundPosX+44+5*32, y, 56+32+8,24));
00068 DelButton.Text= DelText;
00069 DelButton.bUseBorder=false;
00070 DelButton.PadButtonIndex = 2;
00071 Controls[Controls.Length]=DelButton;
00072
00073 CancelButton = XIIIPadButton(CreateControl(class'XIIIPadButton', BackgroundPosX+44+8*32, y, 56+32+8,24));
00074 CancelButton.Text= CancelText;
00075 CancelButton.bUseBorder=true;
00076 CancelButton.PadButtonIndex = 1;
00077 Controls[Controls.Length]=CancelButton;
00078
00079
00080 // OkButton.PadButtonIndex = 2;
00081
00082 }
00083
00084 FUNCTION InitVK( XIIIEditCtrl EditCtrl)
00085 {
00086 myEditCtrl = EditCtrl;
00087 TextStr = myEditCtrl.TextStr;
00088 // bShowDEL = (Len(TextStr)>0);
00089 // DelButton.bNeverFocus = (Len(TextStr)==0);
00090 if ( myEditCtrl.bCapsOnly )
00091 {
00092 CapsButton.bVisible = false;
00093 CapsButton.bNeverFocus = true;
00094 }
00095 }
00096
00097 function ShowWindow()
00098 {
00099 super.ShowWindow();
00100 CancelButton.SetFocus(none);
00101 // bShowBCK = true;
00102 bShowCHO = true;
00103 }
00104
00105 function Paint(Canvas C, float X, float Y)
00106 {
00107 local int i;
00108 local float W, H, EditBoxWidth;
00109 LOCAL string DisplayedText;
00110
00111 if ( WidestCharWidth==0 )
00112 {
00113 C.TextSize("W", WidestCharWidth, H);
00114 }
00115 if ( TextStr=="" )
00116 {
00117 C.TextSize("M", W, H);
00118 W=0;
00119 DisplayedText = "";
00120 }
00121 else
00122 {
00123 if ( !myEditCtrl.bMaskText || myEditCtrl.bNoMaskWhenEdit )
00124 DisplayedText = TextStr;
00125 else
00126 DisplayedText = myEditCtrl.ConvertToStars( TextStr );
00127
00128 C.TextSize(DisplayedText, W, H);
00129 }
00130 bAllowTypeIn = Len(TextStr)<myEditCtrl.MaxWidth;
00131
00132 if ( bGrey )
00133 {
00134 if ( bAllowTypeIn )
00135 {
00136 for (i=0;i<40;i++)
00137 {
00138 // LettersButton[i].bNeverFocus=false;
00139 LettersButton[i].TextColor=BlackColor;
00140 }
00141 bGrey = false;
00142 }
00143 }
00144 else
00145 {
00146 if ( !bAllowTypeIn )
00147 {
00148 for (i=0;i<40;i++)
00149 {
00150 // LettersButton[i].bNeverFocus=true;
00151 LettersButton[i].TextColor=Grey3Color;
00152 }
00153 /* if ( FocusedControl!=OkButton && FocusedControl!=CancelButton && FocusedControl!=CapsButton )
00154 {
00155 XIIIButton(FocusedControl).bUseBorder = false;
00156 CapsButton.FocusFirst( self, false );
00157 CapsButton.bUseBorder = true;
00158 }*/
00159 bGrey = true;
00160 }
00161 }
00162
00163 Super.Paint(C,X,Y);
00164
00165 C.bUseBorder = true;
00166 C.DrawColor = WhiteColor;
00167 C.DrawColor.A = 240;
00168 C.Style = 5;
00169
00170 DrawStretchedTexture(C, BackgroundPosX*fRatioX, BackgroundPosY*fRatioY, BackgroundWidth*fRatioX, BackgroundHeight*fRatioY, myRoot.FondMenu);
00171 // C.DrawColor = BlackColor;
00172 C.Style = 1;
00173
00174 EditBoxWidth = myEditCtrl.MaxWidth * WidestCharWidth+16;
00175 DrawStretchedTexture(C, (BackgroundPosX+(BackgroundWidth-EditBoxWidth)*0.5)*fRatioX, (BackgroundPosY+6)*fRatioY, EditBoxWidth*fRatioX, 32*fRatioY, myRoot.FondMenu);
00176 C.bUseBorder = false;
00177
00178 C.DrawColor = BlackColor;
00179 C.SetPos((BackgroundPosX+(BackgroundWidth-W)*0.5)*fRatioX, (BackgroundPosY+10)*fRatioY);
00180 C.DrawText(DisplayedText, false);
00181
00182 if ( bAllowTypeIn && (myRoot.GetPlayerOwner().Level.TimeSeconds-int(myRoot.GetPlayerOwner().Level.TimeSeconds)) < 0.5 )
00183 DrawStretchedTexture(C, (BackgroundPosX+(BackgroundWidth+W)*0.5)*fRatioX, (BackgroundPosY+10)*fRatioY-2+H*0.75, 8, 2, myRoot.FondMenu);
00184
00185 C.DrawColor = WhiteColor;
00186 }
00187
00188 FUNCTION SwitchCaps()
00189 {
00190 LOCAL int c;
00191 bCaps=!bCaps;
00192 if ( bCaps )
00193 {
00194 for (c=0;c<40;c++)
00195 LettersButton[c].Text=Mid(CapsCharSet,c,1);
00196 }
00197 else
00198 {
00199 for (c=0;c<40;c++)
00200 LettersButton[c].Text=Mid(CharSet,c,1);
00201 }
00202 }
00203
00204 FUNCTION Delete()
00205 {
00206 LOCAL bool bMustShowDel;
00207
00208 TextStr=Mid(TextStr,0,Len(TextStr)-1);
00209 /* DelButton.bNeverFocus = (Len(TextStr)==0);
00210 if ( DelButton.bNeverFocus && DelButton==FocusedControl )
00211 {
00212 DelButton.bUseBorder = false;
00213 CapsButton.FocusFirst(Self,false);
00214 CapsButton.bUseBorder = true;
00215 }*/
00216 }
00217
00218 function bool InternalOnKeyEvent(out byte Key, out byte State, float delta)
00219 {
00220 local int index, c, l;
00221 local bool bUp, bDown, bLeft, bRight;
00222
00223 if (State==1)// IST_Press // to avoid auto-repeat
00224 {
00225 if ( Key==0x0D/*IK_Enter*/)
00226 {
00227 if ( FocusedControl==OkButton )
00228 {
00229 myEditCtrl.SetText( TextStr );
00230 myRoot.CloseMenu(true);
00231 myEditCtrl.FocusFirst(Self,false);
00232 return true;
00233 }
00234 else if ( FocusedControl==CancelButton )
00235 {
00236 myRoot.CloseMenu(true);
00237 myEditCtrl.FocusFirst(Self,false);
00238 return true;
00239 }
00240 else if ( FocusedControl==DelButton )
00241 {
00242 Delete();
00243 return true;
00244 }
00245 else if ( FocusedControl==CapsButton )
00246 {
00247 SwitchCaps();
00248 return true;
00249 }
00250 else
00251 {
00252 if ( bAllowTypeIn )
00253 {
00254 TextStr=TextStr$XIIIButton(FocusedControl).Text;
00255 // DelButton.bNeverFocus=false;
00256 }
00257 return true;
00258 }
00259 // return InternalOnClick(FocusedControl);
00260
00261 }
00262 if ( !myEditCtrl.bCapsOnly && CapsButton.IsRightKeyPressed( Key ) )
00263 {
00264 SwitchCaps();
00265 return true;
00266 }
00267 if ( DelButton.IsRightKeyPressed( Key ) )
00268 {
00269 Delete();
00270 return true;
00271 }
00272 if ( CancelButton.IsRightKeyPressed( Key ) )
00273 {
00274 myRoot.CloseMenu(true);
00275 myEditCtrl.FocusFirst(Self,false);
00276 return true;
00277 }
00278
00279 bLeft = (Key==0x25);
00280 bRight = (Key==0x27);
00281 bUp = (Key==0x26);
00282 bDown = (Key==0x28);
00283
00284 // controls are
00285 // 0
00286 // 1 2
00287 if ( bLeft || bRight || bUp || bDown )
00288 {
00289 XIIIButton(FocusedControl).bUseBorder=false;
00290 if ( FocusedControl==OkButton )
00291 {
00292 if ( bRight )
00293 NextControl(FocusedControl);
00294 if ( bUp )
00295 Controls[30].FocusFirst(Self,false);
00296 if ( bDown )
00297 Controls[0].FocusFirst(Self,false);
00298 }
00299 else if ( FocusedControl==CapsButton )
00300 {
00301 if ( bLeft )
00302 PrevControl(FocusedControl);
00303 if ( bRight )
00304 NextControl(FocusedControl);
00305 if ( bUp )
00306 Controls[33].FocusFirst(Self,false);
00307 if ( bDown )
00308 Controls[3].FocusFirst(Self,false);
00309 }
00310 else if ( FocusedControl==DelButton )
00311 {
00312 if ( bLeft )
00313 PrevControl(FocusedControl);
00314 if ( bRight )
00315 NextControl(FocusedControl);
00316 if ( bUp )
00317 Controls[36].FocusFirst(Self,false);
00318 if ( bDown )
00319 Controls[6].FocusFirst(Self,false);
00320 }
00321 else if ( FocusedControl==CancelButton )
00322 {
00323 if ( bLeft )
00324 PrevControl(FocusedControl);
00325 if ( bUp )
00326 Controls[39].FocusFirst(Self,false);
00327 if ( bDown )
00328 Controls[9].FocusFirst(Self,false);
00329 }
00330 else
00331 {
00332 index = FindComponentIndex(FocusedControl);
00333 l = index/10;
00334 c = index - 10*l ;
00335
00336 if ( bLeft )
00337 c = (c+9)%10;
00338 if ( bRight )
00339 c = (c+1)%10;
00340 if ( bUp)
00341 {
00342 if ( /*!DelButton.bNeverFocus &&*/ l==0 && ( c==5 || c==6 || c==7 ))
00343 {
00344 l=4;
00345 c=2;
00346 }
00347 else if ( l==0 && ( c==0 ))
00348 {
00349 l=4;
00350 c=0;
00351 }
00352 else if ( l==0 && ( c==1 || c==2 || c==3 || c==4 ))
00353 {
00354 l=4;
00355 c=1;
00356 }
00357 else if ( l==0 && ( c==8 || c==9 ))
00358 {
00359 l=4;
00360 c=3;
00361 }
00362 else
00363 l = (l+3)%4;
00364 }
00365 if ( bDown )
00366 {
00367 if ( /*!DelButton.bNeverFocus &&*/ l==3 && ( c==5 || c==6 || c==7 ))
00368 {
00369 l=4;
00370 c=2;
00371 }
00372 else if ( l==3 && ( c==8 || c==9 ))
00373 {
00374 l=4;
00375 c=3;
00376 }
00377 else if ( l==3 && ( c==0 ))
00378 {
00379 l=4;
00380 c=0;
00381 }
00382 else if ( l==3 && ( c==1 || c==2 || c==3 || c==4 ))
00383 {
00384 l=4;
00385 c=1;
00386 }
00387 else
00388 l = (l+1)%4;
00389 }
00390 Controls[l*10+c].FocusFirst(Self,false);
00391 }
00392 XIIIButton(FocusedControl).bUseBorder=true;
00393 return true;
00394 }
00395 }
00396 return super.InternalOnKeyEvent(Key, state, delta);
00397 }
00398
00399
00400
00401
00402
00403
00404
00405
00406 defaultproperties
00407 {
00408 OKText="Ok"
00409 CancelText="Cancel"
00410 CapsText="Capitals"
00411 DelText="Delete"
00412 CharSet="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'-._"
00413 CapsCharSet="0123456789abcdefghijklmnopqrstuvwxyz'-._"
00414 bForceHelp=True
00415 Background=None
00416 bCheckResolution=True
00417 bRequire640x480=False
00418 bAllowedAsLast=True
00419 bHidePreviousPage=False
00420 }
|