## XIDInterf
Class XIIIMsgBoxInGame

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

    Core.Object
       |
       +--GUI.GUI
          |
          +--GUI.GUIComponent
             |
             +--GUI.GUIMultiComponent
                |
                +--GUI.GUIPage
                   |
                   +--XIDInterf.XIIIWindow
                      |
                      +--XIDInterf.XIIIMsgBoxInGame

Direct Known Subclasses:None

class XIIIMsgBoxInGame
extends XIDInterf.XIIIWindow

    // ====================================================================
    //  (c) 2002, Epic Games, Inc.  All Rights Reserved
    // ====================================================================

Variables
`string` | `ButtonNames[8]` Buttons Names: Ok, Cancel, Retry, Continue, Yes, No, Abort, Ignore. Clamped [0,7].
`array` | `Buttons` Buttons Names: Ok, Cancel, Retry, Continue, Yes, No, Abort, Ignore. Clamped [0,7].
`DefaultButton,` | `CancelButton` Buttons Names: Ok, Cancel, Retry, Continue, Yes, No, Abort, Ignore. Clamped [0,7].
`MarginWidth,` | `MarginHeight` Buttons Names: Ok, Cancel, Retry, Continue, Yes, No, Abort, Ignore. Clamped [0,7].
`Material` | `MessageIcon` Like Warning/Question/Exclamation
`GUILabel` | `lMessage`

Function Summary
`bool` | `AddButton(int idesc, bool bDefault, out XIIIGUIButton)`
`bool` | `ButtonClick(GUIComponent Sender)`
`void` | `InitBox(float _OrgX, float _OrgY, float _LineWidth, float _LineHeight, float _Width, float _Height)`
`void` | `InitComponent(GUIController pMyController, GUIComponent MyOwner)`
`bool` | `InternalOnKeyEvent(out byte, out byte, float delta)`
`bool` | `InternalOnPreDraw(Canvas C)`
`void` | `LayoutButtons(byte ActiveButton)`
`void` | `Paint(Canvas C, float X, float Y)`
`string` | `Replace(string Src, string Tag, string Value)`
`void` | `SetupQuestion(string Question, byte bButtons, byte ActiveButton, optional string)`
`void` | `UpdateTextDisplayed(string NewText)`

