private HorizontalLayout CreateGroundFloor(float width) { var doorStartWidth = width / 2 - 2; var numberOfThings = (int)(doorStartWidth / (GroundFloorThingWidth + 1.5)); //thing, .75+.75mes sides var separatorWidth = (doorStartWidth - numberOfThings * GroundFloorThingWidth) / (numberOfThings + 1); var horizontal = new HorizontalLayout(); if (width < 4f) { horizontal.Add(Construct(this.constructors[PanelType.Wall], width, floorHeight)); return(horizontal); } horizontal.Add(Construct(this.constructors[PanelType.Wall], doorStartWidth, floorHeight)); horizontal.Add(Construct(constructors[PanelType.Entrance], 4, floorHeight)); //Door - doorwidth = 2 -> 4 space with door separators horizontal.Add(Construct(this.constructors[PanelType.Wall], doorStartWidth, floorHeight)); // for (int i = 0; i < numberOfThings; i++) //Before door // { // horizontal.Add(Construct(this.constructors[PanelType.Wall], separatorWidth + GroundFloorThingWidth, floorHeight)); //Separator // } // horizontal.Add(Construct(this.constructors[PanelType.Wall], separatorWidth, floorHeight)); //Last Separator // // horizontal.Add(Construct(constructors[PanelType.Entrance], 4, floorHeight)); //Door - doorwidth = 2 -> 4 space with door separators // // horizontal.Add(Construct(this.constructors[PanelType.Wall], (numberOfThings + 1) * separatorWidth, floorHeight)); //Separator // for (int i = 0; i < numberOfThings; i++) //After door // { // // } // horizontal.Add(Construct(this.constructors[PanelType.Wall], separatorWidth, floorHeight)); //Last Separator return(horizontal); }
private ILayout PlanEntranceFacade(float facadeWidth, int floors, float entranceInterval, bool hasAttic, bool leftIsConvex, bool rightIsConvex) { float remainder; List <PanelSize> panelSizes = DivideFacade(facadeWidth, leftIsConvex, rightIsConvex, out remainder); bool hasBalconies = RandomE.Chance(0.5f); commonConstructors[PanelType.Entrance] = constructors[PanelType.Entrance].GetRandom(); commonConstructors[PanelType.EntranceWindow] = constructors[PanelType.EntranceWindow].GetRandom(); commonConstructors[PanelType.Wall] = constructors[PanelType.Wall].GetRandom(); var horizontal = new HorizontalLayout(); bool hasRemainder = remainder > Geometry.Epsilon; if (hasRemainder) { horizontal.Add(CreateBufferWallVertical(remainder / 2, floors, hasAttic)); } int entranceCount = Mathf.Max(Mathf.FloorToInt(facadeWidth / entranceInterval) - 1, 1); int entranceIndexInterval = (panelSizes.Count - entranceCount) / (entranceCount + 1); int lastEntranceIndex = -1; for (int i = 0; i < entranceCount; i++) { int entranceIndex = (i + 1) * entranceIndexInterval + i; horizontal.Add(CreateNormalFacadeVertical(panelSizes, lastEntranceIndex + 1, entranceIndex, floors, hasAttic, hasBalconies)); horizontal.Add(CreateEntranceVertical(sizeValues[panelSizes[entranceIndex]], floors, hasAttic)); if (i == entranceCount - 1) { horizontal.Add(CreateNormalFacadeVertical(panelSizes, entranceIndex + 1, panelSizes.Count, floors, hasAttic, hasBalconies)); } lastEntranceIndex = entranceIndex; } if (hasRemainder) { horizontal.Add(CreateBufferWallVertical(remainder / 2, floors, hasAttic)); } return(horizontal); }
private HorizontalLayout CreateHorizontal(List <PanelSize> panelSizes, int from, int to, float height, List <Func <ILayoutElement> > constructors) { var horizontal = new HorizontalLayout(); for (int i = from; i < to; i++) { float width = sizeValues[panelSizes[i]]; horizontal.Add(Construct(constructors, width, height)); } return(horizontal); }
// bool registerCallbackToParent = false; public VisualWindow() { this.StyleBorderRadius(4, 4, 4, 4); this.StyleBorderWidth(1, 1, 2, 2); Color borderColor = new Color32(58, 121, 187, 255); this.StyleBorderColor(Color.grey, Color.grey, borderColor, borderColor); Color backgroundColor = EditorGUIUtility.isProSkin ? new Color32(64, 64, 64, 255) : new Color32(184, 184, 184, 255); this.StyleBackgroundColor(backgroundColor); this.StyleMinSize(128, 32); this.StyleMaxSize(9999, 9999); this.StylePosition(Position.Absolute); this.AddManipulator(new UIDragger(this, true)); this.RegisterCallback <MouseOverEvent>(RegisterParentGeometryChanged); headerElement = new HorizontalLayout(); headerElement.name = nameof(headerElement).ToUpper(); headerElement.StyleMaxHeight(24); headerElement.StyleMinHeight(24); headerElement.StylePadding(18, 18, 4, 4); headerElement.StyleJustifyContent(Justify.Center); headerElement.RegisterCallback <MouseUpEvent>((callback) => { if (callback.button == 2) { this.style.width = this.style.height = StyleKeyword.Auto; Repaint(); } }); base.Add(headerElement); labelElement = new Label(); labelElement.name = nameof(labelElement).ToUpper(); name = labelElement.text = "Untitled"; labelElement.StyleMargin(0, 0, 0, 2); labelElement.StyleAlignSelf(Align.Center); labelElement.StyleFont(FontStyle.Bold); headerElement.Add(labelElement); Image closeButton = new Image(); closeButton.name = nameof(closeButton).ToUpper(); closeButton.image = EditorGUIUtility.IconContent("winbtn_win_close").image; closeButton.StyleSize(16, 16); closeButton.StyleBorderWidth(1, 0, 0, 1); closeButton.StyleBorderRadius(0, 0, 4, 0); closeButton.StyleBorderColor(borderColor); closeButton.StylePosition(Position.Absolute); closeButton.StyleAlignSelf(Align.FlexEnd); base.Add(closeButton); closeButton.RegisterCallback <MouseDownEvent>((e) => { this.StyleDisplay(DisplayStyle.None); }); contentElement = new VisualElement(); contentElement.name = nameof(contentElement).ToUpper(); contentElement.StyleMargin(0, 0, 0, 9); base.Add(contentElement); Image resizeButton = new Image(); resizeButton.name = nameof(resizeButton).ToUpper(); resizeButton.StyleAlignSelf(Align.FlexEnd); resizeButton.StylePosition(Position.Absolute); resizeButton.StyleSize(8, 8); resizeButton.StyleBorderRadius(0, 0, 0, 4); resizeButton.StyleBorderWidth(0, 2, 0, 2); resizeButton.StyleBorderColor(Color.grey); resizeButton.StyleRight(1); resizeButton.StyleBottom(1); base.Add(resizeButton); var uIResizer = new UIResizer(this); resizeButton.AddManipulator(uIResizer); uIResizer.mouseMoveAction += () => { resizeButton.StyleRight(1); resizeButton.StyleBottom(1); }; }
private void Init(string title) { this.StyleFont(FontStyle.Bold); this.StyleMinHeight(20); this.StyleBorderWidth(0, 0, 1, 0); Color borderColor = EditorGUIUtility.isProSkin ? new Color32(35, 35, 35, 255) : new Color32(153, 153, 153, 255); this.StyleBorderColor(borderColor); headerElement = new HorizontalLayout(); headerElement.StyleHeight(21); headerElement.StyleMaxHeight(21); headerElement.StyleMinHeight(21); headerElement.StylePadding(4, 0, 0, 0); headerElement.StyleAlignItem(Align.Center); Color backgroundColor = EditorGUIUtility.isProSkin ? new Color32(80, 80, 80, 255) : new Color32(222, 222, 222, 255); headerElement.StyleBackgroundColor(backgroundColor); Color hoverBorderColor = new Color32(58, 121, 187, 255); headerElement.RegisterCallback <MouseEnterEvent>((evt) => { headerElement.StyleBorderWidth(1); headerElement.StyleBorderColor(hoverBorderColor); }); headerElement.RegisterCallback <MouseLeaveEvent>((evt) => { headerElement.StyleBorderWidth(0); headerElement.StyleBorderColor(Color.clear); }); base.Add(headerElement); contentElement = new VerticalLayout(); contentElement.StyleDisplay(value); base.Add(contentElement); labelElement = new Label(); labelElement.text = title; headerElement.Add(labelElement); imageElement = new Image(); imageElement.name = nameof(imageElement); imageElement.StyleMargin(0, 4, 0, 0); imageElement.StyleSize(16, 16); headerElement.Add(imageElement); imageElement.SendToBack(); imageElement.RegisterCallback <GeometryChangedEvent>((evt) => { imageElement.StyleDisplay(imageElement.image == null ? DisplayStyle.None : DisplayStyle.Flex); }); foloutImage = new Image(); foloutImage.StyleWidth(13); foloutImage.StyleMargin(0, 2, 0, 0); foloutImage.scaleMode = ScaleMode.ScaleToFit; foloutImage.image = value ? onIcon : offIcon; if (!EditorGUIUtility.isProSkin) { foloutImage.tintColor = Color.grey; } headerElement.Add(foloutImage); foloutImage.SendToBack(); headerElement.RegisterCallback <MouseUpEvent>((evt) => { if (evt.button == 0) { Value = !Value; evt.StopPropagation(); } }); }
private HorizontalLayout CreateHorizontal(List <PanelSize> panelSizes, int from, int to, float height, List <Func <ILayoutElement> > constructors, List <int> continuousWindowIndexes = null) { var horizontal = new HorizontalLayout(); for (int i = from; i < to; i++) { float width = sizeValues[panelSizes[i]]; if (CurrentBuilding.FacadeType == BuildingFacadeType.EmptyMiddleVertical || CurrentBuilding.FacadeType == BuildingFacadeType.Cross) { // The middle column of windows doesn't appear if (i == panelSizes.Count / 2) { horizontal.Add(Construct(this.constructors[PanelType.Wall], width, height)); } else { horizontal.Add(Construct(constructors, width, height)); } } else if (CurrentBuilding.FacadeType == BuildingFacadeType.EmptyThickMiddleVertical || CurrentBuilding.FacadeType == BuildingFacadeType.ThickCross) { //3 middle columns of windows doesn't appear if (i == panelSizes.Count / 2 || i == panelSizes.Count / 2 - 1 || i == panelSizes.Count / 2 + 1) { horizontal.Add(Construct(this.constructors[PanelType.Wall], width, height)); } else { horizontal.Add(Construct(constructors, width, height)); } } else if (CurrentBuilding.FacadeType == BuildingFacadeType.LeftSideEmpty) { //Windows don't appear on the left side if (i < panelSizes.Count / 2) { horizontal.Add(Construct(this.constructors[PanelType.Wall], width, height)); } else { horizontal.Add(Construct(constructors, width, height)); } } else if (CurrentBuilding.FacadeType == BuildingFacadeType.RightSideEmpty) { //Windows don't appear on the right side if (i > panelSizes.Count / 2) { horizontal.Add(Construct(this.constructors[PanelType.Wall], width, height)); } else { horizontal.Add(Construct(constructors, width, height)); } } else if (CurrentBuilding.FacadeType == BuildingFacadeType.MiddleColumnFullGlass) { // The middle column is full glass if (i == panelSizes.Count / 2) { horizontal.Add(Construct(this.constructors[PanelType.ContinuousWindow], width, height)); } else if (i == panelSizes.Count / 2 - 1 || i == panelSizes.Count / 2 + 1) { horizontal.Add(Construct(this.constructors[PanelType.Wall], width, height)); } else { horizontal.Add(Construct(constructors, width, height)); } } else if (CurrentBuilding.FacadeType == BuildingFacadeType.SWithContGlass) { //Makes an S with continuous glass if (continuousWindowIndexes != null && continuousWindowIndexes.Contains(i)) { horizontal.Add(Construct(this.constructors[PanelType.ContinuousWindow], width, height)); } else { horizontal.Add(Construct(this.constructors[PanelType.Wall], width, height)); } } else { horizontal.Add(Construct(constructors, width, height)); } } return(horizontal); }
public void BuildItem() { container.Clear(); if (data.state == ToDoData.ToDoState.NoStart) { var startBtn = new ImageButtonView(ImageButtonIcon.playIcon, () => { data.startTime = DateTime.Now; data.state.Val = ToDoData.ToDoState.Started; //改变了state会自动储存 UpdateItem(); }).Height(20).Width(40).BackgroundColor(Color.green); container.Add(startBtn); } else if (data.state == ToDoData.ToDoState.Started) { var finishedBtn = new ImageButtonView(ImageButtonIcon.finishIcon, () => { data.finishTime = DateTime.Now; data.state.Val = ToDoData.ToDoState.Done; UpdateItem(); }).Height(20).Width(40).BackgroundColor(Color.green); container.Add(finishedBtn); } else if (data.state == ToDoData.ToDoState.Done) { var resetBtn = new ImageButtonView(ImageButtonIcon.resetIcon, () => { data.createTime = DateTime.Now; data.state.Val = ToDoData.ToDoState.NoStart; UpdateItem(); }).Height(20).Width(40).BackgroundColor(Color.grey); container.Add(resetBtn); } var boxView = new BoxView("无").AddTo(container) .TextMiddleCenter().Width(20).FontSize(12) .FontColor(Color.white).FontBold(); new CategoryComponent(data.category).AddTo(container); var contentLabel = new LabelView(data.content).Height(20).FontSize(15).TextMiddleCenter(); container.Add(contentLabel); if (showTime) { new LabelView(data.finishTime.ToString("完成于 HH:mm:ss")) .Height(20).Width(80).TextMiddleLeft().FontBold(); new LabelView(data.UsedTimeText) .Height(20).Width(100).TextMiddleLeft().AddTo(container); } var priorityVal = data.priority.Val; Color priorityColor = Color.clear; switch (priorityVal) { case ToDoData.ToDoPriority.A: boxView.Context = "A"; priorityColor = Color.red; boxView.BackgroundColor(Color.red); break; case ToDoData.ToDoPriority.B: boxView.Context = "B"; priorityColor = Color.yellow; boxView.BackgroundColor(Color.yellow); break; case ToDoData.ToDoPriority.C: boxView.Context = "C"; priorityColor = Color.cyan; boxView.BackgroundColor(Color.cyan); break; case ToDoData.ToDoPriority.D: boxView.Context = "D"; priorityColor = Color.blue; boxView.BackgroundColor(Color.blue); break; case ToDoData.ToDoPriority.None: boxView.Context = "无"; priorityColor = Color.gray; boxView.BackgroundColor(Color.gray); break; } var priority = new EnumPopupView <ToDoData.ToDoPriority>(priorityVal) .Width(30).Height(20).BackgroundColor(priorityColor).AddTo(container); priority.ValueProperty.RegisterValueChanged((val) => { data.priority.Val = val; switch (val) { case ToDoData.ToDoPriority.A: boxView.Context = "A"; priority.BackgroundColor(Color.red); boxView.BackgroundColor(Color.red); break; case ToDoData.ToDoPriority.B: boxView.Context = "B"; priority.BackgroundColor(Color.yellow); boxView.BackgroundColor(Color.yellow); break; case ToDoData.ToDoPriority.C: boxView.Context = "C"; priority.BackgroundColor(Color.cyan); boxView.BackgroundColor(Color.cyan); break; case ToDoData.ToDoPriority.D: boxView.Context = "D"; priority.BackgroundColor(Color.blue); boxView.BackgroundColor(Color.blue); break; case ToDoData.ToDoPriority.None: boxView.Context = "无"; priority.BackgroundColor(Color.gray); boxView.BackgroundColor(Color.gray); break; } UpdateItem(); }); new ImageButtonView(ImageButtonIcon.editorIcon, () => { OpenSubWindow(); }) .Width(25).Height(25).BackgroundColor(Color.black).AddTo(container); var deleteBtn = new ImageButtonView(ImageButtonIcon.deleteIcon, () => { data.finished.ClearValueChanged(); ToDoDataManager.RemoveToDoItem(data); deleteAct?.Invoke(data); UpdateItem(); }).Height(25).Width(25).BackgroundColor(Color.red); container.Add(deleteBtn); }