using Terraria.ModLoader;
using Terraria;
using Terraria.GameContent.Generation;
using System.Collections.Generic;
using Terraria.World.Generation;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria.GameContent.UI.Elements;
using Terraria.UI;
namespace SkyDiveExperiment
{
public class SkyDiveExperiment : Mod
{
public SkyDiveExperiment()
{
Properties = new ModProperties()
{
Autoload = true, // We need Autoload to be true so our ModWorld class below will be loaded.
};
}
}
internal class InterruptModWorld : ModWorld
{
internal static bool continueWorldGen = false;
internal static bool skydive;
public override void PostWorldGen()
{
Main.MenuUI.SetState(new ExampleUI());
while (true)
{
if (continueWorldGen)
{
if (skydive)
{
Main.spawnTileY = 100; // Do things based on choice
}
Main.MenuUI.GoBack();
continueWorldGen = false; // reset for next world gen
break;
}
}
}
}
class ExampleUI : UIState
{
public UIPanel coinCounterPanel;
private UIText _buttonLabel;
public override void OnInitialize()
{
coinCounterPanel = new UIPanel();
coinCounterPanel.SetPadding(0);
coinCounterPanel.HAlign = .5f;
coinCounterPanel.VAlign = .5f;
coinCounterPanel.Width.Set(300f, 0f);
coinCounterPanel.Height.Set(100f, 0f);
coinCounterPanel.BackgroundColor = new Color(73, 94, 171);
UITextPanel text = new UITextPanel("Would you like to go Sky diving?");
text.HAlign = 0.5f;
text.Top.Set(5f, 0f);
coinCounterPanel.Append(text);
_buttonLabel = new UIText("", 1f, false);
_buttonLabel.VAlign = .8f;
_buttonLabel.HAlign = .5f;
coinCounterPanel.Append(_buttonLabel);
Texture2D buttonPlayTexture = ModLoader.GetTexture("Terraria/UI/ButtonPlay");
UIImageButton playButton = new UIImageButton(buttonPlayTexture);
playButton.Width.Set(22, 0f);
playButton.Height.Set(22, 0f);
playButton.VAlign = .8f;
playButton.HAlign = .25f;
playButton.OnClick += new MouseEvent(PlayButtonClicked);
playButton.OnMouseOver += new UIElement.MouseEvent(PlayMouseOver);
playButton.OnMouseOut += new UIElement.MouseEvent(ButtonMouseOut);
coinCounterPanel.Append(playButton);
Texture2D buttonDeleteTexture = ModLoader.GetTexture("Terraria/UI/ButtonDelete");
UIImageButton closeButton = new UIImageButton(buttonDeleteTexture);
closeButton.Width.Set(22, 0f);
closeButton.Height.Set(22, 0f);
closeButton.VAlign = .8f;
closeButton.HAlign = .75f;
closeButton.OnClick += new MouseEvent(CloseButtonClicked);
closeButton.OnMouseOver += new UIElement.MouseEvent(DeleteMouseOver);
closeButton.OnMouseOut += new UIElement.MouseEvent(ButtonMouseOut);
coinCounterPanel.Append(closeButton);
base.Append(coinCounterPanel);
}
private void PlayButtonClicked(UIMouseEvent evt, UIElement listeningElement)
{
Main.PlaySound(10, -1, -1, 1);
InterruptModWorld.skydive = true;
InterruptModWorld.continueWorldGen = true;
}
private void CloseButtonClicked(UIMouseEvent evt, UIElement listeningElement)
{
Main.PlaySound(10, -1, -1, 1);
InterruptModWorld.skydive = false;
InterruptModWorld.continueWorldGen = true;
}
private void PlayMouseOver(UIMouseEvent evt, UIElement listeningElement)
{
this._buttonLabel.SetText("YEAH!");
}
private void DeleteMouseOver(UIMouseEvent evt, UIElement listeningElement)
{
this._buttonLabel.SetText("No way!");
}
private void ButtonMouseOut(UIMouseEvent evt, UIElement listeningElement)
{
this._buttonLabel.SetText("");
}
}
}