-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1915 from Legend-of-Dragoon-Modding/main.1910.mon…
…itor-config Add monitor config (closes #1910)
- Loading branch information
Showing
4 changed files
with
95 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/legend/game/modding/coremod/config/MonitorConfigEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package legend.game.modding.coremod.config; | ||
|
||
import legend.game.inventory.screens.controls.Dropdown; | ||
import legend.game.saves.ConfigCategory; | ||
import legend.game.saves.ConfigCollection; | ||
import legend.game.saves.ConfigEntry; | ||
import legend.game.saves.ConfigStorageLocation; | ||
import org.lwjgl.PointerBuffer; | ||
|
||
import static legend.core.GameEngine.CONFIG; | ||
import static legend.core.GameEngine.RENDERER; | ||
import static org.lwjgl.glfw.GLFW.glfwGetMonitorName; | ||
import static org.lwjgl.glfw.GLFW.glfwGetMonitors; | ||
|
||
public class MonitorConfigEntry extends ConfigEntry<Integer> { | ||
public MonitorConfigEntry() { | ||
super( | ||
0, | ||
ConfigStorageLocation.GLOBAL, | ||
ConfigCategory.GRAPHICS, | ||
i -> new byte[] {i.byteValue()}, | ||
bytes -> (int)bytes[0] | ||
); | ||
|
||
this.setEditControl((current, gameState) -> { | ||
final Dropdown dropdown = new Dropdown(); | ||
dropdown.onSelection(index -> gameState.setConfig(this, index)); | ||
|
||
final PointerBuffer monitorPtrs = glfwGetMonitors(); | ||
|
||
for(int i = 0; i < monitorPtrs.limit(); i++) { | ||
final long ptr = monitorPtrs.get(i); | ||
dropdown.addOption(glfwGetMonitorName(ptr)); | ||
} | ||
|
||
dropdown.setSelectedIndex(CONFIG.getConfig(this)); | ||
return dropdown; | ||
}); | ||
} | ||
|
||
@Override | ||
public void onChange(final ConfigCollection configCollection, final Integer oldValue, final Integer newValue) { | ||
super.onChange(configCollection, oldValue, newValue); | ||
RENDERER.window().updateMonitor(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters