Inheritance: idWindowVariable
Beispiel #1
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();
                }
            }
        }
Beispiel #2
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);
				}
			}
		}
Beispiel #3
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);
                }
            }
        }
Beispiel #4
0
		public bool Parse(idScriptParser parser, bool rebuild)
		{
			if(this.Disposed == true)
			{
				throw new ObjectDisposedException(this.GetType().Name);
			}

			if(rebuild == true)
			{
				CleanUp();
			}

			_timeLineEvents.Clear();
			_namedEvents.Clear();
			_transitions.Clear();

			idToken token2;
			idToken token = parser.ExpectTokenType(TokenType.Name, 0);
			DrawWindow drawWindow;

			SetInitialState(token.ToString());

			parser.ExpectTokenString("{");
			token = parser.ExpectAnyToken();

			bool ret = true;

			while(token.ToString() != "}")
			{
				string tokenLower = token.ToString().ToLower();

				// track what was parsed so we can maintain it for the guieditor
				parser.SetMarker();

				if((tokenLower == "windowdef") || (tokenLower == "animationdef"))
				{
					if(tokenLower == "animationdef")
					{
						_visible.Set(false);
						_rect.Set(new idRectangle(0, 0, 0, 0));
					}

					token = parser.ExpectTokenType(TokenType.Name, 0);
					token2 = token;

					parser.UnreadToken(token);

					drawWindow = FindChildByName(token2.ToString());

					if((drawWindow != null) && (drawWindow.Window != null))
					{
						SaveExpressionParseState();
						drawWindow.Window.Parse(parser, rebuild);
						RestoreExpressionParseState();
					}
					else
					{
						idWindow window = new idWindow(_gui, _context);

						SaveExpressionParseState();
						window.Parse(parser, rebuild);
						RestoreExpressionParseState();

						window.Parent = this;

						drawWindow = new DrawWindow();

						if(window.IsSimple == true)
						{
							drawWindow.Simple = new idSimpleWindow(window);
							_drawWindows.Add(drawWindow);
						}
						else
						{
							AddChild(window);
							SetFocus(window, false);

							drawWindow.Window = window;
							_drawWindows.Add(drawWindow);
						}
					}
				}
				else if(tokenLower == "editdef")
				{
					SaveExpressionParseState();

					idEditWindow window = new idEditWindow(_context, _gui);
					window.Parse(parser, rebuild);

					RestoreExpressionParseState();

					AddChild(window);

					window.Parent = this;

					drawWindow = new DrawWindow();
					drawWindow.Simple = null;
					drawWindow.Window = window;

					_drawWindows.Add(drawWindow);
				}
				else if(tokenLower == "choicedef")
				{
					SaveExpressionParseState();

					idChoiceWindow window = new idChoiceWindow(_context, _gui);
					window.Parse(parser, rebuild);

					RestoreExpressionParseState();

					AddChild(window);

					window.Parent = this;

					drawWindow = new DrawWindow();
					drawWindow.Simple = null;
					drawWindow.Window = window;

					_drawWindows.Add(drawWindow);
				}
				else if(tokenLower == "sliderdef")
				{
					SaveExpressionParseState();

					idSliderWindow window = new idSliderWindow(_context, _gui);
					window.Parse(parser, rebuild);

					RestoreExpressionParseState();

					AddChild(window);

					window.Parent = this;

					drawWindow = new DrawWindow();
					drawWindow.Simple = null;
					drawWindow.Window = window;

					_drawWindows.Add(drawWindow);
				}
				else if(tokenLower == "markerdef")
				{
					idConsole.Warning("TODO: markerDef");
					/*idMarkerWindow *win = new idMarkerWindow(dc, gui);
					SaveExpressionParseState();
					win->Parse(src, rebuild);	
					RestoreExpressionParseState();
					AddChild(win);
					win->SetParent(this);
					dwt.simp = NULL;
					dwt.win = win;
					drawWindows.Append(dwt);*/
				}
				else if(tokenLower == "binddef")
				{
					SaveExpressionParseState();

					idBindWindow window = new idBindWindow(_context, _gui);
					window.Parse(parser, rebuild);

					RestoreExpressionParseState();

					AddChild(window);

					window.Parent = this;

					drawWindow = new DrawWindow();
					drawWindow.Simple = null;
					drawWindow.Window = window;

					_drawWindows.Add(drawWindow);
				}
				else if(tokenLower == "listdef")
				{
					SaveExpressionParseState();

					idListWindow window = new idListWindow(_context, _gui);
					window.Parse(parser, rebuild);

					RestoreExpressionParseState();

					AddChild(window);

					window.Parent = this;

					drawWindow = new DrawWindow();
					drawWindow.Simple = null;
					drawWindow.Window = window;

					_drawWindows.Add(drawWindow);
				}
				else if(tokenLower == "fielddef")
				{
					idConsole.Warning("TODO: fieldDef");
					/*idFieldWindow *win = new idFieldWindow(dc, gui);
					SaveExpressionParseState();
					win->Parse(src, rebuild);	
					RestoreExpressionParseState();
					AddChild(win);
					win->SetParent(this);
					dwt.simp = NULL;
					dwt.win = win;
					drawWindows.Append(dwt);*/
				}
				else if(tokenLower == "renderdef")
				{					
					SaveExpressionParseState();

					idRenderWindow window = new idRenderWindow(_context, _gui);
					window.Parse(parser, rebuild);

					RestoreExpressionParseState();

					AddChild(window);

					window.Parent = this;

					drawWindow = new DrawWindow();
					drawWindow.Simple = null;
					drawWindow.Window = window;

					_drawWindows.Add(drawWindow);
				}
				else if(tokenLower == "gamessddef")
				{
					idConsole.Warning("TODO: gameSSDDef");
					/*idGameSSDWindow *win = new idGameSSDWindow(dc, gui);
					SaveExpressionParseState();
					win->Parse(src, rebuild);	
					RestoreExpressionParseState();
					AddChild(win);
					win->SetParent(this);
					dwt.simp = NULL;
					dwt.win = win;
					drawWindows.Append(dwt);*/
				}
				else if(tokenLower == "gamebearshootdef")
				{
					idConsole.Warning("TODO: gameBearShootDef");
					/*idGameBearShootWindow *win = new idGameBearShootWindow(dc, gui);
					SaveExpressionParseState();
					win->Parse(src, rebuild);	
					RestoreExpressionParseState();
					AddChild(win);
					win->SetParent(this);
					dwt.simp = NULL;
					dwt.win = win;
					drawWindows.Append(dwt);*/
				}
				else if(tokenLower == "gamebustoutdef")
				{
					idConsole.Warning("TODO: gameBustOutDef");
					/*idGameBustOutWindow *win = new idGameBustOutWindow(dc, gui);
					SaveExpressionParseState();
					win->Parse(src, rebuild);	
					RestoreExpressionParseState();
					AddChild(win);
					win->SetParent(this);
					dwt.simp = NULL;
					dwt.win = win;
					drawWindows.Append(dwt);*/
				}
				// 
				//  added new onEvent
				else if(tokenLower == "onnamedevent")
				{
					// read the event name
					if((token = parser.ReadToken()) == null)
					{
						parser.Error("Expected event name");
						return false;
					}

					idNamedEvent ev = new idNamedEvent(token.ToString());
					parser.SetMarker();

					if(ParseScript(parser, ev.Event) == false)
					{
						ret = false;
						break;
					}

					_namedEvents.Add(ev);
				}
				else if(tokenLower == "ontime")
				{
					idTimeLineEvent ev = new idTimeLineEvent();

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

					int tmp;
					int.TryParse(token.ToString(), out tmp);

					ev.Time = tmp;

					// reset the mark since we dont want it to include the time
					parser.SetMarker();

					if(ParseScript(parser, ev.Event) == false)
					{
						ret = false;
						break;
					}

					// this is a timeline event
					ev.Pending = true;
					_timeLineEvents.Add(ev);
				}
				else if(tokenLower == "definefloat")
				{
					token = parser.ReadToken();
					tokenLower = token.ToString().ToLower();

					idWinFloat var = new idWinFloat(tokenLower);

					_definedVariables.Add(var);

					// add the float to the editors wrapper dict
					// Set the marker after the float name
					parser.SetMarker();

					// Read in the float 
					_regList.AddRegister(tokenLower, RegisterType.Float, parser, this, var);
				}
				else if(tokenLower == "definevec4")
				{
					token = parser.ReadToken();
					tokenLower = token.ToString().ToLower();

					idWinVector4 var = new idWinVector4(tokenLower);

					// set the marker so we can determine what was parsed
					// set the marker after the vec4 name
					parser.SetMarker();

					// FIXME: how about we add the var to the desktop instead of this window so it won't get deleted
					//        when this window is destoyed which even happens during parsing with simple windows ?
					//definedVars.Append(var);
					_gui.Desktop._definedVariables.Add(var);
					_gui.Desktop._regList.AddRegister(tokenLower, RegisterType.Vector4, parser, _gui.Desktop, var);
				}
				else if(tokenLower == "float")
				{
					token = parser.ReadToken();
					tokenLower = token.ToString();

					idWinFloat var = new idWinFloat(tokenLower);
					_definedVariables.Add(var);

					// add the float to the editors wrapper dict
					// set the marker to after the float name
					parser.SetMarker();

					// Parse the float
					_regList.AddRegister(tokenLower, RegisterType.Float, parser, this, var);
				}
				else if(ParseScriptEntry(token, parser) == true)
				{

				}
				else if(ParseInternalVariable(token.ToString(), parser) == true)
				{

				}
				else
				{
					ParseRegisterEntry(token.ToString(), parser);
				}

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

					break;
				}
			}

			if(ret == true)
			{
				EvaluateRegisters(-1, true);
			}

			SetupFromState();
			PostParse();

			return ret;
		}