Inheritance: idWindowVariable
Exemple #1
0
        private static void Script_ResetTime(idWindow window, List <idWinGuiScript> source)
        {
            idWinString parameter  = (source.Count > 0) ? source[0].Variable as idWinString : null;
            DrawWindow  drawWindow = null;

            if ((parameter != null) && (source.Count > 1))
            {
                drawWindow = window.UserInterface.Desktop.FindChildByName(parameter);
                parameter  = source[1].Variable as idWinString;
            }

            int tmp;

            int.TryParse(parameter, out tmp);

            if ((drawWindow != null) && (drawWindow.Window != null))
            {
                drawWindow.Window.ResetTime(tmp);
                drawWindow.Window.EvaluateRegisters(-1, true);
            }
            else
            {
                window.ResetTime(tmp);
                window.EvaluateRegisters(-1, true);
            }
        }
Exemple #2
0
        private static void Script_SetFocus(idWindow window, List <idWinGuiScript> source)
        {
            idWinString parameter = source[0].Variable as idWinString;

            if (parameter != null)
            {
                DrawWindow drawWindow = window.UserInterface.Desktop.FindChildByName(parameter.ToString());

                if ((drawWindow != null) && (drawWindow.Window != null))
                {
                    window.SetFocus(drawWindow.Window);
                }
            }
        }
Exemple #3
0
        private static void Script_Transition(idWindow window, List <idWinGuiScript> source)
        {
            // transitions always affect rect or vec4 vars
            if (source.Count >= 4)
            {
                idWinRectangle rect = null;
                idWinVector4   vec4 = source[0].Variable as idWinVector4;

                //
                //  added float variable
                idWinFloat val = null;
                //
                if (vec4 == null)
                {
                    rect = source[0].Variable as idWinRectangle;
                    //
                    //  added float variable
                    if (rect == null)
                    {
                        val = source[0].Variable as idWinFloat;
                    }
                    //
                }

                idWinVector4 from    = source[1].Variable as idWinVector4;
                idWinVector4 to      = source[2].Variable as idWinVector4;
                idWinString  timeStr = source[3].Variable as idWinString;
                //
                //  added float variable
                if (((vec4 == null) && (rect == null) && (val == null)) && (from != null) && (to != null) && (timeStr != null))
                {
                    idConsole.Warning("Bad transition in gui {0} in window {1}", window.UserInterface.SourceFile, window.Name);
                }
                else
                {
                    int time;
                    int.TryParse(timeStr.ToString(), out time);

                    float accel = 0.0f;
                    float decel = 0.0f;

                    if (source.Count > 4)
                    {
                        idWinString accelStr = source[4].Variable as idWinString;
                        idWinString decelStr = source[5].Variable as idWinString;

                        float.TryParse(accelStr.ToString(), out accel);
                        float.TryParse(decelStr.ToString(), out decel);
                    }

                    if (vec4 != null)
                    {
                        vec4.Evaluate = false;
                        window.AddTransition(vec4, from, to, time, accel, decel);
                    }
                    else if (val != null)
                    {
                        val.Evaluate = false;
                        window.AddTransition(val, from, to, time, accel, decel);
                    }
                    else
                    {
                        rect.Evaluate = false;
                        window.AddTransition(rect, from, to, time, accel, decel);
                    }

                    window.StartTransition();
                }
            }
        }
Exemple #4
0
        public bool Parse(idScriptParser parser)
        {
            // first token should be function call
            // then a potentially variable set of parms
            // ended with a ;
            idToken    token;
            GuiCommand cmd = new GuiCommand();

            if ((token = parser.ReadToken()) == null)
            {
                parser.Error("Unexpected end of file");
                return(false);
            }

            _handler = null;

            string tokenLower = token.ToString().ToLower();

            foreach (GuiCommand tmp in CommandList)
            {
                if (tmp.Name.ToLower() == tokenLower)
                {
                    _handler = tmp.Handler;
                    cmd      = tmp;
                    break;
                }
            }

            if (_handler == null)
            {
                parser.Error("Unknown script call {0}", token.ToString());
            }

            // now read parms til ;
            // all parms are read as idWinStr's but will be fixed up later
            // to be proper types
            while (true)
            {
                if ((token = parser.ReadToken()) == null)
                {
                    parser.Error("Unexpected end of file");
                    return(false);
                }

                tokenLower = token.ToString().ToLower();

                if (tokenLower == ";")
                {
                    break;
                }
                else if (tokenLower == "}")
                {
                    parser.UnreadToken(token);
                    break;
                }

                idWinString str = new idWinString(string.Empty);
                str.Set(token.ToString());

                _parameters.Add(new idWinGuiScript(true, str));
            }

            //
            //  verify min/max params
            if ((_handler != null) && ((_parameters.Count < cmd.MinParameterCount) || (_parameters.Count > cmd.MaxParameterCount)))
            {
                parser.Error("incorrect number of parameters for script {0}", cmd.Name);
            }
            //

            return(true);
        }
		private void Init()
		{
			_bindName = new idWinString("bind");
			_waitingOnKey = false;
		}
Exemple #6
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);
                }
            }
        }
Exemple #7
0
 private void Init()
 {
     _bindName     = new idWinString("bind");
     _waitingOnKey = false;
 }
