Commit graph

168 commits

Author SHA1 Message Date
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 71ca1a7553 Do not abort on failure to load PCX
Using assert to check for conditions that can be caused by improper
configuration is wrong.  If the load failed, return.
2020-05-17 23:35:26 +00:00
Kp cc38cdf4b8 Qualify uses of std::make_unique 2020-05-02 21:18:42 +00:00
Kp 53761500f1 Qualify uses of std::array 2020-05-02 21:18:42 +00:00
Kp d197ba42c3 Fix mouse-selection in listboxes
Commit d355ef4030 removed a seemingly unnecessary modification of the
global variable grd_curcanv->cv_font, after eliminating all local reads
of it.  However, a non-local read, buried in listbox_mouse, depended on
grd_curcanv->cv_font being set to a MEDIUM font.  After that commit,
grd_curcanv->cv_font retained its prior value, which is not a MEDIUM
font.  This caused listbox_mouse to compute an incorrect height of the
lines in the listbox, which manifested as the game choosing the wrong
line when the mouse is clicked in the listbox.

Fix the problem by explicitly using MEDIUM3_FONT, since that was
usually the value left in grd_curcanv->cv_font prior to that commit.  In
some cases, a different MEDIUM font would be left there, but all the
MEDIUM fonts have the same height, so they are interchangeable for this
purpose.

Reported-by: Q3BFG10K <https://github.com/dxx-rebirth/dxx-rebirth/issues/498>
Fixes: d355ef4030 ("Pass font to various drawing functions")
2020-04-04 19:30:23 +00:00
Kp ed4cb636b7 Fix memory leak when deleting listbox items 2020-03-14 03:41:30 +00:00
Kp 597cb41717 Downgrade PCX failures from Error to CON_URGENT
There is no need to kill the program due to a missing or malformed PCX file.
2019-07-07 22:00:02 +00:00
Kp 063bf29225 Enable -Wimplicit-fallthrough=5; fix resulting breaks
This enables using -Wimplicit-fallthrough with ccache+distcc, which
strip the fallthrough comments, but do not strip the attribute
annotationns.
2019-04-04 04:29:03 +00:00
Kp bba8a327a0 Remove use of -Wno-implicit-fallthrough 2018-08-24 02:58:21 +00:00
Kp d97afc2ad5 Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog.  This was substantially more trouble than it should have been,
but the result is good.

Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.

Now:
- Empty directories are hidden entirely.  There is nothing for the user
  to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
  parent, since there is no ambiguity about what the user would want.
  If the parent in turn has only that one promoted element when the scan
  of the parent finishes, then the element can be promoted up again.
  This continues until the root is reached or until a level has more
  than one entry.  For this purpose, both missions and directories count
  as entries.
- Directory entries are decorated to inform the user how many
  immediate subdirectories are present, how many missions are present
  immediately in the directory, and how many missions total are present,
  counting all subdirectories.  If there are zero immediate
  subdirectories, then the directory count is not shown.  For this
  purpose, directories that were hidden due to a lack of missions are
  not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
  user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
  sub-dialog, appropriate sub-dialogs are opened so that the last played
  mission can be pre-selected.

