Exemplo n.º 1
0
        public void Initialize()
        {
            UpdateSelectedNodeInfo(null);
            graphViewer.Graph = null;
            new GameMasterDataManager();
            GameMasterDataManager.GetInstance().Load();
            addNewGameMasterNode.DropDownItems.Clear();
            foreach (EncounterScriptFile scriptFile in GameMasterDataManager.GetInstance().GetGenericScriptNodes())
            {
                if (scriptFile.DefaultJson.Length > 0 || scriptFile.Schema != null)
                {
                    var item = addNewGameMasterNode.DropDownItems.Add(scriptFile.Name);
                    if (scriptFile.Schema != null)
                    {
                        if (!string.IsNullOrEmpty(scriptFile.Schema.Title) && !string.IsNullOrEmpty(scriptFile.Schema.Description))
                        {
                            item.ToolTipText = scriptFile.Schema.Title + "\n\n" + scriptFile.Schema.Description;
                        }
                        else if (!string.IsNullOrEmpty(scriptFile.Schema.Title))
                        {
                            item.ToolTipText = scriptFile.Schema.Title;
                        }
                        else if (!string.IsNullOrEmpty(scriptFile.Schema.Description))
                        {
                            item.ToolTipText = scriptFile.Schema.Description;
                        }
                    }
                }
            }

            encounterTreeView.Nodes.Clear();
            GameMasterDataManager.GetInstance().FillEncounterNodeTree(encounterTreeView);
        }
Exemplo n.º 2
0
 private void attachEdgeMenuItem_Click(object sender, EventArgs e)
 {
     mSelectedNode.NodeData.NodeFile.Json["in_edge"] = attachEdgeMenuItem.Tag as string;
     mSelectedNode.IsModified = true;
     GameMasterDataManager.GetInstance().SaveModifiedFiles();
     GameMasterDataManager.GetInstance().RefreshGraph(this);
 }
Exemplo n.º 3
0
        private void encounterGraphContextMenu_Opening(object sender, CancelEventArgs e)
        {
            UpdateHoveredObjects(graphViewer.ObjectUnderMouseCursor);

            GameMasterNode hoveredNode = GameMasterDataManager.GetInstance().GetGameMasterNode(mHoveredDNode?.DrawingNode.Id);

            deleteNodeToolStripMenuItem.Enabled = mHoveredDNode != null;

            copyGameMasterNode.Enabled = mHoveredDNode != null;
            copyGameMasterNode.Text    = "Clone " + (mHoveredDNode != null ? hoveredNode.Name : "Node");

            moveToArcMenuItem.Enabled = mHoveredDNode != null && hoveredNode.Owner == null;
            moveToArcMenuItem.DropDownItems.Clear();
            if (moveToArcMenuItem.Enabled)
            {
                var dm = GameMasterDataManager.GetInstance();
                foreach (var arc in dm.GetAllNodesOfType(GameMasterNodeType.ARC))
                {
                    if (arc.Owner == dm.GraphRoot)
                    {
                        moveToArcMenuItem.DropDownItems.Add(arc.Name).Tag = arc;
                    }
                }
            }

            attachEdgeMenuItem.Enabled = mSelectedNode != null && mHoveredDEdge != null && mHoveredDEdge.Edge.UserData is string;
            attachEdgeMenuItem.Text    = "Set as in_edge" + (attachEdgeMenuItem.Enabled ? " of " + mSelectedNode.Name : "");
            attachEdgeMenuItem.Tag     = mHoveredDEdge?.Edge.UserData; // Lame. Things are unhovered when we click, so remember our target.
        }
