コード例 #1
0
ファイル: DomainModel.cs プロジェクト: jamClark/Stellarmap
        private void GenerateDomainXMLFile(VirtualDomain vd)
        {
            StringBuilder str = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");

            str.Append("\n<domain name=\"" + this.DomainName + "\" >\n");
            str.Append("\t<lpc name=\"include.h\" type=\"header\" />\n");


            //save list of room files
            str.Append("\t<directory name=\"room\">\n");
            foreach (RoomModel room in this.Rooms)
            {
                str.Append("\t\t<lpc name=\"" + room.RawFileName + "\" type=\"roomfile\" x=\"" + vd.GetIconPosition(room.FileName).X + "\" y=\"" + vd.GetIconPosition(room.FileName).Y + "\" icon=\"" + vd.GetIconDesc(room.FileName) + "\"/>\n");
            }
            str.Append("\t</directory>\n");

            //doors
            str.Append("\t<directory name=\"doors\">\n");
            foreach (FileReferenceModel door in DomainFileReferences[THIS_DOMAIN].Doors.Values)
            {
                str.Append("\t\t<lpc name=\"" + door.RawName + "\" type=\"inventory\" class=\"" + door.Type.ToString().ToLower() + "\" />\n");
            }
            str.Append("\t</directory>\n");

            //save list of other assorted inventory files (npc/items/etc)
            str.Append("\t<directory name=\"inventory\">\n");
            foreach (FileReferenceModel item in DomainFileReferences[THIS_DOMAIN].Inventory.Values)
            {
                str.Append("\t\t<lpc name=\"" + item.RawName + "\" type=\"inventory\" class=\"" + item.Type.ToString().ToLower() + "\" />\n");
            }
            str.Append("\t</directory>\n");

            //referenced domains
            str.Append("\t<directory name=\"references\">\n");
            foreach (DomainReference domRef in DomainFileReferences)
            {
                if (domRef.Name != this.Name && domRef.Name != "domain")
                {
                    str.Append("\t\t<ref name=\"" + domRef.Name + "\" />\n");
                }
            }
            str.Append("\t</directory>\n");

            str.Append("</domain>\n");
            System.IO.Directory.SetCurrentDirectory(this.RootDirectory);
            using (System.IO.StreamWriter stream = new StreamWriter(this.DomainName + ".xml"))
            {
                stream.Write(str);
                stream.Flush();
            }
        }
コード例 #2
0
ファイル: DomainModel.cs プロジェクト: jamClark/Stellarmap
        private bool Serialize(VirtualDomain vd)
        {
            //generates directory structure, domain include header, and domain master xml file
            Stellarmap.DeadSouls.Globals.DomainDirectories.ValidateDirectoriesExist(this.RootDirectory);
            Include.CreateFile(this.RootDirectory);

            string roomPath = this.RootDirectory + "\\" + Include.StripDeadSoulsPath(DeadSouls.Globals.DomainDirectories.Room);

            DeadSouls.Globals.DomainFiles.GenerateFiles(this.RootDirectory);
            GenerateDomainXMLFile(vd);

            //generate lpc room files
            foreach (RoomModel room in this.Rooms)
            {
                room.SaveModelToDisk(roomPath);
            }
            return(true);
        }