Source Code

    00001	// ====================================================================
    00002	//  (c) 2002, Epic Games, Inc.  All Rights Reserved
    00003	// ====================================================================
    00004
    00005	class XIIIMsgBoxInGame extends XIIIWindow;
    00006
    00007	var GUILabel lMessage;
    00008	var Material MessageIcon;	// Like Warning/Question/Exclamation
    00009	var localized string ButtonNames[8]; // Buttons Names: Ok, Cancel, Retry, Continue, Yes, No, Abort, Ignore.  Clamped [0,7].
    00010	var array<XIIIGUIButton> Buttons;
    00011	var XIIIGUIButton DefaultButton, CancelButton;
    00012
    00013	var float MarginWidth, MarginHeight;
    00014
    00015	delegate OnButtonClick(byte bButton);
    00016	delegate OnTick(float deltatime);
    00017
    00018	function InitComponent(GUIController pMyController, GUIComponent MyOwner)
    00019	{
    00020	  local int i;
    00021
    00022		OnPreDraw=InternalOnPreDraw;
    00023		Super.Initcomponent(pMyController, MyOwner);
    00024		lMessage=GUILabel(Controls[1]);
    00025		ParentPage.InactiveFadeColor=class'Canvas'.static.MakeColor(128,128,128,255);
    00026	  OnKeyEvent=InternalOnKeyEvent;
    00027	}
    00028
    00029	function InitBox(float _OrgX, float _OrgY, float _LineWidth, float _LineHeight, float _Width, float _Height)
    00030	{
    00031	    WinWidth=_Width;            // Set Window's width
    00032	    WinHeight=_Height;           // Set Window's height
    00033	    WinTop=_OrgY;            // Set the windows location on the Y axis
    00034	    WinLeft=_OrgX;           // Set the windows location on the X axis
    00035	    MarginWidth = _LineWidth;
    00036	    MarginHeight = _LineHeight;
    00037
    00038	    Controls[0].WinWidth=_Width;            // Set Window's width
    00039	    Controls[0].WinHeight=_Height;           // Set Window's height
    00040	    Controls[0].WinTop=_OrgY+_lineheight*2+30;            // Set the windows location on the Y axis
    00041	    Controls[0].WinLeft=_OrgX;           // Set the windows location on the X axis
    00042
    00043
    00044	    if (GUILabel(Controls[0]).Caption=="")
    00045	    {
    00046	        Controls[0].WinWidth=_Width;
    00047	        Controls[0].WinHeight=0; // no message
    00048	        Controls[0].WinTop=_OrgY;
    00049	        Controls[0].WinLeft=_OrgX;
    00050	    }
    00051
    00052	    Controls[1].WinWidth=_Width-2*(_LineWidth+1);
    00053	    Controls[1].WinHeight=_Height-2*(_LineHeight+1)+10;
    00054	    Controls[1].WinTop=_OrgY+_Height/2+35;
    00055	    Controls[1].WinLeft=_OrgX+_LineWidth;
    00056	}
    00057
    00058	event Tick(float deltatime)
    00059	{
    00060		OnTick(deltatime);
    00061	}
    00062
    00063	function bool InternalOnPreDraw(Canvas C)
    00064	{
    00065	local float XL, YL;
    00066	local int i;
    00067	local array<string> MsgArray, MsgArray2;
    00068	local int NeededHeight;
    00069
    00070	    // captions
    00071		if (GUILabel(Controls[0]).TextFont != "")
    00072			C.Font = Controller.GetMenuFont(GUILabel(Controls[0]).TextFont).GetFont(C.SizeX);
    00073
    00074		C.TextSize("W", XL, YL);
    00075		C.WrapStringToArray(GUILabel(Controls[0]).Caption, MsgArray2, GUILabel(Controls[0]).ActualWidth(), "|");
    00076	    YL *= (MsgArray2.Length+1);
    00077		Controls[0].WinHeight = YL + GUILabel(Controls[0]).Style.BorderOffsets[1] + GUILabel(Controls[0]).Style.BorderOffsets[3];
    00078
    00079		if (lMessage.TextFont != "")
    00080			C.Font = Controller.GetMenuFont(lMessage.TextFont).GetFont(C.SizeX);
    00081
    00082		C.TextSize("W", XL, YL);
    00083		C.WrapStringToArray(lMessage.Caption, MsgArray, lMessage.ActualWidth(), "|");
    00084	    YL *= (MsgArray.Length+1); // 0 is first index.
    00085
    00086		if (lMessage.Style != None)
    00087			YL += lMessage.Style.BorderOffsets[1] + lMessage.Style.BorderOffsets[3];
    00088
    00089		lMessage.WinHeight = YL;
    00090
    00091		if (Buttons.Length==0)
    00092		  NeededHeight = lMessage.WinHeight + Controls[0].WinHeight + 2*MarginHeight;
    00093		else
    00094		  NeededHeight = lMessage.WinHeight + Buttons[0].ActualHeight() + Controls[0].WinHeight + 2*MarginHeight;
    00095	    if (NeededHeight > WinHeight)
    00096	        WinHeight = NeededHeight;
    00097
    00098		lMessage.WinTop = WinTop + WinHeight/2 - lMessage.WinHeight/2 + lMessage.Style.BorderOffsets[1] + lMessage.Style.BorderOffsets[1] + 10;
    00099
    00100		for (i = 0; i<Buttons.Length; i++)
    00101	    {
    00102			Buttons[i].WinTop = WinTop + WinHeight - Buttons[i].ActualHeight() - 2*MarginHeight;
    00103	    }
    00104
    00105	    OnPreDraw=None;
    00106		return true;
    00107	}
    00108
    00109	function LayoutButtons(byte ActiveButton)
    00110	{
    00111	local int i;
    00112	local float left, HalfBtnW, btnw;
    00113
    00114		// Simply center the button(s)
    00115		HalfBtnW = WinWidth /(2*Buttons.Length + (Buttons.Length + 1)); // interval is half button width
    00116		btnw = 2 * HalfBtnW;
    00117		left = HalfBtnW + WinLeft;
    00118
    00119		NextControl(FocusedControl);
    00120
    00121		for (i = 0; i<Buttons.Length; i++)
    00122		{
    00123			Buttons[i].WinLeft = left;
    00124			Buttons[i].WinWidth = btnw;
    00125	        Buttons[i].WinHeight = 30*fScaleTo;
    00126			left += 3 * HalfBtnW;
    00127
    00128			Buttons[i].WinTop = WinTop+WinHeight - Buttons[i].WinHeight - 5;
    00129		}
    00130	}
    00131
    00132	function Paint(Canvas C, float X, float Y)
    00133	{
    00134	    local float XX,YY,W, H;
    00135	    local int i;
    00136
    00137	    Super.Paint(C,X,Y);
    00138
    00139	    C.DrawMsgboxBackground(true, WinLeft, WinTop, MarginWidth, MarginHeight, WinWidth, WinHeight);
    00140	}
    00141
    00142	function UpdateTextDisplayed(string NewText)
    00143	{
    00144	    lMessage.Caption = NewText;
    00145		OnPreDraw=InternalOnPreDraw;
    00146	}
    00147
    00148	function SetupQuestion(string Question, byte bButtons, byte ActiveButton, optional string Caption)
    00149	{
    00150		LOCAL XIIIGUIButton DefaultButton;
    00151	//  if (caption == "")
    00152	//    caption = "Error";
    00153	    GUILabel(Controls[0]).Caption = Caption;
    00154
    00155		lMessage.Caption = Question;
    00156
    00157		// Create Buttons Based on Buttons parameter
    00158		if ((bButtons & QBTN_Ok) != 0)
    00159			AddButton(0, ActiveButton==QBTN_Ok, DefaultButton);
    00160		if ((bButtons & QBTN_Continue) != 0)
    00161			AddButton(3, ActiveButton==QBTN_Continue, DefaultButton);
    00162		if ((bButtons & QBTN_Ignore) != 0)
    00163			AddButton(7, ActiveButton==QBTN_Ignore, DefaultButton);
    00164		if ((bButtons & QBTN_Yes) != 0)
    00165			AddButton(4, ActiveButton==QBTN_Yes, DefaultButton);
    00166		if ((bButtons & QBTN_No) != 0)
    00167			AddButton(5, ActiveButton==QBTN_No, DefaultButton);
    00168		if ((bButtons & QBTN_Abort) != 0)
    00169			AddButton(6, ActiveButton==QBTN_Abort, DefaultButton);
    00170		if ((bButtons & QBTN_Retry) != 0)
    00171			AddButton(2, ActiveButton==QBTN_Retry, DefaultButton);
    00172		if ((bButtons & QBTN_Cancel) != 0)
    00173		{
    00174			AddButton(1, ActiveButton==QBTN_Cancel, DefaultButton);
    00175			CancelButton = Buttons[Buttons.Length-1];
    00176		}
    00177		LayoutButtons(ActiveButton);
    00178		if ( DefaultButton==none )
    00179			NextControl(FocusedControl);
    00180		else
    00181			DefaultButton.FocusFirst( self, false );
    00182	}
    00183
    00184	function bool AddButton(int idesc, bool bDefault, out XIIIGUIButton DefaultButton )
    00185	{
    00186		LOCAL XIIIGUIButton btn;
    00187
    00188		btn = new class'XIIIGUIButton';
    00189		btn.StyleName="MsgBoxButton";
    00190		btn.InitComponent(Controller, MenuOwner);
    00191
    00192		Controls[Controls.Length] = btn;
    00193		Buttons[Buttons.Length] = btn;
    00194		btn.Caption = ButtonNames[Clamp(idesc,0,7)];
    00195		btn.OnClick = ButtonClick;
    00196		btn.Tag = 1 << idesc;
    00197		if ( bDefault )
    00198			DefaultButton=btn;
    00199		return bDefault;
    00200	}
    00201
    00202	function bool ButtonClick(GUIComponent Sender)
    00203	{
    00204	local int T;
    00205
    00206		T = XIIIGUIButton(Sender).Tag;
    00207
    00208		ParentPage.InactiveFadeColor=ParentPage.Default.InactiveFadeColor;
    00209		Controller.CloseMenu(true);
    00210		OnButtonClick(T);
    00211		return true;
    00212	}
    00213
    00214	function bool InternalOnKeyEvent(out byte Key, out byte State, float delta)
    00215	{
    00216	  if (Buttons.Length==0)
    00217	    return true;
    00218
    00219	    if (State==1 /*|| State==2 || State==3*/)// IST_Press // to avoid auto-repeat
    00220	    {
    00221	        if ((Key==0x0D/*IK_Enter*/)||(Key==0x01/*IK_LeftMouse*/))
    00222		    {
    00223	            ButtonClick(Controller.FocusedControl);
    00224	            return true;
    00225		    }
    00226		    if (Key==0x08/*IK_Backspace*/)
    00227		    {
    00228		        if (CancelButton != none)
    00229				      ButtonClick(CancelButton);
    00230	    	    return true;
    00231		    }
    00232		    if (Key==0x25/*IK_Left*/)
    00233		    {
    00234		        NextControl(FocusedControl);
    00235	    	    return true;
    00236		    }
    00237		    if (Key==0x27/*IK_Right*/)
    00238		    {
    00239		        PrevControl(FocusedControl);
    00240	    	    return true;
    00241		    }
    00242	    }
    00243	    return Super.InternalOnKeyEvent(Key, State, delta);
    00244	}
    00245
