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

Captains log, star date 2020... #4795

Merged
merged 10 commits into from
Jul 13, 2020
Merged

Conversation

impaktor
Copy link
Member

@impaktor impaktor commented Feb 16, 2020

Introduction

Inspired by this flight log add-on for original Frontier, I've implemented something similar. This is highly work in progress. I've used the FlightLog that automatically logs departures from stations, and arrival/departure times into systems. I've also added a custom log, that can be created by writing some fitting string, and pressing enter; and show all three in a Flight Log tab in InfoView.

Currently text can only be entered into the custom logs, but I'll extend the other two logs (system, and station) so one can enter, as @nozmajner suggested: "this was a smelly station".

Potential: Custom entries at start give backstory

I've played around with adding a custom log entry from the mainmenu, when starting a new game, so the first entry could be:

"Just picked up the ship that uncle Nick left for me to inherrit. This rusty old bucket isn't much, but together we'll write our destiny in the stars, and it's my new home. Can't wait to undock!"

"Now I've cleared my debt with Wu, and sold all my belongings, and all I got was this lousy ship. By it's mine, and with it I can escape this god forsaken world and build a brighter future, forever onwards!"

Biggest hurdle

  • Currently, it's to get the three logs (system, station, custom) to be printed in date-order, instead of printing each one in turn. I think the FlightLog method might have some method that sorts them, or combines them, but they have different table fields, so... need to think.

  • Multiline input. I've experimented with adding multiline text-input field, but the game crashes if I try to use it, so for now, it's just a dead commit.

  • Also, this is a savebumping PR, since the updated FlightLog library will be incompatible with the previous, since I'm adding more fields (also log player's money), and a custom log.

To do

  • 0 Allow re-editing old entries in custom logs
  • 1 Clear flightlog upon new game (bug of old?)
  • 2 Remove (only?) custom entries
  • 3 Do we also want to be able to remove SYSTEM and STATION auto-logs as well?
  • 4 Add startup custom entry, backstory of how the ship ended up in the player's possession
  • 5 Edit/update Entries of SYSTEM and STATION auto-logs as well?
  • 6 sort them on dates, not printing SYSTEM, STATION & CUSTOM logs separately. EDIT: Solved this by printing each log in a separate tab, thus Add support for IMGUI tabs in pigui #4893
  • 7 Better "Location" strings for CUSTOM, for if docked, landed, in orbit etc.
  • 8 Document new methods in FlightLog
  • 9 Put strings in to translation system
  • 10 Use coloured text for some of the log-fields? E.g. Date, or similar?
  • 11 Better Log icon for InfoView tab
  • 12 Replace "Remove"-button with trashcan?
  • 13 Maybe/probably support multiline text box/input.
  • 14 Save versioning of flightlog, to avoid save-bumping.
  • 15. Make textWrapped include the secondary optional argument in LuaPiGui.cpp

For future

These are things that might be intuitive next steps to add, but I don't plan to do them, so up for grabs:

  • Export log to text-file?
  • Filter logs
  • Hyperlink systems/stations to map

Current state

This is a screenshot of where I'm at. It works pretty well, as is, I think, although only single line text-input, and the tree logs are only date-sorted within each group (First it prints all custom logs, then all system logs, then all station logs).

2020-02-23-122512_1600x900_scrot

Closes #204

@sturnclaw
Copy link
Member

@impaktor you could avoid bumping saves by simply serializing a Version field in the FlightLog object, and then checking if that field is nil and fixing up the log entries. It looks there aren't many changes which would need fixing up; you can simply display N/A if need be when there isn't data stored in a save file about how much money you had.

I'd like to retain backwards save compatibility as much as possible, and this really isn't a feature that's worth breaking saves over, in my opinion. It's a little more work, but it avoids invalidating saves.

@impaktor impaktor force-pushed the captains_log branch 5 times, most recently from 66d490c to 9fe7f44 Compare February 20, 2020 08:39
@impaktor
Copy link
Member Author

