Exemplo n.º 1
0
        public static ControlCombination CreateFrom(string combinationString, bool logErrors = false)
        {
            if(combinationString == null)
                return null;

            string[] data = combinationString.ToLower().Split(' ');

            if(data.Length == 0)
                return null;

            var obj = new ControlCombination();

            for(int d = 0; d < data.Length; d++)
            {
                var s = data[d].Trim();

                if(s.Length == 0 || obj.raw.Contains(s))
                    continue;

                object o;

                if(InputHandler.inputs.TryGetValue(s, out o))
                {
                    obj.raw.Add(s);
                    obj.combination.Add(o);
                }
                else
                {
                    if(logErrors)
                        Log.Info("WARNING: Input not found: " + s);

                    return null;
                }
            }

            obj.combinationString = String.Join(" ", obj.raw);
            return obj;
        }
Exemplo n.º 2
0
        public static string GetFriendlyStringOr(ControlCombination input1, ControlCombination input2)
        {
            tmp.Clear();

            if(input1 != null)
                tmp.Append(input1.GetFriendlyString().ToUpper());

            if(input2 != null)
            {
                string secondary = input2.GetFriendlyString();

                if(secondary.Length > 0)
                {
                    if(tmp.Length > 0)
                        tmp.Append(" or ");

                    tmp.Append(secondary.ToUpper());
                }
            }

            var val = tmp.ToString();
            tmp.Clear();
            return val;
        }
Exemplo n.º 3
0
        public static bool GetPressedOr(ControlCombination input1, ControlCombination input2, bool anyPressed = false, bool justPressed = false)
        {
            if(input1 != null && GetPressed(input1.combination, anyPressed, justPressed))
                return true;

            if(input2 != null && GetPressed(input2.combination, anyPressed, justPressed))
                return true;

            return false;
        }
Exemplo n.º 4
0
 private void ReadSettings(TextReader file)
 {
     try
     {
         string line;
         string[] args;
         int i;
         bool b;
         
         while((line = file.ReadLine()) != null)
         {
             if(line.Length == 0)
                 continue;
             
             i = line.IndexOf("//");
             
             if(i > -1)
                 line = (i == 0 ? "" : line.Substring(0, i));
             
             if(line.Length == 0)
                 continue;
             
             args = line.Split(CHARS, 2);
             
             if(args.Length != 2)
             {
                 Log.Error("Unknown "+FILE+" line: "+line+"\nMaybe is missing the '=' ?");
                 continue;
             }
             
             args[0] = args[0].Trim().ToLower();
             args[1] = args[1].Trim().ToLower();
             
             switch(args[0])
             {
                 case "useladderinput1":
                 case "useladderinput2":
                     if(args[1].Length == 0)
                         continue;
                     var obj = ControlCombination.CreateFrom(args[1]);
                     if(obj != null)
                     {
                         if(args[0].EndsWith("1"))
                             useLadder1 = obj;
                         else
                             useLadder2 = obj;
                     }
                     else
                         Log.Error("Invalid "+args[0]+" value: " + args[1]);
                     continue;
                 case "relativecontrols":
                     if(bool.TryParse(args[1], out b))
                         relativeControls = b;
                     else
                         Log.Error("Invalid "+args[0]+" value: " + args[1]);
                     continue;
                 case "clientprediction":
                     if(bool.TryParse(args[1], out b))
                         clientPrediction = b;
                     else
                         Log.Error("Invalid "+args[0]+" value: " + args[1]);
                     continue;
             }
         }
         
         Log.Info("Loaded settings:\n" + GetSettingsString(false));
     }
     catch(Exception e)
     {
         Log.Error(e);
     }
 }