Files
mame/plugins/timer/init.lua

80 lines
2.3 KiB
Lua
Raw Permalink Normal View History

-- license:BSD-3-Clause
-- copyright-holders:Vas Crabb
-- TODO: track time properly across soft reset and state load
local exports = {
name = 'timer',
version = '0.0.3',
description = 'Game play timer',
license = 'BSD-3-Clause',
author = { name = 'Vas Crabb' } }
2016-04-07 21:42:42 -05:00
local timer = exports
local reset_subscription, stop_subscription
2016-04-07 21:42:42 -05:00
function timer.startplugin()
local total_time = 0
local start_time = 0
2016-04-08 13:18:04 -05:00
local play_count = 0
local emu_total = emu.attotime()
local reference = 0
local lastupdate
local highlight -- hacky - workaround for the menu not remembering the selected item if its ref is nullptr
2016-11-08 09:52:10 +01:00
local function sectohms(time)
local hrs = time // 3600
local min = (time % 3600) // 60
2016-04-08 13:18:04 -05:00
local sec = time % 60
return string.format(_p('plugin-timer', '%03d:%02d:%02d'), hrs, min, sec)
end
local function menu_populate()
lastupdate = os.time()
local refname = (reference == 0) and _p('plugin-timer', 'Wall clock') or _p('plugin-timer', 'Emulated time')
local time = (reference == 0) and (lastupdate - start_time) or manager.machine.time.seconds
local total = (reference == 0) and (total_time + time) or (manager.machine.time + emu_total).seconds
return
{
{ _p("plugin-timer", "Reference"), refname, (reference == 0) and 'r' or 'l' },
{ '---', '', '' },
{ _p("plugin-timer", "Current time"), sectohms(time), "off" },
{ _p("plugin-timer", "Total time"), sectohms(total), "off" },
{ _p("plugin-timer", "Play Count"), tostring(play_count), "off" } },
highlight,
"idle"
end
local function menu_callback(index, event)
if (index == 1) and ((event == 'left') or (event == 'right') or (event == 'select')) then
reference = reference ~ 1
return true
end
highlight = index
return os.time() > lastupdate
end
reset_subscription = emu.add_machine_reset_notifier(
function ()
if emu.romname() ~= '___empty' then
start_time = os.time()
local persister = require('timer/timer_persist')
total_time, play_count, emu_total = persister:start_session()
end
end)
stop_subscription = emu.add_machine_stop_notifier(
function ()
if emu.romname() ~= '___empty' then
local persister = require('timer/timer_persist')
persister:update_totals(start_time)
end
end)
-frontend: Refactored menu event handling and fixed a number of issues. (#8777) * Moved common code for drawing about box, info viewer, and other text box menus to a base class; removed the last of the info viewer logic and the multi-line item hack from the base menu class. * Added previous/next group navigation for general inputs and plugin input selection menus. * Moved message catalog logic to lib/util, allowing osd and emu to use localised messages. * Made the base menu class use the UI manager’s feature for holding session state rather than a static map and mutex. * Improved menu event handling model, and fixed many issues, particularly with menus behaving badly when hidden/shown. * Added better support for menus that don’t participate in the usual menu stack, like the menuless sliders and the save/load state menus. * Made a number of menus refresh state when being shown after being hidden (fixes MT08121 among other issues). * Fixed indication of mounted slot option in the slot option details menu. * Improved appearance of background menus when emulation isn't running - draw all menus in the stack, and darken the background menus to make the edges of the active menu clearer. * Fixed locale issues in -listxml. -debugger: Made GUI debuggers more uniform. * Added new memory view features to Win32 debugger. * Fixed spelling of hexadecimal in Cocoa debugger and added decimal address option. * Fixed duplicate keyboard shortcut in Cocoa debugger (Shift-Cmd-D was both new device window and 64-bit float format). * Made keyboard shortcuts slightly more consistent across debuggers. -plugins: Moved input selection menu and sequence polling code to a common library. Fixed the issue that prevented keyboard inputs being mapped with -steadykey on. -docs: Started adding some documentation for MAME's internal UI, and updated the list of example front-ends. -Regenerated message catalog sources. For translators, the new strings are mostly: * The names of the inputs provided by the OS-dependent layer for things like fullscreen and video features. These show up in the user interface inputs menu. * The names for automatically generated views. These show up in the video options menu - test with a system with a lot of screens to see more variants. * The input macro plugin UI. * A few format strings for analog input assignments. * A few strings for the about box header.
2021-10-31 12:31:16 +11:00
emu.register_menu(menu_callback, menu_populate, _p("plugin-timer", "Timer"))
end
return exports