public Game() { controlPanel = new MyTableLayoutPanel(3, 1, "AAS300", "A"); { { imageFeedBack = new MyCheckBox("Image Feed Back"); imageFeedBack.Checked = true; controlPanel.AddControl(imageFeedBack, 0, 0); } { showImageFeedBack = new MyCheckBox("Show Image Feed Back"); showImageFeedBack.Checked = false; showImageFeedBack.CheckedChanged += ShowImageFeedBack_CheckedChanged; controlPanel.AddControl(showImageFeedBack, 0, 0); } { Panel pnl = new Panel(); { pnl.Dock = DockStyle.Fill; pnl.AutoScroll = true; { generalSettings = new MyInputField(); generalSettings.Dock = DockStyle.Top; generalSettings.AddField("Image Feed Back Width", imageFeedBackSize.Width.ToString()).TextChanged += (o, e) => { try { imageFeedBackSize.Width = int.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("Image Feed Back Height", imageFeedBackSize.Height.ToString()).TextChanged += (o, e) => { try { imageFeedBackSize.Height = int.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("Port", SocketHandler.port.ToString()).TextChanged += (o, e) => { try { SocketHandler.port = int.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("darryMode", darryMode.ToString()).TextChanged += (o, e) => { try { darryMode = bool.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("max_upward_speed", max_upward_speed.ToString()).TextChanged += (o, e) => { try { max_upward_speed = double.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("alpha", alpha.ToString()).TextChanged += (o, e) => { try { alpha = double.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("重利", gravity.ToString()).TextChanged += (o, e) => { try { gravity = double.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("升力", liftForce.ToString()).TextChanged += (o, e) => { try { liftForce = double.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("可見障礙物數量", obstacleCount.ToString()).TextChanged += (o, e) => { try { obstacleCount = int.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("存活區的範圍", rangeY.ToString()).TextChanged += (o, e) => { try { rangeY = Interval.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("障礙物距離的範圍", obstacleDistance.ToString()).TextChanged += (o, e) => { try { obstacleDistance = Interval.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("障礙物寬度(通過時間)的範圍", obstacleWidth.ToString()).TextChanged += (o, e) => { try { obstacleWidth = Interval.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("障礙物通道底部高度的範圍", obstacleY.ToString()).TextChanged += (o, e) => { try { obstacleY = Interval.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("障礙物通道寬度的範圍", obstacleHeight.ToString()).TextChanged += (o, e) => { try { obstacleHeight = Interval.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; pnl.Controls.Add(generalSettings); } } controlPanel.AddControl(pnl, 2, 0); } } Reset(); Update(true); }
public Game() { controlPanel = new MyTableLayoutPanel(2, 1, "AA", "A"); { generalSettings = new MyInputField(); generalSettings.AddField("Port", SocketHandler.port.ToString()).TextChanged += (o, e) => { try { SocketHandler.port = int.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("darryMode", darryMode.ToString()).TextChanged += (o, e) => { try { darryMode = bool.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("max_upward_speed", max_upward_speed.ToString()).TextChanged += (o, e) => { try { max_upward_speed = double.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("alpha", alpha.ToString()).TextChanged += (o, e) => { try { alpha = double.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("重利", gravity.ToString()).TextChanged += (o, e) => { try { gravity = double.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("升力", liftForce.ToString()).TextChanged += (o, e) => { try { liftForce = double.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("可見障礙物數量", obstacleCount.ToString()).TextChanged += (o, e) => { try { obstacleCount = int.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("存活區的範圍", rangeY.ToString()).TextChanged += (o, e) => { try { rangeY = Interval.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("障礙物距離的範圍", obstacleDistance.ToString()).TextChanged += (o, e) => { try { obstacleDistance = Interval.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("障礙物寬度(通過時間)的範圍", obstacleWidth.ToString()).TextChanged += (o, e) => { try { obstacleWidth = Interval.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("障礙物通道底部高度的範圍", obstacleY.ToString()).TextChanged += (o, e) => { try { obstacleY = Interval.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("障礙物通道寬度的範圍", obstacleHeight.ToString()).TextChanged += (o, e) => { try { obstacleHeight = Interval.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; controlPanel.AddControl(generalSettings, 1, 0); } Reset(); Update(true); }
void Start() { if (!serverIsRunned) { Server(); serverIsRunned = true; } mainCanvas = new MyCanvas(new Vector2(Screen.width, Screen.height)); MakeState(); windowTests = MakeTests(); windowTests.SetActive(stateMenu.IsOpenTestsWindow); var buttonWindowTests = new MyButton(() => windowTests.SetActive(!windowTests.isOpen), ButtonSprite, new Rect(0, 0, 64, 48), "Tests"); var rectB = buttonWindowTests.Element.GetComponent<RectTransform>(); var inputField = new MyInputField("Input", ButtonSprite, new Rect(0, 0, 160, 25)); buttonWindowTests.SetAnchor(new Vector2(0, 1), new Vector2(0, 1)); var buttonLog = new MyButton( () => Dispatcher.AddRunner(new LogRunner(inputField.Element.GetComponent<InputField>().text)), ButtonSprite, new Rect(0, 0, 64, 48), "Log play"); var rectLog = buttonLog.Element.GetComponent<RectTransform>(); buttonLog.SetAnchor(0, 0, 0, 0); rectLog.anchoredPosition = new Vector2(300, 40); rectB.offsetMin = new Vector2(100, -200); UIElement.SetSize(rectB, new Vector2(120, 30)); var buttonTutorial = new MyButton( () => Dispatcher.AddRunner(new TutorialRunner(new LoadingData { AssemblyName = "RoboMovies", Level = "Test" })), ButtonSprite, new Rect(0, 00, 120, 48), "Tutorial"); buttonTutorial.SetAnchor(new Vector2(0, 1), new Vector2(0, 1)); rectB = buttonTutorial.Element.GetComponent<RectTransform>(); rectB.offsetMin = new Vector2(100, -300); UIElement.SetSize(rectB, new Vector2(120, 30)); dropDownListAssembly = Instantiate(DropDownList); dropDownListAssembly.name = "BambaLeilo"; dropDownListAssembly.transform.localPosition = new Vector3(0, 0); var dropDown = dropDownListAssembly.GetComponent<Dropdown>(); dropDown.GetComponent<RectTransform>().position = new Vector3(0, 0, 0); dropDown.options = new List<Dropdown.OptionData>(); foreach (var e in Dispatcher.Loader.Levels.Keys) dropDown.options.Add(new Dropdown.OptionData(e)); for (var i = 0; i < dropDown.options.Count; i++) if (dropDown.options[i].text == stateMenu.CurrentAssembly) dropDown.value = i; dropDownListLevel = Instantiate(DropDownList); dropDownListLevel.name = "BambaLeiloLevel"; dropDownListLevel.transform.localPosition = new Vector3(0, 0); var dropDownList = dropDownListLevel.GetComponent<Dropdown>(); dropDownList.GetComponent<RectTransform>().position = new Vector3(0, 0, 0); dropDownList.options = new List<Dropdown.OptionData>(); foreach (var e in Dispatcher.Loader.Levels[stateMenu.CurrentAssembly].Keys) dropDownList.options.Add(new Dropdown.OptionData(e)); for (var i = 0; i < dropDownList.options.Count; i++) if (dropDownList.options[i].text == stateMenu.CurrentLevel) { dropDownList.value = i; dropDownList.options[i] = new Dropdown.OptionData(stateMenu.CurrentLevel); } var backGround = new MyImage(menuBackground, new Rect(0, 0, menuBackground.textureRect.width, menuBackground.textureRect.height)); mainCanvas.AddElement(backGround); mainCanvas.AddElement(inputField); mainCanvas.AddElement(windowTests.Head); mainCanvas.AddElement(buttonWindowTests); mainCanvas.AddElement(buttonTutorial); mainCanvas.AddElement(buttonLog); dropDownListLevel.transform.SetParent(mainCanvas.Element.transform); dropDown.transform.SetParent(mainCanvas.Element.transform); var rectDrop = dropDownListAssembly.GetComponent<RectTransform>(); rectDrop.anchorMin = new Vector2(0, 1); rectDrop.anchorMax = new Vector2(0, 1); rectDrop.anchoredPosition = new Vector3(100, -40, 0); rectDrop = dropDownListLevel.GetComponent<RectTransform>(); rectDrop.anchorMin = new Vector2(0, 1); rectDrop.anchorMax = new Vector2(0, 1); rectDrop.anchoredPosition = new Vector3(300, -40, 0); rectDrop = inputField.Element.GetComponent<RectTransform>(); inputField.SetAnchor(0, 0, 0, 0); rectDrop.anchoredPosition = new Vector3(100, 40, 0); }
private void InitializeControls() { this.FormClosing += Form1_FormClosing; { TLP = new MyTableLayoutPanel(5, 1, "PAAAA", "P"); { { LBL = new MyLabel(""); status = "Q, W, O: control\r\nP: restart all"; TLP.AddControl(LBL, 0, 0); } { MyTableLayoutPanel tlp = new MyTableLayoutPanel(1, 2, "A", "AA"); { PBX = new PictureBox(); PBX.Dock = DockStyle.Fill; PBX.SizeMode = PictureBoxSizeMode.AutoSize; PBX.Image = Properties.Resources.buttonDark; tlp.AddControl(PBX, 0, 0); } { Panel pnl = new Panel(); pnl.Dock = DockStyle.Fill; pnl.AutoSize = true; pnl.AutoSizeMode = AutoSizeMode.GrowAndShrink; PictureBox pbx = new PictureBox(); pbx.Dock = DockStyle.Fill; pbx.SizeMode = PictureBoxSizeMode.Zoom; pbx.Image = Properties.Resources.computer; MyLabel lbl = new MyLabel(""); lbl.Font = new Font("Consolas", 8, FontStyle.Bold); lbl.Dock = DockStyle.None; lbl.ForeColor = Color.FromArgb(64, 0, 0, 0); lbl.BackColor = Color.Transparent; lbl.Parent = pbx; //{ // Bitmap bmp = new Bitmap(1, 1); // bmp.SetPixel(0, 0, Color.Transparent); // lbl.BackgroundImage = bmp; //} //pnl.Controls.Add(lbl); pnl.Controls.Add(pbx); tlp.AddControl(pnl, 0, 1); Thread thread = new Thread(() => { Thread.Sleep(3000); while (true) { Thread.Sleep(20); StringBuilder s = new StringBuilder(); for (int i = 0; i < 10; i++) { for (int j = 0; j < 30; j++) { s.Append(random.Next(0, 2) == 0 ? '0' : '1'); } s.Append("\r\n"); } lbl.Invoke(new Action(() => { lbl.Text = s.ToString(); })); } }); thread.IsBackground = true; thread.Start(); } TLP.AddControl(tlp, 1, 0); } { TB = new TrackBar(); TB.Dock = DockStyle.Fill; TB.Minimum = 0; TB.Maximum = 1000; TLP.AddControl(TB, 2, 0); } { TXB = new MyTextBox(false); TXB.KeyDown += Form1_KeyDown; TXB.KeyUp += Form1_KeyUp; TXB.TextChanged += (object s, EventArgs e1) => { TXB.Text = null; }; TLP.AddControl(TXB, 3, 0); } { IFD = new MyInputField(); IFD.AddField("Play speed (FPS)", FPS.ToString()).TextChanged += (object s, EventArgs e1) => { double t; if (!double.TryParse((s as TextBox).Text, out t)) { MessageBox.Show("格式不正確"); } else { FPS = t; } }; TLP.AddControl(IFD, 4, 0); } } this.Controls.Add(TLP); } }