Skip to content

Commit

Permalink
2.5D Editor Viewport for Mono C#
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronfranke committed Mar 1, 2020
1 parent 99175c7 commit f70e9ce
Show file tree
Hide file tree
Showing 17 changed files with 1,155 additions and 21 deletions.
5 changes: 3 additions & 2 deletions mono/2.5d/2.5D Demo (Mono C#).csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -53,6 +53,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="addons\node25d-cs\Basis25D.cs" />
<Compile Include="addons\node25d-cs\main_screen\Gizmo25D.cs" />
<Compile Include="addons\node25d-cs\Node25D.cs" />
<Compile Include="addons\node25d-cs\ShadowMath25D.cs" />
<Compile Include="addons\node25d-cs\Transform25D.cs" />
Expand All @@ -63,4 +64,4 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
7 changes: 7 additions & 0 deletions mono/2.5d/addons/godot-plugin-refresher/plugin.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[plugin]

name="Godot Plugin Refresher"
description="A toolbar addition to facilitate toggling off/on a selected plugin."
author="willnationsdev"
version="1.0"
script="plugin_refresher_plugin.gd"
59 changes: 59 additions & 0 deletions mono/2.5d/addons/godot-plugin-refresher/plugin_refresher.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
tool
extends HBoxContainer

const ADDONS_PATH = "res://addons/"
const PLUGIN_PATH = "godot-plugin-refresher"

signal request_refresh_plugin(p_name)
signal confirm_refresh_plugin(p_name)

onready var options = $OptionButton

func _ready():
$RefreshButton.icon = get_icon('Reload', 'EditorIcons')
reload_items()

func reload_items():
if not options:
return
var dir = Directory.new()
dir.change_dir(ADDONS_PATH)
dir.list_dir_begin(true, true)
var file = dir.get_next()
options.clear()
while file:
if dir.dir_exists(ADDONS_PATH.plus_file(file)) and file != PLUGIN_PATH:
options.add_item(file)
file = dir.get_next()

func select_plugin(p_name):
if not options:
return
if p_name == null or p_name.empty():
return

for idx in options.get_item_count():
var plugin = options.get_item_text(idx)
if plugin == p_name:
options.selected = options.get_item_id(idx)
break

func _on_RefreshButton_pressed():
if options.selected == -1:
return # nothing selected

var plugin = options.get_item_text(options.selected)
if not plugin or plugin.empty():
return
emit_signal("request_refresh_plugin", plugin)

func show_warning(p_name):
$ConfirmationDialog.dialog_text = """
Plugin `%s` is currently disabled.\n
Do you want to enable it now?
""" % [p_name]
$ConfirmationDialog.popup_centered()

func _on_ConfirmationDialog_confirmed():
var plugin = options.get_item_text(options.selected)
emit_signal('confirm_refresh_plugin', plugin)
54 changes: 54 additions & 0 deletions mono/2.5d/addons/godot-plugin-refresher/plugin_refresher.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://addons/godot-plugin-refresher/plugin_refresher.gd" type="Script" id=1]

[sub_resource type="Image" id=3]
data = {
"data": PoolByteArray( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
"format": "LumAlpha8",
"height": 16,
"mipmaps": false,
"width": 16
}

[sub_resource type="ImageTexture" id=2]
flags = 4
flags = 4
image = SubResource( 3 )
size = Vector2( 16, 16 )

[node name="PluginRefresher" type="HBoxContainer"]
margin_right = 40.0
margin_bottom = 40.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="VSeparator" type="VSeparator" parent="."]
margin_right = 4.0
margin_bottom = 40.0

[node name="OptionButton" type="OptionButton" parent="."]
margin_left = 8.0
margin_right = 158.0
margin_bottom = 40.0
rect_min_size = Vector2( 150, 0 )
text = "node25d"
items = [ "node25d", null, false, 0, null ]
selected = 0

[node name="RefreshButton" type="ToolButton" parent="."]
margin_left = 162.0
margin_right = 190.0
margin_bottom = 40.0
icon = SubResource( 2 )

[node name="ConfirmationDialog" type="ConfirmationDialog" parent="."]
margin_right = 278.0
margin_bottom = 110.0
rect_min_size = Vector2( 300, 70 )
window_title = "Plugin Refresher"
dialog_autowrap = true
[connection signal="pressed" from="RefreshButton" to="." method="_on_RefreshButton_pressed"]
[connection signal="confirmed" from="ConfirmationDialog" to="." method="_on_ConfirmationDialog_confirmed"]
97 changes: 97 additions & 0 deletions mono/2.5d/addons/godot-plugin-refresher/plugin_refresher_plugin.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
tool
extends EditorPlugin

const PLUGIN_CONFIG_DIR = 'plugins/plugin_refresher'
const PLUGIN_CONFIG = 'settings.cfg'
const SETTINGS = 'settings'
const SETTING_RECENT = 'recently_used'

var plugin_config = ConfigFile.new()

const PluginRefresherScene = preload("plugin_refresher.tscn")

var refresher

func _enter_tree():
refresher = PluginRefresherScene.instance()
add_control_to_container(CONTAINER_TOOLBAR, refresher)

# Watch whether any plugin is changed, added or removed on the filesystem
var efs = get_editor_interface().get_resource_filesystem()
efs.connect("filesystem_changed", self, "_on_filesystem_changed")

refresher.connect("request_refresh_plugin", self, "_on_request_refresh_plugin")
refresher.connect("confirm_refresh_plugin", self, "_on_confirm_refresh_plugin")

_load_settings()


func _exit_tree():
remove_control_from_container(CONTAINER_TOOLBAR, refresher)
refresher.free()


func _load_settings():
var path = get_config_path()

var fs = Directory.new()
if not fs.file_exists(path):
# Create new if running for the first time
var config = ConfigFile.new()
fs.make_dir_recursive(path.get_base_dir())
config.save(path)
else:
plugin_config.load(path)


func _save_settings():
plugin_config.save(get_config_path())


func get_config_path():
var dir = get_editor_interface().get_editor_settings().get_project_settings_dir()
var home = dir.plus_file(PLUGIN_CONFIG_DIR)
var path = home.plus_file(PLUGIN_CONFIG)

return path


func _on_filesystem_changed():
if refresher:
refresher.reload_items()
refresher.select_plugin(get_recent_plugin())


func get_recent_plugin():
if not plugin_config.has_section_key(SETTINGS, SETTING_RECENT):
return null # not saved yet

var recent = plugin_config.get_value(SETTINGS, SETTING_RECENT)
return recent


func _on_request_refresh_plugin(p_name):
assert(not p_name.empty())

var disabled = not get_editor_interface().is_plugin_enabled(p_name)
if disabled:
refresher.show_warning(p_name)
else:
refresh_plugin(p_name)


func _on_confirm_refresh_plugin(p_name):
refresh_plugin(p_name)


func refresh_plugin(p_name):
print("Refreshing plugin: ", p_name)

var enabled = get_editor_interface().is_plugin_enabled(p_name)
if enabled: # can only disable an active plugin
get_editor_interface().set_plugin_enabled(p_name, false)

get_editor_interface().set_plugin_enabled(p_name, true)

plugin_config.set_value(SETTINGS, SETTING_RECENT, p_name)
_save_settings()
50 changes: 40 additions & 10 deletions mono/2.5d/addons/node25d-cs/Node25D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ protected void Node25DReady()
/// </summary>
protected void Node25DProcess()
{
if (transform25D.basis == new Basis25D())
{
SetViewMode(0);
}
CheckViewMode();
if (spatialNode != null)
{
Expand All @@ -92,34 +96,60 @@ protected void Node25DProcess()
{
spatialNode = GetChild<Spatial>(0);
}

GlobalPosition = transform25D.FlatPosition;
}

public void SetViewMode(int viewModeIndex)
{
switch (viewModeIndex)
{
case 0:
transform25D.basis = Basis25D.FortyFive * SCALE;
break;
case 1:
transform25D.basis = Basis25D.Isometric * SCALE;
break;
case 2:
transform25D.basis = Basis25D.TopDown * SCALE;
break;
case 3:
transform25D.basis = Basis25D.FrontSide * SCALE;
break;
case 4:
transform25D.basis = Basis25D.ObliqueY * SCALE;
break;
case 5:
transform25D.basis = Basis25D.ObliqueZ * SCALE;
break;
}
}

private void CheckViewMode()
{
if (Input.IsActionJustPressed("top_down_mode"))
if (Input.IsActionJustPressed("forty_five_mode"))
{
transform25D.basis = Basis25D.TopDown * SCALE;
SetViewMode(0);
}
else if (Input.IsActionJustPressed("front_side_mode"))
else if (Input.IsActionJustPressed("isometric_mode"))
{
transform25D.basis = Basis25D.FrontSide * SCALE;
SetViewMode(1);
}
else if (Input.IsActionJustPressed("forty_five_mode"))
else if (Input.IsActionJustPressed("top_down_mode"))
{
transform25D.basis = Basis25D.FortyFive * SCALE;
SetViewMode(2);
}
else if (Input.IsActionJustPressed("isometric_mode"))
else if (Input.IsActionJustPressed("front_side_mode"))
{
transform25D.basis = Basis25D.Isometric * SCALE;
SetViewMode(3);
}
else if (Input.IsActionJustPressed("oblique_y_mode"))
{
transform25D.basis = Basis25D.ObliqueY * SCALE;
SetViewMode(4);
}
else if (Input.IsActionJustPressed("oblique_z_mode"))
{
transform25D.basis = Basis25D.ObliqueZ * SCALE;
SetViewMode(5);
}
}

Expand Down
Loading

0 comments on commit f70e9ce

Please sign in to comment.