idTech4.UI.idUserInterface.InitFromFile C# (CSharp) Method

InitFromFile() public method

public InitFromFile ( string path, bool rebuild = true, bool cache = true ) : bool
path string
rebuild bool
cache bool
return bool
		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;
		}

Usage Example

示例#1
0
        public idUserInterface FindInterface(string path, bool autoLoad = false, bool needUnique = false, bool forceNotUnique = false)
        {
            foreach (idUserInterface gui in _guiList)
            {
                if (gui.SourceFile.Equals(path, StringComparison.OrdinalIgnoreCase) == true)
                {
                    if ((forceNotUnique == false) && ((needUnique == true) || (gui.IsInteractive == true)))
                    {
                        break;
                    }

                    gui.AddReference();

                    return(gui);
                }
            }

            if (autoLoad == true)
            {
                idUserInterface gui = new idUserInterface();

                if (gui.InitFromFile(path) == true)
                {
                    gui.IsUnique = (forceNotUnique == true) ? false : needUnique;
                    return(gui);
                }
            }

            return(null);
        }
All Usage Examples Of idTech4.UI.idUserInterface::InitFromFile