## XIDInterf
Class XIIIMsgBox

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

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

Direct Known Subclasses:XIIIMsgBoxQuitGame

class XIIIMsgBox
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
`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)`
`void` | `AdjustPosition(Canvas C)`
`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 XIIIMsgBox 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	var bool ShowWorking;
    00016	var texture tWorking[4];
    00017	var string sWorking[4];
    00018
    00019	var int frameCounter;
    00020	var int index;
    00021
    00022
    00023
    00024	delegate OnButtonClick(byte bButton);
    00025	delegate OnTick(float deltatime);
    00026
    00027
    00028	function InitComponent(GUIController pMyController, GUIComponent MyOwner)
    00029	{
    00030	  local int i;
    00031
    00032		OnPreDraw=InternalOnPreDraw;
    00033		Super.Initcomponent(pMyController, MyOwner);
    00034		lMessage=GUILabel(Controls[1]);
    00035		ParentPage.InactiveFadeColor=class'Canvas'.static.MakeColor(128,128,128,255);
    00036	  OnKeyEvent=InternalOnKeyEvent;
    00037
    00038	  for (i=0; i<4; i++)
    00039	    tWorking[i] = texture(DynamicLoadObject(sWorking[i], class'Texture'));
    00040	}
    00041
    00042	FUNCTION ShowWindow( )
    00043	{
    00044		bShowACC = true;
    00045	}
    00046
    00047	function PaintGfxBackground(Canvas C, float X, float Y)
    00048	{
    00049	  local float W, H;
    00050	  C.DrawColor = WhiteColor;
    00051	  C.Style = 5;
    00052
    00053	  if (ShowWorking)
    00054	  {
    00055	    if (frameCounter++ > 12)
    00056	    {
    00057	        frameCounter = 0;
    00058	        index = index+1;
    00059	        if (index>3) index=0;
    00060	    }
    00061	    DrawStretchedTexture(C, WinLeft+MarginWidth/2+(WinWidth-tWorking[index].USize)/2, WinTop+MarginHeight/2+30, tWorking[index].USize, tWorking[index].VSize, tWorking[index]);
    00062	  }
    00063
    00064	  C.bUseBorder = false;
    00065	  C.DrawColor = BlackColor;
    00066	}
    00067
    00068	function InitBox(float _OrgX, float _OrgY, float _LineWidth, float _LineHeight, float _Width, float _Height)
    00069	{
    00070
    00071	    WinWidth=_Width;            // Set Window's width
    00072	    WinHeight=_Height;           // Set Window's height
    00073	    WinTop=_OrgY;            // Set the windows location on the Y axis
    00074	    WinLeft=_OrgX;           // Set the windows location on the X axis
    00075	    MarginWidth = _LineWidth;
    00076	    MarginHeight = _LineHeight;
    00077
    00078	    Controls[0].WinWidth=_Width;            // Set Window's width
    00079	    Controls[0].WinHeight=_Height;           // Set Window's height
    00080	    Controls[0].WinTop=_OrgY+_lineheight*2+30;            // Set the windows location on the Y axis
    00081	    Controls[0].WinLeft=_OrgX;           // Set the windows location on the X axis
    00082
    00083
    00084	    if (GUILabel(Controls[0]).Caption=="")
    00085	    {
    00086	        Controls[0].WinWidth=_Width;
    00087	        Controls[0].WinHeight=0; // no message
    00088	        Controls[0].WinTop=_OrgY;
    00089	        Controls[0].WinLeft=_OrgX;
    00090	    }
    00091
    00092	    Controls[1].WinWidth=_Width-2*(_LineWidth+1);
    00093	    Controls[1].WinHeight=_Height-2*(_LineHeight+1)+10;
    00094	    Controls[1].WinTop=_OrgY+_Height/2+35;
    00095	    Controls[1].WinLeft=_OrgX+_LineWidth;
    00096	}
    00097
    00098	event Tick(float deltatime)
    00099	{
    00100		OnTick(deltatime);
    00101	}
    00102
    00103
    00104	function AdjustPosition(Canvas C)
    00105	{
    00106		local int i;
    00107		local float left, btnw, BetweenBtnW;
    00108
    00109		// adjust message box position
    00110		WinLeft = (C.ClipX - WinWidth)/2;
    00111		WinTop = (C.ClipY - WinHeight)/2;
    00112
    00113		// adjust title text position
    00114		Controls[0].WinLeft = WinLeft;
    00115		Controls[0].WinTop = WinTop + MarginHeight;
    00116
    00117		// adjust main text position
    00118		Controls[1].WinLeft = WinLeft + MarginWidth;
    00119		Controls[1].WinTop = WinTop + WinHeight/2 - lMessage.WinHeight/2 + lMessage.Style.BorderOffsets[1] + lMessage.Style.BorderOffsets[1] + 10;
    00120
    00121		// adjust buttons position
    00122	    btnw = 88;      // required width to fit "Abbrechen"
    00123	    BetweenBtnW = (WinWidth - Buttons.Length * btnw) / (Buttons.Length+1);
    00124	    left = WinLeft + BetweenBtnW;
    00125		for (i=0;i<Buttons.Length;i++)
    00126		{
    00127			Buttons[i].WinLeft = left;
    00128			Buttons[i].WinTop = WinTop + WinHeight - Buttons[i].ActualHeight() - 2*MarginHeight;
    00129	        left += (btnw + BetweenBtnW);
    00130		}
    00131	}
    00132
    00133
    00134	function bool InternalOnPreDraw(Canvas C)
    00135	{
    00136		local float XL, YL;
    00137		local int i;
    00138		local array<string> MsgArray, MsgArray2;
    00139		local int NeededHeight;
    00140
    00141		if ( myRoot.CurrentPF == 0 )
    00142			AdjustPosition(C);
    00143
    00144	    // captions
    00145		if (GUILabel(Controls[0]).TextFont != "")
    00146			C.Font = Controller.GetMenuFont(GUILabel(Controls[0]).TextFont).GetFont(C.SizeX);
    00147
    00148		C.TextSize("W", XL, YL);
    00149		C.WrapStringToArray(GUILabel(Controls[0]).Caption, MsgArray2, GUILabel(Controls[0]).ActualWidth(), "|");
    00150	    YL *= (MsgArray2.Length+1);
    00151		Controls[0].WinHeight = YL + GUILabel(Controls[0]).Style.BorderOffsets[1] + GUILabel(Controls[0]).Style.BorderOffsets[3];
    00152
    00153		if (lMessage.TextFont != "")
    00154			C.Font = Controller.GetMenuFont(lMessage.TextFont).GetFont(C.SizeX);
    00155
    00156		C.TextSize("W", XL, YL);
    00157		C.WrapStringToArray(lMessage.Caption, MsgArray, lMessage.ActualWidth(), "|");
    00158	    YL *= (MsgArray.Length+1); // 0 is first index.
    00159
    00160		if (lMessage.Style != None)
    00161			YL += lMessage.Style.BorderOffsets[1] + lMessage.Style.BorderOffsets[3];
    00162
    00163		lMessage.WinHeight = YL;
    00164
    00165		if (Buttons.Length==0)
    00166		  NeededHeight = lMessage.WinHeight + Controls[0].WinHeight + 2*MarginHeight;
    00167		else
    00168		  NeededHeight = lMessage.WinHeight + Buttons[0].ActualHeight() + Controls[0].WinHeight + 2*MarginHeight;
    00169	    if (NeededHeight > WinHeight)
    00170	        WinHeight = NeededHeight;
    00171
    00172		lMessage.WinTop = WinTop + WinHeight/2 - lMessage.WinHeight/2 + lMessage.Style.BorderOffsets[1] + lMessage.Style.BorderOffsets[1] + 10;
    00173
    00174		for (i = 0; i<Buttons.Length; i++)
    00175	    {
    00176			Buttons[i].WinTop = WinTop + WinHeight - Buttons[i].ActualHeight() - 2*MarginHeight;
    00177	    }
    00178
    00179		fRatioX = C.ClipX / 640;
    00180		fRatioY = C.ClipY / 480;
    00181
    00182	    OnPreDraw=None;
    00183		return true;
    00184	}
    00185
    00186	function LayoutButtons(byte ActiveButton)
    00187	{
    00188	    local int i;
    00189	    local float left, BetweenBtnW, btnw;
    00190
    00191	    btnw = 88;      // required width to fit "Abbrechen"
    00192	    BetweenBtnW = (WinWidth - Buttons.Length * btnw) / (Buttons.Length+1);
    00193	    left = WinLeft + BetweenBtnW;
    00194	    log("WinWidth="$WinWidth$", btnw="$btnw$", BetweenBtnW="$BetweenBtnW);
    00195
    00196	    //NextControl(FocusedControl);
    00197
    00198		for (i = 0; i<Buttons.Length; i++)
    00199		{
    00200			Buttons[i].WinLeft = left;
    00201			Buttons[i].WinWidth = btnw;
    00202	        Buttons[i].WinHeight = 30*fScaleTo;
    00203	        left += (btnw + BetweenBtnW);
    00204
    00205			Buttons[i].WinTop = WinTop+WinHeight - Buttons[i].WinHeight - 5;
    00206		}
    00207	}
    00208
    00209	function Paint(Canvas C, float X, float Y)
    00210	{
    00211	    local float XX,YY,W, H;
    00212	    local int i;
    00213
    00214	    local float nx, ny;
    00215
    00216		if ( myRoot.CurrentPF == 0 )
    00217		{
    00218			if (myRoot.bMapMenu || bCenterInGame)
    00219				C.SetOrigin(0, 0);
    00220			AdjustPosition(C);
    00221		}
    00222
    00223	    Super.Paint(C,X,Y);
    00224
    00225	    C.DrawMsgboxBackground(true, WinLeft, WinTop, MarginWidth, MarginHeight, WinWidth, WinHeight);
    00226	    PaintGfxBackground(C, X, Y);
    00227	    C.DrawColor = WhiteColor;       // always exit a paint with a white color !
    00228	}
    00229
    00230	function UpdateTextDisplayed(string NewText)
    00231	{
    00232	    lMessage.Caption = NewText;
    00233		OnPreDraw=InternalOnPreDraw;
    00234	}
    00235
    00236	function SetupQuestion(string Question, byte bButtons, byte ActiveButton, optional string Caption)
    00237	{
    00238		LOCAL XIIIGUIButton DefaultButton;
    00239	//  if (caption == "")
    00240	//    caption = "Error";
    00241	    GUILabel(Controls[0]).Caption = Caption;
    00242
    00243	  if (bButtons==0)
    00244	    ShowWorking = true;
    00245
00246 lMessage.Caption = Question; 00247 00248 // Create Buttons Based on Buttons parameter 00249 if ((bButtons & QBTN_Ok) != 0) 00250 AddButton(0, ActiveButton==QBTN_Ok, DefaultButton); 00251 if ((bButtons & QBTN_Continue) != 0) 00252 AddButton(3, ActiveButton==QBTN_Continue, DefaultButton); 00253 if ((bButtons & QBTN_Ignore) != 0) 00254 AddButton(7, ActiveButton==QBTN_Ignore, DefaultButton); 00255 if ((bButtons & QBTN_Yes) != 0) 00256 AddButton(4, ActiveButton==QBTN_Yes, DefaultButton); 00257 if ((bButtons & QBTN_No) != 0) 00258 AddButton(5, ActiveButton==QBTN_No, DefaultButton); 00259 if ((bButtons & QBTN_Abort) != 0) 00260 AddButton(6, ActiveButton==QBTN_Abort, DefaultButton); 00261 if ((bButtons & QBTN_Retry) != 0) 00262 AddButton(2, ActiveButton==QBTN_Retry, DefaultButton); 00263 if ((bButtons & QBTN_Cancel) != 0) 00264 { 00265 AddButton(1, ActiveButton==QBTN_Cancel, DefaultButton); 00266 CancelButton = Buttons[Buttons.Length-1]; 00267 } 00268 LayoutButtons(ActiveButton); 00269 if ( DefaultButton==none ) 00270 NextControl(FocusedControl); 00271 else 00272 DefaultButton.FocusFirst( self, false ); 00273 } 00274 00275 function bool AddButton(int idesc, bool bDefault, out XIIIGUIButton DefaultButton ) 00276 { 00277 LOCAL XIIIGUIButton btn; 00278 00279 btn = new class'XIIIGUIButton'; 00280 btn.StyleName="MsgBoxButton"; 00281 btn.InitComponent(Controller, MenuOwner); 00282 00283 Controls[Controls.Length] = btn; 00284 Buttons[Buttons.Length] = btn; 00285 btn.Caption = ButtonNames[Clamp(idesc,0,7)]; 00286 btn.OnClick = ButtonClick; 00287 btn.Tag = 1 << idesc; 00288 if ( bDefault ) 00289 DefaultButton=btn; 00290 return bDefault; 00291 } 00292 00293 function bool ButtonClick(GUIComponent Sender) 00294 { 00295 local int T; 00296 00297 T = XIIIGUIButton(Sender).Tag; 00298 00299 ParentPage.InactiveFadeColor=ParentPage.Default.InactiveFadeColor; 00300 Controller.CloseMenu(true); 00301 OnButtonClick(T); 00302 return true; 00303 } 00304 00305 function bool InternalOnKeyEvent(out byte Key, out byte State, float delta) 00306 { 00307 if (Buttons.Length==0) 00308 return true; 00309 00310 if (State==1 /*|| State==2 || State==3*/)// IST_Press // to avoid auto-repeat 00311 { 00312 if ((Key==0x0D/*IK_Enter*/)||(Key==0x01/*IK_LeftMouse*/)) 00313 { 00314 ButtonClick(Controller.FocusedControl); 00315 return true; 00316 } 00317 if (Key==0x08/*IK_Backspace*/) 00318 { 00319 if (CancelButton != none) 00320 ButtonClick(CancelButton); 00321 return true; 00322 } 00323 if (Key==0x25/*IK_Left*/) 00324 { 00325 NextControl(FocusedControl); 00326 return true; 00327 } 00328 if (Key==0x27/*IK_Right*/) 00329 { 00330 PrevControl(FocusedControl); 00331 return true; 00332 } 00333 } 00334 return Super.InternalOnKeyEvent(Key, State, delta); 00335 } 00336 00337 function string Replace(string Src, string Tag, string Value) 00338 { 00339 local string retval; 00340 local int p, tsz; 00341 00342 Tag="%"$Tag$"%"; 00343 tsz = Len(Tag); 00344 p = InStr(Src, Tag); 00345 while (p != -1) 00346 { 00347 retval = retval$Left(Src, p)$Value; 00348 Src=Mid(Src, p+tsz); 00349 p = InStr(Src, Tag); 00350 } 00351 return retval$Src; 00352 } 00353 00354 00355 00356 defaultproperties 00357 { 00358 ButtonNames(0)="Ok" 00359 ButtonNames(1)="Cancel" 00360 ButtonNames(2)="Retry" 00361 ButtonNames(3)="Continue" 00362 ButtonNames(4)="Yes" 00363 ButtonNames(5)="No" 00364 ButtonNames(6)="Abort" 00365 ButtonNames(7)="Ignore" 00366 sWorking(0)="GUIContent.Working01" 00367 sWorking(1)="GUIContent.Working02" 00368 sWorking(2)="GUIContent.Working03" 00369 sWorking(3)="GUIContent.Working02" 00370 bHidePreviousPage=False 00371 bDoStoreInSaveMenuStack=False 00372 Controls(0)=GUILabel'XIDInterf.XIIIMsgBox.TitleText' 00373 Controls(1)=GUILabel'XIDInterf.XIIIMsgBox.lblQuestion' 00374 WinTop=110.000000 00375 WinLeft=160.000000 00376 WinWidth=320.000000 00377 WinHeight=240.000000 00378 }

End Source Code