Ejemplo n.º 1
0
        private void UpdateSpellRow(MyClasses.MetaViewWrappers.IListRow row, int index)
        {
            int   origSpellId = int.Parse((string)row[SpellList.OrigSpellId][0]);
            Spell origSpell   = mFS.SpellTable.GetById(origSpellId);

            UpdateSpellRow(row, index, origSpell);
        }
Ejemplo n.º 2
0
 private void InsertEmptyTabRow(MyClasses.MetaViewWrappers.IList tab)
 {
     MyClasses.MetaViewWrappers.IListRow row = tab.Add();
     row[SpellList.Icon][1]        = AegisRedIcon;
     row[SpellList.Name][0]        = EmptyTabString;
     row[SpellList.SpellId][0]     = "-1";
     row[SpellList.OrigSpellId][0] = "-1";
 }
Ejemplo n.º 3
0
        private void UpdateSpellRow(MyClasses.MetaViewWrappers.IListRow row, int index, Spell spell)
        {
            Color rowColor = Color.White;

            if (!Core.CharacterFilter.IsSpellKnown(spell.Id))
            {
                rowColor = SpellListColors.RedGray;
            }

            bool replace;
            int  minLevel, maxLevel;

            switch (spell.School.Id)
            {
            case SpellSchools.Creature:
                replace  = chkReplCrit.Checked;
                minLevel = choLowCrit.Selected + 1;
                maxLevel = choHighCrit.Selected + 1;
                break;

            case SpellSchools.Item:
                replace  = chkReplItem.Checked;
                minLevel = choLowItem.Selected + 1;
                maxLevel = choHighItem.Selected + 1;
                break;

            case SpellSchools.Life:
                replace  = chkReplLife.Checked;
                minLevel = choLowLife.Selected + 1;
                maxLevel = choHighLife.Selected + 1;
                break;

            case SpellSchools.War:
                replace  = chkReplWar.Checked;
                minLevel = choLowWar.Selected + 1;
                maxLevel = choHighWar.Selected + 1;
                break;

            default:
                throw new Exception("Unknown spell school: " + spell.School.Name + " (ID: " + spell.School.Id + ")");
            }

            // Search for the highest level spell known in the group
            int    curLevel = 0;
            int    bestSpellId = spell.Id, bestLevel = minLevel;
            int    displayIcon = spell.IconId;
            string displayName = spell.Name;

            if (!IsDisplayingCurrentChar && replace &&
                (!Core.CharacterFilter.IsSpellKnown(spell.Id) || !chkOnlyReplUnknown.Checked))
            {
                List <SpellAndLevel> group;
                if (SpellIdToGroup.TryGetValue(spell.Id, out group))
                {
                    foreach (SpellAndLevel sl in group)
                    {
                        if (spell.Id == sl.SpellId)
                        {
                            curLevel = sl.Level;
                            if (curLevel < minLevel)
                            {
                                // Don't upgrade if the current spell is lower than the min level
                                bestSpellId = spell.Id;
                                break;
                            }
                        }
                        if (Core.CharacterFilter.IsSpellKnown(sl.SpellId) &&
                            sl.Level >= bestLevel && sl.Level <= maxLevel)
                        {
                            bestSpellId = sl.SpellId;
                            bestLevel   = sl.Level;
                        }
                    }
                    if (bestSpellId != spell.Id)
                    {
                        if (bestLevel < curLevel)
                        {
                            rowColor = SpellListColors.Yellow;
                        }
                        else if (bestLevel > curLevel)
                        {
                            rowColor = SpellListColors.Green;
                        }
                        else if (bestLevel == curLevel)
                        {
                            // The rare case where they may know a spell such as
                            // Dark Flame, but not Flame Bolt V
                            rowColor = Color.White;
                        }

                        if (chkShowAsLoaded.Checked)
                        {
                            Spell tmp = mFS.SpellTable.GetById(bestSpellId);
                            displayIcon = tmp.IconId;
                            displayName = tmp.Name;
                        }
                    }
                }
            }

            row[SpellList.Icon][1]        = displayIcon;
            row[SpellList.Name][0]        = "(" + (index + 1) + ") " + displayName;
            row[SpellList.Name].Color     = rowColor;
            row[SpellList.SpellId][0]     = bestSpellId.ToString();
            row[SpellList.OrigSpellId][0] = spell.Id.ToString();
        }