コード例 #3
0
        public GUIMouseStateMachine(VirtualDomain domainView, IViewPort viewPort, Control parent)
        {
            System.Diagnostics.Debug.Assert(domainView != null);
            refVirtualDomain = domainView;
            refViewPort      = viewPort;
            refParent        = parent;

            //Note: there are no actions defined for the ContextMenu state. It must be handled externaly
            //by the controlling form. That form must attach event handlers to the appropriate
            //context menu events and then call ContextMenuClose to return to the appropriate state
            //when the menu is closed.

            /*
             * Static States
             */
            ActionTriggers.Add(new EventCombo(MouseEvents.MoveMouse, MouseStates.Normal), MouseActions.NormalOrHover);           //also node hover
            ActionTriggers.Add(new EventCombo(MouseEvents.MouseWheel, MouseStates.Normal), MouseActions.WheelViewVertically);
            ActionTriggers.Add(new EventCombo(MouseEvents.LeftClick, MouseStates.Normal), MouseActions.DragRect);
            ActionTriggers.Add(new EventCombo(MouseEvents.RightClick, MouseStates.Normal), MouseActions.Context);
            ActionTriggers.Add(new EventCombo(MouseEvents.CtrlDown, MouseStates.Normal), MouseActions.EnterAltMode);
            ActionTriggers.Add(new EventCombo(MouseEvents.ShiftDown, MouseStates.Normal), MouseActions.EnterShiftedMode);
            ActionTriggers.Add(new EventCombo(MouseEvents.MiddleClick, MouseStates.Normal), MouseActions.EnterDraggingView);

            ActionTriggers.Add(new EventCombo(MouseEvents.MoveMouse, MouseStates.Hover), MouseActions.NormalOrHover);
            ActionTriggers.Add(new EventCombo(MouseEvents.MouseWheel, MouseStates.Hover), MouseActions.WheelViewVertically);
            ActionTriggers.Add(new EventCombo(MouseEvents.LeftClick, MouseStates.Hover), MouseActions.Activate);
            ActionTriggers.Add(new EventCombo(MouseEvents.RightClick, MouseStates.Hover), MouseActions.Context);
            ActionTriggers.Add(new EventCombo(MouseEvents.CtrlDown, MouseStates.Hover), MouseActions.EnterAltHover);
            ActionTriggers.Add(new EventCombo(MouseEvents.CtrlDown, MouseStates.Hover), MouseActions.EnterAltMode);
            ActionTriggers.Add(new EventCombo(MouseEvents.ShiftDown, MouseStates.Hover), MouseActions.EnterShiftedMode);
            ActionTriggers.Add(new EventCombo(MouseEvents.MiddleClick, MouseStates.Hover), MouseActions.EnterDraggingView);


            ActionTriggers.Add(new EventCombo(MouseEvents.MoveMouse, MouseStates.NodeHover), MouseActions.NormalOrHover);     //@
            ActionTriggers.Add(new EventCombo(MouseEvents.LeftClick, MouseStates.NodeHover), MouseActions.DragLine);          //@
            ActionTriggers.Add(new EventCombo(MouseEvents.ShiftDown, MouseStates.NodeHover), MouseActions.EnterShiftedMode);
            ActionTriggers.Add(new EventCombo(MouseEvents.MiddleClick, MouseStates.NodeHover), MouseActions.EnterDraggingView);
            ActionTriggers.Add(new EventCombo(MouseEvents.MouseWheel, MouseStates.NodeHover), MouseActions.WheelViewVertically);


            ActionTriggers.Add(new EventCombo(MouseEvents.LeftClick, MouseStates.GroupMode), MouseActions.GrabGroup);
            ActionTriggers.Add(new EventCombo(MouseEvents.RightClick, MouseStates.GroupMode), MouseActions.DeselctAndContext);
            ActionTriggers.Add(new EventCombo(MouseEvents.MiddleClick, MouseStates.GroupMode), MouseActions.EnterDraggingViewGroup);
            //ActionTriggers.Add(new EventCombo(MouseEvents.CtrlDown,MouseStates.GroupMode),MouseActions.EnterAltGroupMode);


            /*
             * Dynamic States
             */
            ActionTriggers.Add(new EventCombo(MouseEvents.MoveMouse, MouseStates.DraggingImage), MouseActions.MoveImage);           //this could enter AutoDraging state as well
            ActionTriggers.Add(new EventCombo(MouseEvents.LeftRelease, MouseStates.DraggingImage), MouseActions.EnterHover);

            //ActionTriggers.Add(new EventCombo(MouseEvents.MoveMouse,MouseStates.AutoDragging),MouseActions.AutoDrag); //this could enter DraggingImage state as well
            //ActionTriggers.Add(new EventCombo(MouseEvents.LeftHold,MouseStates.AutoDragging),MouseActions.AutoDrag);
            //ActionTriggers.Add(new EventCombo(MouseEvents.LeftRelease,MouseStates.AutoDragging),MouseActions.EnterHover);

            //selection Rect
            ActionTriggers.Add(new EventCombo(MouseEvents.MoveMouse, MouseStates.DraggingSelectionRect), MouseActions.DragRect);
            ActionTriggers.Add(new EventCombo(MouseEvents.LeftRelease, MouseStates.DraggingSelectionRect), MouseActions.SelectGroup);
            ActionTriggers.Add(new EventCombo(MouseEvents.RightClick, MouseStates.DraggingSelectionRect), MouseActions.SelectGroup);

            //connection line
            ActionTriggers.Add(new EventCombo(MouseEvents.MoveMouse, MouseStates.DraggingLine), MouseActions.DragLine);          //@
            ActionTriggers.Add(new EventCombo(MouseEvents.LeftRelease, MouseStates.DraggingLine), MouseActions.EndDragLine);     //@


            ActionTriggers.Add(new EventCombo(MouseEvents.MoveMouse, MouseStates.DraggingGroup), MouseActions.MoveGroup);
            ActionTriggers.Add(new EventCombo(MouseEvents.LeftRelease, MouseStates.DraggingGroup), MouseActions.EnterGroupMode);


            /*
             * Alternate Triggers
             */
            ActionTriggers.Add(new EventCombo(MouseEvents.MoveMouse, MouseStates.AltMode), MouseActions.AltModeOrAltHover);
            ActionTriggers.Add(new EventCombo(MouseEvents.CtrlUp, MouseStates.AltMode), MouseActions.EnterNormal);
            ActionTriggers.Add(new EventCombo(MouseEvents.LeftClick, MouseStates.AltMode), MouseActions.EnterDraggingView);

            ActionTriggers.Add(new EventCombo(MouseEvents.MoveMouse, MouseStates.DraggingView), MouseActions.MoveView);
            ActionTriggers.Add(new EventCombo(MouseEvents.LeftRelease, MouseStates.DraggingView), MouseActions.EnterAltMode);
            ActionTriggers.Add(new EventCombo(MouseEvents.CtrlUp, MouseStates.DraggingView), MouseActions.EnterNormal);
            ActionTriggers.Add(new EventCombo(MouseEvents.MiddleRelease, MouseStates.DraggingView), MouseActions.EnterPreviousMode);

            ActionTriggers.Add(new EventCombo(MouseEvents.MiddleRelease, MouseStates.DraggingViewGroup), MouseActions.EnterGroupMode);
            ActionTriggers.Add(new EventCombo(MouseEvents.MoveMouse, MouseStates.DraggingViewGroup), MouseActions.MoveView);

            //ActionTriggers.Add(new EventCombo(MouseEvents.MoveMouse,MouseStates.AltHover),MouseActions.AltModeOrAltHover);
            //ActionTriggers.Add(new EventCombo(MouseEvents.CtrlUp,MouseStates.AltHover),MouseActions.EnterHover);
            //ActionTriggers.Add(new EventCombo(MouseEvents.LeftClick,MouseStates.AltHover),MouseActions.AddToImageGroup);

            //ActionTriggers.Add(new EventCombo(MouseEvents.LeftClick,MouseStates.AltGroupMode),MouseActions.DraggingViewOrGroup);
            //ActionTriggers.Add(new EventCombo(MouseEvents.MoveMouse,MouseStates.AltGroupMode),MouseActions.AltModeOrAltHover);
            //ActionTriggers.Add(new EventCombo(MouseEvents.CtrlUp,MouseStates.AltGroupMode),MouseActions.EnterGroupMode);
            //ActionTriggers.Add(new EventCombo(MouseEvents.MoveMouse,MouseStates.AltGroupMode),MouseActions.AltModeOrAltHover);

            /*
             * Shifted Triggers
             */
            ActionTriggers.Add(new EventCombo(MouseEvents.MouseWheel, MouseStates.ShiftMode), MouseActions.WheelViewHorizontally);
            ActionTriggers.Add(new EventCombo(MouseEvents.ShiftUp, MouseStates.ShiftMode), MouseActions.EnterNormal);
        }
