public PlayerGroupSelectionWindow(Region region, string title, bool addingPlayer) { CenterToParent(); this.CanMove = true; this._region = region; UIView.exclusiveControl = this; UILabel lTitle = new UILabel(title); UIScrollView scrollView = new UIScrollView(); UIButton bCancel = new UIButton(HEROsMod.HeroText("Cancel")); lTitle.X = Spacing; lTitle.Y = Spacing; lTitle.Scale = .6f; scrollView.X = lTitle.X; scrollView.Y = lTitle.Y + lTitle.Height + SmallSpacing; scrollView.Width = 300; scrollView.Height = 350; bCancel.X = scrollView.X + scrollView.Width - bCancel.Width; bCancel.Y = scrollView.Y + scrollView.Height + Spacing; bCancel.onLeftClick += bCancel_onLeftClick; this.Anchor = AnchorPosition.Center; this.Width = scrollView.Width + Spacing * 2; this.Height = bCancel.Y + bCancel.Height + Spacing; this.X = Main.screenWidth / 2; this.Y = Main.screenHeight / 2; AddChild(lTitle); AddChild(scrollView); AddChild(bCancel); float yPos = Spacing; if (addingPlayer) { for (int i = 0; i < Network.RegisteredUsers.Count; i++) { UserWithID user = Network.RegisteredUsers[i]; UILabel userLabel = new UILabel(user.Username); userLabel.Tag = user.ID; userLabel.X = Spacing; userLabel.Y = yPos; userLabel.Scale = .35f; yPos += userLabel.Height; userLabel.onLeftClick += userLabel_onLeftClick; scrollView.AddChild(userLabel); } } else { for (int i = 0; i < Network.Groups.Count; i++) { Group group = Network.Groups[i]; UILabel groupLabel = new UILabel(group.Name); groupLabel.Tag = group.ID; groupLabel.X = Spacing; groupLabel.Y = yPos; groupLabel.Scale = .35f; yPos += groupLabel.Height; groupLabel.onLeftClick += groupLabel_onLeftClick; scrollView.AddChild(groupLabel); } } scrollView.ContentHeight = yPos + Spacing; }
public void SelectRegion(Region region) { scrollView.ClearContent(); SelectedRegion = region; ModUtils.DebugText(string.Format(HEROsMod.HeroText("SelectedRegion"), region.Name, region.ID)); bCreateRegion.Visible = false; bDeleteRegion.Visible = true; bAddGroup.Visible = true; bAddPlayer.Visible = true; bBack.Visible = true; colorSlider.Visible = true; bSaveColor.Visible = true; bProtectChests.Visible = true; bProtectChests.Selected = region.ChestsProtected; colorSlider.Value = Main.rgbToHsl(region.Color).X; //_prevRegionColor = new Color(region.Color.ToVector3()); float yPos = Spacing; int itemCount = 0; for (int i = 0; i < region.AllowedGroupsIDs.Count; i++) { Group group = Network.GetGroupByID(region.AllowedGroupsIDs[i]); if (group == null) { continue; } UIButton bRemove = new UIButton(HEROsMod.HeroText("Remove")); UIRect bg = new UIRect(); bg.X = LargeSpacing; bg.Y = yPos; bg.Height = bRemove.Height + SmallSpacing * 2; bg.Width = scrollView.Width - 20 - LargeSpacing * 2; yPos += bg.Height; bg.ForegroundColor = itemCount % 2 == 0 ? Color.Transparent : Color.Blue * .1f; UILabel label = new UILabel(HEROsMod.HeroText("Group")); label.X = Spacing; label.Y = Spacing; label.Scale = .5f; UILabel lName = new UILabel(group.Name); lName.X = label.X + 100; lName.Y = label.Y; lName.Scale = label.Scale; bRemove.X = bg.Width - bRemove.Width - Spacing; bRemove.Y = SmallSpacing; bRemove.Tag = group.ID; bRemove.onLeftClick += RemoveGroup; bg.AddChild(label); bg.AddChild(bRemove); bg.AddChild(lName); scrollView.AddChild(bg); itemCount++; } for (int i = 0; i < region.AllowedPlayersIDs.Count; i++) { UserWithID user = null; for (int j = 0; j < Network.RegisteredUsers.Count; j++) { if (Network.RegisteredUsers[j].ID == region.AllowedPlayersIDs[i]) { user = Network.RegisteredUsers[j]; break; } } if (user == null) { continue; } UIButton bRemove = new UIButton(HEROsMod.HeroText("Remove")); UIRect bg = new UIRect(); bg.X = LargeSpacing; bg.Y = yPos; bg.Height = bRemove.Height + SmallSpacing * 2; bg.Width = scrollView.Width - 20 - LargeSpacing * 2; yPos += bg.Height; bg.ForegroundColor = itemCount % 2 == 0 ? Color.Transparent : Color.Blue * .1f; UILabel label = new UILabel(HEROsMod.HeroText("User")); label.X = Spacing; label.Y = Spacing; label.Scale = .5f; UILabel lName = new UILabel(user.Username); lName.X = label.X + 100; lName.Y = label.Y; lName.Scale = label.Scale; bRemove.X = bg.Width - bRemove.Width - Spacing; bRemove.Y = SmallSpacing; bRemove.Tag = user.ID; bRemove.onLeftClick += RemovePlayer; bg.AddChild(label); bg.AddChild(bRemove); bg.AddChild(lName); scrollView.AddChild(bg); itemCount++; } scrollView.ContentHeight = yPos + Spacing; }