コード例 #1
0
        public void SetText(string text)
        {
            // TODO: Allow text resizing w/layout etc.
            // just do a hack for now I guess
            if (loadingTitle != null)
                RemoveItem(loadingTitle);

            AddItem(LayoutManager.AlignItem(loadingTitle = new GUILabel(text, new Font("Verdana", 12, FontStyle.Bold), Color.Blue, new Point(0, -30), Size.Empty),
                                            LayoutRules.Positioning.Center, LayoutRules.Positioning.Center));
        }
コード例 #2
0
ファイル: LoadingLayer.cs プロジェクト: carlhuth/GenXSource
        public void SetText(string text)
        {
            // TODO: Allow text resizing w/layout etc.
            // just do a hack for now I guess
            if (loadingTitle != null)
            {
                RemoveItem(loadingTitle);
            }

            AddItem(LayoutManager.AlignItem(loadingTitle = new GUILabel(text, new Font("Verdana", 12, FontStyle.Bold), Color.Blue, new Point(0, -30), Size.Empty),
                                            LayoutRules.Positioning.Center, LayoutRules.Positioning.Center));
        }
コード例 #3
0
        public override IResource LoadContent(string filePath, string rzPath, string subPath,
                                              string contentType, XmlNodeList rzNode,
                                              out IResource[] loadedDependants,
                                              out IResource[] loadedDependancies, DeviceInterface devIf)
        {
            ILog log = devIf.CDI.GeneralLog;
            log.AddItem(new LogItem(string.Format("Starting loading layer rz ([{0}]{1})", contentType, rzPath), LogItem.ItemLevel.DebugInfo));

            XmlDocument xml = new XmlDocument();
            xml.Load(filePath);

            List<ISharableResource> sharedRzs = new List<ISharableResource>();

            // look for layer info
            XmlNode layerNode = xml.SelectSingleNode("/layer");
            Point position = ParsePoint(layerNode.Attributes["position"].InnerText);
            Size dimensions = ParseSize(layerNode.Attributes["size"].InnerText);
            string booClass = null, booFile = null;
            if (layerNode.Attributes["classFile"] != null)
                booFile = layerNode.Attributes["classFile"].InnerText;
            if (layerNode.Attributes["className"] != null)
                booClass = layerNode.Attributes["className"].InnerText;

            // parse boo script file
            BooScript script = null;
            StringBuilder scriptText;
            if (booFile != null && booClass != null)
            {
                string scriptRzPath = rzPath.Substring(0, rzPath.Length - Path.GetFileName(rzPath).Length) +  booFile;
                log.AddItem(new LogItem(string.Format("Found Layer Script ({0})", scriptRzPath), LogItem.ItemLevel.DebugInfo));
                script = (BooScript)devIf.GetSharedResource(scriptRzPath, ref sharedRzs);
                scriptText = new StringBuilder();
                scriptText.Append(script.Script);
            }
            else
            {
                log.AddItem(new LogItem("Generating Layer Script", LogItem.ItemLevel.DebugInfo));
                // build boo script for layer
                BooScriptBuilder.CreateClass(new string[] { "import Genetibase.VisUI.Scripting from \"NuGenVisUI\"" },
                                             "AutoGenLayer", "ScriptLayer", out scriptText);

                script = new BooScript(scriptText.ToString(), null);
                booClass = "AutoGenLayer";
            }
            
            // load resources
            Dictionary<string, IResource> refRzs = new Dictionary<string, IResource>();
            XmlElement resourcesNode = (XmlElement)layerNode.SelectSingleNode("resources");
            foreach (XmlNode node in resourcesNode.ChildNodes)
            {
                if (node.NodeType != XmlNodeType.Comment)
                {
                    string rzName = node.Attributes["name"].InnerText;
                    string rzUrl = node.Attributes["url"].InnerText;
                    IResource rz = devIf.GetSharedResource(rzUrl, ref sharedRzs);
                    refRzs[rzName] = rz;
                }
            }

            SimpleGUILayer layer = new SimpleGUILayer(devIf, position, dimensions, rzPath, null, sharedRzs.ToArray());

            // pre-load script for layer
            XmlNode itemsNode = layerNode.SelectSingleNode("items");
            /*foreach (XmlNode node in itemsNode.ChildNodes)
            {
                // parse common events
                if (node.Attributes["onclick"] != null)
                {
                    string booCode = node.Attributes["onclick"].InnerText;
                    // insert into script
                    BooScriptBuilder.InsertFunction("", node.Name + "_onclick", "obj as object, args as MouseEventArgs", booCode, ref scriptText);
                }
            }*/

            // compile new script
            log.AddItem(new LogItem(string.Format("Compiling Layer Script (Length: {0})", scriptText.Length), LogItem.ItemLevel.DebugInfo));
            script = new BooScript(scriptText.ToString(), null);
            if (script.Compile())
                log.AddItem(new LogItem("Compiled Layer Script", LogItem.ItemLevel.Success));
            else
                log.AddItem(new LogItem("Failed to Compile Layer Script", LogItem.ItemLevel.Failure));

            // create class instance
            Type layerClass = script.GeneratedAssembly.GetType(booClass);
            ScriptLayer sLayer = (ScriptLayer)script.GeneratedAssembly.CreateInstance(booClass);
            
            // load items
            Font font = new Font("Tahoma", 10);
            foreach (XmlNode node in itemsNode.ChildNodes)
            {
                // TODO: Parse layout instructions
                // TODO: Log building?
                // Parse common attributes
                GUIItemType_Config itemConf;
                Point pos = Point.Empty;
                Size size = Size.Empty;
                LayoutRules.Positioning xLayout = LayoutRules.Positioning.Near;
                LayoutRules.Positioning yLayout = LayoutRules.Positioning.Near;
                MouseEventHandler onclickHandler = null;

                // parse and map common events
                if (node.Attributes["onclick"] != null)
                {
                    string methodName = node.Name + "_onclick";
                    BooScriptEventsBridge evBridge = new BooScriptEventsBridge(sLayer, layerClass.GetMethod(methodName));
                    onclickHandler = evBridge.MouseHandler;
                }

                if (guiItemsConfig.TryGetValue(node.Name, out itemConf))
                {
                    if (itemConf.usePos && node.Attributes["position"] != null)
                        pos = ParsePoint(node.Attributes["position"].InnerText);
                    if (itemConf.useSize && node.Attributes["size"] != null)
                        size = ParseSize(node.Attributes["size"].InnerText);
                    if (itemConf.useLayout && node.Attributes["layout"] != null)
                        ParseLayout(node.Attributes["layout"].InnerText, out xLayout, out yLayout);
                }
                GUILayerItem item = null;
                if (node.Name == "label")
                {
                    string text = node.Attributes["text"].InnerText;
                    
                    item = new GUILabel(text, font, Color.Red, pos, Size.Empty);
                }
                else if (node.Name == "icon")
                {
                    string imgRz = node.Attributes["img"].InnerText;
                    TextureResource.Icon icon = (TextureResource.Icon)refRzs[imgRz];
                    bool highlight = (node.Attributes["highlight"].InnerText == bool.TrueString);
                    bool enabled = (node.Attributes["enabled"].InnerText == bool.TrueString);

                    item = new GUIIcon(pos, size, icon, highlight, enabled);
                }

                if (item != null)
                {
                    item = LayoutManager.AlignItem(item, xLayout, yLayout);
                    if (onclickHandler != null)
                        layer.AddItem(item, null, null, onclickHandler);
                    else
                        layer.AddItem(item);
                }
            }

            log.AddItem(new LogItem(string.Format("Loaded layer rz ([{0}]{1})", contentType, rzPath), LogItem.ItemLevel.DebugInfo));

            loadedDependancies = null;
            loadedDependants = null;
            
            return layer;
        }