Example #1
0
    public void ShowWidget(WidgetTypes widgetType)
    {
        // destroy current widget
        if (currentWidget != null)
        {
            // destroy widget when new WidgetType is not equel to currentWidget
            if (widgetType != currentWidget.GetComponent <AWidget>().WidgetType)
            {
                Destroy(currentWidget);
            }
        }

        if (widgetType == WidgetTypes.Default)
        {
            Debug.LogWarning("Widget type is Default.");
        }
        else
        {
            // instantiate new widget
            try
            {
                currentWidget = GameObject.Instantiate(Widgets.Find(w => w.GetComponent <AWidget>().WidgetType == widgetType));
            }
            catch (System.Exception)
            {
                Debug.LogError("Can't instantiate Widget: " + widgetType + ", make sure it is provided to the WidgetManager!");
            }
        }
    }
Example #2
0
        private string GetIconStylesToValue(WidgetTypes widgetType, IconStyles?iconStyles)
        {
            if (widgetType == WidgetTypes.AppWidget && !iconStyles.HasValue)
            {
                throw new ArgumentNullException(nameof(iconStyles));
            }

            return(widgetType == WidgetTypes.AppWidget && iconStyles == IconStyles.YandexMono ? "_mono" : null);
        }
Example #3
0
        private string GetConditionIconResource(WidgetTypes widgetType, IconStyles?iconStyles, string codes,
                                                string theme)
        {
            var result =
                string.Format("{0}{1}{2}{3}{4}", GetIconStylesPrefix(widgetType, iconStyles),
                              WidgetTypeToValue(widgetType), codes, GetIconStylesToValue(widgetType, iconStyles), theme);

            return(result);
        }
Example #4
0
        public int GetConditionIconId(WidgetTypes widgetType, IconStyles?iconStyles, IWeatherDataPoint dataPoint,
                                      bool useTwilight, bool isCurrently)
        {
            var weatherCode = dataPoint?.WeatherCode;

            // sunrise, sunset
            var dataPointDate = dataPoint?.Date;

            if (dataPointDate.HasValue)
            {
                if (isCurrently)
                {
                    var now = DateTime.UtcNow;
                    if (dataPointDate < now)
                    {
                        dataPointDate = now;
                    }
                }
            }

            var conditionIconResource = GetConditionIconResource(weatherCode, dataPoint?.WeatherUnrecognizedCode,
                                                                 useTwilight, dataPointDate, dataPoint?.Astronomy);
            var resourceName = GetConditionIconResource(widgetType, iconStyles, conditionIconResource,
                                                        AppSettings.WeatherConditionIconTheme);

            var resourceId = GetIdentifier(resourceName);

            if (!resourceId.HasValue)
            {
                var name = resourceName;
                if (name.Contains("_min"))
                {
                    name       = name.Replace("_min", string.Empty);
                    resourceId = GetIdentifier(name);
                }

                if (!resourceId.HasValue)
                {
                    if (name.Contains("_max"))
                    {
                        name       = name.Replace("_max", string.Empty);
                        resourceId = GetIdentifier(name);
                    }
                }
            }

            if (!resourceId.HasValue && weatherCode != WeatherCodes.Undefined && weatherCode != WeatherCodes.Error)
            {
                Log.ErrorFormat("Can't find condition icon by code '{0}', resource name '{1}'.", weatherCode,
                                resourceName);
            }

            return(resourceId ?? GetUnderfoundIcon(widgetType, iconStyles));
        }
Example #5
0
 public static GameObject InstantiateWidget(WidgetTypes widgetType, GameObject gameObject)
 {
     if (widgetType == WidgetTypes.BossTotals)
     {
         return(GameObject.Instantiate(bossTotalsWidget, gameObject.transform.position, Quaternion.identity, gameObject.transform.parent));
     }
     else if (widgetType == WidgetTypes.LogTotals)
     {
         return(GameObject.Instantiate(logTotalsWidget, gameObject.transform.position, Quaternion.identity, gameObject.transform.parent));
     }
     else
     {
         return(null);
     }
 }
