Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show brush selection #136

Merged
merged 2 commits into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions editor/CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Fix reset import model dialog on close
- Change scene camera to be base camera class
- Duplicate materials from inspector
- Show brush selection

[0.4.2] ~ 10/24/2022
- Fix shader compilation error for Terrain when using normal maps
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.mbrlabs.mundus.editor.ui.modules.inspector.components.terrain

import com.kotcrab.vis.ui.widget.tabbedpane.Tab
import com.mbrlabs.mundus.editor.tools.brushes.TerrainBrush

abstract class BaseBrushTab(private val parent: TerrainComponentWidget,
private val mode: TerrainBrush.BrushMode)
: Tab(false, false) {

protected val terrainBrushGrid: TerrainBrushGrid = TerrainBrushGrid(parent, mode);

/**
* Clears selection.
*/
override fun onHide() {
super.onHide()
terrainBrushGrid.clearSelection()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class TerrainBrushGrid(private val parent: TerrainComponentWidget,
private val strengthSlider = ImprovedSlider(0f, 1f, 0.1f)

private val toolManager: ToolManager = Mundus.inject()
private val buttons: ArrayList<FaTextButton> = arrayListOf()

init {
Mundus.registerEventListener(this)
Expand Down Expand Up @@ -75,6 +76,11 @@ class TerrainBrushGrid(private val parent: TerrainComponentWidget,
add(settingsTable).expand().fill().padLeft(5f).padRight(5f).padTop(5f).row()
}

fun clearSelection() {
toolManager.deactivateTool()
buttons.forEach { it.style = FaTextButton.styleNoBg }
}

fun activateBrush(brush: TerrainBrush) {
try {
brush.mode = brushMode
Expand All @@ -95,10 +101,14 @@ class TerrainBrushGrid(private val parent: TerrainComponentWidget,
*/
private inner class BrushItem(brush: TerrainBrush) : VisTable() {
init {
add(FaTextButton(brush.iconFont))
val button = FaTextButton(brush.iconFont)
add(button)
buttons.add(button)
addListener(object : ClickListener() {
override fun clicked(event: InputEvent?, x: Float, y: Float) {
clearSelection()
activateBrush(brush)
button.style = FaTextButton.styleActive
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,21 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.utils.Align
import com.kotcrab.vis.ui.widget.VisLabel
import com.kotcrab.vis.ui.widget.VisTable
import com.kotcrab.vis.ui.widget.tabbedpane.Tab
import com.mbrlabs.mundus.editor.tools.brushes.TerrainBrush

/**
* @author Marcus Brummer
* @version 30-01-2016
*/
class TerrainFlattenTab(parent: TerrainComponentWidget) : Tab(false, false) {
class TerrainFlattenTab(parent: TerrainComponentWidget) : BaseBrushTab(parent, TerrainBrush.BrushMode.FLATTEN) {

private val table = VisTable()
private val brushGrid: TerrainBrushGrid

init {
table.align(Align.left)
table.add(VisLabel("Hold shift to sample a height")).center().row()

brushGrid = TerrainBrushGrid(parent, TerrainBrush.BrushMode.FLATTEN)
table.add(brushGrid).expand().fill().row()
table.add(terrainBrushGrid).expand().fill().row()
}

override fun getTabTitle(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import com.badlogic.gdx.utils.Align
import com.kotcrab.vis.ui.VisUI
import com.kotcrab.vis.ui.util.dialog.Dialogs
import com.kotcrab.vis.ui.widget.*
import com.kotcrab.vis.ui.widget.tabbedpane.Tab
import com.mbrlabs.mundus.commons.assets.Asset
import com.mbrlabs.mundus.commons.assets.TextureAsset
import com.mbrlabs.mundus.commons.terrain.SplatTexture
Expand All @@ -45,7 +44,7 @@ import java.io.IOException
* @author Marcus Brummer
* @version 30-01-2016
*/
class TerrainPaintTab(private val parentWidget: TerrainComponentWidget) : Tab(false, false) {
class TerrainPaintTab(private val parentWidget: TerrainComponentWidget) : BaseBrushTab(parentWidget, TerrainBrush.BrushMode.PAINT) {

companion object {
private val TAG = TerrainPaintTab::class.java.simpleName
Expand All @@ -63,7 +62,7 @@ class TerrainPaintTab(private val parentWidget: TerrainComponentWidget) : Tab(fa
root.align(Align.left)

// brushes
root.add(TerrainBrushGrid(parentWidget, TerrainBrush.BrushMode.PAINT)).expand().fill().padBottom(5f).row()
root.add(terrainBrushGrid).expand().fill().padBottom(5f).row()

// textures
root.add(VisLabel("Textures:")).padLeft(5f).left().row()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@ package com.mbrlabs.mundus.editor.ui.modules.inspector.components.terrain
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.utils.Align
import com.kotcrab.vis.ui.widget.VisTable
import com.kotcrab.vis.ui.widget.tabbedpane.Tab
import com.mbrlabs.mundus.editor.tools.brushes.TerrainBrush

/**
* @author JamesTKhan
* @version July 17, 2022
*/
class TerrainSmoothTab(parent: TerrainComponentWidget) : Tab(false, false) {
class TerrainSmoothTab(parent: TerrainComponentWidget) : BaseBrushTab(parent, TerrainBrush.BrushMode.SMOOTH) {

private val table = VisTable()
private val brushGrid: TerrainBrushGrid

init {
table.align(Align.left)

brushGrid = TerrainBrushGrid(parent, TerrainBrush.BrushMode.SMOOTH)
table.add(brushGrid).expand().fill().row()
table.add(terrainBrushGrid).expand().fill().row()
}

override fun getTabTitle(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,19 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.utils.Align
import com.kotcrab.vis.ui.widget.VisLabel
import com.kotcrab.vis.ui.widget.VisTable
import com.kotcrab.vis.ui.widget.tabbedpane.Tab
import com.mbrlabs.mundus.editor.tools.brushes.TerrainBrush

/**
* @author Marcus Brummer
* @version 30-01-2016
*/
class TerrainUpDownTab(private val parent: TerrainComponentWidget) : Tab(false, false) {
class TerrainUpDownTab(private val parent: TerrainComponentWidget) : BaseBrushTab(parent, TerrainBrush.BrushMode.RAISE_LOWER) {
private val table = VisTable()

init {
table.align(Align.left)
table.add(VisLabel("Hold shift to lower")).center().row()
table.add(TerrainBrushGrid(this.parent, TerrainBrush.BrushMode.RAISE_LOWER)).expandX().fillX().row()
table.add(terrainBrushGrid).expandX().fillX().row()
}

override fun getTabTitle(): String {
Expand Down