impaktor commented Feb 20, 2020

  • I've added more friendly versioning to the to-do list.

  • The to-do list is numbered if anyone want to reference / give feedback to it. E.g. I don't know if we want to be able to remove the auto-generated log-entries (every system we've been to and every station we departed from).

  • I've now combined the "Flight state" and "location" string, for custom logs so, when the player creates a custom log entry, it will automatically generate a suitable string:

    • Location: Flying in space, relative to Sirius A
    • Location: Docked at Torvald's station, in orbit around Earth
    • Location: Docked at London station, on Earth
    • Location: Landed on Mars, lat, long
  • I've updated the screenshot in the first post (I've fixed the "::" seen in screenshot -- an artefact of me re-using strings from translation system)

@impaktor impaktor force-pushed the captains_log branch 7 times, most recently from 766f5c2 to aca89a3 Compare February 24, 2020 12:17
@impaktor impaktor mentioned this pull request Feb 28, 2020
@impaktor impaktor force-pushed the captains_log branch 3 times, most recently from 267309b to 8f259e0 Compare March 6, 2020 12:26
impaktor referenced this pull request Apr 30, 2020
Patch kindly suggested by Gliese852
@impaktor impaktor force-pushed the captains_log branch 2 times, most recently from ad85af0 to 24a6651 Compare May 7, 2020 16:31
@impaktor impaktor force-pushed the captains_log branch 3 times, most recently from aa04c60 to c2f5752 Compare June 27, 2020 13:12
@impaktor
Copy link
Member Author

impaktor commented Jun 27, 2020

OK, this was stalled since 4 months, because I didn't want to deal with the underlying three different data structures for logs, and how to sort them / weave them together (or re-write the whole thing).

Solution: Tabs! And it also feels more feature rich this way, since now the player sees they got three logs, instead of just the one! For now, you can add text entry field to all three logs (custom log, auto-log system events, and auto-log station-events), but only the custom logs can be deleted fully. Maybe it's a feature, maybe it's a bug. I dunno.

Things of interest for others to review

When starting a new game, there's some back story (and some hints):

2020-06-27-152341_1600x900_scrot

2020-06-27-140320_1600x900_scrot

2020-06-27-152401_1600x900_scrot

Remains?

This PR is now done, so I'm removing the WIP on it. Please hold off with merging this at least a few days. (I should probably squash the last commit into the first one, both are just adding documentation to lua functions) Done.

Future

There are many routes to develop this further, like integrating this with sector view, whith notes on systems, or filter and search function, or auto-logging buying/selling prices in station log, or/and kills, crimes, missions? (I suspect a re-write of the FlightLog module might be needed then). Anyway, I don't intend to do anything more on this, now, so I'll leave any future work to others.

@impaktor impaktor marked this pull request as ready for review June 27, 2020 13:35
@robothauler
Copy link
Contributor

image

@impaktor impaktor force-pushed the captains_log branch 2 times, most recently from f6f7770 to f763362 Compare July 3, 2020 09:30
@impaktor
Copy link
Member Author

impaktor commented Jul 3, 2020

I've made the final tweaks on this now. I've changed it so station events are logged when docking, instead of un-docking, since I find that more intuitive.

Also, I realized when displaying the logs separately, station logs should also show which planet and system one docked in, or else one has to look in system log to see time stamp for different jumps.

Perhaps more (other) station events can be logged, like what the player buys, but I suspect that will require reworking flightlog library a bit.

Ready for final review.

@impaktor
Copy link
Member Author

@Web-eWorks if you want to hold this for review, then speak up, as I'd like to merge this the comming days.

