XIDInterf
Class XIIIComboControl

source: C:\XIII\XIDInterf\Classes\XIIIComboControl.uc
Core.Object
   |
   +--GUI.GUI
      |
      +--GUI.GUIComponent
         |
         +--GUI.GUILabel
            |
            +--XIDInterf.XIIIGUIBaseButton
               |
               +--XIDInterf.XIIIComboControl
Direct Known Subclasses:None

class XIIIComboControl
extends XIDInterf.XIIIGUIBaseButton


Variables
 int Index
 Items, Items2
 ItemX, TextY
 bGlassLook, bAlwaysFocus
 bShowLeftArrow, bShowBordersOnlyWhenFocused
 bool bSplitScreenMode
 fSplitX, fSpaceX
 tHighlight, tArrow


Function Summary
 void AddItem(string newItem, optional string)
 void AlignLeft()
 void BeforePaint(Canvas C, float X, float Y)
     
// Important
// fRatioX has no influence on arrows sizes calculation in split screen mode
// Arrows will be the same size in 2 or 4 viewports
 void Clear()
 void Created()
 int FindItemIndex(string Value, optional bool)
 int GetSelectedIndex()
 string GetValue()
 string GetValue2()
 void InitComponent(GUIController MyController, GUIComponent MyOwner)
 bool InternalOnClick(out byte)
 bool InternalOnKeyEvent(out byte, out byte, float delta)
 void Paint(Canvas C, float X, float Y)
 void SetArrows()
 void SetSelectedIndex(int ind)
 void Update()



Source Code


