idTech4.UI.idWindow.AddDefinedVariable C# (CSharp) Method

AddDefinedVariable() public method

public AddDefinedVariable ( idWindowVariable var ) : void
var idWindowVariable
return void
		public void AddDefinedVariable(idWindowVariable var)
		{
			if(this.Disposed == true)
			{
				throw new ObjectDisposedException(this.GetType().Name);
			}

			if(_definedVariables.Contains(var) == false)
			{
				_definedVariables.Add(var);
			}
		}

Usage Example

Example #1
0
		public void FixupParameters(idWindow window)
		{
			if(_handler == Script_Set)
			{
				bool precacheBackground = false;
				bool precacheSounds = false;

				idWinString str = (idWinString) _parameters[0].Variable;
				idWindowVariable dest = window.GetVariableByName(str.ToString(), true);

				if(dest != null)
				{
					_parameters[0].Variable = dest;
					_parameters[0].Owner = false;

					if(dest is idWinBackground)
					{
						precacheBackground = true;
					}
				}
				else if(str.ToString().ToLower() == "cmd")
				{
					precacheSounds = true;
				}

				int parameterCount = _parameters.Count;

				for(int i = 1; i < parameterCount; i++)
				{
					str = (idWinString) _parameters[i].Variable;
					string strValue = str.ToString();

					if(strValue.StartsWith("gui::", StringComparison.InvariantCultureIgnoreCase) == true)
					{
						//  always use a string here, no point using a float if it is one
						//  FIXME: This creates duplicate variables, while not technically a problem since they
						//  are all bound to the same guiDict, it does consume extra memory and is generally a bad thing
						idWinString defVar = new idWinString(null);
						defVar.Init(strValue, window);

						window.AddDefinedVariable(defVar);

						_parameters[i].Variable = defVar;
						_parameters[i].Owner = false;

						//dest = win->GetWinVarByName(*str, true);
						//if (dest) {
						//	delete parms[i].var;
						//	parms[i].var = dest;
						//	parms[i].own = false;
						//}
						// 
					}
					else if(strValue.StartsWith("$") == true)
					{
						// 
						//  dont include the $ when asking for variable
						dest = window.UserInterface.Desktop.GetVariableByName(strValue.Substring(1), true);
						// 					
						if(dest != null)
						{
							_parameters[i].Variable = dest;
							_parameters[i].Owner = false;
						}
					}
					else if(strValue.StartsWith("#str_") == true)
					{
						str.Set(idE.Language.Get(strValue));
					}
					else if(precacheBackground == true)
					{
						idE.DeclManager.FindMaterial(strValue).Sort = (float) MaterialSort.Gui;
					}
					else if(precacheSounds == true)
					{
						idConsole.Warning("TODO: PrecacheSounds");
						// Search for "play <...>"
						/*idToken token;
						idParser parser( LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT );
						parser.LoadMemory(str->c_str(), str->Length(), "command");

						while ( parser.ReadToken(&token) ) {
							if ( token.Icmp("play") == 0 ) {
								if ( parser.ReadToken(&token) && ( token != "" ) ) {
									declManager->FindSound( token.c_str() );
								}
							}
						}*/
					}
				}
			}
			else if(_handler == Script_Transition)
			{
				if(_parameters.Count < 4)
				{
					idConsole.Warning("Window {0} in gui {1} has a bad transition definition", window.Name, window.UserInterface.SourceFile);
				}

				idWinString str = (idWinString) _parameters[0].Variable;

				// 
				DrawWindow destOwner = null;
				idWindowVariable dest = window.GetVariableByName(str.ToString(), true, ref destOwner);
				// 

				if(dest != null)
				{
					_parameters[0].Variable = dest;
					_parameters[0].Owner = false;
				}
				else
				{
					idConsole.Warning("Window {0} in gui {1}: a transition does not have a valid destination var {2}", window.Name, window.UserInterface.SourceFile, str);
				}

				// 
				//  support variables as parameters		
				for(int c = 1; c < 3; c++)
				{
					str = (idWinString) _parameters[c].Variable;
					idWinVector4 v4 = new idWinVector4(null);

					_parameters[c].Variable = v4;
					_parameters[c].Owner = true;

					DrawWindow owner = null;

					if(str.ToString().StartsWith("$") == true)
					{
						dest = window.GetVariableByName(str.ToString().Substring(1), true, ref owner);
					}
					else
					{
						dest = null;
					}

					if(dest != null)
					{
						idWindow ownerParent;
						idWindow destParent;

						if(owner != null)
						{
							ownerParent = (owner.Simple != null) ? owner.Simple.Parent : owner.Window.Parent;
							destParent = (destOwner.Simple != null) ? destOwner.Simple.Parent : destOwner.Window.Parent;

							// if its the rectangle they are referencing then adjust it 
							if((ownerParent != null) && (destParent != null) && (dest == ((owner.Simple != null) ? owner.Simple.GetVariableByName("rect") : owner.Window.GetVariableByName("rect"))))
							{
								idRectangle rect = ((idWinRectangle) dest).Data;
								ownerParent.ClientToScreen(ref rect);
								destParent.ScreenToClient(ref rect);

								v4.Set(dest.ToString());
							}
							else
							{
								v4.Set(dest.ToString());
							}
						}
						else
						{
							v4.Set(dest.ToString());
						}
					}
					else
					{
						v4.Set(str.ToString());
					}
				}
			}
			else
			{
				int c = _parameters.Count;

				for(int i = 0; i < c; i++)
				{
					_parameters[i].Variable.Init(_parameters[i].Variable.ToString(), window);
				}
			}
		}