public void OnClick() { // Suspending layout when adding or removing a large // group of controls can speed up the process noticeably from.SuspendLayout(); to.SuspendLayout(); while (from.Controls.Count > 0) { var control = from.Controls[0]; // Removes the control from the source container, // but does not delete it. from.RemoveControl(control); // Setting the control's ZOrder property to -1 // tells the container to auto-increment it, // which in this scene has the effect of placing // it at the end of the list. control.ZOrder = -1; // Add the existing control to the target container to.AddControl(control); } // Always remember to tell the control to resume its // normal layout handling. from.ResumeLayout(); to.ResumeLayout(); // The from control may now have an invalid scroll position. from.ScrollPosition = Vector2.zero; }
public void AddBuilding(BuildingInfo bi) { if (bi.type == 0) { dfButton button = (dfButton)Instantiate(prefabBuildingButton); dfButton helpButton = (dfButton)Instantiate(prefabHelpButton); button.Text = bi.ButtonText(); BuildingInfoContainer container = button.GetComponent <BuildingInfoContainer>(); container.bi = bi; buildingBackButton.ZOrder = 0; button.ZOrder = -1; buildButtonPanel.AddControl(button); button.AddControl(helpButton); HelpButton helpScript = helpButton.GetComponent <HelpButton>(); helpScript.bi = bi; helpButton.RelativePosition = new Vector3(button.Width - helpButton.Width - 8, button.Height - helpButton.Height - 2, 0); helpButton.BringToFront(); } }
public void OnClick(dfControl control, dfMouseEventArgs mouseEvent) { var count = _scrollPanel.Controls.Count; var label = _scrollPanel.AddControl <dfLabel>(); label.Text = "Item " + count; label.Width = _scrollPanel.Width - _scrollPanel.ScrollPadding.horizontal; label.Height = 24; label.BackgroundSprite = "frame-basic"; label.TextAlignment = TextAlignment.Center; label.RelativePosition = new Vector3(0, count * 24); }
public void AddResearch(Research r) { if (state == null) { state = GameState.Instance; } dfButton button = (dfButton)Instantiate(prefabResearchButton); ResearchContainer container = button.GetComponent <ResearchContainer>(); container.r = r; container.state = state; button.Text = r.ButtonText(state.population, state.iq); button.ZOrder = -1; researchBackButton.ZOrder = 0; researchButtonPanel.AddControl(button); }
public void OnClick() { for (int i = 0; i < 10; i++) { // Creates the new control and adds it to the target // Scroll Panel. Returns a reference to the new // control. var button = target.AddControl <dfButton>(); // Set whatever properties the control needs after creation button.NormalBackgroundColor = colors[colorNum % colors.Length]; button.BackgroundSprite = "button-normal"; button.Text = string.Format("Button {0}", button.ZOrder); button.Anchor = dfAnchorStyle.Left | dfAnchorStyle.Right; button.Width = target.Width - target.ScrollPadding.horizontal; } colorNum += 1; }
void GenerateList2(string filter) { var children = new List <GameObject>(); foreach (Transform child in UserPanel.transform) { children.Add(child.gameObject); } children.ForEach(child => Destroy(child)); IEnumerable <Player> filtered = users.Where(t => t.Username.ToLower().Contains(filter.ToLower())); foreach (Player player in filtered) { ParseObject friend = null; if (friends != null) { friend = friends.Where(t => ((Player)t[REQUEST_FROM]).ObjectId.Equals(player.ObjectId) || ((Player)t[REQUEST_TO]).ObjectId.Equals(player.ObjectId)).FirstOrDefault(); // friend = friends.FirstOrDefault(); // print("Friend: " + ((Player)friend[REQUEST_TO]).ObjectId); // print("Player: " + player.ObjectId); } var panel = UserPanel.AddControl <UserListItem>(); panel.BackgroundSprite = "BLANK_TEXTURE"; if (friend != null) { panel.BackgroundColor = new Color32(255, 229, 255, 255); } else { panel.BackgroundColor = new Color32(213, 229, 255, 255); } panel.Height = 50; panel.Width = UserPanel.Width - UserPanel.FlowPadding.left - UserPanel.FlowPadding.right; panel.User = player; dfLabel nameLabel = panel.AddControl <dfLabel>(); nameLabel.Text = player.Username; nameLabel.AutoSize = true; nameLabel.RelativePosition = new Vector3(50, 12); nameLabel.Color = new Color32(0, 0, 0, 255); dfSprite onlineSprite = panel.AddControl <dfSprite>(); if (player.IsOnline) { onlineSprite.SpriteName = "OUYA_O 24px"; } else { onlineSprite.SpriteName = "OUYA_A 24px"; } onlineSprite.RelativePosition = new Vector3(13, 13); if (!player.Username.Equals(Player.CurrentUser.Username)) { var addButton = panel.AddControl <dfButton>(); addButton.BackgroundSprite = "button-normal"; addButton.HoverSprite = "button-hilite"; addButton.PressedSprite = "button-normal"; addButton.FocusSprite = "button-hilite"; addButton.DisabledSprite = "button-disabled"; addButton.Text = "Add"; addButton.Width = 50; addButton.Height = 30; addButton.RelativePosition = new Vector3(panel.Width - addButton.Width - 5, 10); addButton.Click += new MouseEventHandler(actionClick_add); } } }
void GenerateRoomList() { var children = new List <GameObject>(); foreach (Transform child in ActiveRoomsPanel.transform) { children.Add(child.gameObject); } children.ForEach(child => Destroy(child)); if (PhotonNetwork.connected) { int sel_idx = -1; if (currentlySelected != null) { sel_idx = currentlySelected.GetComponent <RoomData>().Index; } int idx = 0; if (PhotonNetwork.GetRoomList().Length == 0) { dfLabel label = ActiveRoomsPanel.AddControl <dfLabel>(); label.Padding = new RectOffset(10, 10, 10, 10); label.Text = "No games available"; label.Color = new Color32(200, 200, 200, 255); label.AutoSize = true; } else { foreach (RoomInfo game in PhotonNetwork.GetRoomList().OrderBy(t => Mathf.Abs((int)t.customProperties["level"] - Player.Level))) { dfPanel listItem = ActiveRoomsPanel.AddPrefab(ListItem) as dfPanel; // as UserListItem; listItem.Width = ActiveRoomsPanel.Width - ActiveRoomsPanel.FlowPadding.left - ActiveRoomsPanel.FlowPadding.right; listItem.Click += new MouseEventHandler(listItem_Click); listItem.DoubleClick += new MouseEventHandler(listItem_DoubleClick); RoomData data = listItem.GetComponent <RoomData>(); data.Game = game; data.Index = idx++; if (data.Index == sel_idx) { // print("They match!"); data.Selected = true; listItem.BackgroundColor = new Color32(0, 0, 0, 255); currentlySelected = listItem; currentlySelected.Find("Selected Indicator").GetComponent <dfSprite>().Show(); } dfLabel roomName = listItem.Find("Room Name").GetComponent <dfLabel>(); roomName.Text = string.Format("{0} ({1})", game.customProperties["name"].ToString(), game.customProperties["level"].ToString()); dfLabel mapName = listItem.Find("Map Type").GetComponent <dfLabel>(); mapName.Text = game.customProperties["map"].ToString(); dfLabel modeName = listItem.Find("Game Mode").GetComponent <dfLabel>(); modeName.Text = game.customProperties["mode"].ToString(); dfLabel numberPlayers = listItem.Find("Number Players").GetComponent <dfLabel>(); numberPlayers.Text = string.Format("{0}/{1}", game.playerCount, game.maxPlayers); if (game.playerCount < game.maxPlayers) { numberPlayers.Color = new Color32(0, 255, 0, 255); } else { numberPlayers.Color = new Color32(255, 0, 0, 255); } } } } }
private float AddBox(Brain b, int level, float prev_center, Color32 color) { AddedBrains++; var top_padding = 10; var spacing = 150; // var button = _panel.AddControl<BrainButton>(); BrainButton button = _panel.AddPrefab(ListItem) as BrainButton; // as UserListItem; dfLabel NameLabel = button.Find("Brain Name Label").GetComponent <dfLabel>(); dfLabel GenerationLabel = button.Find("Generation Label").GetComponent <dfLabel>(); dfLabel FitnessLabel = button.Find("Fitness Label").GetComponent <dfLabel>(); BrainButton branchButton = button.Find("Branch Button").GetComponent <BrainButton>(); dfPanel NamePanel = button.Find("Panel").GetComponent <dfPanel>(); NameLabel.Text = b.Name; GenerationLabel.Text = "Age: " + b.Generation; FitnessLabel.Text = string.Format("Fitness: {0:0.00}", b.BestFitness); button.Brain = b; button.Click += button_Click; button.IsNewBrain = b.IsNewBrain; button.DragStart += button_DragStart; NamePanel.BackgroundColor = color; //button.BackgroundSprite = "BLANK_TEXTURE"; // button.NormalBackgroundColor = color; //button.HoverSprite = "listitem-hover"; //button.PressedSprite = "listitem-selected"; //button.Width = 150; //button.Height = 80; var center_spacing = _panel.Width / (LevelCount[level]); var center = center_spacing * CurrentCount[level] - center_spacing / 2; CurrentCount[level] += 1; button.RelativePosition = new Vector3(center - button.Width / 2, top_padding + level * spacing); var plus = branchButton; plus.Brain = b; plus.Click += new_button_Click; // plus.RelativePosition = new Vector3(124, plus.RelativePosition.y); if (level > 0) { var line = _panel.AddControl <dfSprite>(); line.SpriteName = "BLANK_TEXTURE"; line.Width = 2; //line.Height = spacing - button.Height; float B = spacing - button.Height; line.Height = HypotenuseLength(prev_center, center, B) + 20; Vector3 rot = Vector3.forward; float angle = Angle(B, center - prev_center); // print("Angle: " + angle); line.transform.Rotate(rot, angle); float padding = 0; if (angle < 0) { padding = -5; } if (angle > 0) { padding = 5; } line.RelativePosition = new Vector3(prev_center, top_padding + level * spacing - B + padding - 5); line.ZOrder = 0; } var empty = _panel.AddControl <dfSprite>(); empty.RelativePosition = new Vector3(center - button.Width / 2, top_padding + level * spacing + button.Height + 30); return(center); }