00246 function string Replace(string Src, string Tag, string Value) 00247 { 00248 local string retval; 00249 local int p, tsz; 00250 00251 Tag="%"$Tag$"%"; 00252 tsz = Len(Tag); 00253 p = InStr(Src, Tag); 00254 while (p != -1) 00255 { 00256 retval = retval$Left(Src, p)$Value; 00257 Src=Mid(Src, p+tsz); 00258 p = InStr(Src, Tag); 00259 } 00260 return retval$Src; 00261 } 00262 00263 00264 00265 defaultproperties 00266 { 00267 ButtonNames(0)="Ok" 00268 ButtonNames(1)="Cancel" 00269 ButtonNames(2)="Retry" 00270 ButtonNames(3)="Continue" 00271 ButtonNames(4)="Yes" 00272 ButtonNames(5)="No" 00273 ButtonNames(6)="Abort" 00274 ButtonNames(7)="Ignore" 00275 bHidePreviousPage=False 00276 Controls(0)=GUILabel'XIDInterf.XIIIMsgBoxInGame.TitleText' 00277 Controls(1)=GUILabel'XIDInterf.XIIIMsgBoxInGame.lblQuestion' 00278 WinTop=110.000000 00279 WinLeft=160.000000 00280 WinWidth=320.000000 00281 WinHeight=240.000000 00282 }

End Source Code