diff --git a/overlap2d/src/com/uwsoft/editor/view/ui/properties/panels/UIPolygonComponentProperties.java b/overlap2d/src/com/uwsoft/editor/view/ui/properties/panels/UIPolygonComponentProperties.java index f43e8f12a..ee20d0a32 100644 --- a/overlap2d/src/com/uwsoft/editor/view/ui/properties/panels/UIPolygonComponentProperties.java +++ b/overlap2d/src/com/uwsoft/editor/view/ui/properties/panels/UIPolygonComponentProperties.java @@ -21,10 +21,14 @@ import com.badlogic.gdx.utils.Align; import com.kotcrab.vis.ui.widget.VisLabel; import com.kotcrab.vis.ui.widget.VisTextButton; +import com.kotcrab.vis.ui.widget.VisSelectBox; import com.uwsoft.editor.Overlap2DFacade; import com.uwsoft.editor.event.ButtonToNotificationListener; +import com.uwsoft.editor.event.SelectBoxChangeListener; import com.uwsoft.editor.view.ui.properties.UIRemovableProperties; +import com.badlogic.gdx.utils.Array; + /** * Created by azakhary on 7/2/2015. */ @@ -43,6 +47,9 @@ public class UIPolygonComponentProperties extends UIRemovableProperties { private VisTextButton copyBtn; private VisTextButton pasteBtn; + private VisSelectBox polygonyzerBox; + + public UIPolygonComponentProperties() { super("Polygon Component"); } @@ -61,6 +68,14 @@ public void initView() { mainTable.add(pasteBtn).right().padRight(4); mainTable.row(); + polygonyzerBox = new VisSelectBox<>("white"); + Array types = new Array<>(); + types.add("EWJORDAN"); + types.add("BAYAZIT"); + polygonyzerBox.setItems(types); + mainTable.add(polygonyzerBox).width(150).left().colspan(4); + mainTable.row(); + initListeners(); } @@ -68,6 +83,13 @@ public void setVerticesCount(int count) { verticesCountLbl.setText(count+""); } + public String getPolygonyzerType() { + return polygonyzerBox.getSelected().toString(); + } + + public void setPolygonizerType(String v) { + polygonyzerBox.setSelected(v); + } public void initEmptyView() { mainTable.clear(); @@ -83,6 +105,7 @@ public void initEmptyView() { private void initListeners() { copyBtn.addListener(new ButtonToNotificationListener(COPY_BUTTON_CLICKED)); pasteBtn.addListener(new ButtonToNotificationListener(PASTE_BUTTON_CLICKED)); + polygonyzerBox.addListener(new SelectBoxChangeListener(getUpdateEventName())); } private void initEmptyViewListeners() { diff --git a/overlap2d/src/com/uwsoft/editor/view/ui/properties/panels/UIPolygonComponentPropertiesMediator.java b/overlap2d/src/com/uwsoft/editor/view/ui/properties/panels/UIPolygonComponentPropertiesMediator.java index ce39ca7c4..c3f81d8f8 100644 --- a/overlap2d/src/com/uwsoft/editor/view/ui/properties/panels/UIPolygonComponentPropertiesMediator.java +++ b/overlap2d/src/com/uwsoft/editor/view/ui/properties/panels/UIPolygonComponentPropertiesMediator.java @@ -28,10 +28,13 @@ import com.uwsoft.editor.renderer.components.DimensionsComponent; import com.uwsoft.editor.renderer.components.PolygonComponent; import com.uwsoft.editor.renderer.utils.ComponentRetriever; +import com.uwsoft.editor.renderer.utils.PolygonUtils; +import com.uwsoft.editor.utils.poly.Clipper; import com.uwsoft.editor.view.stage.Sandbox; import com.uwsoft.editor.view.ui.properties.UIItemPropertiesMediator; import org.apache.commons.lang3.ArrayUtils; + /** * Created by azakhary on 7/2/2015. */ @@ -95,11 +98,15 @@ protected void translateObservableDataToView(Entity item) { } else { viewComponent.initEmptyView(); } + + viewComponent.setPolygonizerType("BAYAZIT"); } @Override protected void translateViewToItemData() { - + polygonComponent = observableReference.getComponent(PolygonComponent.class); + Vector2[] points = PolygonUtils.mergeTouchingPolygonsToOne(polygonComponent.vertices); + polygonComponent.vertices = polygonize(points); } private void addDefaultMesh() { @@ -120,6 +127,10 @@ private void copyMesh() { Sandbox.getInstance().copyToLocalClipboard("meshData", polygonComponent.vertices); } + private Vector2[][] polygonize(Vector2[] vertices) { + return Clipper.polygonize(Clipper.Polygonizer.valueOf(viewComponent.getPolygonyzerType()), vertices); + } + private void pasteMesh() { Vector2[][] vertices = (Vector2[][]) Sandbox.getInstance().retrieveFromLocalClipboard("meshData"); if(vertices == null) return;