Пример #1
0
 public static bool HasUnmetDependencies(List<ISkill> selectedSkillList, SkillSquare skill)
 {
     foreach (string dependencyName in skill.DependentSkills)
     {
         if (!IsSkillSelected(selectedSkillList, dependencyName))
             return true;
     }
     return false;
 }
Пример #2
0
        private void ReadFileCallback(XmlReader reader, object data)
        {
            if (reader.LocalName != "Skills")
                throw new System.InvalidOperationException("Bad skill defination file");

            m_tabLoading.DefaultCurorPosition = new Point(int.Parse(reader.GetAttribute("DefaultX")), int.Parse(reader.GetAttribute("DefaultY")));

            m_maxRow = int.Parse(reader.GetAttribute("MaxRow"));

            SkillSquare currentSquare = null;
            bool inIcon = false;
            bool inDependencies = false;
            while (true)
            {
                reader.Read();
                if (reader.NodeType == XmlNodeType.EndElement && reader.LocalName == "Skills")
                    break;

                if (reader.LocalName == "Skill")
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        string name = reader.GetAttribute("Name");
                        int column = int.Parse(reader.GetAttribute("Column"));
                        int row = int.Parse(reader.GetAttribute("Row"));
                        currentSquare = new SkillSquare(CalculatePosition(column, row), name);
                        m_tabLoading.SkillSquares.Add(currentSquare);
                        HandleNewPoint(column, row);
                    }
                }
                else if (reader.LocalName == "Icon")
                {
                    if (reader.NodeType == XmlNodeType.Element)
                        inIcon = true;
                    else if (reader.NodeType == XmlNodeType.EndElement)
                        inIcon = false;
                }
                else if (reader.LocalName.StartsWith("Row") && reader.NodeType == XmlNodeType.Element)
                {
                    // reader.ReadElementContentAsString() apparently moves us to the next row, so do this while we have a row
                    do
                    {
                        if (!inIcon)
                            throw new InvalidOperationException("SkillTreeTabXMLHelper - Found a row outside of an icon?");
                        int rowNumber = int.Parse(reader.LocalName.Substring(3));

                        string value = reader.ReadElementContentAsString();
                        if (rowNumber != 0 && rowNumber != 1 && rowNumber != 2 && rowNumber != 3)
                            throw new InvalidOperationException("SkillTreeTabXMLHelper - Invalid row in icon?");

                        // Icon text is offset from the upper left
                        Point position = currentSquare.UpperLeft + new Point(1, 2 + rowNumber);
                        m_iconTextLines.Add(new Pair<Point, string>(position, value));
                    }
                    while (reader.LocalName.StartsWith("Row") && reader.NodeType == XmlNodeType.Element);
                }
                else if (reader.LocalName == "Dependencies" && reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.NodeType == XmlNodeType.Element)
                        inDependencies = true;
                    else if (reader.NodeType == XmlNodeType.EndElement)
                        inDependencies = false;
                }
                else if (reader.LocalName == "Dependency" && reader.NodeType == XmlNodeType.Element)
                {
                    if (!inDependencies)
                        throw new InvalidOperationException("SkillTreeTabXMLHelper - Found a dependency outside of a dependencies?");

                    currentSquare.AddDependency(reader.GetAttribute("Name"));
                }
            }
        }
