mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 19:10:38 +02:00
Merge pull request #3928 from huffman/entity-tool-settings
Entity tool settings
This commit is contained in:
commit
55ec455f77
3 changed files with 97 additions and 30 deletions
|
@ -29,11 +29,11 @@
|
||||||
elPosY.value = origin.y.toFixed(2);
|
elPosY.value = origin.y.toFixed(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.minorGridSpacing) {
|
if (data.minorGridSpacing !== undefined) {
|
||||||
elMinorSpacing.value = data.minorGridSpacing;
|
elMinorSpacing.value = data.minorGridSpacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.majorGridEvery) {
|
if (data.majorGridEvery !== undefined) {
|
||||||
elMajorSpacing.value = data.majorGridEvery;
|
elMajorSpacing.value = data.majorGridEvery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@
|
||||||
gridColor = data.gridColor;
|
gridColor = data.gridColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.elSnapToGrid !== undefined) {
|
if (data.snapToGrid !== undefined) {
|
||||||
elSnapToGrid.checked = data.snapToGrid == true;
|
elSnapToGrid.checked = data.snapToGrid == true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
var SETTING_GRID_VISIBLE = 'gridVisible';
|
||||||
|
var SETTING_GRID_SNAP_TO_GRID = 'gridSnapToGrid';
|
||||||
|
var SETTING_GRID_MINOR_WIDTH= 'gridMinorWidth';
|
||||||
|
var SETTING_GRID_MAJOR_EVERY = 'gridMajorEvery';
|
||||||
|
var SETTING_GRID_COLOR = 'gridColor';
|
||||||
|
|
||||||
Grid = function(opts) {
|
Grid = function(opts) {
|
||||||
var that = {};
|
var that = {};
|
||||||
|
|
||||||
|
@ -12,9 +18,6 @@ Grid = function(opts) {
|
||||||
|
|
||||||
var worldSize = 16384;
|
var worldSize = 16384;
|
||||||
|
|
||||||
var minorGridWidth = 0.5;
|
|
||||||
var majorGridWidth = 1.5;
|
|
||||||
|
|
||||||
var snapToGrid = false;
|
var snapToGrid = false;
|
||||||
|
|
||||||
var gridOverlay = Overlays.addOverlay("grid", {
|
var gridOverlay = Overlays.addOverlay("grid", {
|
||||||
|
@ -23,7 +26,7 @@ Grid = function(opts) {
|
||||||
color: { red: 0, green: 0, blue: 128 },
|
color: { red: 0, green: 0, blue: 128 },
|
||||||
alpha: 1.0,
|
alpha: 1.0,
|
||||||
rotation: Quat.fromPitchYawRollDegrees(90, 0, 0),
|
rotation: Quat.fromPitchYawRollDegrees(90, 0, 0),
|
||||||
minorGridWidth: 0.1,
|
minorGridSpacing: 0.1,
|
||||||
majorGridEvery: 2,
|
majorGridEvery: 2,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -40,18 +43,39 @@ Grid = function(opts) {
|
||||||
that.getSnapToGrid = function() { return snapToGrid; };
|
that.getSnapToGrid = function() { return snapToGrid; };
|
||||||
|
|
||||||
that.setEnabled = function(enabled) {
|
that.setEnabled = function(enabled) {
|
||||||
|
if (that.enabled != enabled) {
|
||||||
that.enabled = enabled;
|
that.enabled = enabled;
|
||||||
|
|
||||||
|
if (enabled) {
|
||||||
|
if (selectionManager.hasSelection()) {
|
||||||
|
that.setPosition(selectionManager.getBottomPosition());
|
||||||
|
} else {
|
||||||
|
that.setPosition(MyAvatar.position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
updateGrid();
|
updateGrid();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
that.setVisible = function(visible, noUpdate) {
|
that.setVisible = function(visible, noUpdate) {
|
||||||
|
if (visible != that.visible) {
|
||||||
that.visible = visible;
|
that.visible = visible;
|
||||||
updateGrid();
|
updateGrid();
|
||||||
|
|
||||||
|
if (visible) {
|
||||||
|
if (selectionManager.hasSelection()) {
|
||||||
|
that.setPosition(selectionManager.getBottomPosition());
|
||||||
|
} else {
|
||||||
|
that.setPosition(MyAvatar.position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!noUpdate) {
|
if (!noUpdate) {
|
||||||
that.emitUpdate();
|
that.emitUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
that.snapToSurface = function(position, dimensions) {
|
that.snapToSurface = function(position, dimensions) {
|
||||||
if (!snapToGrid) {
|
if (!snapToGrid) {
|
||||||
|
@ -171,7 +195,7 @@ Grid = function(opts) {
|
||||||
Overlays.editOverlay(gridOverlay, {
|
Overlays.editOverlay(gridOverlay, {
|
||||||
position: { x: origin.y, y: origin.y, z: -origin.y },
|
position: { x: origin.y, y: origin.y, z: -origin.y },
|
||||||
visible: that.visible && that.enabled,
|
visible: that.visible && that.enabled,
|
||||||
minorGridWidth: minorGridSpacing,
|
minorGridSpacing: minorGridSpacing,
|
||||||
majorGridEvery: majorGridEvery,
|
majorGridEvery: majorGridEvery,
|
||||||
color: gridColor,
|
color: gridColor,
|
||||||
alpha: gridAlpha,
|
alpha: gridAlpha,
|
||||||
|
@ -181,15 +205,43 @@ Grid = function(opts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
|
saveSettings();
|
||||||
|
|
||||||
Overlays.deleteOverlay(gridOverlay);
|
Overlays.deleteOverlay(gridOverlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadSettings() {
|
||||||
|
that.setVisible(Settings.getValue(SETTING_GRID_VISIBLE) == "true", true);
|
||||||
|
snapToGrid = Settings.getValue(SETTING_GRID_SNAP_TO_GRID) == "true";
|
||||||
|
minorGridSpacing = parseFloat(Settings.getValue(SETTING_GRID_MINOR_WIDTH), 10);
|
||||||
|
majorGridEvery = parseInt(Settings.getValue(SETTING_GRID_MAJOR_EVERY), 10);
|
||||||
|
try {
|
||||||
|
var newColor = JSON.parse(Settings.getValue(SETTING_GRID_COLOR));
|
||||||
|
if (newColor.red !== undefined && newColor.green !== undefined && newColor.blue !== undefined) {
|
||||||
|
gridColor.red = newColor.red;
|
||||||
|
gridColor.green = newColor.green;
|
||||||
|
gridColor.blue = newColor.blue;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
|
updateGrid();
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveSettings() {
|
||||||
|
Settings.setValue(SETTING_GRID_VISIBLE, that.visible);
|
||||||
|
Settings.setValue(SETTING_GRID_SNAP_TO_GRID, snapToGrid);
|
||||||
|
Settings.setValue(SETTING_GRID_MINOR_WIDTH, minorGridSpacing);
|
||||||
|
Settings.setValue(SETTING_GRID_MAJOR_EVERY, majorGridEvery);
|
||||||
|
Settings.setValue(SETTING_GRID_COLOR, JSON.stringify(gridColor));
|
||||||
|
}
|
||||||
|
|
||||||
that.addListener = function(callback) {
|
that.addListener = function(callback) {
|
||||||
that.onUpdate = callback;
|
that.onUpdate = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
Script.scriptEnding.connect(cleanup);
|
Script.scriptEnding.connect(cleanup);
|
||||||
updateGrid();
|
|
||||||
|
loadSettings();
|
||||||
|
|
||||||
that.onUpdate = null;
|
that.onUpdate = null;
|
||||||
|
|
||||||
|
|
|
@ -213,6 +213,28 @@ var toolBar = (function () {
|
||||||
Overlays.editOverlay(loadFileMenuItem, { visible: active });
|
Overlays.editOverlay(loadFileMenuItem, { visible: active });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
that.setActive = function(active) {
|
||||||
|
if (active != isActive) {
|
||||||
|
isActive = active;
|
||||||
|
if (!isActive) {
|
||||||
|
entityListTool.setVisible(false);
|
||||||
|
gridTool.setVisible(false);
|
||||||
|
grid.setEnabled(false);
|
||||||
|
propertiesTool.setVisible(false);
|
||||||
|
selectionManager.clearSelections();
|
||||||
|
cameraManager.disable();
|
||||||
|
} else {
|
||||||
|
cameraManager.enable();
|
||||||
|
entityListTool.setVisible(true);
|
||||||
|
gridTool.setVisible(true);
|
||||||
|
propertiesTool.setVisible(true);
|
||||||
|
grid.setEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
toolBar.selectTool(activeButton, active);
|
||||||
|
};
|
||||||
|
|
||||||
var RESIZE_INTERVAL = 50;
|
var RESIZE_INTERVAL = 50;
|
||||||
var RESIZE_TIMEOUT = 20000;
|
var RESIZE_TIMEOUT = 20000;
|
||||||
var RESIZE_MAX_CHECKS = RESIZE_TIMEOUT / RESIZE_INTERVAL;
|
var RESIZE_MAX_CHECKS = RESIZE_TIMEOUT / RESIZE_INTERVAL;
|
||||||
|
@ -288,21 +310,7 @@ var toolBar = (function () {
|
||||||
clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
|
clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
|
||||||
|
|
||||||
if (activeButton === toolBar.clicked(clickedOverlay)) {
|
if (activeButton === toolBar.clicked(clickedOverlay)) {
|
||||||
isActive = !isActive;
|
that.setActive(!isActive);
|
||||||
if (!isActive) {
|
|
||||||
entityListTool.setVisible(false);
|
|
||||||
gridTool.setVisible(false);
|
|
||||||
grid.setEnabled(false);
|
|
||||||
propertiesTool.setVisible(false);
|
|
||||||
selectionManager.clearSelections();
|
|
||||||
cameraManager.disable();
|
|
||||||
} else {
|
|
||||||
cameraManager.enable();
|
|
||||||
entityListTool.setVisible(true);
|
|
||||||
gridTool.setVisible(true);
|
|
||||||
grid.setEnabled(true);
|
|
||||||
propertiesTool.setVisible(true);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -813,6 +821,13 @@ function handeMenuEvent(menuItem) {
|
||||||
|
|
||||||
Menu.menuItemEvent.connect(handeMenuEvent);
|
Menu.menuItemEvent.connect(handeMenuEvent);
|
||||||
|
|
||||||
|
Controller.keyPressEvent.connect(function(event) {
|
||||||
|
if (event.text == 'w' || event.text == 'a' || event.text == 's' || event.text == 'd'
|
||||||
|
|| event.text == 'UP' || event.text == 'DOWN' || event.text == 'LEFT' || event.text == 'RIGHT') {
|
||||||
|
toolBar.setActive(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Controller.keyReleaseEvent.connect(function (event) {
|
Controller.keyReleaseEvent.connect(function (event) {
|
||||||
// since sometimes our menu shortcut keys don't work, trap our menu items here also and fire the appropriate menu items
|
// since sometimes our menu shortcut keys don't work, trap our menu items here also and fire the appropriate menu items
|
||||||
if (event.text == "`") {
|
if (event.text == "`") {
|
||||||
|
|
Loading…
Reference in a new issue