Skip to content

Commit

Permalink
prop collision toggle added
Browse files Browse the repository at this point in the history
  • Loading branch information
tubixpvp committed Feb 2, 2025
1 parent 71fdaa7 commit 5a18f40
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 12 deletions.
49 changes: 49 additions & 0 deletions src/alternativa/editor/PropGeneralPropertiesPanel.mxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="onCreationComplete()" percentWidth="15" percentHeight="100"
title="Prop Parameters">

<fx:Script>
<![CDATA[
import alternativa.types.Set;
import alternativa.editor.prop.MeshProp;
import alternativa.editor.prop.Sprite3DProp;
private const _selectedProps:Vector.<MeshProp> = new Vector.<MeshProp>();
private function onCreationComplete():void
{
}
private function onCollisionChanged(param1:Event):void
{
for each(var prop:MeshProp in _selectedProps)
{
prop.collisionEnabled = this.collision.selected;
}
}
public function init(selectedProps:Set, collisionEnabled:Boolean) : void
{
_selectedProps.length = 0;
for(var prop:* in selectedProps)
{
if(prop is MeshProp && !(prop is Sprite3DProp))
{
_selectedProps.push(prop as MeshProp);
}
}
this.collision.selected = collisionEnabled;
}
]]>
</fx:Script>

<mx:VBox paddingTop="5" paddingBottom="5" paddingLeft="5" paddingRight="5">
<mx:CheckBox id="collision" label="Collision enabled" change="onCollisionChanged(event)"/>
</mx:VBox>

</mx:Panel>
7 changes: 7 additions & 0 deletions src/alternativa/editor/SceneContainer.as
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ package alternativa.editor

