From 5a6454a12ddfe7ba8347d024da6c4e97f79eda05 Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Tue, 27 Jun 2023 19:29:52 +0530 Subject: [PATCH] video options and fix shaders lol --- src/gui/GuiXboxListButton.hx | 14 +++- src/gui/GuiXboxOptionsList.hx | 28 +++++-- src/gui/OptionsListGui.hx | 4 +- src/gui/VideoOptionsGui.hx | 101 ++++++++++++++++++++++++++ src/shaders/DefaultCubemapMaterial.hx | 1 - src/shaders/NoiseTileMaterial.hx | 1 - src/shaders/RefractMaterial.hx | 1 - 7 files changed, 136 insertions(+), 14 deletions(-) create mode 100644 src/gui/VideoOptionsGui.hx diff --git a/src/gui/GuiXboxListButton.hx b/src/gui/GuiXboxListButton.hx index cc0db78a..bb75e1a8 100644 --- a/src/gui/GuiXboxListButton.hx +++ b/src/gui/GuiXboxListButton.hx @@ -114,9 +114,12 @@ class GuiXboxListButton extends GuiControl { } public override function onMouseRelease(mouseState:MouseState) { - if (mouseState.handled) + var renderRect = getHitTestRect(); + renderRect.position = renderRect.position.add(new Vector(24, 20)); // Offset + renderRect.extent.set(439, 53); + if (!renderRect.inRect(mouseState.position)) return; - mouseState.handled = true; + super.onMouseRelease(mouseState); if (this.pressedAction != null && !disabled) { this.pressedAction(new GuiEvent(this)); @@ -124,9 +127,12 @@ class GuiXboxListButton extends GuiControl { } public override function onMouseEnter(mouseState:MouseState) { - if (mouseState.handled) + var renderRect = getHitTestRect(); + renderRect.position = renderRect.position.add(new Vector(24, 20)); // Offset + renderRect.extent.set(439, 53); + if (!renderRect.inRect(mouseState.position)) return; - mouseState.handled = true; + super.onMouseEnter(mouseState); if (buttonSounds && !disabled) { diff --git a/src/gui/GuiXboxOptionsList.hx b/src/gui/GuiXboxOptionsList.hx index 42866ea7..0fbc0bc4 100644 --- a/src/gui/GuiXboxOptionsList.hx +++ b/src/gui/GuiXboxOptionsList.hx @@ -22,7 +22,7 @@ class GuiXboxOptionsList extends GuiControl { var onChangeFunc:Int->Bool = null; - public function new(icon:Int, name:String, values:Array) { + public function new(icon:Int, name:String, values:Array, midcolumn:Float = 0.3) { super(); this.options = values; @@ -58,7 +58,7 @@ class GuiXboxOptionsList extends GuiControl { rightShadeFilter.enable = false; leftButton = new GuiAnim([arrowButtonImage, arrowButtonImagePressed]); - leftButton.position = new Vector(815 * 0.3, 0); + leftButton.position = new Vector(815 * midcolumn, 0); leftButton.extent = new Vector(114, 94); leftButton.anim.filter = leftShadeFilter; this.addChild(leftButton); @@ -82,19 +82,20 @@ class GuiXboxOptionsList extends GuiControl { var arial14fontdata = ResourceLoader.getFileEntry("data/font/Arial Bold.fnt"); var arial14b = new BitmapFont(arial14fontdata.entry); @:privateAccess arial14b.loader = ResourceLoader.loader; - var arial14 = arial14b.toSdfFont(cast 26 * Settings.uiScale, h2d.Font.SDFChannel.MultiChannel); + var arial14 = arial14b.toSdfFont(cast 25 * Settings.uiScale, h2d.Font.SDFChannel.MultiChannel); labelText = new GuiText(arial14); - labelText.position = new Vector(155, 36); + labelText.position = new Vector(815 * midcolumn - 125, 36); labelText.extent = new Vector(100, 35); labelText.vertSizing = Top; + labelText.justify = Right; labelText.text.text = name; labelText.text.textColor = 0x787878; this.addChild(labelText); optionText = new GuiText(arial14); - optionText.position = new Vector(400, 36); - optionText.extent = new Vector(200, 35); + optionText.position = new Vector(815 * midcolumn + 155.5, 36); + optionText.extent = new Vector(815 * (0.8 - midcolumn) / 2, 35); optionText.vertSizing = Top; optionText.text.text = values[0]; optionText.text.textColor = 0x787878; @@ -108,6 +109,21 @@ class GuiXboxOptionsList extends GuiControl { optIcon.anim.currentFrame = 1; labelText.text.textColor = 0x101010; optionText.text.textColor = 0x101010; + } else { + var htr = this.getHitTestRect(); + htr.position = htr.position.add(new Vector(24, 20)); + htr.extent.set(776, 53); + if (htr.inRect(mouseState.position)) { + bgFill.anim.currentFrame = 1; + optIcon.anim.currentFrame = 1; + labelText.text.textColor = 0x101010; + optionText.text.textColor = 0x101010; + } else { + bgFill.anim.currentFrame = 0; + optIcon.anim.currentFrame = 0; + labelText.text.textColor = 0x787878; + optionText.text.textColor = 0x787878; + } } var leftBtnRect = leftButton.getHitTestRect(); var rightBtnRect = rightButton.getHitTestRect(); diff --git a/src/gui/OptionsListGui.hx b/src/gui/OptionsListGui.hx index 520ac771..345c322b 100644 --- a/src/gui/OptionsListGui.hx +++ b/src/gui/OptionsListGui.hx @@ -58,7 +58,9 @@ class OptionsListGui extends GuiImage { MarbleGame.canvas.pushDialog(new MarbleSelectGui()); }); btnList.addButton(3, 'Input and Sound Options', (e) -> {}); - btnList.addButton(3, 'Video Options', (e) -> {}); + btnList.addButton(3, 'Video Options', (e) -> { + MarbleGame.canvas.setContent(new VideoOptionsGui()); + }); btnList.addButton(3, 'Misc Options', (e) -> {}); btnList.addButton(5, 'How to Play', (e) -> { MarbleGame.canvas.setContent(new AboutMenuOptionsGui()); diff --git a/src/gui/VideoOptionsGui.hx b/src/gui/VideoOptionsGui.hx new file mode 100644 index 00000000..a37c9f05 --- /dev/null +++ b/src/gui/VideoOptionsGui.hx @@ -0,0 +1,101 @@ +package gui; + +import src.MarbleGame; +import hxd.res.BitmapFont; +import h3d.Vector; +import src.ResourceLoader; +import src.Settings; + +class VideoOptionsGui extends GuiImage { + public function new() { + var res = ResourceLoader.getImage("data/ui/xbox/BG_fadeOutSoftEdge.png").resource.toTile(); + super(res); + var domcasual32fontdata = ResourceLoader.getFileEntry("data/font/DomCasualD.fnt"); + var domcasual32b = new BitmapFont(domcasual32fontdata.entry); + @:privateAccess domcasual32b.loader = ResourceLoader.loader; + var domcasual32 = domcasual32b.toSdfFont(cast 42 * Settings.uiScale, MultiChannel); + + this.horizSizing = Width; + this.vertSizing = Height; + this.position = new Vector(); + this.extent = new Vector(640, 480); + + var scene2d = MarbleGame.canvas.scene2d; + + var offsetX = (scene2d.width - 1280) / 2; + var offsetY = (scene2d.height - 720) / 2; + + var subX = 640 - (scene2d.width - offsetX) * 640 / scene2d.width; + var subY = 480 - (scene2d.height - offsetY) * 480 / scene2d.height; + + var innerCtrl = new GuiControl(); + innerCtrl.position = new Vector(offsetX, offsetY); + innerCtrl.extent = new Vector(640 - subX, 480 - subY); + innerCtrl.horizSizing = Width; + innerCtrl.vertSizing = Height; + this.addChild(innerCtrl); + + var coliseumfontdata = ResourceLoader.getFileEntry("data/font/ColiseumRR.fnt"); + var coliseumb = new BitmapFont(coliseumfontdata.entry); + @:privateAccess coliseumb.loader = ResourceLoader.loader; + var coliseum = coliseumb.toSdfFont(cast 44 * Settings.uiScale, MultiChannel); + + var rootTitle = new GuiText(coliseum); + rootTitle.position = new Vector(100, 30); + rootTitle.extent = new Vector(1120, 80); + rootTitle.text.textColor = 0xFFFFFF; + rootTitle.text.text = "VIDEO OPTIONS"; + rootTitle.text.alpha = 0.5; + innerCtrl.addChild(rootTitle); + + var yPos = 160; + + var resolutionOpt = new GuiXboxOptionsList(1, "Fullscreen Res", [ + "1024 x 800", + "1280 x 720", + "1366 x 768", + "1440 x 900", + "1600 x 900", + "1920 x 1080" + ], 0.35); + + resolutionOpt.vertSizing = Bottom; + resolutionOpt.horizSizing = Right; + resolutionOpt.position = new Vector(380, yPos); + resolutionOpt.extent = new Vector(815, 94); + innerCtrl.addChild(resolutionOpt); + + yPos += 60; + + var displayOpt = new GuiXboxOptionsList(1, "Resolution", ["Fullscreen", "Windowed"], 0.35); + displayOpt.vertSizing = Bottom; + displayOpt.horizSizing = Right; + displayOpt.position = new Vector(380, yPos); + displayOpt.extent = new Vector(815, 94); + innerCtrl.addChild(displayOpt); + + yPos += 60; + + var vsyncOpt = new GuiXboxOptionsList(1, "VSync", ["Disabled", "Enabled"], 0.35); + vsyncOpt.vertSizing = Bottom; + vsyncOpt.horizSizing = Right; + vsyncOpt.position = new Vector(380, yPos); + vsyncOpt.extent = new Vector(815, 94); + innerCtrl.addChild(vsyncOpt); + + var bottomBar = new GuiControl(); + bottomBar.position = new Vector(0, 590); + bottomBar.extent = new Vector(640, 200); + bottomBar.horizSizing = Width; + bottomBar.vertSizing = Bottom; + innerCtrl.addChild(bottomBar); + + var backButton = new GuiXboxButton("Ok", 160); + backButton.position = new Vector(960, 0); + backButton.vertSizing = Bottom; + backButton.horizSizing = Right; + backButton.gamepadAccelerator = ["OK"]; + backButton.pressedAction = (e) -> MarbleGame.canvas.setContent(new OptionsListGui()); + bottomBar.addChild(backButton); + } +} diff --git a/src/shaders/DefaultCubemapMaterial.hx b/src/shaders/DefaultCubemapMaterial.hx index ce55f259..1741bccb 100644 --- a/src/shaders/DefaultCubemapMaterial.hx +++ b/src/shaders/DefaultCubemapMaterial.hx @@ -78,7 +78,6 @@ class DefaultCubemapMaterial extends hxsl.Shader { var diffuse = diffuseMap.get(calculatedUV); var outCol = diffuse; var bumpNormal = normalMap.get(calculatedUV * secondaryMapUvFactor).xyz * 2 - 1; - bumpNormal.y *= -1; var incidentRay = normalize(pixelTransformedPosition - camera.position); var reflectionRay = reflect(incidentRay, transformedNormal); diff --git a/src/shaders/NoiseTileMaterial.hx b/src/shaders/NoiseTileMaterial.hx index 39c9eadf..3bf56761 100644 --- a/src/shaders/NoiseTileMaterial.hx +++ b/src/shaders/NoiseTileMaterial.hx @@ -58,7 +58,6 @@ class NoiseTileMaterial extends hxsl.Shader { } function fragment() { var bumpNormal = normalMap.get(calculatedUV * secondaryMapUvFactor).xyz * 2 - 1; - bumpNormal.y *= -1; var bumpDot = saturate(dot(bumpNormal, outLightVec.xyz)); // Diffuse part var diffuse = diffuseMap.get(calculatedUV); diff --git a/src/shaders/RefractMaterial.hx b/src/shaders/RefractMaterial.hx index 1a861ecd..701d5427 100644 --- a/src/shaders/RefractMaterial.hx +++ b/src/shaders/RefractMaterial.hx @@ -60,7 +60,6 @@ class RefractMaterial extends hxsl.Shader { } function fragment() { var bumpNormal = normalMap.get(calculatedUV * secondaryMapUvFactor).xyz * 2 - 1; - bumpNormal.y *= -1; // Refract var distortion = 0.3; var off = projectedPosition;