00001	class XIIIComboControl extends XIIIGUIBaseButton;
00002	
00003	var array <string> Items, Items2;
00004	//var XIIIArrowButton leftArrow, rightArrow;
00005	var bool bDisplayBg, bSelected, bArrows, bGlassLook, bAlwaysFocus;
00006	var texture tHighlight, tArrow;
00007	var int CaptionX, ItemX, TextY;
00008	var bool bCalculateSize, bShowRightArrow, bShowLeftArrow, bShowBordersOnlyWhenFocused;
00009	var float FirstBoxWidth, SecondBoxWidth, BoxHeight, CanvasClipX, OldRatioX, OldRatioY, fSplitX, fSpaceX;
00010	
00011	var int Index;
00012	
00013	var bool bSplitScreenMode;
00014	
00015	function InitComponent(GUIController MyController, GUIComponent MyOwner)
00016	{
00017		Super.InitComponent(MyController, MyOwner);
00018		OnKeyEvent = InternalOnKeyEvent;
00019	}
00020	
00021	FUNCTION Update()
00022	{
00023		if ( OldRatioX!=fRatioX || OldRatioY!=fRatioY )
00024		{
00025			if ( Text=="" )
00026			{
00027				FirstBoxWidth = 0;
00028				SecondBoxWidth = (WinWidth*640)*fRatioX;
00029			}
00030			else
00031			{
00032				if ( bCalculateSize )
00033				{
00034					FirstBoxWidth = (WinWidth*320)*fRatioX;
00035					SecondBoxWidth= (WinWidth*320)*fRatioX;
00036					bCalculateSize=false;
00037				}
00038				else
00039				{
00040					SecondBoxWidth=WinWidth*640*fRatioX - FirstBoxWidth;
00041				}
00042			}
00043			BoxHeight = WinHeight*480*fRatioY;
00044	
00045			if ( !bSplitScreenMode )
00046				fSplitX = fRatioX;
00047			else
00048				fSplitX = 1.0;
00049	
00050			OldRatioX = fRatioX;
00051			OldRatioY = fRatioY;
00052		}
00053	}
00054	
00055	
00056	function Created()
00057	{
00058	    super.Created();
00059	    TextAlign = TXTA_Center;
00060	}
00061	
00062	function SetArrows()
00063	{
00064	     bArrows = true;
00065	}
00066	
00067	function AlignLeft()
00068	{
00069	    TextAlign = TXTA_Left;
00070	}
00071	
00072	function int GetSelectedIndex()
00073	{
00074	     return Index;
00075	}
00076	
00077	function SetSelectedIndex(int ind)
00078	{
00079		if (ind > -1) 
00080			Index = ind;
00081	
00082		bShowLeftArrow = ( Index!=0 );
00083		bShowRightArrow = ( Items.Length!=0 )&&( Index!=Items.Length-1 );
00084	}
00085	
00086	function AddItem(string newItem, optional string newItem2)
00087	{
00088	     Items[Items.Length] = newItem;
00089	     if (newItem2 != "") 
00090	         Items2[Items2.Length] = newItem2;
00091	}
00092	
00093	function string GetValue()
00094	{
00095	     return Items[Index];
00096	}
00097	
00098	function string GetValue2()
00099	{
00100	     return Items2[Index];
00101	}
00102	
00103	function Clear()
00104	{
00105	     Index = 0;
00106	     Items.Length=0;
00107	}
00108	
00109	function int FindItemIndex(string Value, optional bool bIgnoreCase)
00110	{
00111	     local int Count;
00112	
00113	     Count = 0;
00114	     while(Count < Items.Length)
00115	     {
00116	          if(bIgnoreCase && Items[Count] ~= Value) 
00117	              return Count;
00118	          if(Items[Count] == Value) 
00119	              return Count;
00120	
00121	          Count++;
00122	     }
00123	
00124	     return -1;
00125	}
00126	
00127	// Important
00128	// fRatioX has no influence on arrows sizes calculation in split screen mode
00129	// Arrows will be the same size in 2 or 4 viewports
00130	
00131	function BeforePaint(Canvas C, float X, float Y)
00132	{
00133		local float W, H, CW;
00134	
00135		C.SpaceX=0;
00136		Update();
00137	
00138		if (Items.Length>0)
00139			C.TextSize( Items[index], W, H);
00140	
00141		if (Text == "")
00142			ItemX = (WinWidth*640*fRatioX - W)*0.5;
00143		else
00144		{
00145			ItemX = FirstBoxWidth - 16*fSplitX + ( SecondBoxWidth - W ) * 0.5;
00146	
00147			C.TextSize( Text, CW, H);
00148			CaptionX = (FirstBoxWidth - CW - 32*fSplitX)/2;
00149		}
00150		TextY = (WinHeight*480*fRatioY - H)/2 + 1;
00151	
00152		if ( SecondBoxWidth<W )
00153		{
00154			fSpaceX= int((SecondBoxWidth-W)/(len(Text)-1)-0.9);
00155			C.SpaceX = fSpaceX;
00156			C.StrLen( Items[index], W, H);
00157			ItemX= FirstBoxWidth - 16*fSplitX + ( SecondBoxWidth - W ) * 0.5;
00158			C.SpaceX = 0;
00159		}
00160		else
00161		{
00162			fSpaceX= 0;
00163		}
00164	}
00165	
00166	function Paint(Canvas C, float X, float Y)
00167	{
00168		CanvasClipX = C.ClipX;
00169	
00170	    C.DrawColor = BackColor;
00171	    C.Style = 5;
00172	    if (bVisible && bNeverFocus) 
00173	        BackColor.A = 128;
00174	    else 
00175	        BackColor.A = 255;
00176	
00177	    if (bGlassLook) 
00178	    {
00179	        if ((bHasFocus) || (bAlwaysFocus))
00180	            C.DrawColor.A = 255;
00181	        else 
00182	            C.DrawColor.A = 128;
00183	    }
00184	    if (bSelected && tHighLight != none)
00185	        DrawStretchedTexture(C, 0, 0, WinWidth, WinHeight, tHighLight);
00186	
00187	    C.bUseBorder = !bShowBordersOnlyWhenFocused || bHasFocus;
00188	
00189		if (Text=="")
00190		{
00191			DrawStretchedTexture(C, (int(bArrows)*20)*fSplitX, (int(bArrows)*6)*fRatioY, WinWidth*640*fRatioX - int(bArrows)*36*fSplitX, (WinHeight*480 - int(bArrows)*12)*fRatioY, myRoot.FondMenu);
00192		}
00193		else 
00194		{
00195			DrawStretchedTexture(C, 0, 0, FirstBoxWidth - 32*fSplitX, BoxHeight, myRoot.FondMenu);
00196			DrawStretchedTexture(C, FirstBoxWidth - 16*fSplitX, 0, SecondBoxWidth, BoxHeight, myRoot.FondMenu);
00197		}
00198	
00199	    C.bUseBorder = false;
00200	
00201	    if (bArrows && (!bShowBordersOnlyWhenFocused || bHasFocus) && ( bShowLeftArrow || bShowRightArrow ) )
00202	    {
00203			if (Text!="")
00204			{
00205				C.SetPos(FirstBoxWidth - 36*fSplitX,4*fRatioY);
00206			}
00207			else 
00208				C.SetPos(0 ,4*fRatioY);
00209	
00210			if ( bShowLeftArrow )
00211				C.DrawTile( tArrow, 16*fSplitX, BoxHeight - 8*fRatioY, tArrow.USize, 0, -tArrow.USize, tArrow.VSize );
00212			if ( bShowRightArrow )
00213			{
00214				C.SetPos(WinWidth*640*fRatioX - 12*fSplitX, 4*fRatioY);
00215				C.DrawTile( tArrow, 16*fSplitX, BoxHeight - 8*fRatioY, 0, 0, tArrow.USize, tArrow.VSize );
00216			}
00217	    }
00218	    C.DrawColor = TextColor;
00219	
00220		C.SetPos(ItemX + 1,TextY);
00221	
00222		C.SpaceX = fSpaceX;
00223	    if(Text!="")
00224	    {
00225	        if (Items.Length>0)
00226	        {
00227	            C.DrawText( Items[Index], false);
00228	        }
00229	        C.Font = font'XIIIFonts.PoliceF16';
00230	        C.SetPos(CaptionX, TextY);
00231			C.SpaceX=0;
00232			C.DrawText( Text, false);
00233	    }
00234	    else
00235	        C.DrawText( Items[Index], false);
00236	    C.Style = 1;
00237		C.SpaceX=0;
00238	}
00239	
00240	function bool InternalOnClick( out byte Key )
00241	{
00242		LOCAL float RelativeX;
00243	
00244	    if ( (myRoot.bMapMenu || XIIIWindow(MenuOwner).bCenterInGame) && (CanvasClipX > 800) )
00245			RelativeX = ((Controller.MouseX-(CanvasClipX-800)*0.5)/fRatioX-WinLeft*640);
00246		else
00247			RelativeX = (Controller.MouseX/fRatioX-WinLeft*640);
00248	
00249		if ( bArrows  )
00250		{
00251			if (Text!="")
00252			{
00253				if ( bCalculateSize )
00254				{
00255					if ( RelativeX<WinWidth*640/2-34 )
00256					{
00257						return true;
00258					}
00259					else if ( RelativeX>WinWidth*640 - 16 )
00260					{
00261						Key = 0x27;
00262					}
00263					else if ( RelativeX<WinWidth*640/2 - 18 )
00264					{
00265						Key = 0x25;
00266					}
00267				}
00268				else
00269				{
00270					if ( RelativeX<FirstBoxWidth/fRatioX - 34 )
00271					{
00272						return true;
00273					}
00274					else if ( RelativeX>WinWidth*640 - 16 )
00275					{
00276						Key = 0x27;
00277					}
00278					else if ( RelativeX<FirstBoxWidth/fRatioX - 18 )
00279					{
00280						Key = 0x25;
00281					}
00282				}
00283			}
00284			else
00285			{
00286				 if ( RelativeX>WinWidth*640 - 16 )
00287				{
00288					Key = 0x27;
00289				}
00290				else if ( RelativeX<18 )
00291				{
00292					Key = 0x25;
00293				}
00294			}
00295		}
00296	
00297		return false;
00298	}
00299	
00300	function bool InternalOnKeyEvent(out byte Key, out byte State, float delta)
00301	{
00302		if ( bArrows && Key==0x01 && State==1 )
00303		{
00304			return InternalOnClick( Key );
00305		}
00306		return false;
00307	}
00308	
00309	
00310	
00311	
00312	defaultproperties
00313	{
00314	     bGlassLook=True
00315	     tArrow=Texture'XIIIMenuStart.Interface_LoadGame.fleches'
00316	     bCalculateSize=True
00317	}

End Source Code