Ejemplo n.º 1
0
        /// <summary>
        ///   Initialises the game state and loads any resources that are needed.
        /// </summary>
        /// <returns>
        ///   True if the game state was initialised and all resources were loaded successfully,
        ///   otherwise false.
        /// </returns>
        public override bool LoadContent()
        {
            if (Program.Theme.BackgroundTexture == null)
            {
                return(Logger.LogReturn("Failed loading theme background texture.", false, LogType.Error));
            }
            if (Program.Theme.PointerTexture == null)
            {
                return(Logger.LogReturn("Failed loading theme pointer texture.", false, LogType.Error));
            }
            if (Program.Theme.DefaultIcon == null)
            {
                return(Logger.LogReturn("Failed loading theme default icon texture.", false, LogType.Error));
            }
            if (Program.Theme.Font == null)
            {
                return(Logger.LogReturn("Failed loading theme font.", false, LogType.Error));
            }

            Vector2u winsize = Manager.Game.Window.Size;

            m_bgview = new View(new Vector2f(winsize.X / 2.0f, winsize.Y / 2.0f),
                                new Vector2f(winsize.X, winsize.Y));
            m_icoview = new View(new Vector2f(winsize.X / 2.0f, winsize.Y + (winsize.Y / 2.0f)),
                                 new Vector2f(winsize.X, winsize.Y));
            m_icoviewy = m_icoview.Center.Y;

            Manager.Game.Window.SetView(m_bgview);

            m_back = new MiEntity("Background", Manager.Game.Window);

            if (!m_back.AddChild(CreateBackground()))
            {
                return(Logger.LogReturn("Failed creating background.", false, LogType.Error));
            }
            if (!m_back.AddChild(CreatePointer()))
            {
                return(Logger.LogReturn("Failed creating pointer.", false, LogType.Error));
            }

            m_icons = new MiEntity("Icons", Manager.Game.Window);

            string[] files = Program.GetFiles();

            for (uint i = 0; i < files.Length; i++)
            {
                MiEntity ent = CreateIcon(files[i], i);

                if (ent == null)
                {
                    return(Logger.LogReturn("Failed creating file icon entity for file \"" + files[i] + "\".", false, LogType.Error));
                }

                m_icons.AddChild(ent);
            }

            Manager.Game.Window.MouseWheelScrolled += MouseWheelScrolled;
            return(true);
        }
Ejemplo n.º 2
0
        private MiEntity CreateIcon(string file, uint index)
        {
            Theme    theme    = Program.Theme;
            Settings settings = Program.FolderSettings;
            Vector2u cellbord = Program.GetIconBorder();
            Vector2u cellsize;
            {
                uint csize = Program.GetCellSize();

                cellsize.X = csize;
                cellsize.Y = settings.DisplayType == IconDisplayType.IconOnly ?
                             csize : (uint)((float)(csize / 3.0f) * 4);
            }

            MiEntity icongroup = new MiEntity("IconGroup" + index.ToString(), Manager.Game.Window),
                     icon      = new MiEntity("Icon", Manager.Game.Window),
                     label     = new MiEntity("Label", Manager.Game.Window);

            label.Visible = settings.DisplayType == IconDisplayType.Default;

            if (!icongroup.AddChild(icon) || !icongroup.AddChild(label))
            {
                return(Logger.LogReturn <MiEntity>("Failed assembling icon group.", null, LogType.Error));
            }

            string filename = Path.GetFileName(file);

            if (!icongroup.AddNewComponent <Transform>())
            {
                return(Logger.LogReturn <MiEntity>("Failed creating icon group components.", null, LogType.Error));
            }

            Transform igtran = icongroup.GetComponent <Transform>();

            igtran.Size = new Vector2f(cellsize.X, cellsize.Y);

            switch (Program.PointerDirection)
            {
            case Direction.Left:
                igtran.Position = new Vector2f(theme.PointerSize.X + (cellsize.X / 2.0f), cellsize.Y / 2.0f);
                break;

            case Direction.Right:
                igtran.Position = new Vector2f(cellsize.X / 2.0f, cellsize.Y / 2.0f);
                break;
            }

            igtran.SetOrigin(Allignment.Middle);

            uint x = index % settings.GridCells.X,
                 y = index / settings.GridCells.X;

            igtran.Position += new Vector2f((x * cellsize.X) + (cellsize.X / 2),
                                            (y * cellsize.Y) + (cellsize.Y / 2)) +
                               new Vector2f(0, Manager.Game.Window.Size.Y);

            if (!icon.AddNewComponent <Sprite>() || !icon.AddNewComponent <Clickable>())
            {
                return(Logger.LogReturn <MiEntity>("Failed creating icon components.", null, LogType.Error));
            }

            Clickable click = icon.GetComponent <Clickable>();

            void OnClick(object sender, EventArgs e)
            {
                try
                {
                    RenderWindow window = Manager.Game.Window;
                    Vector2i     pos    = Mouse.GetPosition(window);

                    if (pos.X < 0 || pos.X > window.Size.X ||
                        pos.Y < 0 || pos.Y > window.Size.Y)
                    {
                        return;
                    }

                    if (file != null && File.Exists(file))
                    {
                        Process proc = Process.Start(file);
                        Manager.Game.Window.SetVisible(false);
                        proc.WaitForExit();
                        Manager.Game.Exit();
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log("Unable to open file \"" + file + "\": " + ex.Message, LogType.Error);
                }
            }

            click.Click += OnClick;

            Transform itran = icon.GetComponent <Transform>();

            itran.Size     = new Vector2f(settings.IconSize, settings.IconSize);
            itran.Origin   = Allignment.Middle;
            itran.Position = igtran.Position;

            if (settings.DisplayType == IconDisplayType.Default)
            {
                itran.Position -= new Vector2f(0, igtran.Size.Y / 8.0f);
            }

            Texture tex = IconManager.Manager.Get(Path.Combine(FolderPaths.Executable, file));

            if (tex != null)
            {
                icon.GetComponent <Sprite>().Image.OverrideTexture = IconManager.Manager.Get(Path.Combine(FolderPaths.Executable, file));
            }
            else
            {
                icon.GetComponent <Sprite>().Image.Path = theme.DefaultIconPath;
            }

            string displaystring = settings.ShowFileExtention ? filename : Path.GetFileNameWithoutExtension(file);

            if (!label.AddComponent(new Label(theme.TextStyle, displaystring, Allignment.Middle)))
            {
                return(Logger.LogReturn <MiEntity>("Failed creating label components.", null, LogType.Error));
            }

            Label lab = label.GetComponent <Label>();

            lab.Refresh();

            while (lab.String.Length > 0 && lab.GetTextBounds().Width >= igtran.ScaledSize.X - 4)
            {
                lab.String = lab.String.Substring(0, lab.String.Length - 1);
                lab.Refresh();
            }

            Transform ltran = label.GetComponent <Transform>();

            ltran.Size     = new Vector2f(settings.IconSize, 24);
            ltran.Origin   = Allignment.Middle;
            ltran.Position = igtran.Position + new Vector2f(0.0f, igtran.Size.Y / 4.0f);

            return(icongroup);
        }