add recent rom list in menu

This commit is contained in:
Matthew Berry 2021-07-20 08:47:39 -07:00
parent 7d34186893
commit 119300b76c
2 changed files with 30 additions and 1 deletions

View file

@ -1,7 +1,7 @@
require "yaml" require "yaml"
CONFIG_FILE_PATH = Path["~/.config/crab/"].expand(home: true) 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 CONFIG_FILE = CONFIG_FILE_PATH / CONFIG_FILE_NAME
Dir.mkdir_p(CONFIG_FILE_PATH) Dir.mkdir_p(CONFIG_FILE_PATH)
@ -11,6 +11,7 @@ class Config
include YAML::Serializable include YAML::Serializable
property explorer_dir : String? property explorer_dir : String?
property keybindings : Hash(LibSDL::Keycode, Input)? property keybindings : Hash(LibSDL::Keycode, Input)?
property recents : Array(String)?
property gba : GBA? property gba : GBA?
property gbc : GBC? property gbc : GBC?
@ -80,6 +81,14 @@ def set_keybindings(keybindings : Hash(LibSDL::Keycode, Input)) : Nil
write { |config| config.keybindings = keybindings } write { |config| config.keybindings = keybindings }
end 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? def gbc_bios : String?
config.gbc.try(&.bios) config.gbc.try(&.bios)
end end

View file

@ -26,6 +26,7 @@ class SDLOpenGLImGuiFrontend < Frontend
@blending = false @blending = false
@enable_overlay = false @enable_overlay = false
@pause = false @pause = false
@recents : Array(String) = recents
@opengl_info : OpenGLInfo @opengl_info : OpenGLInfo
@ -85,6 +86,12 @@ class SDLOpenGLImGuiFrontend < Frontend
LibSDL.close_audio(1) LibSDL.close_audio(1)
@controller = init_controller(nil, rom) @controller = init_controller(nil, rom)
@file_explorer.clear_selection @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_size(@window, @controller.window_width * SCALE, @controller.window_height * SCALE)
LibSDL.set_window_position(@window, LibSDL::WindowPosition::CENTERED, LibSDL::WindowPosition::CENTERED) LibSDL.set_window_position(@window, LibSDL::WindowPosition::CENTERED, LibSDL::WindowPosition::CENTERED)
LibGL.viewport(0, 0, @window.width, @window.height) LibGL.viewport(0, 0, @window.width, @window.height)
@ -175,10 +182,23 @@ class SDLOpenGLImGuiFrontend < Frontend
open_rom_selection = ImGui.menu_item "Open ROM" open_rom_selection = ImGui.menu_item "Open ROM"
open_bios_selection = ImGui.menu_item "Select BIOS" unless @controller.class == StubbedController 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 "Overlay", "", pointerof(@enable_overlay)
# ImGui.menu_item "Blend", "", pointerof(@enable_blend) todo: re-implement blending now that frames are cleared # ImGui.menu_item "Blend", "", pointerof(@enable_blend) todo: re-implement blending now that frames are cleared
ImGui.menu_item "Pause", "", pointerof(@pause) ImGui.menu_item "Pause", "", pointerof(@pause)
open_keybindings = ImGui.menu_item "Keybindings" open_keybindings = ImGui.menu_item "Keybindings"
ImGui.separator
exit if ImGui.menu_item "Exit" exit if ImGui.menu_item "Exit"
ImGui.end_menu ImGui.end_menu