Exemplo n.º 4
0
        private IEnumerable <string> GetAllEdges()
        {
            if (graphViewer.Graph == null)
            {
                yield break;
            }

            SortedSet <string> allEdges = new SortedSet <string>();

            allEdges.Add("start");
            foreach (var node in graphViewer.Graph.Nodes)
            {
                GameMasterNode nodeData      = GameMasterDataManager.GetInstance().GetGameMasterNode(node.Id);
                var            encounterNode = nodeData?.NodeData as EncounterNodeData;
                if (encounterNode != null)
                {
                    foreach (var edge in encounterNode.OutEdgeStrings)
                    {
                        allEdges.Add(edge);
                    }
                }
            }

            foreach (var edge in allEdges)
            {
                yield return('"' + edge + '"');
            }
        }
 private void encounterTreeView_AfterSelect(object sender, TreeViewEventArgs e)
 {
     GameMasterDataManager.GetInstance().OnCampaignSelected(this, e.Node);
     if (GameMasterDataManager.GetInstance().GraphRoot != null)
     {
         addNewGameMasterNode.Enabled = true;
     }
 }
 private void OnRefreshTimerTick(object sender, EventArgs e)
 {
     GameMasterDataManager.GetInstance().RefreshGraph(this);
     if (refreshGraphTimer != null)
     {
         refreshGraphTimer.Stop();
         refreshGraphTimer = null;
     }
 }
        private void addNewGameMasterNode_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            ToolStripItem clickedItem = e.ClickedItem;

            if (clickedItem != null && GameMasterDataManager.GetInstance().GraphRoot != null)
            {
                mSelectedNewScriptNode = clickedItem.Text;
                saveNewEncounterNodeDialog.InitialDirectory = System.IO.Path.GetFullPath(GameMasterDataManager.GetInstance().GraphRoot.Directory);
                saveNewEncounterNodeDialog.ShowDialog(this);
            }
        }
 public void Reload()
 {
     // Reload the encounter designer.
     GameMasterDataManager.GetInstance().ClearModifiedFlags();
     GameMasterDataManager.GetInstance().RefreshGraph(this);
     encounterTreeView.Refresh();
     if (mNodePreview != null)
     {
         // This can be null.
         mNodePreview.Refresh();
     }
     Initialize();
 }
Exemplo n.º 9
0
        private void moveToArcMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (mSelectedNode == null || mSelectedNode.Owner != null || !(mSelectedNode.NodeData is EncounterNodeData))
            {
                return;
            }

            var selectedNodeId = mSelectedNode.Id;

            mSelectedNode.Owner = e.ClickedItem.Tag as GameMasterNode;
            (mSelectedNode.Owner.NodeData as ArcNodeData).AddEncounter(mSelectedNode.NodeData as EncounterNodeData);
            mSelectedNode.Owner.IsModified = true;
            GameMasterDataManager.GetInstance().SaveModifiedFiles();
            GameMasterDataManager.GetInstance().RefreshGraph(this);
        }
Exemplo n.º 10
0
        private void UpdateHoveredObjects(IViewerObject hoveredObject)
        {
            // Update hovered node.
            var dNode = hoveredObject as DNode;

            if (mHoveredDNode != dNode)
            {
                if (mHoveredDNode != null)
                {
                    SetBranchHighlighted(mHoveredDNode, false);
                    mHoveredDNode = null;
                }

                if (dNode != null)
                {
                    GameMasterNode nodeData = GameMasterDataManager.GetInstance().GetGameMasterNode(dNode.DrawingNode.Id);
                    if (nodeData != null)
                    {
                        mHoveredDNode = dNode;
                        SetBranchHighlighted(mHoveredDNode, true);
                    }
                }
            }

            // Update hovered edge.
            var dEdge = hoveredObject as DEdge;

            if (mHoveredDEdge != dEdge)
            {
                if (mHoveredDEdge != null)
                {
                    mHoveredDEdge.DrawingEdge.Attr.LineWidth -= 2;
                    graphViewer.Invalidate(mHoveredDEdge);
                    mHoveredDEdge = null;
                    graphViewer.SetToolTip(mHoveredEdgeTooltip, "");
                }

                if (dEdge != null)
                {
                    dEdge.DrawingEdge.Attr.LineWidth += 2;
                    graphViewer.Invalidate(dEdge);
                    mHoveredDEdge = dEdge;
                    graphViewer.SetToolTip(mHoveredEdgeTooltip, mHoveredDEdge.Edge.UserData as string);
                }
            }
        }
 private void graphViewer_MouseDown(object sender, MouseEventArgs e)
 {
     if (graphViewer.Graph != null)
     {
         object obj   = graphViewer.GetObjectAt(e.X, e.Y);
         var    dnode = obj as DNode;
         if (dnode != null)
         {
             Node           drawingNode = dnode.DrawingNode;
             GameMasterNode nodeData    = GameMasterDataManager.GetInstance().GetGameMasterNode(drawingNode.Id);
             UpdateSelectedNodeInfo(nodeData);
         }
         else
         {
             UpdateSelectedNodeInfo(null);
         }
     }
 }
        public void Initialize()
        {
            UpdateSelectedNodeInfo(null);
            graphViewer.Graph = null;
            new GameMasterDataManager();
            GameMasterDataManager.GetInstance().Load();
            addNewGameMasterNode.DropDownItems.Clear();
            foreach (EncounterScriptFile scriptFile in GameMasterDataManager.GetInstance().GetGenericScriptNodes())
            {
                if (scriptFile.DefaultJson.Length > 0)
                {
                    addNewGameMasterNode.DropDownItems.Add(scriptFile.Name);
                }
            }

            encounterTreeView.Nodes.Clear();
            GameMasterDataManager.GetInstance().FillEncounterNodeTree(encounterTreeView);
        }