Currently, there is no in-game override to return to the prior rollup
rules.

Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
Kp 60a99f1ea2 Allow longer mission titles in New Game dialog 2018-06-27 03:34:34 +00:00
Kp c8b04d0c83 Allow more items on screen in a listbox 2018-06-18 04:11:39 +00:00
Kp d786122b37 Force type of ternary expressions
When using variadic forwarding constructors
(`sconf_cxx11_inherit_constructor=force-failure`) instead of inheriting
constructors, some ternary expressions become ambiguous due to the
inability to forward the `explicit` modifier from the base class
constructor to the derived class.  Add explicit type overrides to
disambiguate these expressions to the result that the compiler would
have picked on its own when using inheriting constructors.
2018-06-12 02:53:06 +00:00
Kp f51b7b6b20 Enforce separation of font X/Y scaling 2018-06-08 04:04:05 +00:00
Kp d355ef4030 Pass font to various drawing functions 2018-05-19 23:21:42 +00:00
Kp fda1eb851e Pass fonts to LINE_SPACING 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 e63bbe8c52 Set d_event type at construction 2018-05-12 18:24:19 +00:00
Kp 685137d5f5 Fix infinite loop in newmenu default handler
If no character matches the typed character, the loop should exit when
`lb->citem == cc`, which should happen after every entry is visited
once.  However, if no item is selected, `lb->citem == -1`, and `cc` is
never `-1`, so the exit path never triggers.  Rewrite the loop to be
bounded by number of steps, rather than bounded by returning to a
particular offset.  This also protects against undefined behavior if the
menu had zero elements.
2018-04-28 21:58:46 +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 4f6c8575f2 Cache canvas in listbox_create_structure 2017-04-30 16:25:19 +00:00
Kp 8d2bc05624 Cache canvas in listbox_draw 2017-04-30 16:25:19 +00:00
Kp 170d0ac777 Pass canvas &to nm_draw_background 2017-04-08 16:48:20 +00:00
Kp aaf7874235 Remove canvas juggling in nm_draw_background 2017-04-08 16:48:19 +00:00
Kp d827e73de9 Pass canvas &to draw_item 2017-04-08 16:48:19 +00:00
Kp 795eeecb3f Move marquee data to substructure 2017-03-26 21:53:47 +00:00
Kp 6c0be636ea Combine draw_item case branches 2017-03-11 19:56:29 +00:00
Kp a245e47fcc Pass canvas to nm_string_inputbox 2017-03-11 19:56:29 +00:00
Kp b21fc54ba4 Pass canvas to nm_string_black 2017-03-11 19:56:29 +00:00
Kp a7344b7dd0 Pass canvas to nm_string_slider 2017-03-11 19:56:29 +00:00
Kp 51a69a5a65 Pass canvas to nm_draw_background1 2017-03-11 19:56:29 +00:00
Kp b10ec2cb01 Cache canvas in newmenu_create_structure 2017-03-10 01:22:33 +00:00
Kp 569d64e927 Propagate Hack_DblClick_MenuMode 2017-02-11 21:42:47 +00:00
Kp d8638c6c89 Pass canvas to UP_ARROW_MARKER, DOWN_ARROW_MARKER 2017-02-11 21:42:43 +00:00
Kp 6b8f08142f Pass canvas to LINE_SPACING
Macro LINE_SPACING previously used global grd_curcanv implicitly.
Change it to take a canvas argument.  Change all callers to pass
grd_curcanv, so that usage is explicit.
2017-02-11 21:42:42 +00:00
Kp ed9fe62d85 Expand GHEIGHT
As a macro, it always refers to the global grd_curcanv.  This interferes
with converting canvas handling to be an argument.  Expand GHEIGHT so
that uses of grd_curcanv can be changed individually.
2017-02-11 21:42:42 +00:00
Kp 03c43b1d7f Expand GWIDTH
As a macro, it always refers to the global grd_curcanv.  This interferes
with converting canvas handling to be an argument.  Expand GWIDTH so
that uses of grd_curcanv can be changed individually.
2017-02-11 21:42:42 +00:00
Kp 6f81d13c41 Pass canvas to gr_set_curfont 2017-02-11 21:42:38 +00:00
Kp f88cfd9901 Cache canvas in newmenu_mouse MBTN_LEFT 2017-02-11 21:42:38 +00:00
Kp 3becce8cb1 Pass canvas to nm_rstring 2017-02-11 21:42:36 +00:00
Kp fbc16efa0f Pass canvas to nm_string 2017-02-11 21:42:36 +00:00
Kp 725ec77006 Avoid unnecessary allocations in nm_string
Only allocate a temporary string if a tab exists to be overwritten.
2017-02-11 21:42:36 +00:00
Kp 2c6e8fd446 Simplify nm_string 2017-02-11 21:42:36 +00:00
Kp d65ad71099 Cache newmenu_mouse LINE_SPACING 2017-02-11 21:42:35 +00:00
Kp ae33aaafc1 Pass canvas to gr_set_fontcolor 2017-02-11 21:42:32 +00:00
Kp 43a700a200 Prefer grs_main_bitmap::reset() to direct reinitialization
This ensures that any allocated resources are always freed.
2017-02-11 21:42:31 +00:00
Kp 5da784dbed Pass canvas to gr_{,u}string 2017-01-08 22:32:00 +00:00
Kp 1ef6b9d5bc Pass font to gr_get_string_size 2017-01-08 22:31:59 +00:00
Kp 0480ba8030 Pass canvas to gr_string(int,int,const char*,int,int) 2017-01-08 22:31:59 +00:00