unify grabbing controls
This commit is contained in:
parent
70e4105e1b
commit
0168e81ffe
|
@ -197,9 +197,9 @@ var editor = {
|
||||||
stash: "",
|
stash: "",
|
||||||
|
|
||||||
start_play_ed() {
|
start_play_ed() {
|
||||||
this.stash = this.edit_level.save();
|
// this.stash = this.edit_level.save();
|
||||||
this.edit_level.kill();
|
// this.edit_level.kill();
|
||||||
load_configs("game.config");
|
// load_configs("game.config");
|
||||||
Game.play();
|
Game.play();
|
||||||
Player.players[0].uncontrol(this);
|
Player.players[0].uncontrol(this);
|
||||||
Player.players[0].control(limited_editor);
|
Player.players[0].control(limited_editor);
|
||||||
|
@ -719,7 +719,7 @@ editor.inputs['C-p'] = function() {
|
||||||
if (!Game.playing()) {
|
if (!Game.playing()) {
|
||||||
editor.start_play_ed();
|
editor.start_play_ed();
|
||||||
// if (!Level.loadlevel("debug"))
|
// if (!Level.loadlevel("debug"))
|
||||||
World.loadlevel("game");
|
Primum.spawn(ur.start);
|
||||||
} else {
|
} else {
|
||||||
Game.pause();
|
Game.pause();
|
||||||
}
|
}
|
||||||
|
@ -856,9 +856,7 @@ editor.inputs['C-y'] = function() {
|
||||||
texteditor.on_close = function() { editor.edit_level.script = texteditor.value;};
|
texteditor.on_close = function() { editor.edit_level.script = texteditor.value;};
|
||||||
|
|
||||||
editor.openpanel(texteditor);
|
editor.openpanel(texteditor);
|
||||||
if (!editor.edit_level.script)
|
texteditor.value = "";
|
||||||
editor.edit_level.script = "";
|
|
||||||
texteditor.value = editor.edit_level.script;
|
|
||||||
texteditor.start();
|
texteditor.start();
|
||||||
};
|
};
|
||||||
editor.inputs['C-y'].doc = "Open script editor for the level.";
|
editor.inputs['C-y'].doc = "Open script editor for the level.";
|
||||||
|
@ -983,13 +981,9 @@ editor.inputs.rm = function() {
|
||||||
editor.unselect();
|
editor.unselect();
|
||||||
};
|
};
|
||||||
|
|
||||||
editor.inputs.mm = function() {
|
editor.try_pick = function()
|
||||||
if (editor.brush_obj) {
|
{
|
||||||
editor.selectlist = editor.dup_objects([editor.brush_obj]);
|
editor.grabselect = [];
|
||||||
editor.selectlist[0].pos = Mouse.worldpos;
|
|
||||||
editor.grabselect = editor.selectlist[0];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (editor.sel_comp && 'pick' in editor.sel_comp) {
|
if (editor.sel_comp && 'pick' in editor.sel_comp) {
|
||||||
var o = editor.sel_comp.pick(Mouse.worldpos);
|
var o = editor.sel_comp.pick(Mouse.worldpos);
|
||||||
|
@ -998,16 +992,27 @@ editor.inputs.mm = function() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var grabobj = editor.try_select();
|
if (editor.selectlist.length > 0) {
|
||||||
editor.grabselect = [];
|
editor.grabselect = editor.selectlist.slice();
|
||||||
if (!grabobj) return;
|
return;
|
||||||
|
|
||||||
if (Keys.ctrl()) {
|
|
||||||
grabobj = editor.dup_objects([grabobj])[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var grabobj = editor.try_select();
|
||||||
|
|
||||||
|
if (!grabobj) return;
|
||||||
editor.grabselect = [grabobj];
|
editor.grabselect = [grabobj];
|
||||||
editor.selectlist = [grabobj];
|
editor.selectlist = [grabobj];
|
||||||
|
}
|
||||||
|
|
||||||
|
editor.inputs.mm = function() {
|
||||||
|
if (editor.brush_obj) {
|
||||||
|
editor.selectlist = editor.dup_objects([editor.brush_obj]);
|
||||||
|
editor.selectlist[0].pos = Mouse.worldpos;
|
||||||
|
editor.grabselect = editor.selectlist[0];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
editor.try_pick();
|
||||||
};
|
};
|
||||||
editor.inputs['C-mm'] = editor.inputs.mm;
|
editor.inputs['C-mm'] = editor.inputs.mm;
|
||||||
|
|
||||||
|
@ -1075,14 +1080,12 @@ editor.inputs.mouse.scroll = function(scroll)
|
||||||
editor.grabselect?.forEach(function(x) {
|
editor.grabselect?.forEach(function(x) {
|
||||||
x.pos = x.pos.add(scroll.scale(editor.camera.zoom));
|
x.pos = x.pos.add(scroll.scale(editor.camera.zoom));
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
editor.inputs.mouse['C-scroll'] = function(scroll)
|
scroll.y *= -1;
|
||||||
{
|
|
||||||
editor.camera.pos = editor.camera.pos.sub(scroll.scale(editor.camera.zoom * 3).scale([1,-1]));
|
editor.camera.pos = editor.camera.pos.sub(scroll.scale(editor.camera.zoom * 3).scale([1,-1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.inputs.mouse['C-M-scroll'] = function(scroll)
|
editor.inputs.mouse['C-scroll'] = function(scroll)
|
||||||
{
|
{
|
||||||
editor.camera.zoom += scroll.y/100;
|
editor.camera.zoom += scroll.y/100;
|
||||||
}
|
}
|
||||||
|
@ -1116,16 +1119,7 @@ editor.inputs['C-S-g'] = function() { editor.openpanel(groupsaveaspanel); };
|
||||||
editor.inputs['C-S-g'].doc = "Save selected objects as a new level.";
|
editor.inputs['C-S-g'].doc = "Save selected objects as a new level.";
|
||||||
|
|
||||||
editor.inputs.g = function() {
|
editor.inputs.g = function() {
|
||||||
editor.grabselect = [];
|
editor.try_pick();
|
||||||
|
|
||||||
if (this.sel_comp) {
|
|
||||||
if ('pos' in this.sel_comp)
|
|
||||||
editor.grabselect = [this.sel_comp];
|
|
||||||
} else
|
|
||||||
editor.grabselect = editor.selectlist.slice();
|
|
||||||
|
|
||||||
if (!editor.grabselect.empty)
|
|
||||||
Mouse.disabled();
|
|
||||||
};
|
};
|
||||||
editor.inputs.g.doc = "Move selected objects.";
|
editor.inputs.g.doc = "Move selected objects.";
|
||||||
editor.inputs.g.released = function() { editor.grabselect = []; Mouse.normal(); };
|
editor.inputs.g.released = function() { editor.grabselect = []; Mouse.normal(); };
|
||||||
|
|
|
@ -466,28 +466,14 @@ prototypes.from_file = function(file)
|
||||||
var newur = Object.create(upperur);
|
var newur = Object.create(upperur);
|
||||||
file = file.replaceAll('.','/');
|
file = file.replaceAll('.','/');
|
||||||
|
|
||||||
var jsfile = file + ".js";
|
var jsfile = prototypes.get_ur_file(urpath, ".js");
|
||||||
var jsonfile = file + ".json";
|
var jsonfile = prototypes.get_ur_file(urpath, ".json");
|
||||||
|
|
||||||
var script = undefined;
|
var script = undefined;
|
||||||
var json = undefined;
|
var json = undefined;
|
||||||
|
|
||||||
if (IO.exists(jsfile))
|
if (jsfile) script = IO.slurp(jsfile);
|
||||||
script = IO.slurp(jsfile);
|
if (jsonfile) json = JSON.parse(IO.slurp(jsonfile));
|
||||||
else {
|
|
||||||
jsfile = urpath + "/" + path.at(-1) + ".js";
|
|
||||||
if (IO.exists(jsfile)) script = IO.slurp(jsfile);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
try {json = JSON.parse(IO.slurp(jsonfile)); }
|
|
||||||
catch(e) {
|
|
||||||
jsonfile = file + "/" + path.at(-1) + ".json";
|
|
||||||
if (IO.exists(jsonfile)) json = JSON.parse(IO.slurp(jsonfile));
|
|
||||||
}
|
|
||||||
} catch(e) {
|
|
||||||
Log.warn(`JSON in file ${jsonfile} is malformed.${e}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!json && !script) {
|
if (!json && !script) {
|
||||||
Log.warn(`Could not make ur from ${file}`);
|
Log.warn(`Could not make ur from ${file}`);
|
||||||
|
@ -535,6 +521,11 @@ prototypes.list_ur = function()
|
||||||
return list_obj(ur);
|
return list_obj(ur);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prototypes.ur2file = function(urpath)
|
||||||
|
{
|
||||||
|
return urpath.replaceAll('.', '/');
|
||||||
|
}
|
||||||
|
|
||||||
prototypes.file2ur = function(file)
|
prototypes.file2ur = function(file)
|
||||||
{
|
{
|
||||||
file = file.strip_ext();
|
file = file.strip_ext();
|
||||||
|
@ -564,6 +555,16 @@ prototypes.get_ur = function(name)
|
||||||
return prototypes.ur[urpath];
|
return prototypes.ur[urpath];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prototypes.get_ur_file = function(path, ext)
|
||||||
|
{
|
||||||
|
var urpath = prototypes.ur2file(path);
|
||||||
|
var file = urpath + ext;
|
||||||
|
if (IO.exists(file)) return file;
|
||||||
|
file = urpath + "/" + path.split('.').at(-1) + ext;
|
||||||
|
if (IO.exists(file)) return file;
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
prototypes.generate_ur = function(path)
|
prototypes.generate_ur = function(path)
|
||||||
{
|
{
|
||||||
var ob = IO.glob("**.js");
|
var ob = IO.glob("**.js");
|
||||||
|
|
|
@ -135,8 +135,7 @@ var GUI = {
|
||||||
};
|
};
|
||||||
|
|
||||||
def.items.forEach(function(item,idx) {
|
def.items.forEach(function(item,idx) {
|
||||||
Object.setPrototypeOf(def.items[idx], def);
|
def.items[idx].__proto__ = def;
|
||||||
|
|
||||||
if (def.items[idx-1])
|
if (def.items[idx-1])
|
||||||
def.up = def.items[idx-1];
|
def.up = def.items[idx-1];
|
||||||
|
|
||||||
|
|
|
@ -78,26 +78,6 @@ var texteditor = Object.copy(inputpanel, {
|
||||||
this.cursor++;
|
this.cursor++;
|
||||||
},
|
},
|
||||||
|
|
||||||
input_enter_pressrep() {
|
|
||||||
var white = this.line_starting_whitespace(this.cursor);
|
|
||||||
this.insert_char('\n');
|
|
||||||
|
|
||||||
for (var i = 0; i < white; i++)
|
|
||||||
this.insert_char(" ");
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
input_text(char) {
|
|
||||||
if (Keys.ctrl() || Keys.alt()) return;
|
|
||||||
this.insert_char(char);
|
|
||||||
this.keycb();
|
|
||||||
},
|
|
||||||
|
|
||||||
input_backspace_pressrep() {
|
|
||||||
this.value = this.value.slice(0,this.cursor-1) + this.value.slice(this.cursor);
|
|
||||||
this.cursor--;
|
|
||||||
},
|
|
||||||
|
|
||||||
line_starting_whitespace(p) {
|
line_starting_whitespace(p) {
|
||||||
var white = 0;
|
var white = 0;
|
||||||
var l = this.line_start(p);
|
var l = this.line_start(p);
|
||||||
|
@ -189,6 +169,27 @@ var texteditor = Object.copy(inputpanel, {
|
||||||
});
|
});
|
||||||
|
|
||||||
texteditor.inputs = {};
|
texteditor.inputs = {};
|
||||||
|
texteditor.inputs.char = function(char) {
|
||||||
|
this.insert_char(char);
|
||||||
|
this.keycb();
|
||||||
|
},
|
||||||
|
|
||||||
|
texteditor.inputs.enter = function(){
|
||||||
|
var white = this.line_starting_whitespace(this.cursor);
|
||||||
|
this.insert_char('\n');
|
||||||
|
|
||||||
|
for (var i = 0; i < white; i++)
|
||||||
|
this.insert_char(" ");
|
||||||
|
};
|
||||||
|
texteditor.inputs.enter.rep = true;
|
||||||
|
|
||||||
|
texteditor.inputs.backspace = function(){
|
||||||
|
this.value = this.value.slice(0,this.cursor-1) + this.value.slice(this.cursor);
|
||||||
|
this.cursor--;
|
||||||
|
};
|
||||||
|
texteditor.inputs.backspace.rep = true;
|
||||||
|
|
||||||
|
|
||||||
texteditor.inputs['C-s'] = function() {
|
texteditor.inputs['C-s'] = function() {
|
||||||
editor.edit_level.script = texteditor.value;
|
editor.edit_level.script = texteditor.value;
|
||||||
editor.save_current();
|
editor.save_current();
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include <chipmunk/chipmunk.h>
|
#include <chipmunk/chipmunk.h>
|
||||||
#include "2dphysics.h"
|
#include "2dphysics.h"
|
||||||
#include "resources.h"
|
#include "resources.h"
|
||||||
|
#include "debugdraw.h"
|
||||||
#include "text.sglsl.h"
|
#include "text.sglsl.h"
|
||||||
|
|
||||||
#include "stb_image_write.h"
|
#include "stb_image_write.h"
|
||||||
|
@ -178,16 +178,20 @@ struct sFont *MakeFont(const char *fontfile, int height) {
|
||||||
|
|
||||||
static int curchar = 0;
|
static int curchar = 0;
|
||||||
|
|
||||||
void draw_char_box(struct Character c, cpVect cursor, float scale, struct rgba color)
|
void draw_char_box(struct Character c, HMM_Vec2 cursor, float scale, struct rgba color)
|
||||||
{
|
{
|
||||||
cpVect wh;
|
cpVect wh;
|
||||||
|
|
||||||
wh.x = 8 * scale;
|
wh.x = 8 * scale;
|
||||||
wh.y = 14;
|
wh.y = 14;
|
||||||
cursor.x += wh.x / 2.f;
|
cursor.X += wh.x / 2.f;
|
||||||
cursor.y += wh.y / 2.f;
|
cursor.Y += wh.y / 2.f;
|
||||||
|
|
||||||
// draw_box(cursor, wh, color);
|
cpVect b;
|
||||||
|
b.x = cursor.X;
|
||||||
|
b.y = cursor.Y;
|
||||||
|
|
||||||
|
draw_box(b, wh, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void text_flush(HMM_Mat4 *proj) {
|
void text_flush(HMM_Mat4 *proj) {
|
||||||
|
@ -229,31 +233,6 @@ void sdrawCharacter(struct Character c, HMM_Vec2 cursor, float scale, struct rgb
|
||||||
|
|
||||||
memcpy(text_buffer + curchar, &vert, sizeof(struct text_vert));
|
memcpy(text_buffer + curchar, &vert, sizeof(struct text_vert));
|
||||||
curchar++;
|
curchar++;
|
||||||
return;
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (drawcaret == curchar) {
|
|
||||||
draw_char_box(c, cursor, scale, color);
|
|
||||||
shader_use(shader);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
sg_append_buffer(bind_text.vertex_buffers[0], SG_RANGE_REF(verts));
|
|
||||||
|
|
||||||
offset[0] = 1;
|
|
||||||
offset[1] = -1;
|
|
||||||
fill_charverts(verts, cursor, scale, c, offset);
|
|
||||||
sg_update_buffer(bind_text.vertex_buffers[0], SG_RANGE_REF(verts));
|
|
||||||
|
|
||||||
offset[1] = 1;
|
|
||||||
fill_charverts(verts, cursor, scale, c, offset);
|
|
||||||
sg_update_buffer(bind_text.vertex_buffers[0], SG_RANGE_REF(verts));
|
|
||||||
|
|
||||||
offset[0] = -1;
|
|
||||||
offset[1] = -1;
|
|
||||||
fill_charverts(verts, cursor, scale, c, offset);
|
|
||||||
sg_update_buffer(bind_text.vertex_buffers[0], SG_RANGE_REF(verts));
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void text_settype(struct sFont *mfont) {
|
void text_settype(struct sFont *mfont) {
|
||||||
|
@ -321,6 +300,9 @@ int renderText(const char *text, HMM_Vec2 pos, float scale, struct rgba color, f
|
||||||
struct rgba usecolor = color;
|
struct rgba usecolor = color;
|
||||||
|
|
||||||
while (*line != '\0') {
|
while (*line != '\0') {
|
||||||
|
if (caret == curchar)
|
||||||
|
draw_char_box(font->Characters[69], cursor, scale, color);
|
||||||
|
|
||||||
if (isblank(*line)) {
|
if (isblank(*line)) {
|
||||||
sdrawCharacter(font->Characters[*line], cursor, scale, usecolor);
|
sdrawCharacter(font->Characters[*line], cursor, scale, usecolor);
|
||||||
cursor.X += font->Characters[*line].Advance * tracking * scale;
|
cursor.X += font->Characters[*line].Advance * tracking * scale;
|
||||||
|
@ -351,10 +333,8 @@ int renderText(const char *text, HMM_Vec2 pos, float scale, struct rgba color, f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* if (caret > curchar) {
|
// if (caret > curchar)
|
||||||
draw_char_box(font->Characters[69], cursor, scale, color);
|
// draw_char_box(font->Characters[69], cursor, scale, color);
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
return cursor.Y - pos.Y;
|
return cursor.Y - pos.Y;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue