From 05df005d2616e7c8190ec10bb21f6a134929268c Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Sat, 7 May 2016 08:44:33 -0700 Subject: [PATCH 1/2] starting to add a selectable polygonizer --- .../panels/UIPolygonComponentProperties.java | 25 +++++++++++++++++ .../UIPolygonComponentPropertiesMediator.java | 27 +++++++++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) 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..15b74cc08 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. */ @@ -36,6 +40,7 @@ public class UIPolygonComponentProperties extends UIRemovableProperties { public static final String PASTE_BUTTON_CLICKED = prefix + ".PASTE_BUTTON_CLICKED"; public static final String ADD_DEFAULT_MESH_BUTTON_CLICKED = prefix + ".ADD_DEFAULT_MESH_BUTTON_CLICKED"; public static final String CLOSE_CLICKED = prefix + ".CLOSE_CLICKED"; + public static final String POLYGONIZER_CHANGED = prefix + ".POLYGONIZER_CHANGED"; private VisTextButton addDefaultMeshButton; @@ -43,6 +48,9 @@ public class UIPolygonComponentProperties extends UIRemovableProperties { private VisTextButton copyBtn; private VisTextButton pasteBtn; + private VisSelectBox polygonyzerBox; + + public UIPolygonComponentProperties() { super("Polygon Component"); } @@ -61,6 +69,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 +84,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 +106,8 @@ public void initEmptyView() { private void initListeners() { copyBtn.addListener(new ButtonToNotificationListener(COPY_BUTTON_CLICKED)); pasteBtn.addListener(new ButtonToNotificationListener(PASTE_BUTTON_CLICKED)); + polygonyzerBox.addListener(new SelectBoxChangeListener(POLYGONIZER_CHANGED)); + 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..0912f614b 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. */ @@ -53,7 +56,8 @@ public String[] listNotificationInterests() { UIPolygonComponentProperties.ADD_DEFAULT_MESH_BUTTON_CLICKED, UIPolygonComponentProperties.COPY_BUTTON_CLICKED, UIPolygonComponentProperties.PASTE_BUTTON_CLICKED, - UIPolygonComponentProperties.CLOSE_CLICKED + UIPolygonComponentProperties.CLOSE_CLICKED, + UIPolygonComponentProperties.POLYGONIZER_CHANGED }; return ArrayUtils.addAll(defaultNotifications, notificationInterests); @@ -73,6 +77,9 @@ public void handleNotification(Notification notification) { case UIPolygonComponentProperties.PASTE_BUTTON_CLICKED: pasteMesh(); break; + case UIPolygonComponentProperties.POLYGONIZER_CHANGED: + changePolygonizer(); + break; case UIPolygonComponentProperties.CLOSE_CLICKED: Overlap2DFacade.getInstance().sendNotification(MsgAPI.ACTION_REMOVE_COMPONENT, RemoveComponentFromItemCommand.payload(observableReference, PolygonComponent.class)); break; @@ -95,11 +102,19 @@ protected void translateObservableDataToView(Entity item) { } else { viewComponent.initEmptyView(); } + + viewComponent.setPolygonizerType("BAYAZIT"); } @Override protected void translateViewToItemData() { - + System.out.println("here" + viewComponent.getPolygonyzerType()); + polygonComponent = observableReference.getComponent(PolygonComponent.class); + Vector2[] points = PolygonUtils.mergeTouchingPolygonsToOne(polygonComponent.vertices); +polygonComponent.vertices = polygonize(points); + // Object[] payload = UpdatePolygonComponentCommand.payloadInitialState(observableReference); + // payload = UpdatePolygonComponentCommand.payload(payload, polygonize(points)); + // Overlap2DFacade.getInstance().sendNotification(MsgAPI.ACTION_UPDATE_MESH_DATA, payload); } private void addDefaultMesh() { @@ -120,6 +135,14 @@ 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 changePolygonizer() { + + } + private void pasteMesh() { Vector2[][] vertices = (Vector2[][]) Sandbox.getInstance().retrieveFromLocalClipboard("meshData"); if(vertices == null) return; From d4baca7c6f5e5b2d5433d309219effb593df9c8c Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Sat, 7 May 2016 08:49:13 -0700 Subject: [PATCH 2/2] cleanup for review. --- .../panels/UIPolygonComponentProperties.java | 2 -- .../UIPolygonComponentPropertiesMediator.java | 20 ++++--------------- 2 files changed, 4 insertions(+), 18 deletions(-) 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 15b74cc08..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 @@ -40,7 +40,6 @@ public class UIPolygonComponentProperties extends UIRemovableProperties { public static final String PASTE_BUTTON_CLICKED = prefix + ".PASTE_BUTTON_CLICKED"; public static final String ADD_DEFAULT_MESH_BUTTON_CLICKED = prefix + ".ADD_DEFAULT_MESH_BUTTON_CLICKED"; public static final String CLOSE_CLICKED = prefix + ".CLOSE_CLICKED"; - public static final String POLYGONIZER_CHANGED = prefix + ".POLYGONIZER_CHANGED"; private VisTextButton addDefaultMeshButton; @@ -106,7 +105,6 @@ public void initEmptyView() { private void initListeners() { copyBtn.addListener(new ButtonToNotificationListener(COPY_BUTTON_CLICKED)); pasteBtn.addListener(new ButtonToNotificationListener(PASTE_BUTTON_CLICKED)); - polygonyzerBox.addListener(new SelectBoxChangeListener(POLYGONIZER_CHANGED)); polygonyzerBox.addListener(new SelectBoxChangeListener(getUpdateEventName())); } 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 0912f614b..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 @@ -56,8 +56,7 @@ public String[] listNotificationInterests() { UIPolygonComponentProperties.ADD_DEFAULT_MESH_BUTTON_CLICKED, UIPolygonComponentProperties.COPY_BUTTON_CLICKED, UIPolygonComponentProperties.PASTE_BUTTON_CLICKED, - UIPolygonComponentProperties.CLOSE_CLICKED, - UIPolygonComponentProperties.POLYGONIZER_CHANGED + UIPolygonComponentProperties.CLOSE_CLICKED }; return ArrayUtils.addAll(defaultNotifications, notificationInterests); @@ -77,9 +76,6 @@ public void handleNotification(Notification notification) { case UIPolygonComponentProperties.PASTE_BUTTON_CLICKED: pasteMesh(); break; - case UIPolygonComponentProperties.POLYGONIZER_CHANGED: - changePolygonizer(); - break; case UIPolygonComponentProperties.CLOSE_CLICKED: Overlap2DFacade.getInstance().sendNotification(MsgAPI.ACTION_REMOVE_COMPONENT, RemoveComponentFromItemCommand.payload(observableReference, PolygonComponent.class)); break; @@ -108,13 +104,9 @@ protected void translateObservableDataToView(Entity item) { @Override protected void translateViewToItemData() { - System.out.println("here" + viewComponent.getPolygonyzerType()); - polygonComponent = observableReference.getComponent(PolygonComponent.class); - Vector2[] points = PolygonUtils.mergeTouchingPolygonsToOne(polygonComponent.vertices); -polygonComponent.vertices = polygonize(points); - // Object[] payload = UpdatePolygonComponentCommand.payloadInitialState(observableReference); - // payload = UpdatePolygonComponentCommand.payload(payload, polygonize(points)); - // Overlap2DFacade.getInstance().sendNotification(MsgAPI.ACTION_UPDATE_MESH_DATA, payload); + polygonComponent = observableReference.getComponent(PolygonComponent.class); + Vector2[] points = PolygonUtils.mergeTouchingPolygonsToOne(polygonComponent.vertices); + polygonComponent.vertices = polygonize(points); } private void addDefaultMesh() { @@ -138,10 +130,6 @@ private void copyMesh() { private Vector2[][] polygonize(Vector2[] vertices) { return Clipper.polygonize(Clipper.Polygonizer.valueOf(viewComponent.getPolygonyzerType()), vertices); } - - private void changePolygonizer() { - - } private void pasteMesh() { Vector2[][] vertices = (Vector2[][]) Sandbox.getInstance().retrieveFromLocalClipboard("meshData");