This commit is contained in:
Jeena 2014-02-10 22:22:14 +01:00
parent 89c5e4a5d8
commit ed23753c04
17 changed files with 286 additions and 224 deletions

View file

@ -20,6 +20,8 @@ function (DomController, Settings, Exception, NotificationCenter) {
NotificationCenter.on("view/fullscreenChange", this.onFullscreenChange, this);
NotificationCenter.on("view/toggleDebugMode", this.onToggleDebugMode, this);
NotificationCenter.on("view/toggleInfo", this.onToggleInfo, this);
}
AbstractView.prototype.isWebGlEnabled = function () {
@ -37,35 +39,35 @@ function (DomController, Settings, Exception, NotificationCenter) {
}
AbstractView.prototype.loadPlayerMesh = function(player) {
throw new Exception('Abstract Function loadPlayerMesh not overwritten ');
throw new Exception('Abstract Function loadPlayerMesh not overwritten');
};
AbstractView.prototype.loadMeshes = function(objects) {
throw new Exception('Abstract Function loadMeshes not overwritten ');
throw new Exception('Abstract Function loadMeshes not overwritten');
};
AbstractView.prototype.render = function () {
throw new Exception('Abstract Function render not overwritten ');
throw new Exception('Abstract Function render not overwritten');
}
AbstractView.prototype.createMesh = function (texturePath, callback, options) {
throw new Exception('Abstract Function createMesh not overwritten ');
throw new Exception('Abstract Function createMesh not overwritten');
}
AbstractView.prototype.createAnimatedMesh = function (texturePaths, callback, options) {
throw new Exception('Abstract Function createAnimatedMesh not overwritten ');
throw new Exception('Abstract Function createAnimatedMesh not overwritten');
}
AbstractView.prototype.addMesh = function(mesh) {
throw new Exception('Abstract Function addMesh not overwritten ');
throw new Exception('Abstract Function addMesh not overwritten');
};
AbstractView.prototype.removeMesh = function(mesh) {
throw new Exception('Abstract Function removeMesh not overwritten ');
throw new Exception('Abstract Function removeMesh not overwritten');
};
AbstractView.prototype.updateMesh = function(mesh, options) {
throw new Exception('Abstract Function updateMesh not overwritten ');
throw new Exception('Abstract Function updateMesh not overwritten');
};
AbstractView.prototype.setMe = function(player) {
@ -73,15 +75,15 @@ function (DomController, Settings, Exception, NotificationCenter) {
};
AbstractView.prototype.addPlayer = function(player) {
throw new Exception('Abstract Function addPlayer not overwritten ');
throw new Exception('Abstract Function addPlayer not overwritten');
};
AbstractView.prototype.removPlayer = function(player) {
throw new Exception('Abstract Function removPlayer not overwritten ');
throw new Exception('Abstract Function removPlayer not overwritten');
};
AbstractView.prototype.setCameraPosition = function (x, y) {
throw new Exception('Abstract Function setCameraPosition not overwritten ');
throw new Exception('Abstract Function setCameraPosition not overwritten');
}
AbstractView.prototype.calculateCameraPosition = function() {
@ -101,7 +103,7 @@ function (DomController, Settings, Exception, NotificationCenter) {
};
AbstractView.prototype.setCameraZoom = function (z) {
throw new Exception('Abstract Function setCameraZoom not overwritten ');
throw new Exception('Abstract Function setCameraZoom not overwritten');
};
AbstractView.prototype.onFullscreenChange = function(isFullScreen) {
@ -125,5 +127,9 @@ function (DomController, Settings, Exception, NotificationCenter) {
this.debugMode = debugMode;
};
AbstractView.prototype.toggleInfo = function(show, string) {
throw new Exception('Abstract Function showInfo not overwritten');
};
return AbstractView;
});

View file

@ -16,6 +16,9 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
this.camera = null;
this.stage = null;
this.container = null;
this.infoContainer = null;
this.infoFilters = [];
this.infoBox = null;
this.init();
this.pixi = PIXI;
}
@ -35,21 +38,40 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
this.stage = new PIXI.Stage(0x333333);
this.initCamera();
/*
var blurFilter = new PIXI.BlurFilter();
blurFilter.blurX = 12;
blurFilter.blurY = 0;
var grayFilter = new PIXI.GrayFilter();
grayFilter.gray = .6;
this.stage.filters = [grayFilter];
*/
this.initInfo();
this.setCanvas(this.renderer.view);
}
PixiView.prototype.initCamera = function () {
this.container = new PIXI.DisplayObjectContainer();
this.stage.addChild(this.container);
}
PixiView.prototype.initInfo = function() {
this.infoContainer = new PIXI.DisplayObjectContainer();
this.stage.addChild(this.infoContainer);
var blurFilter = new PIXI.BlurFilter();
blurFilter.blurX = 12;
blurFilter.blurY = 12;
var grayFilter = new PIXI.GrayFilter();
grayFilter.gray = 0.85;
this.infoFilters = [blurFilter, grayFilter];
this.infoText = new PIXI.Text("", {font: "normal 20px monospace", fill: "red", align: "center"});
this.infoBox = new PIXI.Graphics();
this.infoBox.alpha = 0.7;
this.infoContainer.addChild(this.infoBox);
this.infoContainer.addChild(this.infoText);
this.infoContainer.visible = false;
};
PixiView.prototype.render = function () {
if(this.me) {
if(this.me && this.me.isSpawned) {
var pos = this.calculateCameraPosition();
this.setCameraPosition(pos.x, pos.y);
}
@ -79,11 +101,15 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
var textures = [];
for (var i = 0; i < texturePaths.length; i++) {
var texture = PIXI.Texture.fromImage(texturePaths[i]);
texture.width = options.width;
texture.height = options.height;
PIXI.texturesToUpdate.push(texture);
textures.push(texture);
}
var mesh = new PIXI.MovieClip(textures);
if(options) this.updateMesh(mesh, options);
mesh.animationSpeed = 0.5;
mesh.play();
@ -117,12 +143,6 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
};
}
PixiView.prototype.initCamera = function () {
this.container = new PIXI.DisplayObjectContainer();
this.stage.addChild(this.container);
}
PixiView.prototype.calculateCameraPosition = function() {
var zoom = this.container.scale.x;
@ -161,5 +181,35 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
}
};
PixiView.prototype.toggleInfo = function(show, string) {
if(show) {
this.infoText.setText(string);
this.infoText.updateText();
this.infoText.dirty = false;
var x = Settings.STAGE_WIDTH / 2 - this.infoText.width / 2,
y = Settings.STAGE_HEIGHT / 2 - this.infoText.height / 2;
this.infoText.position = new PIXI.Point(x, y);
var borderWidth = 3;
var padding = 20;
this.infoBox.clear();
this.infoBox.beginFill(0x000000);
this.infoBox.lineStyle(borderWidth, 0xAA0000);
this.infoBox.drawRect(0, 0, this.infoText.width - borderWidth + 2 * padding * 2, this.infoText.height - borderWidth + 2 * padding);
this.infoBox.endFill();
this.infoBox.position.x = this.infoText.position.x + borderWidth/2 - padding * 2;
this.infoBox.position.y = this.infoText.position.y + borderWidth/2 - padding;
this.infoContainer.visible = true;
this.container.filters = this.infoFilters;
this.infoFilters.forEach(function(filter) { filter.dirty = true; });
} else {
this.infoText.setText("...");
this.infoContainer.visible = false;
this.container.filters = null;
}
};
return PixiView;
});