Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CR] Filter in vehicle menu for part installation #13341

Closed
wants to merge 2 commits into from

Conversation

Maykeye
Copy link
Contributor

@Maykeye Maykeye commented Aug 18, 2015

This PR adds ability to filter parts for iinstallation in vehicle interaction menu.

Displaying query for filtering caused nasty artifacts (windows were not redrawn nor in console, not in tiles, there were black spaces) so I've updated curses port to redraw them and patched the same artifacts that appeared after closing help '?'.

I've tested it on linux with tiles on and off, can't say if behaves properly on windows.

return 0;
}
win->draw = true;
for (int i = 0; i < win->height; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of repeating the loop, why not call clearok?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it doesn't work.

clearok updates stdscr without touching win and I don't know if it's intended or not, but calling it doesn't fix black screen issues, while looping does.

(Oh, there's also a problem with clearok that its proper declaration is int clearok(WINDOW *win, bool bf);, not clearok(WINDOW *win) - but since veh_interact.cpp doesn't call it, I left it as is)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clearok updates stdscr without touching win and I don't know if it's intended or not, but calling it doesn't fix black screen issues, while looping does.

I did not see that, it looks like a bug. It's only used inside of wclear, which in turn is only used by clear in cursesport.cpp, it's a mess and it's probably not worth touching it.

The implementation of redrawwin is fine.

@drbig
Copy link
Contributor

drbig commented Aug 19, 2015

Regarding redrawwin - I wonder if it could help with: 1) drawing the deathcam message in tiles, 2) drawing the "now saving" popup in tiles.

@Maykeye
Copy link
Contributor Author

Maykeye commented Aug 19, 2015

@drbig, popup is actually separated issue caused by double buffering. cursesport updates out of screen buffer without actually outputting anything to the screen. When game ends saving files, it redraws game screen(overwrites out of screen buffer once more), then after a while back buffer is outputted to the screen but popups are already gone.

@Night-Pryanik
Copy link
Contributor

Will it be possible solution for this (#11706)?

@Maykeye
Copy link
Contributor Author

Maykeye commented Aug 19, 2015

@Night-Pryanik No. It simply adds possibility to filter vehicle parts by name.

It doesn't change the actual installation process where parts are removed from inventory and attached to the vehicle, only UI which happens before the actual installation begins.

/*
* case insensitive string::find( string::findstr ). findstr must be lowercased
*/
bool lcmatch(const std::string &str, const std::string &findstr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some specific reason why you moved this function around? game.cpp isn't really a good place for it, it has nothing to do with the game itself.

While ui.cpp may not be the best, it kind of fits there as it is mostly used for UI related stuff. Alternatively, it could be in in output.cpp or in catacharset.cpp (the function is btw. not Unicode-compatible).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved declaration to game.h so every second .cpp file would stop redeclaring it. And since it was moved to game.h for that, it might be defined in game.cpp as well.

I originally moved it to ui.h, but most files that used the function didn't include ui.h so it was not that much better(which I forgot to uninclude - it doesn't make sense to include entire ui.h for simple lcmatch). I din't find general helper functions header or file so moved to game.h which is included everywhere

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Because it's already included everywhere" is pretty much the worst reason to put a function in a particular file, the fact that everything includes game.h already is a major problem that we're trying to fix, and this makes the code go the wrong way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it doesn't feel like UI. It's string function. Should I make new header or there more appropriate header?

@Maykeye
Copy link
Contributor Author

Maykeye commented Aug 30, 2015

Rebased to fix unmergeability.

@Coolthulhu
Copy link
Contributor

This PR didn't have updates for a while.

Is there a major problem with it that prevents merging?

It looks quite useful, as out vehicle part menu got quite bloated.

@BevapDin
Copy link
Contributor

I'm not convinced that letting the input context redraw the windows is a good solution. In my opinion, the caller (the loop that calls input_context::handle_input) should detect that the key bindings menu had been opened (which is already possible, just check for the action "HELP_KEYBINDINGS") and it should then redraw the screen.

This is an important difference when the normal drawing code displays the current key bindings. If the bindings were changed and the input context only calls the curses redraw-functions, it will draw the current buffer, which will still contain the information about the old key bindings. That information must be updated by the caller as only the caller knows where to print it.

@Maykeye
Copy link
Contributor Author

Maykeye commented Sep 24, 2015

Just checking for HELP_KEYBINDINGS bloats code too much:

veh_interact.cpp for example has five instances of main_context.handle_input().

Adding special case for HELP_KEYBINDINGS also spreads windows information around code: most windows are created near input_context so if e.g. new window was added, it's much easier to add window to list of windows to redraw, than to remember where windows are actually updated.

If handler needs more than curses functions, it can check action just as input_context::display_help does already. In most cases it is not necessary.

Filter filters parts by name

Updated curses port to behave more like curses

* Added redrawwin

* Added handling of null pointer to wrefresh

Moved lcmatch to game.cpp and game.h

Function lcmatch was declared too many times in too many files.

Since all of them included game.h already and including ui.h
made little sense just for lcmatch, moved it to game.*

Workaround for popup in tiles

In several places in tiles build popup didn't appear for the following
reason:

Curses port writes to back renderer but the actual screen is not updated anywhere in
cursesport.cpp. It's updated from renderer in try_update
which is called from message handling routine.

If screen was rewritten before message processed started again, then no matter
how many calls to wrefresh were done, they were not actually printed
to the screen. Only backscreen renderer changed.

Update wrefresh to update actual renderer.
Note that it's not placed inside of `if (win->draw)`.
In e.g. when popup() calls refresh mainwin->draw is false.

Refactored input_context to keep track of windows

Now after input_context corrupts screen after HELP_KEYBINDING,
it redraws windows that were assigned to it.

As result, it fixes  CleverRaven#8514, fixes CleverRaven#9835 in

* Character menu (in-game)
* Construction menu
* Character creation menu
* World creation menu
* Vehicle interaction menu
@sparr
Copy link
Member

sparr commented Dec 17, 2015

Am I correctly interpreting the discussion here that the only thing wrong with the original feature is that our current window-redrawing code can't handle it, and no one likes the various possible solutions to that problem?

Conflicts:
	src/crafting.cpp
	src/game.cpp
	src/input.cpp
	src/newcharacter.cpp
@Maykeye
Copy link
Contributor Author

Maykeye commented Jan 16, 2016

@sparr
Essentially yes. Currently there is no good way which works both in tiles and curses to redraw screen after it was corrupted by window after it was destroyed.

@Maykeye
Copy link
Contributor Author

Maykeye commented Mar 18, 2016

Out of sync

@Maykeye Maykeye closed this Mar 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants