mirror of
https://github.com/nillerusr/source-engine.git
synced 2026-08-18 22:41:58 +00:00
upload "kind" alien swarm
This commit is contained in:
@@ -0,0 +1,283 @@
|
||||
#include "kv_editor.h"
|
||||
#include "location_editor_frame.h"
|
||||
#include "kv_editor_base_panel.h"
|
||||
#include "kv_fit_children_panel.h"
|
||||
#include "ScrollingWindow.h"
|
||||
#include "filesystem.h"
|
||||
#include <vgui/ILocalize.h>
|
||||
#include "vgui/ISurface.h"
|
||||
#include <vgui_controls/FileOpenDialog.h>
|
||||
#include <vgui_controls/MessageBox.h>
|
||||
#include <vgui_controls/Button.h>
|
||||
#include <vgui_controls/TreeView.h>
|
||||
#include "location_layout_panel.h"
|
||||
#include "asw_mission_chooser.h"
|
||||
#include "asw_location_grid.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
extern char g_gamedir[1024];
|
||||
|
||||
namespace
|
||||
{
|
||||
bool GroupTreeSortFunc( KeyValues *pItem1, KeyValues *pItem2 )
|
||||
{
|
||||
return Q_stricmp( pItem1->GetString( "Text" ), pItem2->GetString( "Text" ) ) < 0;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CLocation_Editor_Frame::CLocation_Editor_Frame( Panel *parent, const char *name ) : BaseClass( parent, name )
|
||||
{
|
||||
//vgui::HScheme scheme = vgui::scheme()->LoadSchemeFromFile( "tilegen_scheme.res", NULL );
|
||||
//SetScheme( scheme );
|
||||
|
||||
m_pGroupPage = new CGroup_Edit_Page( this, "GroupPage" );
|
||||
m_pGroupPage->m_pEditor->AddActionSignalTarget( this );
|
||||
m_pGroupPage->AddActionSignalTarget( this );
|
||||
|
||||
m_pSaveButton = new vgui::Button( this, "SaveButton", "Save", this, "Save" );
|
||||
m_pScrollingWindow = new CScrollingWindow( this, "ScrollingWindow" );
|
||||
m_pLocationLayoutPanel = new CLocation_Layout_Panel( this, this, "LocationLayoutPanel" );
|
||||
|
||||
m_pScrollingWindow->SetChildPanel( m_pLocationLayoutPanel );
|
||||
|
||||
m_pTree = new vgui::TreeView( this, "Tree" );
|
||||
m_pTree->MakeReadyForUse();
|
||||
IScheme *pscheme = vgui::scheme()->GetIScheme( GetScheme() );
|
||||
HFont treeFont = pscheme->GetFont( "DefaultVerySmall" );
|
||||
m_pTree->SetFont( treeFont );
|
||||
m_pTree->SetSortFunc( GroupTreeSortFunc );
|
||||
m_iRootIndex = -1;
|
||||
m_iCurrentLocationID = -1;
|
||||
|
||||
UpdateTree();
|
||||
|
||||
LoadControlSettings( "tilegen/LocationEditor.res", "GAME" );
|
||||
|
||||
//SetSize( 384, 420 );
|
||||
SetMinimumSize( 384, 420 );
|
||||
|
||||
SetSizeable( true );
|
||||
SetMinimizeButtonVisible( false );
|
||||
SetMaximizeButtonVisible( false );
|
||||
SetMenuButtonVisible( false );
|
||||
m_bFirstPerformLayout = true;
|
||||
|
||||
SetTitle( "Location Grid Editor", true );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CLocation_Editor_Frame::~CLocation_Editor_Frame()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Kills the whole app on close
|
||||
//-----------------------------------------------------------------------------
|
||||
void CLocation_Editor_Frame::OnClose( void )
|
||||
{
|
||||
BaseClass::OnClose();
|
||||
}
|
||||
|
||||
void VGUIMessageBox( vgui::Panel *pParent, const char *pTitle, const char *pMsg, ... );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Parse commands coming in from the VGUI dialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void CLocation_Editor_Frame::OnCommand( const char *command )
|
||||
{
|
||||
BaseClass::OnCommand( command );
|
||||
|
||||
if ( !Q_strnicmp( command, "Location", 8 ) )
|
||||
{
|
||||
int iLocationID = atoi( command + 8 );
|
||||
SetLocationID( iLocationID );
|
||||
}
|
||||
else if ( !Q_stricmp( command, "Save" ) )
|
||||
{
|
||||
if ( !LocationGrid()->SaveLocationGrid() )
|
||||
{
|
||||
VGUIMessageBox( this, "Save Error", "Failed to save %s. Make sure file is checked out from Perforce.", "resource/mission_grid.txt" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CLocation_Editor_Frame::KeyValuesChanged( vgui::Panel *panel )
|
||||
{
|
||||
if ( panel == m_pGroupPage->m_pEditor )
|
||||
{
|
||||
CASW_Location_Group *pGroup = LocationGrid()->GetCGroup( m_pGroupPage->m_iCurrentGroupIndex );
|
||||
if ( pGroup )
|
||||
{
|
||||
pGroup->LoadFromKeyValues( m_pGroupPage->m_pEditor->GetKeys() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CLocation_Editor_Frame::NewGroup( vgui::Panel *panel )
|
||||
{
|
||||
LocationGrid()->CreateNewGroup();
|
||||
UpdateTree();
|
||||
}
|
||||
|
||||
void CLocation_Editor_Frame::DeleteGroup( vgui::Panel *panel )
|
||||
{
|
||||
LocationGrid()->DeleteGroup( m_pGroupPage->m_iCurrentGroupIndex );
|
||||
UpdateTree();
|
||||
}
|
||||
|
||||
void CLocation_Editor_Frame::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
if ( m_bFirstPerformLayout )
|
||||
{
|
||||
int screenWide, screenTall;
|
||||
surface()->GetScreenSize( screenWide, screenTall );
|
||||
|
||||
m_bFirstPerformLayout = false;
|
||||
//int inset_x = screenWide * 0.15f;
|
||||
//int inset_y = screenWide * 0.04f;
|
||||
//SetBounds( inset_x, inset_y, screenWide - inset_x * 3, screenTall - inset_y * 2 );
|
||||
}
|
||||
}
|
||||
|
||||
void CLocation_Editor_Frame::ApplySchemeSettings(vgui::IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
}
|
||||
|
||||
void CLocation_Editor_Frame::UpdateTree()
|
||||
{
|
||||
m_pTree->RemoveAll();
|
||||
|
||||
if ( !LocationGrid() )
|
||||
return;
|
||||
|
||||
KeyValues *kv = new KeyValues( "TVI" );
|
||||
kv->SetString( "Text", "Groups" );
|
||||
m_iRootIndex = m_pTree->AddItem( kv, -1 );
|
||||
|
||||
for ( int i = 0; i < LocationGrid()->GetNumGroups(); i++ )
|
||||
{
|
||||
CASW_Location_Group *pGroup = LocationGrid()->GetCGroup( i );
|
||||
if ( !pGroup )
|
||||
continue;
|
||||
KeyValues *pGroupEntry = new KeyValues("Group");
|
||||
pGroupEntry->SetString( "Text", pGroup->GetGroupName() );
|
||||
pGroupEntry->SetInt( "Index", i );
|
||||
pGroupEntry->SetString( "Type", "Group" );
|
||||
int iItem = m_pTree->AddItem( pGroupEntry, m_iRootIndex );
|
||||
m_pTree->SetItemFgColor( iItem, Color(255, 255, 255, 255) );
|
||||
}
|
||||
m_pTree->ExpandItem( m_iRootIndex, true );
|
||||
}
|
||||
|
||||
void CLocation_Editor_Frame::OnTreeViewItemSelected( int itemIndex )
|
||||
{
|
||||
KeyValues *pKV = m_pTree->GetItemData( itemIndex );
|
||||
if ( pKV && pKV->FindKey( "Text" ) )
|
||||
{
|
||||
//const char *pGroupName = pKV->GetString( "Text" );
|
||||
//CASW_Location_Group *pGroup = LocationGrid()->GetGroupByName( pGroupName );
|
||||
//if ( !pGroup )
|
||||
//return;
|
||||
|
||||
if ( m_pTree->GetItemParent( itemIndex ) == m_iRootIndex && Q_stricmp( pKV->GetString( "Text" ), "Ungrouped" ) )
|
||||
{
|
||||
int index = pKV->GetInt( "Index", -1 );
|
||||
m_pGroupPage->m_iCurrentGroupIndex = index;
|
||||
|
||||
SetGroup( LocationGrid()->GetCGroup( index ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
int id = pKV->GetInt( "LocationID", -1 );
|
||||
SetLocationID( id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CLocation_Editor_Frame::SetLocationID( int iLocationID )
|
||||
{
|
||||
if ( !LocationGrid() )
|
||||
return;
|
||||
|
||||
m_iCurrentLocationID = iLocationID;
|
||||
|
||||
// TODO: Find the group this location is in and show it, if we're not showing it already
|
||||
IASW_Location *pLoc = LocationGrid()->GetLocationByID( iLocationID );
|
||||
if ( !pLoc )
|
||||
return;
|
||||
|
||||
IASW_Location_Group *pSelectedGroup = pLoc->GetGroup();
|
||||
if ( !pSelectedGroup )
|
||||
return;
|
||||
|
||||
for ( int i = 0; i < LocationGrid()->GetNumGroups(); i++ )
|
||||
{
|
||||
if ( pSelectedGroup == LocationGrid()->GetCGroup( i ) )
|
||||
{
|
||||
m_pGroupPage->m_iCurrentGroupIndex = i;
|
||||
SetGroup( LocationGrid()->GetCGroup( i ) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CLocation_Editor_Frame::SetGroup( IASW_Location_Group *pGroup )
|
||||
{
|
||||
if ( !pGroup )
|
||||
return;
|
||||
|
||||
CASW_Location_Group *pCGroup = dynamic_cast<CASW_Location_Group*>( pGroup );
|
||||
if ( pCGroup )
|
||||
{
|
||||
m_pGroupPage->m_pEditor->SetKeys( pCGroup->GetKeyValuesForEditor() );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Shows kv editor for manipulating a specific group
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
CGroup_Edit_Page::CGroup_Edit_Page( Panel *parent, const char *name ) : BaseClass( parent, name )
|
||||
{
|
||||
m_pEditor = new CKV_Editor( this, "KVEditor" );
|
||||
m_pEditor->SetFileSpec( "tilegen/location_group_editor_spec.txt", "GAME" );
|
||||
m_pNewGroupButton = new vgui::Button( this, "NewGroupButton", "New Group", this, "NewGroup" );
|
||||
m_pDeleteGroupButton = new vgui::Button( this, "DeleteGroupButton", "Delete Group", this, "DeleteGroup" );
|
||||
m_iCurrentGroupIndex = -1;
|
||||
}
|
||||
|
||||
CGroup_Edit_Page::~CGroup_Edit_Page()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CGroup_Edit_Page::PerformLayout()
|
||||
{
|
||||
m_pEditor->SetBounds( 5, 45, GetWide() - 10, GetTall() - 55 );
|
||||
m_pNewGroupButton->SetBounds( GetWide() - 110, 16, 100, 22 );
|
||||
m_pDeleteGroupButton->SetBounds( GetWide() - 215, 16, 100, 22 );
|
||||
}
|
||||
|
||||
void CGroup_Edit_Page::OnCommand( const char *command )
|
||||
{
|
||||
BaseClass::OnCommand( command );
|
||||
}
|
||||
|
||||
void CGroup_Edit_Page::ApplySchemeSettings( vgui::IScheme *pScheme )
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
#ifndef _INCLUDED_LOCATION_EDITOR_FRAME_H
|
||||
#define _INCLUDED_LOCATION_EDITOR_FRAME_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <vgui_controls/Frame.h>
|
||||
#include <vgui_controls/ImageList.h>
|
||||
#include <vgui_controls/SectionedListPanel.h>
|
||||
#include <vgui_controls/PHandle.h>
|
||||
#include <FileSystem.h>
|
||||
#include "vgui/mousecode.h"
|
||||
#include "vgui/IScheme.h"
|
||||
#include "ConfigManager.h"
|
||||
#include "vstdlib/random.h"
|
||||
|
||||
class CScrollingWindow;
|
||||
class CKV_Editor_Base_Panel;
|
||||
class CKV_Fit_Children_Panel;
|
||||
class CKV_Editor;
|
||||
class CLocation_Layout_Panel;
|
||||
class IASW_Location_Group;
|
||||
namespace vgui
|
||||
{
|
||||
class PanelListPanel;
|
||||
class ImagePanel;
|
||||
class MenuBar;
|
||||
class CheckButton;
|
||||
class Button;
|
||||
class Menu;
|
||||
class TreeView;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Shows kv editor for manipulating a specific group
|
||||
//-----------------------------------------------------------------------------
|
||||
class CGroup_Edit_Page : public vgui::Panel
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CGroup_Edit_Page, vgui::Panel );
|
||||
|
||||
public:
|
||||
CGroup_Edit_Page( Panel *parent, const char *name );
|
||||
virtual ~CGroup_Edit_Page();
|
||||
|
||||
virtual void PerformLayout();
|
||||
virtual void ApplySchemeSettings(vgui::IScheme *pScheme);
|
||||
virtual void OnCommand( const char *command );
|
||||
|
||||
// panel for editing keyvalues
|
||||
CKV_Editor* m_pEditor;
|
||||
vgui::Button *m_pNewGroupButton;
|
||||
vgui::Button *m_pDeleteGroupButton;
|
||||
int m_iCurrentGroupIndex;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Main dialog for visualizing and editing location grid keyvalues
|
||||
//-----------------------------------------------------------------------------
|
||||
class CLocation_Editor_Frame : public vgui::Frame
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CLocation_Editor_Frame, vgui::Frame );
|
||||
|
||||
public:
|
||||
CLocation_Editor_Frame( Panel *parent, const char *name );
|
||||
virtual ~CLocation_Editor_Frame();
|
||||
|
||||
virtual void PerformLayout();
|
||||
virtual void ApplySchemeSettings(vgui::IScheme *pScheme);
|
||||
|
||||
int GetCurrentLocationID() { return m_iCurrentLocationID; }
|
||||
|
||||
void SetGroup( IASW_Location_Group *pGroup );
|
||||
|
||||
MESSAGE_FUNC_PTR( KeyValuesChanged, "KeyValuesChanged", panel );
|
||||
MESSAGE_FUNC_PTR( NewGroup, "NewGroup", panel );
|
||||
MESSAGE_FUNC_PTR( DeleteGroup, "DeleteGroup", panel );
|
||||
|
||||
protected:
|
||||
virtual void OnClose();
|
||||
virtual void OnCommand( const char *command );
|
||||
|
||||
void SetLocationID( int iLocationID );
|
||||
|
||||
bool m_bFirstPerformLayout;
|
||||
|
||||
CGroup_Edit_Page *m_pGroupPage;
|
||||
vgui::Button *m_pSaveButton;
|
||||
CScrollingWindow* m_pScrollingWindow;
|
||||
CLocation_Layout_Panel* m_pLocationLayoutPanel;
|
||||
|
||||
void UpdateTree();
|
||||
MESSAGE_FUNC_INT( OnTreeViewItemSelected, "TreeViewItemSelected", itemIndex );
|
||||
vgui::TreeView *m_pTree;
|
||||
int m_iCurrentLocationID;
|
||||
int m_iRootIndex;
|
||||
|
||||
CUniformRandomStream m_Random;
|
||||
};
|
||||
|
||||
|
||||
#endif // _INCLUDED_LOCATION_EDITOR_FRAME_H
|
||||
@@ -0,0 +1,318 @@
|
||||
#include "location_layout_panel.h"
|
||||
#include <vgui/ILocalize.h>
|
||||
#include "vgui/ISurface.h"
|
||||
#include "asw_mission_chooser.h"
|
||||
#include <vgui_controls/ImagePanel.h>
|
||||
#include <vgui_controls/Label.h>
|
||||
#include <vgui/IInput.h>
|
||||
#include "asw_location_grid.h"
|
||||
#include "location_editor_frame.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
#define YRES(y) ( y * ( ( float )1024.0f / 480.0 ) )
|
||||
#define UNDO_YRES(y) ( y / ( ( float )1024.0f / 480.0 ) )
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Shows hex locations
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
CLocation_Layout_Panel::CLocation_Layout_Panel( Panel *parent, Panel *pActionTarget, const char *name ) : BaseClass( parent, name )
|
||||
{
|
||||
m_pActionTarget = pActionTarget;
|
||||
m_pEditorFrame = dynamic_cast<CLocation_Editor_Frame*>( parent );
|
||||
|
||||
m_pBgImage = new vgui::ImagePanel( this, "LayoutBgImage" );
|
||||
m_pBgImage->SetShouldScaleImage( true );
|
||||
m_pBgImage->SetMouseInputEnabled( false );
|
||||
}
|
||||
|
||||
CLocation_Layout_Panel::~CLocation_Layout_Panel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CLocation_Layout_Panel::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
SetSize( YRES(853), YRES(480) );
|
||||
m_pBgImage->SetImage( "briefing/map.vmt" );
|
||||
m_pBgImage->SetSize( YRES(853), YRES(480) );
|
||||
}
|
||||
|
||||
void CLocation_Layout_Panel::ApplySchemeSettings(vgui::IScheme *scheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(scheme);
|
||||
|
||||
SetPaintBackgroundEnabled( true );
|
||||
SetPaintBackgroundType( 0 );
|
||||
SetBgColor( Color( 0, 0, 0, 255 ) );
|
||||
}
|
||||
|
||||
void CLocation_Layout_Panel::OnThink()
|
||||
{
|
||||
CreateLocationPanels();
|
||||
}
|
||||
|
||||
void CLocation_Layout_Panel::CreateLocationPanels()
|
||||
{
|
||||
if ( !LocationGrid() )
|
||||
return;
|
||||
|
||||
int iCount = 0;
|
||||
for ( int i = 0; i < LocationGrid()->GetNumGroups(); i++ )
|
||||
{
|
||||
IASW_Location_Group *pGroup = LocationGrid()->GetGroup( i );
|
||||
if ( !pGroup )
|
||||
continue;
|
||||
|
||||
for ( int k = 0; k < pGroup->GetNumLocations(); k++ )
|
||||
{
|
||||
if ( m_LocationPanels.Count() <= iCount )
|
||||
{
|
||||
CLocation_Panel *pPanel = new CLocation_Panel( this, "Location_Panel" );
|
||||
pPanel->AddActionSignalTarget( m_pActionTarget );
|
||||
m_LocationPanels.AddToTail( pPanel );
|
||||
}
|
||||
m_LocationPanels[iCount]->SetLocationID( pGroup->GetLocation( k )->GetID() );
|
||||
iCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ====================================================================================================
|
||||
|
||||
CLocation_Panel::CLocation_Panel( Panel *parent, const char *name ) : BaseClass( parent, name )
|
||||
{
|
||||
m_iLocationID = -1;
|
||||
m_pHexImage = new vgui::ImagePanel( this, "HexImage" );
|
||||
m_pHexImage->SetShouldScaleImage( true );
|
||||
m_pHexImage->SetMouseInputEnabled( false );
|
||||
m_actionMessage = NULL;
|
||||
m_pLayoutPanel = dynamic_cast<CLocation_Layout_Panel*>( parent );
|
||||
m_bDragging = false;
|
||||
m_pIDLabel = new vgui::Label( this, "IDLabel", "" );
|
||||
m_pIDLabel->SetContentAlignment( vgui::Label::a_center );
|
||||
m_pIDLabel->SetMouseInputEnabled( false );
|
||||
}
|
||||
|
||||
CLocation_Panel::~CLocation_Panel()
|
||||
{
|
||||
if ( m_actionMessage )
|
||||
{
|
||||
m_actionMessage->deleteThis();
|
||||
}
|
||||
}
|
||||
|
||||
void CLocation_Panel::SetLocationID( int i )
|
||||
{
|
||||
m_iLocationID = i;
|
||||
if ( m_actionMessage )
|
||||
{
|
||||
m_actionMessage->deleteThis();
|
||||
}
|
||||
char buffer[32];
|
||||
Q_snprintf( buffer, sizeof( buffer ), "Location%d", i );
|
||||
m_actionMessage = new KeyValues( "command", "command", buffer );
|
||||
Q_snprintf( buffer, sizeof( buffer ), "%d", i );
|
||||
m_pIDLabel->SetText( buffer );
|
||||
}
|
||||
|
||||
|
||||
void CLocation_Panel::OnThink()
|
||||
{
|
||||
if ( m_bDragging )
|
||||
{
|
||||
if ( !vgui::input()->IsMouseDown( MOUSE_LEFT ) )
|
||||
{
|
||||
m_bDragging = false;
|
||||
// update pos with editor
|
||||
int x, y;
|
||||
GetPos( x, y );
|
||||
|
||||
int fx = UNDO_YRES( x );
|
||||
int fy = UNDO_YRES( y );
|
||||
|
||||
IASW_Location *pLocation = LocationGrid()->GetLocationByID( m_iLocationID );
|
||||
if ( pLocation )
|
||||
{
|
||||
pLocation->SetPos( fx, fy );
|
||||
if ( pLocation->GetID() == 21 )
|
||||
{
|
||||
int pw, ph;
|
||||
GetParent()->GetSize( pw, ph );
|
||||
float flXFraction = (float) x / (float) pw;
|
||||
float flYFraction = (float) y / (float) ph;
|
||||
Msg( "EdLoc21 x=%d y=%d fx=%d fx=%d xfrac=%f yfrac=%f edw=%d edh=%d\n",
|
||||
x, y,
|
||||
fx, fy,
|
||||
flXFraction, flYFraction,
|
||||
pw, ph );
|
||||
}
|
||||
m_pLayoutPanel->GetLocationEditorFrame()->SetGroup( pLocation->GetGroup() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int current_posx, current_posy;
|
||||
vgui::input()->GetCursorPos( current_posx, current_posy );
|
||||
|
||||
//GetParent()->ScreenToLocal( current_posx, current_posy );
|
||||
SetPos( current_posx + m_MouseOffset.x, current_posy + m_MouseOffset.y );
|
||||
}
|
||||
}
|
||||
|
||||
UpdateHexColor();
|
||||
|
||||
if ( IsCursorOverHex() )
|
||||
{
|
||||
//MissionGridPanel *pParent = dynamic_cast<MissionGridPanel*>( GetParent() );
|
||||
//if ( pParent )
|
||||
//{
|
||||
//pParent->OnCursorOverLocationPanel( this );
|
||||
//}
|
||||
}
|
||||
|
||||
if ( !LocationGrid() )
|
||||
return;
|
||||
|
||||
IASW_Location *pLocation = LocationGrid()->GetLocationByID( m_iLocationID );
|
||||
if ( !pLocation )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( m_iLastXPos != YRES( pLocation->GetXPos() ) || m_iLastYPos != YRES( pLocation->GetYPos() ) )
|
||||
{
|
||||
InvalidateLayout( true );
|
||||
}
|
||||
}
|
||||
|
||||
void CLocation_Panel::OnMousePressed( vgui::MouseCode code )
|
||||
{
|
||||
if ( !IsCursorOverHex() )
|
||||
return;
|
||||
|
||||
// don't drag if we're not already selected
|
||||
if ( m_pLayoutPanel->GetLocationEditorFrame()->GetCurrentLocationID() != m_iLocationID )
|
||||
return;
|
||||
|
||||
m_bDragging = true;
|
||||
|
||||
int x, y;
|
||||
GetPos( x, y );
|
||||
|
||||
int current_posx, current_posy;
|
||||
vgui::input()->GetCursorPos( current_posx, current_posy );
|
||||
|
||||
m_MouseOffset.x = x - current_posx;
|
||||
m_MouseOffset.y = y - current_posy;
|
||||
}
|
||||
|
||||
void CLocation_Panel::OnMouseReleased( vgui::MouseCode code )
|
||||
{
|
||||
if ( !IsCursorOverHex() )
|
||||
return;
|
||||
|
||||
PostActionSignal( m_actionMessage->MakeCopy() );
|
||||
}
|
||||
|
||||
bool CLocation_Panel::IsCursorOverHex()
|
||||
{
|
||||
if ( !IsCursorOver() )
|
||||
return false;
|
||||
|
||||
int current_posx, current_posy;
|
||||
vgui::input()->GetCursorPos( current_posx, current_posy );
|
||||
ScreenToLocal( current_posx, current_posy );
|
||||
// this is a hacky way to constraining the "click" location to match the current art, if we change the art, we should change the bounds
|
||||
if ( current_posx > GetWide() * 0.75f || current_posy > GetTall() * 0.85f )
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CLocation_Panel::UpdateHexColor()
|
||||
{
|
||||
if ( !LocationGrid() )
|
||||
return;
|
||||
|
||||
IASW_Location *pLocation = LocationGrid()->GetLocationByID( m_iLocationID );
|
||||
if ( !pLocation )
|
||||
{
|
||||
m_pHexImage->SetDrawColor( Color( 0, 0, 0, 0 ) );
|
||||
return;
|
||||
}
|
||||
|
||||
CLocation_Editor_Frame *pFrame = m_pLayoutPanel->GetLocationEditorFrame();
|
||||
|
||||
if ( IsCursorOverHex() )
|
||||
{
|
||||
m_pHexImage->SetDrawColor( Color( 255, 255, 255, 200 ) );
|
||||
}
|
||||
else if ( pFrame && pFrame->GetCurrentLocationID() == m_iLocationID )
|
||||
{
|
||||
m_pHexImage->SetDrawColor( Color( 255, 255, 0, 200 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pHexImage->SetDrawColor( Color( 200, 200, 200, 200 ) );
|
||||
}
|
||||
}
|
||||
|
||||
void CLocation_Panel::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
int hex_size = YRES( 22 );
|
||||
|
||||
if ( !LocationGrid() )
|
||||
return;
|
||||
|
||||
IASW_Location *pLocation = LocationGrid()->GetLocationByID( m_iLocationID );
|
||||
if ( !pLocation )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_iLastXPos = YRES( pLocation->GetXPos() );
|
||||
m_iLastYPos = YRES( pLocation->GetYPos() );
|
||||
|
||||
int x = m_iLastXPos;
|
||||
int y = m_iLastYPos;
|
||||
|
||||
int iShrink = 0;
|
||||
if ( pLocation->IsMissionOptional() )
|
||||
iShrink = hex_size * 0.2;
|
||||
|
||||
if ( !m_bDragging )
|
||||
{
|
||||
SetBounds( x + iShrink, y + iShrink, hex_size - iShrink * 2, hex_size - iShrink * 2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
SetSize( hex_size - iShrink * 2, hex_size - iShrink * 2 );
|
||||
}
|
||||
m_pHexImage->SetBounds( 0, 0, hex_size - iShrink * 2, hex_size - iShrink * 2 );
|
||||
m_pIDLabel->SetBounds( 0, 0, hex_size, hex_size );
|
||||
m_pIDLabel->SetZPos( 2 );
|
||||
}
|
||||
|
||||
void CLocation_Panel::ApplySchemeSettings(vgui::IScheme *scheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(scheme);
|
||||
|
||||
SetPaintBackgroundEnabled( false );
|
||||
|
||||
m_pIDLabel->SetFont( scheme->GetFont( "DefaultVerySmall" ) );
|
||||
m_pIDLabel->SetFgColor( Color( 255, 255, 255, 255 ) );
|
||||
m_pIDLabel->SetPaintBackgroundEnabled( false );
|
||||
|
||||
m_pHexImage->SetImage( "briefing/map_icon_available.vmt" );
|
||||
UpdateHexColor();
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
#ifndef _INCLUDED_LOCATION_LAYOUT_PANEL_H
|
||||
#define _INCLUDED_LOCATION_LAYOUT_PANEL_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <vgui_controls/Panel.h>
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
class ImagePanel;
|
||||
};
|
||||
class CLocation_Editor_Frame;
|
||||
class CLocation_Layout_Panel;
|
||||
|
||||
// ====================================================================================================
|
||||
// a panel showing an individual location
|
||||
class CLocation_Panel : public vgui::Panel
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CLocation_Panel, vgui::Panel );
|
||||
public:
|
||||
CLocation_Panel( Panel *parent, const char *name );
|
||||
virtual ~CLocation_Panel();
|
||||
|
||||
virtual void OnThink();
|
||||
virtual void OnMousePressed( vgui::MouseCode code );
|
||||
virtual void OnMouseReleased( vgui::MouseCode code );
|
||||
virtual void PerformLayout();
|
||||
virtual void ApplySchemeSettings( vgui::IScheme *scheme );
|
||||
|
||||
void SetLocationID( int i );
|
||||
|
||||
int m_iLocationID;
|
||||
|
||||
private:
|
||||
bool IsCursorOverHex();
|
||||
void UpdateHexColor();
|
||||
|
||||
vgui::ImagePanel *m_pHexImage;
|
||||
vgui::Label *m_pIDLabel;
|
||||
KeyValues *m_actionMessage;
|
||||
CLocation_Layout_Panel *m_pLayoutPanel;
|
||||
int m_iLastXPos;
|
||||
int m_iLastYPos;
|
||||
|
||||
// dragging hexes around
|
||||
bool m_bDragging;
|
||||
Vector2D m_MouseOffset;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Shows all location hexes
|
||||
//-----------------------------------------------------------------------------
|
||||
class CLocation_Layout_Panel : public vgui::Panel
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CLocation_Layout_Panel, vgui::Panel );
|
||||
|
||||
public:
|
||||
CLocation_Layout_Panel( Panel *parent, vgui::Panel *pActionTarget, const char *name );
|
||||
virtual ~CLocation_Layout_Panel();
|
||||
|
||||
virtual void OnThink();
|
||||
virtual void PerformLayout();
|
||||
virtual void ApplySchemeSettings(vgui::IScheme *pScheme);
|
||||
|
||||
void CreateLocationPanels();
|
||||
CLocation_Editor_Frame* GetLocationEditorFrame() { return m_pEditorFrame; }
|
||||
|
||||
CUtlVector<CLocation_Panel*> m_LocationPanels;
|
||||
vgui::Panel *m_pActionTarget;
|
||||
vgui::ImagePanel *m_pBgImage;
|
||||
CLocation_Editor_Frame* m_pEditorFrame;
|
||||
};
|
||||
|
||||
#endif // _INCLUDED_LOCATION_LAYOUT_PANEL_H
|
||||
@@ -0,0 +1,82 @@
|
||||
#include "mission_txt_leaf_panel.h"
|
||||
#include <vgui_controls/TextEntry.h>
|
||||
#include <vgui_controls/Button.h>
|
||||
#include <vgui_controls/FileOpenDialog.h>
|
||||
#include "KeyValues.h"
|
||||
#include "filesystem.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( CMission_Txt_Panel )
|
||||
|
||||
extern char g_gamedir[1024];
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CMission_Txt_Panel::CMission_Txt_Panel( Panel *parent, const char *name ) : BaseClass( parent, name )
|
||||
{
|
||||
m_pPickButton = new vgui::Button(this, "PickButton", "...", this, "Pick");
|
||||
}
|
||||
|
||||
void CMission_Txt_Panel::OnCommand( const char *command )
|
||||
{
|
||||
if (Q_stricmp( command, "Pick" ) == 0 )
|
||||
{
|
||||
DoPick();
|
||||
}
|
||||
|
||||
BaseClass::OnCommand( command );
|
||||
}
|
||||
|
||||
|
||||
void CMission_Txt_Panel::DoPick()
|
||||
{
|
||||
// Pop up the dialog
|
||||
FileOpenDialog *pFileDialog = new FileOpenDialog(this, "Pick Room Template", true);
|
||||
|
||||
char template_dir[1024];
|
||||
Q_snprintf( template_dir, sizeof( template_dir ), "%s\\tilegen\\missions", g_gamedir );
|
||||
Msg( "DoPick(): missions dir is %s\n", template_dir );
|
||||
Msg( " g_gamedir is %s\n", g_gamedir );
|
||||
pFileDialog->SetStartDirectory( template_dir );
|
||||
pFileDialog->AddFilter("*.txt", "Mission txt (*.txt)", true);
|
||||
pFileDialog->AddActionSignalTarget(this);
|
||||
|
||||
pFileDialog->DoModal(false);
|
||||
}
|
||||
|
||||
MessageMapItem_t CMission_Txt_Panel::m_MessageMap[] =
|
||||
{
|
||||
MAP_MESSAGE_CONSTCHARPTR(CMission_Txt_Panel, "FileSelected", OnFileSelected, "fullpath"),
|
||||
};
|
||||
|
||||
IMPLEMENT_PANELMAP(CMission_Txt_Panel, CKV_Leaf_Panel);
|
||||
|
||||
void CMission_Txt_Panel::OnFileSelected( const char *fullpath )
|
||||
{
|
||||
char buffer[MAX_PATH];
|
||||
bool bConverted = g_pFullFileSystem->FullPathToRelativePath( fullpath, buffer, MAX_PATH );
|
||||
if ( !bConverted )
|
||||
{
|
||||
Warning( "Failed to convert this to a relative path: %s\n", fullpath );
|
||||
return;
|
||||
}
|
||||
Q_FixSlashes( buffer );
|
||||
m_pTextEntry->SetText( buffer );
|
||||
TextEntryChanged( m_pTextEntry );
|
||||
}
|
||||
|
||||
void CMission_Txt_Panel::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
int iLabelSpace = MAX( m_pLabel->GetWide() + 5, 100 );
|
||||
m_pTextEntry->SetBounds( iLabelSpace, 0, 390 - ( iLabelSpace + 25 ), 20 );
|
||||
SetSize( 420, 20 );
|
||||
|
||||
m_pPickButton->SetBounds( 367, 0, 25, 20 );
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef _INCLUDED_MISSION_TXT_LEAF_PANEL_H
|
||||
#define _INCLUDED_MISSION_TXT_LEAF_PANEL_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "kv_leaf_panel.h"
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
class TextEntry;
|
||||
class Button;
|
||||
};
|
||||
|
||||
// a vgui panel for showing a generic leaf
|
||||
class CMission_Txt_Panel : public CKV_Leaf_Panel
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CMission_Txt_Panel, CKV_Leaf_Panel );
|
||||
|
||||
public:
|
||||
CMission_Txt_Panel( Panel *parent, const char *name );
|
||||
|
||||
virtual void OnCommand( const char *command );
|
||||
void DoPick();
|
||||
void OnFileSelected(const char *fullpath);
|
||||
virtual void PerformLayout();
|
||||
|
||||
DECLARE_PANELMAP();
|
||||
vgui::Button* m_pPickButton;
|
||||
};
|
||||
|
||||
|
||||
#endif // _INCLUDED_MISSION_TXT_LEAF_PANEL_H
|
||||
Reference in New Issue
Block a user