diff --git a/index.html b/index.html index 60e2379..b6889d2 100644 --- a/index.html +++ b/index.html @@ -72,10 +72,11 @@ - - - + + + + diff --git a/index.html b/index.html index 60e2379..b6889d2 100644 --- a/index.html +++ b/index.html @@ -72,10 +72,11 @@ - - - + + + + diff --git a/index.js b/index.js index 469e75e..a126949 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,12 @@ this.win = win; win.showDevTools(); - window.addEventListener('resize', this.resize.bind(this)); + window.addEventListener("keyup", event => + { + if (event.key == "F5") win.reload(); + }); + + window.addEventListener('resize', this.resize.bind(this)); // start up express this.app = express(); @@ -36,14 +41,14 @@ const address = Object.values(os.networkInterfaces()).flatMap(i => i).filter(i => i.family == "IPv4" && !i.internal)[0].address - var gameContainer = document.getElementById("gameContainer"); - Engine.InitEngine(gameContainer, { width: window.innerWidth, height: window.innerHeight, roundPixels: false} ); + var gameContainer = document.getElementById("gameContainer"); + Engine.InitEngine(gameContainer, { width: window.innerWidth, height: window.innerHeight, roundPixels: false} ); - Game.Server = wsServer; + Game.Server = this.wsServer; Game.Address = address; - var gameManager = new GameManager(); - gameManager.init("shared/js/", HostGame); + var gameManager = new GameManager(); + gameManager.init("shared/js/", HostGame); } connect(req) diff --git a/index.html b/index.html index 60e2379..b6889d2 100644 --- a/index.html +++ b/index.html @@ -72,10 +72,11 @@ - - - + + + + diff --git a/index.js b/index.js index 469e75e..a126949 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,12 @@ this.win = win; win.showDevTools(); - window.addEventListener('resize', this.resize.bind(this)); + window.addEventListener("keyup", event => + { + if (event.key == "F5") win.reload(); + }); + + window.addEventListener('resize', this.resize.bind(this)); // start up express this.app = express(); @@ -36,14 +41,14 @@ const address = Object.values(os.networkInterfaces()).flatMap(i => i).filter(i => i.family == "IPv4" && !i.internal)[0].address - var gameContainer = document.getElementById("gameContainer"); - Engine.InitEngine(gameContainer, { width: window.innerWidth, height: window.innerHeight, roundPixels: false} ); + var gameContainer = document.getElementById("gameContainer"); + Engine.InitEngine(gameContainer, { width: window.innerWidth, height: window.innerHeight, roundPixels: false} ); - Game.Server = wsServer; + Game.Server = this.wsServer; Game.Address = address; - var gameManager = new GameManager(); - gameManager.init("shared/js/", HostGame); + var gameManager = new GameManager(); + gameManager.init("shared/js/", HostGame); } connect(req) diff --git a/shared/js/Engine/Dialogs/PrettyMessageBox.js b/shared/js/Engine/Dialogs/PrettyMessageBox.js new file mode 100644 index 0000000..f1bc33d --- /dev/null +++ b/shared/js/Engine/Dialogs/PrettyMessageBox.js @@ -0,0 +1,129 @@ +class PrettyMessageBox extends Engine.Dialog +{ + //public delegate void MessageBoxCallback(bool doSomething); + constructor(parentClip /*Drawable*/) + { + super(parentClip); + + this.okButton = new Engine.DrawableButton("Button_SimpleGreen", "OK"); + this.cancelButton = new Engine.DrawableButton("Button_SimpleRed", "Cancel"); + this.text = new Engine.DrawableText(); + this.scrollText = new ScrollingTextBox(); + this.boxWidth = 380; + this.boxHeight = 200; + this.fixedBoxWidth = 380; + this.fixedBoxHeight = 200; + this.callbackFunction = null; + + this.background = new Engine.Drawable("BGStandard"); + + this.text.textAreaWidth = this.boxWidth * 0.75; + this.text.textAreaHeight = this.boxHeight * 0.75; + + this.name = "MessageBox"; + this.background.setNineRect(0.4, 0.4, 0.6, 0.6); + this.background.width = this.boxWidth; + this.background.height = this.boxHeight; + + this.backgroundBounds = new Engine.Drawable(); + this.backgroundBounds.setAsBox(this.backgroundBounds.graphics, this.boxWidth, this.boxHeight, new Color(0, 0, 0, 127), 1); + + this.addChild(this.background); + this.addChild(this.text); + + this.okButton.setWidth(100); + this.cancelButton.setWidth(100); + + var space = (this.boxWidth - this.okButton.width - this.cancelButton.width) / 3; + + this.okButton.y = this.boxHeight - (this.okButton.height * 1.5); + this.okButton.x = space; + + this.cancelButton.y = this.okButton.y; + this.cancelButton.x = this.okButton.x + this.okButton.width + space; + + this.addChild(this.okButton); + this.addChild(this.cancelButton); + + this.cancelButton.onClick = () => this.clickedCancel(); + this.okButton.onClick = () => this.clickedOK(); + + this.dialogWidth = this.boxWidth; + this.dialogHeight = this.boxHeight; + } + + clickedCancel() + { + if (this.callbackFunction != null) this.callbackFunction(false); + this.hide(); + } + + clickedOK() + { + if (this.callbackFunction != null) this.callbackFunction(true); + this.hide(); + } + + show(message /*String*/, okText /*String*/, closeText /*String*/, callbackFunction /*Action*/) + { + this.active = true; + this.callbackFunction = callbackFunction; + this.parentClip.addChild(this); + + this.boxWidth = this.fixedBoxWidth; + this.boxHeight = this.fixedBoxHeight; + + this.background.width = this.boxWidth; + this.background.height = this.boxHeight; + + this.addChild(this.text); + this.removeChild(this.scrollText); + + this.text.textAreaWidth = this.background.width * 0.75; + this.text.setText(message, "Arial", 14); + + this.okButton.setButtonText(okText); + this.cancelButton.setButtonText(closeText); + + if (closeText == "") this.removeChild(this.cancelButton); + else this.addChild(this.cancelButton); + + if (okText == "") this.removeChild(this.okButton); + else this.addChild(this.okButton); + + this.layout(); + this.showDialog(); + } + + layout() + { + //Rect texDims = text.getRect(); + //text.SetTint(Color.blue); + this.text.x = (this.boxWidth - this.text.width) * 0.5; + this.text.y = 30; + + this.scrollText.x = 10; + this.scrollText.y = this.text.y; + + var space = (this.boxWidth - this.okButton.width - this.cancelButton.width) * 0.33; + this.okButton.x = space; + if (!this.cancelButton.hasParent) this.okButton.x = (this.boxWidth * 0.5 - this.okButton.width * 0.5); + this.okButton.y = this.boxHeight - (this.okButton.height * 1.5); + + this.cancelButton.x = this.okButton.x + this.okButton.width + space; + if (!this.okButton.hasParent) this.cancelButton.x = this.boxWidth * 0.5 - this.cancelButton.width * 0.5; + this.cancelButton.y = this.boxHeight - (this.cancelButton.height * 1.5); + + this.dialogWidth = this.boxWidth; + this.dialogHeight = this.boxHeight; + + // autosize the box on default view + if (this.text.y + this.text.height > this.okButton.y) + { + this.background.height = this.text.y + this.text.height + this.okButton.height * 2; + this.dialogHeight = this.background.height; + this.okButton.y = this.background.height - (this.okButton.height * 1.5); + this.cancelButton.y = this.okButton.y; + } + } +} \ No newline at end of file diff --git a/index.html b/index.html index 60e2379..b6889d2 100644 --- a/index.html +++ b/index.html @@ -72,10 +72,11 @@ - - - + + + + diff --git a/index.js b/index.js index 469e75e..a126949 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,12 @@ this.win = win; win.showDevTools(); - window.addEventListener('resize', this.resize.bind(this)); + window.addEventListener("keyup", event => + { + if (event.key == "F5") win.reload(); + }); + + window.addEventListener('resize', this.resize.bind(this)); // start up express this.app = express(); @@ -36,14 +41,14 @@ const address = Object.values(os.networkInterfaces()).flatMap(i => i).filter(i => i.family == "IPv4" && !i.internal)[0].address - var gameContainer = document.getElementById("gameContainer"); - Engine.InitEngine(gameContainer, { width: window.innerWidth, height: window.innerHeight, roundPixels: false} ); + var gameContainer = document.getElementById("gameContainer"); + Engine.InitEngine(gameContainer, { width: window.innerWidth, height: window.innerHeight, roundPixels: false} ); - Game.Server = wsServer; + Game.Server = this.wsServer; Game.Address = address; - var gameManager = new GameManager(); - gameManager.init("shared/js/", HostGame); + var gameManager = new GameManager(); + gameManager.init("shared/js/", HostGame); } connect(req) diff --git a/shared/js/Engine/Dialogs/PrettyMessageBox.js b/shared/js/Engine/Dialogs/PrettyMessageBox.js new file mode 100644 index 0000000..f1bc33d --- /dev/null +++ b/shared/js/Engine/Dialogs/PrettyMessageBox.js @@ -0,0 +1,129 @@ +class PrettyMessageBox extends Engine.Dialog +{ + //public delegate void MessageBoxCallback(bool doSomething); + constructor(parentClip /*Drawable*/) + { + super(parentClip); + + this.okButton = new Engine.DrawableButton("Button_SimpleGreen", "OK"); + this.cancelButton = new Engine.DrawableButton("Button_SimpleRed", "Cancel"); + this.text = new Engine.DrawableText(); + this.scrollText = new ScrollingTextBox(); + this.boxWidth = 380; + this.boxHeight = 200; + this.fixedBoxWidth = 380; + this.fixedBoxHeight = 200; + this.callbackFunction = null; + + this.background = new Engine.Drawable("BGStandard"); + + this.text.textAreaWidth = this.boxWidth * 0.75; + this.text.textAreaHeight = this.boxHeight * 0.75; + + this.name = "MessageBox"; + this.background.setNineRect(0.4, 0.4, 0.6, 0.6); + this.background.width = this.boxWidth; + this.background.height = this.boxHeight; + + this.backgroundBounds = new Engine.Drawable(); + this.backgroundBounds.setAsBox(this.backgroundBounds.graphics, this.boxWidth, this.boxHeight, new Color(0, 0, 0, 127), 1); + + this.addChild(this.background); + this.addChild(this.text); + + this.okButton.setWidth(100); + this.cancelButton.setWidth(100); + + var space = (this.boxWidth - this.okButton.width - this.cancelButton.width) / 3; + + this.okButton.y = this.boxHeight - (this.okButton.height * 1.5); + this.okButton.x = space; + + this.cancelButton.y = this.okButton.y; + this.cancelButton.x = this.okButton.x + this.okButton.width + space; + + this.addChild(this.okButton); + this.addChild(this.cancelButton); + + this.cancelButton.onClick = () => this.clickedCancel(); + this.okButton.onClick = () => this.clickedOK(); + + this.dialogWidth = this.boxWidth; + this.dialogHeight = this.boxHeight; + } + + clickedCancel() + { + if (this.callbackFunction != null) this.callbackFunction(false); + this.hide(); + } + + clickedOK() + { + if (this.callbackFunction != null) this.callbackFunction(true); + this.hide(); + } + + show(message /*String*/, okText /*String*/, closeText /*String*/, callbackFunction /*Action*/) + { + this.active = true; + this.callbackFunction = callbackFunction; + this.parentClip.addChild(this); + + this.boxWidth = this.fixedBoxWidth; + this.boxHeight = this.fixedBoxHeight; + + this.background.width = this.boxWidth; + this.background.height = this.boxHeight; + + this.addChild(this.text); + this.removeChild(this.scrollText); + + this.text.textAreaWidth = this.background.width * 0.75; + this.text.setText(message, "Arial", 14); + + this.okButton.setButtonText(okText); + this.cancelButton.setButtonText(closeText); + + if (closeText == "") this.removeChild(this.cancelButton); + else this.addChild(this.cancelButton); + + if (okText == "") this.removeChild(this.okButton); + else this.addChild(this.okButton); + + this.layout(); + this.showDialog(); + } + + layout() + { + //Rect texDims = text.getRect(); + //text.SetTint(Color.blue); + this.text.x = (this.boxWidth - this.text.width) * 0.5; + this.text.y = 30; + + this.scrollText.x = 10; + this.scrollText.y = this.text.y; + + var space = (this.boxWidth - this.okButton.width - this.cancelButton.width) * 0.33; + this.okButton.x = space; + if (!this.cancelButton.hasParent) this.okButton.x = (this.boxWidth * 0.5 - this.okButton.width * 0.5); + this.okButton.y = this.boxHeight - (this.okButton.height * 1.5); + + this.cancelButton.x = this.okButton.x + this.okButton.width + space; + if (!this.okButton.hasParent) this.cancelButton.x = this.boxWidth * 0.5 - this.cancelButton.width * 0.5; + this.cancelButton.y = this.boxHeight - (this.cancelButton.height * 1.5); + + this.dialogWidth = this.boxWidth; + this.dialogHeight = this.boxHeight; + + // autosize the box on default view + if (this.text.y + this.text.height > this.okButton.y) + { + this.background.height = this.text.y + this.text.height + this.okButton.height * 2; + this.dialogHeight = this.background.height; + this.okButton.y = this.background.height - (this.okButton.height * 1.5); + this.cancelButton.y = this.okButton.y; + } + } +} \ No newline at end of file diff --git a/shared/js/Engine/Utils/Keyboard.js b/shared/js/Engine/Utils/Keyboard.js index 2f4ab9e..fe9dce9 100644 --- a/shared/js/Engine/Utils/Keyboard.js +++ b/shared/js/Engine/Utils/Keyboard.js @@ -77,9 +77,9 @@ onKeyDown(event) { - if (event.keyCode == this.KEY.F5) return; - if (event.keyCode == this.KEY.L && event.ctrlKey) return; - if (event.keyCode == this.KEY.I && event.ctrlKey && event.shiftKey) return; + //if (event.keyCode == this.KEY.F5) return; + //if (event.keyCode == this.KEY.L && event.ctrlKey) return; + //if (event.keyCode == this.KEY.I && event.ctrlKey && event.shiftKey) return; event.preventDefault(); if (event.repeat) return; diff --git a/index.html b/index.html index 60e2379..b6889d2 100644 --- a/index.html +++ b/index.html @@ -72,10 +72,11 @@ - - - + + + + diff --git a/index.js b/index.js index 469e75e..a126949 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,12 @@ this.win = win; win.showDevTools(); - window.addEventListener('resize', this.resize.bind(this)); + window.addEventListener("keyup", event => + { + if (event.key == "F5") win.reload(); + }); + + window.addEventListener('resize', this.resize.bind(this)); // start up express this.app = express(); @@ -36,14 +41,14 @@ const address = Object.values(os.networkInterfaces()).flatMap(i => i).filter(i => i.family == "IPv4" && !i.internal)[0].address - var gameContainer = document.getElementById("gameContainer"); - Engine.InitEngine(gameContainer, { width: window.innerWidth, height: window.innerHeight, roundPixels: false} ); + var gameContainer = document.getElementById("gameContainer"); + Engine.InitEngine(gameContainer, { width: window.innerWidth, height: window.innerHeight, roundPixels: false} ); - Game.Server = wsServer; + Game.Server = this.wsServer; Game.Address = address; - var gameManager = new GameManager(); - gameManager.init("shared/js/", HostGame); + var gameManager = new GameManager(); + gameManager.init("shared/js/", HostGame); } connect(req) diff --git a/shared/js/Engine/Dialogs/PrettyMessageBox.js b/shared/js/Engine/Dialogs/PrettyMessageBox.js new file mode 100644 index 0000000..f1bc33d --- /dev/null +++ b/shared/js/Engine/Dialogs/PrettyMessageBox.js @@ -0,0 +1,129 @@ +class PrettyMessageBox extends Engine.Dialog +{ + //public delegate void MessageBoxCallback(bool doSomething); + constructor(parentClip /*Drawable*/) + { + super(parentClip); + + this.okButton = new Engine.DrawableButton("Button_SimpleGreen", "OK"); + this.cancelButton = new Engine.DrawableButton("Button_SimpleRed", "Cancel"); + this.text = new Engine.DrawableText(); + this.scrollText = new ScrollingTextBox(); + this.boxWidth = 380; + this.boxHeight = 200; + this.fixedBoxWidth = 380; + this.fixedBoxHeight = 200; + this.callbackFunction = null; + + this.background = new Engine.Drawable("BGStandard"); + + this.text.textAreaWidth = this.boxWidth * 0.75; + this.text.textAreaHeight = this.boxHeight * 0.75; + + this.name = "MessageBox"; + this.background.setNineRect(0.4, 0.4, 0.6, 0.6); + this.background.width = this.boxWidth; + this.background.height = this.boxHeight; + + this.backgroundBounds = new Engine.Drawable(); + this.backgroundBounds.setAsBox(this.backgroundBounds.graphics, this.boxWidth, this.boxHeight, new Color(0, 0, 0, 127), 1); + + this.addChild(this.background); + this.addChild(this.text); + + this.okButton.setWidth(100); + this.cancelButton.setWidth(100); + + var space = (this.boxWidth - this.okButton.width - this.cancelButton.width) / 3; + + this.okButton.y = this.boxHeight - (this.okButton.height * 1.5); + this.okButton.x = space; + + this.cancelButton.y = this.okButton.y; + this.cancelButton.x = this.okButton.x + this.okButton.width + space; + + this.addChild(this.okButton); + this.addChild(this.cancelButton); + + this.cancelButton.onClick = () => this.clickedCancel(); + this.okButton.onClick = () => this.clickedOK(); + + this.dialogWidth = this.boxWidth; + this.dialogHeight = this.boxHeight; + } + + clickedCancel() + { + if (this.callbackFunction != null) this.callbackFunction(false); + this.hide(); + } + + clickedOK() + { + if (this.callbackFunction != null) this.callbackFunction(true); + this.hide(); + } + + show(message /*String*/, okText /*String*/, closeText /*String*/, callbackFunction /*Action*/) + { + this.active = true; + this.callbackFunction = callbackFunction; + this.parentClip.addChild(this); + + this.boxWidth = this.fixedBoxWidth; + this.boxHeight = this.fixedBoxHeight; + + this.background.width = this.boxWidth; + this.background.height = this.boxHeight; + + this.addChild(this.text); + this.removeChild(this.scrollText); + + this.text.textAreaWidth = this.background.width * 0.75; + this.text.setText(message, "Arial", 14); + + this.okButton.setButtonText(okText); + this.cancelButton.setButtonText(closeText); + + if (closeText == "") this.removeChild(this.cancelButton); + else this.addChild(this.cancelButton); + + if (okText == "") this.removeChild(this.okButton); + else this.addChild(this.okButton); + + this.layout(); + this.showDialog(); + } + + layout() + { + //Rect texDims = text.getRect(); + //text.SetTint(Color.blue); + this.text.x = (this.boxWidth - this.text.width) * 0.5; + this.text.y = 30; + + this.scrollText.x = 10; + this.scrollText.y = this.text.y; + + var space = (this.boxWidth - this.okButton.width - this.cancelButton.width) * 0.33; + this.okButton.x = space; + if (!this.cancelButton.hasParent) this.okButton.x = (this.boxWidth * 0.5 - this.okButton.width * 0.5); + this.okButton.y = this.boxHeight - (this.okButton.height * 1.5); + + this.cancelButton.x = this.okButton.x + this.okButton.width + space; + if (!this.okButton.hasParent) this.cancelButton.x = this.boxWidth * 0.5 - this.cancelButton.width * 0.5; + this.cancelButton.y = this.boxHeight - (this.cancelButton.height * 1.5); + + this.dialogWidth = this.boxWidth; + this.dialogHeight = this.boxHeight; + + // autosize the box on default view + if (this.text.y + this.text.height > this.okButton.y) + { + this.background.height = this.text.y + this.text.height + this.okButton.height * 2; + this.dialogHeight = this.background.height; + this.okButton.y = this.background.height - (this.okButton.height * 1.5); + this.cancelButton.y = this.okButton.y; + } + } +} \ No newline at end of file diff --git a/shared/js/Engine/Utils/Keyboard.js b/shared/js/Engine/Utils/Keyboard.js index 2f4ab9e..fe9dce9 100644 --- a/shared/js/Engine/Utils/Keyboard.js +++ b/shared/js/Engine/Utils/Keyboard.js @@ -77,9 +77,9 @@ onKeyDown(event) { - if (event.keyCode == this.KEY.F5) return; - if (event.keyCode == this.KEY.L && event.ctrlKey) return; - if (event.keyCode == this.KEY.I && event.ctrlKey && event.shiftKey) return; + //if (event.keyCode == this.KEY.F5) return; + //if (event.keyCode == this.KEY.L && event.ctrlKey) return; + //if (event.keyCode == this.KEY.I && event.ctrlKey && event.shiftKey) return; event.preventDefault(); if (event.repeat) return; diff --git a/shared/js/Game/GameDialogs.js b/shared/js/Game/GameDialogs.js new file mode 100644 index 0000000..b1c5d59 --- /dev/null +++ b/shared/js/Game/GameDialogs.js @@ -0,0 +1,14 @@ +class GameDialogs +{ + showPrettyMessageBox(message, okText, closeText, callbackFunction, controller, overLayer) + { + if (callbackFunction === undefined) callbackFunction = null; + if (controller === undefined) controller = null; + if (overLayer === undefined) overLayer = false; + + var dialog = Engine.DialogManagerInstance.getDialog(PrettyMessageBox, overLayer ? Engine.DialogManagerStatics.UseLayer.Over : Engine.DialogManagerStatics.UseLayer.Dialogs); + dialog.show(message, okText, closeText, callbackFunction, null); + + return dialog; + } +} diff --git a/index.html b/index.html index 60e2379..b6889d2 100644 --- a/index.html +++ b/index.html @@ -72,10 +72,11 @@ - - - + + + + diff --git a/index.js b/index.js index 469e75e..a126949 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,12 @@ this.win = win; win.showDevTools(); - window.addEventListener('resize', this.resize.bind(this)); + window.addEventListener("keyup", event => + { + if (event.key == "F5") win.reload(); + }); + + window.addEventListener('resize', this.resize.bind(this)); // start up express this.app = express(); @@ -36,14 +41,14 @@ const address = Object.values(os.networkInterfaces()).flatMap(i => i).filter(i => i.family == "IPv4" && !i.internal)[0].address - var gameContainer = document.getElementById("gameContainer"); - Engine.InitEngine(gameContainer, { width: window.innerWidth, height: window.innerHeight, roundPixels: false} ); + var gameContainer = document.getElementById("gameContainer"); + Engine.InitEngine(gameContainer, { width: window.innerWidth, height: window.innerHeight, roundPixels: false} ); - Game.Server = wsServer; + Game.Server = this.wsServer; Game.Address = address; - var gameManager = new GameManager(); - gameManager.init("shared/js/", HostGame); + var gameManager = new GameManager(); + gameManager.init("shared/js/", HostGame); } connect(req) diff --git a/shared/js/Engine/Dialogs/PrettyMessageBox.js b/shared/js/Engine/Dialogs/PrettyMessageBox.js new file mode 100644 index 0000000..f1bc33d --- /dev/null +++ b/shared/js/Engine/Dialogs/PrettyMessageBox.js @@ -0,0 +1,129 @@ +class PrettyMessageBox extends Engine.Dialog +{ + //public delegate void MessageBoxCallback(bool doSomething); + constructor(parentClip /*Drawable*/) + { + super(parentClip); + + this.okButton = new Engine.DrawableButton("Button_SimpleGreen", "OK"); + this.cancelButton = new Engine.DrawableButton("Button_SimpleRed", "Cancel"); + this.text = new Engine.DrawableText(); + this.scrollText = new ScrollingTextBox(); + this.boxWidth = 380; + this.boxHeight = 200; + this.fixedBoxWidth = 380; + this.fixedBoxHeight = 200; + this.callbackFunction = null; + + this.background = new Engine.Drawable("BGStandard"); + + this.text.textAreaWidth = this.boxWidth * 0.75; + this.text.textAreaHeight = this.boxHeight * 0.75; + + this.name = "MessageBox"; + this.background.setNineRect(0.4, 0.4, 0.6, 0.6); + this.background.width = this.boxWidth; + this.background.height = this.boxHeight; + + this.backgroundBounds = new Engine.Drawable(); + this.backgroundBounds.setAsBox(this.backgroundBounds.graphics, this.boxWidth, this.boxHeight, new Color(0, 0, 0, 127), 1); + + this.addChild(this.background); + this.addChild(this.text); + + this.okButton.setWidth(100); + this.cancelButton.setWidth(100); + + var space = (this.boxWidth - this.okButton.width - this.cancelButton.width) / 3; + + this.okButton.y = this.boxHeight - (this.okButton.height * 1.5); + this.okButton.x = space; + + this.cancelButton.y = this.okButton.y; + this.cancelButton.x = this.okButton.x + this.okButton.width + space; + + this.addChild(this.okButton); + this.addChild(this.cancelButton); + + this.cancelButton.onClick = () => this.clickedCancel(); + this.okButton.onClick = () => this.clickedOK(); + + this.dialogWidth = this.boxWidth; + this.dialogHeight = this.boxHeight; + } + + clickedCancel() + { + if (this.callbackFunction != null) this.callbackFunction(false); + this.hide(); + } + + clickedOK() + { + if (this.callbackFunction != null) this.callbackFunction(true); + this.hide(); + } + + show(message /*String*/, okText /*String*/, closeText /*String*/, callbackFunction /*Action*/) + { + this.active = true; + this.callbackFunction = callbackFunction; + this.parentClip.addChild(this); + + this.boxWidth = this.fixedBoxWidth; + this.boxHeight = this.fixedBoxHeight; + + this.background.width = this.boxWidth; + this.background.height = this.boxHeight; + + this.addChild(this.text); + this.removeChild(this.scrollText); + + this.text.textAreaWidth = this.background.width * 0.75; + this.text.setText(message, "Arial", 14); + + this.okButton.setButtonText(okText); + this.cancelButton.setButtonText(closeText); + + if (closeText == "") this.removeChild(this.cancelButton); + else this.addChild(this.cancelButton); + + if (okText == "") this.removeChild(this.okButton); + else this.addChild(this.okButton); + + this.layout(); + this.showDialog(); + } + + layout() + { + //Rect texDims = text.getRect(); + //text.SetTint(Color.blue); + this.text.x = (this.boxWidth - this.text.width) * 0.5; + this.text.y = 30; + + this.scrollText.x = 10; + this.scrollText.y = this.text.y; + + var space = (this.boxWidth - this.okButton.width - this.cancelButton.width) * 0.33; + this.okButton.x = space; + if (!this.cancelButton.hasParent) this.okButton.x = (this.boxWidth * 0.5 - this.okButton.width * 0.5); + this.okButton.y = this.boxHeight - (this.okButton.height * 1.5); + + this.cancelButton.x = this.okButton.x + this.okButton.width + space; + if (!this.okButton.hasParent) this.cancelButton.x = this.boxWidth * 0.5 - this.cancelButton.width * 0.5; + this.cancelButton.y = this.boxHeight - (this.cancelButton.height * 1.5); + + this.dialogWidth = this.boxWidth; + this.dialogHeight = this.boxHeight; + + // autosize the box on default view + if (this.text.y + this.text.height > this.okButton.y) + { + this.background.height = this.text.y + this.text.height + this.okButton.height * 2; + this.dialogHeight = this.background.height; + this.okButton.y = this.background.height - (this.okButton.height * 1.5); + this.cancelButton.y = this.okButton.y; + } + } +} \ No newline at end of file diff --git a/shared/js/Engine/Utils/Keyboard.js b/shared/js/Engine/Utils/Keyboard.js index 2f4ab9e..fe9dce9 100644 --- a/shared/js/Engine/Utils/Keyboard.js +++ b/shared/js/Engine/Utils/Keyboard.js @@ -77,9 +77,9 @@ onKeyDown(event) { - if (event.keyCode == this.KEY.F5) return; - if (event.keyCode == this.KEY.L && event.ctrlKey) return; - if (event.keyCode == this.KEY.I && event.ctrlKey && event.shiftKey) return; + //if (event.keyCode == this.KEY.F5) return; + //if (event.keyCode == this.KEY.L && event.ctrlKey) return; + //if (event.keyCode == this.KEY.I && event.ctrlKey && event.shiftKey) return; event.preventDefault(); if (event.repeat) return; diff --git a/shared/js/Game/GameDialogs.js b/shared/js/Game/GameDialogs.js new file mode 100644 index 0000000..b1c5d59 --- /dev/null +++ b/shared/js/Game/GameDialogs.js @@ -0,0 +1,14 @@ +class GameDialogs +{ + showPrettyMessageBox(message, okText, closeText, callbackFunction, controller, overLayer) + { + if (callbackFunction === undefined) callbackFunction = null; + if (controller === undefined) controller = null; + if (overLayer === undefined) overLayer = false; + + var dialog = Engine.DialogManagerInstance.getDialog(PrettyMessageBox, overLayer ? Engine.DialogManagerStatics.UseLayer.Over : Engine.DialogManagerStatics.UseLayer.Dialogs); + dialog.show(message, okText, closeText, callbackFunction, null); + + return dialog; + } +} diff --git a/shared/js/Game/GameManager.js b/shared/js/Game/GameManager.js index 29d0443..1adac9c 100644 --- a/shared/js/Game/GameManager.js +++ b/shared/js/Game/GameManager.js @@ -17,8 +17,9 @@ this.frameTime = 0; } - init(jsRoot) + init(jsRoot, gameClass) { + this.gameClass = gameClass; EngineSettings.AssetRoot = nw ? "shared/images/" : "images/"; EngineSettings.Pixi.ticker.add(delta => { this.lastFrameTime = performance.now(); this.update(delta); }); @@ -97,7 +98,7 @@ UILoaded() { - if (++this.loadCount >= this.expectedLoadCount) this.game = Game.InitGame(Engine.rootDrawable); + if (++this.loadCount >= this.expectedLoadCount) this.game = Game.InitGame(Engine.rootDrawable, this.gameClass); } /*