public class SceneContainer extends UIComponent
{
private static var _instance:SceneContainer;
public static function get instance() : SceneContainer
{
return _instance;
}

private static const cameraPoint:Point3D = new Point3D(0,0,1000);

private static const cameraOffset:Point3D = new Point3D();
Expand Down Expand Up @@ -100,6 +106,7 @@ package alternativa.editor

public function SceneContainer()
{
_instance = this;
this.multiplePropMode = MultiPropMode.NONE;
this.mouseDownPoint = new Point();
this.rectProps = new Set();
Expand Down
4 changes: 4 additions & 0 deletions src/alternativa/editor/mapexport/TanksXmlExporterV1Lite.as
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ package alternativa.editor.mapexport

protected function createTileCollisionXml(param1:MeshProp, param2:XML) : void
{
if(!param1.collisionEnabled)
{
return;
}
var loc4:CollisionPrimitive = null;
var loc3:Vector.<CollisionPrimitive> = this.collPrimCache.getPrimitives(param1.libraryName,param1.groupName,param1.name);
if(loc3 == null)
Expand Down
77 changes: 74 additions & 3 deletions src/alternativa/editor/prop/MeshProp.as
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ package alternativa.editor.prop

public class MeshProp extends Prop
{
[Embed(source="no_collision_texture.png")]
private static const NO_COLLISION_TEXTURE_MASK_Class:Class;

private static const NO_COLLISION_TEXTURE_Bitmap:BitmapData = new NO_COLLISION_TEXTURE_MASK_Class().bitmapData;

public var bitmaps:Map;

protected var _textureName:String = "";
Expand All @@ -33,6 +38,12 @@ package alternativa.editor.prop
private var bound:Mesh;

private var _objects:Vector.<Object3D>;

private var _collisionEnabled:Boolean = true;

private var _noCollisionTexture:BitmapData = null;
private var _noCollisionMaterial:TextureMaterial = null;


public function MeshProp(mainObject:Object3D, objects:Vector.<Object3D>, param2:String, param3:String, param4:String, param5:Boolean = true)
{
Expand Down Expand Up @@ -121,6 +132,7 @@ package alternativa.editor.prop
{
loc2 = loc1 as Mesh;
loc2.setMaterialToAllFaces(this.collisionMaterial);
addChild(loc2);
}
setMaterial(null);
}
Expand All @@ -133,6 +145,7 @@ package alternativa.editor.prop
{
loc2 = loc1 as Mesh;
loc2.setMaterialToAllFaces(null);
removeChild(loc2);
}
setMaterial(_material);
}
Expand Down Expand Up @@ -162,17 +175,27 @@ package alternativa.editor.prop
{
_material.dispose();
}

_material = new TextureMaterial(bitmapData);
if(_selected)
{
this.disposeSelectTexture();

this.disposeSelectTexture();

if(_selected)
{
select();
}
else
{
setMaterial(_material);
}
if(_noCollisionTexture != null)
{
_noCollisionMaterial.dispose();
_noCollisionMaterial = null;
_noCollisionTexture.dispose();
_noCollisionTexture = null;
}
this.setToCollisionDisabledTextureIfNeeded();
if(this._textureName == "DEFAULT")
{
this._textureName = "";
Expand Down Expand Up @@ -216,6 +239,7 @@ package alternativa.editor.prop
loc2.bitmaps = this.bitmaps;
loc2._textureName = this._textureName;
loc2.height = height;
loc2.collisionEnabled = this._collisionEnabled;
return loc2;
}

Expand Down Expand Up @@ -259,6 +283,53 @@ package alternativa.editor.prop
this.bound = null;
}
}

public function get collisionEnabled() : Boolean
{
return this._collisionEnabled;
}
public function set collisionEnabled(enabled:Boolean) : void
{
if(this._collisionEnabled == enabled)
return;

this._collisionEnabled = enabled;

this.setToCollisionDisabledTextureIfNeeded();
}
private function setToCollisionDisabledTextureIfNeeded() : void
{
if(_collisionEnabled)
return;
if(_selected) //shouldn't change texture of 'selected'
return;
if(hidden)
return;
if(this._textureName == InvisibleTexture.TEXTURE_NAME)
return;

if(_noCollisionTexture == null)
{
_noCollisionTexture = this.bitmapData.clone();

_matrix.a = this.bitmapData.width / NO_COLLISION_TEXTURE_Bitmap.width;
_matrix.d = this.bitmapData.height / NO_COLLISION_TEXTURE_Bitmap.height;

_noCollisionTexture.draw(NO_COLLISION_TEXTURE_Bitmap, _matrix);

//_noCollisionTexture = NO_COLLISION_TEXTURE_Bitmap.clone();
_noCollisionMaterial = new TextureMaterial(_noCollisionTexture);
}

setMaterial(_noCollisionMaterial);
}

public override function deselect() : void
{
super.deselect();

this.setToCollisionDisabledTextureIfNeeded();
}
}
}

2 changes: 1 addition & 1 deletion src/alternativa/editor/prop/Prop.as
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ package alternativa.editor.prop

public static const KILL_GEOMETRY:int = 6;

private static const _matrix:Matrix = new Matrix();
protected static const _matrix:Matrix = new Matrix();

private static var redClass:Class = Prop_redClass;

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 41 additions & 8 deletions src/alternativa/editor/scene/MainScene.as
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ package alternativa.editor.scene
import flash.geom.Vector3D;
import alternativa.engine3d.core.Object3DContainer;
import alternativa.editor.prop.CTFFlagBase;
import alternativa.editor.PropGeneralPropertiesPanel;
import mx.controls.Alert;
import mx.containers.HBox;
import alternativa.editor.SceneContainer;

