public idRegister(string name, RegisterType type, idWindowVariable var) { _name = name; _type = type; _var = var; _registerCount = RegisterTypeCount[(int)type]; _enabled = (_type == RegisterType.String) ? false : true; }
public idWindowVariable GetVariableByName(string name) { idWindowVariable ret = null; string nameLower = name.ToLower(); 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 == "bordercolor") { ret = _borderColor; } else if (nameLower == "textscale") { ret = _textScale; } else if (nameLower == "rotate") { ret = _rotate; } else if (nameLower == "text") { ret = _text; } else if (nameLower == "backgroundname") { ret = _backgroundName; } else if (nameLower == "hidecursor") { ret = _hideCursor; } return(ret); }
public idWinGuiScript(bool owner, idWindowVariable var) { _owner = owner; _variable = var; }
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); } } }
public void Add(idWindowVariable var) { _vars.Add(var); }
public idRegister(string name, RegisterType type, idWindowVariable var) { _name = name; _type = type; _var = var; _registerCount = RegisterTypeCount[(int) type]; _enabled = (_type == RegisterType.String) ? false : true; }
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(","); } } } } }
/// <summary> /// /// </summary> /// <param name="parser"></param> /// <param name="var"></param> /// <param name="component"></param> /// <returns>Returns a register index.</returns> private int ParseTerm(idScriptParser parser, idWindowVariable var, int component) { int a, b; object tmp; idToken token = parser.ReadToken(); string tokenValue = token.ToString().ToLower(); if(tokenValue == "(") { a = ParseExpression(parser); parser.ExpectTokenString(")"); return a; } else if(tokenValue == "time") { return (int) WindowExpressionRegister.Time; } // parse negative numbers else if(tokenValue == "-") { token = parser.ReadToken(); if((token.Type == TokenType.Number) || (token.ToString() == ".")) { return ExpressionConstant(-token.ToFloat()); } parser.Warning("Bad negative number '{0}'", token.ToString()); return 0; } if((token.Type == TokenType.Number) || (token.ToString() == ".") || (token.ToString() == "-")) { return ExpressionConstant(token.ToFloat()); } // see if it is a table name idDeclTable table = idE.DeclManager.FindType<idDeclTable>(DeclType.Table, token.ToString(), false); if(table != null) { a = table.Index; // parse a table expression parser.ExpectTokenString("["); b = ParseExpression(parser); parser.ExpectTokenString("]"); return EmitOperation(a, b, WindowExpressionOperationType.Table); } if(var == null) { var = GetVariableByName(token.ToString(), true); } if(var != null) { var.Init(tokenValue, this); tmp = var; b = component; if(var is idWinVector4) { if((token = parser.ReadToken()) != null) { if(token.ToString() == "[") { b = ParseExpression(parser); parser.ExpectTokenString("]"); } else { parser.UnreadToken(token); } } return EmitOperation(tmp, b, WindowExpressionOperationType.Var); } else if(var is idWinFloat) { return EmitOperation(tmp, b, WindowExpressionOperationType.VarF); } else if(var is idWinInteger) { return EmitOperation(tmp, b, WindowExpressionOperationType.VarI); } else if(var is idWinBool) { return EmitOperation(tmp, b, WindowExpressionOperationType.VarB); } else if(var is idWinString) { return EmitOperation(tmp, b, WindowExpressionOperationType.VarS); } else { parser.Warning("Variable expression not vec4, float or int '{0}'", token.ToString()); } return 0; } else { // ugly but used for post parsing to fixup named vars EmitOperation(token.ToString(), -2, WindowExpressionOperationType.Var); } return 0; }
public TransitionData(idWindowVariable var) { this.Variable = var; this.Interp = new idInterpolateAccelerationDecelerationLinear<Vector4>(); this.Offset = 0; }
private int ParseExpressionPriority(idScriptParser parser, int priority, idWindowVariable var = null, int component = 0) { if(priority == 0) { return ParseTerm(parser, var, component); } idToken token; string tokenValue; int a = ParseExpressionPriority(parser, priority - 1, var, component); if((token = parser.ReadToken()) == null) { // we won't get EOF in a real file, but we can when parsing from generated strings return a; } tokenValue = token.ToString(); if(priority == 1) { if(tokenValue == "*") { return ParseEmitOperation(parser, a, WindowExpressionOperationType.Multiply, priority); } else if(tokenValue == "/") { return ParseEmitOperation(parser, a, WindowExpressionOperationType.Divide, priority); } else if(tokenValue == "%") { return ParseEmitOperation(parser, a, WindowExpressionOperationType.Modulo, priority); } } else if(priority == 2) { if(tokenValue == "+") { return ParseEmitOperation(parser, a, WindowExpressionOperationType.Add, priority); } else if(tokenValue == "-") { return ParseEmitOperation(parser, a, WindowExpressionOperationType.Subtract, priority); } } else if(priority == 3) { if(tokenValue == ">") { return ParseEmitOperation(parser, a, WindowExpressionOperationType.GreaterThan, priority); } else if(tokenValue == ">=") { return ParseEmitOperation(parser, a, WindowExpressionOperationType.GreaterThanOrEqual, priority); } else if(tokenValue == "<") { return ParseEmitOperation(parser, a, WindowExpressionOperationType.LessThan, priority); } else if(tokenValue == "<=") { return ParseEmitOperation(parser, a, WindowExpressionOperationType.LessThanOrEqual, priority); } else if(tokenValue == "==") { return ParseEmitOperation(parser, a, WindowExpressionOperationType.Equal, priority); } else if(tokenValue == "!=") { return ParseEmitOperation(parser, a, WindowExpressionOperationType.NotEqual, priority); } } else if(priority == 4) { if(tokenValue == "&&") { return ParseEmitOperation(parser, a, WindowExpressionOperationType.And, priority); } else if(tokenValue == "||") { return ParseEmitOperation(parser, a, WindowExpressionOperationType.Or, priority); } else if(tokenValue == "?") { WindowExpressionOperation op; int o = ParseEmitOperation(parser, a, WindowExpressionOperationType.Conditional, priority, out op); if((token = parser.ReadToken()) == null) { return o; } else if(token.ToString() == ":") { a = ParseExpressionPriority(parser, priority - 1, var); op.D = a; } return priority; } } // assume that anything else terminates the expression // not too robust error checking... parser.UnreadToken(token); return a; }
/// <summary> /// Returns a register index. /// </summary> /// <param name="parser"></param> /// <param name="var"></param> /// <param name="component"></param> /// <returns></returns> public int ParseExpression(idScriptParser parser, idWindowVariable var, int component) { if(this.Disposed == true) { throw new ObjectDisposedException(this.GetType().Name); } return ParseExpressionPriority(parser, 4 /* TOP_PRIORITY */, var); }
public void AddUpdateVariable(idWindowVariable var) { if(this.Disposed == true) { throw new ObjectDisposedException(this.GetType().Name); } _updateVariables.Add(var); }
public void AddTransition(idWindowVariable dest, Vector4 from, Vector4 to, int time, float accelTime, float decelTime) { if(this.Disposed == true) { throw new ObjectDisposedException(this.GetType().Name); } TransitionData data = new TransitionData(dest); data.Interp.Init(this.UserInterface.Time, accelTime * time, decelTime * time, time, from, to); _transitions.Add(data); }
public void AddDefinedVariable(idWindowVariable var) { if(this.Disposed == true) { throw new ObjectDisposedException(this.GetType().Name); } if(_definedVariables.Contains(var) == false) { _definedVariables.Add(var); } }