/**********************************************************************
This file is part of Crack dot Com's free source code release of Golgotha.
for information about compiling & licensing issues visit this URL
 If that doesn't help, contact Jonathan Clark at 
  golgotha_source@usa.net (Subject should have "GOLG" in it) 
***********************************************************************/

#include "m1_info.hh"
#include "lisp/li_types.hh"
#include "file/file.hh"
#include "make_tlist.hh"
#include "gui/text_scroll.hh"
#include "r1_api.hh"
#include "tmanage.hh"
#include "max_object.hh"
#include "tupdate.hh"
#include "st_edit.hh"
#include "render.hh"

m1_info_struct m1_info;
extern i4_text_scroll_window_class *m1_warn_window;

const i4_const_str m1_info_struct::current_filename()
{
  if (m1_info.models.size()==0)
    return i4_const_str("");
  else
    return *m1_info.models[m1_info.current_model];
}

void m1_info_struct::set_current_filename(const i4_const_str &str)
{
  if (m1_info.models.size()==0)
  {
    m1_info.models.add();
    m1_info.current_model=0;
  }
  else
    delete m1_info.models[m1_info.current_model];

  m1_info.models[m1_info.current_model]=new i4_str(str);
}


void m1_info_struct::get_texture_list(i4_array &array, i4_bool for_all)
{
  int i;

  if (for_all)
  {
    // add any textures from res files
    if (res_files.size())
    {
      i4_file_class *fp[500];

    
      for (i=0; i tmp_array(0,32);
      g1_get_load_info(fp, res_files.size(), array, tmp_array, tmp_int, i4_T);
      
      for (i=0; iget_tmanager();
  
  if (!obj)
    return;

  if (tman)
  {
    int i;
    tman->reset();
    textures_loaded=i4_F;

    i4_status_class *stat=i4_create_status("Updating textures");

    int nq=m1_info.obj->num_quad;
    for (i=0; itexture_names[i], i4_F, stat, 
                        i/(float)nq, (i+1)/(float)nq);

    if (stat) delete stat;
    

    for (i=0; inum_quad; i++)    
      m1_info.obj->quad[i].material_ref=tman->register_texture(*m1_info.obj->texture_names[i],
                                                               m1_info.current_filename());

    m1_st_edit->edit_poly_changed();
    m1_render_window->request_redraw(i4_F);
  }
}