コード例 #4
0
ファイル: DomainModel.cs プロジェクト: jamClark/Stellarmap
        private bool Deserialize(VirtualDomain vd)
        {
            //the workspace was already reset so the root directory should be good to go
            //find the master XML file and begin disecting the directory layout and file locations
            string masterFile = this.RootDirectory + "\\" + this.Name + ".xml";

            if (!System.IO.File.Exists(masterFile))
            {
                throw new DomainModelException("No domain master file found. Cannot load domain.");
            }

            Sluggy.Utility.XmlParser xml;
            try{
                bool validFile = false;
                xml = new Sluggy.Utility.XmlParser(masterFile);
                if (xml.Contents.Children[0].Name == "domain")
                {
                    validFile = true;
                    Sluggy.Utility.Tag domainTag = xml.Contents.Children[0];
                    foreach (Sluggy.Utility.Tag tag in domainTag.Children)
                    {
                        //HACK ALERT - might as well just hardcode a giant ugly-ass switch while I'm at it
                        //look for the 'room' directory tag
                        #region room tag parsing
                        if (tag.Name == "directory" && tag.Attributes["name"] == "room")
                        {
                            //we now have the room directory, start loading room files
                            foreach (Sluggy.Utility.Tag roomTag in tag.Children)
                            {
                                string roomName, iconName;
                                int    xPos, yPos;

                                if (roomTag.Attributes.ContainsKey("name"))
                                {
                                    roomName = roomTag.Attributes["name"];
                                }
                                else
                                {
                                    throw new DomainModelException("Missing room name in domain master file. Canceling domain laoding. Please manually edit the master xml file to reflect all room files.");
                                }
                                if (roomTag.Attributes.ContainsKey("x"))
                                {
                                    xPos = System.Convert.ToInt32(roomTag.Attributes["x"]);
                                }
                                else
                                {
                                    xPos = 0;
                                }
                                if (roomTag.Attributes.ContainsKey("y"))
                                {
                                    yPos = System.Convert.ToInt32(roomTag.Attributes["y"]);
                                }
                                else
                                {
                                    yPos = 0;
                                }
                                if (roomTag.Attributes.ContainsKey("icon"))
                                {
                                    iconName = roomTag.Attributes["icon"];
                                }
                                else
                                {
                                    iconName = Globals.ImageBoxProperties.DefaultIconDesc;
                                }


                                //failure to load a room does not necesitate failure to load the domain
                                try{ this.LoadRoom(roomName); }
                                catch (Sluggy.Utility.XMLParserException exception)
                                {
                                    //throw new DomainModelException("Invalid master XML file. Could not load domain.",exception);
                                    System.Windows.Forms.MessageBox.Show("Failure loading room file '" + roomName + "' due to parsing error.\n\n" + exception.Message);
                                }
                                catch (DomainModelException exception)
                                {
                                    System.Windows.Forms.MessageBox.Show(exception.Message);
                                }

                                vd.AddImage(new System.Drawing.Point(xPos, yPos),
                                            Globals.ImageBoxProperties.DefaultImage,
                                            this.DomainFileReferences[THIS_DOMAIN].ConvertRoomNameToFullPath(roomName),
                                            iconName);
                                //the room object still needs it's iocn bitmap to be set
                                //however, the bitmaps loaded from the config file are only
                                //available to the DomainViewForm so it will have to deal with this
                            }
                            //break;
                        }
                        #endregion

                        #region door tag parsing
                        if (tag.Name == "directory" && tag.Attributes["name"] == "doors")
                        {
                            foreach (Sluggy.Utility.Tag doorTag in tag.Children)
                            {
                                if (doorTag.Attributes.ContainsKey("name") && doorTag.Attributes.ContainsKey("class"))
                                {
                                    string name      = doorTag.Attributes["name"];
                                    string doorClass = doorTag.Attributes["class"];

                                    if (!DomainFileReferences[THIS_DOMAIN].Inventory.ContainsKey(name))
                                    {
                                        FileReferenceModel mod = new FileReferenceModel(name, Include.DetermineSaveType(doorClass), Include, this.Name);
                                        DomainFileReferences[THIS_DOMAIN].Doors.Add(name, mod);
                                    }
                                }
                            }
                        }
                        #endregion

                        #region item tag parsing
                        if (tag.Name == "directory" && tag.Attributes["name"] == "inventory")
                        {
                            foreach (Sluggy.Utility.Tag itemTag in tag.Children)
                            {
                                if (itemTag.Attributes.ContainsKey("name") && itemTag.Attributes.ContainsKey("class"))
                                {
                                    string name      = itemTag.Attributes["name"];
                                    string itemClass = itemTag.Attributes["class"];

                                    if (!DomainFileReferences[THIS_DOMAIN].Inventory.ContainsKey(name))
                                    {
                                        FileReferenceModel mod = new FileReferenceModel(name, Include.DetermineSaveType(itemClass), Include, this.Name);
                                        DomainFileReferences[THIS_DOMAIN].Inventory.Add(name, mod);
                                    }
                                }
                            }
                        }
                        #endregion

                        #region domain references
                        if (tag.Name == "directory" && tag.Attributes["name"] == "references")
                        {
                            foreach (Sluggy.Utility.Tag itemTag in tag.Children)
                            {
                                if (itemTag.Attributes.ContainsKey("name"))
                                {
                                    string name = itemTag.Attributes["name"];
                                    if (name != this.Name && name != "domain")
                                    {
                                        this.AddDomainReference(name);
                                    }
                                }
                            }
                        }
                        #endregion
                        //break;
                    }
                }
                if (!validFile)
                {
                    throw new DomainModelException("Invalid master XML file. Could not load domain.");
                }
            }
            catch (Sluggy.Utility.XMLParserException exception)
            {
                throw new DomainModelException("Failed to parse domain master XML file.\n\n" + exception.Message);
            }
            catch (System.IndexOutOfRangeException exception)
            {
                throw new DomainModelException("Corrupted master XML file. Could not load domain.", exception);
            }
            catch (System.ArgumentOutOfRangeException exception)
            {
                throw new DomainModelException("Corrupted master XML file. Could not load domain.", exception);
            }

            return(true);
        }
