Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback requested for adding choosable polygonizer #399

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -43,6 +47,9 @@ public class UIPolygonComponentProperties extends UIRemovableProperties {
private VisTextButton copyBtn;
private VisTextButton pasteBtn;

private VisSelectBox<String> polygonyzerBox;


public UIPolygonComponentProperties() {
super("Polygon Component");
}
Expand All @@ -61,13 +68,28 @@ public void initView() {
mainTable.add(pasteBtn).right().padRight(4);
mainTable.row();

polygonyzerBox = new VisSelectBox<>("white");
Array<String> types = new Array<>();
types.add("EWJORDAN");
types.add("BAYAZIT");
polygonyzerBox.setItems(types);
mainTable.add(polygonyzerBox).width(150).left().colspan(4);
mainTable.row();

initListeners();
}

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();

Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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() {
Expand All @@ -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;
Expand Down