Пример #3
0
        // Drawing each dependency line is a special case, 
        // so drawing between x and an adjacent row/column is a case
        //  5  1  4
        //  3  x  2
        private void DrawDependencyLine(SkillSquare current, SkillSquare dependent)
        {
            // Flip the polarity of the rows sine we're counting bottom up for those (backwards)
            int rowDifference = -1 * ((current.UpperLeft.Y - dependent.UpperLeft.Y) / RowOffSetPer);
            int columnDifference = (current.UpperLeft.X - dependent.UpperLeft.X) / ColumnOffSetPer;

            if (rowDifference >= 1 && columnDifference == 0)
            {
                // 1
                for (int i = 1; i <= GapBetweenRows + ((rowDifference - 1) * (GapBetweenRows + SquareSize)); ++i)
                    SetChar(current.UpperLeft + new Point(OffsetToCenterOfSize, i + SquareSize - 1), (char)TCODSpecialCharacter.VertLine);
                return;
            }
            else if (rowDifference == 0 && columnDifference == 1)
            {
                // 2
                for (int i = 1; i <= GapBetweenColumns; ++i)
                    SetChar(current.UpperLeft + new Point(-i, OffsetToCenterOfSize), (char)TCODSpecialCharacter.HorzLine);
                return;
            }
            else if (rowDifference == 0 && columnDifference == -1)
            {
                // 3
                for (int i = 1; i <= GapBetweenColumns; ++i)
                    SetChar(current.UpperLeft + new Point(SquareSize + i, OffsetToCenterOfSize), (char)TCODSpecialCharacter.HorzLine);
                return;
            }
            else if (rowDifference == 1 && columnDifference == 1)
            {
                // 4
                for (int i = 0; i < GapBetweenColumns; ++i)
                    SetChar(dependent.UpperLeft + new Point(SquareSize + i, -i), (char)224);
                return;
            }
            else if (rowDifference == 1 && columnDifference == -1)
            {
                // 5
                for (int i = 0; i < GapBetweenColumns; ++i)
                    SetChar(dependent.UpperLeft + new Point(-i - 1, -i), (char)225);
                return;
            }

            throw new InvalidDataException(string.Format("SkillTreeTabXMLHelper drawing dependency I don't know how to draw - {0} to {1}", current.SkillName, dependent.SkillName));
        }
Пример #4
0
        private void DrawSkillPopup(TCODConsole console, List<ISkill> selectedSkillList, int skillPointsLeft, SkillSquare cursorSkillSquare, ISkill cursorOverSkill, Point cursorPosition)
        {
            Point drawUpperLeft = ConvertGridToDrawCoord(cursorSkillSquare.UpperRight + new Point(1, 1), cursorPosition);
            
            int numberOfDependencies = cursorSkillSquare.DependentSkills.Count();
            int dialogHeight = ExplainPopupHeight;
            if (numberOfDependencies > 0)
            {
                int linesOfDependencies = numberOfDependencies;
                foreach (string dependentSkillName in cursorSkillSquare.DependentSkills)
                    linesOfDependencies += console.getHeightRect(drawUpperLeft.X + 2 + 3, 0, 20, 2, dependentSkillName);
                
                dialogHeight += 2 + linesOfDependencies;
                drawUpperLeft += new Point(0, 2 + linesOfDependencies);
            }

            string title = cursorOverSkill.Name;
            if (title.Length > 22)
                title = title.Substring(0, 22);

            console.printFrame(drawUpperLeft.X, drawUpperLeft.Y - dialogHeight, ExplainPopupWidth, dialogHeight, true, TCODBackgroundFlag.Set, title);

            int textX = drawUpperLeft.X + 2;
            int textY = drawUpperLeft.Y - dialogHeight + 2;

            // If we can't afford it and it isn't already selected, show the cost in red
            if (!selectedSkillList.Contains(cursorOverSkill) && cursorOverSkill.Cost > skillPointsLeft)
            {
                m_dialogHelper.SaveColors(console);
                console.setForegroundColor(TCODColor.red);
                console.print(textX, textY, string.Format("Skill Point Cost: {0}", cursorOverSkill.Cost));
                m_dialogHelper.ResetColors(console);
            }
            else
            {
                console.print(textX, textY, string.Format("Skill Point Cost: {0}", cursorOverSkill.Cost));
            }
            textY++;

            if (numberOfDependencies > 0)
            {
                textY++;
                console.print(textX, textY, "Dependencies:");
                textY++;
                m_dialogHelper.SaveColors(console);
                foreach (string dependentSkillName in cursorSkillSquare.DependentSkills)
                {
                    if (SkillTreeModelHelpers.IsSkillSelected(selectedSkillList, dependentSkillName))
                        m_dialogHelper.SetColors(console, false, true);
                    else
                        m_dialogHelper.SetColors(console, false, false);

                    console.printRect(textX + 3, textY, 20, 2, dependentSkillName);
                    textY++;
                }
                m_dialogHelper.ResetColors(console);
            }
            textY++;

            console.printRectEx(textX, textY, ExplainPopupWidth - 4, ExplainPopupHeight - 6, TCODBackgroundFlag.Set, TCODAlignment.LeftAlignment, cursorOverSkill.Description);
        }