| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504 |
- /*
- ** Command & Conquer Renegade(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- // EditLODDialog.cpp : implementation file
- //
- #include "stdafx.h"
- #include "W3DView.h"
- #include "EditLODDialog.h"
- #include "DistLod.H"
- #include "Utils.H"
- #include "RendObj.H"
- #include "W3DViewDoc.H"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////
- //
- // Local Constants
- //
- const int COL_NAME = 0;
- const int COL_SWITCH_UP = 1;
- const int COL_SWITCH_DN = 2;
- /////////////////////////////////////////////////////////////
- //
- // CEditLODDialog
- //
- CEditLODDialog::CEditLODDialog(CWnd* pParent /*=NULL*/)
- : m_spinIncrement (0.5F),
- CDialog(CEditLODDialog::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CEditLODDialog)
- //}}AFX_DATA_INIT
- return ;
- }
- /////////////////////////////////////////////////////////////
- //
- // DoDataExchange
- //
- void
- CEditLODDialog::DoDataExchange (CDataExchange* pDX)
- {
- // Allow the base class to process this message
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CEditLODDialog)
- DDX_Control(pDX, IDC_SWITCH_UP_SPIN, m_switchUpSpin);
- DDX_Control(pDX, IDC_SWITCH_DN_SPIN, m_switchDownSpin);
- DDX_Control(pDX, IDC_HIERARCHY_LIST, m_hierarchyListCtrl);
- //}}AFX_DATA_MAP
- return ;
- }
- BEGIN_MESSAGE_MAP(CEditLODDialog, CDialog)
- //{{AFX_MSG_MAP(CEditLODDialog)
- ON_NOTIFY(UDN_DELTAPOS, IDC_SWITCH_UP_SPIN, OnDeltaposSwitchUpSpin)
- ON_NOTIFY(UDN_DELTAPOS, IDC_SWITCH_DN_SPIN, OnDeltaposSwitchDnSpin)
- ON_NOTIFY(LVN_ITEMCHANGED, IDC_HIERARCHY_LIST, OnItemChangedHierarchyList)
- ON_EN_UPDATE(IDC_SWITCH_DN_EDIT, OnUpdateSwitchDnEdit)
- ON_EN_UPDATE(IDC_SWITCH_UP_EDIT, OnUpdateSwitchUpEdit)
- ON_BN_CLICKED(IDC_RECALC, OnRecalc)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////
- //
- // OnInitDialog
- //
- BOOL
- CEditLODDialog::OnInitDialog (void)
- {
- // Allow the base class to process this message
- CDialog::OnInitDialog ();
- // Center the dialog around the data tree view instead
- // of the direct center of the screen
- ::CenterDialogAroundTreeView (m_hWnd);
- // Get a pointer to the doc
- CW3DViewDoc *pCDoc = ::GetCurrentDocument ();
- if (pCDoc)
- {
- // Get the current LOD from the doc
- DistLODClass *pLOD = (DistLODClass *)pCDoc->GetDisplayedObject ();
- ASSERT (pLOD);
- if (pLOD)
- {
- int iSubObjects = pLOD->Get_Num_Sub_Objects ();
- // Add the columns to the list control
- m_hierarchyListCtrl.InsertColumn (COL_NAME, "Name");
- m_hierarchyListCtrl.InsertColumn (COL_SWITCH_UP, "Switch Up");
- m_hierarchyListCtrl.InsertColumn (COL_SWITCH_DN, "Switch Down");
- RenderObjClass *pfirst_subobj = pLOD->Get_Sub_Object (0);
- if (pfirst_subobj != NULL) {
- m_spinIncrement = pfirst_subobj->Get_Bounding_Sphere ().Radius / 5.0F;
- MEMBER_RELEASE (pfirst_subobj);
- }
-
- // Loop through all the subobjects
- for (int iObject = 0;
- (iObject < iSubObjects);
- iObject ++)
- {
- // Get this subobject
- RenderObjClass *pCSubObject = pLOD->Get_Sub_Object (iObject);
- if (pCSubObject)
- {
- // Add this object to the list
- int iIndex = m_hierarchyListCtrl.InsertItem (COL_NAME, pCSubObject->Get_Name ());
- CString stringTemp;
- stringTemp.Format ("%.2f", pLOD->Get_Switch_Up_Dist (iObject));
- m_hierarchyListCtrl.SetItemText (iIndex, COL_SWITCH_UP, stringTemp);
- stringTemp.Format ("%.2f", pLOD->Get_Switch_Down_Dist (iObject));
- m_hierarchyListCtrl.SetItemText (iIndex, COL_SWITCH_DN, stringTemp);
- // Free this object
- MEMBER_RELEASE (pCSubObject);
- }
- }
- m_switchUpSpin.SetRange (-20, UD_MAXVAL-20);
- m_switchDownSpin.SetRange (-20, UD_MAXVAL-20);
-
- // Resize the columns so they are wide enough to display the largest string
- m_hierarchyListCtrl.SetColumnWidth (COL_NAME, LVSCW_AUTOSIZE);
- m_hierarchyListCtrl.SetColumnWidth (COL_SWITCH_UP, LVSCW_AUTOSIZE_USEHEADER);
- m_hierarchyListCtrl.SetColumnWidth (COL_SWITCH_DN, LVSCW_AUTOSIZE_USEHEADER);
- // Select the first item in the list
- m_hierarchyListCtrl.SetItemState (0, LVIS_SELECTED, LVIS_SELECTED);
- }
- }
-
- return TRUE;
- }
- /////////////////////////////////////////////////////////////
- //
- // OnOK
- //
- void
- CEditLODDialog::OnOK (void)
- {
- // Get a pointer to the doc
- CW3DViewDoc *pCDoc = ::GetCurrentDocument ();
- if (pCDoc)
- {
- // Get the current LOD from the doc
- DistLODClass *pLOD = (DistLODClass *)pCDoc->GetDisplayedObject ();
- ASSERT (pLOD);
- if (pLOD)
- {
- int iSubObjects = pLOD->Get_Num_Sub_Objects ();
- // Loop through all the subobjects and add them to the list control
- for (int iObject = 0;
- (iObject < iSubObjects);
- iObject ++)
- {
- // Get the switch up distance from the list control
- CString stringTemp = m_hierarchyListCtrl.GetItemText (iObject, COL_SWITCH_UP);
-
- // Convert the string to a float and pass this value
- // onto the LOD manager
- float switchDistance = ::atof (stringTemp);
- pLOD->Set_Switch_Up_Dist (iObject, switchDistance);
- // Get the switch down distance from the list control
- stringTemp = m_hierarchyListCtrl.GetItemText (iObject, COL_SWITCH_DN);
-
- // Convert the string to a float and pass this value
- // onto the LOD manager
- switchDistance = ::atof (stringTemp);
- pLOD->Set_Switch_Down_Dist (iObject, switchDistance);
- }
- }
- }
- // Allow the base class to process this message
- CDialog::OnOK ();
- return ;
- }
- /////////////////////////////////////////////////////////////
- //
- // OnCancel
- //
- void
- CEditLODDialog::OnCancel (void)
- {
- // Allow the base class to process this message
- CDialog::OnCancel ();
- return ;
- }
- /////////////////////////////////////////////////////////////
- //
- // OnDeltaposSwitchUpSpin
- //
- void
- CEditLODDialog::OnDeltaposSwitchUpSpin
- (
- NMHDR* pNMHDR,
- LRESULT* pResult
- )
- {
- NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
- if (pNMUpDown)
- {
- float newVal = float(pNMUpDown->iPos) / 10.00F;
- // Change the switching distance in the edit control
- CString stringTemp;
- stringTemp.Format ("%.2f", newVal);
- SetDlgItemText (IDC_SWITCH_UP_EDIT, stringTemp);
- // Find the selected item in the list control
- int iIndex = m_hierarchyListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
- if (iIndex != -1)
- {
- // Change the switching distance in the list control
- m_hierarchyListCtrl.SetItemText (iIndex, COL_SWITCH_UP, stringTemp);
- }
- }
-
- *pResult = 0;
- return ;
- }
- /////////////////////////////////////////////////////////////
- //
- // OnDeltaposSwitchDnSpin
- //
- void
- CEditLODDialog::OnDeltaposSwitchDnSpin
- (
- NMHDR* pNMHDR,
- LRESULT* pResult
- )
- {
- NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
- if (pNMUpDown)
- {
- float newVal = float(pNMUpDown->iPos) / 10.00F;
- // Change the switching distance in the edit control
- CString stringTemp;
- stringTemp.Format ("%.2f", newVal);
- SetDlgItemText (IDC_SWITCH_DN_EDIT, stringTemp);
- // Find the selected item in the list control
- int iIndex = m_hierarchyListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
- if (iIndex != -1)
- {
- // Change the switching distance in the list control
- m_hierarchyListCtrl.SetItemText (iIndex, COL_SWITCH_DN, stringTemp);
- }
- }
-
- *pResult = 0;
- return ;
- }
- /////////////////////////////////////////////////////////////
- //
- // OnItemChangedHierarchyList
- //
- void
- CEditLODDialog::OnItemChangedHierarchyList
- (
- NMHDR* pNMHDR,
- LRESULT* pResult
- )
- {
- // Did the 'state' of the entry change?
- NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
- if (pNMListView &&
- (pNMListView->uChanged & LVIF_STATE) == LVIF_STATE)
- {
-
- if ((pNMListView->uNewState & LVIS_SELECTED) != LVIS_SELECTED)
- {
- // Is there a selected item in the list control?
- if (m_hierarchyListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED) == -1)
- {
- // Disabled the edit and spin controls
- EnableControls (FALSE);
- }
- }
- else
- {
- // Enable the edit and spin controls
- EnableControls (TRUE);
- // Load the control with data for the selected item.
- ResetControls (pNMListView->iItem);
- }
- }
-
- *pResult = 0;
- return ;
- }
- /////////////////////////////////////////////////////////////
- //
- // ResetControls
- //
- void
- CEditLODDialog::ResetControls (int iIndex)
- {
- //
- // Set the text of the group box
- //
- CString stringTemp = m_hierarchyListCtrl.GetItemText (iIndex, COL_NAME);
- // Set the text of the group box
- CString stringTitle;
- stringTitle.Format ("Settings (%s)", (LPCTSTR)stringTemp);
- SetDlgItemText (IDC_SETTINGS_GROUP, stringTitle);
- //
- // Reset the switch up controls
- //
- // Get the switch up distance from the list control
- stringTemp = m_hierarchyListCtrl.GetItemText (iIndex, COL_SWITCH_UP);
- // Set the text of the edit control to reflect the switching distance
- SetDlgItemText (IDC_SWITCH_UP_EDIT, stringTemp);
-
- // Set the current position of the spin control
- float switchDistance = ::atof (stringTemp);
- m_switchUpSpin.SetPos (int(switchDistance * 10.00F));
- //
- // Reset the switch down controls
- //
- // Get the switch down distance from the list control
- stringTemp = m_hierarchyListCtrl.GetItemText (iIndex, COL_SWITCH_DN);
- // Set the text of the edit control to reflect the switching distance
- SetDlgItemText (IDC_SWITCH_DN_EDIT, stringTemp);
- // Set the current position of the spin control
- switchDistance = ::atof (stringTemp);
- m_switchDownSpin.SetPos (int(switchDistance * 10.00F));
- return ;
- }
- /////////////////////////////////////////////////////////////
- //
- // EnableControls
- //
- void
- CEditLODDialog::EnableControls (BOOL bEnable)
- {
- // Enable or disable the windows
- ::EnableWindow (::GetDlgItem (m_hWnd, IDC_SETTINGS_GROUP), bEnable);
- ::EnableWindow (::GetDlgItem (m_hWnd, IDC_SWITCH_UP_SPIN), bEnable);
- ::EnableWindow (::GetDlgItem (m_hWnd, IDC_SWITCH_UP_EDIT), bEnable);
- ::EnableWindow (::GetDlgItem (m_hWnd, IDC_SWITCH_DN_SPIN), bEnable);
- ::EnableWindow (::GetDlgItem (m_hWnd, IDC_SWITCH_DN_EDIT), bEnable);
- ::EnableWindow (::GetDlgItem (m_hWnd, IDC_RECALC), bEnable);
- return ;
- }
- /////////////////////////////////////////////////////////////
- //
- // OnUpdateSwitchDnEdit
- //
- void
- CEditLODDialog::OnUpdateSwitchDnEdit (void)
- {
- // Get the switching distance from the edit control
- CString stringTemp;
- GetDlgItemText (IDC_SWITCH_DN_EDIT, stringTemp);
- float newVal = ::atof (stringTemp);
- // Change the switching distance in the spin control
- m_switchDownSpin.SetPos (int(newVal * 10.00F));
- // Find the selected item in the list control
- int iIndex = m_hierarchyListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
- if (iIndex != -1)
- {
- // Change the switching distance in the list control
- m_hierarchyListCtrl.SetItemText (iIndex, COL_SWITCH_DN, stringTemp);
- }
- return ;
- }
- /////////////////////////////////////////////////////////////
- //
- // OnUpdateSwitchUpEdit
- //
- void CEditLODDialog::OnUpdateSwitchUpEdit (void)
- {
- // Get the switching distance from the edit control
- CString stringTemp;
- GetDlgItemText (IDC_SWITCH_UP_EDIT, stringTemp);
- float newVal = ::atof (stringTemp);
- // Change the switching distance in the spin control
- m_switchUpSpin.SetPos (int(newVal * 10.00F));
- // Find the selected item in the list control
- int iIndex = m_hierarchyListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
- if (iIndex != -1)
- {
- // Change the switching distance in the list control
- m_hierarchyListCtrl.SetItemText (iIndex, COL_SWITCH_UP, stringTemp);
- }
- return ;
- }
- /////////////////////////////////////////////////////////////
- //
- // OnRecalc
- //
- void CEditLODDialog::OnRecalc (void)
- {
- // Get the up switching distance from the edit control
- CString stringTemp;
- GetDlgItemText (IDC_SWITCH_UP_EDIT, stringTemp);
- float switchUp = ::atof (stringTemp);
- // Get the down switching distance from the edit control
- stringTemp;
- GetDlgItemText (IDC_SWITCH_DN_EDIT, stringTemp);
- float switchDown = ::atof (stringTemp);
- if (switchUp < switchDown)
- {
- // Calculate the current range
- float switchDelta = switchDown - switchUp;
- float switchOverlap = switchDelta * 0.1F;
- // Get a pointer to the doc
- CW3DViewDoc *pCDoc = ::GetCurrentDocument ();
- if (pCDoc)
- {
- // Get the current LOD from the doc
- DistLODClass *pLOD = (DistLODClass *)pCDoc->GetDisplayedObject ();
- ASSERT (pLOD);
- if (pLOD)
- {
- int iSubObjects = pLOD->Get_Num_Sub_Objects ();
- switchUp = switchDown - switchOverlap;
- // Loop through all the subobjects (following the highlighted one)
- for (int iObject = m_hierarchyListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED) + 1;
- (iObject < iSubObjects);
- iObject ++)
- {
- // Set the text of the switch up column
- CString stringTemp;
- stringTemp.Format ("%.2f", switchUp);
- m_hierarchyListCtrl.SetItemText (iObject, COL_SWITCH_UP, stringTemp);
- // Set the text of the switch dn column
- stringTemp.Format ("%.2f", switchUp+switchDelta);
- m_hierarchyListCtrl.SetItemText (iObject, COL_SWITCH_DN, stringTemp);
- // Add the range to the switch up distance
- switchUp += switchDelta-switchOverlap;
- }
- }
- }
- }
- return ;
- }
|