Commit graph

179 commits

Author SHA1 Message Date
Kp fcd5991eeb Clamp kconfig window size to screen size 2021-02-25 03:53:49 +00:00
Kp 6c814ff095 Draw kconfig background based on window dimensions
Replace hardcoded dimensions with the dimensions used by the window
being drawn.
2021-02-25 03:53:49 +00:00
Dmitry Grigoryev fbd05a1592 optimize include files (include what you use) 2021-02-06 21:38:50 +01:00
Kp 479884288c Always delegate to window_create for send_creation_events 2020-12-20 20:39:07 +00:00
Kp 29d3e9a8c4 Move kconfig initialization to NSDMI where possible 2020-10-22 02:26:16 +00:00
Kp ae657007fe Remove send_creation_events parameter
It is always nullptr.
2020-10-22 02:26:16 +00:00
Kp ffb653c0b8 Pass control_info & to various functions
Switch from a direct global reference to passing control_info& as a
parameter.
2020-10-12 03:28:26 +00:00
Kp b3c3066a38 Fix no-joystick build
When joystick support is not present, `event_joystick_get_button` is not
declared in joy.h.

Fixes: c24864b180 ("make menus controllable with joystick")
2020-09-11 03:08:02 +00:00
Kp 52660dd40c Make kc_menu inherit from window 2020-08-28 00:18:45 +00:00
Kp 22afbfce15 Use zip for kc_set_exclusive_binding iteration 2020-08-28 00:18:45 +00:00
Kp b6a6cec9bd Move kconfig_start_changing to dsx 2020-08-28 00:18:45 +00:00
Kp 96c007687c Move kc_drawquestion to dcx 2020-08-28 00:18:45 +00:00
Kp b79eff0e5c Deduplicate fades[]
Two identical copies were defined in different places.  Use the global
one for both consumers.
2020-08-28 00:18:45 +00:00
Kp 1d3e546848 Inline window_get_canvas
The helper returns a reference to a mutable canvas, so there is no
isolation provided by using the helper.
2020-08-28 00:18:45 +00:00
Kp 74a698253b Fix kconfig zip traversal past the end of kcm_* arrays
For historical reasons, the kcm_* arrays are smaller than the player's
configuration settings.  Move the kcm_ arrays to be the first range
passed to zip, so that traversal does not exceed the array.

Fixes: d959eeca8f ("Use zip in kconfig to allow use of range-based for")
2020-08-28 00:18:45 +00:00
Kp a8b6a8393b Fix PCH build
Add a comment in the #include directive to hide it from the PCH scanner,
since this file should not be included in the PCH.  It is only used in
one file, and it is included under special circumstances.  In
particular, it is included while inside a namespace.
2020-08-10 03:45:14 +00:00
Kp 6285878c4c Add color_palette_index type alias, to note palette-related uint8_t 2020-07-16 02:31:04 +00:00
Kp 6af56a27f2 Remove outdated joystick preprocessor guards
Testing for buttons||hats||axes is equivalent to testing for
joysticks!=0, since SConstruct forces joysticks=0 when
buttons == 0 && hats == 0 && axes == 0.  Remove tests of
buttons||hats||axes when those occur inside a test for joysticks!=0.
2020-07-16 02:31:04 +00:00
Kp 4f26a205ea Increase height of kconfig joystick window
The addition of the binding for a menu key causes the axes to float off
the bottom of the window.  Increase the window height to fix this.
2020-07-09 02:47:18 +00:00
Kp 5735175999 Merge 'refs/pull/516/head' into master 2020-07-09 02:47:18 +00:00
Kp 569802e00f Convert kconfig array lookups to require correct enumerated type
This ensures that an array is indexed by the appropriate type.  Indexing
a mouse array with a joystick index is undefined behavior, and with this
change, such undefined behavior is now a compilation error.
2020-07-05 23:34:33 +00:00
Kp a27b50a357 Use symbolic names to look up kconfig offsets 2020-07-05 23:34:33 +00:00
Kp d959eeca8f Use zip in kconfig to allow use of range-based for 2020-07-05 23:34:33 +00:00
Kp 6e4b63e098 Use C++17 std::size instead of custom lengthof
lengthof was added to provide the size of C arrays.  C++17 std::size is
now available, and can serve the same purpose.  Remove the custom
lengthof.