I've noticed I have unused definition (local orbiteer = ui.fonts.orbiteer) that I could remove, but other than that, I'm happy with the code. (that's my self-review 😃 )

Copy link
Member

@sturnclaw sturnclaw left a comment

Choose a reason for hiding this comment

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

The game-start prose is a little awkward but that's nothing particularly major. I've suggested one minor change, but I think this is pretty good to go.

name = l.FLIGHT_LOG,
icon = ui.theme.icons.bookmark,
showView = true,
draw = function() drawLog() end,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
draw = function() drawLog() end,
draw = drawLog,

You can also pass the function by value directly instead of invoking another function call each time we draw this module. It's not a big inefficiency, but it makes things a little less confusing.

Comment on lines +836 to +864

--
-- Function: ui.coloredSelectedIconButton
--
-- > clicked = ui.coloredSelectedIconButton(icon, button_size, is_selected,
-- > frame_padding, bg_color, fg_color, tooltip, img_size)
--
--
-- Example:
--
-- > clicked = ui.coloredSelectedIconButton(ui.theme.icons.bullseye, Vector2(10,10), false,
-- > 0, ui.theme.colors.buttonBlue, Color(255,0,0), "Click for action##42", Vector2(8,8))
--
-- Parameters:
--
-- icon - image to place on button, e.g. from ui.theme.icons
-- button_size - size of button, Vector2
-- is_selected - bool
-- frame_padding - number
-- bg_color - Color(R,G,B), for background
-- fg_color - Color(R,G,B), for forground
-- tooltip - string, mouseover text, will be used as ID, must be unique, append "##uniqueID" if needed
-- img_size - size of icon on the button, Vector2
--
-- Returns:
--
-- clicked - true if button was clicked
--
ui.coloredSelectedIconButton = function(icon, thesize, is_selected, frame_padding, bg_color, fg_color, tooltipID, img_size)
Copy link
Member

Choose a reason for hiding this comment

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

THANK YOU for documenting this function. This made my day!

impaktor added 7 commits July 13, 2020 07:49
This method used to require each instance to have a unique tooltip string.
Now it supports having the same tooltip repeated, provided it is appended with
a "...##ID", where ID is a unique identifier. Also added documentation.
Defaults to empty. Will allow player to enter info on system/station
e.g. "Smelly station, but nice ring system".
We have a flightlog for automatically logging station-departures,
and one for system arrival/departure.

Have now added a custom one, that captures player stats, and a custom field
for text entries.
Lets us keep backwards compatibility as we add more features to this library
@impaktor
Copy link
Member Author

I merged in master, and now, for some reason, this segfaults when launching pioneer,

Thread 1 "pioneer" received signal SIGSEGV, Segmentation fault.
ImGui::BeginTabBar (str_id=0x7fffffffcd30 "mytabbar", flags=flags@entry=0) at /home/me/usr/src/pioneer/contrib/imgui/imgui_widgets.cpp:6407
6407	    if (window->SkipItems)
(gdb) bt
#0  ImGui::BeginTabBar (str_id=0x7fffffffcd30 "mytabbar", flags=flags@entry=0) at /home/me/usr/src/pioneer/contrib/imgui/imgui_widgets.cpp:6407
#1  0x00005555558887ce in l_pigui_begin_tab_bar (l=0x555555de8d70) at /usr/include/c++/10.1.0/bits/basic_string.h:2299
#2  0x00005555558c3756 in luaD_precall (L=L@entry=0x555555de8d70, func=<optimized out>, func@entry=0x5555566b4130, nresults=nresults@entry=1)
    at /home/me/usr/src/pioneer/contrib/lua/src/ldo.c:318
#3  0x00005555558d255d in luaV_execute (L=L@entry=0x555555de8d70) at /home/me/usr/src/pioneer/contrib/lua/src/lvm.c:709
#4  0x00005555558c3b28 in luaD_call (L=0x555555de8d70, func=<optimized out>, nResults=<optimized out>, allowyield=<optimized out>)
    at /home/me/usr/src/pioneer/contrib/lua/src/ldo.c:395
#5  0x00005555558c307c in luaD_rawrunprotected (L=L@entry=0x555555de8d70, f=f@entry=0x5555558ba0b0 <f_call>, ud=ud@entry=0x7fffffffcfe0)
    at /home/me/usr/src/pioneer/contrib/lua/src/ldo.c:131
#6  0x00005555558c3d5f in luaD_pcall (L=L@entry=0x555555de8d70, func=func@entry=0x5555558ba0b0 <f_call>, u=u@entry=0x7fffffffcfe0, old_top=112, ef=<optimized out>)
    at /home/me/usr/src/pioneer/contrib/lua/src/ldo.c:595
#7  0x00005555558bc937 in lua_pcallk (L=L@entry=0x555555de8d70, nargs=nargs@entry=0, nresults=nresults@entry=1, errfunc=errfunc@entry=6, ctx=ctx@entry=0, k=k@entry=0x0)
    at /home/me/usr/src/pioneer/contrib/lua/src/lapi.c:949
#8  0x00005555558b98b5 in pi_lua_dofile (l=l@entry=0x555555de8d70, code=..., nret=nret@entry=1) at /home/me/usr/src/pioneer/src/lua/core/Sandbox.cpp:209
#9  0x00005555558b5f82 in load_file_cached (L=0x555555de8d70, path="/pigui/modules/info-view/06-flightlog.lua", cacheIdx=5) at /home/me/usr/src/pioneer/src/SmartPtr.h:27
#10 0x00005555558b63c8 in lua_import_module (L=0x555555de8d70, moduleName="pigui.modules.info-view.06-flightlog") at /home/me/usr/src/pioneer/src/lua/core/Import.cpp:319
#11 0x00005555558b7c12 in pi_lua_import (popImported=true, importName="pigui.modules.info-view.06-flightlog", L=0x555555de8d70)
    at /home/me/usr/src/pioneer/src/lua/core/Import.cpp:407
#12 pi_lua_import_recursive (L=L@entry=0x555555de8d70, moduleName="pigui.modules") at /home/me/usr/src/pioneer/src/lua/core/Import.cpp:407
#13 0x0000555555866c7a in Lua::InitModules () at /usr/include/c++/10.1.0/bits/char_traits.h:322
#14 0x000055555561548a in std::function<void ()>::operator()() const (this=0x555555bcaa60) at /usr/include/c++/10.1.0/bits/std_function.h:617
#15 LoadStep::Update (this=<optimized out>, deltaTime=<optimized out>) at /home/me/usr/src/pioneer/src/Pi.cpp:614
#16 0x000055555596fc2f in Application::Run (this=0x555555b8fab0) at /usr/include/c++/10.1.0/bits/shared_ptr_base.h:1324
#17 0x00005555555dfc70 in main (argc=<optimized out>, argv=<optimized out>) at /home/me/usr/src/pioneer/src/Pi.h:143

So I assume I've done something bad when I added the tab bar in #4893

@Gliese852
Copy link
Contributor

@impaktor for some reason, the function BeginTabBar is triggered during module loading

@The-EG
Copy link
Contributor

The-EG commented Jul 13, 2020

At the end of 06-flightlog.lua, line 227, change draw = drawLog() to draw = drawLog.

You want to assign the reference to the function to draw not it's return value (which causes it to run).

impaktor added 3 commits July 13, 2020 17:04
Will show the automatically logged events (station, and system visits), as
well as allow custom text entries to these, and custom logs to be made at
arbitrary points.
This feels more intuitive, to log arrival event, rather than undocking event.

Typically, arrival data is important for checking if one made a mission dead line.
@impaktor
Copy link
Member Author

@Gliese852 & @The-EG doh! yeah, thanks! Merging it now.

@impaktor impaktor merged commit 1827942 into pioneerspacesim:master Jul 13, 2020
@impaktor impaktor deleted the captains_log branch July 13, 2020 15:15
@WKFO
Copy link
Contributor

WKFO commented Jul 14, 2020

I tried this again recently and when I try to make an entry while in hyperspace, it does this:
errorrr
I think this was fixed, though. Can anyone else give it a try?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Thoughts On A Ships Log
6 participants