Exemple #8
0
		public bool Parse(idScriptParser parser)
		{
			// first token should be function call
			// then a potentially variable set of parms
			// ended with a ;
			idToken token;
			GuiCommand cmd = new GuiCommand();

			if((token = parser.ReadToken()) == null)
			{
				parser.Error("Unexpected end of file");
				return false;
			}

			_handler = null;

			string tokenLower = token.ToString().ToLower();

			foreach(GuiCommand tmp in CommandList)
			{
				if(tmp.Name.ToLower() == tokenLower)
				{
					_handler = tmp.Handler;
					cmd = tmp;
					break;
				}
			}

			if(_handler == null)
			{
				parser.Error("Unknown script call {0}", token.ToString());
			}

			// now read parms til ;
			// all parms are read as idWinStr's but will be fixed up later 
			// to be proper types
			while(true)
			{
				if((token = parser.ReadToken()) == null)
				{
					parser.Error("Unexpected end of file");
					return false;
				}

				tokenLower = token.ToString().ToLower();

				if(tokenLower == ";")
				{
					break;
				}
				else if(tokenLower == "}")
				{
					parser.UnreadToken(token);
					break;
				}

				idWinString str = new idWinString(string.Empty);
				str.Set(token.ToString());

				_parameters.Add(new idWinGuiScript(true, str));
			}

			// 
			//  verify min/max params
			if((_handler != null) && ((_parameters.Count < cmd.MinParameterCount) || (_parameters.Count > cmd.MaxParameterCount)))
			{
				parser.Error("incorrect number of parameters for script {0}", cmd.Name);
			}
			// 

			return true;
		}
Exemple #9
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);
				}
			}
		}
Exemple #10
0
		private bool ParseRegisterEntry(string name, idScriptParser parser)
		{
			string work = name.ToLower();
			idWindowVariable var = GetVariableByName(work, false);

			if(var != null)
			{
				RegisterType regType;

				// check builtins first
				if(_builtInVariables.TryGetValue(work, out regType) == true)
				{
					_regList.AddRegister(work, regType, parser, this, var);

					return true;
				}
			}

			// not predefined so just read the next token and add it to the state
			idToken token;

			if((token = parser.ReadToken()) != null)
			{
				if(var != null)
				{
					var.Set(token.ToString());
					return true;
				}

				switch(token.Type)
				{
					case TokenType.Number:
						if((token.SubType & TokenSubType.Integer) == TokenSubType.Integer)
						{
							var = new idWinInteger(work);
							var.Set(token.ToString());
						}
						else if((token.SubType & TokenSubType.Float) == TokenSubType.Float)
						{
							var = new idWinFloat(work);
							var.Set(token.ToString());
						}
						else
						{
							var = new idWinString(work);
							var.Set(token.ToString());
						}

						_definedVariables.Add(var);
						break;

					default:
						var = new idWinString(work);
						var.Set(token.ToString());

						_definedVariables.Add(var);
						break;
				}
			}

			return true;
		}
Exemple #11
0
		public virtual idWindowVariable GetVariableByName(string name, bool fixup, ref DrawWindow owner)
		{
			if(this.Disposed == true)
			{
				throw new ObjectDisposedException(this.GetType().Name);
			}

			idWindowVariable ret = null;

			if(owner != null)
			{
				owner = null;
			}

			string nameLower = name.ToLower();

			if(nameLower == "notime")
			{
				ret = _noTime;
			}
			else if(nameLower == "background")
			{
				ret = _backgroundName;
			}
			else if(nameLower == "visible")
			{
				ret = _visible;
			}
			else if(nameLower == "rect")
			{
				ret = _rect;
			}
			else if(nameLower == "backcolor")
			{
				ret = _backColor;
			}
			else if(nameLower == "matcolor")
			{
				ret = _materialColor;
			}
			else if(nameLower == "forecolor")
			{
				ret = _foreColor;
			}
			else if(nameLower == "hovercolor")
			{
				ret = _hoverColor;
			}
			else if(nameLower == "bordercolor")
			{
				ret = _borderColor;
			}
			else if(nameLower == "textscale")
			{
				ret = _textScale;
			}
			else if(nameLower == "rotate")
			{
				ret = _rotate;
			}
			else if(nameLower == "noevents")
			{
				ret = _noEvents;
			}
			else if(nameLower == "text")
			{
				ret = _text;
			}
			else if(nameLower == "backgroundname")
			{
				ret = _backgroundName;
			}
			else if(nameLower == "hidecursor")
			{
				ret = _hideCursor;
			}

			string key = name;
			bool guiVar = key.StartsWith(idWindowVariable.Prefix);

			foreach(idWindowVariable var in _definedVariables)
			{
				if(nameLower.Equals(var.Name, StringComparison.OrdinalIgnoreCase) == true)
				{
					ret = var;
					break;
				}
			}

			if(ret != null)
			{
				if((fixup == true) && (name.StartsWith("$") == false))
				{
					DisableRegister(name);
				}

				if(_parent != null)
				{
					owner = _parent.FindChildByName(_name);
				}

				return ret;
			}

			int keyLength = key.Length;

			if((keyLength > 5) && (guiVar == true))
			{
				idWindowVariable var = new idWinString(name);
				var.Init(name, this);

				_definedVariables.Add(var);

				return var;
			}
			else if(fixup == true)
			{
				int n = key.IndexOf("::");

				if(n > 0)
				{
					string winName = key.Substring(0, n);
					string var = key.Substring(n + 2);

					DrawWindow win = this.UserInterface.Desktop.FindChildByName(winName);

					if(win != null)
					{
						if(win.Window != null)
						{
							return win.Window.GetVariableByName(var, false, ref owner);
						}
						else
						{
							owner = win;
						}

						return win.Simple.GetVariableByName(var);
					}
				}
			}

			return null;
		}