Example #6
0
        private string WidgetTypeToValue(WidgetTypes widgetType)
        {
            switch (widgetType)
            {
            case WidgetTypes.AppWidget:
            case WidgetTypes.Widget:
                return("_widget");

            case WidgetTypes.Item:
                return(null);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Example #7
0
        public Drawable GetConditionIcon(WidgetTypes widgetType, IconStyles?iconStyles, IWeatherDataPoint dataPoint,
                                         bool useTwilight, bool isCurrently)
        {
            var cachekey = GetConditionIconId(widgetType, iconStyles, dataPoint, useTwilight, isCurrently);

            if (!_drawableCache.ContainsKey(cachekey))
            {
                if (_appCompatDrawableUtil == null)
                {
                    _appCompatDrawableUtil = new AppCompatDrawableUtil();
                }

                _drawableCache[cachekey] = _appCompatDrawableUtil.GetDrawable(_appContext.Resources, cachekey,
                                                                              _appContext.Theme);
            }

            return(_drawableCache[cachekey]);
        }
Example #8
0
        private string GetIconStylesPrefix(WidgetTypes widgetType, IconStyles?iconStyles)
        {
            if (widgetType == WidgetTypes.Widget || widgetType == WidgetTypes.Item || !iconStyles.HasValue)
            {
                return("yandex");
            }

            switch (iconStyles)
            {
            case IconStyles.FancyWidgets:
                return("fancy");

            case IconStyles.YandexColor:
            case IconStyles.YandexMono:
                return("yandex");

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Example #9
0
        private int GetUnderfoundIcon(WidgetTypes widgetType, IconStyles?iconStyles)
        {
            const int yandexWidgetUndefinedIcon = Resource.Drawable.yandex_widget_ovc_white;

            switch (widgetType)
            {
            case WidgetTypes.AppWidget:
                switch (iconStyles)
                {
                case IconStyles.FancyWidgets:
                    return(Resource.Drawable.fancy_widget_ovc_white);

                case IconStyles.YandexColor:
                    return(yandexWidgetUndefinedIcon);

                case IconStyles.YandexMono:
                    return(Resource.Drawable.yandex_widget_ovc_mono_white);

                default:
                    if (iconStyles.HasValue)
                    {
                        throw new ArgumentOutOfRangeException();
                    }
                    throw new ArgumentNullException(nameof(iconStyles));
                }

            case WidgetTypes.Widget:
                return(yandexWidgetUndefinedIcon);

            case WidgetTypes.Item:
                return(Resource.Drawable.yandex_ovc_white);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Example #10
0
        public SortedDictionary <string, string> GenerateCode()
        {
            var codeByType = new Dictionary <Type, string>();
            var sb         = new StringBuilder();
            var cw         = new Serenity.Reflection.CodeWriter(sb, 4);

            foreach (var assembly in Assemblies)
            {
                foreach (var type in assembly.GetTypes())
                {
                    var formScriptAttribute = (FormScriptAttribute)type.GetCustomAttribute(typeof(FormScriptAttribute));
                    if (formScriptAttribute == null)
                    {
                        continue;
                    }

                    var ns = DoGetNamespace(type);

                    sb.Clear();
                    cw.Indented("public partial class ");
                    sb.Append(DoGetTypeName(type));
                    sb.AppendLine(" : PrefixedContext");
                    cw.InBrace(delegate
                    {
                        cw.Indented("[InlineConstant] public const string FormKey = \"");
                        sb.Append(formScriptAttribute.Key);
                        sb.AppendLine("\";");
                        sb.AppendLine();

                        cw.Indented("public ");
                        sb.Append(DoGetTypeName(type));
                        sb.AppendLine("(string idPrefix) : base(idPrefix) {}");
                        sb.AppendLine();

                        foreach (var item in Serenity.PropertyGrid.PropertyItemHelper.GetPropertyItemsFor(type))
                        {
                            var editorType        = item.EditorType ?? "String";
                            string widgetTypeName = null;
                            foreach (var rootNamespace in RootNamespaces)
                            {
                                string wn = rootNamespace + "." + editorType;
                                if (WidgetTypes.Contains(wn))
                                {
                                    widgetTypeName = wn;
                                    break;
                                }

                                wn += "Editor";
                                if (WidgetTypes.Contains(wn))
                                {
                                    widgetTypeName = wn;
                                    break;
                                }
                            }

                            if (widgetTypeName == null)
                            {
                                var wn = editorType;
                                if (!WidgetTypes.Contains(editorType))
                                {
                                    wn = editorType + "Editor";
                                }

                                if (WidgetTypes.Contains(wn))
                                {
                                    widgetTypeName = wn;
                                }
                            }

                            if (widgetTypeName == null)
                            {
                                continue;
                            }

                            var fullName = widgetTypeName;

                            if (widgetTypeName.StartsWith(ns + "."))
                            {
                                widgetTypeName = widgetTypeName.Substring(ns.Length + 1);
                            }
                            else
                            {
                                foreach (var rn in RootNamespaces)
                                {
                                    if (widgetTypeName.StartsWith(rn + "."))
                                    {
                                        widgetTypeName = widgetTypeName.Substring(rn.Length + 1);
                                    }
                                }
                            }

                            cw.Indented("public ");
                            sb.Append(widgetTypeName);
                            sb.Append(" ");
                            sb.Append(item.Name);
                            sb.Append(" { ");
                            sb.Append("[InlineCode(\"{this}.w('");
                            sb.Append(item.Name);
                            sb.Append("', ");
                            sb.Append(fullName);
                            sb.AppendLine(")\")] get; private set; }");
                        }
                    });

                    codeByType[type] = sb.ToString();
                    sb.Clear();
                }
            }

            var ordered     = codeByType.Keys.OrderBy(x => DoGetNamespace(x)).ThenBy(x => x.Name);
            var byNameSpace = ordered.ToLookup(x => DoGetNamespace(x));

            var result = new SortedDictionary <string, string>();

            foreach (var ns in byNameSpace.ToArray().OrderBy(x => x.Key))
            {
                foreach (var type in ns)
                {
                    sb.Clear();
                    sb.AppendLine();
                    cw.Indented("namespace ");
                    sb.AppendLine(ns.Key);
                    cw.InBrace(delegate
                    {
                        foreach (var usingNamespace in UsingNamespaces.ToArray().OrderBy(x => x))
                        {
                            cw.Indented("using ");
                            sb.Append(usingNamespace);
                            sb.AppendLine(";");
                        }

                        sb.AppendLine();

                        int i = 0;

                        {
                            if (i++ > 0)
                            {
                                sb.AppendLine();
                            }

                            cw.IndentedMultiLine(codeByType[type].TrimEnd());
                        }
                    });

                    var filename = ns.Key + "." + DoGetTypeName(type) + ".cs";

                    foreach (var rn in RootNamespaces)
                    {
                        if (filename.StartsWith(rn + "."))
                        {
                            filename = filename.Substring(rn.Length + 1);
                        }
                    }

                    result.Add(filename, sb.ToString());
                }
            }

            return(result);
        }
Example #11
0
        /// <summary>
        /// Change items.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Type_SelectionChanged(object sender, EventArgs e)
        {
            if (ActiveComponent != null)
            {
                ComponentContent.Remove(ActiveComponent);
            }

            WidgetTypes type = (WidgetTypes)Type.SelectedItem;

            switch (type)
            {
            case WidgetTypes.SEQUENCE:
                if (SequenceComponent == null)
                {
                    SequenceComponent = new SequenceVariable();
                }
                ActiveComponent = SequenceComponent;
                SequenceComponent.ClearData();
                ComponentContent.PackStart(SequenceComponent, true, true);
                break;

            case WidgetTypes.VARIABLE:
                if (VariableComponent == null)
                {
                    VariableComponent = new VariableVariable();
                }
                ActiveComponent = VariableComponent;
                VariableComponent.ClearData();
                ComponentContent.PackStart(VariableComponent, true, true);
                break;

            case WidgetTypes.RAND_INT:
                if (NumberComponent == null)
                {
                    NumberComponent = new NumberVariable();
                }
                ActiveComponent = NumberComponent;
                NumberComponent.ClearData();
                ComponentContent.PackStart(NumberComponent, true, true);
                break;

            case WidgetTypes.RAND_STRING:
                if (StringComponent == null)
                {
                    StringComponent = new StringVariable();
                }
                ActiveComponent = StringComponent;
                StringComponent.ClearData();
                ComponentContent.PackStart(StringComponent, true, true);
                break;

            case WidgetTypes.RAND_FLOAT:
                if (FloatComponent == null)
                {
                    FloatComponent = new FloatVariable();
                }
                ActiveComponent = FloatComponent;
                FloatComponent.ClearData();
                ComponentContent.PackStart(FloatComponent, true, true);
                break;


            default:
                if (TextVariableComponent == null)
                {
                    TextVariableComponent = new TextVariable();
                }
                ActiveComponent = TextVariableComponent;
                TextVariableComponent.ClearData();
                ComponentContent.PackStart(TextVariableComponent, true, true);
                break;
            }
        }
 /// <summary>
 /// this will ask the WidgetManager to show Widget X
 /// </summary>
 /// <param name="widget">widget to show</param>
 public void ShowWidget(WidgetTypes widget)
 {
     WidgetManager.Instance.ShowWidget(widget);
 }
Example #13
0
 public static Type GetTypeByName(string typeName)
 {
     return(WidgetTypes.FirstOrDefault(x => x.FullName == typeName));
 }
Example #14
0
        public string GenerateCode()
        {
            var codeByType = new Dictionary <Type, string>();
            var sb         = new StringBuilder();
            var cw         = new Serenity.Reflection.CodeWriter(sb, 4);

            foreach (var type in this.Assembly.GetTypes())
            {
                if (type.GetCustomAttribute(typeof(Serenity.FormScriptAttribute)) == null)
                {
                    continue;
                }

                var ns = DoGetNamespace(type);

                sb.Clear();
                cw.Indented("public partial class ");
                sb.Append(DoGetTypeName(type));
                sb.AppendLine(" : PrefixedContext");
                cw.InBrace(delegate
                {
                    cw.Indented("public ");
                    sb.Append(DoGetTypeName(type));
                    sb.AppendLine("(string idPrefix) : base(idPrefix) {}");
                    sb.AppendLine();

                    foreach (var item in Serenity.Web.PropertyEditor.PropertyEditorHelper.GetPropertyItemsFor(type))
                    {
                        var editorType        = item.EditorType;
                        string widgetTypeName = null;
                        foreach (var rootNamespace in RootNamespaces)
                        {
                            string wn = rootNamespace + "." + editorType;
                            if (WidgetTypes.Contains(wn))
                            {
                                widgetTypeName = wn;
                                UsingNamespaces.Add(rootNamespace);
                                break;
                            }

                            wn += "Editor";
                            if (WidgetTypes.Contains(wn))
                            {
                                widgetTypeName = wn;
                                UsingNamespaces.Add(rootNamespace);
                                break;
                            }
                        }

                        if (widgetTypeName == null)
                        {
                            continue;
                        }

                        if (widgetTypeName.StartsWith(ns + "."))
                        {
                            widgetTypeName = widgetTypeName.Substring(ns.Length + 1);
                        }
                        else
                        {
                            foreach (var rn in RootNamespaces)
                            {
                                if (widgetTypeName.StartsWith(rn + "."))
                                {
                                    widgetTypeName = widgetTypeName.Substring(rn.Length + 1);
                                }
                            }
                        }

                        cw.Indented("public ");
                        sb.Append(widgetTypeName);
                        sb.Append(" ");
                        sb.Append(item.Name);
                        sb.Append(" { get { return ById<");
                        sb.Append(widgetTypeName);
                        sb.Append(">(\"");
                        sb.Append(item.Name);
                        sb.AppendLine("\"); } }");
                    }
                });

                codeByType[type] = sb.ToString();
                sb.Clear();
            }

            sb.Clear();
            sb.AppendLine();

            foreach (var ns in UsingNamespaces)
            {
                cw.Indented("using ");
                sb.Append(ns);
                sb.AppendLine(";");
            }

            var ordered     = codeByType.Keys.OrderBy(x => DoGetNamespace(x)).ThenBy(x => x.Name);
            var byNameSpace = ordered.ToLookup(x => DoGetNamespace(x));

            foreach (var ns in byNameSpace.ToArray().OrderBy(x => x.Key))
            {
                sb.AppendLine();
                cw.Indented("namespace ");
                sb.AppendLine(ns.Key);
                cw.InBrace(delegate
                {
                    int i = 0;
                    foreach (var type in ns)
                    {
                        if (i++ > 0)
                        {
                            sb.AppendLine();
                        }

                        cw.IndentedMultiLine(codeByType[type].TrimEnd());
                    }
                });
            }

            return(sb.ToString());
        }