Skip to content

Commit

Permalink
0.3.7.738
Browse files Browse the repository at this point in the history
  • Loading branch information
gleblebedev committed Dec 3, 2023
1 parent 8925c36 commit ae3397d
Show file tree
Hide file tree
Showing 11 changed files with 402 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
]
},
"unofficial.Urho3DNet.Editor": {
"version": "0.3.7.733",
"version": "0.3.7.738",
"commands": [
"rbfx"
]
Expand Down
105 changes: 105 additions & 0 deletions Content/Common/Data/Objects/Tile.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,111 @@
},
{
"_typeName": "RigidBody"
},
{
"_typeName": "Tile",
"attributes": [
{
"name": "Link",
"type": "Int",
"value": 1
},
{
"name": "LinkSource",
"type": "Int",
"value": 2
},
{
"name": "LinkTarget",
"type": "Int",
"value": 3
}
]
}
],
"nodes": [
{
"_id": 1,
"attributes": [
{
"name": "Is Enabled",
"type": "Bool",
"value": false
},
{
"name": "Name",
"type": "String",
"value": "Link"
}
],
"components": [
{
"_typeName": "AnimatedModel",
"attributes": [
{
"name": "Model",
"type": "ResourceRef",
"value": "Model;Models/Link.mdl"
},
{
"name": "Material",
"type": "ResourceRefList",
"value": "Material;Materials/White.material"
},
{
"name": "Bone Animation Enabled",
"type": "VariantVector",
"value": [
{
"type": "Bool",
"value": true
},
{
"type": "Bool",
"value": true
},
{
"type": "Bool",
"value": true
}
]
}
]
}
],
"nodes": [
{
"attributes": [
{
"name": "Name",
"type": "String",
"value": "Root"
}
],
"nodes": [
{
"_id": 2,
"attributes": [
{
"name": "Name",
"type": "String",
"value": "A"
}
]
},
{
"_id": 3,
"attributes": [
{
"name": "Name",
"type": "String",
"value": "B"
}
]
}
]
}
]
}
]
},
Expand Down
4 changes: 2 additions & 2 deletions Content/Common/Data/Scenes/Scene.scene
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0"?>
<resource _id="1">
<attributes>
<attribute name="Next Node ID" type="Int" value="31" />
<attribute name="Next Component ID" type="Int" value="57" />
<attribute name="Next Node ID" type="Int" value="21" />
<attribute name="Next Component ID" type="Int" value="42" />
</attributes>
<components>
<component _id="1" _typeName="Octree" />
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Urho3DNetVersion>0.3.7.733</Urho3DNetVersion>
<Urho3DNetVersion>0.3.7.738</Urho3DNetVersion>
</PropertyGroup>
</Project>
133 changes: 107 additions & 26 deletions RbfxTemplate/GameState.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.IO;
using RbfxTemplate.GameStates;
using Urho3DNet;

namespace RbfxTemplate
Expand All @@ -14,13 +15,37 @@ public sealed class GameState : RmlUIStateBase
private readonly Viewport _viewport;

private Dictionary<string, Material> _tileMaterials = new Dictionary<string, Material>();
private readonly Node _link;

private PickSate _pickSate;
private DragSate _dragSate;
private StateBase _state;

public StateBase State
{
get
{
return _state;
}
set
{
if (_state != value)
{
_state?.Deactivate();
_state = value;
_state?.Activate();
}
}
}

private PhysicsRaycastResult _raycastResult;

public GameState(UrhoPluginApplication app) : base(app, "UI/GameScreen.rml")
{
MouseMode = MouseMode.MmFree;
IsMouseVisible = true;

_raycastResult = new PhysicsRaycastResult();

_app = app;
_scene = Context.CreateObject<Scene>();
_scene.Ptr.LoadXML("Scenes/Scene.scene");
Expand All @@ -41,23 +66,25 @@ public GameState(UrhoPluginApplication app) : base(app, "UI/GameScreen.rml")
Context.ResourceCache.GetResource<Material>("Materials/Emoji/" + matName);
}

_link = _scene.Ptr.GetChild("Link", true);

Vector3 pos = Vector3.Zero;
var tilePrefab = Context.ResourceCache.GetResource<PrefabResource>("Objects/Tile.prefab");
foreach (var tileMaterial in _tileMaterials)
{
var tile = _scene.Ptr.CreateChild();
var prefabReference = tile.CreateComponent<PrefabReference>();
prefabReference.SetPrefab(Context.ResourceCache.GetResource<PrefabResource>("Objects/Tile.prefab"));
prefabReference.Inline(PrefabInlineFlag.None);
var tile = _scene.Ptr.InstantiatePrefab(tilePrefab);
//var prefabReference = tile.CreateComponent<PrefabReference>();
//prefabReference.SetPrefab();
//prefabReference.Inline(PrefabInlineFlag.None);
var model = tile.GetComponent<StaticModel>(true);
model.SetMaterial(tileMaterial.Value);
tile.Position = pos;
pos += Vector3.Forward;
}

