Files
fs2open.github.com/code/lab/dialogs/lab_ui_helpers.cpp
T
Fabian WoltermannandFabian Woltermann 87926995df Feature/dear imgui (#4987)
* Add imgui

* migrate render options

* remove wmcgui

* Add subsystem selection and highlighting

* Add a syntactic sugar extension for imgui

* don't rebuild the mission list every frame

* Add imgui_sugar extension

* Move helper functions out of lab_ui, add function to display consolidated table text for object

* add button to export cubemap

* fix entering and exiting the lab

* refactor some of this for greater cleanness

* use techroom lighting when no mission background is set

* minor things

* add imguizmo

* add imguizmo

* Add imgui

* migrate render options

* remove wmcgui

* Add subsystem selection and highlighting

* Add a syntactic sugar extension for imgui

* don't rebuild the mission list every frame

* Move helper functions out of lab_ui, add function to display consolidated table text for object

* add button to export cubemap

* fix entering and exiting the lab

* refactor some of this for greater cleanness

* minor things

* add imguizmo

* add imguizmo

* Add button to reset changes made in the render dialog

* refactoring

* unfuck rebase

* fix issue with loose mission files

* use with_CollapsingHeader for greater uniformity

* add weapon selection functionality

* make primaries and secondaries fire again

* implement animation triggers

* avoid crash when switching back and forth between ships with and without team colors

* add control to set team color setting to renderer texture dialog

* make sure the table text updates when the ship class changes

* let rotating subsystems rotate

* do not add imgui.h to pstypes

* code cleanup

* add subsys highlighter from fred

* Highlight non-modelled subsystems as well

* add cmdline flag to show the imgui demo dialogue

* fix compiler warnings reported by CI

* fix error when building the subsystem list

* refactor variable/method naming

* code cleanup

* remove vestigial code

* update to imgui 1.89.1

* add credits entry for imgui

* use the imgui namespace

* Separate the background dialog out into its own window

* make sure the subsystem highlights are placed correctly

Co-authored-by: Fabian Woltermann <[email protected]>
2022-12-18 16:29:20 +01:00

201 lines
4.4 KiB
C++

#include "lab_ui_helpers.h"
#include "cfile/cfile.h"
#include "lab/labv2_internal.h"
SCP_string get_ship_table_text(ship_info* sip)
{
char line[256], line2[256], file_text[82];
int i, j, n, found = 0, comment = 0, num_files = 0;
SCP_vector<SCP_string> tbl_file_names;
SCP_string result;
auto fp = cfopen("ships.tbl", "r");
Assert(fp);
while (cfgets(line, 255, fp)) {
while (line[strlen(line) - 1] == '\n')
line[strlen(line) - 1] = 0;
for (i = j = 0; line[i]; i++) {
if (line[i] == '/' && line[i + 1] == '/')
break;
if (line[i] == '/' && line[i + 1] == '*') {
comment = 1;
i++;
continue;
}
if (line[i] == '*' && line[i + 1] == '/') {
comment = 0;
i++;
continue;
}
if (!comment)
line2[j++] = line[i];
}
line2[j] = 0;
if (!strnicmp(line2, "$Name:", 6)) {
drop_trailing_white_space(line2);
found = 0;
i = 6;
while (line2[i] == ' ' || line2[i] == '\t' || line2[i] == '@')
i++;
if (!stricmp(line2 + i, sip->name)) {
result += "-- ships.tbl -------------------------------\r\n";
found = 1;
}
}
if (found) {
result += line;
result += "\r\n";
}
}
cfclose(fp);
// done with ships.tbl, so now check all modular ship tables...
num_files = cf_get_file_list(tbl_file_names, CF_TYPE_TABLES, NOX("*-shp.tbm"), CF_SORT_REVERSE);
for (n = 0; n < num_files; n++) {
tbl_file_names[n] += ".tbm";
fp = cfopen(tbl_file_names[n].c_str(), "r");
Assert(fp);
memset(line, 0, sizeof(line));
memset(line2, 0, sizeof(line2));
found = 0;
comment = 0;
while (cfgets(line, 255, fp)) {
while (line[strlen(line) - 1] == '\n')
line[strlen(line) - 1] = 0;
for (i = j = 0; line[i]; i++) {
if (line[i] == '/' && line[i + 1] == '/')
break;
if (line[i] == '/' && line[i + 1] == '*') {
comment = 1;
i++;
continue;
}
if (line[i] == '*' && line[i + 1] == '/') {
comment = 0;
i++;
continue;
}
if (!comment)
line2[j++] = line[i];
}
line2[j] = 0;
if (!strnicmp(line2, "$Name:", 6)) {
drop_trailing_white_space(line2);
found = 0;
i = 6;
while (line2[i] == ' ' || line2[i] == '\t' || line2[i] == '@')
i++;
if (!stricmp(line2 + i, sip->name)) {
memset(file_text, 0, sizeof(file_text));
snprintf(file_text,
sizeof(file_text) - 1,
"-- %s -------------------------------\r\n",
tbl_file_names[n].c_str());
result += file_text;
found = 1;
}
}
if (found) {
result += line;
result += "\r\n";
}
}
cfclose(fp);
}
return result;
}
SCP_string get_directory_or_vp(const char* path)
{
SCP_string result(path);
// Is this a mission in a directory?
size_t found = result.find("data" DIR_SEPARATOR_STR "missions");
if (found == std::string::npos) // Guess not
{
found = result.find(".vp");
}
const auto directory_name_pos = result.rfind(DIR_SEPARATOR_CHAR, found - strlen(DIR_SEPARATOR_STR) - 1);
result = result.substr(directory_name_pos, found - directory_name_pos);
found = result.find(DIR_SEPARATOR_CHAR);
// Strip directory separators
while (found != std::string::npos) {
result.erase(found, strlen(DIR_SEPARATOR_STR));
found = result.find(DIR_SEPARATOR_CHAR);
}
return result;
}
bool graphics_options_changed()
{
auto stored_settings = getLabManager()->graphicsSettings;
if (stored_settings.ambient_factor != lighting_profile::lab_get_ambient())
return true;
if (stored_settings.light_factor != lighting_profile::lab_get_light())
return true;
if (stored_settings.emissive_factor != lighting_profile::lab_get_emissive())
return true;
if (stored_settings.exposure_level != lighting_profile::current_exposure())
return true;
if (stored_settings.tonemapper != lighting_profile::current_tonemapper())
return true;
if (stored_settings.bloom_level != gr_bloom_intensity())
return true;
if (stored_settings.aa_mode != Gr_aa_mode)
return true;
if (stored_settings.ppcv.shoulder_angle != lighting_profile::lab_get_ppc().shoulder_angle)
return true;
if (stored_settings.ppcv.shoulder_length != lighting_profile::lab_get_ppc().shoulder_length)
return true;
if (stored_settings.ppcv.shoulder_strength != lighting_profile::lab_get_ppc().shoulder_strength)
return true;
if (stored_settings.ppcv.toe_length != lighting_profile::lab_get_ppc().toe_length)
return true;
if (stored_settings.ppcv.toe_strength != lighting_profile::lab_get_ppc().toe_strength)
return true;
return false;
}