mirror of
https://github.com/mattrberry/crab.git
synced 2025-01-15 03:40:56 +01:00
add recent rom list in menu
This commit is contained in:
parent
7d34186893
commit
119300b76c
2 changed files with 30 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
|||
require "yaml"
|
||||
|
||||
CONFIG_FILE_PATH = Path["~/.config/crab/"].expand(home: true)
|
||||
CONFIG_FILE_NAME = Path["crab.yml"]
|
||||
CONFIG_FILE_NAME = "crab.yml"
|
||||
CONFIG_FILE = CONFIG_FILE_PATH / CONFIG_FILE_NAME
|
||||
|
||||
Dir.mkdir_p(CONFIG_FILE_PATH)
|
||||
|
@ -11,6 +11,7 @@ class Config
|
|||
include YAML::Serializable
|
||||
property explorer_dir : String?
|
||||
property keybindings : Hash(LibSDL::Keycode, Input)?
|
||||
property recents : Array(String)?
|
||||
property gba : GBA?
|
||||
property gbc : GBC?
|
||||
|
||||
|
@ -80,6 +81,14 @@ def set_keybindings(keybindings : Hash(LibSDL::Keycode, Input)) : Nil
|
|||
write { |config| config.keybindings = keybindings }
|
||||
end
|
||||
|
||||
def recents : Array(String)
|
||||
config.recents || [] of String
|
||||
end
|
||||
|
||||
def set_recents(recents : Array(String)) : Nil
|
||||
write { |config| config.recents = recents }
|
||||
end
|
||||
|
||||
def gbc_bios : String?
|
||||
config.gbc.try(&.bios)
|
||||
end
|
||||
|
|
|
@ -26,6 +26,7 @@ class SDLOpenGLImGuiFrontend < Frontend
|
|||
@blending = false
|
||||
@enable_overlay = false
|
||||
@pause = false
|
||||
@recents : Array(String) = recents
|
||||
|
||||
@opengl_info : OpenGLInfo
|
||||
|
||||
|
@ -85,6 +86,12 @@ class SDLOpenGLImGuiFrontend < Frontend
|
|||
LibSDL.close_audio(1)
|
||||
@controller = init_controller(nil, rom)
|
||||
@file_explorer.clear_selection
|
||||
|
||||
@recents.delete(rom)
|
||||
@recents.insert(0, rom)
|
||||
@recents.pop(@recents.size - 8) if @recents.size > 8
|
||||
set_recents @recents
|
||||
|
||||
LibSDL.set_window_size(@window, @controller.window_width * SCALE, @controller.window_height * SCALE)
|
||||
LibSDL.set_window_position(@window, LibSDL::WindowPosition::CENTERED, LibSDL::WindowPosition::CENTERED)
|
||||
LibGL.viewport(0, 0, @window.width, @window.height)
|
||||
|
@ -175,10 +182,23 @@ class SDLOpenGLImGuiFrontend < Frontend
|
|||
|
||||
open_rom_selection = ImGui.menu_item "Open ROM"
|
||||
open_bios_selection = ImGui.menu_item "Select BIOS" unless @controller.class == StubbedController
|
||||
if ImGui.begin_menu "Recent", @recents.size > 0
|
||||
@recents.each do |recent|
|
||||
load_new_rom(recent) if ImGui.menu_item recent
|
||||
end
|
||||
ImGui.separator
|
||||
if ImGui.menu_item "Clear"
|
||||
@recents.clear
|
||||
set_recents @recents
|
||||
end
|
||||
ImGui.end_menu
|
||||
end
|
||||
ImGui.separator
|
||||
ImGui.menu_item "Overlay", "", pointerof(@enable_overlay)
|
||||
# ImGui.menu_item "Blend", "", pointerof(@enable_blend) todo: re-implement blending now that frames are cleared
|
||||
ImGui.menu_item "Pause", "", pointerof(@pause)
|
||||
open_keybindings = ImGui.menu_item "Keybindings"
|
||||
ImGui.separator
|
||||
exit if ImGui.menu_item "Exit"
|
||||
ImGui.end_menu
|
||||
|
||||
|
|
Loading…
Reference in a new issue