Permalink
Browse files

Merge pull request #2 from prujohn/master

More enhancements/fix to the UI structure.  Custom icons for the asset tree.
  • Loading branch information...
2 parents 58b6d11 + b747750 commit 1623be1e35c27e6d400789b81900ea9f9fcf123c @donny-dont committed Oct 5, 2012
Showing with 222 additions and 111 deletions.
  1. +32 −15 web/controls/vector3_input.dart
  2. +3 −1 web/editor.dart
  3. BIN web/resources/cube.png
  4. BIN web/resources/sphere.png
  5. +14 −0 web/viewmodels/box_entity_view_model.dart
  6. +53 −33 web/viewmodels/editor_view_model.dart
  7. +12 −2 web/viewmodels/entity_view_model.dart
  8. +0 −45 web/viewmodels/generated_mesh_view_model.dart
  9. +14 −0 web/viewmodels/plane_entity_view_model.dart
  10. +6 −0 web/viewmodels/properties/box_properties_view_model.dart
  11. +34 −0 web/viewmodels/properties/entity_properties_view_model.dart
  12. +16 −0 web/viewmodels/properties/sphere_properties_view_model.dart
  13. +3 −6 web/viewmodels/properties/transform_properties_view_model.dart
  14. +14 −0 web/viewmodels/sphere_entity_view_model.dart
  15. +1 −1 web/views/properties/box_properties.dart
  16. +1 −1 web/views/properties/entity_properties.dart
  17. +1 −1 web/views/properties/plane_properties.dart
  18. +1 −1 web/views/properties/sphere_properties.dart
  19. +1 −1 web/views/properties/transform_properties.dart
  20. 0 web/views/templates/{assets.buckshot → assets.xml}
  21. +1 −0 web/views/templates/box_icon.xml
  22. 0 web/views/templates/{box_properties.buckshot → box_properties.xml}
  23. +6 −0 web/views/templates/editor.buckshot
  24. 0 web/views/templates/{entity_properties.buckshot → entity_properties.xml}
  25. +2 −0 web/views/templates/plane_icon.xml
  26. +2 −0 web/views/templates/plane_properties.xml
  27. +1 −0 web/views/templates/sphere_icon.xml
  28. +0 −4 web/views/templates/sphere_properties.buckshot
  29. +4 −0 web/views/templates/sphere_properties.xml
  30. 0 web/views/templates/{transform_properties.buckshot → transform_properties.xml}
@@ -31,42 +31,59 @@ class Vector3Input extends Control
void _initVector3InputProperties()
{
xProperty = new FrameworkProperty(this, 'x',
+ propertyChangedCallback: (v) => _onValueChanged(),
defaultValue:'0');
yProperty = new FrameworkProperty(this, 'y',
+ propertyChangedCallback: (v) => _onValueChanged(),
defaultValue:'0');
zProperty = new FrameworkProperty(this, 'z',
+ propertyChangedCallback: (v) => _onValueChanged(),
defaultValue:'0');
+ }
+
+ void onFirstLoad(){
+ // Get references to our textboxes and then set the bindings.
+ final tbX = Template.findByName('__vector3x__', template) as TextBox;
+ final tbY = Template.findByName('__vector3y__', template) as TextBox;
+ final tbZ = Template.findByName('__vector3z__', template) as TextBox;
- xProperty.propertyChanging + _valueChanged;
- yProperty.propertyChanging + _valueChanged;
- zProperty.propertyChanging + _valueChanged;
+ bind(tbX.textProperty, xProperty, bindingMode:BindingMode.TwoWay);
+ bind(tbY.textProperty, yProperty, bindingMode:BindingMode.TwoWay);
+ bind(tbZ.textProperty, zProperty, bindingMode:BindingMode.TwoWay);
}
- num get x => _validNum(getValue(xProperty));
+ num get x => validNum(getValue(xProperty));
set x(num value) => setValue(xProperty, '$value');
- num get y => _validNum(getValue(yProperty));
+ num get y => validNum(getValue(yProperty));
set y(num value) => setValue(yProperty, '$value');
- num get z => _validNum(getValue(zProperty));
+ num get z => validNum(getValue(zProperty));
set z(num value) => setValue(zProperty, '$value');
- num _validNum(String value){
+ /**
+ * From a String [value], returns a valid num. If the string is not
+ * valid, then the return is 0.
+ */
+ static num validNum(String value){
if (value == null) return 0;
if (value.isEmpty()) return 0;
+ num numValue;
+
try{
- return parseDouble(value);
+ numValue = parseDouble(value);
}
on FormatException catch(e){
- return 0;
+ numValue = 0;
}
- }
- void _valueChanged(sender, args){
- changed.invokeAsync(this, new VectorChangedEventArgs(x,y,z));
+ return numValue;
}
+ void _onValueChanged() =>
+ changed.invokeAsync(this, new VectorChangedEventArgs(x,y,z));
+
String get defaultControlTemplate {
return
'''
@@ -75,11 +92,11 @@ class Vector3Input extends Control
<stack>
<stack orientation='horizontal'>
<textblock text='X:' />
- <textbox width='50' text='{template x, mode=TwoWay}' />
+ <textbox name='__vector3x__' width='50' />
<textblock text='Y:' />
- <textbox width='50' text='{template y, mode=TwoWay}' />
+ <textbox name='__vector3y__' width='50' />
<textblock text='Z:' />
- <textbox width='50' text='{template z, mode=TwoWay}' />
+ <textbox name='__vector3z__' width='50' />
</stack>
</stack>
</template>
View
@@ -62,7 +62,6 @@
#source('views/properties/plane_properties.dart');
#source('viewmodels/editor_view_model.dart');
-#source('viewmodels/generated_mesh_view_model.dart');
#source('viewmodels/entity_view_model.dart');
#source('viewmodels/properties/transform_properties_view_model.dart');
#source('viewmodels/properties/sphere_properties_view_model.dart');
@@ -71,6 +70,9 @@
#source('viewmodels/properties/entity_properties_view_model.dart');
#source('viewmodels/properties/properties_view_model_base.dart');
#source('viewmodels/properties/empty_properties_view_model.dart');
+#source('viewmodels/box_entity_view_model.dart');
+#source('viewmodels/sphere_entity_view_model.dart');
+#source('viewmodels/plane_entity_view_model.dart');
void main()
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,14 @@
+
+class BoxEntityViewModel extends EntityViewModel
+{
+ BoxEntityViewModel() :
+ super(new BoxVisualModel(), new BoxPropertiesViewModel()){
+ entityName = 'Box';
+ }
+
+ Future<String> get fileTemplate =>
+ Template.getTemplate('web/views/templates/box_icon.xml');
+
+ Future<String> get folderTemplate =>
+ Template.getTemplate('web/views/templates/box_icon.xml');
+}
@@ -27,6 +27,7 @@ class EditorViewModel extends ViewModelBase
// Model events
registerEventHandler('add_box_clicked', _addBoxHandler);
registerEventHandler('add_sphere_clicked', _addSphereHandler);
+ registerEventHandler('add_plane_clicked', _addPlaneHandler);
// Canvas events
registerEventHandler('canvas_loaded', _canvasLoadedHandler);
@@ -110,35 +111,52 @@ class EditorViewModel extends ViewModelBase
void _addBoxHandler(_, __)
{
- final boxVM =
- new EntityViewModel(new BoxVisualModel(), new BoxPropertiesViewModel())
- ..entityName ='Box';
+ addEntity(new BoxEntityViewModel());
+ }
+
+ void _addSphereHandler(_, __)
+ {
+ addEntity(new SphereEntityViewModel());
+ }
+
+ void _addPlaneHandler(_, __){
+ addEntity(new PlaneEntityViewModel());
+ }
+ /** Adds an [entityVM] to the application and updates the UI. */
+ void addEntity(EntityViewModel entityVM){
// something should always be selected (_scene is default)
assert(_currentNode != null);
- // Using the tag property to hold a reference to the entity view model
- // object.
- final node = new TreeNode()
- ..header = boxVM.entityName
- ..tag = boxVM;
- if (_currentNode != _scene){
- // setup the relationships
- boxVM.parent = _currentNode.tag;
- _currentNode.tag.children.add(boxVM);
- }
+ Futures
+ .wait([entityVM.fileTemplate, entityVM.folderTemplate])
+ .chain((result){
+ return Futures.wait(result.map((r) => Template.deserialize(r)));
+ })
+ .then((results){
+ // Using the tag property to hold a reference to the entity view model
+ // object.
+ final node = new TreeNode()
+ ..header = entityVM.entityName
+ ..tag = entityVM
+ ..fileIcon = results[0]
+ ..folderIcon = results[1];
+
+ if (_currentNode != _scene){
+ // setup the relationships
+ entityVM.parent = _currentNode.tag;
+ _currentNode.tag.children.add(entityVM);
+ }
+
+ _currentNode.childNodes.add(node);
+ _currentNode.childVisibility = Visibility.visible;
+ _currentNode = node;
+
+ _updateUITo(_currentNode);
+ });
- _currentNode.childNodes.add(node);
- _currentNode.childVisibility = Visibility.visible;
- _currentNode = node;
- _updateUITo(_currentNode);
- }
-
- void _addSphereHandler(_, __)
- {
- print('Adding sphere');
}
//---------------------------------------------------------------------
@@ -159,18 +177,20 @@ class EditorViewModel extends ViewModelBase
.propertyVM
.setDataContext()
.then((_){
- evm
- .propertyVM
- .propertyViews
- .forEach((String name, View view){
- view.ready.then((t){
- final ai = new AccordionItem()
- ..header = name
- ..body = view.rootVisual;
-
- _componentArea.accordionItems.add(ai);
+ Futures
+ .wait(evm.propertyVM.propertyViews.getValues().map((v) => v.ready))
+ .then((_){
+ evm
+ .propertyVM
+ .propertyViews
+ .forEach((String name, View view){
+ final ai = new AccordionItem()
+ ..header = name
+ ..body = view.rootVisual;
+
+ _componentArea.accordionItems.add(ai);
+ });
});
- });
});
}
@@ -1,17 +1,27 @@
/**
- * Represents content, properties, and operations for an entity.
+ * Base class that represents content, properties, and operations for an entity.
*/
-class EntityViewModel extends ViewModelBase
+abstract class EntityViewModel extends ViewModelBase
{
+ /** The model to be used by this entity */
final GeneratedMeshModel model;
+
+ /** The property view model to be used by this entity */
final EntityPropertiesViewModel propertyVM;
+ /** FrameworkProperty that represents the entity friendly name */
FrameworkProperty entityNameProperty;
/** Reference to the parent of this EntityViewModel. Null if no parent. */
EntityViewModel parent;
+ /** The icon template to be used when the entity has no children. */
+ abstract Future<String> get fileTemplate;
+
+ /** The icon template to be used when the entity has children. */
+ abstract Future<String> get folderTemplate;
+
/**
* Reference to the child EntityViewModel's of this EntityViewModel.
*
@@ -1,45 +0,0 @@
-
-// (JOHN)
-// I didn't bring this over into the new property system, since I wasn't
-// sure where you wanted it (EntityPropertiesViewModel? or it's own?)
-class GeneratedMeshViewModel extends ViewModelBase
-{
- GeneratedMeshModel _meshModel;
-
- GeneratedMeshViewModel(GeneratedMeshModel this._meshModel)
- {
- registerEventHandler('texture_coords_changed', _textureCoordsHandler);
- registerEventHandler('normal_changed', _normalChangedHandler);
- registerEventHandler('tangent_changed', _tangentChangedHandler);
- }
-
- void _textureCoordsHandler(CheckBox checkBox, _)
- {
- if (checkBox.isChecked)
- print('Texcoords checked!');
- else
- print('Texcoords unchecked!');
-
- _meshModel.texCoords = checkBox.isChecked;
- }
-
- void _normalChangedHandler(CheckBox checkBox, _)
- {
- if (checkBox.isChecked)
- print('Normal checked!');
- else
- print('Normal unchecked!');
-
- _meshModel.normals = checkBox.isChecked;
- }
-
- void _tangentChangedHandler(CheckBox checkBox, _)
- {
- if (checkBox.isChecked)
- print('Tangent checked!');
- else
- print('Tangent unchecked!');
-
- _meshModel.tangents = checkBox.isChecked;
- }
-}
@@ -0,0 +1,14 @@
+
+class PlaneEntityViewModel extends EntityViewModel
+{
+ PlaneEntityViewModel() :
+ super(new PlaneVisualModel(), new PlanePropertiesViewModel()){
+ entityName = 'Plane';
+ }
+
+ Future<String> get fileTemplate =>
+ Template.getTemplate('web/views/templates/plane_icon.xml');
+
+ Future<String> get folderTemplate =>
+ Template.getTemplate('web/views/templates/plane_icon.xml');
+}
@@ -3,5 +3,11 @@ class BoxPropertiesViewModel extends TransformPropertiesViewModel
{
BoxPropertiesViewModel(){
propertyViews['Box Properties'] = new BoxProperties();
+
+ registerEventHandler('extents_changed', extents_changed);
+ }
+
+ void extents_changed(_, args){
+ print('box extents changed!');
}
}
@@ -4,5 +4,39 @@ class EntityPropertiesViewModel extends PropertiesViewModelBase
EntityPropertiesViewModel(){
propertyViews['Entity Properties'] = new EntityProperties();
+
+ registerEventHandler('texture_coords_changed', _textureCoordsHandler);
+ registerEventHandler('normal_changed', _normalChangedHandler);
+ registerEventHandler('tangent_changed', _tangentChangedHandler);
+ }
+
+ void _textureCoordsHandler(CheckBox checkBox, _)
+ {
+ if (checkBox.isChecked)
+ print('Texcoords checked!');
+ else
+ print('Texcoords unchecked!');
+
+ model.texCoords = checkBox.isChecked;
+ }
+
+ void _normalChangedHandler(CheckBox checkBox, _)
+ {
+ if (checkBox.isChecked)
+ print('Normal checked!');
+ else
+ print('Normal unchecked!');
+
+ model.normals = checkBox.isChecked;
+ }
+
+ void _tangentChangedHandler(CheckBox checkBox, _)
+ {
+ if (checkBox.isChecked)
+ print('Tangent checked!');
+ else
+ print('Tangent unchecked!');
+
+ model.tangents = checkBox.isChecked;
}
}
Oops, something went wrong.

0 comments on commit 1623be1

Please sign in to comment.