/// <summary> /// Update /// </summary> public override void Update() { base.Update(); ConcurrentBag <TextSprite> text_sprite_bag = new ConcurrentBag <TextSprite>(); ForEachComponent <TextSprite>((text_sprite) => { text_sprite_bag.Add(text_sprite); }); TextSprite[] text_sprites = text_sprite_bag.ToArray(); while (sprites.Count > text_sprites.Length) { int index = sprites.Count - 1; window.RemoveControl(sprites[index]); sprites.RemoveAt(index); } for (int i = 0; i < text_sprites.Length; i++) { ColoredTextField sprite; TextSprite text_sprite = text_sprites[i]; RectTransform rectangle_transform = text_sprite.GetComponent <RectTransform>(); if (i < sprites.Count) { sprite = sprites[i]; } else { if (rectangle_transform == null) { sprite = window.AddControl <ColoredTextField>(RectInt.zero); } else { sprite = window.AddControl <ColoredTextField>(rectangle_transform.Position - CameraPosition, rectangle_transform.Size); } sprite.AllowTransparency = true; sprites.Add(sprite); } if (rectangle_transform == null) { sprite.IsVisible = false; } else { sprite.Text = text_sprite.Text; sprite.Position = rectangle_transform.Position - CameraPosition; sprite.Size = rectangle_transform.Size; sprite.IsVisible = true; } } }
private void StartGame(Story story) { var progressBar = Elements.OfType <ProgressBar>().Single(c => c.Name == "Progress"); // LOW: Could make static class to check the statemanager's states for MenuState and return progress bar instead of passing as param IGameDataInitializer initializer; try { switch (story) { case Story.Custom: initializer = new CustomStoryInitializer(progressBar); break; case Story.QuantumGateOne: initializer = new QuantumGateInitializer(progressBar); break; case Story.QuantumGateTwo: initializer = new QuantumGateTwoInitializer(progressBar); break; default: throw new ArgumentOutOfRangeException(nameof(story), story, null); } Window.ClearControls(); Window.AddControl(Elements.Single(c => c.Name == "Progress")); Window.AddControl(Elements.Single(c => c.Name == "ProgressStatus")); initializer.VerifyGameData(); } catch (OperationCanceledException ex) when(ex.Message.Contains("Cancelled locating game data")) { const string errorMessage = "Cancelled locating game data"; //throw new FailedToInitializeStateException(errorMessage, ex); MessageBox.Show(errorMessage); return; } catch (Exception ex) when(ex is InvalidGameDataException || ex is FileNotFoundException) { var errorMessage = ""; var exception = ex as InvalidGameDataException; if (exception != null) { errorMessage = $"Could not start {story}, {exception.BadFiles.Count()} bad files"; } if (ex is FileNotFoundException) { errorMessage = $"Could not start {story}, are you sure you have the right directory?"; } //throw new FailedToInitializeStateException(errorMessage, ex); //HIGH: Maybe send this to a label in the menu instead of blowing up? MessageBox.Show(errorMessage); return; } Window.ClearControls(); StateManager.LoadState(new GameState(Window, initializer.StoryData)); }
public virtual void Initialize() { Window.ClearControls(); foreach (var control in Elements) { Window.AddControl(control); } IsInitializationComplete = true; }
/// <summary> /// Constructor /// </summary> /// <param name="window">Window</param> public NightSkyRenderer(Window window) { this.window = window; background = window.AddControl <ColoredTextField>(RectInt.zero); background.AllowTransparency = true; lastHorizontalPosition = HorizontalPosition; lastHorizonStart = HorizonStart; lastWindowSize = window.Size; UpdateNightSky(); }
static void Main(string[] args) { Window window = new Window(); canvas = window.AddControl <Canvas>(Vector2Int.zero, Vector2Int.zero); window.OnKeyPressed += KeyPressedEvent; window.OnWindowResized += WindowResizedEvent; Console.CursorVisible = false; while (keepRunning) { window.Refresh(); BuildBuffer(); } Console.CursorVisible = true; }
/// <summary> /// Constructor /// </summary> /// <param name="window">Window</param> public GroundRenderer(Window window) { this.window = window; background = window.AddControl <ColoredTextField>(0, 0, window.Width, (int)GroundHeight); background.TextAlignment = ETextAlignment.BottomLeft; lastPatternBodyLength = PatternBodyLength; lastPatternLineLength = PatternLineLength; lastTopGroundColor = TopGroundColor; lastBottomGroundColor = BottomGroundColor; lastTopLineColor = TopLineColor; lastBottomLineColor = BottomLineColor; lastGroundHeight = GroundHeight; lastHorizontalPosition = HorizontalPosition; lastWindowWidth = window.Width; UpdateGroundPattern(); }
// HIGH: Game state should not care about these, if a stage needs them, it will grab them and register as needed public void InitializeControls() { var player = StaticControls.GetControlByName("MainVideoPlayer") as AxVLCPlugin2; if (player == null) { throw new NullReferenceException("MainVideoPlayer from static controls is null."); } Window.AddControl(player); // NOTE: This sets the parent and must be called before creating the control player.CreateControl(); // TODO: This is a static object and should be initialized more reliably player.audio.mute = true; player.Visible = true; player.AutoPlay = false; player.Toolbar = false; player.MediaPlayerPlaying += MainVideoPlayer_MediaPlayerPlaying; player.MediaPlayerEndReached += MainVideoPlayer_MediaPlayerEndReached; var scenebox = StaticControls.GetControlByName("SceneBox"); var topNavigation = StaticControls.GetControlByName("TopNavigation"); var leftNavigation = StaticControls.GetControlByName("LeftNavigation"); var rightNavigation = StaticControls.GetControlByName("RightNavigation"); var bottomNavigation = StaticControls.GetControlByName("BottomNavigation"); topNavigation.Parent = scenebox; leftNavigation.Parent = scenebox; rightNavigation.Parent = scenebox; bottomNavigation.Parent = scenebox; Window.AddControl(scenebox); Window.AddControl(topNavigation); Window.AddControl(leftNavigation); Window.AddControl(rightNavigation); Window.AddControl(bottomNavigation); ResizeControlToParent(player); ResizeControlToParent(scenebox); Window.Resize += WindowOnResize; foreach (var control in StaticControls.StoryNavigationControls) { control.Visible = false; } }
protected override void OnGUI() { base.OnGUI(); var rect = Rectangle; var arrow = new Rect(rect.x + rect.width / 2 - 7, rect.y + rect.height, 15, 15); GUI.DrawTexture(arrow, Assets["arrowdown"]); if (Input.ButtonReleased(Editor.EMouseButton.Left)) { if (arrow.Contains(Input.MousePosition)) { if (LineOut2 != null) { LineOut2.Remove(); LineOut2 = null; } LineOut2 = ConditionalLine.HookLineOut2(this); Window.AddControl(LineOut2); Input.Use(); } } else if (Input.ButtonReleased(Editor.EMouseButton.Right)) { if (arrow.Contains(Input.MousePosition)) { if (LineOut2 != null) { LineOut2.Remove(); LineOut2 = null; } Input.Use(); } } }
public SimpleConsoleApplication AddControlToWindow(IControl control) { theWindow.AddControl(control); return(this); }
protected override void OnGUI() { var rect = Rectangle; GUI.Box(rect, "", ExtendedGUI.DefaultWindowStyle); if (Progress > 0 && ErrorType == ErrorType.None) { GUI.DrawTexture(new Rect(rect.x, rect.y, rect.width * Progress, 15), Assets["progressBar"]); } Texture2D errorTex = null; switch (ErrorType) { case ErrorType.Execute: errorTex = Assets["genericException"]; break; case ErrorType.Arugment: errorTex = Assets["argumentException"]; break; case ErrorType.PreExecute: errorTex = Assets["genericException"]; break; case ErrorType.PostExecute: errorTex = Assets["genericException"]; break; } if (errorTex) { GUI.DrawTexture(new Rect(rect.x, rect.y, rect.width, 15), errorTex); } var topRect = new Rect(rect.x, rect.y, rect.width, 16); GUI.Label(topRect, name, headerStyle); if (Input.ButtonReleased(EMouseButton.Left) && topRect.Contains(Input.MousePosition)) { var n = DateTime.Now.Ticks; var t = n - previousTicks; if (t <= 5000000) { (Window as AutomatronEditor).LookAtAutomationSmooth(this); n = 0; } previousTicks = n; } if (!Globals.IsError && Input.ButtonReleased(EMouseButton.Right) && topRect.Contains(Input.MousePosition)) { var gm = GenericMenuBuilder.CreateMenu(); gm.AddItem("Remove Incoming Lines", false, RemoveIncomingLines); gm.AddItem("Remove Outgoing Lines", false, RemoveOutgoingLines); gm.ShowAsContext(); } if (showCloseButton && !Globals.IsExecuting) { var cRect = new Rect(rect.x + rect.width - 14, rect.y + 1, 13, 13); if (cRect.Contains(Input.MousePosition)) { GUI.DrawTexture(cRect, Assets["crossActive"]); if (Input.ButtonReleased(EMouseButton.Left)) { Remove(); Input.Use(); } } else { GUI.DrawTexture(cRect, Assets["crossNormal"]); } } var lArrow = new Rect(rect.x - 15, rect.y, 15, 15); var rArrow = new Rect(rect.x + rect.width, rect.y, 15, 15); if (showInArrow) { GUI.DrawTexture(lArrow, Assets["arrowleft"]); if (!Globals.IsExecuting) { if (Input.ButtonReleased(EMouseButton.Left)) { if (lArrow.Contains(Input.MousePosition)) { var line = AutomationLine.HookLineIn(this); if (LinesIn.Contains(line)) { LinesIn.Remove(line); } LinesIn.Add(line); Window.AddControl(line); Input.Use(); } } else if (Input.ButtonReleased(EMouseButton.Right)) { if (lArrow.Contains(Input.MousePosition)) { if (LinesIn.Count > 0) { for (int i = LinesIn.Count - 1; i >= 0; i--) { LinesIn[i].Remove(); } } Input.Use(); } } } } if (showOutArrow) { GUI.DrawTexture(rArrow, Assets["arrowright"]); if (!Globals.IsExecuting) { if (Input.ButtonReleased(EMouseButton.Left)) { if (rArrow.Contains(Input.MousePosition)) { if (LineOut != null) { LineOut.Remove(); LineOut = null; } LineOut = AutomationLine.HookLineOut(this); Window.AddControl(LineOut); Input.Use(); } } else if (Input.ButtonReleased(EMouseButton.Right)) { if (rArrow.Contains(Input.MousePosition)) { if (LineOut != null) { LineOut.Remove(); LineOut = null; } Input.Use(); } } } } if (!Globals.IsExecuting) { if (Input.ButtonPressed(EMouseButton.Left)) { dragger = null; switch (SortingOrder) { case ESortingOrder.Automation: if (rect.Contains(Input.MousePosition)) { SortingOrder = ESortingOrder.AutomationSelected; } break; case ESortingOrder.AutomationSelected: if (!rect.Contains(Input.MousePosition)) { SortingOrder = ESortingOrder.Automation; } break; } } if (Input.ButtonDown(EMouseButton.Left)) { if (dragger == null) { var dragRect = new Rect(rect.x, rect.y, rect.width - 16, 16); if (dragRect.Contains(Input.MousePosition)) { dragger = this; GUIUtility.keyboardControl = 0; } } } if (Input.ButtonReleased(EMouseButton.Left)) { dragger = null; } if (dragger == this) { Position += Input.DragDelta; } } var fieldRect = new Rect(rect.x, rect.y + 18, rect.width, rect.height); foreach (var item in fields) { var height = item.GetHeight(); fieldRect.height = height; item.OnGUI(fieldRect); fieldRect.y += height; } if (Input.ButtonReleased(EMouseButton.Right) && rect.Contains(Input.MousePosition)) { Input.Use(); } if (Input.ButtonDown(EMouseButton.Middle) && rect.Contains(Input.MousePosition)) { Input.Use(); } UpdateSize(); }
private void OpenList() { if (0 == this.items.Count) { return; } Window window = this.Window.Desktop.NewTempWindow(""); int cx = 0; int cy = window.TopOffset; for (Control control = this; control != null; control = control.Parent) { cx += control.Bounds.X; cy += control.Bounds.Y; } ScrollPanel scrollPanel = window.CreateControl <ScrollPanel>(); scrollPanel.Border = BorderStyle.Flat; scrollPanel.BackColor = Colors.White; scrollPanel.FillParent = true; window.AddControl(scrollPanel); ListBox listBox = window.CreateControl <ListBox>(); listBox.ListStyle = ListStyle.Details; listBox.Border = BorderStyle.None; listBox.Name = "listBoxItems"; scrollPanel.AddControl(listBox); bool hasIcon = false; foreach (ComboBoxItem item in this.items) { if (((null != item.Icon) && (item.Icon.Length > 0)) || (null != item.image)) { hasIcon = true; break; } } foreach (ComboBoxItem item in this.items) { ListItem listItem = window.CreateControl <ListItem>(); listItem.ListStyle = ListStyle.Details; listItem.Text = item.Text; listItem.Tag = item; /* if (null != item.image) * { * listItem.IconPicture = item.image; * } * else */ { listItem.Icon = item.Icon; } listItem.Clicked += this.ItemClicked; listItem.BackColor = Colors.None; // listItem.SetFont(this.m_strFontName, this.m_nFontSize, this.m_bFontBold, this.m_bFontItalic); listItem.NeedTranslation = this.NeedTranslation; if (false == hasIcon) { listItem.TextOffset.X = 0; listItem.TextOffset.Y = 0; } listBox.AddControl(listItem); } int maxHeight = this.items.Count * (12 + this.FontInfo.Size + 1); if (maxHeight > 300) { maxHeight = 300; listBox.Bounds = new Rectangle(1, 1, this.Bounds.Width - 4 - scrollPanel.horizontalScrollBar.ButtonSize, 0); } else { listBox.Bounds = new Rectangle(0, 0, this.Bounds.Width - 4, 0); } listBox.BackColor = Colors.None; listBox.AutoSize = true; window.Bounds = new Rectangle(cx, cy + this.Bounds.Height, this.Bounds.Width, maxHeight + 3); window.Border = BorderStyle.None; window.BackColor = Colors.None; window.Moveable = false; window.Sizeable = true; window.Closing += this.WindowClosing; this.listWindow = window; }