private void Start() { playerDialogueButtonsContainer = GetComponentsInChildren <ScrollRect>().ToList().Find(t => t.gameObject.name == "Player Dialogue Buttons Container").gameObject.GetComponentInChildren <ContentSizeFitter>().gameObject; dialogueLogContainer = GetComponentsInChildren <ScrollRect>().ToList().Find(t => t.gameObject.name == "Dialogue Log Container").gameObject.GetComponentInChildren <ContentSizeFitter>().gameObject; playerCommunication = FindObjectOfType <PlayerCommunication_>(); npcCommunication = (NpcCommunication_)((NpcBehaviour_)((Npc_)GetComponentInParent <NpcBottomUi_>().owner).mechanics_.behaviour_).unitCommunication_; NpcStats_ thisNpc = (NpcStats_)((Npc_)GetComponentInParent <NpcBottomUi_>().owner).mechanics_.stats_; questManager = FindObjectOfType <QuestManager>(); if (!isStarted && thisNpc.diplomacy == Diplomacy.Allied) { Button greetingButton = Instantiate(buttonTemplate, playerDialogueButtonsContainer.transform); greetingButton.GetComponentInChildren <Text>().text = playerCommunication.GetGreetingDialogue().dialogueText; greetingButton.onClick.AddListener ( delegate { questManager.ActivateQuest(playerCommunication.GetGreetingDialogue().activateQuest); RefreshNpcDialogueLog(playerCommunication.GetGreetingDialogue()); } ); isStarted = true; } }
public void Load(QuestData dataToLoad, QuestManager questManager) { Debug.Log("Quest Load"); //Set the villager indexes villagerIndexes = dataToLoad.villagerIndexes; //Init the quest with the loaded data Init(dataToLoad.name, dataToLoad.slots, null, dataToLoad.time, questManager, dataToLoad.difficulty); if (manager == null) { Debug.Log("Manager is null"); } if (dataToLoad.active) { //Add each villager from the index for (int i = 0; i < villagerIndexes.Count; i++) { AddCharacter(manager.GetVillager(villagerIndexes[i])); } //Activate the quest properly questManager.ActivateQuest(this); } }
public void RefreshPlayerDialogueButtons(Dialogue npcQuestion) { DestroyPreviousPlayerDialogueButtons(); List <Dialogue> playerAnswers = playerCommunication.GetPlayerAnswers(npcQuestion); foreach (Dialogue playerAnswer in playerAnswers) { Button dialogueButton = Instantiate(buttonTemplate, playerDialogueButtonsContainer.transform); dialogueButton.GetComponentInChildren <Text>().text = playerAnswer.dialogueText; dialogueButton.onClick.AddListener ( delegate { questManager.ActivateQuest(playerAnswer.activateQuest); RefreshNpcDialogueLog(playerAnswer); } ); } }
public override void OnInitialize() { _isPossible = new bool[QuestManager.Quests.Count]; _rightPageLines = new List <UISolid>(); _imageMasks = new Texture2D[15]; for (int i = 0; i < _imageMasks.Length; i++) { _imageMasks[i] = SpiritMod.Instance.GetTexture("UI/QuestUI/Textures/ImageMask" + i); } UIMoveExpandWindow mainWindow = new UIMoveExpandWindow(SpiritMod.Instance.GetTexture("UI/QuestUI/Textures/AdventurerBook"), false, false, 10); mainWindow.Left.Set(450, 0); mainWindow.Top.Set(230, 0); mainWindow.Width.Set(1098, 0); mainWindow.Height.Set(760, 0); mainWindow.MinWidth.Set(1098, 0); // 1019 mainWindow.MinHeight.Set(760, 0); // 706 mainWindow.SetPadding(0f); // ensure the UI stays on screen when moved mainWindow.ForceScreenStick = true; // DEBUGGING FEATURE // TODO: REMOVE BEFORE RELEASE! mainWindow.OnMiddleDoubleClick += (UIMouseEvent evt, UIElement listeningElement) => { if (Main.keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftControl) && Main.keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftAlt) && Main.keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift)) { QuestManager.RestartEverything(); QuestManager.UnlockQuest <FirstAdventure>(false); } }; mainWindow.OnRightDoubleClick += (UIMouseEvent evt, UIElement listeningElement) => { if (Main.keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftControl) && Main.keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftAlt) && Main.keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift)) { foreach (Quest quest in QuestManager.Quests) { QuestManager.UnlockQuest(quest, false); } } }; _bookOverlay = new UIShaderImage(null); _bookOverlay.Left.Set(0f, 0f); _bookOverlay.Top.Set(0f, 0f); _bookOverlay.Width.Set(0f, 1f); _bookOverlay.Height.Set(0f, 1f); mainWindow.Append(_bookOverlay); // left page area UIElement leftPage = new UIElement(); leftPage.Left.Set(0f, 0.200196271f); leftPage.Top.Set(0f, 0.19121813f); leftPage.Width.Set(0f, 0.333660451f); leftPage.Height.Set(0f, 0.637393768f); leftPage.SetPadding(0); // right page area UIElement rightPage = new UIElement(); rightPage.Left.Set(0f, 0.593719333f); rightPage.Top.Set(0f, 0.169971671f); rightPage.Width.Set(0f, 0.333660451f); rightPage.Height.Set(0f, 0.722379603f); rightPage.SetPadding(0); // top buttons #region top buttons _questSectionIndex = 0; _questSectionButtons = CreateButtons(0f, 0.8f, true, "Available", "Active", "Completed"); for (int i = 0; i < _questSectionButtons.Length; i++) { int index = i; _questSectionButtons[i].OnMouseDown += (UIMouseEvent evt, UIElement el) => { ChangeFilter(0); ChangeSection(index); }; leftPage.Append(_questSectionButtons[i]); } ButtonArraySelect(_questSectionIndex, _questSectionButtons); #endregion leftPage.Append(CreateLine(22f, false)); // bottom buttons #region bottom buttons _questFilterIndex = 0; _questFilterButtons = CreateButtons(26f, 0.7f, false, "All", "Main", "Explorer", "Forager", "Slayer", "Other"); for (int i = 0; i < _questFilterButtons.Length; i++) { int index = i; _questFilterButtons[i].OnMouseDown += (UIMouseEvent evt, UIElement el) => { ChangeFilter(index); }; leftPage.Append(_questFilterButtons[i]); } ButtonArraySelect(_questFilterIndex, _questFilterButtons); #endregion leftPage.Append(CreateLine(48f, false)); UIElement questContainer = new UIElement(); questContainer.Width.Set(0f, 1f); questContainer.Top.Set(52f, 0f); questContainer.Height.Set(-72f, 1f); questContainer.SetPadding(0f); _questList = new UIModifiedList(); _questList.Width.Set(-18f, 1f); _questList.Height.Set(0f, 1f); _questList.SetPadding(0f); _questList.ListPadding = 2f; // create all the quest panels #region quests _allQuestButtons = new UISelectableQuest[QuestManager.Quests.Count]; for (int i = 0; i < QuestManager.Quests.Count; i++) { _allQuestButtons[i] = new UISelectableQuest(QuestManager.Quests[i], this); QuestManager.Quests[i].OnQuestStateChanged += _allQuestButtons[i].HandleState; QuestManager.Quests[i].OnQuestStateChanged += (Quest q) => FullBookUpdate(); _allQuestButtons[i].HandleState(QuestManager.Quests[i]); } for (int i = 0; i < _allQuestButtons.Length; i++) { int index = i; _allQuestButtons[i].OnMouseDown += (UIMouseEvent evt, UIElement el) => { _selectedQuestIndex = index; ButtonArraySelect(index, _allQuestButtons); }; } ButtonArraySelect(_selectedQuestIndex, _allQuestButtons); #endregion UIQuestBookScrollBar questListScrollbar = new UIQuestBookScrollBar(SpiritMod.Instance.BookUserInterface); questListScrollbar.SetView(100f, 1000f); questListScrollbar.Height.Set(-2f, 1f); questListScrollbar.Top.Set(2f, 0f); questListScrollbar.HAlign = 1f; questListScrollbar.Colour = new Color(43, 28, 17); _questList.SetScrollbar(questListScrollbar); questContainer.Append(questListScrollbar); questContainer.Append(_questList); leftPage.Append(questContainer); _questProgressCounterText = new UISimpleWrappableText("", 0.8f); _questProgressCounterText.Top.Set(-16f, 1f); _questProgressCounterText.Left.Set(-50f, 1f); _questProgressCounterText.Width.Set(50f, 0f); _questProgressCounterText.Height.Set(16f, 0f); _questProgressCounterText.Centered = true; _questProgressCounterText.Colour = new Color(43, 28, 17); leftPage.Append(_questProgressCounterText); // quest title _questTitleText = new UISimpleWrappableText("", 0.8f); _questTitleText.Top.Set(-26f, 0f); _questTitleText.Width.Set(0f, 1f); _questTitleText.Large = true; _questTitleText.Centered = true; _questTitleText.Colour = new Color(43, 28, 17); rightPage.Append(_questTitleText); // quest category _questCategoryText = new UISimpleWrappableText("", 1.08f); _questCategoryText.Top.Set(25f, 0f); _questCategoryText.Width.Set(0f, 1f); _questCategoryText.Centered = true; _questCategoryText.Border = true; _questCategoryText.BorderColour = new Color(43, 28, 17) * 0.8f; rightPage.Append(_questCategoryText); // image _questImage = new UIShaderImage(null); _questImage.Effect = SpiritMod.Instance.GetEffect("Effects/QuestShaders"); _questImage.Pass = _questImage.Effect.CurrentTechnique.Passes["Sepia"]; _questImage.PointSample = true; _questImage.Top.Set(50f, 0f); _questImage.Width.Set(0f, 1f); _questImage.Height.Set(130f, 0f); rightPage.Append(_questImage); // objectives title _questObjectivesTitle = new UISimpleWrappableText("Objectives", 0.8f); _questObjectivesTitle.Top.Set(189f, 0f); _questObjectivesTitle.Colour = new Color(43, 28, 17); rightPage.Append(_questObjectivesTitle); _questObjectivesLeftArrow = new UIImageButton(SpiritMod.Instance.GetTexture("UI/QuestUI/Textures/LeftArrow")); _questObjectivesLeftArrow.Left.Set(-60f, 1f); _questObjectivesLeftArrow.Top.Set(188f, 0f); _questObjectivesLeftArrow.SetVisibility(1f, 0.5f); _questObjectivesLeftArrow.OnClick += (UIMouseEvent evt, UIElement listeningElement) => { int page = _questObjectivesText.Page; page--; if (page < 0) { page = 0; } _questObjectivesText.Page = page; UpdateArrows(page, _questObjectivesText.MaxPage); }; rightPage.Append(_questObjectivesLeftArrow); _questObjectivesRightArrow = new UIImageButton(SpiritMod.Instance.GetTexture("UI/QuestUI/Textures/RightArrow")); _questObjectivesRightArrow.Left.Set(-14f, 1f); _questObjectivesRightArrow.Top.Set(188f, 0f); _questObjectivesRightArrow.SetVisibility(1f, 0.5f); _questObjectivesRightArrow.OnClick += (UIMouseEvent evt, UIElement listeningElement) => { int page = _questObjectivesText.Page; page++; if (page > _questObjectivesText.MaxPage) { page = _questObjectivesText.MaxPage; } _questObjectivesText.Page = page; UpdateArrows(page, _questObjectivesText.MaxPage); }; rightPage.Append(_questObjectivesRightArrow); _questObjectivesPageText = new UISimpleWrappableText("1 / 1", 0.62f); _questObjectivesPageText.Centered = true; _questObjectivesPageText.Left.Set(-31f, 1f); _questObjectivesPageText.Top.Set(188f, 0f); _questObjectivesPageText.Colour = new Color(43, 28, 17); rightPage.Append(_questObjectivesPageText); rightPage.Append(CreateLine(203f)); _questObjectivesText = new UISimpleWrappableText("", 0.7f); _questObjectivesText.Top.Set(209f, 0f); _questObjectivesText.Width.Set(0f, 1f); _questObjectivesText.MinWidth.Set(0f, 1f); _questObjectivesText.Wrappable = true; _questObjectivesText.MaxLines = 4; _questObjectivesText.Colour = new Color(43, 28, 17); rightPage.Append(_questObjectivesText); // client title _questClientTitle = new UISimpleWrappableText("Client - ", 0.8f); _questClientTitle.Top.Set(288f, 0f); _questClientTitle.Colour = new Color(43, 28, 17); rightPage.Append(_questClientTitle); rightPage.Append(CreateLine(302f)); _questClientText = new UISimpleWrappableText("", 0.7f, false, true); _questClientText.Top.Set(306f, 0f); _questClientText.Width.Set(0f, 1f); _questClientText.MinWidth.Set(0f, 1f); _questClientText.Colour = new Color(43, 28, 17); rightPage.Append(_questClientText); // rewards title _questRewardsTitle = new UISimpleWrappableText("Rewards", 0.8f); _questRewardsTitle.Top.Set(426f, 0f); _questRewardsTitle.Colour = new Color(43, 28, 17); rightPage.Append(_questRewardsTitle); rightPage.Append(CreateLine(440f)); _questRewardList = new UIGridList(); _questRewardList.Top.Set(444f, 0f); _questRewardList.Height.Set(44f, 0f); _questRewardList.Width.Set(0f, 1f); _questRewardList.ItemSize = new Vector2(42); _questRewardList.ListPadding = 4f; rightPage.Append(_questRewardList); _interactionWarningText = new UISimpleWrappableText("", 0.65f); _interactionWarningText.Top.Set(491f, 0f); _interactionWarningText.Left.Set(0f, 0f); _interactionWarningText.Height.Set(22f, 0f); _interactionWarningText.Width.Set(-106f, 1f); _interactionWarningText.Colour = new Color(43, 28, 17); //_interactionWarningText.Centered = true; rightPage.Append(_interactionWarningText); _questInteractButton = new UISelectableOutlineRectPanel(); _questInteractButton.Top.Set(491f, 0f); _questInteractButton.Left.Set(-110f, 1f); _questInteractButton.Height.Set(22f, 0f); _questInteractButton.Width.Set(110f, 0f); _questInteractButton.DrawBorder = true; _questInteractButton.SelectedFillColour = new Color(102, 86, 67) * SELECTED_OPACITY; _questInteractButton.HoverFillColour = new Color(102, 86, 67) * HOVERED_OPACITY; _questInteractButton.NormalOutlineColour = new Color(102, 86, 67) * 0.5f; _questInteractButton.SelectedOutlineColour = new Color(102, 86, 67) * 0.9f; _questInteractButton.HoverOutlineColour = new Color(102, 86, 67) * 0.7f; _questInteractButton.OnMouseDown += (UIMouseEvent evt, UIElement listeningElement) => { _questInteractButton.IsSelected = true; }; _questInteractButton.OnMouseUp += (UIMouseEvent evt, UIElement listeningElement) => { _questInteractButton.IsSelected = false; }; _questInteractButton.OnClick += (UIMouseEvent evt, UIElement listeningElement) => { if (SelectedQuest.RewardsGiven) { return; } if (SelectedQuest.IsCompleted) { QuestManager.GiveRewards(SelectedQuest); UpdateCurrentQuest(); } else if (!SelectedQuest.IsActive) { bool success = QuestManager.ActivateQuest(_selectedQuestIndex); if (success) { ChangeSection(1); // change section to active section UpdateCurrentQuest(); } else { if (QuestManager.ActiveQuests.Count >= QuestManager.MAX_QUESTS_ACTIVE) { _interactionWarningText.Text = "You cannot activate any more quests."; } } } else { if (_showingWarning) { QuestManager.DeactivateQuest(_selectedQuestIndex); _interactionWarningText.Text = ""; _showingWarning = false; return; } // show a warning _interactionWarningText.Text = "Are you sure? You will [c/910000:lose your progress]."; _showingWarning = true; } }; _questInteractText = new UISimpleWrappableText("Activate"); _questInteractText.Centered = true; _questInteractText.Top.Set(-9f, 0f); _questInteractText.Width.Set(0f, 1f); _questInteractText.Height.Set(0f, 1f); _questInteractText.Scale = 0.8f; _questInteractText.UpdateText(); _questInteractText.Colour = new Color(43, 28, 17); _questInteractButton.Append(_questInteractText); rightPage.Append(_questInteractButton); _obnoxiousTutorialGlow = new UIShaderImage(Main.blackTileTexture); _obnoxiousTutorialGlow.Top.Set(450f, 0f); _obnoxiousTutorialGlow.Left.Set(-150f, 1f); _obnoxiousTutorialGlow.Height.Set(102f, 0f); _obnoxiousTutorialGlow.Width.Set(189f, 0f); _obnoxiousTutorialGlow.Effect = SpiritMod.Instance.GetEffect("Effects/QuestShaders"); _obnoxiousTutorialGlow.Effect.Parameters["NoiseTexture"].SetValue(SpiritMod.Instance.GetTexture("Noise/noise")); _obnoxiousTutorialGlow.Effect.Parameters["NoiseWidth"].SetValue(489f); _obnoxiousTutorialGlow.Pass = _obnoxiousTutorialGlow.Effect.CurrentTechnique.Passes["GodRays"]; _obnoxiousTutorialGlow.PreDraw += () => { var e = _obnoxiousTutorialGlow.Effect; float radius = 40f; Vector2 size = new Vector2(190f, 102f); e.Parameters["GodRayRadius"].SetValue(radius); e.Parameters["GodRayRadiusTimesPi"].SetValue(radius * MathHelper.Pi); e.Parameters["GodRayMovementMultiplier"].SetValue(0.25f); e.Parameters["GodRayRadiusTimesPiOverTwo"].SetValue(radius * MathHelper.PiOver2); e.Parameters["RectSize"].SetValue(size); e.Parameters["InnerRectSize"].SetValue(new Vector2(size.X - radius * 2f, size.Y - radius * 2f)); e.Parameters["RectCenter"].SetValue(size * 0.5f); e.Parameters["Time"].SetValue((float)(Main._drawInterfaceGameTime.TotalGameTime.TotalSeconds)); e.Parameters["UVRectMinX"].SetValue(radius / size.X); e.Parameters["UVRectMinY"].SetValue(radius / size.Y); e.Parameters["UVRectMaxX"].SetValue((size.X - radius) / size.X); e.Parameters["UVRectMaxY"].SetValue((size.Y - radius) / size.Y); e.Parameters["GodRayColour"].SetValue(new Color(255, 243, 178, 255).ToVector4()); }; rightPage.Append(_obnoxiousTutorialGlow); mainWindow.Append(leftPage); mainWindow.Append(rightPage); UpdateList(); SelectQuest(_allQuestButtons[_selectedQuestIndex].MyQuest); Append(mainWindow); }
public void ActivateQuest() { questManager.ActivateQuest(this); }