## XIDInterf
Class XIIILiveMsgBox

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

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

Direct Known Subclasses:XIIIMenuLiveJoinMsgBox

class XIIILiveMsgBox
extends XIDInterf.XIIILiveWindow

    // ====================================================================
    //  (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
`bool` | `ShowWorking` Buttons Names: Ok, Cancel, Retry, Continue, Yes, No, Abort, Ignore. Clamped [0,7].
`int` | `frameCounter` Buttons Names: Ok, Cancel, Retry, Continue, Yes, No, Abort, Ignore. Clamped [0,7].
`int` | `index` Buttons Names: Ok, Cancel, Retry, Continue, Yes, No, Abort, Ignore. Clamped [0,7].
`GUILabel` | `lMessage`
`string` | `sWorking[4]` Buttons Names: Ok, Cancel, Retry, Continue, Yes, No, Abort, Ignore. Clamped [0,7].
`Texture` | `tWorking[4]` Buttons Names: Ok, Cancel, Retry, Continue, Yes, No, Abort, Ignore. Clamped [0,7].

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)`
`void` | `PaintGfxBackground(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` | `ShowWindow( )`
`void` | `UpdateTextDisplayed(string NewText)`

Source Code

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

End Source Code