Add Debug Console settings
1. Adding the ability to customize display, scale (size), shortcuts to the DebugConsole class. 2. Adding a function to utils.py to get Debug Console settings from Render: Armory. 3. Added Debug Console settings to the Armory Project interface: - Enable (default value - False); - Position (Left, Center, Right, default value - Right); - Scale Console (from 0.3 to 10); - Visible. 4. Added transfer of Debug Console settings to exporter.py. 5. Added logical nodes to control DebugConsole while the application is running.
This commit is contained in:
parent
646ff75669
commit
305878db42
26
Sources/armory/logicnode/GetDebugConsoleSettings.hx
Normal file
26
Sources/armory/logicnode/GetDebugConsoleSettings.hx
Normal file
|
@ -0,0 +1,26 @@
|
|||
package armory.logicnode;
|
||||
import armory.trait.internal.DebugConsole;
|
||||
|
||||
class GetDebugConsoleSettings extends LogicNode {
|
||||
|
||||
public function new(tree: LogicTree) {
|
||||
super(tree);
|
||||
}
|
||||
|
||||
override function get(from: Int): Dynamic {
|
||||
#if arm_debug
|
||||
switch(from) {
|
||||
case 0: return armory.trait.internal.DebugConsole.getVisible();
|
||||
case 1: return armory.trait.internal.DebugConsole.getScale();
|
||||
case 2: {
|
||||
switch (armory.trait.internal.DebugConsole.getPosition()) {
|
||||
case PositionStateEnum.LEFT: return "Left";
|
||||
case PositionStateEnum.CENTER: return "Center";
|
||||
case PositionStateEnum.RIGHT: return "Right";
|
||||
}
|
||||
}
|
||||
}
|
||||
#end
|
||||
return null;
|
||||
}
|
||||
}
|
32
Sources/armory/logicnode/SetDebugConsoleSettings.hx
Normal file
32
Sources/armory/logicnode/SetDebugConsoleSettings.hx
Normal file
|
@ -0,0 +1,32 @@
|
|||
package armory.logicnode;
|
||||
import armory.trait.internal.DebugConsole;
|
||||
|
||||
class SetDebugConsoleSettings extends LogicNode {
|
||||
|
||||
public var property0: String;
|
||||
|
||||
public function new(tree: LogicTree) {
|
||||
super(tree);
|
||||
}
|
||||
|
||||
override function run(from: Int) {
|
||||
#if arm_debug
|
||||
var visible: Dynamic = inputs[1].get();
|
||||
armory.trait.internal.DebugConsole.setVisible(visible);
|
||||
|
||||
var scale: Dynamic = inputs[2].get();
|
||||
if ((scale >= 0.3) && (scale <= 10.0))
|
||||
armory.trait.internal.DebugConsole.setScale(scale);
|
||||
|
||||
switch (property0) {
|
||||
case "Left":
|
||||
return armory.trait.internal.DebugConsole.setPosition(PositionStateEnum.LEFT);
|
||||
case "Center":
|
||||
return armory.trait.internal.DebugConsole.setPosition(PositionStateEnum.CENTER);
|
||||
case "Right":
|
||||
return armory.trait.internal.DebugConsole.setPosition(PositionStateEnum.RIGHT);
|
||||
}
|
||||
#end
|
||||
runOutput(0);
|
||||
}
|
||||
}
|
|
@ -19,9 +19,9 @@ class DebugConsole extends Trait {
|
|||
#if (!arm_debug)
|
||||
public function new() { super(); }
|
||||
#else
|
||||
|
||||
public var visible = true;
|
||||
var ui: Zui;
|
||||
|
||||
public static var visible = true;
|
||||
static var ui: Zui;
|
||||
var scaleFactor = 1.0;
|
||||
|
||||
var lastTime = 0.0;
|
||||
|
@ -56,25 +56,64 @@ class DebugConsole extends Trait {
|
|||
public static var debugFloat = 1.0;
|
||||
public static var watchNodes: Array<armory.logicnode.LogicNode> = [];
|
||||
|
||||
public function new(scaleFactor = 1.0) {
|
||||
super();
|
||||
public static var position_console: PositionStateEnum = PositionStateEnum.RIGHT;
|
||||
var shortcut_visible = kha.input.KeyCode.Tilde;
|
||||
var shortcut_scale_in = kha.input.KeyCode.OpenBracket;
|
||||
var shortcut_scale_out = kha.input.KeyCode.CloseBracket;
|
||||
|
||||
public function new(scaleFactor = 1.0, scaleDebugConsole = 1.0, positionDebugConsole = 2, visibleDebugConsole = 1,
|
||||
keyCodeVisible = kha.input.KeyCode.Tilde, keyCodeScaleIn = kha.input.KeyCode.OpenBracket, keyCodeScaleOut = kha.input.KeyCode.CloseBracket) {
|
||||
super();
|
||||
this.scaleFactor = scaleFactor;
|
||||
|
||||
iron.data.Data.getFont("font_default.ttf", function(font: kha.Font) {
|
||||
ui = new Zui({scaleFactor: scaleFactor, font: font});
|
||||
// Set settings
|
||||
setScale(scaleDebugConsole);
|
||||
setVisible(visibleDebugConsole == 1);
|
||||
switch(positionDebugConsole) {
|
||||
case 0: setPosition(PositionStateEnum.LEFT);
|
||||
case 1: setPosition(PositionStateEnum.CENTER);
|
||||
case 2: setPosition(PositionStateEnum.RIGHT);
|
||||
}
|
||||
shortcut_visible = keyCodeVisible;
|
||||
shortcut_scale_in = keyCodeScaleIn;
|
||||
shortcut_scale_out = keyCodeScaleOut;
|
||||
|
||||
notifyOnRender2D(render2D);
|
||||
notifyOnUpdate(update);
|
||||
if (haxeTrace == null) {
|
||||
haxeTrace = haxe.Log.trace;
|
||||
haxe.Log.trace = consoleTrace;
|
||||
}
|
||||
}
|
||||
// Toggle console
|
||||
kha.input.Keyboard.get().notify(null, null, function(char: String) {
|
||||
if (char == "~") visible = !visible;
|
||||
else if (char == "[") { debugFloat -= 0.1; trace(debugFloat); }
|
||||
else if (char == "]") { debugFloat += 0.1; trace(debugFloat); }
|
||||
});
|
||||
kha.input.Keyboard.get().notify(null, function(key: kha.input.KeyCode) {
|
||||
// DebugFloat
|
||||
if (key == kha.input.KeyCode.OpenBracket) {
|
||||
debugFloat -= 0.1;
|
||||
trace("debugFloat = "+ debugFloat);
|
||||
}
|
||||
else if (key == kha.input.KeyCode.CloseBracket){
|
||||
debugFloat += 0.1;
|
||||
trace("debugFloat = "+ debugFloat);
|
||||
}
|
||||
// Shortcut - Visible
|
||||
if (key == shortcut_visible) visible = !visible;
|
||||
// Scale In
|
||||
else if (key == shortcut_scale_in) {
|
||||
var debugScale = getScale() - 0.1;
|
||||
if (debugScale > 0.3) {
|
||||
setScale(debugScale);
|
||||
}
|
||||
}
|
||||
// Scale Out
|
||||
else if (key == shortcut_scale_out) {
|
||||
var debugScale = getScale() + 0.1;
|
||||
if (debugScale < 10.0) {
|
||||
setScale(debugScale);
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -127,10 +166,17 @@ class DebugConsole extends Trait {
|
|||
if (!visible) return;
|
||||
var hwin = Id.handle();
|
||||
var htab = Id.handle({position: 0});
|
||||
var ww = Std.int(280 * scaleFactor);
|
||||
var ww = Std.int(280 * scaleFactor * getScale());
|
||||
// RIGHT
|
||||
var wx = iron.App.w() - ww;
|
||||
var wy = 0;
|
||||
var wh = iron.App.h();
|
||||
// Check position
|
||||
switch (position_console) {
|
||||
case PositionStateEnum.LEFT: wx = 0;
|
||||
case PositionStateEnum.CENTER: wx = Math.round(iron.App.w() / 2 - ww / 2);
|
||||
case PositionStateEnum.RIGHT: wx = iron.App.w() - ww;
|
||||
}
|
||||
|
||||
// var bindG = ui.windowDirty(hwin, wx, wy, ww, wh) || hwin.redraws > 0;
|
||||
var bindG = true;
|
||||
|
@ -654,5 +700,35 @@ class DebugConsole extends Trait {
|
|||
f *= Math.pow(10, precision);
|
||||
return Math.round(f) / Math.pow(10, precision);
|
||||
}
|
||||
|
||||
public static function getVisible(): Bool {
|
||||
return visible;
|
||||
}
|
||||
|
||||
public static function setVisible(value: Bool) {
|
||||
visible = value;
|
||||
}
|
||||
|
||||
public static function getScale(): Float {
|
||||
return ui.SCALE();
|
||||
}
|
||||
|
||||
public static function setScale(value: Float) {
|
||||
ui.setScale(value);
|
||||
}
|
||||
|
||||
public static function setPosition(value: PositionStateEnum) {
|
||||
position_console = value;
|
||||
}
|
||||
|
||||
public static function getPosition(): PositionStateEnum {
|
||||
return position_console;
|
||||
}
|
||||
#end
|
||||
}
|
||||
|
||||
enum PositionStateEnum {
|
||||
LEFT;
|
||||
CENTER;
|
||||
RIGHT;
|
||||
}
|
|
@ -2605,10 +2605,25 @@ class ArmoryExporter:
|
|||
if 'traits' not in self.output:
|
||||
self.output['traits'] = []
|
||||
ArmoryExporter.export_ui = True
|
||||
# Position
|
||||
debug_console_pos_type = 2
|
||||
if (wrd.arm_debug_console_position == 'Left'):
|
||||
debug_console_pos_type = 0
|
||||
elif (wrd.arm_debug_console_position == 'Center'):
|
||||
debug_console_pos_type = 1
|
||||
else:
|
||||
debug_console_pos_type = 2
|
||||
# Parameters
|
||||
out_trait = {
|
||||
'type': 'Script',
|
||||
'class_name': 'armory.trait.internal.DebugConsole',
|
||||
'parameters': [str(arm.utils.get_ui_scale())]
|
||||
'parameters': [str(arm.utils.get_ui_scale()),
|
||||
str(wrd.arm_debug_console_scale),
|
||||
str(debug_console_pos_type),
|
||||
str(int(wrd.arm_debug_console_visible)),
|
||||
str(int(arm.utils.get_debug_console_visible_sc())),
|
||||
str(int(arm.utils.get_debug_console_scale_in_sc())),
|
||||
str(int(arm.utils.get_debug_console_scale_out_sc()))]
|
||||
}
|
||||
self.output['traits'].append(out_trait)
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
from arm.logicnode.arm_nodes import *
|
||||
|
||||
class GetDebugConsoleSettings(ArmLogicTreeNode):
|
||||
"""Get Debug Console Settings"""
|
||||
bl_idname = 'LNGetDebugConsoleSettings'
|
||||
bl_label = 'Get Debug Console Settings'
|
||||
arm_version = 1
|
||||
|
||||
def init(self, context):
|
||||
super(GetDebugConsoleSettings, self).init(context)
|
||||
self.add_output('NodeSocketBool', 'Visible')
|
||||
self.add_output('NodeSocketFloat', 'Scale')
|
||||
self.add_output('NodeSocketString', 'Position')
|
||||
|
||||
# Add Node
|
||||
add_node(GetDebugConsoleSettings, category=PKG_AS_CATEGORY)
|
|
@ -0,0 +1,26 @@
|
|||
from arm.logicnode.arm_nodes import *
|
||||
|
||||
class SetDebugConsoleSettings(ArmLogicTreeNode):
|
||||
"""Set Debug Console Settings"""
|
||||
bl_idname = 'LNSetDebugConsoleSettings'
|
||||
bl_label = 'Set Debug Console Settings'
|
||||
arm_version = 1
|
||||
|
||||
property0: EnumProperty(
|
||||
items = [('Left', 'Left', 'Left'),
|
||||
('Center', 'Center', 'Center'),
|
||||
('Right', 'Right', 'Right')],
|
||||
name='', default='Right')
|
||||
|
||||
def init(self, context):
|
||||
super(SetDebugConsoleSettings, self).init(context)
|
||||
self.add_input('ArmNodeSocketAction', 'In')
|
||||
self.add_input('NodeSocketBool', 'Visible')
|
||||
self.add_input('NodeSocketFloat', 'Scale')
|
||||
self.inputs[-1].default_value = 1.0
|
||||
self.add_output('ArmNodeSocketAction', 'Out')
|
||||
|
||||
def draw_buttons(self, context, layout):
|
||||
layout.prop(self, 'property0')
|
||||
|
||||
add_node(SetDebugConsoleSettings, category=PKG_AS_CATEGORY)
|
|
@ -68,7 +68,15 @@ def init_properties():
|
|||
('Viewport', 'Viewport', 'Viewport')],
|
||||
name="Camera", description="Viewport camera", default='Scene', update=assets.invalidate_compiler_cache)
|
||||
bpy.types.World.arm_play_scene = PointerProperty(name="Scene", description="Scene to launch", update=assets.invalidate_compiler_cache, type=bpy.types.Scene)
|
||||
bpy.types.World.arm_debug_console = BoolProperty(name="Debug Console", description="Show inspector in player and enable debug draw.\nRequires that Zui is not disabled", default=False, update=assets.invalidate_shader_cache)
|
||||
# Debug Console
|
||||
bpy.types.World.arm_debug_console = BoolProperty(name="Enable", description="Show inspector in player and enable debug draw.\nRequires that Zui is not disabled", default=arm.utils.get_debug_console_auto(), update=assets.invalidate_shader_cache)
|
||||
bpy.types.World.arm_debug_console_position = EnumProperty(
|
||||
items=[('Left', 'Left', 'Left'),
|
||||
('Center', 'Center', 'Center'),
|
||||
('Right', 'Right', 'Right')],
|
||||
name="Position", description="Position Debug Console", default='Right', update=assets.invalidate_shader_cache)
|
||||
bpy.types.World.arm_debug_console_scale = FloatProperty(name="Scale Console", description="Scale Debug Console", default=1.0, min=0.3, max=10.0, subtype='FACTOR', update=assets.invalidate_shader_cache)
|
||||
bpy.types.World.arm_debug_console_visible = BoolProperty(name="Visible", description="Setting the console visibility at application start", default=True, update=assets.invalidate_shader_cache)
|
||||
bpy.types.World.arm_verbose_output = BoolProperty(name="Verbose Output", description="Print additional information to the console during compilation", default=False)
|
||||
bpy.types.World.arm_runtime = EnumProperty(
|
||||
items=[('Krom', 'Krom', 'Krom'),
|
||||
|
@ -303,6 +311,10 @@ def create_wrd():
|
|||
def init_properties_on_load():
|
||||
if not 'Arm' in bpy.data.worlds:
|
||||
init_properties()
|
||||
# New project?
|
||||
if bpy.data.filepath == '':
|
||||
wrd = bpy.data.worlds['Arm']
|
||||
wrd.arm_debug_console = arm.utils.get_debug_console_auto()
|
||||
arm.utils.fetch_script_names()
|
||||
|
||||
def update_armory_world():
|
||||
|
|
|
@ -445,9 +445,6 @@ class ARM_PT_ProjectFlagsPanel(bpy.types.Panel):
|
|||
layout.use_property_split = True
|
||||
layout.use_property_decorate = False
|
||||
wrd = bpy.data.worlds['Arm']
|
||||
row = layout.row()
|
||||
row.enabled = wrd.arm_ui != 'Disabled'
|
||||
row.prop(wrd, 'arm_debug_console')
|
||||
layout.prop(wrd, 'arm_verbose_output')
|
||||
layout.prop(wrd, 'arm_cache_build')
|
||||
layout.prop(wrd, 'arm_live_patch')
|
||||
|
@ -462,6 +459,32 @@ class ARM_PT_ProjectFlagsPanel(bpy.types.Panel):
|
|||
layout.prop(wrd, 'arm_texture_quality')
|
||||
layout.prop(wrd, 'arm_sound_quality')
|
||||
|
||||
class ARM_PT_ProjectFlagsDebugConsolePanel(bpy.types.Panel):
|
||||
bl_label = "Debug Console"
|
||||
bl_space_type = "PROPERTIES"
|
||||
bl_region_type = "WINDOW"
|
||||
bl_context = "render"
|
||||
bl_options = {'DEFAULT_CLOSED'}
|
||||
bl_parent_id = "ARM_PT_ProjectFlagsPanel"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.use_property_split = True
|
||||
layout.use_property_decorate = False
|
||||
wrd = bpy.data.worlds['Arm']
|
||||
row = layout.row()
|
||||
row.enabled = wrd.arm_ui != 'Disabled'
|
||||
row.prop(wrd, 'arm_debug_console')
|
||||
row = layout.row()
|
||||
row.enabled = wrd.arm_debug_console
|
||||
row.prop(wrd, 'arm_debug_console_position')
|
||||
row = layout.row()
|
||||
row.enabled = wrd.arm_debug_console
|
||||
row.prop(wrd, 'arm_debug_console_scale')
|
||||
row = layout.row()
|
||||
row.enabled = wrd.arm_debug_console
|
||||
row.prop(wrd, 'arm_debug_console_visible')
|
||||
|
||||
class ARM_PT_ProjectWindowPanel(bpy.types.Panel):
|
||||
bl_label = "Window"
|
||||
bl_space_type = "PROPERTIES"
|
||||
|
@ -1990,6 +2013,7 @@ def register():
|
|||
bpy.utils.register_class(ARM_PT_ArmoryExporterPanel)
|
||||
bpy.utils.register_class(ARM_PT_ArmoryProjectPanel)
|
||||
bpy.utils.register_class(ARM_PT_ProjectFlagsPanel)
|
||||
bpy.utils.register_class(ARM_PT_ProjectFlagsDebugConsolePanel)
|
||||
bpy.utils.register_class(ARM_PT_ProjectWindowPanel)
|
||||
bpy.utils.register_class(ARM_PT_ProjectModulesPanel)
|
||||
bpy.utils.register_class(ARM_PT_RenderPathPanel)
|
||||
|
@ -2053,6 +2077,7 @@ def unregister():
|
|||
bpy.utils.unregister_class(ARM_PT_ArmoryPlayerPanel)
|
||||
bpy.utils.unregister_class(ARM_PT_ArmoryExporterPanel)
|
||||
bpy.utils.unregister_class(ARM_PT_ArmoryProjectPanel)
|
||||
bpy.utils.unregister_class(ARM_PT_ProjectFlagsDebugConsolePanel)
|
||||
bpy.utils.unregister_class(ARM_PT_ProjectFlagsPanel)
|
||||
bpy.utils.unregister_class(ARM_PT_ProjectWindowPanel)
|
||||
bpy.utils.unregister_class(ARM_PT_ProjectModulesPanel)
|
||||
|
|
|
@ -199,6 +199,26 @@ def get_save_on_build():
|
|||
addon_prefs = preferences.addons['armory'].preferences
|
||||
return False if not hasattr(addon_prefs, 'save_on_build') else addon_prefs.save_on_build
|
||||
|
||||
def get_debug_console_auto():
|
||||
preferences = bpy.context.preferences
|
||||
addon_prefs = preferences.addons['armory'].preferences
|
||||
return False if not hasattr(addon_prefs, 'debug_console_auto') else addon_prefs.debug_console_auto
|
||||
|
||||
def get_debug_console_visible_sc():
|
||||
preferences = bpy.context.preferences
|
||||
addon_prefs = preferences.addons['armory'].preferences
|
||||
return 192 if not hasattr(addon_prefs, 'debug_console_visible_sc') else addon_prefs.debug_console_visible_sc
|
||||
|
||||
def get_debug_console_scale_in_sc():
|
||||
preferences = bpy.context.preferences
|
||||
addon_prefs = preferences.addons['armory'].preferences
|
||||
return 219 if not hasattr(addon_prefs, 'debug_console_scale_in_sc') else addon_prefs.debug_console_scale_in_sc
|
||||
|
||||
def get_debug_console_scale_out_sc():
|
||||
preferences = bpy.context.preferences
|
||||
addon_prefs = preferences.addons['armory'].preferences
|
||||
return 221 if not hasattr(addon_prefs, 'debug_console_scale_out_sc') else addon_prefs.debug_console_scale_out_sc
|
||||
|
||||
def get_viewport_controls():
|
||||
preferences = bpy.context.preferences
|
||||
addon_prefs = preferences.addons['armory'].preferences
|
||||
|
|
Loading…
Reference in a new issue