コード例 #5
0
ファイル: DomainModel.cs プロジェクト: jamClark/Stellarmap
 public bool LoadModelFromDisk(VirtualDomain vd)
 {
     return(this.Deserialize(vd));
 }
コード例 #6
0
ファイル: DomainModel.cs プロジェクト: jamClark/Stellarmap
 public bool SaveModelToDisk(VirtualDomain vd)
 {
     return(this.Serialize(vd));
 }
コード例 #7
0
 public void Initialize(VirtualDomain vDomain, PaintEventHandler renderEvent)
 {
     System.Diagnostics.Debug.Assert(vDomain != null && renderEvent != null);
     refVirtualDomain = vDomain;
     RenderEvent     += new PaintEventHandler(renderEvent);
 }
コード例 #8
0
 public DomainOptionsWindow(VirtualDomain vd, ref Dictionary <string, Bitmap> roomIcons) : this()
 {
     this.refDomainRenderer = vd;
     this.refRoomIcons      = roomIcons;
 }
コード例 #9
0
 public bool LoadModelFromDisk(VirtualDomain vd)
 {
     return(Model.LoadModelFromDisk(vd));
 }
コード例 #10
0
 public bool SaveModelToDisk(VirtualDomain vd)
 {
     return(Model.SaveModelToDisk(vd));
 }