The generated code is the same in both cases, other than the change in
line numbers caused by removal of the #include directives.
2020-07-05 23:34:32 +00:00
Martin Fiedler 853a0c41e1 added joystick binding for showing ingame menu
A new configurable joystick button binding is
introduced that opens the ingame menu, i.e. the
menu that appears when pressing the Escape key.

Fortunately, there was still enough space left
in the button binding maps for both games. The
configuration screen, however, needed to be
extended by a row to make room for the new
binding on d2x.

One known issue: When using an old player
configuration file, the menu button bindings
are initially set to J1 B1, because the unused
slots in DefaultKeySettings used to be
initialized that way. There's not much we can
do about that; the player needs to remove
these bogus assignments by hand. We can (and
do) prevent that from happening again, though,
by initializing new player files with correct
unmapped buttons.
2020-06-29 23:16:04 +02:00
Martin Fiedler c24864b180 make menus controllable with joystick
In most menus, keyboard commands are synthesized
from controller buttons, leveraging the existing
axis-to-button translation.

Menu controls are currently fixed:
- button 0 (A) is confirm (Enter)
- button 1 (B) is cancel (Esc)
- button 2 (X) is switch (Space)
- button 3 (Y) is delete (Delete)
- axes 0 and 1 (main analog pad) maps to cursor keys
- all hats (D-pads) map to cursor keys

Title screens and credits can be confirmed
with any joystick button or axis motion too.
2020-06-28 17:08:26 +02:00
Kp b08620292d Fix input handling in automap
The automap code keeps a mostly-private secondary copy of control_info.
The change to reset control_info before the event loop reset the main
copy of control_info for the automap, not the copy that the automap
actually used.  Fix this by passing the desired control_info to relevant
functions instead of always using the global variable Controls.

Fixes: c621a970c6 ("Reset kconfig counters once, before the event loop")
2020-05-28 03:21:22 +00:00
Kp c621a970c6 Reset kconfig counters once, before the event loop 2020-05-27 03:07:17 +00:00
Kp 53761500f1 Qualify uses of std::array 2020-05-02 21:18:42 +00:00
Kp 5fa8c06914 Add experimental support for autosaves
Set autosave interval to 10 minutes, unless specified in the player's
configuration file.  Players can change the autosave to 0 minutes to
disable it.
2020-04-19 20:47:07 +00:00
Kp cc144647b5 Make kconfig.ui-table.cpp compile when freestanding
Special macros are used to pass information to
`generate-kconfig-udlr.py`.  Provide default definitions for these
macros in `kconfig.ui-table.cpp`, and override them in the one build
where they need to be special.  This enables `kconfig.ui-table.cpp` to
build cleanly when invoked from the command line in the compilation
database.
2019-12-22 05:34:08 +00:00
Kp f26d91bbe2 Change kconfig type/state fields to enums 2019-12-22 05:34:08 +00:00
Kp d2f2f98850 Use symbolic STATE_NONE for kconfig entries with no state bit 2019-12-22 05:34:08 +00:00
daivuk 74ef8b02e6 Added axis buttons
Each axis can act as two buttons in both ways.
For example, a player might map slide left and slide right to J1 -A1 and J1 +A1 as button presses instead of the slide L/R axis.

This is mostly to fix XBox 360 Controller Left and Right triggers. But it can work on every axis if the player wishes to bind them.
2019-09-01 13:11:14 -04:00
Kp d355ef4030 Pass font to various drawing functions 2018-05-19 23:21:42 +00:00
Kp 08446f0ab6 Pass font to gr_string,gr_printf 2018-05-19 23:21:42 +00:00
Kp 3796c46440 Improve default keybindings
Slide left/right: A/D
Slide up/down: C/X
Accelerate/reverse: W/S
Afterburner (D2 only): Left-Shift

