Skip to content

Commit

Permalink
Make logpanel optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraq committed Jun 2, 2024
1 parent d813a71 commit 7f6e5b9
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import nz.net.ultraq.redhorizon.engine.graphics.imgui.ControlsOverlay
import nz.net.ultraq.redhorizon.engine.graphics.imgui.DebugOverlay
import nz.net.ultraq.redhorizon.engine.graphics.imgui.GuiEvent
import nz.net.ultraq.redhorizon.engine.graphics.imgui.ImGuiElement
import nz.net.ultraq.redhorizon.engine.graphics.imgui.LogPanel
import nz.net.ultraq.redhorizon.engine.input.InputEventStream
import nz.net.ultraq.redhorizon.engine.input.KeyEvent
import nz.net.ultraq.redhorizon.engine.scenegraph.Scene
Expand Down Expand Up @@ -102,7 +101,6 @@ class Application implements EventTarget {
graphicsSystem.on(SystemReadyEvent) { event ->
graphicsSystem.imGuiLayer.addOverlay(new DebugOverlay(config.debug).toggleWith(inputEventStream, GLFW_KEY_D))
graphicsSystem.imGuiLayer.addOverlay(new ControlsOverlay(inputEventStream).toggleWith(inputEventStream, GLFW_KEY_C))
graphicsSystem.imGuiLayer.addUiElement(new LogPanel(config.debug))
uiElements.each { overlayRenderPass ->
graphicsSystem.imGuiLayer.addUiElement(overlayRenderPass)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class DebugOverlay implements ImGuiElement<DebugOverlay> {
*/
DebugOverlay(boolean enabled) {

ImGuiLoggingAppender.instance.on(ImGuiLogEvent) { event ->
ImGuiLoggingAppender.instance?.on(ImGuiLogEvent) { event ->
if (event.persistentKey) {
persistentLines[event.persistentKey] = event.message
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class ImGuiLayer implements AutoCloseable, InputSource {
this.config = config
debugOverlay = config.debug
drawUiElements = config.startWithChrome
drawOverlays = config.startWithChrome
drawOverlays = config.debug
shaderScanlines = config.scanlines
shaderSharpUpscaling = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import nz.net.ultraq.redhorizon.engine.graphics.GraphicsConfiguration
import nz.net.ultraq.redhorizon.engine.graphics.GraphicsRequests.SpriteSheetRequest
import nz.net.ultraq.redhorizon.engine.graphics.MainMenu.MenuItem
import nz.net.ultraq.redhorizon.engine.graphics.WindowMaximizedEvent
import nz.net.ultraq.redhorizon.engine.graphics.imgui.LogPanel
import nz.net.ultraq.redhorizon.engine.input.KeyEvent
import nz.net.ultraq.redhorizon.engine.resources.ResourceManager
import nz.net.ultraq.redhorizon.engine.scenegraph.Scene
Expand Down Expand Up @@ -110,7 +111,7 @@ class Explorer {
maximized: userPreferences.get(ExplorerPreferences.WINDOW_MAXIMIZED),
renderResolution: new Dimension(1280, 800),
startWithChrome: true
), entryList, nodeList)
), new LogPanel(true), entryList, nodeList)
.addTimeSystem()
.onApplicationStart(this::applicationStart)
.onApplicationStop(this::applicationStop)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class MapViewerScript extends Script<Map> {
}
}
removeEventFunctions << inputEventStream.on(ScrollEvent) { event ->
if (gameWindow.hovered) {
if (gameWindow ? gameWindow.hovered : true) {

// Zoom in/out using CTRL + scroll up/down
if (ctrl) {
Expand All @@ -104,7 +104,7 @@ class MapViewerScript extends Script<Map> {
}
removeControlFunctions << inputEventStream.addControl(
new MouseControl(GLFW_MOD_CONTROL, GLFW_MOUSE_BUTTON_RIGHT, 'Reset scale', { ->
if (gameWindow.hovered) {
if (gameWindow ? gameWindow.hovered : true) {
camera.resetScale()
}
})
Expand All @@ -125,7 +125,7 @@ class MapViewerScript extends Script<Map> {
removeEventFunctions << inputEventStream.on(MouseButtonEvent) { event ->
if (event.button == GLFW_MOUSE_BUTTON_LEFT) {
if (event.action == GLFW_PRESS) {
if (gameWindow.hovered) {
if (gameWindow ? gameWindow.hovered : true) {
dragging = true
}
}
Expand All @@ -137,7 +137,7 @@ class MapViewerScript extends Script<Map> {

// Zoom in/out using the scroll wheel
removeEventFunctions << inputEventStream.on(ScrollEvent) { event ->
if (gameWindow.hovered) {
if (gameWindow ? gameWindow.hovered : true) {
if (event.yOffset < 0) {
scaleIndex = Math.clamp(scaleIndex - 1, 0, scaleRange.length - 1)
}
Expand All @@ -149,7 +149,7 @@ class MapViewerScript extends Script<Map> {
}
removeControlFunctions << inputEventStream.addControl(
new MouseControl(GLFW_MOUSE_BUTTON_RIGHT, 'Reset scale', { ->
if (gameWindow.hovered) {
if (gameWindow ? gameWindow.hovered : true) {
camera.resetScale()
}
})
Expand Down
2 changes: 0 additions & 2 deletions redhorizon-sandbox/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ dependencies {
implementation project(':redhorizon-events')
implementation project(':redhorizon-filetypes')
implementation platform("org.lwjgl:lwjgl-bom:${lwjglVersion}")
implementation "ch.qos.logback:logback-classic:${logbackVersion}"
implementation 'nz.net.ultraq.preferences:preferences:3.1.0'
implementation "org.joml:joml-primitives:${jomlPrimitivesVersion}"
implementation 'org.lwjgl:lwjgl-glfw'
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package nz.net.ultraq.redhorizon.sandbox

import nz.net.ultraq.preferences.Preferences
import nz.net.ultraq.redhorizon.classic.filetypes.IniFile
import nz.net.ultraq.redhorizon.classic.filetypes.MapFile
import nz.net.ultraq.redhorizon.classic.filetypes.PalFile
Expand All @@ -28,6 +27,7 @@ import nz.net.ultraq.redhorizon.engine.graphics.GraphicsConfiguration
import nz.net.ultraq.redhorizon.engine.resources.ResourceManager
import nz.net.ultraq.redhorizon.engine.scenegraph.Scene
import nz.net.ultraq.redhorizon.explorer.PaletteType
import nz.net.ultraq.redhorizon.explorer.objects.GridLines
import nz.net.ultraq.redhorizon.explorer.scripts.MapViewerScript
import nz.net.ultraq.redhorizon.filetypes.Palette

Expand All @@ -43,7 +43,6 @@ import org.slf4j.LoggerFactory
class Sandbox {

private static final Logger logger = LoggerFactory.getLogger(Sandbox)
private static final Preferences userPreferences = new Preferences()
private static final String mapFileName = 'scr01ea.ini'

final Palette palette
Expand All @@ -55,27 +54,25 @@ class Sandbox {
'nz.net.ultraq.redhorizon.classic.filetypes')

static void main(String[] args) {
new Sandbox()
new Sandbox(args.length > 0 && args[0] == '--touchpad-input')
System.exit(0)
}

/**
* Constructor, build the sandbox.
*/
Sandbox() {
Sandbox(boolean touchpadInput) {

palette = getResourceAsStream(PaletteType.RA_TEMPERATE.file).withBufferedStream { inputStream ->
return new PalFile(inputStream).withAlphaMask()
}
touchpadInput = userPreferences.get(SandboxPreferences.TOUCHPAD_INPUT)
this.touchpadInput = touchpadInput

new Application('Sandbox', '0.1.0')
.addAudioSystem()
.addGraphicsSystem(new GraphicsConfiguration(
clearColour: Colour.GREY,
maximized: userPreferences.get(SandboxPreferences.WINDOW_MAXIMIZED),
renderResolution: new Dimension(1280, 800),
startWithChrome: true
renderResolution: new Dimension(1280, 800)
))
.addTimeSystem()
.onApplicationStart(this::applicationStart)
Expand All @@ -85,6 +82,8 @@ class Sandbox {

private void applicationStart(Application application, Scene scene) {

scene << new GridLines()

logger.info('Loading sandbox map, {}', mapFileName)

var mapFile = getResourceAsStream(mapFileName).withBufferedStream { new IniFile(it) as MapFile }
Expand Down

This file was deleted.

0 comments on commit 7f6e5b9

Please sign in to comment.