Exemplo n.º 13
0
        public void Reload()
        {
            // Reload the encounter designer.
            GameMasterDataManager.GetInstance().ClearModifiedFlags();
            GameMasterDataManager.GetInstance().RefreshGraph(this);
            encounterTreeView.Refresh();
            if (mNodePreview != null)
            {
                // This can be null.
                mNodePreview.Refresh();
            }

            Initialize();

            // Reselect previously selected campaign if we had one open in the graph view before reloading
            if (mSelectedCampaign != null)
            {
                GameMasterDataManager.GetInstance().OnCampaignSelected(this, mSelectedCampaign);
            }
        }
Exemplo n.º 14
0
            public bool OnAccept(string inputMessage)
            {
                // Do the cloning
                string potentialNewNodeName = inputMessage.Trim();

                if (potentialNewNodeName.Length <= 1)
                {
                    MessageBox.Show("You must enter a name longer than 1 character for the clone!");
                    return(false);
                }

                if (potentialNewNodeName.Equals(mNode.Name))
                {
                    MessageBox.Show("You must enter a new unique name for the clone!");
                    return(false);
                }

                GameMasterDataManager.GetInstance().CloneNode(mViewer, mNode, potentialNewNodeName);
                return(true);
            }
 private void deleteNodeToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (mSelectedNode != null)
     {
         string       path   = mSelectedNode.Path;
         DialogResult result = MessageBox.Show("Are you sure you want to delete " + path + "?", "Confirm Delete", MessageBoxButtons.OKCancel);
         if (result == DialogResult.OK)
         {
             GameMasterNode currentCampaign     = GameMasterDataManager.GetInstance().GraphRoot;
             string         currentCampaignName = currentCampaign != null ? currentCampaign.Name : null;
             string         currentCampaignMod  = currentCampaign != null ? currentCampaign.Module : null;
             System.IO.File.Delete(path);
             Initialize();
             if (currentCampaignName != null)
             {
                 GameMasterDataManager.GetInstance().SelectCampaign(this, currentCampaignMod, currentCampaignName);
             }
         }
     }
 }
        private void saveNewEncounterNodeDialog_FileOk(object sender, CancelEventArgs e)
        {
            string filePath = saveNewEncounterNodeDialog.FileName;

            if (filePath == null)
            {
                return;
            }

            filePath = JsonHelper.NormalizeSystemPath(filePath);
            GameMasterNode existingNode = GameMasterDataManager.GetInstance().GetGameMasterNode(filePath);

            if (existingNode != null)
            {
                MessageBox.Show("Cannot override an existing node. Either edit that node or create a new name.");
                return;
            }

            GameMasterDataManager.GetInstance().AddNewGenericScriptNode(this, mSelectedNewScriptNode, filePath);
        }
        private void graphViewer_EdgeAdded(object sender, EventArgs e)
        {
            Edge edge = (Edge)sender;

            if (!GameMasterDataManager.GetInstance().TryAddEdge(edge.Source, edge.Target))
            {
                // Shouldn't add this edge. Undo it
                graphViewer.Undo();
            }
            else
            {
                GameMasterDataManager.GetInstance().SaveModifiedFiles();
                if (refreshGraphTimer == null)
                {
                    refreshGraphTimer          = new Timer();
                    refreshGraphTimer.Interval = 100;
                    refreshGraphTimer.Enabled  = true;
                    refreshGraphTimer.Tick    += new EventHandler(OnRefreshTimerTick);
                    refreshGraphTimer.Start();
                }
            }
        }
Exemplo n.º 18
0
        private void UpdateValidationSchema()
        {
            if (mNodePreview == null || mSelectedNode == null)
            {
                return;
            }

            var encounterNode = mSelectedNode.NodeData as EncounterNodeData;

            if (encounterNode == null)
            {
                return;
            }

            var schema = GameMasterDataManager.GetInstance().GetEncounterSchema(encounterNode.EncounterType);

            if (schema != null)
            {
                var suggester = mNodePreview.SetValidationSchema(schema);
                suggester.AddCustomSource("http://stonehearth.net/schemas/encounters/elements/edge.json", GetAllEdges);
                suggester.AddCustomSource("http://stonehearth.net/schemas/encounters/elements/node.json", GetAllNodes);
            }
        }