This produces the more FPS-typical WASD layout for
forward/left/back/right movement, and maps the crouch/stand bindings to
slide up/down.  This ticket sat for longer than it should have (though
it never missed a release).  Several competing designs were suggested,
but only one could be made active.  After consideration, I used my own
bindings on the basis that, while some other bindings may be better,
every other configuration repurposed a classic weapons-fire key to
movement.  Returning players who get the "new defaults" on a newly
created pilot profile might be very surprised by having their fire keys
move.  Since these are only defaults, and can be rebound by the player
with a few minutes work, these defaults do not need to be perfect.  They
just need to be an improvement over original Descent.

Delete unexpand-cpp-kconfig-key.py.  It will likely never be needed, and
was added in the prior commit solely to have a file to recover if it
ever is needed.

Requested-by: Mako88 <https://github.com/dxx-rebirth/dxx-rebirth/issues/214>
2018-05-12 21:13:05 +00:00
Kp 1fd8c184fd Convert kconfig default keys to their CPP define equivalents 2018-05-12 21:13:05 +00:00
Kp e69e195a3a Remove useless static_cast<float> in kconfig
gcc-8 warns that static_cast<float>(float_var + 1) is useless.  Remove
the cast.

References: <https://github.com/dxx-rebirth/dxx-rebirth/issues/388>
2018-05-05 22:33:55 +00:00
Kp 2571081962 Rewrite UI table to use symbolic constants for positioning 2018-02-01 05:38:47 +00:00
Kp 22fe81666a Unify some control_info fields 2018-01-29 01:56:40 +00:00
Kp 66b0f6bf37 Compile out unused joystick entries
Presently, user profiles are not portable between a build with
max_axes_per_joystick=0 and one with max_axes_per_joystick!=0.
Attempting to do so causes some buttons to be assigned to the wrong
action.  Since the intended use case for max_axes_per_joystick=0 and
similar is to completely remove joystick support on a system that will
never use a joystick, this is acceptable for now.  A future overhaul to
improve storage of user kconfig settings may fix this.
2017-12-24 00:28:35 +00:00
Kp f73b783095 Generate kconfig udlr relations at build time 2017-12-24 00:28:35 +00:00
Kp 0106833538 Move kconfig ui tables to separate file 2017-12-24 00:28:35 +00:00
Kp 0a95ecc3a6 Mark changed values in kconfig UI 2017-12-15 04:47:30 +00:00
Kp 7311712399 Compile out joystick key settings when DXX_MAX_JOYSTICKS=0 2017-12-05 05:29:55 +00:00
Kp 35bd791d32 Remove obsolete kconfig TABLE_CREATION code
It generates code different from the current definitions, even when no
logical changes are present.  This code has not been used in at least 2
years, since commit bc7c469ab2 ("Use
array<> for more globals") changed the definitions of some variables
that this code regenerates, and this code still generates the old
definition.  Future changes will cause further deviation.
2017-12-05 05:29:55 +00:00
Kp d049f738c8 Convert various gr_set_current_canvas calls to reference form 2017-11-05 20:49:08 +00:00
Kp 49c0cdae2e Simplify calls to gr_set_default_canvas
Rather than use an inline wrapper and rely on the compiler optimizer to
redirect gr_set_current_canvas(nullptr) to gr_set_default_canvas,
rewrite all relevant calls directly in the source.

git grep -l 'gr_set_current_canvas' | xargs sed -i -e 's:gr_set_current_canvas(\s*NULL\|nullptr\s*);:gr_set_default_canvas();:'
2017-11-05 20:49:08 +00:00
Kp 170d0ac777 Pass canvas &to nm_draw_background 2017-04-08 16:48:20 +00:00