Deactivate();
_pickSate = new PickSate(this);
_dragSate = new DragSate(this);
State = _pickSate;

Deactivate();
}

public override void OnDataModelInitialized(GameRmlUIComponent component)
Expand All @@ -72,39 +99,65 @@ public override void Activate(StringVariantMap bundle)
SubscribeToEvent(E.MouseButtonUp, HandleMouseUp);
SubscribeToEvent(E.MouseMove, HandleMouseMove);

SubscribeToEvent(E.TouchBegin, HandleTouchBegin);
SubscribeToEvent(E.TouchEnd, HandleTouchEnd);
SubscribeToEvent(E.TouchMove, HandleTouchMove);

_scene.Ptr.IsUpdateEnabled = true;



base.Activate(bundle);
}

private void HandleMouseMove(StringHash arg1, VariantMap arg2)
private void HandleTouchBegin(VariantMap args)
{
if (!_link.IsEnabled)
return;
var touchId = args[E.TouchBegin.TouchID].Int;
var x = args[E.TouchBegin.X].Int;
var y = args[E.TouchBegin.Y].Int;
_state.HandleTouchBegin(touchId, new IntVector2(x,y));
}

var x = arg2[E.MouseMove.X].Int;
var y = arg2[E.MouseMove.Y].Int;
var ray = _viewport.GetScreenRay(x, y);
var normal = Vector3.Up;
var d = normal.DotProduct(ray.Direction);
float t = -(normal.DotProduct(ray.Origin) + 0.0f) / d;
var a = _link.GetChild("A", true);
var b = _link.GetChild("B", true);
b.Position = ray.Origin + ray.Direction * t;
a.LookAt(b.Position);
b.LookAt(a.Position);
private void HandleTouchEnd(VariantMap args)
{
var touchId = args[E.TouchEnd.TouchID].Int;
var x = args[E.TouchEnd.X].Int;
var y = args[E.TouchEnd.Y].Int;
_state.HandleTouchEnd(touchId, new IntVector2(x, y));
}

private void HandleMouseUp(StringHash arg1, VariantMap arg2)
private void HandleTouchMove(VariantMap args)
{
_link.IsEnabled = false;
var touchId = args[E.TouchMove.TouchID].Int;
var x = args[E.TouchMove.X].Int;
var y = args[E.TouchMove.Y].Int;
_state.HandleTouchMove(touchId, new IntVector2(x, y));
}

private void HandleMouseDown(StringHash arg1, VariantMap arg2)
private void HandleMouseMove(VariantMap args)
{
_link.IsEnabled = true;
var buttons = args[E.MouseMove.Buttons].Int;
var qualifiers = args[E.MouseMove.Qualifiers].Int;
var x = args[E.MouseMove.X].Int;
var y = args[E.MouseMove.Y].Int;
_state.HandleMouseMove(new IntVector2(x, y), buttons, qualifiers);

}

private void HandleMouseUp(StringHash arg1, VariantMap args)
{
var buttons = args[E.MouseButtonUp.Buttons].Int;
var qualifiers = args[E.MouseButtonUp.Qualifiers].Int;
var button = args[E.MouseButtonUp.Button].Int;
_state.HandleMouseUp(button, Context.Input.MousePosition, buttons, qualifiers);
}

private void HandleMouseDown(StringHash arg1, VariantMap args)
{
var buttons = args[E.MouseButtonDown.Buttons].Int;
var qualifiers = args[E.MouseButtonDown.Qualifiers].Int;
var button = args[E.MouseButtonDown.Button].Int;
_state.HandleMouseDown(button, Context.Input.MousePosition, buttons, qualifiers);
}

public override void Deactivate()
Expand Down Expand Up @@ -132,5 +185,33 @@ private void HandleKeyUp(VariantMap args)
return;
}
}
public Ray GetScreenRay(IntVector2 inputMousePosition)
{
return _viewport.GetScreenRay(inputMousePosition.X, inputMousePosition.Y);
}

public Tile PickTile(IntVector2 inputMousePosition)
{
var ray = GetScreenRay(inputMousePosition);
var physics = _scene.Ptr.GetComponent<PhysicsWorld>();
physics.RaycastSingle(_raycastResult, ray, 100);
if (_raycastResult.Body != null)
{
return _raycastResult.Body.Node.GetComponent<Tile>() ?? _raycastResult.Body.Node.GetParentComponent<Tile>(true);
}
return null;
}

public void DragTile(Tile tile, int? touchId)
{
_dragSate.TrackTile(tile, touchId);
State = _dragSate;

}

public void LinkTiles(Tile pickTile)
{
State = _pickSate;
}
}
}
Loading

0 comments on commit ae3397d

Please sign in to comment.