Exemplo n.º 19
0
        private IEnumerable <string> GetAllNodes()
        {
            if (graphViewer.Graph == null)
            {
                yield break;
            }

            SortedSet <string> allNodes = new SortedSet <string>();

            foreach (var node in graphViewer.Graph.Nodes)
            {
                GameMasterNode nodeData = GameMasterDataManager.GetInstance().GetGameMasterNode(node.Id);
                if (nodeData != null)
                {
                    allNodes.Add(nodeData.Name);
                }
            }

            foreach (var node in allNodes)
            {
                yield return('"' + node + '"');
            }
        }
Exemplo n.º 20
0
        private void ValidateSchema()
        {
            textBox.Styles[Style.LineNumber].BackColor = Color.LightGray;

            if (textBox.Lexer != ScintillaNET.Lexer.Json)
            {
                // No validation possible.
                return;
            }

            // Find errors.
            var result = JsonSchemaTools.Validate(jsonValidationSchema, textBox.Text);

            validationErrors = result.Item2;
            textBox.Styles[Style.LineNumber].BackColor = Color.LightGreen;
            if (result.Item1 == JsonSchemaTools.ValidationResult.Valid)
            {
                var hasBespokeSchema = jsonValidationSchema != null &&
                                       ((mFileData as JsonFileData).Json.Value <string>("encounter_type") == "none" ||
                                        jsonValidationSchema != GameMasterDataManager.GetInstance().GetEncounterSchema(null));
                textBox.Styles[Style.LineNumber].BackColor = hasBespokeSchema ? Color.LightGreen : Color.LightGray;
            }
            else
            {
                textBox.Styles[Style.LineNumber].BackColor = (result.Item1 == JsonSchemaTools.ValidationResult.InvalidJson) ? Color.IndianRed : Color.Orange;
            }

            // Display errors.
            textBox.MarkerDeleteAll(kErrorMarkerNumber);
            if (validationErrors.Count > 0)
            {
                foreach (var error in validationErrors)
                {
                    textBox.Lines[error.Key].MarkerAdd(kErrorMarkerNumber);
                }
            }
        }
Exemplo n.º 21
0
        private void deleteNodeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (mSelectedNode != null)
            {
                encounterGraphContextMenu.Hide();
                string       path   = mSelectedNode.Path;
                DialogResult result = MessageBox.Show("Are you sure you want to delete " + path + "?", "Confirm Delete", MessageBoxButtons.OKCancel);
                if (result == DialogResult.OK)
                {
                    // Unparent.
                    var encounter = mSelectedNode.NodeData as EncounterNodeData;
                    if (encounter != null)
                    {
                        var owner = mSelectedNode.Owner;
                        if (owner?.NodeData is ArcNodeData)
                        {
                            (owner.NodeData as ArcNodeData).RemoveEncounter(encounter);
                        }
                    }

                    // Delete the actual file.
                    System.IO.File.Delete(path);

                    // Reinitialize.
                    GameMasterNode currentCampaign     = GameMasterDataManager.GetInstance().GraphRoot;
                    string         currentCampaignName = currentCampaign != null ? currentCampaign.Name : null;
                    string         currentCampaignMod  = currentCampaign != null ? currentCampaign.Module : null;
                    Initialize();
                    if (currentCampaignName != null)
                    {
                        GameMasterDataManager.GetInstance().SelectCampaign(this, currentCampaignMod, currentCampaignName);
                    }
                    GameMasterDataManager.GetInstance().RefreshGraph(this);
                }
            }
        }
Exemplo n.º 22
0
        private void graphViewer_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Middle)
            {
                mPreviousMouseX = e.X;
                mPreviousMouseY = e.Y;
            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Left ||
                     e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                if (graphViewer.Graph != null)
                {
                    var dNode = graphViewer.ObjectUnderMouseCursor as DNode;
                    if (dNode != null)
                    {
                        GameMasterNode nodeData = GameMasterDataManager.GetInstance().GetGameMasterNode(dNode.DrawingNode.Id);
                        if (nodeData != null)
                        {
                            if (mSelectedDNode != null)
                            {
                                SetBranchFocused(mSelectedDNode, false);
                                mSelectedDNode.DrawingNode.Attr.LineWidth = 1;
                                graphViewer.Invalidate(mSelectedDNode);
                            }

                            mSelectedDNode = dNode;
                            SetBranchFocused(mSelectedDNode, true);
                            mSelectedDNode.DrawingNode.Attr.LineWidth = 5;
                            graphViewer.Invalidate(mSelectedDNode);

                            UpdateSelectedNodeInfo(nodeData);
                        }
                    }
                }
            }
        }
