Java Code Examples for com.badlogic.gdx.utils.reflect.Field#getType()

The following examples show how to use com.badlogic.gdx.utils.reflect.Field#getType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BehaviorTreeViewer.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
private static void appendFieldString (StringBuilder sb, Task<?> task, TaskAttribute ann, Field field) {
	// prefer name from annotation if there is one
	String name = ann.name();
	if (name == null || name.length() == 0) name = field.getName();
	Object value;
	try {
		field.setAccessible(true);
		value = field.get(task);
	} catch (ReflectionException e) {
		Gdx.app.error("", "Failed to get field", e);
		return;
	}
	sb.append(name).append(":");
	Class<?> fieldType = field.getType();
	if (fieldType.isEnum() || fieldType == String.class) {
		sb.append('\"').append(value).append('\"');
	} else if (Distribution.class.isAssignableFrom(fieldType)) {
		sb.append('\"').append(DAs.toString((Distribution)value)).append('\"');
	} else
		sb.append(value);
}
 
Example 2
Source File: ColorPickerDialog.java    From gdx-skineditor with Apache License 2.0 5 votes vote down vote up
/**
 * Check if the color is already in use somewhere else in the skin
 */
public boolean isColorInUse(Color color) {

	try {
		// Check if it is already in use somewhere!
		for (String widget : SkinEditorGame.widgets) {
			String widgetStyle = "com.badlogic.gdx.scenes.scene2d.ui." + widget + "$" + widget + "Style";
			Class<?> style = Class.forName(widgetStyle);
			ObjectMap<String, ?> styles = game.skinProject.getAll(style);
			Iterator<String> it = styles.keys().iterator();
			while (it.hasNext()) {
				Object item = styles.get((String) it.next());
				Field[] fields = ClassReflection.getFields(item.getClass());
				for (Field field : fields) {

					if (field.getType() == Color.class) {

						Color c = (Color) field.get(item);
						if (color.equals(c)) {
							return true;
						}

					}

				}

			}

		}
	} catch (Exception e) {
		e.printStackTrace();

	}

	return false;
}
 
Example 3
Source File: FontPickerDialog.java    From gdx-skineditor with Apache License 2.0 5 votes vote down vote up
/**
 * Is font is already in use somewhere else?
 */
public boolean isFontInUse(BitmapFont font) {

	try {
		// Check if it is already in use somewhere!
		for (String widget : SkinEditorGame.widgets) {
			String widgetStyle = "com.badlogic.gdx.scenes.scene2d.ui." + widget + "$" + widget + "Style";
			Class<?> style = Class.forName(widgetStyle);
			ObjectMap<String, ?> styles = game.skinProject.getAll(style);
			Iterator<String> it = styles.keys().iterator();
			while (it.hasNext()) {
				Object item = styles.get((String) it.next());
				Field[] fields = ClassReflection.getFields(item.getClass());
				for (Field field : fields) {

					if (field.getType() == BitmapFont.class) {

						BitmapFont f = (BitmapFont) field.get(item);
						if (font.equals(f)) {
							return true;
						}

					}

				}

			}

		}
	} catch (Exception e) {
		e.printStackTrace();

	}

	return false;
}
 
Example 4
Source File: StyleData.java    From skin-composer with MIT License 4 votes vote down vote up
private void newStyleProperties(Class clazz) {
    for (Field field : ClassReflection.getFields(clazz)) {
        StyleProperty styleProperty = new StyleProperty(field.getType(), field.getName(), true);
        properties.put(field.getName(), styleProperty);
    }
}