Skip to content

Lab Weapon Viewer #6704

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions code/graphics/shadows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ void shadows_render_all(fov_t fov, matrix *eye_orient, vec3d *eye_pos)

switch(objp->type)
{
case OBJ_RAW_POF:
case OBJ_SHIP:
{
obj_queue_render(objp, &scene);
Expand Down
82 changes: 57 additions & 25 deletions code/lab/dialogs/lab_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ void LabUi::build_weapon_list() const
{
//weapon display needs to be rethought

//with_TreeNode("Weapon Classes")
//{
// build_weapon_subtype_list();
//}
with_TreeNode("Weapon Classes")
{
build_weapon_subtype_list();
}
}

void LabUi::build_background_list() const
Expand Down Expand Up @@ -342,13 +342,17 @@ void LabUi::show_render_options()

with_CollapsingHeader("Model features")
{
Checkbox("Rotate/Translate Subsystems", &animate_subsystems);
if (getLabManager()->CurrentMode == LabMode::Ship) {
Checkbox("Rotate/Translate Subsystems", &animate_subsystems);
}
Checkbox("Show full detail", &show_full_detail);
Checkbox("Show thrusters", &show_thrusters);
Checkbox("Show afterburners", &show_afterburners);
Checkbox("Show weapons", &show_weapons);
Checkbox("Show Insignia", &show_insignia);
Checkbox("Show damage lightning", &show_damage_lightning);
if (getLabManager()->CurrentMode == LabMode::Ship) {
Checkbox("Show afterburners", &show_afterburners);
Checkbox("Show weapons", &show_weapons);
Checkbox("Show Insignia", &show_insignia);
Checkbox("Show damage lightning", &show_damage_lightning);
}
Checkbox("No glowpoints", &no_glowpoints);
}

Expand All @@ -372,6 +376,7 @@ void LabUi::show_render_options()
with_CollapsingHeader("Scene rendering options")
{
Checkbox("Hide Post Processing", &hide_post_processing);
Checkbox("Hide particles", &no_particles);
Checkbox("Render as wireframe", &use_wireframe_rendering);
Checkbox("Render without light", &no_lighting);
Checkbox("Render with emissive lighting", &show_emissive_lighting);
Expand Down Expand Up @@ -487,6 +492,7 @@ void LabUi::show_render_options()
getLabManager()->Renderer->setRenderFlag(LabRenderFlag::ShowWeapons, show_weapons);
getLabManager()->Renderer->setRenderFlag(LabRenderFlag::ShowEmissiveLighting, show_emissive_lighting);
getLabManager()->Renderer->setRenderFlag(LabRenderFlag::MoveSubsystems, animate_subsystems);
getLabManager()->Renderer->setRenderFlag(LabRenderFlag::NoParticles, no_particles);
getLabManager()->Renderer->setEmissiveFactor(emissive_factor);
getLabManager()->Renderer->setAmbientFactor(ambient_factor);
getLabManager()->Renderer->setLightFactor(light_factor);
Expand Down Expand Up @@ -523,7 +529,7 @@ void LabUi::do_triggered_anim(animation::ModelAnimationTriggerType type,
TextUnformatted(colB); \


void LabUi::build_table_info_txtbox(ship_info* sip) const
static void build_ship_table_info_txtbox(ship_info* sip)
{
with_TreeNode("Table information")
{
Expand All @@ -543,6 +549,26 @@ void LabUi::build_table_info_txtbox(ship_info* sip) const
}
}

static void build_weapon_table_info_txtbox(weapon_info* wip)
{
with_TreeNode("Table information")
{
// Cache result across frames for performance
static SCP_string table_text;
static int old_class = getLabManager()->CurrentClass;

if (table_text.length() == 0 || old_class != getLabManager()->CurrentClass) {
table_text = get_weapon_table_text(wip);
}

InputTextMultiline("##weapon_table_text",
const_cast<char*>(table_text.c_str()),
table_text.length(),
ImVec2(-FLT_MIN, GetTextLineHeight() * 16),
ImGuiInputTextFlags_ReadOnly);
}
}

void LabUi::build_model_info_box_actual(ship_info* sip, polymodel* pm) const
{
ImGuiTableFlags flags = ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg;
Expand Down Expand Up @@ -751,15 +777,9 @@ void LabUi::build_weapon_options(ship* shipp) const {

build_primary_weapon_combobox(text, wip, primary_slot);
SameLine();
static bool should_fire[MAX_SHIP_PRIMARY_BANKS] = {false, false, false};
SCP_string cb_text;
sprintf(cb_text, "Fire bank %i", bank);
Checkbox(cb_text.c_str(), &should_fire[bank]);
if (should_fire[bank]) {
getLabManager()->FirePrimaries |= 1 << bank;
} else {
getLabManager()->FirePrimaries &= ~(1 << bank);
}
Checkbox(cb_text.c_str(), &getLabManager()->FirePrimaries[bank]);

bank++;
}
Expand All @@ -777,15 +797,9 @@ void LabUi::build_weapon_options(ship* shipp) const {
sprintf(text, "##Secondary bank %i", bank);
build_secondary_weapon_combobox(text, wip, secondary_slot);
SameLine();
static bool should_fire[MAX_SHIP_SECONDARY_BANKS] = {false, false, false, false};
SCP_string cb_text;
sprintf(cb_text, "Fire bank %i##secondary", bank);
Checkbox(cb_text.c_str(), &should_fire[bank]);
if (should_fire[bank]) {
getLabManager()->FireSecondaries |= 1 << bank;
} else {
getLabManager()->FireSecondaries &= ~(1 << bank);
}
Checkbox(cb_text.c_str(), &getLabManager()->FireSecondaries[bank]);

bank++;
}
Expand Down Expand Up @@ -1127,7 +1141,7 @@ void LabUi::show_object_options() const

with_CollapsingHeader(sip->name)
{
build_table_info_txtbox(sip);
build_ship_table_info_txtbox(sip);

build_model_info_box(sip, pm);

Expand All @@ -1154,6 +1168,24 @@ void LabUi::show_object_options() const
{
build_weapon_options(shipp);
}
} else if (getLabManager()->CurrentMode == LabMode::Weapon && getLabManager()->isSafeForWeapons()) {
auto wip = &Weapon_info[getLabManager()->CurrentClass];

with_CollapsingHeader("Weapon Info")
{
build_weapon_table_info_txtbox(wip);
}

with_CollapsingHeader("Object Actions")
{
Checkbox("Allow weapon to reach end of life", &getLabManager()->AllowWeaponDestruction);

if (VALID_FNAME(wip->tech_model)) {
if (Checkbox("Show Tech Model", &getLabManager()->ShowingTechModel)) {
getLabManager()->changeDisplayedObject(LabMode::Weapon, getLabManager()->CurrentClass);
}
}
}
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions code/lab/dialogs/lab_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ enum class LabTurretAimType {

class LabUi {
public:
bool show_thrusters = false; // So that it can be toggled on/off based on the lab mode being changed

void create_ui();
void object_changed();
void closeUi();
Expand All @@ -31,7 +33,6 @@ class LabUi {
void build_texture_quality_combobox();
void build_antialiasing_combobox();
void build_tone_mapper_combobox();
void build_table_info_txtbox(ship_info* sip) const;
void build_model_info_box(ship_info* sip, polymodel* pm) const;
void build_subsystem_list(object* objp, ship* shipp) const;
void build_subsystem_list_entry(SCP_string& subsys_name,
Expand Down Expand Up @@ -85,6 +86,7 @@ class LabUi {
bool show_damage_lightning = false;
bool animate_subsystems = false;
bool hide_post_processing = false;
bool no_particles = false;
bool diffuse_map = true;
bool glow_map = true;
bool spec_map = true;
Expand All @@ -98,10 +100,10 @@ class LabUi {
bool use_wireframe_rendering = false;
bool no_lighting = false;
bool show_full_detail = false;
bool show_thrusters = false;
bool show_afterburners = false;
bool show_weapons = false;
bool show_emissive_lighting = false;
bool show_particles = true;

std::optional<vec3d> volumetrics_pos_backup = std::nullopt;
};
126 changes: 126 additions & 0 deletions code/lab/dialogs/lab_ui_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,132 @@ SCP_string get_ship_table_text(ship_info* sip)
return result;
}

SCP_string get_weapon_table_text(weapon_info* wip)
{
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("weapons.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, wip->name)) {
result += "-- weapons.tbl -------------------------------\r\n";
found = 1;
}
}

if (found) {
result += line;
result += "\r\n";
}
}

cfclose(fp);

num_files = cf_get_file_list(tbl_file_names, CF_TYPE_TABLES, NOX("*-wep.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, wip->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);
Expand Down
2 changes: 2 additions & 0 deletions code/lab/dialogs/lab_ui_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

SCP_string get_ship_table_text(ship_info* sip);

SCP_string get_weapon_table_text(weapon_info* wip);

SCP_string get_directory_or_vp(const char* path);

bool graphics_options_changed();
Loading
Loading