//Set the info given by the CharacterSelectionTable public void SetInfo(LevelCharactersInfo.Character info) { myInfo = info; if (info != null) { Enable_CharacterSlot(); } else { Set_EmptySprite(); } }
//Character has been confirmed, display character sprite public void SetSprite(LevelCharactersInfo.Character info) { charInfo = info; myIcon.spriteName = charInfo.npcTexture; myIcon.enabled = true; myStretch.initialSize.Set(myIcon.GetAtlasSprite().inner.width, myIcon.GetAtlasSprite().inner.height); nameLabel.text = charInfo.npcName; nameLabel.enabled = true; myBorder.enabled = true; cancelSprite.enabled = true; backgroundLabel.enabled = false; myBackground.spriteName = backgroundSpriteName_Blank; }
//Creates an row X column of slots using the given characters public void CreateTable(LevelCharactersInfo characters) { int characterIndex = 0; Bounds b = new Bounds(); List<LevelCharactersInfo.Character> activeCharacterList = characters.levelSpecificCharacters; GenerateSlots(); //Deleting all assigned toys to generate random toys MainDatabase.Instance.DeleteAllAssignedToy(); for (int counter = 0, length = slots.Count; counter < length; ++counter) { if (characterIndex < activeCharacterList.Count) { slots [counter].gameObject.name = activeCharacterList [characterIndex].npcName; slots [counter].SetInfo(activeCharacterList [characterIndex]); slots [counter].SetExclusiveCharacterBackground(); slots [counter].SetConfirmButton(confirmButton); Debug.Log(activeCharacterList [characterIndex].npcName); //Assigning a random toy DBToyInfo newToy = MainDatabase.Instance.GetRandomToy(ApplicationState.Instance.userID); activeCharacterList [characterIndex].toyInfo = newToy; int npcID = MainDatabase.Instance.getIDs("Select NPCID from NPC where NPCName ='" +activeCharacterList [characterIndex].npcName+ "';"); MainDatabase.Instance.InsertAssignedToy(ApplicationState.Instance.userID, newToy.ToyID, newToy.ToyName ,npcID); characterIndex++; } else { slots [counter].Set_EmptySprite(); slots [counter].gameObject.name = "Empty_Slot"; } if (counter == (maxRows - 1)) { characterIndex = 0; activeCharacterList = characters.otherCharacters; } }//endy }
//Sets/Gets the character's names and respective sprites to be used for the slots public void SetCharactersList(LevelCharactersInfo characters) { List<string> charNames = new List<string>(); List<string> charSprites = new List<string>(); List<int> charIndexPosition = new List<int>(); charInfoList = new List<CharacterInformation>(); //Use the cafeteria list if (customLevel.levelSelect == 1) { for (int i = 0; i < cafeteriaCharactersNames.Count; i++) { charNames.Add(cafeteriaCharactersNames [i]); charSprites.Add(cafeteriaCharactersSprites [i]); charIndexPosition.Add(cafeteriaExclusivePositions [i]); } } //Another level list else { charNames = cafeteriaCharactersNames; charSprites = cafeteriaCharactersSprites; } //Add the names and sprites of the characters neutral of the level for (int i = 0; i < neutralCharactersNames.Count; i++) { charNames.Add(neutralCharactersNames [i]); charSprites.Add(neutralCharactersSprites [i]); } //Fills the character info to be given to the slots for (int i = 0; i < charNames.Count; i++) { CharacterInformation charInfo = new CharacterInformation(); charInfo.name = charNames [i]; charInfo.spriteName = charSprites [i]; if (i < charIndexPosition.Count) charInfo.characterIndexPosition = charIndexPosition [i]; else charInfo.characterIndexPosition = i + 1; charInfoList.Add(charInfo); } }
//Slot has been selected, display character and corresponding info (from server) public void Set_CurrentCharacter(LevelCharactersInfo.Character info) { charInfo = info; currentCharacterSprite.enabled = true; currentCharacterSprite.spriteName = charInfo.npcTexture; characterNameLabel.text = charInfo.npcName; UIStretch stretch = currentCharacterSprite.gameObject.GetComponent<UIStretch>(); stretch.initialSize.Set(currentCharacterSprite.GetAtlasSprite().inner.width, currentCharacterSprite.GetAtlasSprite().inner.height); characterBubbleSprite.spriteName = characterBubbleBlankSpriteName; descriptionBubbleSprite.spriteName = descriptionCategoriesSprite; #if !UNITY_WEBPLAYER if (charInfo.npcId != -1) { if (ApplicationState.Instance.previousLevel == ApplicationState.LevelNames.MAIN_MENU) { DBNPCMiniGameInfo npcInfo = MainDatabase.Instance.getNPCInfo(charInfo.npcId); characterLessonLabel.text = MainDatabase.Instance.getCategory(charInfo.npcId); characterStarLabel.text = npcInfo.Stars.ToString(); characterMinigameNameLabel.text = npcInfo.MiniGame; characterMinigameDescriptionLabel.text = npcInfo.MiniGameDescription; List<float> scorePercentages = MainDatabase.Instance.calTotalPercentage(charInfo.npcId, ApplicationState.Instance.userID); if (scorePercentages != null) { for (int i = 0; i < scoreLabelsList.Count; i++) { if (float.IsNaN(scorePercentages [i])) { scoreLabelsList [i].text = "--"; scoreLabelsList [i].color = Color.black; } else scoreLabelsList [i].text = Mathf.Round(scorePercentages [i]).ToString() + "%"; if (scorePercentages [i] < 50) scoreLabelsList [i].color = Color.red; else if (scorePercentages [i] < 70) scoreLabelsList [i].color = new Color(255, 193, 0); else if (scorePercentages [i] <= 100f) scoreLabelsList [i].color = Color.green; else { scoreLabelsList [i].color = Color.black; } } } else { Debug.LogWarning("No aggregated data found"); for (int i = 0; i < scoreLabelsList.Count; i++) { scoreLabelsList [i].text = "--"; scoreLabelsList [i].color = Color.black; } } } else { descriptionBubbleSprite.spriteName = descriptionCategoriesSpriteChild; descriptionToySprite.spriteName = charInfo.toyInfo.Filename; descriptionToyStretch.initialSize = new Vector2 (descriptionToySprite.mInner.width, descriptionToySprite.mInner.height); float r = (float) charInfo.toyInfo.ToyColorR/255; float g = (float) charInfo.toyInfo.ToyColorG/255; float b = (float) charInfo.toyInfo.ToyColorB/255; Color col = new Color(r, g, b, 1); descriptionToySprite.color = col; descriptionToySprite.enabled = true; } } #endif //red: 0 - 49 //yellow 50 - 74 //green 75 - 100 if (occupiedSlots < availableSlots.Count) { gameObject.SetActive(true); setActiveWithButtonSound(); } }