public class MainScene extends EditorScene
{
Expand All @@ -64,7 +68,7 @@ package alternativa.editor.scene

private var texturePanel:TexturePanel;

private var propertyPanel:Panel;
private const propertyPanel:HBox = new HBox();

private var bonusTypesPanel:BonusRegionPropertiesPanel;

Expand All @@ -85,12 +89,15 @@ package alternativa.editor.scene
private var domSpawnPoint:SpawnPoint;

private var controlPointNameField:ControlPointNameField;

private var propGeneralProperties:PropGeneralPropertiesPanel;

public function MainScene()
{
this.hiddenProps = [];
this.bonusTypesPanel = new BonusRegionPropertiesPanel();
this.killZonePanel = new KillZonePropertiesPanel();
this.propGeneralProperties = new PropGeneralPropertiesPanel();
this._selectablePropTypes = new Set();
this.exporters = {};
this.layers = new Layers();
Expand All @@ -112,6 +119,7 @@ package alternativa.editor.scene
this.createControlPointNameTextField();
collider = new EllipsoidCollider(30,30,30);
__root = root;
this.propertyPanel.percentHeight = this.propertyPanel.percentWidth = 100;
GlobalEventDispatcher.addListener(LayerVisibilityChangeEvent.VISIBILITY_CHANGED,this.onLayerVisibilityChange);
GlobalEventDispatcher.addListener(LayerContentChangeEvent.LAYER_CONTENT_CHANGED,this.onLayerContentChange);
GlobalEventDispatcher.addListener(DominationSpawnLinkStartEvent.DOMINATION_SPAWN_LINK_START,this.onDominationLinkStart);
Expand Down Expand Up @@ -178,6 +186,7 @@ package alternativa.editor.scene

public function exportScene(param1:FileType, param2:FileStream) : void
{
SceneContainer.instance.cursorScene.clear();
FileExporter(this.exporters[param1]).exportToFileStream(param2);
this._changed = false;
}
Expand Down Expand Up @@ -391,7 +400,7 @@ package alternativa.editor.scene

public function setPropertyPanel(param1:Panel) : void
{
this.propertyPanel = param1;
param1.addChild(this.propertyPanel);
this.texturePanel = new TexturePanel();
this.texturePanel.addEventListener(PropListEvent.SELECT,this.onTexturePanelSelect);
}
Expand Down Expand Up @@ -553,8 +562,7 @@ package alternativa.editor.scene
}
this.selectedProps.clear();
this.selectedProp = null;
this.hidePropertyPanelItem(this.bonusTypesPanel);
this.hidePropertyPanelItem(this.texturePanel);
this.hideAllPropertyPanelItems();
}

public function deselectProp(param1:Prop) : void
Expand All @@ -569,6 +577,7 @@ package alternativa.editor.scene

if(this.selectedProps.length > 0)
{
this.selectedProp = this.selectedProps.peek();
this.showPropertyPanel();
}

Expand All @@ -593,7 +602,10 @@ package alternativa.editor.scene
this.selectedProp = loc3;
}
}
this.showPropertyPanel();
if(this.selectedProp != null)
{
this.showPropertyPanel();
}
}

public function selectConflictingProps() : void
Expand Down Expand Up @@ -847,7 +859,7 @@ package alternativa.editor.scene
}
}

public function showPropertyPanel() : void
private function showPropertyPanel() : void
{
var loc1:Map = null;
this.hideAllPropertyPanelItems();
Expand All @@ -874,15 +886,34 @@ package alternativa.editor.scene
}
this.bonusTypesPanel.setBonusRegion(null);

for(var item:* in this.selectedProps)

var item:*;
for(item in this.selectedProps)
{
if(!(item is MeshProp))
return;
}

this.showTexturePanel();


var collisionEnabled:Boolean = (this.selectedProp as MeshProp).collisionEnabled;

for(item in this.selectedProps)
{
if(item is Sprite3DProp)
continue;
if(collisionEnabled != (item as MeshProp).collisionEnabled)
{
return;
}
}

this.showTexturePanel();
this.texturePanel.percentWidth = 100 - this.propGeneralProperties.percentWidth;

this.showPropertyPanelItem(this.propGeneralProperties);

this.propGeneralProperties.init(this.selectedProps, collisionEnabled);
}

private function showTexturePanel() : void
Expand All @@ -891,6 +922,8 @@ package alternativa.editor.scene
if(!loc1)
return;

this.texturePanel.percentWidth = 100;

this.showPropertyPanelItem(this.texturePanel);
if(loc1 != this.currentBitmaps)
{
Expand Down

0 comments on commit 5a18f40

Please sign in to comment.