/* Given the reading type sets a reading time during the contents of the currently selected scroll * will be displayed together with a readin channel bar to indicate the time passed. * Needs to be called every frame to update read channel bar and to determine when channel time has ended. */ public void ReadSelected(string type) { float readDuration; if (type == "Read") { readDuration = readingTime; } else if (type == "Chant") { readDuration = chantingTime; } else { return; } if (currentNrScrolls == 0) { return; // No scroll to read } if (!isReading) { Scroll.ScrollInfo info = scrolls[selectedScroll]; //print("Scroll: Color " + info.color + " Content " + info.content); scrollDisplay.SetActive(true); string displayText = "Symptoms:\n" + info.content; scrollDisplay.transform.Find("Scroll Content").GetComponent <Text>().text = displayText; readChannelBarFill.SetActive(true); readChannelBarFill.GetComponent <RectTransform>().sizeDelta = new Vector2(0, readBarHeight); isReading = true; readStartTime = Time.time; } else { float deltaTime = Time.time - readStartTime; float newWidth = (deltaTime / readDuration) * readBarWidth; readChannelBarFill.transform.parent.gameObject.SetActive(true); readChannelBarFill.GetComponent <RectTransform>().sizeDelta = new Vector2(newWidth, readBarHeight); if (deltaTime > readDuration) { isReading = false; scrollDisplay.SetActive(false); readChannelBarFill.transform.parent.gameObject.SetActive(false); if (!hasReadFirst) { string[] messages = { " 'THIS SEEMS TO BE SOME KIND OF CHANT...' " }; infoBox.DisplayInfo(messages); hasReadFirst = true; } } } }
/* Adds the scroll ScrollInfo to Inventory's array of ScrollInfo. * Special cases occur when the number of aquired scrolls reach 1 and 2 to display * messages. The newest added scroll is automatically selected. * Selects the correct color sprite according to the given ScrollInfo. */ public void AddScroll(Scroll.ScrollInfo scroll) { scrolls[currentNrScrolls] = scroll; currentNrScrolls++; selectedScroll = currentNrScrolls - 1; if (currentNrScrolls == 1) { // Scroll sprite number 1 does not need to be positioned. orgScrollBase.SetActive(true); orgScrollBase.transform.Find("Scroll Color").GetComponent <Image>().sprite = scrollColors[(int)scroll.color]; scrollSelect.GetComponent <RectTransform>().anchoredPosition = orgScrollBase.GetComponent <RectTransform>().anchoredPosition; scrollSelect.SetActive(true); if (player.hintInfo) { //infoBox.gameObject.SetActive(true); string[] msg = { "Press 'R' to read scroll.\nYou can only read with light on." }; infoBox.DisplayInfo(msg); } } else { if (currentNrScrolls == 2 && player.hintInfo) { string[] msg = { "Use 'Tab' to browse scrolls" }; infoBox.DisplayInfo(msg); } // Position new scroll sprite GameObject newScroll = Instantiate(orgScrollBase) as GameObject; newScroll.transform.Find("Scroll Color").GetComponent <Image>().sprite = scrollColors[(int)scroll.color]; newScroll.transform.SetParent(this.transform.Find("Scroll Holder").transform); newScroll.GetComponent <RectTransform>().anchorMax = orgScrollBase.GetComponent <RectTransform>().anchorMax; newScroll.GetComponent <RectTransform>().anchorMin = orgScrollBase.GetComponent <RectTransform>().anchorMin; scrollIcons[currentNrScrolls - 1] = newScroll; if (currentNrScrolls == 5) { scrollVertOffset = -scrollVertOffset; } newScroll.GetComponent <RectTransform>().anchoredPosition = new Vector3( (currentNrScrolls % 2 == 0) ? -scrollHoriOffset : scrollHoriOffset, currentNrScrolls == 3 || currentNrScrolls == 4 ? 0 : scrollVertOffset, 0); newScroll.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1); scrollSelect.GetComponent <RectTransform>().anchoredPosition = newScroll.GetComponent <RectTransform>().anchoredPosition; newScroll.SetActive(true); } if (player.lantern.isLit) { ReadSelected("Read"); } }
public void CreateScrolls(List <string> _symptoms) { List <string> symptoms = new List <string>(_symptoms); // So we can destructively remove items Vector3[] occupiedPositions = new Vector3[Inventory.MAX_NR_SCROLLS]; int content; int color; Random.InitState(System.DateTime.Now.Millisecond); int i = 0; int whileSaver = 0; // Keep looping until all scrolls haven succesfully has been positioned // (or worse case we fail to do this under 100 attempts, // NB: This scenario is currently unhandled!) while (i < Inventory.MAX_NR_SCROLLS && whileSaver < 100) { whileSaver++; if (whileSaver == 100) { print("Could not place all scrolls"); // For debug, should not happen! But number is adjusted to the current number } // of scroll positions and max number scrolls. Scroll.ScrollInfo info = new Scroll.ScrollInfo(); // Set a random position int areaID = Random.Range(0, worldMan.numberOfWorldAreas); WorldArea worldArea = worldMan.worldAreas[areaID]; if (worldArea.nrScrollPositions == 0) { continue; } GameObject rndPosition = worldArea.scrollPositions[Random.Range(0, worldArea.nrScrollPositions)]; // If position has already been assigned, go back and choose a new one if (System.Array.Exists <Vector3>(occupiedPositions, element => element == rndPosition.transform.position)) { continue; } occupiedPositions[i] = rndPosition.transform.position; // Add random content and random color content = Random.Range(0, Inventory.MAX_NR_SCROLLS - i); color = Random.Range(0, Inventory.MAX_NR_SCROLLS - i); info.content = symptoms[content]; symptoms.RemoveAt(content); info.color = colors[color]; colors.RemoveAt(color); // Add properties to new scroll and add it to the correct WorldArea's list of Interactable:s GameObject newScrollGameObj = Instantiate(orgScroll) as GameObject; Scroll newScroll = newScrollGameObj.GetComponent <Scroll>(); newScroll.info = info; newScroll.transform.position = rndPosition.transform.position; newScroll.transform.rotation = rndPosition.transform.rotation; newScroll.gameObject.transform.SetParent(transform); newScroll.gameObject.SetActive(true); newScroll.gameObject.layer = InteractableManager.INTERACTABLE_LAYER; worldMan.worldAreas[areaID].interactables.AddLast(newScroll); i++; //print("Created scroll " + newScroll + " " + newScroll.info.content + " " + // newScroll.info.color + " " + newScroll.transform.position); } }