Multi-Location Quest Injection
This commit is contained in:
parent
2f98904614
commit
b0673c82fc
23 changed files with 279 additions and 105 deletions
|
|
@ -14,13 +14,20 @@ public class LocalMenu : MonoBehaviour
|
|||
public TextMeshProUGUI Output;
|
||||
public RectTransform ChoiceParent;
|
||||
public ChoicePrefab ChoicePrefab;
|
||||
|
||||
private Story _currentStory;
|
||||
|
||||
private string _currentPath;
|
||||
private LocationStory _currentLocation;
|
||||
private Story _activeStory;
|
||||
private List<GameObject> _choiceInstances = new List<GameObject>();
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_currentStory = ActionGameManager.Instance.GetStories.First();
|
||||
if (ActionGameManager.Instance.DockedEntity is OrbitalEntity orbital)
|
||||
{
|
||||
_currentLocation = orbital.Story;
|
||||
_activeStory = _currentLocation.Story;
|
||||
}
|
||||
else return;
|
||||
Continue();
|
||||
}
|
||||
|
||||
|
|
@ -28,31 +35,72 @@ public class LocalMenu : MonoBehaviour
|
|||
{
|
||||
ContinueTrigger.OnPointerClickAsObservable().Subscribe(pointerEvent =>
|
||||
{
|
||||
if (_currentStory == null) return;
|
||||
|
||||
if(_currentStory.canContinue) Continue();
|
||||
if (_activeStory == null) return;
|
||||
Continue();
|
||||
});
|
||||
}
|
||||
|
||||
void Continue()
|
||||
{
|
||||
Output.text = _currentStory.Continue();
|
||||
if (!_activeStory.state.previousPointer.isNull) _currentPath = _activeStory.state.previousPointer.path.head.name;
|
||||
if(_activeStory.canContinue) _activeStory.Continue();
|
||||
if (!_activeStory.state.previousPointer.isNull) _currentPath = _activeStory.state.previousPointer.path.head.name;
|
||||
Output.text = _activeStory.currentText;
|
||||
|
||||
foreach(var instance in _choiceInstances)
|
||||
Destroy(instance);
|
||||
_choiceInstances.Clear();
|
||||
|
||||
foreach (var choice in _currentStory.currentChoices)
|
||||
if(_activeStory.currentChoices.Any())
|
||||
{
|
||||
var choiceInstance = Instantiate(ChoicePrefab, ChoiceParent);
|
||||
choiceInstance.Label.text = choice.text;
|
||||
choiceInstance.Button.onClick.AddListener(() =>
|
||||
{
|
||||
_currentStory.ChoosePath(choice.targetPath);
|
||||
Continue();
|
||||
});
|
||||
_choiceInstances.Add(choiceInstance.gameObject);
|
||||
PresentCurrentChoices();
|
||||
}
|
||||
else if (!_activeStory.canContinue)
|
||||
{
|
||||
// There's no choices, but we also can't continue; indicates we hit an END
|
||||
if (_activeStory == _currentLocation.Story)
|
||||
{
|
||||
// END inside location-based story thread, restart the story
|
||||
_activeStory.ResetState();
|
||||
Continue();
|
||||
}
|
||||
else
|
||||
{
|
||||
// END inside quest content, switch back to location thread and present choices
|
||||
_activeStory = _currentLocation.Story;
|
||||
Continue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PresentCurrentChoices()
|
||||
{
|
||||
Debug.Log($"Current Path: \"{_currentPath}\" in {(_activeStory == _currentLocation.Story ? "Location Story" : "Quest Story")}");
|
||||
if(!string.IsNullOrEmpty(_currentPath) && _currentLocation.KnotQuests.ContainsKey(_currentPath))
|
||||
{
|
||||
foreach (var quest in _currentLocation.KnotQuests[_currentPath])
|
||||
{
|
||||
if (quest.Story == _activeStory) continue; // Don't repeat choices for active injected branch
|
||||
|
||||
quest.Story.ChoosePathString(_currentPath);
|
||||
quest.Story.ContinueMaximally();
|
||||
foreach (var choice in quest.Story.currentChoices) PresentChoice(quest.Story, choice);
|
||||
}
|
||||
}
|
||||
foreach (var choice in _activeStory.currentChoices) PresentChoice(_activeStory, choice);
|
||||
}
|
||||
|
||||
void PresentChoice(Story story, Choice choice)
|
||||
{
|
||||
var choiceInstance = Instantiate(ChoicePrefab, ChoiceParent);
|
||||
choiceInstance.Label.text = choice.text;
|
||||
choiceInstance.Button.onClick.AddListener(() =>
|
||||
{
|
||||
_activeStory = story;
|
||||
_activeStory.ChoosePath(choice.targetPath);
|
||||
Continue();
|
||||
});
|
||||
_choiceInstances.Add(choiceInstance.gameObject);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ public class MenuPanel : MonoBehaviour
|
|||
{
|
||||
tabButton.gameObject.SetActive(!tabButton.RequireDock || GameManager.DockedEntity != null);
|
||||
}
|
||||
_tabs[MenuTab.Local].gameObject.SetActive((GameManager.DockedEntity as OrbitalEntity)?.Story!=null);
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
|
|
|
|||
Loading…
Reference in a new issue