コード例 #1
0
        public bool InitFromFile(string path, bool rebuild = true, bool cache = true)
        {
            if (this.Disposed == true)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            if (path == string.Empty)
            {
                return(false);
            }

            _loading = true;

            if ((rebuild == true) || (_desktop == null))
            {
                _desktop = new idWindow(this, idE.UIManager.Context);
            }

            _sourceFile = path;
            _state.Set("text", "Test Text!");

            // load the timestamp so reload guis will work correctly
            byte[]         data    = idE.FileSystem.ReadFile(path, out _timeStamp);
            string         content = UTF8Encoding.UTF8.GetString(data);
            idScriptParser parser  = null;

            if (content != null)
            {
                parser = new idScriptParser(LexerOptions.NoFatalErrors | LexerOptions.NoStringConcatination | LexerOptions.AllowMultiCharacterLiterals | LexerOptions.AllowBackslashStringConcatination);
                parser.LoadMemory(content, path);
            }

            if ((parser != null) && (parser.IsLoaded == true))
            {
                idToken token;

                while ((token = parser.ReadToken()) != null)
                {
                    if (token.ToString().Equals("windowDef", StringComparison.OrdinalIgnoreCase) == true)
                    {
                        if (_desktop.Parse(parser, rebuild) == true)
                        {
                            _desktop.Flags = WindowFlags.Desktop;
                            _desktop.FixupParameters();
                        }
                    }
                }

                _state.Set("name", path);
            }
            else
            {
                _desktop.Name          = "Desktop";
                _desktop.Flags         = WindowFlags.Desktop;
                _desktop.Text          = string.Format("Invalid GUI: {0}", path);
                _desktop.Rectangle     = new idRectangle(0, 0, 640, 480);
                _desktop.DrawRectangle = _desktop.Rectangle;
                _desktop.ForeColor     = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
                _desktop.BackColor     = new Vector4(0.0f, 0.0f, 0.0f, 1.0f);
                _desktop.SetupFromState();

                idConsole.Warning("Couldn't load gui: '{0}'", path);
            }

            _interactive = _desktop.IsInteractive;

            if (idE.UIManager.FindInternalInterface(this) == null)
            {
                idE.UIManager.AddInternalInterface(this);
            }

            _loading = false;

            return(true);
        }
コード例 #2
0
ファイル: idGuiScript.cs プロジェクト: PEMantis/idtech4.net
        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);
        }
コード例 #3
0
		public void AddRegister(string name, RegisterType type, idScriptParser parser, idWindow window, idWindowVariable var)
		{
			idRegister register = FindRegister(name);

			if(register == null)
			{
				int regCount = idRegister.RegisterTypeCount[(int) type];
				register = new idRegister(name, type, var);
				
				if(type == RegisterType.String)
				{
					idToken token;
					
					if((token = parser.ReadToken()) != null)
					{
						var.Init(idE.Language.Get(token.ToString()), window);
					}
				}
				else
				{
					for(int i = 0; i < regCount; i++)
					{
						register.Indexes[i] = window.ParseExpression(parser, null);

						if(i < (regCount - 1))
						{
							parser.ExpectTokenString(",");
						}
					}
				}

				_registers.Add(register);
				_registerDict.Add(name, register);
			}
			else
			{
				int regCount = idRegister.RegisterTypeCount[(int) type];

				register.Variable = var;

				if(type == RegisterType.String)
				{
					idToken token = parser.ReadToken();

					if(token != null)
					{
						var.Init(token.ToString(), window);
					}
				}
				else
				{
					for(int i = 0; i < regCount; i++)
					{
						register.Indexes[i] = window.ParseExpression(parser, null);

						if(i < (regCount - 1))
						{
							parser.ExpectTokenString(",");
						}
					}
				}
			}
		}