Ejemplo n.º 4
0
 private void InsertSpellRow(MyClasses.MetaViewWrappers.IList tab, int index, Spell spell)
 {
     MyClasses.MetaViewWrappers.IListRow row = (index >= tab.RowCount) ? tab.Add() : tab.Insert(index);
     UpdateSpellRow(row, index, spell);
 }
        private void LoadSettings()
        {
            bool     arrowLoaded = false;
            FileInfo settingsFile;

            try
            {
                settingsFile = new FileInfo(Util.FullPath("settings.xml"));
                if (!settingsFile.Exists)
                {
                    LoadArrowImage("Chrome");
                    arrowLoaded     = true;
                    mSettingsLoaded = true;
                    return;
                }
            }
            catch (Exception ex)
            {
                Util.HandleException(ex);
                LoadArrowImage("Chrome");
                arrowLoaded     = true;
                mSettingsLoaded = true;
                return;
            }

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(settingsFile.FullName);

                if (doc.DocumentElement.HasAttribute("version"))
                {
                    int.TryParse(doc.DocumentElement.GetAttribute("version"), out mLoadedSettingsVersion);
                }

                string      val;
                int         intVal;
                double      dblVal;
                bool        boolVal;
                Coordinates coords;
                Point       pt;
                Rectangle   rect;

                foreach (XmlElement ele in doc.DocumentElement.SelectNodes("setting"))
                {
                    val = ele.GetAttribute("value");

                    switch (ele.GetAttribute("name"))
                    {
                    case "ViewPosition":
                        if (TryParsePoint(val, out pt))
                        {
                            SetViewLocation(pt);
                        }
                        break;

                    case "nbkMain":
                        if (int.TryParse(val, out intVal))
                        {
                            if (intVal > 0 && intVal < MainTab.COUNT)
                            {
                                nbkMain.ActiveTab = intVal;
                            }
                        }
                        break;

                    case "nbkHuds":
                        if (int.TryParse(val, out intVal))
                        {
                            if (intVal > 0 && intVal < HudsTab.COUNT)
                            {
                                nbkHuds.ActiveTab = intVal;
                            }
                        }
                        break;

                    case "nbkAtlas":
                        if (int.TryParse(val, out intVal))
                        {
                            if (intVal >= 0 && intVal < AtlasTab.COUNT)
                            {
                                nbkAtlas.ActiveTab = intVal;
                            }
                        }
                        break;

                    case "nbkSettings":
                        if (int.TryParse(val, out intVal))
                        {
                            if (intVal > 0 && intVal < SettingsTab.COUNT)
                            {
                                nbkSettings.ActiveTab = intVal;
                            }
                        }
                        break;

                    case "nbkRouteSettings":
                        if (int.TryParse(val, out intVal))
                        {
                            if (intVal > 0 && intVal < RouteSettingsTab.COUNT)
                            {
                                nbkRouteSettings.ActiveTab = intVal;
                            }
                        }
                        break;

                    //
                    // HUDs > Arrow HUD Tab
                    //
                    case "ArrowHud.Visible":
                        if (bool.TryParse(val, out boolVal))
                        {
                            mArrowHud.Visible = boolVal;
                        }
                        break;

                    case "ArrowHud.Location":
                        if (TryParsePoint(val, out pt))
                        {
                            mArrowHud.Location = pt;
                        }
                        break;

                    // -- Old v
                    case "ArrowHud.DestinationCoords":
                        if (Coordinates.TryParse(val, out coords))
                        {
                            mArrowHud.DestinationCoords = coords;
                        }
                        break;

                    case "ArrowHud.DestinationLocation":
                        if (int.TryParse(val, out intVal))
                        {
                            Location loc;
                            if (mLocDb.TryGet(intVal, out loc) && loc.Coords == mArrowHud.DestinationCoords)
                            {
                                mArrowHud.DestinationLocation = loc;
                            }
                        }
                        break;
                    // -- Old ^

                    case "ArrowHud.DisplayIndoors":
                        if (bool.TryParse(val, out boolVal))
                        {
                            mArrowHud.DisplayIndoors = boolVal;
                        }
                        break;

                    case "ArrowHud.ShowDestinationOver":
                        if (bool.TryParse(val, out boolVal))
                        {
                            mArrowHud.ShowDestinationOver = boolVal;
                        }
                        break;

                    case "ArrowHud.ShowDistanceUnder":
                        if (bool.TryParse(val, out boolVal))
                        {
                            mArrowHud.ShowDistanceUnder = boolVal;
                        }
                        break;

                    case "ArrowHud.PositionLocked":
                        if (bool.TryParse(val, out boolVal))
                        {
                            mArrowHud.PositionLocked = boolVal;
                        }
                        break;

                    case "ArrowHud.ArrowName":
                        LoadArrowImage(val);
                        arrowLoaded = true;
                        break;

                    case "ArrowHud.TextSize":
                        if (int.TryParse(val, out intVal))
                        {
                            mArrowHud.TextSize = intVal;
                        }
                        break;

                    case "ArrowHud.TextColor":
                        // Setting choTextColor.Selected calls its change event handler,
                        // which changes mArrowHud's text color, unless the color is at
                        // index 0, which should always be white (the default for mArrowHud)
                        for (int i = 0; i < choTextColor.Count; i++)
                        {
                            if (val == (string)choTextColor.Data[i])
                            {
                                choTextColor.Selected = i;
                                choTextColor_Change(choTextColor, new MyClasses.MetaViewWrappers.MVIndexChangeEventArgs(0, i));
                                break;
                            }
                        }
                        break;

                    case "ArrowHud.TextBold":
                        if (bool.TryParse(val, out boolVal))
                        {
                            mArrowHud.TextBold = boolVal;
                        }
                        break;

                    //
                    // HUDs > Dereth Map Tab
                    //
                    case "DerethMap.Region":
                        if (TryParseRectangle(val, out rect))
                        {
                            mMapHud.Region = rect;
                        }
                        break;

                    case "DerethMap.Sticky":
                        if (bool.TryParse(val, out boolVal))
                        {
                            mMapHud.Sticky = boolVal;
                        }
                        break;

                    case "DerethMap.CenterOnPlayer":
                        if (bool.TryParse(val, out boolVal))
                        {
                            mMapHud.CenterOnPlayer = boolVal;
                        }
                        break;

                    case "DerethMap.ShowRoute":
                        if (bool.TryParse(val, out boolVal))
                        {
                            mMapHud.ShowRoute = boolVal;
                        }
                        break;

                    case "DerethMap.ShowLocations":
                        if (bool.TryParse(val, out boolVal))
                        {
                            mMapHud.ShowLocations = boolVal;
                        }
                        break;

                    case "DerethMap.ShowLocationsAllZooms":
                        if (bool.TryParse(val, out boolVal))
                        {
                            mMapHud.ShowLocationsAllZooms = boolVal;
                        }
                        break;

                    case "DerethMap.ShowLabels":
                        if (bool.TryParse(val, out boolVal))
                        {
                            mMapHud.ShowLabels = boolVal;
                        }
                        break;

                    // -- Old v
                    case "DerethMap.AlphaActive":
                        if (int.TryParse(val, out intVal))
                        {
                            SetWindowAlpha(mMapHud, true, intVal);
                        }
                        break;

                    case "DerethMap.AlphaInactive":
                        if (int.TryParse(val, out intVal))
                        {
                            SetWindowAlpha(mMapHud, false, intVal);
                        }
                        break;
                    // -- Old ^

                    case "DerethMap.Zoom":
                        if (double.TryParse(val, out dblVal))
                        {
                            mMapHud.Zoom = (float)dblVal;
                        }
                        break;

                    case "DerethMap.DragButton":
                        try { mMapHud.DragButton = (MouseButtons)Enum.Parse(typeof(MouseButtons), val, true); }
                        catch { /* Ignore */ }
                        break;

                    case "DerethMap.SelectLocationButton":
                        try { mMapHud.SelectLocationButton = (MouseButtons)Enum.Parse(typeof(MouseButtons), val, true); }
                        catch { /* Ignore */ }
                        break;

                    case "DerethMap.ContextMenuButton":
                        try { mMapHud.ContextMenuButton = (MouseButtons)Enum.Parse(typeof(MouseButtons), val, true); }
                        catch { /* Ignore */ }
                        break;

                    case "DerethMap.DetailsButton":
                        try { mMapHud.DetailsButton = (MouseButtons)Enum.Parse(typeof(MouseButtons), val, true); }
                        catch { /* Ignore */ }
                        break;

                    //
                    // HUDs > Dungeon Map Tab
                    //
                    case "DungeonMap.Region":
                        if (TryParseRectangle(val, out rect))
                        {
                            mDungeonHud.Region = rect;
                        }
                        break;

                    case "DungeonMap.Sticky":
                        if (bool.TryParse(val, out boolVal))
                        {
                            mDungeonHud.Sticky = boolVal;
                        }
                        break;

                    case "DungeonMap.CurrentDungeon":
                        if (int.TryParse(val, out intVal))
                        {
                            mDungeonHud.LoadDungeonById(intVal);
                        }
                        break;

                    case "DungeonMap.AutoLoadMaps":
                        if (bool.TryParse(val, out boolVal))
                        {
                            mDungeonHud.AutoLoadMaps = boolVal;
                        }
                        break;

                    case "DungeonMap.ShowCompass":
                        if (bool.TryParse(val, out boolVal))
                        {
                            mDungeonHud.ShowCompass = boolVal;
                        }
                        break;

                    case "DungeonMap.AutoRotateMap":
                        if (bool.TryParse(val, out boolVal))
                        {
                            mDungeonHud.AutoRotateMap = boolVal;
                        }
                        break;

                    case "DungeonMap.MoveWithPlayer":
                        if (bool.TryParse(val, out boolVal))
                        {
                            mDungeonHud.MoveWithPlayer = boolVal;
                        }
                        break;

                    case "DungeonMap.DragButton":
                        try { mDungeonHud.DragButton = (MouseButtons)Enum.Parse(typeof(MouseButtons), val, true); }
                        catch { /* Ignore */ }
                        break;

                    //
                    // HUDs > General Tab
                    //
                    case "Toolbar.Visible":
                        if (bool.TryParse(val, out boolVal))
                        {
                            mToolbar.Visible = boolVal;
                        }
                        break;

                    case "Toolbar.Location":
                        if (TryParsePoint(val, out pt))
                        {
                            mToolbar.Location = pt;
                        }
                        break;

                    case "Toolbar.Display":
                        try { mToolbar.Display = (ToolbarDisplay)Enum.Parse(typeof(ToolbarDisplay), val, true); }
                        catch { /* Ignore */ }
                        break;

                    case "Toolbar.Orientation":
                        try { mToolbar.Orientation = (ToolbarOrientation)Enum.Parse(typeof(ToolbarOrientation), val, true); }
                        catch { /* Ignore */ }
                        break;

                    case "MainViewToolButton.Visible":
                        if (bool.TryParse(val, out boolVal))
                        {
                            mMainViewToolButton.Visible = boolVal;
                        }
                        break;

                    case "ArrowToolButton.Visible":
                        if (bool.TryParse(val, out boolVal))
                        {
                            mArrowToolButton.Visible = boolVal;
                        }
                        break;

                    case "DerethToolButton.Visible":
                        if (bool.TryParse(val, out boolVal))
                        {
                            mDerethToolButton.Visible = boolVal;
                        }
                        break;

                    case "DungeonToolButton.Visible":
                        if (bool.TryParse(val, out boolVal))
                        {
                            mDungeonToolButton.Visible = boolVal;
                        }
                        break;

                    case "chkAllowBothMaps":
                        if (bool.TryParse(val, out boolVal))
                        {
                            chkAllowBothMaps.Checked = boolVal;
                        }
                        break;

                    case "Huds.AlphaActive":
                        if (int.TryParse(val, out intVal))
                        {
                            mArrowHud.Alpha = intVal;
                            SetWindowAlpha(mMapHud, true, intVal);
                            SetWindowAlpha(mDungeonHud, true, intVal);
                        }
                        break;

                    case "Huds.AlphaInactive":
                        if (int.TryParse(val, out intVal))
                        {
                            SetWindowAlpha(mMapHud, false, intVal);
                            SetWindowAlpha(mDungeonHud, false, intVal);
                        }
                        break;

                    //
                    // Atlas > Update Tab
                    //
                    case "edtLocationsUrl":
                        edtLocationsUrl.Text = val;
                        break;

                    case "chkUpdateRemind":
                        if (bool.TryParse(val, out boolVal))
                        {
                            chkUpdateRemind.Checked = boolVal;
                        }
                        break;

                    //
                    // Settings > Chat Tab
                    //
                    case "chkLinkCoords":
                        if (bool.TryParse(val, out boolVal))
                        {
                            chkLinkCoords.Checked = boolVal;
                        }
                        break;

                    case "Util.DefaultTargetWindows":
                    {
                        ChatWindow windows;
                        if (Util.TryParseEnum <ChatWindow>(val, out windows) && windows != ChatWindow.Default)
                        {
                            Util.DefaultWindow = windows;
                        }
                    }
                    break;

                    // -- Old v
                    case "choWriteMessagesTo":
                        if (int.TryParse(val, out intVal))
                        {
                            switch (intVal)
                            {
                            case 0: { Util.DefaultWindow = ChatWindow.MainChat; break; }

                            case 1: { Util.DefaultWindow = ChatWindow.One; break; }

                            case 2: { Util.DefaultWindow = ChatWindow.Two; break; }

                            case 3: { Util.DefaultWindow = ChatWindow.Three; break; }

                            case 4: { Util.DefaultWindow = ChatWindow.Four; break; }
                            }
                        }
                        break;
                    // -- Old ^

                    case "chkAlwaysShowErrors":
                        if (bool.TryParse(val, out boolVal))
                        {
                            chkAlwaysShowErrors.Checked = boolVal;
                            Util.WriteErrorsToMainChat  = boolVal;
                        }
                        break;

                    case "edtChatCommand":
                        edtChatCommand.Text = val;
                        break;

                    case "chkEnableCoordsCommand":
                        if (bool.TryParse(val, out boolVal))
                        {
                            chkEnableCoordsCommand.Checked = boolVal;
                        }
                        break;

                    case "edtCoordsCommand":
                        edtCoordsCommand.Text = val;
                        break;

                    case "chkEnableDestCommand":
                        if (bool.TryParse(val, out boolVal))
                        {
                            chkEnableDestCommand.Checked = boolVal;
                        }
                        break;

                    case "edtDestCommand":
                        edtDestCommand.Text = val;
                        break;

                    case "chkEnableFindCommand":
                        if (bool.TryParse(val, out boolVal))
                        {
                            chkEnableFindCommand.Checked = boolVal;
                        }
                        break;

                    case "edtFindCommand":
                        edtFindCommand.Text = val;
                        break;

                    case "chkTrackCorpses":
                        if (bool.TryParse(val, out boolVal))
                        {
                            chkTrackCorpses.Checked = boolVal;
                        }
                        break;

                    //
                    // Settings > Route Finding Tab
                    //
                    case "chkAutoUpdateRecalls":
                        if (bool.TryParse(val, out boolVal))
                        {
                            chkAutoUpdateRecalls.Checked = boolVal;
                        }
                        break;

                    case "edtMaxRunDist":
                        if (double.TryParse(val, out dblVal) && dblVal > 0)
                        {
                            edtMaxRunDist.Text         = dblVal.ToString();
                            RouteFinder.MaxRunDistance = dblVal;
                        }
                        break;

                    case "edtPortalRunDist":
                        if (double.TryParse(val, out dblVal) && dblVal > 0)
                        {
                            edtPortalRunDist.Text    = dblVal.ToString();
                            RouteFinder.PortalWeight = dblVal;
                        }
                        break;

                    case "chkAutoDetectPortalDevices":
                        if (bool.TryParse(val, out boolVal))
                        {
                            chkAutoDetectPortalDevices.Checked = boolVal;
                        }
                        break;
                    }
                }

                // Reset setting
                if (mLoadedSettingsVersion < 2)
                {
                    chkAutoUpdateRecalls.Checked = true;
                }

                XmlElement arrowNode = doc.DocumentElement.SelectSingleNode("arrowTarget") as XmlElement;
                if (arrowNode != null)
                {
                    mArrowHud.LoadDestinationXml(arrowNode, mLocDb);
                }

                XmlElement startLocationsNode = doc.DocumentElement.SelectSingleNode("startLocations") as XmlElement;
                if (startLocationsNode != null)
                {
                    mStartLocations.Clear();
                    foreach (XmlElement node in startLocationsNode.ChildNodes)
                    {
                        RouteStart loc;
                        if (RouteStart.TryParseXml(node, out loc, Core.CharacterFilter.Id, Core.CharacterFilter.Name, MonarchId, MonarchName, Core.CharacterFilter.AccountName))
                        {
                            mStartLocations[loc.Name] = loc;
                        }
                    }
                }

                string     portalDevicesXpath       = "portalDevices/monarch[@guid='" + MonarchId.ToString("X") + "']";
                XmlElement portalDevicesMonarchNode = doc.DocumentElement.SelectSingleNode(portalDevicesXpath) as XmlElement;
                if (portalDevicesMonarchNode != null)
                {
                    foreach (PortalDevice device in mPortalDevices.Values)
                    {
                        device.LoadSettingsXml(portalDevicesMonarchNode);
                    }
                }

                XmlElement favoriteLocationsNode = doc.DocumentElement.SelectSingleNode("favoriteLocations") as XmlElement;
                if (favoriteLocationsNode != null)
                {
                    foreach (XmlElement node in favoriteLocationsNode.GetElementsByTagName("favorite"))
                    {
                        Location loc = GetLocation(node.GetAttribute("id"));
                        if (loc != null)
                        {
                            loc.IsFavorite = true;
                        }
                    }
                }

                XmlElement recentLocationsNode = doc.DocumentElement.SelectSingleNode("recentLocations") as XmlElement;
                if (recentLocationsNode != null)
                {
                    lstRecent.Clear();
                    int ct = 0;
                    foreach (XmlElement node in recentLocationsNode.GetElementsByTagName("recent"))
                    {
                        Location loc = GetLocation(node.GetAttribute("id"));
                        if (loc != null)
                        {
                            MyClasses.MetaViewWrappers.IListRow row = lstRecent.Add();
                            row[LocationList.Icon][1]   = loc.Icon;
                            row[LocationList.Name][0]   = loc.Name;
                            row[LocationList.GoIcon][1] = GoIcon;
                            row[LocationList.ID][0]     = loc.Id.ToString();
                        }
                        if (ct++ >= MaxRecentLocations)
                        {
                            break;
                        }
                    }
                    UpdateListCoords(lstRecent, chkRecentShowRelative.Checked);
                }

                XmlElement recentCoordsNode = doc.DocumentElement.SelectSingleNode("recentCoords") as XmlElement;
                if (recentCoordsNode != null)
                {
                    lstRecentCoords.Clear();
                    foreach (XmlElement node in recentCoordsNode.GetElementsByTagName("recent"))
                    {
                        if (Coordinates.TryParse(node.GetAttribute("coords"), out coords))
                        {
                            MyClasses.MetaViewWrappers.IListRow row = lstRecentCoords.Add();
                            row[RecentCoordsList.Coords][0] = coords.ToString();
                            if (node.HasAttribute("name"))
                            {
                                row[RecentCoordsList.Name][0] = node.GetAttribute("name");
                            }
                            if (node.HasAttribute("icon"))
                            {
                                int    icon;
                                string iconHex = node.GetAttribute("icon");
                                if (int.TryParse(iconHex, NumberStyles.HexNumber, null, out icon))
                                {
                                    row[RecentCoordsList.Icon][1] = icon;
                                }
                            }
                        }
                    }
                }

                if (!arrowLoaded)
                {
                    LoadArrowImage("Chrome");
                }
            }
            catch (Exception ex)
            {
                Util.HandleException(ex, "Error encountered while loading settings.xml file", true);
                string errorPath = Util.FullPath("settings_error.xml");
                if (File.Exists(errorPath))
                {
                    File.Delete(errorPath);
                }
                settingsFile.MoveTo(errorPath);
                Util.SevereError("The old settings.xml file has been renamed to settings_error.xml "
                                 + "and a new settings.xml will be created with the defaults.");
            }
            finally
            {
                mSettingsLoaded   = true;
                mSettingsLoadTime = DateTime.Now;
            }
        }