public override CPState_Base OnGUI(ScreenPositioningData data) { data.GUIBackground(ScreenDat.Background, Cellphone.BackgroundSpriteBorderSize, Cellphone.BackgroundSpriteOffset); PhotographableObject obj = PhotographableObject.Instance; bool canBePhotographed = (obj != null && obj.IsPhotographable() && obj.IsInCamera(MainCamera.Instance)); if (canBePhotographed) data.GUITexture(new Vector2(0.5f, ScreenDat.DisplayTexYOffsetLerp), ScreenDat.DisplayTex); if (data.GUIButton(ScreenDat.PhotoButtonPosLerp, new Vector2(ScreenDat.PhotoButton.width, ScreenDat.PhotoButton.height), new Vector2(), Cellphone.ButtonStyle, ScreenDat.PhotoButton)) { if (canBePhotographed) { obj.OnPhotographed(); SoundAssets.Instance.PlaySound(SoundAssets.Instance.PhotoTaken); return null; } else { SoundAssets.Instance.PlaySound(SoundAssets.Instance.BadButton); } } return this; }
public override CPState_Base OnGUI(ScreenPositioningData data) { if (Cellphone.TriggerNewMessage) { Cellphone.TriggerNewMessage = false; NextMessage(); } //Render background/messages. Vector2 range = data.MaxPos - data.MinPos; data.GUIBackground(ScreenDat.Background, Cellphone.BackgroundSpriteBorderSize, Cellphone.BackgroundSpriteOffset); //Figure out spacing stuff for the scrollable view that messages are rendered in. const float extraMsgSpace = 1000.0f; Vector2 screenMsgAreaSize = range; float borderSize = screenMsgAreaSize.x * ScreenDat.MessageXBorderLerp; screenMsgAreaSize.x -= 2.0f * borderSize; screenMsgAreaSize.y *= -1.0f; screenMsgAreaSize.y -= (data.ScreenSizeScale.y * Cellphone.BackgroundSpriteOffset.y) + (screenMsgAreaSize.y * (1.0f - ScreenDat.FirstMessageYLerp)); Vector2 screenCellTopLeft = new Vector2(data.MinPos.x + borderSize, Mathf.Lerp(data.MinPos.y, data.MaxPos.y, Cellphone.BackgroundSpriteOffset.y * data.ScreenSizeScale.y)); Vector2 screenCellBottomRight = screenCellTopLeft + screenMsgAreaSize; float textHeightOffset = data.GetLerpSize(new Vector2(0.0f, ScreenDat.TextHeightOffset)).y; scrollViewPos = GUI.BeginScrollView(new Rect(screenCellTopLeft.x, screenCellTopLeft.y + textHeightOffset, screenMsgAreaSize.x, screenMsgAreaSize.y - textHeightOffset), scrollViewPos, new Rect(screenCellTopLeft.x, screenCellTopLeft.y - extraMsgSpace, screenMsgAreaSize.x + 0.1f, screenMsgAreaSize.y + extraMsgSpace), false, false); //Now render the messages into the scrollable view. float y = 1.0f - ScreenDat.FirstMessageYLerp; for (int i = CurrentMessage; i >= 0; --i) { CellPhone.MessengerScreenData.Message msg = ScreenDat.Messages[i]; Vector2 texSize = new Vector2(msg.Image.width, msg.Image.height); Vector2 texLerpSize = new Vector2(Mathf.InverseLerp(0.0f, data.MaxPos.x - data.MinPos.x, (texSize.x * data.ScreenSizeScale.x)), Mathf.InverseLerp(0.0f, data.MinPos.y - data.MaxPos.y, (texSize.y * data.ScreenSizeScale.y))); if (msg.FromPlayer) { data.GUITexture(new Vector2(1.0f - ScreenDat.MessageXBorderLerp - (0.5f * texLerpSize.x), y + (0.5f * texLerpSize.y)), msg.Image); } else { data.GUITexture(new Vector2(ScreenDat.MessageXBorderLerp + (0.5f * texLerpSize.x), y + (0.5f * texLerpSize.y)), msg.Image); } float heightLerp = Mathf.InverseLerp(0.0f, data.MinPos.y - data.MaxPos.y, (texSize.y * data.ScreenSizeScale.y)); y += ScreenDat.MessageSeparationLerp + heightLerp; } GUI.EndScrollView(); //Render player-typed text. if (CurrentMessage < ScreenDat.Messages.Length - 1 && ScreenDat.Messages[CurrentMessage + 1].MessageText.Length > 0 && (CurrentState == ScreenState.TypingReply || CurrentState == ScreenState.WaitingForSend)) { Vector2 dims = ScreenDat.MessageBoxBottomRightLerp - ScreenDat.MessageBoxTopLeftLerp; dims.y = -dims.y; dims.x *= 320.0f; dims.y *= 200.0f; data.GUILabel(ScreenDat.MessageBoxTopLeftLerp, dims, Cellphone.SmallTextStyle, ScreenDat.Messages[CurrentMessage + 1].MessageText.Substring(0, typedLetterIndex)); } //Render message button if player needs to type text. if (CurrentState == ScreenState.WaitingForSend) { if (data.GUIButton(ScreenDat.MessageButtonCenterLerp, new Vector2(ScreenDat.NewSendMessage.width, ScreenDat.NewSendMessage.height), new Vector2(), Cellphone.ButtonStyle, ScreenDat.NewSendMessage)) { SoundAssets.Instance.PlaySound(SoundAssets.Instance.TextSent); NextMessage(); } } else if (data.GUIButton(ScreenDat.MessageButtonCenterLerp, new Vector2(ScreenDat.NoSendMessage.width, ScreenDat.NoSendMessage.height), new Vector2(), Cellphone.ButtonStyle, ScreenDat.NoSendMessage)) { SoundAssets.Instance.PlaySound(SoundAssets.Instance.BadButton); } //Update screen state. switch (CurrentState) { case ScreenState.Idle: case ScreenState.WaitingForSend: break; case ScreenState.TypingReply: nextTypedLetter -= Time.deltaTime; if (nextTypedLetter <= 0.0f) { typedLetterIndex += 1; nextTypedLetter += Cellphone.MessengerScreen.PlayerTypeInterval; if (typedLetterIndex >= ScreenDat.Messages[CurrentMessage + 1].MessageText.Length) { CurrentState = ScreenState.WaitingForSend; } } break; case ScreenState.WaitingForReply: currentReplyWait -= Time.deltaTime; if (currentReplyWait <= 0.0f) { NextMessage(); } break; default: Debug.LogError("Unknown messenger screen state '" + CurrentState.ToString() + "'"); break; } return this; }