private static void SelectSourceFile(SelectSourceFileMessage message) { Window sender = message.Target as Window; OpenFileDialog dlg = new OpenFileDialog(); dlg.DefaultExt = message.FileExtension; dlg.Filter = message.FileExtensionFilter; if (dlg.ShowDialog(sender) != true) { return; } message.SelectedFilePath = dlg.FileName; }
private static void SelectSourceFile(SelectSourceFileMessage message) { Window sender = message.Target as Window; OpenFileDialog dlg = new OpenFileDialog(); dlg.DefaultExt = message.FileExtension; dlg.Filter = message.FileExtensionFilter; if (dlg.ShowDialog(sender) != true) { return; } message.SelectedFilePath = dlg.FileName; }
private void LoadQuestLine() { SelectSourceFileMessage message = new SelectSourceFileMessage { FileExtension = ".hqm", FileExtensionFilter = "HQM Files (*.hqm)|*.hqm|All Files (*.*)|*.*" }; this.MessengerInstance.Send(message); if (String.IsNullOrEmpty(message.SelectedFilePath)) { return; } this.questSetsMutable.Clear(); QuestLine ql; using (var stream = File.OpenRead(message.SelectedFilePath)) { ql = new HQMQuestLineReader().ReadQuestLine(stream); } this.PassCode = ql.PassCode; this.Description = ql.Description; Dictionary <int, QuestSetViewModel> questSetMapping = ql.QuestSets.ToDictionary(qs => qs.Id, qs => new QuestSetViewModel { Id = qs.Id, Name = qs.Name }); Dictionary <int, QuestViewModel> questMapping = new Dictionary <int, QuestViewModel>(); foreach (var quest in ql.Quests.Where(q => q != null)) { QuestSetViewModel set = questSetMapping[quest.QuestSetId]; QuestViewModel q = new QuestViewModel { Id = quest.Id, Description = quest.Description, Name = quest.Name, XPos = quest.XPos, YPos = quest.YPos, Icon = Conversions.ItemStackToItemStackViewModel(quest.Icon), IsBig = quest.IsBig, RepeatOption = { RepeatIntervalHours = quest.RepeatIntervalHours, RepeatType = quest.RepeatType }, TriggerOption = { TriggerType = quest.TriggerType, TaskCount = quest.TriggerTaskCount } }; q.ReplaceReputationRewards(quest.ReputationRewards.Select(reward => new ReputationRewardViewModel { ReputationId = reward.Id, Value = reward.Value })); // TODO: tasks. set.AddQuest(q); questMapping.Add(q.Id, q); } foreach (var q in questMapping.Values) { var qOrig = ql.Quests[q.Id]; if (qOrig.RequiredQuestIds == null) { continue; } foreach (var id in qOrig.RequiredQuestIds) { var reQ = ql.Quests[id]; QuestViewModel fromQuest = questMapping[reQ.Id]; QuestSetViewModel set = questSetMapping[reQ.QuestSetId]; if (qOrig.QuestSetId == reQ.QuestSetId) { set.AddQuestLink(fromQuest, q); } else { this.crossSetQuestLinksMutable.Add(new QuestLinkViewModel(fromQuest: fromQuest, toQuest: q)); } } } foreach (var set in questSetMapping.OrderBy(q => q.Key).Select(q => q.Value)) { this.questSetsMutable.Add(set); } foreach (var reputation in ql.Reputations) { this.reputationsMutable.Add(Conversions.ReputationToReputationViewModel(reputation)); } this.SelectedQuestSet = this.questSetsMutable[0]; }
private void LoadQuestLine() { SelectSourceFileMessage message = new SelectSourceFileMessage { FileExtension = ".hqm", FileExtensionFilter = "HQM Files (*.hqm)|*.hqm|All Files (*.*)|*.*" }; this.MessengerInstance.Send(message); if (String.IsNullOrEmpty(message.SelectedFilePath)) { return; } this.questSetsMutable.Clear(); QuestLine ql; using (var stream = File.OpenRead(message.SelectedFilePath)) { ql = new HQMQuestLineReader().ReadQuestLine(stream); } this.PassCode = ql.PassCode; this.Description = ql.Description; Dictionary<int, QuestSetViewModel> questSetMapping = ql.QuestSets.ToDictionary(qs => qs.Id, qs => new QuestSetViewModel { Id = qs.Id, Name = qs.Name }); Dictionary<int, QuestViewModel> questMapping = new Dictionary<int, QuestViewModel>(); foreach (var quest in ql.Quests.Where(q => q != null)) { QuestSetViewModel set = questSetMapping[quest.QuestSetId]; QuestViewModel q = new QuestViewModel { Id = quest.Id, Description = quest.Description, Name = quest.Name, XPos = quest.XPos, YPos = quest.YPos, Icon = Conversions.ItemStackToItemStackViewModel(quest.Icon), IsBig = quest.IsBig, RepeatOption = { RepeatIntervalHours = quest.RepeatIntervalHours, RepeatType = quest.RepeatType }, TriggerOption = { TriggerType = quest.TriggerType, TaskCount = quest.TriggerTaskCount } }; q.ReplaceReputationRewards(quest.ReputationRewards.Select(reward => new ReputationRewardViewModel { ReputationId = reward.Id, Value = reward.Value })); // TODO: tasks. set.AddQuest(q); questMapping.Add(q.Id, q); } foreach (var q in questMapping.Values) { var qOrig = ql.Quests[q.Id]; if (qOrig.RequiredQuestIds == null) { continue; } foreach (var id in qOrig.RequiredQuestIds) { var reQ = ql.Quests[id]; QuestViewModel fromQuest = questMapping[reQ.Id]; QuestSetViewModel set = questSetMapping[reQ.QuestSetId]; if (qOrig.QuestSetId == reQ.QuestSetId) { set.AddQuestLink(fromQuest, q); } else { this.crossSetQuestLinksMutable.Add(new QuestLinkViewModel(fromQuest: fromQuest, toQuest: q)); } } } foreach (var set in questSetMapping.OrderBy(q => q.Key).Select(q => q.Value)) { this.questSetsMutable.Add(set); } foreach (var reputation in ql.Reputations) { this.reputationsMutable.Add(Conversions.ReputationToReputationViewModel(reputation)); } this.SelectedQuestSet = this.questSetsMutable[0]; }