/// <summary> /// Draws and returns the value of a GUI.Button. /// </summary> /// <param name="pos">The position of the button as an interpolant between 0 and 1.</param> /// <returns>Whether the button was pressed.</returns> private bool MainScreenButton(Vector2 posLerp, Texture2D tex, ScreenPositioningData data) { return data.GUIButton(posLerp, Cellphone.MainScreen.ButtonSize, new Vector2(Cellphone.MainScreen.ScreenBorder.x * data.ScreenSizeScale.x, Cellphone.MainScreen.ScreenBorder.y * data.ScreenSizeScale.y), Cellphone.ButtonStyle, tex); }
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; }
void OnGUI() { //Calculate positioning info and draw the inventory background. Texture2D texToUse = (IsSelected ? SelectedTex : DeSelectedTex); if (!IsSelected) SetSelectedCollider(); ScreenPositioningData data = new ScreenPositioningData(MyCollider); if (!IsSelected) SetDeSelectedCollider(); Vector2 center = (data.MinPos + data.MaxPos) * 0.5f; Vector2 texSize = new Vector2(data.ScreenSizeScale.x * texToUse.width, data.ScreenSizeScale.y * texToUse.height); GUI.DrawTexture(new Rect(center.x - (texSize.x * 0.5f), center.y - (texSize.y * 0.5f), texSize.x, texSize.y), texToUse, ScaleMode.StretchToFill, true); Vector2 objTexSizes = data.GetLerpSize(new Vector2(KeyTex.width, KeyTex.height)), halfObjTexSizes = 0.5f * objTexSizes; Vector2 displaySpaceMin = DisplaySpaceMinLerp + halfObjTexSizes, displaySpaceMax = DisplaySpaceMaxLerp - halfObjTexSizes; float displaySpaceMidpointY = (displaySpaceMin.y + displaySpaceMax.y) * 0.5f; if (IsSelected) { if (HasObjects[InventoryObjects.MutilatedRat]) { if (data.GUIButton(displaySpaceMin, new Vector2(KeyTex.width, KeyTex.height), new Vector2(), CellPhone.Instance.ButtonStyle, MutilatedRatTex)) { CurrentlySelected = InventoryObjects.MutilatedRat; } } if (HasObjects[InventoryObjects.Key]) { if (data.GUIButton(new Vector2(displaySpaceMax.x, displaySpaceMin.y), new Vector2(KeyTex.width, KeyTex.height), new Vector2(), CellPhone.Instance.ButtonStyle, KeyTex)) { CurrentlySelected = InventoryObjects.Key; } } if (HasObjects[InventoryObjects.Necklace]) { if (data.GUIButton(new Vector2(displaySpaceMin.x, displaySpaceMidpointY), new Vector2(KeyTex.width, KeyTex.height), new Vector2(), CellPhone.Instance.ButtonStyle, NecklaceTex)) { CurrentlySelected = InventoryObjects.Necklace; } } if (HasObjects[InventoryObjects.WheelValve]) { if (data.GUIButton(new Vector2(displaySpaceMax.x, displaySpaceMidpointY), new Vector2(KeyTex.width, KeyTex.height), new Vector2(), CellPhone.Instance.ButtonStyle, WheelValveTex)) { CurrentlySelected = InventoryObjects.WheelValve; } } } if (CurrentlySelected.HasValue) { Vector2 mousePos = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y), mTexSize = 0.5f * new Vector2(KeyTex.width * data.ScreenSizeScale.x, KeyTex.height * data.ScreenSizeScale.y); GUI.DrawTexture(new Rect(mousePos.x - mTexSize.x, mousePos.y - mTexSize.y, KeyTex.width * data.ScreenSizeScale.x, KeyTex.height * data.ScreenSizeScale.y), CurrentlySelectedTex); } }