Exemplo n.º 23
0
        public override void UpdateGraphNode(Node graphNode)
        {
            base.UpdateGraphNode(graphNode);

            var settings = graphNode.UserData as EncounterNodeRenderer.NodeDisplaySettings;

            var iconBasePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);

            switch (mEncounterType)
            {
            case "generator":
                graphNode.Attr.FillColor = GameMasterNode.kOrange;
                settings.Icon            = Image.FromFile(iconBasePath + "/images/encounter_generator.png");
                break;

            case "none":
                graphNode.Attr.FillColor = GameMasterNode.kGrey;
                break;

            case "create_camp":
                settings.Icon = Image.FromFile(iconBasePath + "/images/encounter_camp.png");
                break;

            case "wait":
            case "wait_for_event":
            case "wait_for_net_worth":
            case "wait_for_requirements_met":
            case "wait_for_time_of_day":
            case "item_threshold":
                settings.Icon = Image.FromFile(iconBasePath + "/images/encounter_wait.png");
                break;

            case "dialog_tree":
            case "donation_dialog":
                settings.Icon = Image.FromFile(iconBasePath + "/images/encounter_dialog.png");
                break;

            case "script":
                settings.Icon = Image.FromFile(iconBasePath + "/images/encounter_script.png");
                break;

            case "shop":
                settings.Icon = Image.FromFile(iconBasePath + "/images/encounter_shop.png");
                break;

            case "counter":
            case "set_counters":
                settings.Icon = Image.FromFile(iconBasePath + "/images/encounter_counter.png");
                break;

            case "destroy_entity":
                settings.Icon = Image.FromFile(iconBasePath + "/images/encounter_destroy.png");
                break;

            case "unlock_recipe":
                settings.Icon = Image.FromFile(iconBasePath + "/images/encounter_recipe.png");
                break;

            case "collection_quest":
            case "delivery_quest":
            case "dispatch_quest":
                settings.Icon = Image.FromFile(iconBasePath + "/images/encounter_quest.png");
                break;

            case "city_raid":
            case "create_mission":
                settings.Icon = Image.FromFile(iconBasePath + "/images/encounter_raid.png");
                break;

            case "city_tier_quest":
            case "town_upgrade_choice":
                settings.Icon = Image.FromFile(iconBasePath + "/images/encounter_tier_quest.png");
                break;

            case "city_tier_achieved":
            case "town_upgrade":
                settings.Icon = Image.FromFile(iconBasePath + "/images/encounter_tier_achieved.png");
                break;

            case "donation":
            case "add_citizen":      // Pushing it.
                settings.Icon = Image.FromFile(iconBasePath + "/images/encounter_loot.png");
                break;

            case "bulletin":
                graphNode.Attr.FillColor = GameMasterNode.kLightGrey;
                settings.Icon            = Image.FromFile(iconBasePath + "/images/document_16xLG.png");
                break;
            }

            settings.HasUnsavedChanges = NodeFile.IsModified;

            if (NodeFile.Owner == null)
            {
                settings.HasErrors = true;
            }

            if (!settings.HasErrors)
            {
                var schema       = GameMasterDataManager.GetInstance().GetEncounterSchema(mEncounterType);
                var jsonFileData = NodeFile.FileData as JsonFileData;
                if (jsonFileData.Json["mixins"] != null)
                {
                    jsonFileData = jsonFileData.CreateFileWithMixinsApplied();
                }

                settings.HasErrors = schema.Validate(jsonFileData.Json).Count > 0;
            }
        }
 public GameMasterDataManager()
 {
     sInstance = this;
 }
 public GameMasterDataManager()
 {
     sInstance = this;
 }
Exemplo n.º 26
0
 private void saveAllToolStripMenuItem_Click(object sender, EventArgs e)
 {
     GameMasterDataManager.GetInstance().SaveModifiedFiles();
     ModuleDataManager.GetInstance().SaveModifiedFiles();
     recipesView.SaveModifiedFiles();
 }