canvas system

This commit is contained in:
RandomityGuy 2021-06-18 22:50:44 +05:30
parent b35c71755a
commit 6e6f2c9fb9
7 changed files with 79 additions and 31 deletions

View file

@ -1,5 +1,8 @@
package;
import gui.GuiControl.MouseState;
import hxd.Window;
import gui.Canvas;
import gui.MainMenuGui;
import hxd.res.DefaultFont;
import h2d.Text;
@ -48,7 +51,7 @@ class Main extends hxd.App {
var world:MarbleWorld;
var dtsObj:DtsObject;
var mmg:MainMenuGui;
var canvas:Canvas;
var fpsCounter:Text;
@ -62,8 +65,9 @@ class Main extends hxd.App {
var mission = new Mission();
mission.root = mis.root;
mmg = new MainMenuGui();
mmg.init(s2d);
canvas = new Canvas(s2d);
canvas.setContent(new MainMenuGui());
// world = new MarbleWorld(s3d, s2d, mission);
@ -77,7 +81,11 @@ class Main extends hxd.App {
override function update(dt:Float) {
super.update(dt);
mmg.update(dt);
var wnd = Window.getInstance();
var mouseState:MouseState = {
position: new Vector(wnd.mouseX, wnd.mouseY)
}
canvas.update(dt, mouseState);
// world.update(dt);
fpsCounter.text = 'FPS: ${this.engine.fps}';
}

29
src/gui/Canvas.hx Normal file
View file

@ -0,0 +1,29 @@
package gui;
import h3d.Vector;
import h2d.Scene;
import gui.GuiControl.MouseState;
class Canvas extends GuiControl {
var scene2d:Scene;
public function new(scene) {
super();
this.scene2d = scene;
this.position = new Vector();
this.extent = new Vector(scene.width, scene.height);
this.horizSizing = Width;
this.vertSizing = Height;
}
public function setContent(content:GuiControl) {
this.dispose();
this.addChild(content);
this.render(scene2d);
}
public override function update(dt:Float, mouseState:MouseState) {
super.update(dt, mouseState);
}
}

View file

@ -23,4 +23,9 @@ class GuiAnim extends GuiControl {
scene2d.addChild(anim);
super.render(scene2d);
}
public override function dispose() {
super.dispose();
this.anim.remove();
}
}

View file

@ -108,4 +108,18 @@ class GuiControl {
this.children.push(ctrl);
ctrl.parent = this;
}
public function removeChildren() {
for (c in this.children) {
c.parent = null;
}
this.children = [];
}
public function dispose() {
for (c in this.children) {
c.dispose();
}
this.children = [];
}
}

View file

@ -22,4 +22,9 @@ class GuiImage extends GuiControl {
scene2d.addChild(bmp);
super.render(scene2d);
}
public override function dispose() {
super.dispose();
this.bmp.remove();
}
}

View file

@ -38,4 +38,9 @@ class GuiText extends GuiControl {
scene2d.addChild(text);
super.render(scene2d);
}
public override function dispose() {
super.dispose();
this.text.remove();
}
}

View file

@ -6,25 +6,17 @@ import hxd.res.BitmapFont;
import h3d.Vector;
import src.ResourceLoader;
class MainMenuGui {
var scene2d:h2d.Scene;
var mainCtrl:GuiControl;
public function new() {}
public function init(scene2d:h2d.Scene) {
this.scene2d = scene2d;
class MainMenuGui extends GuiImage {
public function new() {
super(ResourceLoader.getImage("data/ui/background.jpg").toTile());
var fontdata = ResourceLoader.loader.load("data/font/DomCasual32px.fnt");
var bfont = new BitmapFont(fontdata.entry);
@:privateAccess bfont.loader = ResourceLoader.loader;
mainCtrl = new GuiImage(ResourceLoader.getImage("data/ui/background.jpg").toTile());
mainCtrl.horizSizing = Width;
mainCtrl.vertSizing = Height;
mainCtrl.position = new Vector();
mainCtrl.extent = new Vector(640, 480);
this.horizSizing = Width;
this.vertSizing = Height;
this.position = new Vector();
this.extent = new Vector(640, 480);
var versionText = new GuiText(bfont);
versionText.horizSizing = Center;
@ -32,14 +24,14 @@ class MainMenuGui {
versionText.position = new Vector(289, 457);
versionText.extent = new Vector(62, 18);
versionText.text.text = "1.0.0";
mainCtrl.addChild(versionText);
this.addChild(versionText);
var homebase = new GuiImage(ResourceLoader.getImage("data/ui/home/homegui.png").toTile());
homebase.horizSizing = Center;
homebase.vertSizing = Center;
homebase.extent = new Vector(349, 477);
homebase.position = new Vector(145, 1);
mainCtrl.addChild(homebase);
this.addChild(homebase);
function loadButtonImages(path:String) {
var normal = ResourceLoader.getImage('${path}_n.png').toTile();
@ -67,15 +59,5 @@ class MainMenuGui {
exitButton.position = new Vector(82, 358);
exitButton.extent = new Vector(203, 88);
homebase.addChild(exitButton);
mainCtrl.render(scene2d);
}
public function update(dt:Float) {
var wnd = Window.getInstance();
var mouseState:MouseState = {
position: new Vector(wnd.mouseX, wnd.mouseY)
}
mainCtrl.update(dt, mouseState);
}
}