2010-11-20 10:37:14 +00:00
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
2018-10-02 21:08:17 +00:00
# include <algorithm>
2015-08-17 12:10:08 +00:00
# include <base/color.h>
2020-09-26 19:41:58 +00:00
# include <base/system.h>
2007-05-22 15:03:32 +00:00
2014-01-19 03:02:01 +00:00
# if defined(CONF_FAMILY_UNIX)
# include <pthread.h>
# endif
2010-05-29 07:25:38 +00:00
# include <engine/client.h>
2010-08-17 22:06:00 +00:00
# include <engine/console.h>
2022-06-21 13:26:23 +00:00
# include <engine/gfx/image_manipulation.h>
2010-05-29 07:25:38 +00:00
# include <engine/graphics.h>
# include <engine/input.h>
# include <engine/keys.h>
2020-09-26 19:41:58 +00:00
# include <engine/shared/config.h>
2010-05-29 07:25:38 +00:00
# include <engine/storage.h>
2011-07-08 23:09:06 +00:00
# include <engine/textrender.h>
2007-05-22 15:03:32 +00:00
2020-05-15 14:29:09 +00:00
# include <game/client/components/camera.h>
2020-09-26 19:41:58 +00:00
# include <game/client/gameclient.h>
2010-05-29 07:25:38 +00:00
# include <game/client/render.h>
2011-07-08 23:09:06 +00:00
# include <game/client/ui.h>
2010-11-17 18:46:50 +00:00
# include <game/generated/client_data.h>
2020-09-26 19:41:58 +00:00
# include <game/localization.h>
2007-05-22 15:03:32 +00:00
2011-07-08 23:09:06 +00:00
# include "auto_map.h"
2011-04-19 08:34:51 +00:00
# include "editor.h"
2010-06-05 21:36:52 +00:00
2020-11-15 06:01:53 +00:00
# include <limits>
2018-06-29 21:28:49 +00:00
static const char * VANILLA_IMAGES [ ] = {
" bg_cloud1 " ,
" bg_cloud2 " ,
" bg_cloud3 " ,
" desert_doodads " ,
" desert_main " ,
" desert_mountains " ,
" desert_mountains2 " ,
" desert_sun " ,
" generic_deathtiles " ,
" generic_unhookable " ,
" grass_doodads " ,
" grass_main " ,
" jungle_background " ,
" jungle_deathtiles " ,
" jungle_doodads " ,
" jungle_main " ,
" jungle_midground " ,
" jungle_unhookables " ,
" moon " ,
" mountains " ,
" snow " ,
" stars " ,
" sun " ,
" winter_doodads " ,
" winter_main " ,
" winter_mountains " ,
" winter_mountains2 " ,
2020-09-26 19:41:58 +00:00
" winter_mountains3 " } ;
2018-06-29 21:28:49 +00:00
static bool IsVanillaImage ( const char * pImage )
{
2022-01-23 17:56:37 +00:00
return std : : any_of ( std : : begin ( VANILLA_IMAGES ) , std : : end ( VANILLA_IMAGES ) , [ pImage ] ( const char * pVanillaImage ) { return str_comp ( pImage , pVanillaImage ) = = 0 ; } ) ;
2018-06-29 21:28:49 +00:00
}
2014-12-15 17:59:21 +00:00
2020-09-26 19:41:58 +00:00
const void * CEditor : : ms_pUiGotContext ;
2007-05-22 15:03:32 +00:00
2019-04-26 12:06:32 +00:00
ColorHSVA CEditor : : ms_PickerColor ;
2015-08-17 12:10:08 +00:00
int CEditor : : ms_SVPicker ;
int CEditor : : ms_HuePicker ;
2009-10-27 14:38:53 +00:00
enum
{
2020-09-26 19:41:58 +00:00
BUTTON_CONTEXT = 1 ,
2009-10-27 14:38:53 +00:00
} ;
2008-01-13 11:43:43 +00:00
2010-05-29 07:25:38 +00:00
CEditorImage : : ~ CEditorImage ( )
2009-10-27 14:38:53 +00:00
{
2016-07-02 08:33:37 +00:00
m_pEditor - > Graphics ( ) - > UnloadTexture ( & m_Texture ) ;
2022-03-01 22:19:49 +00:00
free ( m_pData ) ;
2022-06-13 16:28:13 +00:00
m_pData = nullptr ;
2009-10-27 14:38:53 +00:00
}
2014-10-11 11:38:45 +00:00
CEditorSound : : ~ CEditorSound ( )
{
m_pEditor - > Sound ( ) - > UnloadSample ( m_SoundID ) ;
2022-03-01 22:19:49 +00:00
free ( m_pData ) ;
2022-06-13 16:28:13 +00:00
m_pData = nullptr ;
2014-10-11 11:38:45 +00:00
}
2010-05-29 07:25:38 +00:00
CLayerGroup : : CLayerGroup ( )
2007-05-22 15:03:32 +00:00
{
2011-07-12 01:14:46 +00:00
m_aName [ 0 ] = 0 ;
2010-05-29 07:25:38 +00:00
m_Visible = true ;
2011-07-12 15:54:59 +00:00
m_Collapse = false ;
2010-05-29 07:25:38 +00:00
m_GameGroup = false ;
m_OffsetX = 0 ;
m_OffsetY = 0 ;
m_ParallaxX = 100 ;
m_ParallaxY = 100 ;
2022-08-04 23:16:44 +00:00
m_ParallaxZoom = 100 ;
2010-05-29 07:25:38 +00:00
m_UseClipping = 0 ;
m_ClipX = 0 ;
m_ClipY = 0 ;
m_ClipW = 0 ;
m_ClipH = 0 ;
2008-01-12 12:27:55 +00:00
}
2007-05-22 15:03:32 +00:00
2022-05-24 09:24:33 +00:00
template < typename T >
2022-06-15 17:34:41 +00:00
static void DeleteAll ( std : : vector < T > & vList )
2022-05-24 09:24:33 +00:00
{
2022-06-15 17:34:41 +00:00
for ( auto & Item : vList )
2022-05-24 09:24:33 +00:00
delete Item ;
2022-06-15 17:34:41 +00:00
vList . clear ( ) ;
2022-05-24 09:24:33 +00:00
}
2010-05-29 07:25:38 +00:00
CLayerGroup : : ~ CLayerGroup ( )
2007-05-22 15:03:32 +00:00
{
2022-06-11 19:38:18 +00:00
DeleteAll ( m_vpLayers ) ;
2007-05-22 15:03:32 +00:00
}
2010-05-29 07:25:38 +00:00
void CLayerGroup : : Convert ( CUIRect * pRect )
2007-05-22 15:03:32 +00:00
{
2010-05-29 07:25:38 +00:00
pRect - > x + = m_OffsetX ;
pRect - > y + = m_OffsetY ;
2007-05-22 15:03:32 +00:00
}
2010-05-29 07:25:38 +00:00
void CLayerGroup : : Mapping ( float * pPoints )
2007-05-22 15:03:32 +00:00
{
2022-08-06 01:30:37 +00:00
float ParallaxZoom = m_pMap - > m_pEditor - > m_PreviewZoom ? m_ParallaxZoom : 100.0f ;
2022-05-17 13:00:06 +00:00
m_pMap - > m_pEditor - > RenderTools ( ) - > MapScreenToWorld (
2010-05-29 07:25:38 +00:00
m_pMap - > m_pEditor - > m_WorldOffsetX , m_pMap - > m_pEditor - > m_WorldOffsetY ,
2022-08-06 01:30:37 +00:00
m_ParallaxX , m_ParallaxY , ParallaxZoom , m_OffsetX , m_OffsetY ,
2010-05-29 07:25:38 +00:00
m_pMap - > m_pEditor - > Graphics ( ) - > ScreenAspect ( ) , m_pMap - > m_pEditor - > m_WorldZoom , pPoints ) ;
pPoints [ 0 ] + = m_pMap - > m_pEditor - > m_EditorOffsetX ;
pPoints [ 1 ] + = m_pMap - > m_pEditor - > m_EditorOffsetY ;
pPoints [ 2 ] + = m_pMap - > m_pEditor - > m_EditorOffsetX ;
pPoints [ 3 ] + = m_pMap - > m_pEditor - > m_EditorOffsetY ;
2007-05-22 15:03:32 +00:00
}
2010-05-29 07:25:38 +00:00
void CLayerGroup : : MapScreen ( )
2007-05-22 15:03:32 +00:00
{
2010-05-29 07:25:38 +00:00
float aPoints [ 4 ] ;
Mapping ( aPoints ) ;
m_pMap - > m_pEditor - > Graphics ( ) - > MapScreen ( aPoints [ 0 ] , aPoints [ 1 ] , aPoints [ 2 ] , aPoints [ 3 ] ) ;
2007-05-22 15:03:32 +00:00
}
2010-05-29 07:25:38 +00:00
void CLayerGroup : : Render ( )
2007-05-22 15:03:32 +00:00
{
2010-05-29 07:25:38 +00:00
MapScreen ( ) ;
IGraphics * pGraphics = m_pMap - > m_pEditor - > Graphics ( ) ;
if ( m_UseClipping )
{
float aPoints [ 4 ] ;
m_pMap - > m_pGameGroup - > Mapping ( aPoints ) ;
2020-09-26 19:41:58 +00:00
float x0 = ( m_ClipX - aPoints [ 0 ] ) / ( aPoints [ 2 ] - aPoints [ 0 ] ) ;
float y0 = ( m_ClipY - aPoints [ 1 ] ) / ( aPoints [ 3 ] - aPoints [ 1 ] ) ;
float x1 = ( ( m_ClipX + m_ClipW ) - aPoints [ 0 ] ) / ( aPoints [ 2 ] - aPoints [ 0 ] ) ;
float y1 = ( ( m_ClipY + m_ClipH ) - aPoints [ 1 ] ) / ( aPoints [ 3 ] - aPoints [ 1 ] ) ;
2010-05-29 07:25:38 +00:00
2020-09-26 19:41:58 +00:00
pGraphics - > ClipEnable ( ( int ) ( x0 * pGraphics - > ScreenWidth ( ) ) , ( int ) ( y0 * pGraphics - > ScreenHeight ( ) ) ,
( int ) ( ( x1 - x0 ) * pGraphics - > ScreenWidth ( ) ) , ( int ) ( ( y1 - y0 ) * pGraphics - > ScreenHeight ( ) ) ) ;
2008-03-29 11:44:03 +00:00
}
2010-05-29 07:25:38 +00:00
2022-06-11 19:38:18 +00:00
for ( auto & pLayer : m_vpLayers )
2008-01-12 12:27:55 +00:00
{
2022-05-24 09:24:33 +00:00
if ( pLayer - > m_Visible )
2018-07-25 20:57:58 +00:00
{
2022-05-24 09:24:33 +00:00
if ( pLayer - > m_Type = = LAYERTYPE_TILES )
2018-07-26 08:14:14 +00:00
{
2022-05-24 09:24:33 +00:00
CLayerTiles * pTiles = static_cast < CLayerTiles * > ( pLayer ) ;
2018-07-25 20:57:58 +00:00
if ( pTiles - > m_Game | | pTiles - > m_Front | | pTiles - > m_Tele | | pTiles - > m_Speedup | | pTiles - > m_Tune | | pTiles - > m_Switch )
continue ;
}
2022-05-24 09:24:33 +00:00
if ( m_pMap - > m_pEditor - > m_ShowDetail | | ! ( pLayer - > m_Flags & LAYERFLAG_DETAIL ) )
pLayer - > Render ( ) ;
2018-07-25 20:57:58 +00:00
}
}
2018-10-02 01:52:01 +00:00
2022-06-11 19:38:18 +00:00
for ( auto & pLayer : m_vpLayers )
2018-07-25 20:57:58 +00:00
{
2022-05-24 09:24:33 +00:00
if ( pLayer - > m_Visible & & pLayer - > m_Type = = LAYERTYPE_TILES & & pLayer ! = m_pMap - > m_pGameLayer & & pLayer ! = m_pMap - > m_pFrontLayer & & pLayer ! = m_pMap - > m_pTeleLayer & & pLayer ! = m_pMap - > m_pSpeedupLayer & & pLayer ! = m_pMap - > m_pSwitchLayer & & pLayer ! = m_pMap - > m_pTuneLayer )
2008-03-21 17:39:09 +00:00
{
2022-05-24 09:24:33 +00:00
CLayerTiles * pTiles = static_cast < CLayerTiles * > ( pLayer ) ;
2018-07-25 20:57:58 +00:00
if ( pTiles - > m_Game | | pTiles - > m_Front | | pTiles - > m_Tele | | pTiles - > m_Speedup | | pTiles - > m_Tune | | pTiles - > m_Switch )
{
2022-05-24 09:24:33 +00:00
pLayer - > Render ( ) ;
2018-07-25 20:57:58 +00:00
}
2008-03-21 17:39:09 +00:00
}
2008-01-12 12:27:55 +00:00
}
2010-05-29 07:25:38 +00:00
2009-10-27 14:38:53 +00:00
pGraphics - > ClipDisable ( ) ;
2008-01-12 12:27:55 +00:00
}
2022-06-30 22:36:32 +00:00
void CLayerGroup : : AddLayer ( CLayer * pLayer )
2011-03-21 23:31:42 +00:00
{
2020-05-17 14:11:39 +00:00
m_pMap - > m_Modified = true ;
2022-06-30 22:36:32 +00:00
m_vpLayers . push_back ( pLayer ) ;
2011-03-21 23:31:42 +00:00
}
2010-05-29 07:25:38 +00:00
void CLayerGroup : : DeleteLayer ( int Index )
2007-05-22 15:03:32 +00:00
{
2022-06-11 19:38:18 +00:00
if ( Index < 0 | | Index > = ( int ) m_vpLayers . size ( ) )
2020-09-26 19:41:58 +00:00
return ;
2022-06-11 19:38:18 +00:00
delete m_vpLayers [ Index ] ;
m_vpLayers . erase ( m_vpLayers . begin ( ) + Index ) ;
2011-03-21 23:31:42 +00:00
m_pMap - > m_Modified = true ;
2010-05-29 07:25:38 +00:00
}
2007-05-22 15:03:32 +00:00
2022-06-30 22:36:32 +00:00
void CLayerGroup : : GetSize ( float * pWidth , float * pHeight ) const
2007-05-22 15:03:32 +00:00
{
2022-06-30 22:36:32 +00:00
* pWidth = 0 ;
* pHeight = 0 ;
2022-06-11 19:38:18 +00:00
for ( const auto & pLayer : m_vpLayers )
2008-01-12 12:27:55 +00:00
{
float lw , lh ;
2022-05-24 09:24:33 +00:00
pLayer - > GetSize ( & lw , & lh ) ;
2022-06-30 22:36:32 +00:00
* pWidth = maximum ( * pWidth , lw ) ;
* pHeight = maximum ( * pHeight , lh ) ;
2008-01-12 12:27:55 +00:00
}
2007-05-22 15:03:32 +00:00
}
2010-05-29 07:25:38 +00:00
int CLayerGroup : : SwapLayers ( int Index0 , int Index1 )
2007-05-22 15:03:32 +00:00
{
2022-06-11 19:38:18 +00:00
if ( Index0 < 0 | | Index0 > = ( int ) m_vpLayers . size ( ) )
2020-09-26 19:41:58 +00:00
return Index0 ;
2022-06-11 19:38:18 +00:00
if ( Index1 < 0 | | Index1 > = ( int ) m_vpLayers . size ( ) )
2020-09-26 19:41:58 +00:00
return Index0 ;
if ( Index0 = = Index1 )
return Index0 ;
2011-03-21 23:31:42 +00:00
m_pMap - > m_Modified = true ;
2022-06-11 19:38:18 +00:00
std : : swap ( m_vpLayers [ Index0 ] , m_vpLayers [ Index1 ] ) ;
2010-05-29 07:25:38 +00:00
return Index1 ;
2008-03-29 11:44:03 +00:00
}
2010-05-29 07:25:38 +00:00
void CEditorImage : : AnalyseTileFlags ( )
2008-03-29 11:44:03 +00:00
{
2010-05-29 07:25:38 +00:00
mem_zero ( m_aTileFlags , sizeof ( m_aTileFlags ) ) ;
2020-09-26 19:41:58 +00:00
int tw = m_Width / 16 ; // tilesizes
int th = m_Height / 16 ;
if ( tw = = th & & m_Format = = CImageInfo : : FORMAT_RGBA )
2011-08-11 08:59:14 +00:00
{
2010-05-29 07:25:38 +00:00
unsigned char * pPixelData = ( unsigned char * ) m_pData ;
2011-02-12 10:40:36 +00:00
int TileID = 0 ;
2008-09-07 08:30:49 +00:00
for ( int ty = 0 ; ty < 16 ; ty + + )
2011-02-12 10:40:36 +00:00
for ( int tx = 0 ; tx < 16 ; tx + + , TileID + + )
2008-09-07 08:30:49 +00:00
{
2010-05-29 07:25:38 +00:00
bool Opaque = true ;
2008-09-07 08:30:49 +00:00
for ( int x = 0 ; x < tw ; x + + )
for ( int y = 0 ; y < th ; y + + )
2008-03-29 11:44:03 +00:00
{
2020-09-26 19:41:58 +00:00
int p = ( ty * tw + y ) * m_Width + tx * tw + x ;
if ( pPixelData [ p * 4 + 3 ] < 250 )
2008-09-07 08:30:49 +00:00
{
2010-05-29 07:25:38 +00:00
Opaque = false ;
2008-09-07 08:30:49 +00:00
break ;
}
2008-03-29 11:44:03 +00:00
}
2010-05-29 07:25:38 +00:00
if ( Opaque )
2011-02-12 10:40:36 +00:00
m_aTileFlags [ TileID ] | = TILEFLAG_OPAQUE ;
2008-09-07 08:30:49 +00:00
}
}
2008-03-29 11:44:03 +00:00
}
2008-01-12 12:27:55 +00:00
2022-07-01 04:42:36 +00:00
void CEditor : : EnvelopeEval ( int TimeOffsetMillis , int Env , ColorRGBA & Channels , void * pUser )
2011-07-18 10:05:12 +00:00
{
CEditor * pThis = ( CEditor * ) pUser ;
2022-06-11 19:38:18 +00:00
if ( Env < 0 | | Env > = ( int ) pThis - > m_Map . m_vpEnvelopes . size ( ) )
2011-07-18 10:05:12 +00:00
{
2022-07-01 04:42:36 +00:00
Channels = ColorRGBA ( ) ;
2011-07-18 10:05:12 +00:00
return ;
}
2022-06-30 22:36:32 +00:00
CEnvelope * pEnv = pThis - > m_Map . m_vpEnvelopes [ Env ] ;
2022-04-15 08:01:48 +00:00
float t = pThis - > m_AnimateTime ;
2011-07-18 10:05:12 +00:00
t * = pThis - > m_AnimateSpeed ;
2022-04-15 08:01:48 +00:00
t + = ( TimeOffsetMillis / 1000.0f ) ;
2022-06-30 22:36:32 +00:00
pEnv - > Eval ( t , Channels ) ;
2011-07-18 10:05:12 +00:00
}
2008-01-12 12:27:55 +00:00
/********************************************************
OTHER
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-01-13 22:03:32 +00:00
2021-12-03 18:46:31 +00:00
bool CEditor : : DoEditBox ( void * pID , const CUIRect * pRect , char * pStr , unsigned StrSize , float FontSize , float * pOffset , bool Hidden , int Corners )
2020-10-05 15:14:43 +00:00
{
2021-12-03 18:46:31 +00:00
if ( UI ( ) - > LastActiveItem ( ) = = pID )
m_EditBoxActive = 2 ;
2021-12-03 18:54:22 +00:00
return UIEx ( ) - > DoEditBox ( pID , pRect , pStr , StrSize , FontSize , pOffset , Hidden , Corners ) ;
2020-10-05 15:14:43 +00:00
}
2021-12-03 18:46:31 +00:00
bool CEditor : : DoClearableEditBox ( void * pID , void * pClearID , const CUIRect * pRect , char * pStr , unsigned StrSize , float FontSize , float * pOffset , bool Hidden , int Corners )
2008-09-23 13:28:57 +00:00
{
2021-07-17 10:48:22 +00:00
if ( UI ( ) - > LastActiveItem ( ) = = pID )
m_EditBoxActive = 2 ;
2021-12-03 18:54:22 +00:00
return UIEx ( ) - > DoClearableEditBox ( pID , pClearID , pRect , pStr , StrSize , FontSize , pOffset , Hidden , Corners ) ;
2008-09-23 13:28:57 +00:00
}
2008-01-12 12:27:55 +00:00
2019-04-26 21:47:34 +00:00
ColorRGBA CEditor : : GetButtonColor ( const void * pID , int Checked )
2007-05-22 15:03:32 +00:00
{
2010-05-29 07:25:38 +00:00
if ( Checked < 0 )
2020-09-26 19:41:58 +00:00
return ColorRGBA ( 0 , 0 , 0 , 0.5f ) ;
2010-05-29 07:25:38 +00:00
2014-12-15 17:59:21 +00:00
switch ( Checked )
2014-07-10 03:20:40 +00:00
{
2015-06-28 13:02:48 +00:00
case 7 : // selected + game layers
if ( UI ( ) - > HotItem ( ) = = pID )
2020-09-26 19:41:58 +00:00
return ColorRGBA ( 1 , 0 , 0 , 0.4f ) ;
return ColorRGBA ( 1 , 0 , 0 , 0.2f ) ;
2015-06-28 13:02:48 +00:00
case 6 : // game layers
if ( UI ( ) - > HotItem ( ) = = pID )
2020-09-26 19:41:58 +00:00
return ColorRGBA ( 1 , 1 , 1 , 0.4f ) ;
return ColorRGBA ( 1 , 1 , 1 , 0.2f ) ;
2015-06-28 13:02:48 +00:00
2014-12-15 17:59:21 +00:00
case 5 : // selected + image/sound should be embedded
2014-07-10 03:20:40 +00:00
if ( UI ( ) - > HotItem ( ) = = pID )
2020-09-26 19:41:58 +00:00
return ColorRGBA ( 1 , 0 , 0 , 0.75f ) ;
return ColorRGBA ( 1 , 0 , 0 , 0.5f ) ;
2014-07-10 03:20:40 +00:00
2014-12-15 17:59:21 +00:00
case 4 : // image/sound should be embedded
2014-07-10 03:20:40 +00:00
if ( UI ( ) - > HotItem ( ) = = pID )
2020-09-26 19:41:58 +00:00
return ColorRGBA ( 1 , 0 , 0 , 1.0f ) ;
return ColorRGBA ( 1 , 0 , 0 , 0.875f ) ;
2014-07-10 03:20:40 +00:00
2014-12-15 17:59:21 +00:00
case 3 : // selected + unused image/sound
2011-02-12 10:40:36 +00:00
if ( UI ( ) - > HotItem ( ) = = pID )
2020-09-26 19:41:58 +00:00
return ColorRGBA ( 1 , 0 , 1 , 0.75f ) ;
return ColorRGBA ( 1 , 0 , 1 , 0.5f ) ;
2014-12-15 17:59:21 +00:00
case 2 : // unused image/sound
if ( UI ( ) - > HotItem ( ) = = pID )
2020-09-26 19:41:58 +00:00
return ColorRGBA ( 0 , 0 , 1 , 0.75f ) ;
return ColorRGBA ( 0 , 0 , 1 , 0.5f ) ;
2014-12-15 17:59:21 +00:00
case 1 : // selected
if ( UI ( ) - > HotItem ( ) = = pID )
2020-09-26 19:41:58 +00:00
return ColorRGBA ( 1 , 0 , 0 , 0.75f ) ;
return ColorRGBA ( 1 , 0 , 0 , 0.5f ) ;
2010-05-29 07:25:38 +00:00
2014-12-15 17:59:21 +00:00
default : // regular
if ( UI ( ) - > HotItem ( ) = = pID )
2020-09-26 19:41:58 +00:00
return ColorRGBA ( 1 , 1 , 1 , 0.75f ) ;
return ColorRGBA ( 1 , 1 , 1 , 0.5f ) ;
2014-12-15 17:59:21 +00:00
}
2007-05-22 15:03:32 +00:00
}
2010-05-29 07:25:38 +00:00
int CEditor : : DoButton_Editor_Common ( const void * pID , const char * pText , int Checked , const CUIRect * pRect , int Flags , const char * pToolTip )
2007-05-22 15:03:32 +00:00
{
2009-10-27 14:38:53 +00:00
if ( UI ( ) - > MouseInside ( pRect ) )
{
2020-09-26 19:41:58 +00:00
if ( Flags & BUTTON_CONTEXT )
2010-05-29 07:25:38 +00:00
ms_pUiGotContext = pID ;
if ( m_pTooltip )
m_pTooltip = pToolTip ;
2009-10-27 14:38:53 +00:00
}
2010-05-29 07:25:38 +00:00
2009-10-27 14:38:53 +00:00
if ( UI ( ) - > HotItem ( ) = = pID & & pToolTip )
2019-04-11 10:21:42 +00:00
m_pTooltip = pToolTip ;
2010-05-29 07:25:38 +00:00
2022-05-13 22:26:15 +00:00
return UI ( ) - > DoButtonLogic ( pID , Checked , pRect ) ;
2009-10-27 14:38:53 +00:00
// Draw here
//return UI()->DoButton(id, text, checked, r, draw_func, 0);
}
2020-10-06 10:25:10 +00:00
int CEditor : : DoButton_Editor ( const void * pID , const char * pText , int Checked , const CUIRect * pRect , int Flags , const char * pToolTip , int AlignVert )
2009-10-27 14:38:53 +00:00
{
2010-05-29 07:25:38 +00:00
RenderTools ( ) - > DrawUIRect ( pRect , GetButtonColor ( pID , Checked ) , CUI : : CORNER_ALL , 3.0f ) ;
2011-02-16 11:36:51 +00:00
CUIRect NewRect = * pRect ;
2022-03-11 16:34:48 +00:00
SLabelProperties Props ;
Props . m_AlignVertically = AlignVert ;
UI ( ) - > DoLabel ( & NewRect , pText , 10.f , TEXTALIGN_CENTER , Props ) ;
2014-12-15 17:59:21 +00:00
Checked % = 2 ;
2009-10-27 14:38:53 +00:00
return DoButton_Editor_Common ( pID , pText , Checked , pRect , Flags , pToolTip ) ;
2007-05-22 15:03:32 +00:00
}
2019-04-26 22:11:15 +00:00
int CEditor : : DoButton_Env ( const void * pID , const char * pText , int Checked , const CUIRect * pRect , const char * pToolTip , ColorRGBA BaseColor )
2015-07-24 22:04:12 +00:00
{
2017-03-21 10:24:44 +00:00
float Bright = Checked ? 1.0f : 0.5f ;
float Alpha = UI ( ) - > HotItem ( ) = = pID ? 1.0f : 0.75f ;
2020-09-26 19:41:58 +00:00
ColorRGBA Color = ColorRGBA ( BaseColor . r * Bright , BaseColor . g * Bright , BaseColor . b * Bright , Alpha ) ;
2015-07-24 22:04:12 +00:00
2017-03-21 10:24:44 +00:00
RenderTools ( ) - > DrawUIRect ( pRect , Color , CUI : : CORNER_ALL , 3.0f ) ;
2022-03-11 16:34:48 +00:00
UI ( ) - > DoLabel ( pRect , pText , 10.f , TEXTALIGN_CENTER ) ;
2015-07-24 22:04:12 +00:00
Checked % = 2 ;
return DoButton_Editor_Common ( pID , pText , Checked , pRect , 0 , pToolTip ) ;
}
2010-05-29 07:25:38 +00:00
int CEditor : : DoButton_File ( const void * pID , const char * pText , int Checked , const CUIRect * pRect , int Flags , const char * pToolTip )
2008-01-13 16:30:30 +00:00
{
2010-10-07 21:51:07 +00:00
if ( Checked )
2010-05-29 07:25:38 +00:00
RenderTools ( ) - > DrawUIRect ( pRect , GetButtonColor ( pID , Checked ) , CUI : : CORNER_ALL , 3.0f ) ;
2009-10-27 14:38:53 +00:00
CUIRect t = * pRect ;
t . VMargin ( 5.0f , & t ) ;
2022-03-11 16:34:48 +00:00
UI ( ) - > DoLabel ( & t , pText , 10 , TEXTALIGN_LEFT ) ;
2009-10-27 14:38:53 +00:00
return DoButton_Editor_Common ( pID , pText , Checked , pRect , Flags , pToolTip ) ;
2008-01-13 16:30:30 +00:00
}
2010-05-29 07:25:38 +00:00
int CEditor : : DoButton_Menu ( const void * pID , const char * pText , int Checked , const CUIRect * pRect , int Flags , const char * pToolTip )
2008-01-13 22:03:32 +00:00
{
2009-10-27 14:38:53 +00:00
CUIRect r = * pRect ;
2019-04-26 21:47:34 +00:00
RenderTools ( ) - > DrawUIRect ( & r , ColorRGBA ( 0.5f , 0.5f , 0.5f , 1.0f ) , CUI : : CORNER_T , 3.0f ) ;
2008-01-13 22:03:32 +00:00
2009-10-27 14:38:53 +00:00
r = * pRect ;
r . VMargin ( 5.0f , & r ) ;
2022-03-11 16:34:48 +00:00
UI ( ) - > DoLabel ( & r , pText , 10 , TEXTALIGN_LEFT ) ;
2009-10-27 14:38:53 +00:00
return DoButton_Editor_Common ( pID , pText , Checked , pRect , Flags , pToolTip ) ;
2008-01-13 22:03:32 +00:00
}
2010-05-29 07:25:38 +00:00
int CEditor : : DoButton_MenuItem ( const void * pID , const char * pText , int Checked , const CUIRect * pRect , int Flags , const char * pToolTip )
2008-01-13 22:03:32 +00:00
{
2009-10-27 14:38:53 +00:00
if ( UI ( ) - > HotItem ( ) = = pID | | Checked )
2010-05-29 07:25:38 +00:00
RenderTools ( ) - > DrawUIRect ( pRect , GetButtonColor ( pID , Checked ) , CUI : : CORNER_ALL , 3.0f ) ;
2009-10-27 14:38:53 +00:00
CUIRect t = * pRect ;
t . VMargin ( 5.0f , & t ) ;
2022-03-11 16:34:48 +00:00
UI ( ) - > DoLabel ( & t , pText , 10 , TEXTALIGN_LEFT ) ;
2011-01-29 17:48:55 +00:00
return DoButton_Editor_Common ( pID , pText , Checked , pRect , Flags , pToolTip ) ;
2008-01-13 22:03:32 +00:00
}
2010-05-29 07:25:38 +00:00
int CEditor : : DoButton_Tab ( const void * pID , const char * pText , int Checked , const CUIRect * pRect , int Flags , const char * pToolTip )
2007-05-22 15:03:32 +00:00
{
2010-05-29 07:25:38 +00:00
RenderTools ( ) - > DrawUIRect ( pRect , GetButtonColor ( pID , Checked ) , CUI : : CORNER_T , 5.0f ) ;
2011-08-11 08:59:14 +00:00
CUIRect NewRect = * pRect ;
2022-03-11 16:34:48 +00:00
UI ( ) - > DoLabel ( & NewRect , pText , 10 , TEXTALIGN_CENTER ) ;
2009-10-27 14:38:53 +00:00
return DoButton_Editor_Common ( pID , pText , Checked , pRect , Flags , pToolTip ) ;
2007-05-22 15:03:32 +00:00
}
2020-10-06 10:25:10 +00:00
int CEditor : : DoButton_Ex ( const void * pID , const char * pText , int Checked , const CUIRect * pRect , int Flags , const char * pToolTip , int Corners , float FontSize , int AlignVert )
2007-05-22 15:03:32 +00:00
{
2010-05-29 07:25:38 +00:00
RenderTools ( ) - > DrawUIRect ( pRect , GetButtonColor ( pID , Checked ) , Corners , 3.0f ) ;
2011-08-11 08:59:14 +00:00
CUIRect NewRect = * pRect ;
2022-03-11 16:34:48 +00:00
SLabelProperties Props ;
Props . m_AlignVertically = AlignVert ;
UI ( ) - > DoLabel ( & NewRect , pText , FontSize , TEXTALIGN_CENTER , Props ) ;
2009-10-27 14:38:53 +00:00
return DoButton_Editor_Common ( pID , pText , Checked , pRect , Flags , pToolTip ) ;
2007-05-22 15:03:32 +00:00
}
2010-05-29 07:25:38 +00:00
int CEditor : : DoButton_ButtonInc ( const void * pID , const char * pText , int Checked , const CUIRect * pRect , int Flags , const char * pToolTip )
2007-05-22 15:03:32 +00:00
{
2010-05-29 07:25:38 +00:00
RenderTools ( ) - > DrawUIRect ( pRect , GetButtonColor ( pID , Checked ) , CUI : : CORNER_R , 3.0f ) ;
2022-03-11 16:34:48 +00:00
UI ( ) - > DoLabel ( pRect , pText ? pText : " + " , 10 , TEXTALIGN_CENTER ) ;
2009-10-27 14:38:53 +00:00
return DoButton_Editor_Common ( pID , pText , Checked , pRect , Flags , pToolTip ) ;
2007-05-22 15:03:32 +00:00
}
2010-05-29 07:25:38 +00:00
int CEditor : : DoButton_ButtonDec ( const void * pID , const char * pText , int Checked , const CUIRect * pRect , int Flags , const char * pToolTip )
2007-05-22 15:03:32 +00:00
{
2010-05-29 07:25:38 +00:00
RenderTools ( ) - > DrawUIRect ( pRect , GetButtonColor ( pID , Checked ) , CUI : : CORNER_L , 3.0f ) ;
2022-03-11 16:34:48 +00:00
UI ( ) - > DoLabel ( pRect , pText ? pText : " - " , 10 , TEXTALIGN_CENTER ) ;
2009-10-27 14:38:53 +00:00
return DoButton_Editor_Common ( pID , pText , Checked , pRect , Flags , pToolTip ) ;
2007-05-22 15:03:32 +00:00
}
2019-04-26 12:06:32 +00:00
int CEditor : : DoButton_ColorPicker ( const void * pID , const CUIRect * pRect , ColorRGBA * pColor , const char * pToolTip )
2015-08-17 12:10:08 +00:00
{
RenderTools ( ) - > DrawUIRect ( pRect , * pColor , 0 , 0.0f ) ;
2022-06-13 16:28:13 +00:00
return DoButton_Editor_Common ( pID , nullptr , 0 , pRect , 0 , pToolTip ) ;
2015-08-17 12:10:08 +00:00
}
2011-07-10 20:16:16 +00:00
void CEditor : : RenderGrid ( CLayerGroup * pGroup )
{
if ( ! m_GridActive )
return ;
float aGroupPoints [ 4 ] ;
2011-08-11 08:59:14 +00:00
pGroup - > Mapping ( aGroupPoints ) ;
2011-07-10 20:16:16 +00:00
float w = UI ( ) - > Screen ( ) - > w ;
float h = UI ( ) - > Screen ( ) - > h ;
int LineDistance = GetLineDistance ( ) ;
2020-09-26 19:41:58 +00:00
int XOffset = aGroupPoints [ 0 ] / LineDistance ;
int YOffset = aGroupPoints [ 1 ] / LineDistance ;
2011-07-10 20:16:16 +00:00
int XGridOffset = XOffset % m_GridFactor ;
int YGridOffset = YOffset % m_GridFactor ;
2012-08-12 10:41:50 +00:00
Graphics ( ) - > TextureClear ( ) ;
2011-07-10 20:16:16 +00:00
Graphics ( ) - > LinesBegin ( ) ;
for ( int i = 0 ; i < ( int ) w ; i + + )
{
2020-09-26 19:41:58 +00:00
if ( ( i + YGridOffset ) % m_GridFactor = = 0 )
2011-07-10 20:16:16 +00:00
Graphics ( ) - > SetColor ( 1.0f , 0.3f , 0.3f , 0.3f ) ;
else
Graphics ( ) - > SetColor ( 1.0f , 1.0f , 1.0f , 0.15f ) ;
2020-09-26 19:41:58 +00:00
IGraphics : : CLineItem Line = IGraphics : : CLineItem ( LineDistance * XOffset , LineDistance * i + LineDistance * YOffset , w + aGroupPoints [ 2 ] , LineDistance * i + LineDistance * YOffset ) ;
2011-07-10 20:16:16 +00:00
Graphics ( ) - > LinesDraw ( & Line , 1 ) ;
2020-09-26 19:41:58 +00:00
if ( ( i + XGridOffset ) % m_GridFactor = = 0 )
2011-07-10 20:16:16 +00:00
Graphics ( ) - > SetColor ( 1.0f , 0.3f , 0.3f , 0.3f ) ;
else
Graphics ( ) - > SetColor ( 1.0f , 1.0f , 1.0f , 0.15f ) ;
2020-09-26 19:41:58 +00:00
Line = IGraphics : : CLineItem ( LineDistance * i + LineDistance * XOffset , LineDistance * YOffset , LineDistance * i + LineDistance * XOffset , h + aGroupPoints [ 3 ] ) ;
2011-07-10 20:16:16 +00:00
Graphics ( ) - > LinesDraw ( & Line , 1 ) ;
}
Graphics ( ) - > SetColor ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
Graphics ( ) - > LinesEnd ( ) ;
}
2012-08-12 10:41:50 +00:00
void CEditor : : RenderBackground ( CUIRect View , IGraphics : : CTextureHandle Texture , float Size , float Brightness )
2007-05-22 15:03:32 +00:00
{
2010-05-29 07:25:38 +00:00
Graphics ( ) - > TextureSet ( Texture ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > BlendNormal ( ) ;
Graphics ( ) - > QuadsBegin ( ) ;
2010-05-29 07:25:38 +00:00
Graphics ( ) - > SetColor ( Brightness , Brightness , Brightness , 1.0f ) ;
2020-09-26 19:41:58 +00:00
Graphics ( ) - > QuadsSetSubset ( 0 , 0 , View . w / Size , View . h / Size ) ;
2010-05-29 07:25:38 +00:00
IGraphics : : CQuadItem QuadItem ( View . x , View . y , View . w , View . h ) ;
Graphics ( ) - > QuadsDrawTL ( & QuadItem , 1 ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsEnd ( ) ;
2007-05-22 15:03:32 +00:00
}
2022-06-30 22:36:32 +00:00
int CEditor : : UiDoValueSelector ( void * pID , CUIRect * pRect , const char * pLabel , int Current , int Min , int Max , int Step , float Scale , const char * pToolTip , bool IsDegree , bool IsHex , int Corners , ColorRGBA * pColor )
2007-07-30 19:46:31 +00:00
{
2015-03-30 09:44:32 +00:00
// logic
static float s_Value ;
2021-09-13 09:47:47 +00:00
static char s_aNumStr [ 64 ] ;
2015-03-30 09:44:32 +00:00
static bool s_TextMode = false ;
2022-06-30 22:36:32 +00:00
static void * s_pLastTextpID = pID ;
2022-05-13 18:27:03 +00:00
const bool Inside = UI ( ) - > MouseInside ( pRect ) ;
2015-03-30 09:44:32 +00:00
if ( UI ( ) - > MouseButton ( 1 ) & & UI ( ) - > HotItem ( ) = = pID )
{
2022-06-30 22:36:32 +00:00
s_pLastTextpID = pID ;
2015-03-30 09:44:32 +00:00
s_TextMode = true ;
2017-03-21 10:24:44 +00:00
if ( IsHex )
2021-09-13 09:47:47 +00:00
str_format ( s_aNumStr , sizeof ( s_aNumStr ) , " %06X " , Current ) ;
2015-08-20 10:51:30 +00:00
else
2021-09-13 09:47:47 +00:00
str_format ( s_aNumStr , sizeof ( s_aNumStr ) , " %d " , Current ) ;
2015-03-30 09:44:32 +00:00
}
2022-05-27 08:55:32 +00:00
if ( UI ( ) - > CheckActiveItem ( pID ) )
2015-05-31 15:34:32 +00:00
{
if ( ! UI ( ) - > MouseButton ( 0 ) )
{
2021-10-23 11:48:21 +00:00
m_LockMouse = false ;
2022-05-27 09:59:14 +00:00
UI ( ) - > SetActiveItem ( nullptr ) ;
2015-05-31 15:34:32 +00:00
s_TextMode = false ;
}
}
2022-06-30 22:36:32 +00:00
if ( s_TextMode & & s_pLastTextpID = = pID )
2015-03-30 09:44:32 +00:00
{
m_pTooltip = " Type your number " ;
static float s_NumberBoxID = 0 ;
2021-09-13 09:47:47 +00:00
DoEditBox ( & s_NumberBoxID , pRect , s_aNumStr , sizeof ( s_aNumStr ) , 10.0f , & s_NumberBoxID , false , Corners ) ;
2015-03-30 09:44:32 +00:00
UI ( ) - > SetActiveItem ( & s_NumberBoxID ) ;
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyIsPressed ( KEY_RETURN ) | | Input ( ) - > KeyIsPressed ( KEY_KP_ENTER ) | |
2020-09-26 19:41:58 +00:00
( ( UI ( ) - > MouseButton ( 1 ) | | UI ( ) - > MouseButton ( 0 ) ) & & ! Inside ) )
2015-03-30 09:44:32 +00:00
{
2017-03-21 10:24:44 +00:00
if ( IsHex )
2021-09-13 09:47:47 +00:00
Current = clamp ( str_toint_base ( s_aNumStr , 16 ) , Min , Max ) ;
2015-08-20 10:51:30 +00:00
else
2021-09-13 09:47:47 +00:00
Current = clamp ( str_toint ( s_aNumStr ) , Min , Max ) ;
2021-10-23 11:48:21 +00:00
m_LockMouse = false ;
2022-05-27 09:59:14 +00:00
UI ( ) - > SetActiveItem ( nullptr ) ;
2015-03-30 09:44:32 +00:00
s_TextMode = false ;
}
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyIsPressed ( KEY_ESCAPE ) )
2015-03-30 09:44:32 +00:00
{
2021-10-23 11:48:21 +00:00
m_LockMouse = false ;
2022-05-27 09:59:14 +00:00
UI ( ) - > SetActiveItem ( nullptr ) ;
2015-03-30 09:44:32 +00:00
s_TextMode = false ;
}
}
else
{
2022-05-27 08:55:32 +00:00
if ( UI ( ) - > CheckActiveItem ( pID ) )
2015-03-30 09:44:32 +00:00
{
2015-05-31 15:34:32 +00:00
if ( UI ( ) - > MouseButton ( 0 ) )
2015-03-30 09:44:32 +00:00
{
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) | | Input ( ) - > KeyIsPressed ( KEY_RSHIFT ) )
2020-09-26 19:41:58 +00:00
s_Value + = m_MouseDeltaX * 0.05f ;
2015-03-30 09:44:32 +00:00
else
s_Value + = m_MouseDeltaX ;
2011-08-11 08:59:14 +00:00
2015-03-30 09:44:32 +00:00
if ( absolute ( s_Value ) > Scale )
{
2020-09-26 19:41:58 +00:00
int Count = ( int ) ( s_Value / Scale ) ;
2015-03-30 09:44:32 +00:00
s_Value = fmod ( s_Value , Scale ) ;
2020-09-26 19:41:58 +00:00
Current + = Step * Count ;
2015-03-30 09:44:32 +00:00
Current = clamp ( Current , Min , Max ) ;
2019-09-22 11:21:17 +00:00
// Constrain to discrete steps
if ( Count > 0 )
Current = Current / Step * Step ;
else
Current = round_ceil ( Current / ( float ) Step ) * Step ;
2015-03-30 09:44:32 +00:00
}
}
if ( pToolTip & & ! s_TextMode )
m_pTooltip = pToolTip ;
}
else if ( UI ( ) - > HotItem ( ) = = pID )
{
if ( UI ( ) - > MouseButton ( 0 ) )
{
2021-10-23 11:48:21 +00:00
m_LockMouse = true ;
2015-03-30 09:44:32 +00:00
s_Value = 0 ;
UI ( ) - > SetActiveItem ( pID ) ;
}
if ( pToolTip & & ! s_TextMode )
m_pTooltip = pToolTip ;
}
if ( Inside )
UI ( ) - > SetHotItem ( pID ) ;
// render
char aBuf [ 128 ] ;
2015-07-08 11:38:21 +00:00
if ( pLabel [ 0 ] ! = ' \0 ' )
2020-09-26 19:41:58 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %s %d " , pLabel , Current ) ;
2017-03-21 10:24:44 +00:00
else if ( IsDegree )
2020-09-26 19:41:58 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %d° " , Current ) ;
2017-03-21 10:24:44 +00:00
else if ( IsHex )
2020-09-26 19:41:58 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " #%06X " , Current ) ;
2015-07-08 11:38:21 +00:00
else
2020-09-26 19:41:58 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %d " , Current ) ;
2022-06-30 22:36:32 +00:00
RenderTools ( ) - > DrawUIRect ( pRect , pColor ? * pColor : GetButtonColor ( pID , 0 ) , Corners , 5.0f ) ;
2022-03-11 16:34:48 +00:00
UI ( ) - > DoLabel ( pRect , aBuf , 10 , TEXTALIGN_CENTER ) ;
2015-03-30 09:44:32 +00:00
}
2015-07-09 00:08:14 +00:00
2010-05-29 07:25:38 +00:00
return Current ;
2007-05-22 15:03:32 +00:00
}
2021-02-08 21:26:26 +00:00
CLayerGroup * CEditor : : GetSelectedGroup ( ) const
2007-05-22 15:03:32 +00:00
{
2022-06-11 19:38:18 +00:00
if ( m_SelectedGroup > = 0 & & m_SelectedGroup < ( int ) m_Map . m_vpGroups . size ( ) )
return m_Map . m_vpGroups [ m_SelectedGroup ] ;
2022-06-13 16:28:13 +00:00
return nullptr ;
2007-05-22 15:03:32 +00:00
}
2021-02-08 21:26:26 +00:00
CLayer * CEditor : : GetSelectedLayer ( int Index ) const
2007-05-22 15:03:32 +00:00
{
2010-05-29 07:25:38 +00:00
CLayerGroup * pGroup = GetSelectedGroup ( ) ;
if ( ! pGroup )
2022-06-13 16:28:13 +00:00
return nullptr ;
2018-10-02 01:52:01 +00:00
2022-06-11 19:38:18 +00:00
if ( Index < 0 | | Index > = ( int ) m_vSelectedLayers . size ( ) )
2022-06-13 16:28:13 +00:00
return nullptr ;
2018-10-02 01:52:01 +00:00
2022-06-11 19:38:18 +00:00
int LayerIndex = m_vSelectedLayers [ Index ] ;
2008-01-12 12:27:55 +00:00
2022-06-11 19:38:18 +00:00
if ( LayerIndex > = 0 & & LayerIndex < ( int ) m_Map . m_vpGroups [ m_SelectedGroup ] - > m_vpLayers . size ( ) )
return pGroup - > m_vpLayers [ LayerIndex ] ;
2022-06-13 16:28:13 +00:00
return nullptr ;
2007-05-22 15:03:32 +00:00
}
2021-02-08 21:26:26 +00:00
CLayer * CEditor : : GetSelectedLayerType ( int Index , int Type ) const
2007-05-22 15:03:32 +00:00
{
2010-05-29 07:25:38 +00:00
CLayer * p = GetSelectedLayer ( Index ) ;
if ( p & & p - > m_Type = = Type )
2008-01-12 12:27:55 +00:00
return p ;
2022-06-13 16:28:13 +00:00
return nullptr ;
2007-05-22 15:03:32 +00:00
}
2022-05-24 09:24:33 +00:00
std : : vector < CQuad * > CEditor : : GetSelectedQuads ( )
2008-01-12 12:27:55 +00:00
{
2022-06-30 22:36:32 +00:00
CLayerQuads * pQuadLayer = ( CLayerQuads * ) GetSelectedLayerType ( 0 , LAYERTYPE_QUADS ) ;
2022-06-11 20:03:23 +00:00
std : : vector < CQuad * > vpQuads ;
2022-06-30 22:36:32 +00:00
if ( ! pQuadLayer )
2022-06-11 20:03:23 +00:00
return vpQuads ;
vpQuads . resize ( m_vSelectedQuads . size ( ) ) ;
2022-06-11 19:38:18 +00:00
for ( int i = 0 ; i < ( int ) m_vSelectedQuads . size ( ) ; + + i )
2022-06-30 22:36:32 +00:00
vpQuads [ i ] = & pQuadLayer - > m_vQuads [ m_vSelectedQuads [ i ] ] ;
2022-06-11 20:03:23 +00:00
return vpQuads ;
2008-01-12 12:27:55 +00:00
}
2007-12-02 17:55:45 +00:00
2014-10-10 17:11:21 +00:00
CSoundSource * CEditor : : GetSelectedSource ( )
{
CLayerSounds * pSounds = ( CLayerSounds * ) GetSelectedLayerType ( 0 , LAYERTYPE_SOUNDS ) ;
if ( ! pSounds )
2022-06-13 16:28:13 +00:00
return nullptr ;
2022-06-11 19:38:18 +00:00
if ( m_SelectedSource > = 0 & & m_SelectedSource < ( int ) pSounds - > m_vSources . size ( ) )
return & pSounds - > m_vSources [ m_SelectedSource ] ;
2022-06-13 16:28:13 +00:00
return nullptr ;
2014-10-10 17:11:21 +00:00
}
2020-09-02 15:11:24 +00:00
void CEditor : : SelectLayer ( int LayerIndex , int GroupIndex )
2018-07-25 20:57:58 +00:00
{
2020-09-26 19:41:58 +00:00
if ( GroupIndex ! = - 1 )
2020-09-02 15:11:24 +00:00
m_SelectedGroup = GroupIndex ;
2022-06-11 19:38:18 +00:00
m_vSelectedLayers . clear ( ) ;
2022-07-30 11:27:54 +00:00
m_vSelectedQuads . clear ( ) ;
2022-02-26 17:49:06 +00:00
AddSelectedLayer ( LayerIndex ) ;
}
void CEditor : : AddSelectedLayer ( int LayerIndex )
{
2022-06-11 19:38:18 +00:00
m_vSelectedLayers . push_back ( LayerIndex ) ;
2022-02-26 17:49:06 +00:00
m_QuadKnifeActive = false ;
2018-07-25 20:57:58 +00:00
}
2018-08-13 09:11:56 +00:00
void CEditor : : SelectQuad ( int Index )
{
2022-06-11 19:38:18 +00:00
m_vSelectedQuads . clear ( ) ;
m_vSelectedQuads . push_back ( Index ) ;
2018-08-13 09:11:56 +00:00
}
void CEditor : : DeleteSelectedQuads ( )
{
CLayerQuads * pLayer = ( CLayerQuads * ) GetSelectedLayerType ( 0 , LAYERTYPE_QUADS ) ;
if ( ! pLayer )
return ;
2022-06-11 19:38:18 +00:00
for ( int i = 0 ; i < ( int ) m_vSelectedQuads . size ( ) ; + + i )
2018-08-13 09:11:56 +00:00
{
2022-06-11 19:38:18 +00:00
pLayer - > m_vQuads . erase ( pLayer - > m_vQuads . begin ( ) + m_vSelectedQuads [ i ] ) ;
for ( int j = i + 1 ; j < ( int ) m_vSelectedQuads . size ( ) ; + + j )
if ( m_vSelectedQuads [ j ] > m_vSelectedQuads [ i ] )
m_vSelectedQuads [ j ] - - ;
2018-08-13 09:11:56 +00:00
2022-06-11 19:38:18 +00:00
m_vSelectedQuads . erase ( m_vSelectedQuads . begin ( ) + i ) ;
2022-05-24 09:24:33 +00:00
i - - ;
2018-08-13 09:11:56 +00:00
}
2018-08-13 14:46:53 +00:00
}
2021-02-08 21:26:26 +00:00
bool CEditor : : IsQuadSelected ( int Index ) const
2018-08-13 14:46:53 +00:00
{
2022-05-24 09:24:33 +00:00
return FindSelectedQuadIndex ( Index ) > = 0 ;
2018-08-13 14:46:53 +00:00
}
2021-02-08 21:26:26 +00:00
int CEditor : : FindSelectedQuadIndex ( int Index ) const
2018-08-13 14:46:53 +00:00
{
2022-06-11 19:38:18 +00:00
for ( size_t i = 0 ; i < m_vSelectedQuads . size ( ) ; + + i )
if ( m_vSelectedQuads [ i ] = = Index )
2018-08-13 14:46:53 +00:00
return i ;
return - 1 ;
2018-08-13 09:11:56 +00:00
}
2011-03-21 23:31:42 +00:00
void CEditor : : CallbackOpenMap ( const char * pFileName , int StorageType , void * pUser )
2010-09-12 11:15:59 +00:00
{
2020-09-26 19:41:58 +00:00
CEditor * pEditor = ( CEditor * ) pUser ;
2010-10-07 21:51:07 +00:00
if ( pEditor - > Load ( pFileName , StorageType ) )
2010-06-02 16:12:32 +00:00
{
2010-10-08 20:06:12 +00:00
pEditor - > m_ValidSaveFilename = StorageType = = IStorage : : TYPE_SAVE & & pEditor - > m_pFileDialogPath = = pEditor - > m_aFileDialogCurrentFolder ;
2010-09-12 11:15:59 +00:00
pEditor - > m_Dialog = DIALOG_NONE ;
2013-05-26 08:58:03 +00:00
}
2010-06-02 16:12:32 +00:00
}
2015-07-26 10:04:43 +00:00
2011-03-21 23:31:42 +00:00
void CEditor : : CallbackAppendMap ( const char * pFileName , int StorageType , void * pUser )
2010-06-02 16:12:32 +00:00
{
2020-09-26 19:41:58 +00:00
CEditor * pEditor = ( CEditor * ) pUser ;
2010-10-07 21:51:07 +00:00
if ( pEditor - > Append ( pFileName , StorageType ) )
2010-06-02 16:12:32 +00:00
pEditor - > m_aFileName [ 0 ] = 0 ;
2010-06-05 22:47:30 +00:00
else
pEditor - > SortImages ( ) ;
2011-08-11 08:59:14 +00:00
2010-09-12 11:15:59 +00:00
pEditor - > m_Dialog = DIALOG_NONE ;
2010-06-02 16:12:32 +00:00
}
2015-07-26 10:04:43 +00:00
2011-03-21 23:31:42 +00:00
void CEditor : : CallbackSaveMap ( const char * pFileName , int StorageType , void * pUser )
2010-06-25 17:41:55 +00:00
{
2020-09-26 19:41:58 +00:00
CEditor * pEditor = static_cast < CEditor * > ( pUser ) ;
2010-06-25 17:41:55 +00:00
char aBuf [ 1024 ] ;
// add map extension
2018-07-25 08:29:05 +00:00
if ( ! str_endswith ( pFileName , " .map " ) )
2010-06-25 17:41:55 +00:00
{
str_format ( aBuf , sizeof ( aBuf ) , " %s.map " , pFileName ) ;
pFileName = aBuf ;
}
2011-08-13 00:12:40 +00:00
if ( pEditor - > Save ( pFileName ) )
{
str_copy ( pEditor - > m_aFileName , pFileName , sizeof ( pEditor - > m_aFileName ) ) ;
pEditor - > m_ValidSaveFilename = StorageType = = IStorage : : TYPE_SAVE & & pEditor - > m_pFileDialogPath = = pEditor - > m_aFileDialogCurrentFolder ;
pEditor - > m_Map . m_Modified = false ;
}
2011-08-11 08:59:14 +00:00
2010-09-12 11:15:59 +00:00
pEditor - > m_Dialog = DIALOG_NONE ;
2010-06-25 17:41:55 +00:00
}
2007-12-02 17:55:45 +00:00
2015-07-26 10:05:14 +00:00
void CEditor : : CallbackSaveCopyMap ( const char * pFileName , int StorageType , void * pUser )
{
2020-09-26 19:41:58 +00:00
CEditor * pEditor = static_cast < CEditor * > ( pUser ) ;
2015-07-26 10:05:14 +00:00
char aBuf [ 1024 ] ;
// add map extension
2018-07-25 08:29:05 +00:00
if ( ! str_endswith ( pFileName , " .map " ) )
2015-07-26 10:05:14 +00:00
{
str_format ( aBuf , sizeof ( aBuf ) , " %s.map " , pFileName ) ;
pFileName = aBuf ;
}
if ( pEditor - > Save ( pFileName ) )
{
pEditor - > m_Map . m_Modified = false ;
}
pEditor - > m_Dialog = DIALOG_NONE ;
}
2020-09-26 19:41:58 +00:00
static int EntitiesListdirCallback ( const char * pName , int IsDir , int StorageType , void * pUser )
{
CEditor * pEditor = ( CEditor * ) pUser ;
if ( ! IsDir & & str_endswith ( pName , " .png " ) )
{
2018-10-02 21:08:17 +00:00
std : : string Name = pName ;
2022-06-11 19:38:18 +00:00
pEditor - > m_vSelectEntitiesFiles . push_back ( Name . substr ( 0 , Name . length ( ) - 4 ) ) ;
2018-10-02 21:08:17 +00:00
}
return 0 ;
}
2010-05-29 07:25:38 +00:00
void CEditor : : DoToolbar ( CUIRect ToolBar )
2007-05-22 15:03:32 +00:00
{
2021-12-18 11:23:20 +00:00
bool ModPressed = Input ( ) - > ModifierIsPressed ( ) ;
2021-02-16 21:26:58 +00:00
bool ShiftPressed = Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) | | Input ( ) - > KeyIsPressed ( KEY_RSHIFT ) ;
2020-05-15 16:14:39 +00:00
2010-05-29 07:25:38 +00:00
CUIRect TB_Top , TB_Bottom ;
CUIRect Button ;
2011-08-11 08:59:14 +00:00
2022-01-26 19:23:50 +00:00
ToolBar . HSplitMid ( & TB_Top , & TB_Bottom , 5.0f ) ;
2020-09-22 12:28:14 +00:00
2020-05-17 01:39:23 +00:00
// top line buttons
2011-03-21 23:31:42 +00:00
{
2020-05-17 01:39:23 +00:00
// detail button
TB_Top . VSplitLeft ( 40.0f , & Button , & TB_Top ) ;
static int s_HqButton = 0 ;
if ( DoButton_Editor ( & s_HqButton , " HD " , m_ShowDetail , & Button , 0 , " [ctrl+h] Toggle High Detail " ) | |
2021-12-18 11:23:20 +00:00
( Input ( ) - > KeyPress ( KEY_H ) & & ModPressed ) )
2020-05-17 01:39:23 +00:00
{
m_ShowDetail = ! m_ShowDetail ;
}
2008-03-21 17:39:09 +00:00
2022-06-13 16:28:13 +00:00
TB_Top . VSplitLeft ( 5.0f , nullptr , & TB_Top ) ;
2010-05-29 07:25:38 +00:00
2020-05-17 01:39:23 +00:00
// animation button
TB_Top . VSplitLeft ( 40.0f , & Button , & TB_Top ) ;
static int s_AnimateButton = 0 ;
if ( DoButton_Editor ( & s_AnimateButton , " Anim " , m_Animate , & Button , 0 , " [ctrl+m] Toggle animation " ) | |
2021-12-18 11:23:20 +00:00
( Input ( ) - > KeyPress ( KEY_M ) & & ModPressed ) )
2020-05-17 01:39:23 +00:00
{
m_AnimateStart = time_get ( ) ;
m_Animate = ! m_Animate ;
}
2008-01-13 13:42:59 +00:00
2022-06-13 16:28:13 +00:00
TB_Top . VSplitLeft ( 5.0f , nullptr , & TB_Top ) ;
2008-01-13 13:42:59 +00:00
2020-05-17 01:39:23 +00:00
// proof button
TB_Top . VSplitLeft ( 40.0f , & Button , & TB_Top ) ;
static int s_ProofButton = 0 ;
if ( DoButton_Editor ( & s_ProofButton , " Proof " , m_ProofBorders , & Button , 0 , " [ctrl+p] Toggles proof borders. These borders represent what a player maximum can see. " ) | |
2021-12-18 11:23:20 +00:00
( Input ( ) - > KeyPress ( KEY_P ) & & ModPressed ) )
2020-05-17 01:39:23 +00:00
{
m_ProofBorders = ! m_ProofBorders ;
}
2008-01-13 13:42:59 +00:00
2022-06-13 16:28:13 +00:00
TB_Top . VSplitLeft ( 5.0f , nullptr , & TB_Top ) ;
2011-02-18 10:41:27 +00:00
2022-08-06 01:30:37 +00:00
// zoom button
TB_Top . VSplitLeft ( 40.0f , & Button , & TB_Top ) ;
static int s_ZoomButton = 0 ;
if ( DoButton_Editor ( & s_ZoomButton , " Zoom " , m_PreviewZoom , & Button , 0 , " Toggles preview of how layers will be zoomed in-game " ) )
{
m_PreviewZoom = ! m_PreviewZoom ;
}
TB_Top . VSplitLeft ( 5.0f , nullptr , & TB_Top ) ;
2020-05-17 01:39:23 +00:00
// grid button
TB_Top . VSplitLeft ( 40.0f , & Button , & TB_Top ) ;
static int s_GridButton = 0 ;
if ( DoButton_Editor ( & s_GridButton , " Grid " , m_GridActive , & Button , 0 , " [ctrl+g] Toggle Grid " ) | |
2021-12-18 11:23:20 +00:00
( Input ( ) - > KeyPress ( KEY_G ) & & ModPressed ) )
2020-05-17 01:39:23 +00:00
{
m_GridActive = ! m_GridActive ;
}
2016-05-01 00:34:06 +00:00
2022-06-13 16:28:13 +00:00
TB_Top . VSplitLeft ( 5.0f , nullptr , & TB_Top ) ;
2016-05-01 00:34:06 +00:00
2020-05-17 01:39:23 +00:00
// tile info button
TB_Top . VSplitLeft ( 40.0f , & Button , & TB_Top ) ;
static int s_TileInfoButton = 0 ;
if ( DoButton_Editor ( & s_TileInfoButton , " Info " , m_ShowTileInfo , & Button , 0 , " [ctrl+i] Show tile information " ) | |
2021-12-18 11:23:20 +00:00
( Input ( ) - > KeyPress ( KEY_I ) & & ModPressed ) )
2020-05-17 01:39:23 +00:00
{
m_ShowTileInfo = ! m_ShowTileInfo ;
m_ShowEnvelopePreview = 0 ;
}
2011-02-18 10:41:27 +00:00
2022-06-13 16:28:13 +00:00
TB_Top . VSplitLeft ( 5.0f , nullptr , & TB_Top ) ;
2016-04-29 14:53:19 +00:00
2020-05-17 01:39:23 +00:00
// allow place unused tiles button
TB_Top . VSplitLeft ( 40.0f , & Button , & TB_Top ) ;
static int s_AllowPlaceUnusedTilesButton = 0 ;
if ( DoButton_Editor ( & s_AllowPlaceUnusedTilesButton , " Unused " , m_AllowPlaceUnusedTiles , & Button , 0 , " [ctrl+u] Allow placing unused tiles " ) | |
2021-12-18 11:23:20 +00:00
( Input ( ) - > KeyPress ( KEY_U ) & & ModPressed ) )
2020-05-17 01:39:23 +00:00
{
m_AllowPlaceUnusedTiles = ! m_AllowPlaceUnusedTiles ;
}
2016-04-29 14:53:19 +00:00
2022-06-13 16:28:13 +00:00
TB_Top . VSplitLeft ( 5.0f , nullptr , & TB_Top ) ;
2018-09-11 08:35:02 +00:00
2020-05-17 01:39:23 +00:00
TB_Top . VSplitLeft ( 40.0f , & Button , & TB_Top ) ;
static int s_ColorBrushButton = 0 ;
if ( DoButton_Editor ( & s_ColorBrushButton , " Color " , m_BrushColorEnabled , & Button , 0 , " Toggle brush coloring " ) )
{
m_BrushColorEnabled = ! m_BrushColorEnabled ;
}
2018-09-11 08:35:02 +00:00
2022-06-13 16:28:13 +00:00
TB_Top . VSplitLeft ( 5.0f , nullptr , & TB_Top ) ;
2018-10-01 21:04:43 +00:00
2020-05-17 01:39:23 +00:00
TB_Top . VSplitLeft ( 45.0f , & Button , & TB_Top ) ;
2021-05-17 07:11:36 +00:00
static int s_EntitiesButtonID = 0 ;
if ( DoButton_Editor ( & s_EntitiesButtonID , " Entities " , 0 , & Button , 0 , " Choose game layer entities image for different gametypes " ) )
2020-09-26 19:41:58 +00:00
{
2022-06-11 19:38:18 +00:00
m_vSelectEntitiesFiles . clear ( ) ;
2020-05-17 01:39:23 +00:00
Storage ( ) - > ListDirectory ( IStorage : : TYPE_ALL , " editor/entities " , EntitiesListdirCallback , this ) ;
2022-06-11 19:38:18 +00:00
std : : sort ( m_vSelectEntitiesFiles . begin ( ) , m_vSelectEntitiesFiles . end ( ) ) ;
2018-10-02 21:08:17 +00:00
2020-05-17 01:39:23 +00:00
static int s_EntitiesPopupID = 0 ;
2020-09-26 19:41:58 +00:00
UiInvokePopupMenu ( & s_EntitiesPopupID , 0 , Button . x , Button . y + 18.0f ,
2022-06-11 19:38:18 +00:00
250 , m_vSelectEntitiesFiles . size ( ) * 14 + 10 , PopupEntities ) ;
2020-05-17 01:39:23 +00:00
}
2018-10-01 21:04:43 +00:00
2022-06-13 16:28:13 +00:00
TB_Top . VSplitLeft ( 5.0f , nullptr , & TB_Top ) ;
2010-05-29 07:25:38 +00:00
2020-05-17 01:39:23 +00:00
// zoom group
TB_Top . VSplitLeft ( 30.0f , & Button , & TB_Top ) ;
static int s_ZoomOutButton = 0 ;
if ( DoButton_Ex ( & s_ZoomOutButton , " ZO " , 0 , & Button , 0 , " [NumPad-] Zoom out " , CUI : : CORNER_L ) )
m_ZoomLevel + = 50 ;
2010-05-29 07:25:38 +00:00
2020-05-17 01:39:23 +00:00
TB_Top . VSplitLeft ( 30.0f , & Button , & TB_Top ) ;
static int s_ZoomNormalButton = 0 ;
if ( DoButton_Ex ( & s_ZoomNormalButton , " 1:1 " , 0 , & Button , 0 , " [NumPad*] Zoom to normal and remove editor offset " , 0 ) )
{
m_EditorOffsetX = 0 ;
m_EditorOffsetY = 0 ;
m_ZoomLevel = 100 ;
}
2010-05-29 07:25:38 +00:00
2020-05-17 01:39:23 +00:00
TB_Top . VSplitLeft ( 30.0f , & Button , & TB_Top ) ;
static int s_ZoomInButton = 0 ;
if ( DoButton_Ex ( & s_ZoomInButton , " ZI " , 0 , & Button , 0 , " [NumPad+] Zoom in " , CUI : : CORNER_R ) )
m_ZoomLevel - = 50 ;
2010-05-29 07:25:38 +00:00
2022-06-13 16:28:13 +00:00
TB_Top . VSplitLeft ( 5.0f , nullptr , & TB_Top ) ;
2010-05-29 07:25:38 +00:00
2020-05-17 01:39:23 +00:00
// brush manipulation
{
int Enabled = m_Brush . IsEmpty ( ) ? - 1 : 0 ;
2010-05-29 07:25:38 +00:00
2020-05-17 01:39:23 +00:00
// flip buttons
TB_Top . VSplitLeft ( 30.0f , & Button , & TB_Top ) ;
static int s_FlipXButton = 0 ;
if ( DoButton_Ex ( & s_FlipXButton , " X/X " , Enabled , & Button , 0 , " [N] Flip brush horizontal " , CUI : : CORNER_L ) | | ( Input ( ) - > KeyPress ( KEY_N ) & & m_Dialog = = DIALOG_NONE & & m_EditBoxActive = = 0 ) )
{
2022-06-11 19:38:18 +00:00
for ( auto & pLayer : m_Brush . m_vpLayers )
2022-05-24 09:24:33 +00:00
pLayer - > BrushFlipX ( ) ;
2020-05-17 01:39:23 +00:00
}
2010-05-29 07:25:38 +00:00
2020-05-17 01:39:23 +00:00
TB_Top . VSplitLeft ( 30.0f , & Button , & TB_Top ) ;
static int s_FlipyButton = 0 ;
if ( DoButton_Ex ( & s_FlipyButton , " Y/Y " , Enabled , & Button , 0 , " [M] Flip brush vertical " , CUI : : CORNER_R ) | | ( Input ( ) - > KeyPress ( KEY_M ) & & m_Dialog = = DIALOG_NONE & & m_EditBoxActive = = 0 ) )
{
2022-06-11 19:38:18 +00:00
for ( auto & pLayer : m_Brush . m_vpLayers )
2022-05-24 09:24:33 +00:00
pLayer - > BrushFlipY ( ) ;
2020-05-17 01:39:23 +00:00
}
2008-01-12 12:27:55 +00:00
2020-05-17 01:39:23 +00:00
// rotate buttons
TB_Top . VSplitLeft ( 30.0f , & Button , & TB_Top ) ;
static int s_RotationAmount = 90 ;
bool TileLayer = false ;
// check for tile layers in brush selection
2022-06-11 19:38:18 +00:00
for ( auto & pLayer : m_Brush . m_vpLayers )
2022-05-24 09:24:33 +00:00
if ( pLayer - > m_Type = = LAYERTYPE_TILES )
2020-05-17 01:39:23 +00:00
{
TileLayer = true ;
2020-09-26 19:41:58 +00:00
s_RotationAmount = maximum ( 90 , ( s_RotationAmount / 90 ) * 90 ) ;
2020-05-17 01:39:23 +00:00
break ;
}
s_RotationAmount = UiDoValueSelector ( & s_RotationAmount , & Button , " " , s_RotationAmount , TileLayer ? 90 : 1 , 359 , TileLayer ? 90 : 1 , TileLayer ? 10.0f : 2.0f , " Rotation of the brush in degrees. Use left mouse button to drag and change the value. Hold shift to be more precise. " , true ) ;
2008-01-12 12:27:55 +00:00
2020-05-17 01:39:23 +00:00
TB_Top . VSplitLeft ( 30.0f , & Button , & TB_Top ) ;
static int s_CcwButton = 0 ;
if ( DoButton_Ex ( & s_CcwButton , " CCW " , Enabled , & Button , 0 , " [R] Rotates the brush counter clockwise " , CUI : : CORNER_L ) | | ( Input ( ) - > KeyPress ( KEY_R ) & & m_Dialog = = DIALOG_NONE & & m_EditBoxActive = = 0 ) )
{
2022-06-11 19:38:18 +00:00
for ( auto & pLayer : m_Brush . m_vpLayers )
2022-05-24 09:24:33 +00:00
pLayer - > BrushRotate ( - s_RotationAmount / 360.0f * pi * 2 ) ;
2020-05-17 01:39:23 +00:00
}
2008-01-12 12:27:55 +00:00
2020-05-17 01:39:23 +00:00
TB_Top . VSplitLeft ( 30.0f , & Button , & TB_Top ) ;
static int s_CwButton = 0 ;
if ( DoButton_Ex ( & s_CwButton , " CW " , Enabled , & Button , 0 , " [T] Rotates the brush clockwise " , CUI : : CORNER_R ) | | ( Input ( ) - > KeyPress ( KEY_T ) & & m_Dialog = = DIALOG_NONE & & m_EditBoxActive = = 0 ) )
{
2022-06-11 19:38:18 +00:00
for ( auto & pLayer : m_Brush . m_vpLayers )
2022-05-24 09:24:33 +00:00
pLayer - > BrushRotate ( s_RotationAmount / 360.0f * pi * 2 ) ;
2020-05-17 01:39:23 +00:00
}
2010-05-29 07:25:38 +00:00
2020-05-17 01:39:23 +00:00
TB_Top . VSplitLeft ( 5.0f , & Button , & TB_Top ) ;
2008-01-12 12:27:55 +00:00
}
2010-05-29 07:25:38 +00:00
2020-05-17 01:39:23 +00:00
// animation speed
if ( m_Animate )
2008-01-12 12:27:55 +00:00
{
2020-05-17 01:39:23 +00:00
TB_Top . VSplitLeft ( 30.0f , & Button , & TB_Top ) ;
static int s_AnimFasterButton = 0 ;
if ( DoButton_Ex ( & s_AnimFasterButton , " A+ " , 0 , & Button , 0 , " Increase animation speed " , CUI : : CORNER_L ) )
m_AnimateSpeed + = 0.5f ;
TB_Top . VSplitLeft ( 30.0f , & Button , & TB_Top ) ;
static int s_AnimNormalButton = 0 ;
if ( DoButton_Ex ( & s_AnimNormalButton , " 1 " , 0 , & Button , 0 , " Normal animation speed " , 0 ) )
m_AnimateSpeed = 1.0f ;
TB_Top . VSplitLeft ( 30.0f , & Button , & TB_Top ) ;
static int s_AnimSlowerButton = 0 ;
if ( DoButton_Ex ( & s_AnimSlowerButton , " A- " , 0 , & Button , 0 , " Decrease animation speed " , CUI : : CORNER_R ) )
2010-09-27 19:41:41 +00:00
{
2020-05-17 01:39:23 +00:00
if ( m_AnimateSpeed > 0.5f )
m_AnimateSpeed - = 0.5f ;
2010-09-27 19:41:41 +00:00
}
2010-05-29 07:25:38 +00:00
2020-05-17 01:39:23 +00:00
TB_Top . VSplitLeft ( 5.0f , & Button , & TB_Top ) ;
2008-02-05 19:11:34 +00:00
}
2010-05-29 07:25:38 +00:00
2020-05-17 01:39:23 +00:00
// grid zoom
if ( m_GridActive )
2008-02-05 19:11:34 +00:00
{
2020-05-17 01:39:23 +00:00
TB_Top . VSplitLeft ( 30.0f , & Button , & TB_Top ) ;
static int s_GridIncreaseButton = 0 ;
if ( DoButton_Ex ( & s_GridIncreaseButton , " G- " , 0 , & Button , 0 , " Decrease grid " , CUI : : CORNER_L ) )
{
if ( m_GridFactor > 1 )
m_GridFactor - - ;
}
2008-01-12 12:27:55 +00:00
2020-05-17 01:39:23 +00:00
TB_Top . VSplitLeft ( 30.0f , & Button , & TB_Top ) ;
static int s_GridNormalButton = 0 ;
if ( DoButton_Ex ( & s_GridNormalButton , " 1 " , 0 , & Button , 0 , " Normal grid " , 0 ) )
m_GridFactor = 1 ;
TB_Top . VSplitLeft ( 30.0f , & Button , & TB_Top ) ;
static int s_GridDecreaseButton = 0 ;
if ( DoButton_Ex ( & s_GridDecreaseButton , " G+ " , 0 , & Button , 0 , " Increase grid " , CUI : : CORNER_R ) )
{
if ( m_GridFactor < 15 )
m_GridFactor + + ;
}
TB_Top . VSplitLeft ( 5.0f , & Button , & TB_Top ) ;
2020-05-15 16:51:14 +00:00
}
2008-01-12 12:27:55 +00:00
}
2011-08-11 08:59:14 +00:00
2020-05-17 01:39:23 +00:00
// Bottom line buttons
2010-05-29 07:25:38 +00:00
{
2020-05-17 01:39:23 +00:00
// refocus button
2010-05-29 07:25:38 +00:00
{
2020-05-17 01:39:23 +00:00
TB_Bottom . VSplitLeft ( 45.0f , & Button , & TB_Bottom ) ;
static int s_RefocusButton = 0 ;
2020-09-26 19:41:58 +00:00
if ( DoButton_Editor ( & s_RefocusButton , " Refocus " , m_WorldOffsetX & & m_WorldOffsetY ? 0 : - 1 , & Button , 0 , " [HOME] Restore map focus " ) | | ( m_EditBoxActive = = 0 & & Input ( ) - > KeyPress ( KEY_HOME ) ) )
2020-05-15 16:51:14 +00:00
{
2020-05-17 01:39:23 +00:00
m_WorldOffsetX = 0 ;
m_WorldOffsetY = 0 ;
2020-05-15 16:51:14 +00:00
}
2022-06-13 16:28:13 +00:00
TB_Bottom . VSplitLeft ( 5.0f , nullptr , & TB_Bottom ) ;
2010-05-29 07:25:38 +00:00
}
2016-05-01 00:34:06 +00:00
2020-05-17 01:39:23 +00:00
// tile manipulation
2010-09-30 21:31:19 +00:00
{
2020-05-17 01:39:23 +00:00
static int s_BorderBut = 0 ;
CLayerTiles * pT = ( CLayerTiles * ) GetSelectedLayerType ( 0 , LAYERTYPE_TILES ) ;
// no border for tele layer, speedup, front and switch
if ( pT & & ( pT - > m_Tele | | pT - > m_Speedup | | pT - > m_Switch | | pT - > m_Front | | pT - > m_Tune ) )
2022-06-13 16:28:13 +00:00
pT = nullptr ;
2020-05-17 01:39:23 +00:00
if ( pT )
2016-05-15 15:05:21 +00:00
{
2020-05-17 01:39:23 +00:00
TB_Bottom . VSplitLeft ( 60.0f , & Button , & TB_Bottom ) ;
2020-09-20 00:24:17 +00:00
if ( DoButton_Ex ( & s_BorderBut , " Border " , 0 , & Button , 0 , " Place tiles in a 2-tile wide border at the edges of the layer " , CUI : : CORNER_ALL ) )
2020-05-15 16:51:14 +00:00
{
2020-09-20 00:24:17 +00:00
m_PopupEventType = POPEVENT_PLACE_BORDER_TILES ;
m_PopupEventActivated = true ;
2016-05-15 15:05:21 +00:00
}
2020-05-17 01:39:23 +00:00
TB_Bottom . VSplitLeft ( 5.0f , & Button , & TB_Bottom ) ;
}
2020-05-15 16:51:14 +00:00
2020-05-17 01:39:23 +00:00
// do tele/tune/switch/speedup button
{
2022-06-13 16:28:13 +00:00
int ( * pPopupFunc ) ( CEditor * peditor , CUIRect View , void * pContext ) = nullptr ;
2022-06-30 22:36:32 +00:00
const char * pButtonName = nullptr ;
2020-05-17 01:39:23 +00:00
float Height = 0.0f ;
CLayerTiles * pS = ( CLayerTiles * ) GetSelectedLayerType ( 0 , LAYERTYPE_TILES ) ;
if ( pS )
2016-05-15 15:05:21 +00:00
{
2020-05-17 01:39:23 +00:00
if ( pS = = m_Map . m_pSwitchLayer )
{
2022-06-30 22:36:32 +00:00
pButtonName = " Switch " ;
2020-05-17 01:39:23 +00:00
pPopupFunc = PopupSwitch ;
Height = 36 ;
}
else if ( pS = = m_Map . m_pSpeedupLayer )
{
2022-06-30 22:36:32 +00:00
pButtonName = " Speedup " ;
2020-05-17 01:39:23 +00:00
pPopupFunc = PopupSpeedup ;
Height = 53 ;
}
else if ( pS = = m_Map . m_pTuneLayer )
{
2022-06-30 22:36:32 +00:00
pButtonName = " Tune " ;
2020-05-17 01:39:23 +00:00
pPopupFunc = PopupTune ;
Height = 23 ;
}
else if ( pS = = m_Map . m_pTeleLayer )
{
2022-06-30 22:36:32 +00:00
pButtonName = " Tele " ;
2020-05-17 01:39:23 +00:00
pPopupFunc = PopupTele ;
Height = 23 ;
}
2020-05-15 19:53:26 +00:00
2022-06-30 22:36:32 +00:00
if ( pButtonName ! = nullptr )
2020-05-15 16:51:14 +00:00
{
2020-05-17 01:39:23 +00:00
static char aBuf [ 64 ] ;
2022-06-30 22:36:32 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " [ctrl+a] %s " , pButtonName ) ;
2020-05-17 01:39:23 +00:00
TB_Bottom . VSplitLeft ( 60.0f , & Button , & TB_Bottom ) ;
static int s_ModifierButton = 0 ;
2022-06-30 22:36:32 +00:00
if ( DoButton_Ex ( & s_ModifierButton , pButtonName , 0 , & Button , 0 , aBuf , CUI : : CORNER_ALL ) | | ( ModPressed & & Input ( ) - > KeyPress ( KEY_A ) ) )
2020-05-15 19:53:26 +00:00
{
2020-05-17 01:39:23 +00:00
static int s_ModifierPopupID = 0 ;
if ( ! UiPopupExists ( & s_ModifierPopupID ) )
{
UiInvokePopupMenu ( & s_ModifierPopupID , 0 , Button . x , Button . y + Button . h , 120 , Height , pPopupFunc ) ;
}
2020-05-15 19:53:26 +00:00
}
2022-06-13 16:28:13 +00:00
TB_Bottom . VSplitLeft ( 5.0f , nullptr , & TB_Bottom ) ;
2020-05-15 16:51:14 +00:00
}
2016-05-15 15:05:21 +00:00
}
}
2014-03-12 22:57:00 +00:00
}
2015-04-21 02:34:14 +00:00
2020-05-17 01:39:23 +00:00
// do add quad/sound button
CLayer * pLayer = GetSelectedLayer ( 0 ) ;
if ( pLayer & & ( pLayer - > m_Type = = LAYERTYPE_QUADS | | pLayer - > m_Type = = LAYERTYPE_SOUNDS ) )
2015-04-21 02:34:14 +00:00
{
2020-05-17 01:39:23 +00:00
TB_Bottom . VSplitLeft ( 60.0f , & Button , & TB_Bottom ) ;
2019-03-28 12:41:07 +00:00
2020-05-19 16:17:02 +00:00
bool Invoked = false ;
2020-05-17 01:39:23 +00:00
static int s_AddItemButton = 0 ;
2016-05-01 00:34:06 +00:00
2020-05-17 01:39:23 +00:00
if ( pLayer - > m_Type = = LAYERTYPE_QUADS )
2020-05-15 16:51:14 +00:00
{
2020-05-19 16:17:02 +00:00
Invoked = DoButton_Editor ( & s_AddItemButton , " Add Quad " , 0 , & Button , 0 , " [ctrl+q] Add a new quad " ) | |
2021-12-18 11:23:20 +00:00
( Input ( ) - > KeyPress ( KEY_Q ) & & ModPressed ) ;
2020-05-17 01:39:23 +00:00
}
else if ( pLayer - > m_Type = = LAYERTYPE_SOUNDS )
{
2020-05-19 16:17:02 +00:00
Invoked = DoButton_Editor ( & s_AddItemButton , " Add Sound " , 0 , & Button , 0 , " [ctrl+q] Add a new sound source " ) | |
2021-12-18 11:23:20 +00:00
( Input ( ) - > KeyPress ( KEY_Q ) & & ModPressed ) ;
2020-05-15 16:51:14 +00:00
}
2019-03-28 12:41:07 +00:00
2020-05-19 16:17:02 +00:00
if ( Invoked )
2020-05-15 16:51:14 +00:00
{
2020-05-17 01:39:23 +00:00
CLayerGroup * pGroup = GetSelectedGroup ( ) ;
2019-03-28 12:41:07 +00:00
2022-06-30 22:36:32 +00:00
float aMapping [ 4 ] ;
pGroup - > Mapping ( aMapping ) ;
int x = aMapping [ 0 ] + ( aMapping [ 2 ] - aMapping [ 0 ] ) / 2 ;
int y = aMapping [ 1 ] + ( aMapping [ 3 ] - aMapping [ 1 ] ) / 2 ;
2021-12-18 11:23:20 +00:00
if ( Input ( ) - > KeyPress ( KEY_Q ) & & ModPressed )
2016-05-01 00:34:06 +00:00
{
2020-09-26 19:41:58 +00:00
x + = UI ( ) - > MouseWorldX ( ) - ( m_WorldOffsetX * pGroup - > m_ParallaxX / 100 ) - pGroup - > m_OffsetX ;
y + = UI ( ) - > MouseWorldY ( ) - ( m_WorldOffsetY * pGroup - > m_ParallaxY / 100 ) - pGroup - > m_OffsetY ;
2016-05-01 00:34:06 +00:00
}
2020-05-15 16:51:14 +00:00
2020-05-17 01:39:23 +00:00
if ( pLayer - > m_Type = = LAYERTYPE_QUADS )
{
2022-05-24 09:24:33 +00:00
CLayerQuads * pLayerQuads = ( CLayerQuads * ) pLayer ;
2020-05-17 01:39:23 +00:00
int Width = 64 ;
int Height = 64 ;
2022-05-24 09:24:33 +00:00
if ( pLayerQuads - > m_Image > = 0 )
2020-05-17 01:39:23 +00:00
{
2022-06-11 19:38:18 +00:00
Width = m_Map . m_vpImages [ pLayerQuads - > m_Image ] - > m_Width ;
Height = m_Map . m_vpImages [ pLayerQuads - > m_Image ] - > m_Height ;
2020-05-17 01:39:23 +00:00
}
2022-05-24 09:24:33 +00:00
pLayerQuads - > NewQuad ( x , y , Width , Height ) ;
2020-05-17 01:39:23 +00:00
}
else if ( pLayer - > m_Type = = LAYERTYPE_SOUNDS )
{
2022-05-24 09:24:33 +00:00
CLayerSounds * pLayerSounds = ( CLayerSounds * ) pLayer ;
pLayerSounds - > NewSource ( x , y ) ;
2020-05-17 01:39:23 +00:00
}
2016-05-01 00:34:06 +00:00
}
2020-05-17 01:39:23 +00:00
TB_Bottom . VSplitLeft ( 5.0f , & Button , & TB_Bottom ) ;
2016-05-01 00:34:06 +00:00
}
2020-05-17 01:39:23 +00:00
// Brush draw mode button
{
TB_Bottom . VSplitLeft ( 65.0f , & Button , & TB_Bottom ) ;
static int s_BrushDrawModeButton = 0 ;
if ( DoButton_Editor ( & s_BrushDrawModeButton , " Destructive " , m_BrushDrawDestructive , & Button , 0 , " [ctrl+d] Toggle brush draw mode " ) | |
2021-12-18 11:23:20 +00:00
( Input ( ) - > KeyPress ( KEY_D ) & & ModPressed & & ! ShiftPressed ) )
2020-05-17 01:39:23 +00:00
m_BrushDrawDestructive = ! m_BrushDrawDestructive ;
TB_Bottom . VSplitLeft ( 5.0f , & Button , & TB_Bottom ) ;
}
2020-05-15 16:51:14 +00:00
}
2007-05-22 15:03:32 +00:00
}
2012-10-21 12:49:26 +00:00
static void Rotate ( const CPoint * pCenter , CPoint * pPoint , float Rotation )
2007-07-15 13:25:10 +00:00
{
2010-05-29 07:25:38 +00:00
int x = pPoint - > x - pCenter - > x ;
int y = pPoint - > y - pCenter - > y ;
pPoint - > x = ( int ) ( x * cosf ( Rotation ) - y * sinf ( Rotation ) + pCenter - > x ) ;
pPoint - > y = ( int ) ( x * sinf ( Rotation ) + y * cosf ( Rotation ) + pCenter - > y ) ;
2007-07-15 13:25:10 +00:00
}
2014-10-10 17:11:21 +00:00
void CEditor : : DoSoundSource ( CSoundSource * pSource , int Index )
{
enum
{
2020-09-26 19:41:58 +00:00
OP_NONE = 0 ,
2014-10-10 17:11:21 +00:00
OP_MOVE ,
OP_CONTEXT_MENU ,
} ;
void * pID = & pSource - > m_Position ;
static int s_Operation = OP_NONE ;
float wx = UI ( ) - > MouseWorldX ( ) ;
float wy = UI ( ) - > MouseWorldY ( ) ;
float CenterX = fx2f ( pSource - > m_Position . x ) ;
float CenterY = fx2f ( pSource - > m_Position . y ) ;
2022-08-06 15:33:58 +00:00
float dx = ( CenterX - wx ) / m_MouseWScale ;
float dy = ( CenterY - wy ) / m_MouseWScale ;
2020-09-26 19:41:58 +00:00
if ( dx * dx + dy * dy < 50 )
2014-10-10 17:11:21 +00:00
UI ( ) - > SetHotItem ( pID ) ;
bool IgnoreGrid ;
2022-01-22 16:34:23 +00:00
IgnoreGrid = Input ( ) - > KeyIsPressed ( KEY_LALT ) | | Input ( ) - > KeyIsPressed ( KEY_RALT ) ;
2014-10-10 17:11:21 +00:00
2022-05-27 08:55:32 +00:00
if ( UI ( ) - > CheckActiveItem ( pID ) )
2014-10-10 17:11:21 +00:00
{
2021-01-02 12:49:16 +00:00
if ( m_MouseDeltaWx * m_MouseDeltaWx + m_MouseDeltaWy * m_MouseDeltaWy > 0.0f )
2014-10-10 17:11:21 +00:00
{
if ( s_Operation = = OP_MOVE )
{
if ( m_GridActive & & ! IgnoreGrid )
{
int LineDistance = GetLineDistance ( ) ;
float x = 0.0f ;
float y = 0.0f ;
if ( wx > = 0 )
2020-09-26 19:41:58 +00:00
x = ( int ) ( ( wx + ( LineDistance / 2 ) * m_GridFactor ) / ( LineDistance * m_GridFactor ) ) * ( LineDistance * m_GridFactor ) ;
2014-10-10 17:11:21 +00:00
else
2020-09-26 19:41:58 +00:00
x = ( int ) ( ( wx - ( LineDistance / 2 ) * m_GridFactor ) / ( LineDistance * m_GridFactor ) ) * ( LineDistance * m_GridFactor ) ;
2014-10-10 17:11:21 +00:00
if ( wy > = 0 )
2020-09-26 19:41:58 +00:00
y = ( int ) ( ( wy + ( LineDistance / 2 ) * m_GridFactor ) / ( LineDistance * m_GridFactor ) ) * ( LineDistance * m_GridFactor ) ;
2014-10-10 17:11:21 +00:00
else
2020-09-26 19:41:58 +00:00
y = ( int ) ( ( wy - ( LineDistance / 2 ) * m_GridFactor ) / ( LineDistance * m_GridFactor ) ) * ( LineDistance * m_GridFactor ) ;
2014-10-10 17:11:21 +00:00
pSource - > m_Position . x = f2fx ( x ) ;
pSource - > m_Position . y = f2fx ( y ) ;
}
else
{
2018-10-01 19:12:14 +00:00
pSource - > m_Position . x = f2fx ( wx ) ;
pSource - > m_Position . y = f2fx ( wy ) ;
2014-10-10 17:11:21 +00:00
}
}
}
if ( s_Operation = = OP_CONTEXT_MENU )
{
if ( ! UI ( ) - > MouseButton ( 1 ) )
{
2022-06-11 19:38:18 +00:00
if ( m_vSelectedLayers . size ( ) = = 1 )
2018-07-26 08:14:14 +00:00
{
static int s_SourcePopupID = 0 ;
2020-01-23 20:24:48 +00:00
UiInvokePopupMenu ( & s_SourcePopupID , 0 , UI ( ) - > MouseX ( ) , UI ( ) - > MouseY ( ) , 120 , 200 , PopupSource ) ;
2021-10-23 11:48:21 +00:00
m_LockMouse = false ;
2018-07-26 08:14:14 +00:00
}
2014-10-10 17:11:21 +00:00
s_Operation = OP_NONE ;
2022-05-27 09:59:14 +00:00
UI ( ) - > SetActiveItem ( nullptr ) ;
2014-10-10 17:11:21 +00:00
}
}
else
{
if ( ! UI ( ) - > MouseButton ( 0 ) )
{
2021-10-23 11:48:21 +00:00
m_LockMouse = false ;
2014-10-10 17:11:21 +00:00
s_Operation = OP_NONE ;
2022-05-27 09:59:14 +00:00
UI ( ) - > SetActiveItem ( nullptr ) ;
2014-10-10 17:11:21 +00:00
}
}
2020-09-26 19:41:58 +00:00
Graphics ( ) - > SetColor ( 1 , 1 , 1 , 1 ) ;
2014-10-10 17:11:21 +00:00
}
else if ( UI ( ) - > HotItem ( ) = = pID )
{
ms_pUiGotContext = pID ;
2020-09-26 19:41:58 +00:00
Graphics ( ) - > SetColor ( 1 , 1 , 1 , 1 ) ;
2014-10-10 17:11:21 +00:00
m_pTooltip = " Left mouse button to move. Hold alt to ignore grid. " ;
if ( UI ( ) - > MouseButton ( 0 ) )
{
s_Operation = OP_MOVE ;
UI ( ) - > SetActiveItem ( pID ) ;
m_SelectedSource = Index ;
}
if ( UI ( ) - > MouseButton ( 1 ) )
{
m_SelectedSource = Index ;
s_Operation = OP_CONTEXT_MENU ;
UI ( ) - > SetActiveItem ( pID ) ;
}
}
else
{
2020-09-26 19:41:58 +00:00
Graphics ( ) - > SetColor ( 0 , 1 , 0 , 1 ) ;
2014-10-10 17:11:21 +00:00
}
2022-08-06 15:33:58 +00:00
IGraphics : : CQuadItem QuadItem ( CenterX , CenterY , 5.0f * m_MouseWScale , 5.0f * m_MouseWScale ) ;
2014-10-10 17:11:21 +00:00
Graphics ( ) - > QuadsDraw ( & QuadItem , 1 ) ;
}
2022-01-22 13:12:59 +00:00
void CEditor : : DoQuad ( CQuad * pQuad , int Index )
2007-05-22 15:03:32 +00:00
{
2008-01-12 12:27:55 +00:00
enum
{
2020-09-26 19:41:58 +00:00
OP_NONE = 0 ,
2008-01-12 12:27:55 +00:00
OP_MOVE_ALL ,
OP_MOVE_PIVOT ,
OP_ROTATE ,
2008-01-17 23:09:49 +00:00
OP_CONTEXT_MENU ,
2014-10-23 13:55:50 +00:00
OP_DELETE ,
2008-01-12 12:27:55 +00:00
} ;
2010-05-29 07:25:38 +00:00
2008-01-12 12:27:55 +00:00
// some basic values
2022-01-22 13:12:59 +00:00
void * pID = & pQuad - > m_aPoints [ 4 ] ; // use pivot addr as id
2022-06-15 17:34:41 +00:00
static std : : vector < std : : vector < CPoint > > s_vvRotatePoints ;
2010-05-29 07:25:38 +00:00
static int s_Operation = OP_NONE ;
static float s_RotateAngle = 0 ;
2009-10-27 14:38:53 +00:00
float wx = UI ( ) - > MouseWorldX ( ) ;
float wy = UI ( ) - > MouseWorldY ( ) ;
2010-05-29 07:25:38 +00:00
2008-01-12 12:27:55 +00:00
// get pivot
2022-01-22 13:12:59 +00:00
float CenterX = fx2f ( pQuad - > m_aPoints [ 4 ] . x ) ;
float CenterY = fx2f ( pQuad - > m_aPoints [ 4 ] . y ) ;
2008-01-12 12:27:55 +00:00
2022-08-06 15:33:58 +00:00
float dx = ( CenterX - wx ) / m_MouseWScale ;
float dy = ( CenterY - wy ) / m_MouseWScale ;
2020-09-26 19:41:58 +00:00
if ( dx * dx + dy * dy < 50 )
2011-02-12 10:40:36 +00:00
UI ( ) - > SetHotItem ( pID ) ;
2008-01-12 12:27:55 +00:00
2022-06-28 20:06:24 +00:00
const bool IgnoreGrid = Input ( ) - > KeyIsPressed ( KEY_LALT ) | | Input ( ) - > KeyIsPressed ( KEY_RALT ) ;
2011-12-04 17:11:56 +00:00
2010-05-29 07:25:38 +00:00
// draw selection background
2018-08-13 09:11:56 +00:00
if ( IsQuadSelected ( Index ) )
2007-05-22 15:03:32 +00:00
{
2020-09-26 19:41:58 +00:00
Graphics ( ) - > SetColor ( 0 , 0 , 0 , 1 ) ;
2022-08-06 15:33:58 +00:00
IGraphics : : CQuadItem QuadItem ( CenterX , CenterY , 7.0f * m_MouseWScale , 7.0f * m_MouseWScale ) ;
2010-05-29 07:25:38 +00:00
Graphics ( ) - > QuadsDraw ( & QuadItem , 1 ) ;
2007-05-22 15:03:32 +00:00
}
2010-05-29 07:25:38 +00:00
2022-05-27 08:55:32 +00:00
if ( UI ( ) - > CheckActiveItem ( pID ) )
2007-05-22 15:03:32 +00:00
{
2021-01-02 12:49:16 +00:00
if ( m_MouseDeltaWx * m_MouseDeltaWx + m_MouseDeltaWy * m_MouseDeltaWy > 0.0f )
2008-01-12 12:27:55 +00:00
{
2011-08-04 21:34:29 +00:00
// check if we only should move pivot
if ( s_Operation = = OP_MOVE_PIVOT )
2008-01-12 12:27:55 +00:00
{
2011-12-04 17:11:56 +00:00
if ( m_GridActive & & ! IgnoreGrid )
2011-08-04 21:34:29 +00:00
{
int LineDistance = GetLineDistance ( ) ;
2011-07-10 20:16:16 +00:00
2011-08-04 21:34:29 +00:00
float x = 0.0f ;
float y = 0.0f ;
if ( wx > = 0 )
2020-09-26 19:41:58 +00:00
x = ( int ) ( ( wx + ( LineDistance / 2 ) * m_GridFactor ) / ( LineDistance * m_GridFactor ) ) * ( LineDistance * m_GridFactor ) ;
2011-08-04 21:34:29 +00:00
else
2020-09-26 19:41:58 +00:00
x = ( int ) ( ( wx - ( LineDistance / 2 ) * m_GridFactor ) / ( LineDistance * m_GridFactor ) ) * ( LineDistance * m_GridFactor ) ;
2011-08-04 21:34:29 +00:00
if ( wy > = 0 )
2020-09-26 19:41:58 +00:00
y = ( int ) ( ( wy + ( LineDistance / 2 ) * m_GridFactor ) / ( LineDistance * m_GridFactor ) ) * ( LineDistance * m_GridFactor ) ;
2011-08-04 21:34:29 +00:00
else
2020-09-26 19:41:58 +00:00
y = ( int ) ( ( wy - ( LineDistance / 2 ) * m_GridFactor ) / ( LineDistance * m_GridFactor ) ) * ( LineDistance * m_GridFactor ) ;
2011-08-04 21:34:29 +00:00
2022-01-22 13:12:59 +00:00
pQuad - > m_aPoints [ 4 ] . x = f2fx ( x ) ;
pQuad - > m_aPoints [ 4 ] . y = f2fx ( y ) ;
2011-08-04 21:34:29 +00:00
}
2011-07-10 20:16:16 +00:00
else
{
2022-01-22 13:12:59 +00:00
pQuad - > m_aPoints [ 4 ] . x = f2fx ( wx ) ;
pQuad - > m_aPoints [ 4 ] . y = f2fx ( wy ) ;
2011-07-10 20:16:16 +00:00
}
}
2011-08-04 21:34:29 +00:00
else if ( s_Operation = = OP_MOVE_ALL )
2008-01-12 12:27:55 +00:00
{
2018-08-13 09:11:56 +00:00
CLayerQuads * pLayer = ( CLayerQuads * ) GetSelectedLayerType ( 0 , LAYERTYPE_QUADS ) ;
2011-08-04 21:34:29 +00:00
// move all points including pivot
2011-12-04 17:11:56 +00:00
if ( m_GridActive & & ! IgnoreGrid )
2011-08-04 21:34:29 +00:00
{
int LineDistance = GetLineDistance ( ) ;
float x = 0.0f ;
float y = 0.0f ;
if ( wx > = 0 )
2020-09-26 19:41:58 +00:00
x = ( int ) ( ( wx + ( LineDistance / 2 ) * m_GridFactor ) / ( LineDistance * m_GridFactor ) ) * ( LineDistance * m_GridFactor ) ;
2011-08-04 21:34:29 +00:00
else
2020-09-26 19:41:58 +00:00
x = ( int ) ( ( wx - ( LineDistance / 2 ) * m_GridFactor ) / ( LineDistance * m_GridFactor ) ) * ( LineDistance * m_GridFactor ) ;
2011-08-04 21:34:29 +00:00
if ( wy > = 0 )
2020-09-26 19:41:58 +00:00
y = ( int ) ( ( wy + ( LineDistance / 2 ) * m_GridFactor ) / ( LineDistance * m_GridFactor ) ) * ( LineDistance * m_GridFactor ) ;
2011-08-04 21:34:29 +00:00
else
2020-09-26 19:41:58 +00:00
y = ( int ) ( ( wy - ( LineDistance / 2 ) * m_GridFactor ) / ( LineDistance * m_GridFactor ) ) * ( LineDistance * m_GridFactor ) ;
2011-08-11 08:59:14 +00:00
2022-01-22 13:12:59 +00:00
int OffsetX = f2fx ( x ) - pQuad - > m_aPoints [ 4 ] . x ;
int OffsetY = f2fx ( y ) - pQuad - > m_aPoints [ 4 ] . y ;
2011-08-11 08:59:14 +00:00
2022-06-11 19:38:18 +00:00
for ( auto & Selected : m_vSelectedQuads )
2011-08-04 21:34:29 +00:00
{
2022-06-11 19:38:18 +00:00
CQuad * pCurrentQuad = & pLayer - > m_vQuads [ Selected ] ;
2020-10-26 14:14:07 +00:00
for ( auto & Point : pCurrentQuad - > m_aPoints )
2018-08-13 09:11:56 +00:00
{
2020-10-26 14:14:07 +00:00
Point . x + = OffsetX ;
Point . y + = OffsetY ;
2018-08-13 09:11:56 +00:00
}
2011-08-04 21:34:29 +00:00
}
}
else
2011-07-10 20:16:16 +00:00
{
2022-01-22 13:12:59 +00:00
int OffsetX = f2fx ( wx ) - pQuad - > m_aPoints [ 4 ] . x ;
int OffsetY = f2fx ( wy ) - pQuad - > m_aPoints [ 4 ] . y ;
2018-10-01 19:12:14 +00:00
2022-06-11 19:38:18 +00:00
for ( auto & Selected : m_vSelectedQuads )
2011-08-04 21:34:29 +00:00
{
2022-06-11 19:38:18 +00:00
CQuad * pCurrentQuad = & pLayer - > m_vQuads [ Selected ] ;
2020-10-26 14:14:07 +00:00
for ( auto & Point : pCurrentQuad - > m_aPoints )
2018-08-13 09:11:56 +00:00
{
2020-10-26 14:14:07 +00:00
Point . x + = OffsetX ;
Point . y + = OffsetY ;
2018-08-13 09:11:56 +00:00
}
2011-08-04 21:34:29 +00:00
}
2011-07-10 20:16:16 +00:00
}
2008-01-12 12:27:55 +00:00
}
2011-08-04 21:34:29 +00:00
else if ( s_Operation = = OP_ROTATE )
2008-01-12 12:27:55 +00:00
{
2018-08-13 09:11:56 +00:00
CLayerQuads * pLayer = ( CLayerQuads * ) GetSelectedLayerType ( 0 , LAYERTYPE_QUADS ) ;
2022-06-11 19:38:18 +00:00
for ( size_t i = 0 ; i < m_vSelectedQuads . size ( ) ; + + i )
2011-08-04 21:34:29 +00:00
{
2022-06-11 19:38:18 +00:00
CQuad * pCurrentQuad = & pLayer - > m_vQuads [ m_vSelectedQuads [ i ] ] ;
2018-08-13 09:11:56 +00:00
for ( int v = 0 ; v < 4 ; v + + )
{
2022-06-15 17:34:41 +00:00
pCurrentQuad - > m_aPoints [ v ] = s_vvRotatePoints [ i ] [ v ] ;
2018-08-13 09:11:56 +00:00
Rotate ( & pCurrentQuad - > m_aPoints [ 4 ] , & pCurrentQuad - > m_aPoints [ v ] , s_RotateAngle ) ;
}
2011-08-04 21:34:29 +00:00
}
2008-01-12 12:27:55 +00:00
}
2007-05-22 15:03:32 +00:00
}
2010-05-29 07:25:38 +00:00
2020-09-26 19:41:58 +00:00
s_RotateAngle + = ( m_MouseDeltaX ) * 0.002f ;
2010-05-29 07:25:38 +00:00
if ( s_Operation = = OP_CONTEXT_MENU )
2007-05-22 15:03:32 +00:00
{
2009-10-27 14:38:53 +00:00
if ( ! UI ( ) - > MouseButton ( 1 ) )
2008-01-17 23:09:49 +00:00
{
2022-06-11 19:38:18 +00:00
if ( m_vSelectedLayers . size ( ) = = 1 )
2018-07-26 08:14:14 +00:00
{
2018-08-13 09:11:56 +00:00
m_SelectedQuadIndex = FindSelectedQuadIndex ( Index ) ;
2018-07-26 08:14:14 +00:00
static int s_QuadPopupID = 0 ;
2022-02-26 17:49:06 +00:00
UiInvokePopupMenu ( & s_QuadPopupID , 0 , UI ( ) - > MouseX ( ) , UI ( ) - > MouseY ( ) , 120 , 198 , PopupQuad ) ;
2021-10-23 11:48:21 +00:00
m_LockMouse = false ;
2018-07-26 08:14:14 +00:00
}
2010-05-29 07:25:38 +00:00
s_Operation = OP_NONE ;
2022-05-27 09:59:14 +00:00
UI ( ) - > SetActiveItem ( nullptr ) ;
2008-01-17 23:09:49 +00:00
}
2007-05-22 15:03:32 +00:00
}
2014-10-23 13:55:50 +00:00
else if ( s_Operation = = OP_DELETE )
{
if ( ! UI ( ) - > MouseButton ( 1 ) )
{
2022-06-11 19:38:18 +00:00
if ( m_vSelectedLayers . size ( ) = = 1 )
2018-07-26 08:14:14 +00:00
{
2021-10-23 11:48:21 +00:00
m_LockMouse = false ;
2018-07-26 08:14:14 +00:00
m_Map . m_Modified = true ;
2018-08-13 09:11:56 +00:00
DeleteSelectedQuads ( ) ;
2018-07-26 08:14:14 +00:00
}
2014-10-23 13:55:50 +00:00
s_Operation = OP_NONE ;
2022-05-27 09:59:14 +00:00
UI ( ) - > SetActiveItem ( nullptr ) ;
2014-10-23 13:55:50 +00:00
}
}
2008-01-17 23:09:49 +00:00
else
{
2009-10-27 14:38:53 +00:00
if ( ! UI ( ) - > MouseButton ( 0 ) )
2008-01-17 23:09:49 +00:00
{
2021-10-23 11:48:21 +00:00
m_LockMouse = false ;
2010-05-29 07:25:38 +00:00
s_Operation = OP_NONE ;
2022-05-27 09:59:14 +00:00
UI ( ) - > SetActiveItem ( nullptr ) ;
2008-01-17 23:09:49 +00:00
}
2010-05-29 07:25:38 +00:00
}
2008-01-12 12:27:55 +00:00
2020-09-26 19:41:58 +00:00
Graphics ( ) - > SetColor ( 1 , 1 , 1 , 1 ) ;
2008-01-12 12:27:55 +00:00
}
2011-02-12 10:40:36 +00:00
else if ( UI ( ) - > HotItem ( ) = = pID )
2008-01-12 12:27:55 +00:00
{
2011-02-12 10:40:36 +00:00
ms_pUiGotContext = pID ;
2010-05-29 07:25:38 +00:00
2020-09-26 19:41:58 +00:00
Graphics ( ) - > SetColor ( 1 , 1 , 1 , 1 ) ;
2014-10-23 13:55:50 +00:00
m_pTooltip = " Left mouse button to move. Hold shift to move pivot. Hold ctrl to rotate. Hold alt to ignore grid. Hold shift and right click to delete. " ;
2010-05-29 07:25:38 +00:00
2009-10-27 14:38:53 +00:00
if ( UI ( ) - > MouseButton ( 0 ) )
2008-01-12 12:27:55 +00:00
{
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) | | Input ( ) - > KeyIsPressed ( KEY_RSHIFT ) )
2018-08-13 09:11:56 +00:00
{
2010-05-29 07:25:38 +00:00
s_Operation = OP_MOVE_PIVOT ;
2018-08-13 09:11:56 +00:00
SelectQuad ( Index ) ;
}
2021-12-18 11:23:20 +00:00
else if ( Input ( ) - > ModifierIsPressed ( ) )
2008-01-12 12:27:55 +00:00
{
2021-10-23 11:48:21 +00:00
m_LockMouse = true ;
2010-05-29 07:25:38 +00:00
s_Operation = OP_ROTATE ;
s_RotateAngle = 0 ;
2018-10-02 01:52:01 +00:00
2018-08-13 09:11:56 +00:00
if ( ! IsQuadSelected ( Index ) )
SelectQuad ( Index ) ;
2018-10-02 01:52:01 +00:00
2018-08-13 09:11:56 +00:00
CLayerQuads * pLayer = ( CLayerQuads * ) GetSelectedLayerType ( 0 , LAYERTYPE_QUADS ) ;
2022-06-15 17:34:41 +00:00
s_vvRotatePoints . clear ( ) ;
s_vvRotatePoints . resize ( m_vSelectedQuads . size ( ) ) ;
2022-06-11 19:38:18 +00:00
for ( size_t i = 0 ; i < m_vSelectedQuads . size ( ) ; + + i )
2018-08-13 09:11:56 +00:00
{
2022-06-11 19:38:18 +00:00
CQuad * pCurrentQuad = & pLayer - > m_vQuads [ m_vSelectedQuads [ i ] ] ;
2018-08-13 09:11:56 +00:00
2022-06-15 17:34:41 +00:00
s_vvRotatePoints [ i ] . resize ( 4 ) ;
s_vvRotatePoints [ i ] [ 0 ] = pCurrentQuad - > m_aPoints [ 0 ] ;
s_vvRotatePoints [ i ] [ 1 ] = pCurrentQuad - > m_aPoints [ 1 ] ;
s_vvRotatePoints [ i ] [ 2 ] = pCurrentQuad - > m_aPoints [ 2 ] ;
s_vvRotatePoints [ i ] [ 3 ] = pCurrentQuad - > m_aPoints [ 3 ] ;
2018-08-13 09:11:56 +00:00
}
2008-01-12 12:27:55 +00:00
}
else
2018-08-13 09:11:56 +00:00
{
2010-05-29 07:25:38 +00:00
s_Operation = OP_MOVE_ALL ;
2018-10-02 01:52:01 +00:00
2018-08-13 09:11:56 +00:00
if ( ! IsQuadSelected ( Index ) )
SelectQuad ( Index ) ;
}
2010-05-29 07:25:38 +00:00
2011-02-12 10:40:36 +00:00
UI ( ) - > SetActiveItem ( pID ) ;
2008-01-12 12:27:55 +00:00
}
2010-05-29 07:25:38 +00:00
2009-10-27 14:38:53 +00:00
if ( UI ( ) - > MouseButton ( 1 ) )
2008-01-17 23:09:49 +00:00
{
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) | | Input ( ) - > KeyIsPressed ( KEY_RSHIFT ) )
2014-10-23 13:55:50 +00:00
{
s_Operation = OP_DELETE ;
2018-08-13 09:11:56 +00:00
if ( ! IsQuadSelected ( Index ) )
SelectQuad ( Index ) ;
2014-10-23 13:55:50 +00:00
UI ( ) - > SetActiveItem ( pID ) ;
}
else
{
s_Operation = OP_CONTEXT_MENU ;
2018-08-13 09:11:56 +00:00
if ( ! IsQuadSelected ( Index ) )
SelectQuad ( Index ) ;
2014-10-23 13:55:50 +00:00
UI ( ) - > SetActiveItem ( pID ) ;
}
2008-01-17 23:09:49 +00:00
}
2007-05-22 15:03:32 +00:00
}
2008-01-12 12:27:55 +00:00
else
2020-09-26 19:41:58 +00:00
Graphics ( ) - > SetColor ( 0 , 1 , 0 , 1 ) ;
2008-01-12 12:27:55 +00:00
2022-08-06 15:33:58 +00:00
IGraphics : : CQuadItem QuadItem ( CenterX , CenterY , 5.0f * m_MouseWScale , 5.0f * m_MouseWScale ) ;
2010-05-29 07:25:38 +00:00
Graphics ( ) - > QuadsDraw ( & QuadItem , 1 ) ;
2008-01-12 12:27:55 +00:00
}
2011-02-12 10:40:36 +00:00
void CEditor : : DoQuadPoint ( CQuad * pQuad , int QuadIndex , int V )
2008-01-12 12:27:55 +00:00
{
2011-02-12 10:40:36 +00:00
void * pID = & pQuad - > m_aPoints [ V ] ;
2008-01-12 12:27:55 +00:00
2009-10-27 14:38:53 +00:00
float wx = UI ( ) - > MouseWorldX ( ) ;
float wy = UI ( ) - > MouseWorldY ( ) ;
2010-05-29 07:25:38 +00:00
2011-02-12 10:40:36 +00:00
float px = fx2f ( pQuad - > m_aPoints [ V ] . x ) ;
float py = fx2f ( pQuad - > m_aPoints [ V ] . y ) ;
2010-05-29 07:25:38 +00:00
2022-08-06 15:33:58 +00:00
float dx = ( px - wx ) / m_MouseWScale ;
float dy = ( py - wy ) / m_MouseWScale ;
2020-09-26 19:41:58 +00:00
if ( dx * dx + dy * dy < 50 )
2011-02-12 10:40:36 +00:00
UI ( ) - > SetHotItem ( pID ) ;
2008-01-12 12:27:55 +00:00
2010-05-29 07:25:38 +00:00
// draw selection background
2020-09-26 19:41:58 +00:00
if ( IsQuadSelected ( QuadIndex ) & & m_SelectedPoints & ( 1 < < V ) )
2008-01-12 12:27:55 +00:00
{
2020-09-26 19:41:58 +00:00
Graphics ( ) - > SetColor ( 0 , 0 , 0 , 1 ) ;
2022-08-06 15:33:58 +00:00
IGraphics : : CQuadItem QuadItem ( px , py , 7.0f * m_MouseWScale , 7.0f * m_MouseWScale ) ;
2010-05-29 07:25:38 +00:00
Graphics ( ) - > QuadsDraw ( & QuadItem , 1 ) ;
2008-01-12 12:27:55 +00:00
}
2010-05-29 07:25:38 +00:00
2008-01-12 12:27:55 +00:00
enum
{
2020-09-26 19:41:58 +00:00
OP_NONE = 0 ,
2008-01-12 12:27:55 +00:00
OP_MOVEPOINT ,
2008-01-17 23:09:49 +00:00
OP_MOVEUV ,
OP_CONTEXT_MENU
2008-01-12 12:27:55 +00:00
} ;
2010-05-29 07:25:38 +00:00
static bool s_Moved ;
static int s_Operation = OP_NONE ;
2022-06-28 20:06:24 +00:00
const bool IgnoreGrid = Input ( ) - > KeyIsPressed ( KEY_LALT ) | | Input ( ) - > KeyIsPressed ( KEY_RALT ) ;
2011-12-04 17:11:56 +00:00
2022-05-27 08:55:32 +00:00
if ( UI ( ) - > CheckActiveItem ( pID ) )
2007-05-22 15:03:32 +00:00
{
2010-05-29 07:25:38 +00:00
if ( ! s_Moved )
2007-05-22 15:03:32 +00:00
{
2021-01-02 12:49:16 +00:00
if ( m_MouseDeltaWx * m_MouseDeltaWx + m_MouseDeltaWy * m_MouseDeltaWy > 0.0f )
2010-05-29 07:25:38 +00:00
s_Moved = true ;
2007-05-22 15:03:32 +00:00
}
2010-05-29 07:25:38 +00:00
if ( s_Moved )
2007-05-22 15:03:32 +00:00
{
2010-05-29 07:25:38 +00:00
if ( s_Operation = = OP_MOVEPOINT )
2007-05-22 15:03:32 +00:00
{
2018-08-13 09:11:56 +00:00
CLayerQuads * pLayer = ( CLayerQuads * ) GetSelectedLayerType ( 0 , LAYERTYPE_QUADS ) ;
2011-12-04 17:11:56 +00:00
if ( m_GridActive & & ! IgnoreGrid )
2011-07-10 20:16:16 +00:00
{
2018-08-13 09:11:56 +00:00
int LineDistance = GetLineDistance ( ) ;
2011-07-10 20:16:16 +00:00
2018-08-13 09:11:56 +00:00
float x = 0.0f ;
float y = 0.0f ;
if ( wx > = 0 )
2020-09-26 19:41:58 +00:00
x = ( int ) ( ( wx + ( LineDistance / 2 ) * m_GridFactor ) / ( LineDistance * m_GridFactor ) ) * ( LineDistance * m_GridFactor ) ;
2018-08-13 09:11:56 +00:00
else
2020-09-26 19:41:58 +00:00
x = ( int ) ( ( wx - ( LineDistance / 2 ) * m_GridFactor ) / ( LineDistance * m_GridFactor ) ) * ( LineDistance * m_GridFactor ) ;
2018-08-13 09:11:56 +00:00
if ( wy > = 0 )
2020-09-26 19:41:58 +00:00
y = ( int ) ( ( wy + ( LineDistance / 2 ) * m_GridFactor ) / ( LineDistance * m_GridFactor ) ) * ( LineDistance * m_GridFactor ) ;
2018-08-13 09:11:56 +00:00
else
2020-09-26 19:41:58 +00:00
y = ( int ) ( ( wy - ( LineDistance / 2 ) * m_GridFactor ) / ( LineDistance * m_GridFactor ) ) * ( LineDistance * m_GridFactor ) ;
2011-07-10 20:16:16 +00:00
2018-08-13 09:11:56 +00:00
int OffsetX = f2fx ( x ) - pQuad - > m_aPoints [ V ] . x ;
int OffsetY = f2fx ( y ) - pQuad - > m_aPoints [ V ] . y ;
2022-06-11 19:38:18 +00:00
for ( auto & Selected : m_vSelectedQuads )
2018-08-13 09:11:56 +00:00
{
2022-06-11 19:38:18 +00:00
CQuad * pCurrentQuad = & pLayer - > m_vQuads [ Selected ] ;
2018-08-13 09:11:56 +00:00
for ( int m = 0 ; m < 4 ; m + + )
2020-09-26 19:41:58 +00:00
if ( m_SelectedPoints & ( 1 < < m ) )
2018-08-13 09:11:56 +00:00
{
pCurrentQuad - > m_aPoints [ m ] . x + = OffsetX ;
pCurrentQuad - > m_aPoints [ m ] . y + = OffsetY ;
}
}
2011-07-10 20:16:16 +00:00
}
else
{
2018-10-01 19:12:14 +00:00
int OffsetX = f2fx ( wx ) - pQuad - > m_aPoints [ V ] . x ;
int OffsetY = f2fx ( wy ) - pQuad - > m_aPoints [ V ] . y ;
2022-06-11 19:38:18 +00:00
for ( auto & Selected : m_vSelectedQuads )
2018-08-13 09:11:56 +00:00
{
2022-06-11 19:38:18 +00:00
CQuad * pCurrentQuad = & pLayer - > m_vQuads [ Selected ] ;
2018-08-13 09:11:56 +00:00
for ( int m = 0 ; m < 4 ; m + + )
2020-09-26 19:41:58 +00:00
if ( m_SelectedPoints & ( 1 < < m ) )
2018-08-13 09:11:56 +00:00
{
2018-10-01 19:12:14 +00:00
pCurrentQuad - > m_aPoints [ m ] . x + = OffsetX ;
pCurrentQuad - > m_aPoints [ m ] . y + = OffsetY ;
2018-08-13 09:11:56 +00:00
}
}
2011-07-10 20:16:16 +00:00
}
2008-01-12 12:27:55 +00:00
}
2010-05-29 07:25:38 +00:00
else if ( s_Operation = = OP_MOVEUV )
2008-01-12 12:27:55 +00:00
{
2018-08-13 09:11:56 +00:00
CLayerQuads * pLayer = ( CLayerQuads * ) GetSelectedLayerType ( 0 , LAYERTYPE_QUADS ) ;
2022-06-11 19:38:18 +00:00
for ( auto & Selected : m_vSelectedQuads )
2018-08-13 09:11:56 +00:00
{
2022-06-11 19:38:18 +00:00
CQuad * pCurrentQuad = & pLayer - > m_vQuads [ Selected ] ;
2018-08-13 09:11:56 +00:00
for ( int m = 0 ; m < 4 ; m + + )
2020-09-26 19:41:58 +00:00
if ( m_SelectedPoints & ( 1 < < m ) )
2018-08-13 09:11:56 +00:00
{
// 0,2;1,3 - line x
// 0,1;2,3 - line y
2011-01-06 21:30:28 +00:00
2020-09-26 19:41:58 +00:00
pCurrentQuad - > m_aTexcoords [ m ] . x + = f2fx ( m_MouseDeltaWx * 0.001f ) ;
pCurrentQuad - > m_aTexcoords [ ( m + 2 ) % 4 ] . x + = f2fx ( m_MouseDeltaWx * 0.001f ) ;
2011-08-11 08:59:14 +00:00
2020-09-26 19:41:58 +00:00
pCurrentQuad - > m_aTexcoords [ m ] . y + = f2fx ( m_MouseDeltaWy * 0.001f ) ;
pCurrentQuad - > m_aTexcoords [ m ^ 1 ] . y + = f2fx ( m_MouseDeltaWy * 0.001f ) ;
2018-08-13 09:11:56 +00:00
}
}
2007-05-22 15:03:32 +00:00
}
}
2010-05-29 07:25:38 +00:00
if ( s_Operation = = OP_CONTEXT_MENU )
2007-05-22 15:03:32 +00:00
{
2009-10-27 14:38:53 +00:00
if ( ! UI ( ) - > MouseButton ( 1 ) )
2007-05-22 15:03:32 +00:00
{
2022-06-11 19:38:18 +00:00
if ( m_vSelectedLayers . size ( ) = = 1 )
2018-07-26 08:14:14 +00:00
{
2018-08-13 09:11:56 +00:00
m_SelectedQuadPoint = V ;
m_SelectedQuadIndex = FindSelectedQuadIndex ( QuadIndex ) ;
2018-07-26 08:14:14 +00:00
static int s_PointPopupID = 0 ;
UiInvokePopupMenu ( & s_PointPopupID , 0 , UI ( ) - > MouseX ( ) , UI ( ) - > MouseY ( ) , 120 , 150 , PopupPoint ) ;
}
2022-05-27 09:59:14 +00:00
UI ( ) - > SetActiveItem ( nullptr ) ;
2008-01-17 23:09:49 +00:00
}
}
else
{
2009-10-27 14:38:53 +00:00
if ( ! UI ( ) - > MouseButton ( 0 ) )
2008-01-17 23:09:49 +00:00
{
2010-05-29 07:25:38 +00:00
if ( ! s_Moved )
2008-01-17 23:09:49 +00:00
{
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) | | Input ( ) - > KeyIsPressed ( KEY_RSHIFT ) )
2020-09-26 19:41:58 +00:00
m_SelectedPoints ^ = 1 < < V ;
2008-01-17 23:09:49 +00:00
else
2020-09-26 19:41:58 +00:00
m_SelectedPoints = 1 < < V ;
2008-01-17 23:09:49 +00:00
}
2014-01-19 17:06:56 +00:00
2021-10-23 11:48:21 +00:00
m_LockMouse = false ;
2022-05-27 09:59:14 +00:00
UI ( ) - > SetActiveItem ( nullptr ) ;
2007-05-22 15:03:32 +00:00
}
}
2008-01-12 12:27:55 +00:00
2020-09-26 19:41:58 +00:00
Graphics ( ) - > SetColor ( 1 , 1 , 1 , 1 ) ;
2007-05-22 15:03:32 +00:00
}
2011-02-12 10:40:36 +00:00
else if ( UI ( ) - > HotItem ( ) = = pID )
2008-01-12 12:27:55 +00:00
{
2011-02-12 10:40:36 +00:00
ms_pUiGotContext = pID ;
2010-05-29 07:25:38 +00:00
2020-09-26 19:41:58 +00:00
Graphics ( ) - > SetColor ( 1 , 1 , 1 , 1 ) ;
2011-12-04 17:11:56 +00:00
m_pTooltip = " Left mouse button to move. Hold shift to move the texture. Hold alt to ignore grid. " ;
2010-05-29 07:25:38 +00:00
2009-10-27 14:38:53 +00:00
if ( UI ( ) - > MouseButton ( 0 ) )
2008-01-12 12:27:55 +00:00
{
2011-02-12 10:40:36 +00:00
UI ( ) - > SetActiveItem ( pID ) ;
2010-05-29 07:25:38 +00:00
s_Moved = false ;
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) | | Input ( ) - > KeyIsPressed ( KEY_RSHIFT ) )
2008-01-12 12:27:55 +00:00
{
2010-05-29 07:25:38 +00:00
s_Operation = OP_MOVEUV ;
2021-10-23 11:48:21 +00:00
m_LockMouse = true ;
2008-01-12 12:27:55 +00:00
}
else
2010-05-29 07:25:38 +00:00
s_Operation = OP_MOVEPOINT ;
2020-09-26 19:41:58 +00:00
if ( ! ( m_SelectedPoints & ( 1 < < V ) ) )
2008-01-12 12:27:55 +00:00
{
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) | | Input ( ) - > KeyIsPressed ( KEY_RSHIFT ) )
2020-09-26 19:41:58 +00:00
m_SelectedPoints | = 1 < < V ;
2008-01-12 12:27:55 +00:00
else
2020-09-26 19:41:58 +00:00
m_SelectedPoints = 1 < < V ;
2011-11-26 00:44:24 +00:00
s_Moved = true ;
2008-01-12 12:27:55 +00:00
}
2018-10-02 01:52:01 +00:00
2018-08-13 09:11:56 +00:00
if ( ! IsQuadSelected ( QuadIndex ) )
SelectQuad ( QuadIndex ) ;
2008-01-17 23:09:49 +00:00
}
2009-10-27 14:38:53 +00:00
else if ( UI ( ) - > MouseButton ( 1 ) )
2008-01-17 23:09:49 +00:00
{
2010-05-29 07:25:38 +00:00
s_Operation = OP_CONTEXT_MENU ;
2018-08-13 09:11:56 +00:00
if ( ! IsQuadSelected ( QuadIndex ) )
SelectQuad ( QuadIndex ) ;
2011-02-12 10:40:36 +00:00
UI ( ) - > SetActiveItem ( pID ) ;
2020-09-26 19:41:58 +00:00
if ( ! ( m_SelectedPoints & ( 1 < < V ) ) )
2010-06-05 21:36:52 +00:00
{
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) | | Input ( ) - > KeyIsPressed ( KEY_RSHIFT ) )
2020-09-26 19:41:58 +00:00
m_SelectedPoints | = 1 < < V ;
2010-06-05 21:36:52 +00:00
else
2020-09-26 19:41:58 +00:00
m_SelectedPoints = 1 < < V ;
2010-06-05 21:36:52 +00:00
s_Moved = true ;
2010-06-02 18:50:48 +00:00
}
2008-01-12 12:27:55 +00:00
}
}
else
2020-09-26 19:41:58 +00:00
Graphics ( ) - > SetColor ( 1 , 0 , 0 , 1 ) ;
2010-05-29 07:25:38 +00:00
2022-08-06 15:33:58 +00:00
IGraphics : : CQuadItem QuadItem ( px , py , 5.0f * m_MouseWScale , 5.0f * m_MouseWScale ) ;
2010-05-29 07:25:38 +00:00
Graphics ( ) - > QuadsDraw ( & QuadItem , 1 ) ;
2007-05-22 15:03:32 +00:00
}
2022-02-26 17:49:06 +00:00
float CEditor : : TriangleArea ( vec2 A , vec2 B , vec2 C )
{
2022-03-21 06:10:44 +00:00
return abs ( ( ( B . x - A . x ) * ( C . y - A . y ) - ( C . x - A . x ) * ( B . y - A . y ) ) * 0.5f ) ;
2022-02-26 17:49:06 +00:00
}
bool CEditor : : IsInTriangle ( vec2 Point , vec2 A , vec2 B , vec2 C )
{
// Normalize to increase precision
2022-02-26 23:44:34 +00:00
vec2 Min ( minimum ( A . x , B . x , C . x ) , minimum ( A . y , B . y , C . y ) ) ;
vec2 Max ( maximum ( A . x , B . x , C . x ) , maximum ( A . y , B . y , C . y ) ) ;
2022-02-26 17:49:06 +00:00
vec2 Size ( Max . x - Min . x , Max . y - Min . y ) ;
2022-02-26 23:44:34 +00:00
if ( Size . x < 0.0000001f | | Size . y < 0.0000001f )
2022-02-26 17:49:06 +00:00
return false ;
vec2 Normal ( 1.f / Size . x , 1.f / Size . y ) ;
A = ( A - Min ) * Normal ;
B = ( B - Min ) * Normal ;
C = ( C - Min ) * Normal ;
Point = ( Point - Min ) * Normal ;
float Area = TriangleArea ( A , B , C ) ;
return Area > 0.f & & abs ( TriangleArea ( Point , A , B ) + TriangleArea ( Point , B , C ) + TriangleArea ( Point , C , A ) - Area ) < 0.000001f ;
}
void CEditor : : DoQuadKnife ( int QuadIndex )
{
CLayerQuads * pLayer = ( CLayerQuads * ) GetSelectedLayerType ( 0 , LAYERTYPE_QUADS ) ;
2022-06-11 19:38:18 +00:00
CQuad * pQuad = & pLayer - > m_vQuads [ QuadIndex ] ;
2022-02-26 17:49:06 +00:00
bool IgnoreGrid = Input ( ) - > KeyIsPressed ( KEY_LALT ) | | Input ( ) - > KeyIsPressed ( KEY_RALT ) ;
2022-08-06 15:33:58 +00:00
float SnapRadius = 4.f * m_MouseWScale ;
2022-02-26 17:49:06 +00:00
vec2 Mouse = vec2 ( UI ( ) - > MouseWorldX ( ) , UI ( ) - > MouseWorldY ( ) ) ;
vec2 Point = Mouse ;
vec2 v [ 4 ] = {
vec2 ( fx2f ( pQuad - > m_aPoints [ 0 ] . x ) , fx2f ( pQuad - > m_aPoints [ 0 ] . y ) ) ,
vec2 ( fx2f ( pQuad - > m_aPoints [ 1 ] . x ) , fx2f ( pQuad - > m_aPoints [ 1 ] . y ) ) ,
vec2 ( fx2f ( pQuad - > m_aPoints [ 3 ] . x ) , fx2f ( pQuad - > m_aPoints [ 3 ] . y ) ) ,
vec2 ( fx2f ( pQuad - > m_aPoints [ 2 ] . x ) , fx2f ( pQuad - > m_aPoints [ 2 ] . y ) ) } ;
m_pTooltip = " Left click inside the quad to select an area to slice. Hold alt to ignore grid. Right click to leave knife mode " ;
if ( UI ( ) - > MouseButtonClicked ( 1 ) )
{
m_QuadKnifeActive = false ;
return ;
}
2022-03-01 10:33:53 +00:00
2022-02-26 17:49:06 +00:00
// Handle snapping
if ( m_GridActive & & ! IgnoreGrid )
{
float CellSize = ( float ) GetLineDistance ( ) ;
vec2 OnGrid = vec2 ( roundf ( Mouse . x / CellSize ) * CellSize , roundf ( Mouse . y / CellSize ) * CellSize ) ;
2022-03-01 10:33:53 +00:00
if ( IsInTriangle ( OnGrid , v [ 0 ] , v [ 1 ] , v [ 2 ] ) | | IsInTriangle ( OnGrid , v [ 0 ] , v [ 3 ] , v [ 2 ] ) )
2022-02-26 17:49:06 +00:00
Point = OnGrid ;
else
{
float MinDistance = - 1.f ;
for ( int i = 0 ; i < 4 ; i + + )
{
int j = ( i + 1 ) % 4 ;
vec2 Min ( minimum ( v [ i ] . x , v [ j ] . x ) , minimum ( v [ i ] . y , v [ j ] . y ) ) ;
vec2 Max ( maximum ( v [ i ] . x , v [ j ] . x ) , maximum ( v [ i ] . y , v [ j ] . y ) ) ;
2022-02-26 23:44:34 +00:00
if ( in_range ( OnGrid . y , Min . y , Max . y ) & & Max . y - Min . y > 0.0000001f )
2022-02-26 17:49:06 +00:00
{
vec2 OnEdge ( v [ i ] . x + ( OnGrid . y - v [ i ] . y ) / ( v [ j ] . y - v [ i ] . y ) * ( v [ j ] . x - v [ i ] . x ) , OnGrid . y ) ;
float Distance = abs ( OnGrid . x - OnEdge . x ) ;
if ( Distance < CellSize & & ( Distance < MinDistance | | MinDistance < 0.f ) )
{
MinDistance = Distance ;
Point = OnEdge ;
}
}
2022-03-01 10:33:53 +00:00
2022-02-26 23:44:34 +00:00
if ( in_range ( OnGrid . x , Min . x , Max . x ) & & Max . x - Min . x > 0.0000001f )
2022-02-26 17:49:06 +00:00
{
vec2 OnEdge ( OnGrid . x , v [ i ] . y + ( OnGrid . x - v [ i ] . x ) / ( v [ j ] . x - v [ i ] . x ) * ( v [ j ] . y - v [ i ] . y ) ) ;
float Distance = abs ( OnGrid . y - OnEdge . y ) ;
if ( Distance < CellSize & & ( Distance < MinDistance | | MinDistance < 0.f ) )
{
MinDistance = Distance ;
Point = OnEdge ;
}
}
}
}
}
else
{
float MinDistance = - 1.f ;
// Try snapping to corners
2022-03-01 10:33:53 +00:00
for ( const auto & x : v )
2022-02-26 17:49:06 +00:00
{
2022-03-01 10:33:53 +00:00
float Distance = distance ( Mouse , x ) ;
2022-02-26 17:49:06 +00:00
if ( Distance < = SnapRadius & & ( Distance < MinDistance | | MinDistance < 0.f ) )
{
MinDistance = Distance ;
2022-03-01 10:33:53 +00:00
Point = x ;
2022-02-26 17:49:06 +00:00
}
}
2022-03-01 10:33:53 +00:00
if ( MinDistance < 0.f )
2022-02-26 17:49:06 +00:00
{
// Try snapping to edges
for ( int i = 0 ; i < 4 ; i + + )
{
int j = ( i + 1 ) % 4 ;
vec2 s ( v [ j ] - v [ i ] ) ;
float t = ( ( Mouse . x - v [ i ] . x ) * s . x + ( Mouse . y - v [ i ] . y ) * s . y ) / ( s . x * s . x + s . y * s . y ) ;
if ( in_range ( t , 0.f , 1.f ) )
{
vec2 OnEdge = vec2 ( ( v [ i ] . x + t * s . x ) , ( v [ i ] . y + t * s . y ) ) ;
float Distance = distance ( Mouse , OnEdge ) ;
if ( Distance < = SnapRadius & & ( Distance < MinDistance | | MinDistance < 0.f ) )
{
MinDistance = Distance ;
Point = OnEdge ;
}
}
}
}
}
bool ValidPosition = IsInTriangle ( Point , v [ 0 ] , v [ 1 ] , v [ 2 ] ) | | IsInTriangle ( Point , v [ 0 ] , v [ 3 ] , v [ 2 ] ) ;
2022-03-01 10:33:53 +00:00
if ( UI ( ) - > MouseButtonClicked ( 0 ) & & ValidPosition )
2022-02-26 23:44:34 +00:00
{
m_aQuadKnifePoints [ m_QuadKnifeCount ] = Point ;
m_QuadKnifeCount + + ;
}
2022-02-26 17:49:06 +00:00
if ( m_QuadKnifeCount = = 4 )
{
if ( IsInTriangle ( m_aQuadKnifePoints [ 3 ] , m_aQuadKnifePoints [ 0 ] , m_aQuadKnifePoints [ 1 ] , m_aQuadKnifePoints [ 2 ] ) | |
IsInTriangle ( m_aQuadKnifePoints [ 1 ] , m_aQuadKnifePoints [ 0 ] , m_aQuadKnifePoints [ 2 ] , m_aQuadKnifePoints [ 3 ] ) )
{
// Fix concave order
2022-05-15 17:25:36 +00:00
std : : swap ( m_aQuadKnifePoints [ 0 ] , m_aQuadKnifePoints [ 3 ] ) ;
std : : swap ( m_aQuadKnifePoints [ 1 ] , m_aQuadKnifePoints [ 2 ] ) ;
2022-02-26 17:49:06 +00:00
}
2022-05-15 17:25:36 +00:00
std : : swap ( m_aQuadKnifePoints [ 2 ] , m_aQuadKnifePoints [ 3 ] ) ;
2022-02-26 17:49:06 +00:00
CQuad * pResult = pLayer - > NewQuad ( 64 , 64 , 64 , 64 ) ;
2022-06-11 19:38:18 +00:00
pQuad = & pLayer - > m_vQuads [ QuadIndex ] ;
2022-02-26 17:49:06 +00:00
for ( int i = 0 ; i < 4 ; i + + )
{
int t = IsInTriangle ( m_aQuadKnifePoints [ i ] , v [ 0 ] , v [ 3 ] , v [ 2 ] ) ? 2 : 1 ;
2022-03-01 10:33:53 +00:00
2022-02-26 17:49:06 +00:00
vec2 A = vec2 ( fx2f ( pQuad - > m_aPoints [ 0 ] . x ) , fx2f ( pQuad - > m_aPoints [ 0 ] . y ) ) ;
vec2 B = vec2 ( fx2f ( pQuad - > m_aPoints [ 3 ] . x ) , fx2f ( pQuad - > m_aPoints [ 3 ] . y ) ) ;
vec2 C = vec2 ( fx2f ( pQuad - > m_aPoints [ t ] . x ) , fx2f ( pQuad - > m_aPoints [ t ] . y ) ) ;
float TriArea = TriangleArea ( A , B , C ) ;
float WeightA = TriangleArea ( m_aQuadKnifePoints [ i ] , B , C ) / TriArea ;
float WeightB = TriangleArea ( m_aQuadKnifePoints [ i ] , C , A ) / TriArea ;
float WeightC = TriangleArea ( m_aQuadKnifePoints [ i ] , A , B ) / TriArea ;
pResult - > m_aColors [ i ] . r = ( int ) round ( pQuad - > m_aColors [ 0 ] . r * WeightA + pQuad - > m_aColors [ 3 ] . r * WeightB + pQuad - > m_aColors [ t ] . r * WeightC ) ;
pResult - > m_aColors [ i ] . g = ( int ) round ( pQuad - > m_aColors [ 0 ] . g * WeightA + pQuad - > m_aColors [ 3 ] . g * WeightB + pQuad - > m_aColors [ t ] . g * WeightC ) ;
pResult - > m_aColors [ i ] . b = ( int ) round ( pQuad - > m_aColors [ 0 ] . b * WeightA + pQuad - > m_aColors [ 3 ] . b * WeightB + pQuad - > m_aColors [ t ] . b * WeightC ) ;
pResult - > m_aColors [ i ] . a = ( int ) round ( pQuad - > m_aColors [ 0 ] . a * WeightA + pQuad - > m_aColors [ 3 ] . a * WeightB + pQuad - > m_aColors [ t ] . a * WeightC ) ;
pResult - > m_aTexcoords [ i ] . x = ( int ) round ( pQuad - > m_aTexcoords [ 0 ] . x * WeightA + pQuad - > m_aTexcoords [ 3 ] . x * WeightB + pQuad - > m_aTexcoords [ t ] . x * WeightC ) ;
pResult - > m_aTexcoords [ i ] . y = ( int ) round ( pQuad - > m_aTexcoords [ 0 ] . y * WeightA + pQuad - > m_aTexcoords [ 3 ] . y * WeightB + pQuad - > m_aTexcoords [ t ] . y * WeightC ) ;
pResult - > m_aPoints [ i ] . x = f2fx ( m_aQuadKnifePoints [ i ] . x ) ;
pResult - > m_aPoints [ i ] . y = f2fx ( m_aQuadKnifePoints [ i ] . y ) ;
}
pResult - > m_aPoints [ 4 ] . x = ( ( pResult - > m_aPoints [ 0 ] . x + pResult - > m_aPoints [ 3 ] . x ) / 2 + ( pResult - > m_aPoints [ 1 ] . x + pResult - > m_aPoints [ 2 ] . x ) / 2 ) / 2 ;
pResult - > m_aPoints [ 4 ] . y = ( ( pResult - > m_aPoints [ 0 ] . y + pResult - > m_aPoints [ 3 ] . y ) / 2 + ( pResult - > m_aPoints [ 1 ] . y + pResult - > m_aPoints [ 2 ] . y ) / 2 ) / 2 ;
m_QuadKnifeCount = 0 ;
}
// Render
2022-02-28 22:45:57 +00:00
Graphics ( ) - > TextureClear ( ) ;
2022-03-01 10:33:53 +00:00
Graphics ( ) - > LinesBegin ( ) ;
2022-02-28 22:45:57 +00:00
2022-02-26 17:49:06 +00:00
IGraphics : : CLineItem aEdges [ 4 ] = {
IGraphics : : CLineItem ( v [ 0 ] . x , v [ 0 ] . y , v [ 1 ] . x , v [ 1 ] . y ) ,
IGraphics : : CLineItem ( v [ 1 ] . x , v [ 1 ] . y , v [ 2 ] . x , v [ 2 ] . y ) ,
IGraphics : : CLineItem ( v [ 2 ] . x , v [ 2 ] . y , v [ 3 ] . x , v [ 3 ] . y ) ,
IGraphics : : CLineItem ( v [ 3 ] . x , v [ 3 ] . y , v [ 0 ] . x , v [ 0 ] . y ) } ;
2022-02-28 22:45:57 +00:00
Graphics ( ) - > SetColor ( 1.f , 0.5f , 0.f , 1.f ) ;
Graphics ( ) - > LinesDraw ( aEdges , 4 ) ;
2022-02-26 17:49:06 +00:00
IGraphics : : CLineItem aLines [ 4 ] ;
int LineCount = maximum ( m_QuadKnifeCount - 1 , 0 ) ;
for ( int i = 0 ; i < LineCount ; i + + )
aLines [ i ] = IGraphics : : CLineItem ( m_aQuadKnifePoints [ i ] . x , m_aQuadKnifePoints [ i ] . y , m_aQuadKnifePoints [ i + 1 ] . x , m_aQuadKnifePoints [ i + 1 ] . y ) ;
2022-02-28 22:45:57 +00:00
Graphics ( ) - > SetColor ( 1.f , 1.f , 1.f , 1.f ) ;
Graphics ( ) - > LinesDraw ( aLines , LineCount ) ;
2022-02-26 17:49:06 +00:00
if ( ValidPosition )
{
if ( m_QuadKnifeCount > 0 )
2022-02-26 23:44:34 +00:00
{
2022-02-28 22:45:57 +00:00
IGraphics : : CLineItem LineCurrent ( Point . x , Point . y , m_aQuadKnifePoints [ m_QuadKnifeCount - 1 ] . x , m_aQuadKnifePoints [ m_QuadKnifeCount - 1 ] . y ) ;
Graphics ( ) - > LinesDraw ( & LineCurrent , 1 ) ;
2022-02-26 23:44:34 +00:00
}
2022-02-26 17:49:06 +00:00
2022-02-28 22:45:57 +00:00
if ( m_QuadKnifeCount = = 3 )
2022-02-26 23:44:34 +00:00
{
2022-02-28 22:45:57 +00:00
IGraphics : : CLineItem LineClose ( Point . x , Point . y , m_aQuadKnifePoints [ 0 ] . x , m_aQuadKnifePoints [ 0 ] . y ) ;
Graphics ( ) - > LinesDraw ( & LineClose , 1 ) ;
2022-02-26 23:44:34 +00:00
}
2022-02-26 17:49:06 +00:00
}
Graphics ( ) - > LinesEnd ( ) ;
Graphics ( ) - > QuadsBegin ( ) ;
2022-02-28 22:45:57 +00:00
IGraphics : : CQuadItem aMarkers [ 4 ] ;
for ( int i = 0 ; i < m_QuadKnifeCount ; i + + )
2022-08-06 15:33:58 +00:00
aMarkers [ i ] = IGraphics : : CQuadItem ( m_aQuadKnifePoints [ i ] . x , m_aQuadKnifePoints [ i ] . y , 5.f * m_MouseWScale , 5.f * m_MouseWScale ) ;
2022-02-28 22:45:57 +00:00
2022-02-26 17:49:06 +00:00
Graphics ( ) - > SetColor ( 0.f , 0.f , 1.f , 1.f ) ;
2022-02-28 22:45:57 +00:00
Graphics ( ) - > QuadsDraw ( aMarkers , m_QuadKnifeCount ) ;
if ( ValidPosition )
{
2022-08-06 15:33:58 +00:00
IGraphics : : CQuadItem MarkerCurrent ( Point . x , Point . y , 5.f * m_MouseWScale , 5.f * m_MouseWScale ) ;
2022-02-28 22:45:57 +00:00
Graphics ( ) - > QuadsDraw ( & MarkerCurrent , 1 ) ;
}
2022-03-01 10:33:53 +00:00
2022-02-26 17:49:06 +00:00
Graphics ( ) - > QuadsEnd ( ) ;
}
2022-06-11 20:03:23 +00:00
void CEditor : : DoQuadEnvelopes ( const std : : vector < CQuad > & vQuads , IGraphics : : CTextureHandle Texture )
2011-08-15 18:12:31 +00:00
{
2022-06-11 20:03:23 +00:00
size_t Num = vQuads . size ( ) ;
2020-09-26 19:41:58 +00:00
CEnvelope * * apEnvelope = new CEnvelope * [ Num ] ;
2020-11-04 18:12:45 +00:00
mem_zero ( apEnvelope , sizeof ( CEnvelope * ) * Num ) ; // NOLINT(bugprone-sizeof-expression)
2022-05-24 09:24:33 +00:00
for ( size_t i = 0 ; i < Num ; i + + )
2012-10-14 12:04:48 +00:00
{
2022-06-11 20:03:23 +00:00
if ( ( m_ShowEnvelopePreview = = 1 & & vQuads [ i ] . m_PosEnv = = m_SelectedEnvelope ) | | m_ShowEnvelopePreview = = 2 )
if ( vQuads [ i ] . m_PosEnv > = 0 & & vQuads [ i ] . m_PosEnv < ( int ) m_Map . m_vpEnvelopes . size ( ) )
apEnvelope [ i ] = m_Map . m_vpEnvelopes [ vQuads [ i ] . m_PosEnv ] ;
2012-10-14 12:04:48 +00:00
}
2011-08-15 18:12:31 +00:00
//Draw Lines
2012-08-12 10:41:50 +00:00
Graphics ( ) - > TextureClear ( ) ;
2011-08-15 18:12:31 +00:00
Graphics ( ) - > LinesBegin ( ) ;
2020-09-26 19:41:58 +00:00
Graphics ( ) - > SetColor ( 80.0f / 255 , 150.0f / 255 , 230.f / 255 , 0.5f ) ;
2022-05-24 09:24:33 +00:00
for ( size_t j = 0 ; j < Num ; j + + )
2012-10-14 12:04:48 +00:00
{
if ( ! apEnvelope [ j ] )
continue ;
//QuadParams
2022-06-11 20:03:23 +00:00
const CPoint * pPoints = vQuads [ j ] . m_aPoints ;
2022-06-11 19:38:18 +00:00
for ( size_t i = 0 ; i < apEnvelope [ j ] - > m_vPoints . size ( ) - 1 ; i + + )
2011-08-15 18:12:31 +00:00
{
2022-06-11 19:38:18 +00:00
float OffsetX = fx2f ( apEnvelope [ j ] - > m_vPoints [ i ] . m_aValues [ 0 ] ) ;
float OffsetY = fx2f ( apEnvelope [ j ] - > m_vPoints [ i ] . m_aValues [ 1 ] ) ;
2020-09-26 19:41:58 +00:00
vec2 Pos0 = vec2 ( fx2f ( pPoints [ 4 ] . x ) + OffsetX , fx2f ( pPoints [ 4 ] . y ) + OffsetY ) ;
2011-08-15 18:12:31 +00:00
2022-06-11 19:38:18 +00:00
OffsetX = fx2f ( apEnvelope [ j ] - > m_vPoints [ i + 1 ] . m_aValues [ 0 ] ) ;
OffsetY = fx2f ( apEnvelope [ j ] - > m_vPoints [ i + 1 ] . m_aValues [ 1 ] ) ;
2020-09-26 19:41:58 +00:00
vec2 Pos1 = vec2 ( fx2f ( pPoints [ 4 ] . x ) + OffsetX , fx2f ( pPoints [ 4 ] . y ) + OffsetY ) ;
2011-08-15 18:12:31 +00:00
IGraphics : : CLineItem Line = IGraphics : : CLineItem ( Pos0 . x , Pos0 . y , Pos1 . x , Pos1 . y ) ;
Graphics ( ) - > LinesDraw ( & Line , 1 ) ;
}
2012-10-14 12:04:48 +00:00
}
Graphics ( ) - > SetColor ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
2011-08-15 18:12:31 +00:00
Graphics ( ) - > LinesEnd ( ) ;
//Draw Quads
2012-08-12 10:41:50 +00:00
Graphics ( ) - > TextureSet ( Texture ) ;
2012-10-14 12:04:48 +00:00
Graphics ( ) - > QuadsBegin ( ) ;
2015-07-09 00:08:14 +00:00
2022-05-24 09:24:33 +00:00
for ( size_t j = 0 ; j < Num ; j + + )
2012-10-14 12:04:48 +00:00
{
if ( ! apEnvelope [ j ] )
continue ;
//QuadParams
2022-06-11 20:03:23 +00:00
const CPoint * pPoints = vQuads [ j ] . m_aPoints ;
2012-10-14 12:04:48 +00:00
2022-06-11 19:38:18 +00:00
for ( size_t i = 0 ; i < apEnvelope [ j ] - > m_vPoints . size ( ) ; i + + )
2011-08-15 18:12:31 +00:00
{
2012-10-14 12:04:48 +00:00
//Calc Env Position
2022-06-11 19:38:18 +00:00
float OffsetX = fx2f ( apEnvelope [ j ] - > m_vPoints [ i ] . m_aValues [ 0 ] ) ;
float OffsetY = fx2f ( apEnvelope [ j ] - > m_vPoints [ i ] . m_aValues [ 1 ] ) ;
float Rot = fx2f ( apEnvelope [ j ] - > m_vPoints [ i ] . m_aValues [ 2 ] ) / 360.0f * pi * 2 ;
2012-10-14 12:04:48 +00:00
//Set Colours
2022-06-11 20:03:23 +00:00
float Alpha = ( m_SelectedQuadEnvelope = = vQuads [ j ] . m_PosEnv & & m_SelectedEnvelopePoint = = ( int ) i ) ? 0.65f : 0.35f ;
2012-10-14 12:04:48 +00:00
IGraphics : : CColorVertex aArray [ 4 ] = {
2022-06-11 20:03:23 +00:00
IGraphics : : CColorVertex ( 0 , vQuads [ j ] . m_aColors [ 0 ] . r , vQuads [ j ] . m_aColors [ 0 ] . g , vQuads [ j ] . m_aColors [ 0 ] . b , Alpha ) ,
IGraphics : : CColorVertex ( 1 , vQuads [ j ] . m_aColors [ 1 ] . r , vQuads [ j ] . m_aColors [ 1 ] . g , vQuads [ j ] . m_aColors [ 1 ] . b , Alpha ) ,
IGraphics : : CColorVertex ( 2 , vQuads [ j ] . m_aColors [ 2 ] . r , vQuads [ j ] . m_aColors [ 2 ] . g , vQuads [ j ] . m_aColors [ 2 ] . b , Alpha ) ,
IGraphics : : CColorVertex ( 3 , vQuads [ j ] . m_aColors [ 3 ] . r , vQuads [ j ] . m_aColors [ 3 ] . g , vQuads [ j ] . m_aColors [ 3 ] . b , Alpha ) } ;
2012-10-14 12:04:48 +00:00
Graphics ( ) - > SetColorVertex ( aArray , 4 ) ;
//Rotation
if ( Rot ! = 0 )
{
static CPoint aRotated [ 4 ] ;
2022-06-11 20:03:23 +00:00
aRotated [ 0 ] = vQuads [ j ] . m_aPoints [ 0 ] ;
aRotated [ 1 ] = vQuads [ j ] . m_aPoints [ 1 ] ;
aRotated [ 2 ] = vQuads [ j ] . m_aPoints [ 2 ] ;
aRotated [ 3 ] = vQuads [ j ] . m_aPoints [ 3 ] ;
2012-10-14 12:04:48 +00:00
pPoints = aRotated ;
2022-06-11 20:03:23 +00:00
Rotate ( & vQuads [ j ] . m_aPoints [ 4 ] , & aRotated [ 0 ] , Rot ) ;
Rotate ( & vQuads [ j ] . m_aPoints [ 4 ] , & aRotated [ 1 ] , Rot ) ;
Rotate ( & vQuads [ j ] . m_aPoints [ 4 ] , & aRotated [ 2 ] , Rot ) ;
Rotate ( & vQuads [ j ] . m_aPoints [ 4 ] , & aRotated [ 3 ] , Rot ) ;
2012-10-14 12:04:48 +00:00
}
//Set Texture Coords
Graphics ( ) - > QuadsSetSubsetFree (
2022-06-11 20:03:23 +00:00
fx2f ( vQuads [ j ] . m_aTexcoords [ 0 ] . x ) , fx2f ( vQuads [ j ] . m_aTexcoords [ 0 ] . y ) ,
fx2f ( vQuads [ j ] . m_aTexcoords [ 1 ] . x ) , fx2f ( vQuads [ j ] . m_aTexcoords [ 1 ] . y ) ,
fx2f ( vQuads [ j ] . m_aTexcoords [ 2 ] . x ) , fx2f ( vQuads [ j ] . m_aTexcoords [ 2 ] . y ) ,
fx2f ( vQuads [ j ] . m_aTexcoords [ 3 ] . x ) , fx2f ( vQuads [ j ] . m_aTexcoords [ 3 ] . y ) ) ;
2012-10-14 12:04:48 +00:00
//Set Quad Coords & Draw
IGraphics : : CFreeformItem Freeform (
2020-09-26 19:41:58 +00:00
fx2f ( pPoints [ 0 ] . x ) + OffsetX , fx2f ( pPoints [ 0 ] . y ) + OffsetY ,
fx2f ( pPoints [ 1 ] . x ) + OffsetX , fx2f ( pPoints [ 1 ] . y ) + OffsetY ,
fx2f ( pPoints [ 2 ] . x ) + OffsetX , fx2f ( pPoints [ 2 ] . y ) + OffsetY ,
fx2f ( pPoints [ 3 ] . x ) + OffsetX , fx2f ( pPoints [ 3 ] . y ) + OffsetY ) ;
2012-10-14 12:04:48 +00:00
Graphics ( ) - > QuadsDrawFreeform ( & Freeform , 1 ) ;
2011-08-15 18:12:31 +00:00
}
}
2012-10-14 12:04:48 +00:00
Graphics ( ) - > QuadsEnd ( ) ;
2012-08-12 10:41:50 +00:00
Graphics ( ) - > TextureClear ( ) ;
2012-10-14 12:04:48 +00:00
Graphics ( ) - > QuadsBegin ( ) ;
2011-08-15 18:12:31 +00:00
2012-10-14 12:04:48 +00:00
// Draw QuadPoints
2022-05-24 09:24:33 +00:00
for ( size_t j = 0 ; j < Num ; j + + )
2012-10-14 12:04:48 +00:00
{
if ( ! apEnvelope [ j ] )
continue ;
2012-12-07 15:11:40 +00:00
for ( size_t i = 0 ; i < apEnvelope [ j ] - > m_vPoints . size ( ) ; i + + )
2022-06-11 20:03:23 +00:00
DoQuadEnvPoint ( & vQuads [ j ] , j , i ) ;
2011-08-15 18:12:31 +00:00
}
2012-10-14 12:04:48 +00:00
Graphics ( ) - > QuadsEnd ( ) ;
2012-10-21 12:49:26 +00:00
delete [ ] apEnvelope ;
2011-08-14 14:31:48 +00:00
}
2011-08-15 18:12:31 +00:00
2012-10-21 12:49:26 +00:00
void CEditor : : DoQuadEnvPoint ( const CQuad * pQuad , int QIndex , int PIndex )
2011-08-14 14:31:48 +00:00
{
enum
{
2020-09-26 19:41:58 +00:00
OP_NONE = 0 ,
2011-08-15 18:12:31 +00:00
OP_MOVE ,
OP_ROTATE ,
2011-08-14 14:31:48 +00:00
} ;
// some basic values
2022-06-28 20:09:20 +00:00
static float s_LastWx = 0 ;
static float s_LastWy = 0 ;
2011-08-14 14:31:48 +00:00
static int s_Operation = OP_NONE ;
float wx = UI ( ) - > MouseWorldX ( ) ;
2011-08-15 18:12:31 +00:00
float wy = UI ( ) - > MouseWorldY ( ) ;
2022-06-11 19:38:18 +00:00
CEnvelope * pEnvelope = m_Map . m_vpEnvelopes [ pQuad - > m_PosEnv ] ;
void * pID = & pEnvelope - > m_vPoints [ PIndex ] ;
2022-04-01 16:32:51 +00:00
static int s_CurQIndex = - 1 ;
2011-08-14 14:31:48 +00:00
// get pivot
2022-06-11 19:38:18 +00:00
float CenterX = fx2f ( pQuad - > m_aPoints [ 4 ] . x ) + fx2f ( pEnvelope - > m_vPoints [ PIndex ] . m_aValues [ 0 ] ) ;
float CenterY = fx2f ( pQuad - > m_aPoints [ 4 ] . y ) + fx2f ( pEnvelope - > m_vPoints [ PIndex ] . m_aValues [ 1 ] ) ;
2011-08-14 14:31:48 +00:00
2022-08-06 15:33:58 +00:00
float dx = ( CenterX - wx ) / m_MouseWScale ;
float dy = ( CenterY - wy ) / m_MouseWScale ;
2022-05-27 08:55:32 +00:00
if ( dx * dx + dy * dy < 50.0f & & UI ( ) - > CheckActiveItem ( nullptr ) )
2011-08-16 19:35:00 +00:00
{
2011-08-14 14:31:48 +00:00
UI ( ) - > SetHotItem ( pID ) ;
2022-04-01 16:32:51 +00:00
s_CurQIndex = QIndex ;
2011-08-16 19:35:00 +00:00
}
2011-08-14 14:31:48 +00:00
2022-06-28 20:06:24 +00:00
const bool IgnoreGrid = Input ( ) - > KeyIsPressed ( KEY_LALT ) | | Input ( ) - > KeyIsPressed ( KEY_RALT ) ;
2011-12-04 17:11:56 +00:00
2022-05-27 08:55:32 +00:00
if ( UI ( ) - > CheckActiveItem ( pID ) & & s_CurQIndex = = QIndex )
2011-08-14 14:31:48 +00:00
{
2011-08-15 18:12:31 +00:00
if ( s_Operation = = OP_MOVE )
2011-08-14 14:31:48 +00:00
{
2011-12-04 17:11:56 +00:00
if ( m_GridActive & & ! IgnoreGrid )
2011-08-15 18:12:31 +00:00
{
int LineDistance = GetLineDistance ( ) ;
float x = 0.0f ;
float y = 0.0f ;
if ( wx > = 0 )
2020-09-26 19:41:58 +00:00
x = ( int ) ( ( wx + ( LineDistance / 2 ) * m_GridFactor ) / ( LineDistance * m_GridFactor ) ) * ( LineDistance * m_GridFactor ) ;
2011-08-15 18:12:31 +00:00
else
2020-09-26 19:41:58 +00:00
x = ( int ) ( ( wx - ( LineDistance / 2 ) * m_GridFactor ) / ( LineDistance * m_GridFactor ) ) * ( LineDistance * m_GridFactor ) ;
2011-08-15 18:12:31 +00:00
if ( wy > = 0 )
2020-09-26 19:41:58 +00:00
y = ( int ) ( ( wy + ( LineDistance / 2 ) * m_GridFactor ) / ( LineDistance * m_GridFactor ) ) * ( LineDistance * m_GridFactor ) ;
2011-08-15 18:12:31 +00:00
else
2020-09-26 19:41:58 +00:00
y = ( int ) ( ( wy - ( LineDistance / 2 ) * m_GridFactor ) / ( LineDistance * m_GridFactor ) ) * ( LineDistance * m_GridFactor ) ;
2011-08-15 18:12:31 +00:00
2022-06-11 19:38:18 +00:00
pEnvelope - > m_vPoints [ PIndex ] . m_aValues [ 0 ] = f2fx ( x ) - pQuad - > m_aPoints [ 4 ] . x ;
pEnvelope - > m_vPoints [ PIndex ] . m_aValues [ 1 ] = f2fx ( y ) - pQuad - > m_aPoints [ 4 ] . y ;
2011-08-15 18:12:31 +00:00
}
else
{
2022-06-28 20:09:20 +00:00
pEnvelope - > m_vPoints [ PIndex ] . m_aValues [ 0 ] + = f2fx ( wx - s_LastWx ) ;
pEnvelope - > m_vPoints [ PIndex ] . m_aValues [ 1 ] + = f2fx ( wy - s_LastWy ) ;
2011-08-15 18:12:31 +00:00
}
2011-08-14 14:31:48 +00:00
}
2011-08-15 18:12:31 +00:00
else if ( s_Operation = = OP_ROTATE )
2022-06-11 19:38:18 +00:00
pEnvelope - > m_vPoints [ PIndex ] . m_aValues [ 2 ] + = 10 * m_MouseDeltaX ;
2011-08-14 14:31:48 +00:00
2022-06-28 20:09:20 +00:00
s_LastWx = wx ;
s_LastWy = wy ;
2011-08-15 18:12:31 +00:00
if ( ! UI ( ) - > MouseButton ( 0 ) )
{
2021-10-23 11:48:21 +00:00
m_LockMouse = false ;
2011-08-15 18:12:31 +00:00
s_Operation = OP_NONE ;
2022-05-27 09:59:14 +00:00
UI ( ) - > SetActiveItem ( nullptr ) ;
2011-08-14 14:31:48 +00:00
}
2011-08-15 18:12:31 +00:00
Graphics ( ) - > SetColor ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
2011-08-14 14:31:48 +00:00
}
2022-04-01 16:32:51 +00:00
else if ( UI ( ) - > HotItem ( ) = = pID & & s_CurQIndex = = QIndex )
2011-08-14 14:31:48 +00:00
{
ms_pUiGotContext = pID ;
2011-08-15 18:12:31 +00:00
Graphics ( ) - > SetColor ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
2011-12-04 17:11:56 +00:00
m_pTooltip = " Left mouse button to move. Hold ctrl to rotate. Hold alt to ignore grid. " ;
2011-08-14 14:31:48 +00:00
if ( UI ( ) - > MouseButton ( 0 ) )
{
2021-12-18 11:23:20 +00:00
if ( Input ( ) - > ModifierIsPressed ( ) )
2011-08-15 18:12:31 +00:00
{
2021-10-23 11:48:21 +00:00
m_LockMouse = true ;
2011-08-15 18:12:31 +00:00
s_Operation = OP_ROTATE ;
2018-08-13 09:11:56 +00:00
SelectQuad ( QIndex ) ;
2011-08-15 18:12:31 +00:00
}
else
2018-08-13 09:11:56 +00:00
{
2011-08-15 18:12:31 +00:00
s_Operation = OP_MOVE ;
2018-08-13 09:11:56 +00:00
SelectQuad ( QIndex ) ;
}
2011-08-15 18:12:31 +00:00
m_SelectedEnvelopePoint = PIndex ;
m_SelectedQuadEnvelope = pQuad - > m_PosEnv ;
2011-08-14 14:31:48 +00:00
UI ( ) - > SetActiveItem ( pID ) ;
2022-06-28 20:09:20 +00:00
s_LastWx = wx ;
s_LastWy = wy ;
2011-08-15 18:12:31 +00:00
}
else
{
m_SelectedEnvelopePoint = - 1 ;
m_SelectedQuadEnvelope = - 1 ;
2011-08-14 14:31:48 +00:00
}
}
2011-08-15 18:12:31 +00:00
else
Graphics ( ) - > SetColor ( 0.0f , 1.0f , 0.0f , 1.0f ) ;
2011-08-14 14:31:48 +00:00
2022-08-06 15:33:58 +00:00
IGraphics : : CQuadItem QuadItem ( CenterX , CenterY , 5.0f * m_MouseWScale , 5.0f * m_MouseWScale ) ;
2011-08-14 14:31:48 +00:00
Graphics ( ) - > QuadsDraw ( & QuadItem , 1 ) ;
}
2018-04-04 19:41:14 +00:00
void CEditor : : DoMapEditor ( CUIRect View )
2007-05-22 15:03:32 +00:00
{
2008-01-12 12:27:55 +00:00
// render all good stuff
2011-05-04 23:50:23 +00:00
if ( ! m_ShowPicker )
2008-01-12 12:27:55 +00:00
{
2022-06-11 19:38:18 +00:00
for ( auto & pGroup : m_Map . m_vpGroups )
2020-09-26 19:41:58 +00:00
{ // don't render the front, tele, speedup and switch layer now we will do it later to make them on top of others
2010-10-01 19:28:56 +00:00
if (
2022-05-24 09:24:33 +00:00
pGroup = = ( CLayerGroup * ) m_Map . m_pFrontLayer | |
pGroup = = ( CLayerGroup * ) m_Map . m_pTeleLayer | |
pGroup = = ( CLayerGroup * ) m_Map . m_pSpeedupLayer | |
pGroup = = ( CLayerGroup * ) m_Map . m_pSwitchLayer | |
pGroup = = ( CLayerGroup * ) m_Map . m_pTuneLayer )
2010-10-01 19:28:56 +00:00
continue ;
2022-05-24 09:24:33 +00:00
if ( pGroup - > m_Visible )
pGroup - > Render ( ) ;
2009-10-27 14:38:53 +00:00
//UI()->ClipEnable(&view);
2008-01-12 12:27:55 +00:00
}
2010-09-16 20:07:58 +00:00
2014-03-12 22:57:00 +00:00
// render the game, tele, speedup, front, tune and switch above everything else
2010-08-25 14:15:59 +00:00
if ( m_Map . m_pGameGroup - > m_Visible )
2010-09-27 19:41:41 +00:00
{
m_Map . m_pGameGroup - > MapScreen ( ) ;
2022-06-11 19:38:18 +00:00
for ( auto & pLayer : m_Map . m_pGameGroup - > m_vpLayers )
2010-10-01 19:28:56 +00:00
{
2020-09-26 19:41:58 +00:00
if (
2022-05-24 09:24:33 +00:00
pLayer - > m_Visible & &
( pLayer = = m_Map . m_pGameLayer | |
pLayer = = m_Map . m_pFrontLayer | |
pLayer = = m_Map . m_pTeleLayer | |
pLayer = = m_Map . m_pSpeedupLayer | |
pLayer = = m_Map . m_pSwitchLayer | |
pLayer = = m_Map . m_pTuneLayer ) )
pLayer - > Render ( ) ;
2010-10-01 19:28:56 +00:00
}
2010-09-27 19:41:41 +00:00
}
2011-02-18 10:41:27 +00:00
CLayerTiles * pT = static_cast < CLayerTiles * > ( GetSelectedLayerType ( 0 , LAYERTYPE_TILES ) ) ;
if ( m_ShowTileInfo & & pT & & pT - > m_Visible & & m_ZoomLevel < = 300 )
2011-06-02 17:16:22 +00:00
{
GetSelectedGroup ( ) - > MapScreen ( ) ;
2011-02-18 10:41:27 +00:00
pT - > ShowInfo ( ) ;
2011-06-02 17:16:22 +00:00
}
2008-01-12 12:27:55 +00:00
}
2012-01-08 00:14:52 +00:00
else
{
// fix aspect ratio of the image in the picker
2019-04-26 19:36:49 +00:00
float Max = minimum ( View . w , View . h ) ;
2012-01-08 00:14:52 +00:00
View . w = View . h = Max ;
}
2008-01-12 12:27:55 +00:00
2011-02-12 10:40:36 +00:00
static void * s_pEditorID = ( void * ) & s_pEditorID ;
2022-05-13 18:27:03 +00:00
const bool Inside = UI ( ) - > MouseInside ( & View ) ;
2008-01-12 12:27:55 +00:00
2008-03-29 11:44:03 +00:00
// fetch mouse position
2009-10-27 14:38:53 +00:00
float wx = UI ( ) - > MouseWorldX ( ) ;
float wy = UI ( ) - > MouseWorldY ( ) ;
2014-08-22 13:40:23 +00:00
float mx = UI ( ) - > MouseX ( ) ;
float my = UI ( ) - > MouseY ( ) ;
2010-05-29 07:25:38 +00:00
static float s_StartWx = 0 ;
static float s_StartWy = 0 ;
2008-01-12 12:27:55 +00:00
enum
2007-05-22 15:03:32 +00:00
{
2020-09-26 19:41:58 +00:00
OP_NONE = 0 ,
2008-01-12 12:27:55 +00:00
OP_BRUSH_GRAB ,
OP_BRUSH_DRAW ,
2010-05-29 07:25:38 +00:00
OP_BRUSH_PAINT ,
2008-01-12 12:27:55 +00:00
OP_PAN_WORLD ,
OP_PAN_EDITOR ,
} ;
// remap the screen so it can display the whole tileset
2011-05-04 23:50:23 +00:00
if ( m_ShowPicker )
2010-05-29 07:25:38 +00:00
{
CUIRect Screen = * UI ( ) - > Screen ( ) ;
2022-03-21 06:10:44 +00:00
float Size = 32.0f * 16.0f ;
2020-09-26 19:41:58 +00:00
float w = Size * ( Screen . w / View . w ) ;
float h = Size * ( Screen . h / View . h ) ;
float x = - ( View . x / Screen . w ) * w ;
float y = - ( View . y / Screen . h ) * h ;
wx = x + w * mx / Screen . w ;
wy = y + h * my / Screen . h ;
2022-06-30 22:36:32 +00:00
CLayerTiles * pTileLayer = ( CLayerTiles * ) GetSelectedLayerType ( 0 , LAYERTYPE_TILES ) ;
if ( pTileLayer )
2008-01-12 12:27:55 +00:00
{
2020-09-26 19:41:58 +00:00
Graphics ( ) - > MapScreen ( x , y , x + w , y + h ) ;
2022-06-30 22:36:32 +00:00
m_TilesetPicker . m_Image = pTileLayer - > m_Image ;
m_TilesetPicker . m_Texture = pTileLayer - > m_Texture ;
2020-09-26 19:41:58 +00:00
if ( m_BrushColorEnabled )
2018-09-11 08:35:02 +00:00
{
2022-06-30 22:36:32 +00:00
m_TilesetPicker . m_Color = pTileLayer - > m_Color ;
2018-09-11 08:35:02 +00:00
m_TilesetPicker . m_Color . a = 255 ;
}
else
{
m_TilesetPicker . m_Color = { 255 , 255 , 255 , 255 } ;
}
2018-08-19 17:05:42 +00:00
2022-06-30 22:36:32 +00:00
m_TilesetPicker . m_Game = pTileLayer - > m_Game ;
m_TilesetPicker . m_Tele = pTileLayer - > m_Tele ;
m_TilesetPicker . m_Speedup = pTileLayer - > m_Speedup ;
m_TilesetPicker . m_Front = pTileLayer - > m_Front ;
m_TilesetPicker . m_Switch = pTileLayer - > m_Switch ;
m_TilesetPicker . m_Tune = pTileLayer - > m_Tune ;
2018-08-19 17:05:42 +00:00
m_TilesetPicker . Render ( true ) ;
2011-02-18 10:41:27 +00:00
if ( m_ShowTileInfo )
m_TilesetPicker . ShowInfo ( ) ;
2008-01-12 12:27:55 +00:00
}
2014-08-20 22:56:35 +00:00
else
{
2022-06-30 22:36:32 +00:00
CLayerQuads * pQuadLayer = ( CLayerQuads * ) GetSelectedLayerType ( 0 , LAYERTYPE_QUADS ) ;
if ( pQuadLayer )
2014-08-20 22:56:35 +00:00
{
2022-06-30 22:36:32 +00:00
m_QuadsetPicker . m_Image = pQuadLayer - > m_Image ;
2022-06-11 19:38:18 +00:00
m_QuadsetPicker . m_vQuads [ 0 ] . m_aPoints [ 0 ] . x = f2fx ( View . x ) ;
m_QuadsetPicker . m_vQuads [ 0 ] . m_aPoints [ 0 ] . y = f2fx ( View . y ) ;
m_QuadsetPicker . m_vQuads [ 0 ] . m_aPoints [ 1 ] . x = f2fx ( ( View . x + View . w ) ) ;
m_QuadsetPicker . m_vQuads [ 0 ] . m_aPoints [ 1 ] . y = f2fx ( View . y ) ;
m_QuadsetPicker . m_vQuads [ 0 ] . m_aPoints [ 2 ] . x = f2fx ( View . x ) ;
m_QuadsetPicker . m_vQuads [ 0 ] . m_aPoints [ 2 ] . y = f2fx ( ( View . y + View . h ) ) ;
m_QuadsetPicker . m_vQuads [ 0 ] . m_aPoints [ 3 ] . x = f2fx ( ( View . x + View . w ) ) ;
m_QuadsetPicker . m_vQuads [ 0 ] . m_aPoints [ 3 ] . y = f2fx ( ( View . y + View . h ) ) ;
m_QuadsetPicker . m_vQuads [ 0 ] . m_aPoints [ 4 ] . x = f2fx ( ( View . x + View . w / 2 ) ) ;
m_QuadsetPicker . m_vQuads [ 0 ] . m_aPoints [ 4 ] . y = f2fx ( ( View . y + View . h / 2 ) ) ;
2014-08-20 22:56:35 +00:00
m_QuadsetPicker . Render ( ) ;
}
}
2007-05-22 15:03:32 +00:00
}
2010-05-29 07:25:38 +00:00
static int s_Operation = OP_NONE ;
2008-01-12 12:27:55 +00:00
// draw layer borders
2022-06-30 22:36:32 +00:00
CLayer * apEditLayers [ 128 ] ;
2022-05-24 09:24:33 +00:00
size_t NumEditLayers = 0 ;
2010-05-29 07:25:38 +00:00
2014-08-24 11:38:46 +00:00
if ( m_ShowPicker & & GetSelectedLayer ( 0 ) & & GetSelectedLayer ( 0 ) - > m_Type = = LAYERTYPE_TILES )
2007-05-22 15:03:32 +00:00
{
2022-06-30 22:36:32 +00:00
apEditLayers [ 0 ] = & m_TilesetPicker ;
2010-05-29 07:25:38 +00:00
NumEditLayers + + ;
2007-05-22 15:03:32 +00:00
}
2018-03-13 20:59:07 +00:00
else if ( m_ShowPicker )
2014-08-20 22:56:35 +00:00
{
2022-06-30 22:36:32 +00:00
apEditLayers [ 0 ] = & m_QuadsetPicker ;
2014-08-20 22:56:35 +00:00
NumEditLayers + + ;
}
2007-05-22 15:03:32 +00:00
else
2008-01-12 12:27:55 +00:00
{
2018-07-26 08:14:14 +00:00
// pick a type of layers to edit, prefering Tiles layers.
int EditingType = - 1 ;
2022-06-11 19:38:18 +00:00
for ( size_t i = 0 ; i < m_vSelectedLayers . size ( ) ; i + + )
2018-07-25 20:57:58 +00:00
{
2022-06-30 22:36:32 +00:00
CLayer * pLayer = GetSelectedLayer ( i ) ;
if ( pLayer & & ( EditingType = = - 1 | | pLayer - > m_Type = = LAYERTYPE_TILES ) )
2018-07-26 08:14:14 +00:00
{
2022-06-30 22:36:32 +00:00
EditingType = pLayer - > m_Type ;
2018-07-26 08:14:14 +00:00
if ( EditingType = = LAYERTYPE_TILES )
break ;
}
}
2022-06-11 19:38:18 +00:00
for ( size_t i = 0 ; i < m_vSelectedLayers . size ( ) & & NumEditLayers < 128 ; i + + )
2018-07-26 08:14:14 +00:00
{
2022-06-30 22:36:32 +00:00
apEditLayers [ NumEditLayers ] = GetSelectedLayerType ( i , EditingType ) ;
if ( apEditLayers [ NumEditLayers ] )
2018-07-26 08:14:14 +00:00
{
2018-07-25 20:57:58 +00:00
NumEditLayers + + ;
2018-07-26 08:14:14 +00:00
}
2018-07-25 20:57:58 +00:00
}
2008-01-12 12:27:55 +00:00
2022-06-30 22:36:32 +00:00
CLayerGroup * pGroup = GetSelectedGroup ( ) ;
if ( pGroup )
2008-01-12 12:27:55 +00:00
{
2022-06-30 22:36:32 +00:00
pGroup - > MapScreen ( ) ;
2010-05-29 07:25:38 +00:00
2022-06-30 22:36:32 +00:00
RenderGrid ( pGroup ) ;
2011-07-10 20:16:16 +00:00
2022-05-24 09:24:33 +00:00
for ( size_t i = 0 ; i < NumEditLayers ; i + + )
2008-01-12 12:27:55 +00:00
{
2022-06-30 22:36:32 +00:00
if ( apEditLayers [ i ] - > m_Type ! = LAYERTYPE_TILES )
2008-01-12 12:27:55 +00:00
continue ;
2010-05-29 07:25:38 +00:00
2008-01-12 12:27:55 +00:00
float w , h ;
2022-06-30 22:36:32 +00:00
apEditLayers [ i ] - > GetSize ( & w , & h ) ;
2008-01-12 12:27:55 +00:00
2010-05-29 07:25:38 +00:00
IGraphics : : CLineItem Array [ 4 ] = {
IGraphics : : CLineItem ( 0 , 0 , w , 0 ) ,
IGraphics : : CLineItem ( w , 0 , w , h ) ,
IGraphics : : CLineItem ( w , h , 0 , h ) ,
IGraphics : : CLineItem ( 0 , h , 0 , 0 ) } ;
2012-08-12 10:41:50 +00:00
Graphics ( ) - > TextureClear ( ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > LinesBegin ( ) ;
2010-05-29 07:25:38 +00:00
Graphics ( ) - > LinesDraw ( Array , 4 ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > LinesEnd ( ) ;
2008-01-12 12:27:55 +00:00
}
}
}
2010-05-29 07:25:38 +00:00
if ( Inside )
2008-01-12 12:27:55 +00:00
{
2011-02-12 10:40:36 +00:00
UI ( ) - > SetHotItem ( s_pEditorID ) ;
2010-05-29 07:25:38 +00:00
2008-01-12 12:27:55 +00:00
// do global operations like pan and zoom
2022-05-27 08:55:32 +00:00
if ( UI ( ) - > CheckActiveItem ( nullptr ) & & ( UI ( ) - > MouseButton ( 0 ) | | UI ( ) - > MouseButton ( 2 ) ) )
2008-01-12 12:27:55 +00:00
{
2010-05-29 07:25:38 +00:00
s_StartWx = wx ;
s_StartWy = wy ;
2021-12-18 11:23:20 +00:00
if ( Input ( ) - > ModifierIsPressed ( ) | | UI ( ) - > MouseButton ( 2 ) )
2008-01-12 12:27:55 +00:00
{
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) )
2010-05-29 07:25:38 +00:00
s_Operation = OP_PAN_EDITOR ;
2008-01-12 12:27:55 +00:00
else
2010-05-29 07:25:38 +00:00
s_Operation = OP_PAN_WORLD ;
2011-02-12 10:40:36 +00:00
UI ( ) - > SetActiveItem ( s_pEditorID ) ;
2008-01-12 12:27:55 +00:00
}
2014-09-22 20:25:05 +00:00
else
s_Operation = OP_NONE ;
2008-01-12 12:27:55 +00:00
}
// brush editing
2011-02-12 10:40:36 +00:00
if ( UI ( ) - > HotItem ( ) = = s_pEditorID )
2008-01-12 12:27:55 +00:00
{
2019-04-08 17:39:55 +00:00
int Layer = NUM_LAYERS ;
if ( m_ShowPicker )
{
CLayer * pLayer = GetSelectedLayer ( 0 ) ;
if ( pLayer = = m_Map . m_pGameLayer )
Layer = LAYER_GAME ;
else if ( pLayer = = m_Map . m_pFrontLayer )
Layer = LAYER_FRONT ;
else if ( pLayer = = m_Map . m_pSwitchLayer )
Layer = LAYER_SWITCH ;
else if ( pLayer = = m_Map . m_pTeleLayer )
Layer = LAYER_TELE ;
else if ( pLayer = = m_Map . m_pSpeedupLayer )
Layer = LAYER_SPEEDUP ;
else if ( pLayer = = m_Map . m_pTuneLayer )
Layer = LAYER_TUNE ;
}
if ( m_ShowPicker & & Layer ! = NUM_LAYERS )
2021-08-27 14:06:27 +00:00
{
if ( m_SelectEntitiesImage = = " DDNet " )
m_pTooltip = Explain ( EXPLANATION_DDNET , ( int ) wx / 32 + ( int ) wy / 32 * 16 , Layer ) ;
else if ( m_SelectEntitiesImage = = " FNG " )
m_pTooltip = Explain ( EXPLANATION_FNG , ( int ) wx / 32 + ( int ) wy / 32 * 16 , Layer ) ;
2021-08-28 17:51:38 +00:00
else if ( m_SelectEntitiesImage = = " Vanilla " )
m_pTooltip = Explain ( EXPLANATION_VANILLA , ( int ) wx / 32 + ( int ) wy / 32 * 16 , Layer ) ;
2021-08-27 14:06:27 +00:00
}
2019-04-08 17:39:55 +00:00
else if ( m_Brush . IsEmpty ( ) )
2022-04-11 09:28:05 +00:00
m_pTooltip = " Use left mouse button to drag and create a brush. Hold shift to select multiple quads. Use ctrl+right mouse to select layer. " ;
2008-01-12 12:27:55 +00:00
else
2011-03-20 16:04:03 +00:00
m_pTooltip = " Use left mouse button to paint with the brush. Right button clears the brush. " ;
2008-01-12 12:27:55 +00:00
2022-05-27 08:55:32 +00:00
if ( UI ( ) - > CheckActiveItem ( s_pEditorID ) )
2008-01-12 12:27:55 +00:00
{
2009-10-27 14:38:53 +00:00
CUIRect r ;
2010-05-29 07:25:38 +00:00
r . x = s_StartWx ;
r . y = s_StartWy ;
2020-09-26 19:41:58 +00:00
r . w = wx - s_StartWx ;
r . h = wy - s_StartWy ;
2008-01-12 12:27:55 +00:00
if ( r . w < 0 )
{
r . x + = r . w ;
r . w = - r . w ;
}
if ( r . h < 0 )
{
r . y + = r . h ;
r . h = - r . h ;
}
2010-05-29 07:25:38 +00:00
if ( s_Operation = = OP_BRUSH_DRAW )
{
if ( ! m_Brush . IsEmpty ( ) )
2008-01-12 12:27:55 +00:00
{
// draw with brush
2022-05-24 09:24:33 +00:00
for ( size_t k = 0 ; k < NumEditLayers ; k + + )
2008-01-12 12:27:55 +00:00
{
2022-06-11 19:38:18 +00:00
size_t BrushIndex = k % m_Brush . m_vpLayers . size ( ) ;
2022-06-30 22:36:32 +00:00
if ( apEditLayers [ k ] - > m_Type = = m_Brush . m_vpLayers [ BrushIndex ] - > m_Type )
2019-02-11 08:41:26 +00:00
{
2022-06-30 22:36:32 +00:00
if ( apEditLayers [ k ] - > m_Type = = LAYERTYPE_TILES )
2019-02-11 08:41:26 +00:00
{
2022-06-30 22:36:32 +00:00
CLayerTiles * pLayer = ( CLayerTiles * ) apEditLayers [ k ] ;
CLayerTiles * pBrushLayer = ( CLayerTiles * ) m_Brush . m_vpLayers [ BrushIndex ] ;
2019-02-11 08:41:26 +00:00
2022-06-30 22:36:32 +00:00
if ( pLayer - > m_Tele < = pBrushLayer - > m_Tele & & pLayer - > m_Speedup < = pBrushLayer - > m_Speedup & & pLayer - > m_Front < = pBrushLayer - > m_Front & & pLayer - > m_Game < = pBrushLayer - > m_Game & & pLayer - > m_Switch < = pBrushLayer - > m_Switch & & pLayer - > m_Tune < = pBrushLayer - > m_Tune )
pLayer - > BrushDraw ( pBrushLayer , wx , wy ) ;
2019-02-11 08:41:26 +00:00
}
else
{
2022-06-30 22:36:32 +00:00
apEditLayers [ k ] - > BrushDraw ( m_Brush . m_vpLayers [ BrushIndex ] , wx , wy ) ;
2019-02-11 08:41:26 +00:00
}
}
2008-01-12 12:27:55 +00:00
}
}
}
2010-05-29 07:25:38 +00:00
else if ( s_Operation = = OP_BRUSH_GRAB )
2008-01-12 12:27:55 +00:00
{
2009-10-27 14:38:53 +00:00
if ( ! UI ( ) - > MouseButton ( 0 ) )
2008-01-12 12:27:55 +00:00
{
2018-08-13 09:11:56 +00:00
if ( Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) )
{
2022-06-30 22:36:32 +00:00
CLayerQuads * pQuadLayer = ( CLayerQuads * ) GetSelectedLayerType ( 0 , LAYERTYPE_QUADS ) ;
if ( pQuadLayer )
2018-08-13 09:11:56 +00:00
{
2022-06-30 22:36:32 +00:00
for ( size_t i = 0 ; i < pQuadLayer - > m_vQuads . size ( ) ; i + + )
2018-08-13 09:11:56 +00:00
{
2022-06-30 22:36:32 +00:00
CQuad * pQuad = & pQuadLayer - > m_vQuads [ i ] ;
float px = fx2f ( pQuad - > m_aPoints [ 4 ] . x ) ;
float py = fx2f ( pQuad - > m_aPoints [ 4 ] . y ) ;
2010-05-29 07:25:38 +00:00
2020-09-26 19:41:58 +00:00
if ( px > r . x & & px < r . x + r . w & & py > r . y & & py < r . y + r . h )
2018-08-13 09:11:56 +00:00
if ( ! IsQuadSelected ( i ) )
2022-06-11 19:38:18 +00:00
m_vSelectedQuads . push_back ( i ) ;
2018-08-13 09:11:56 +00:00
}
}
}
else
{
// grab brush
char aBuf [ 256 ] ;
2020-09-26 19:41:58 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " grabbing %f %f %f %f " , r . x , r . y , r . w , r . h ) ;
2018-08-13 09:11:56 +00:00
Console ( ) - > Print ( IConsole : : OUTPUT_LEVEL_DEBUG , " editor " , aBuf ) ;
// TODO: do all layers
int Grabs = 0 ;
2022-05-24 09:24:33 +00:00
for ( size_t k = 0 ; k < NumEditLayers ; k + + )
2022-06-30 22:36:32 +00:00
Grabs + = apEditLayers [ k ] - > BrushGrab ( & m_Brush , r ) ;
2018-08-13 09:11:56 +00:00
if ( Grabs = = 0 )
m_Brush . Clear ( ) ;
2022-06-11 19:38:18 +00:00
for ( auto & pLayer : m_Brush . m_vpLayers )
2022-05-24 09:24:33 +00:00
pLayer - > m_BrushRefCount = 1 ;
2018-10-02 01:52:01 +00:00
2022-06-11 19:38:18 +00:00
m_vSelectedQuads . clear ( ) ;
2018-08-13 09:11:56 +00:00
m_SelectedPoints = 0 ;
}
2008-01-12 12:27:55 +00:00
}
else
{
2008-01-17 23:09:49 +00:00
//editor.map.groups[selected_group]->mapscreen();
2022-05-24 09:24:33 +00:00
for ( size_t k = 0 ; k < NumEditLayers ; k + + )
2022-06-30 22:36:32 +00:00
apEditLayers [ k ] - > BrushSelecting ( r ) ;
2021-09-22 19:48:55 +00:00
UI ( ) - > MapScreen ( ) ;
2008-01-12 12:27:55 +00:00
}
}
2010-05-29 07:25:38 +00:00
else if ( s_Operation = = OP_BRUSH_PAINT )
2008-01-12 12:27:55 +00:00
{
2010-05-29 07:25:38 +00:00
if ( ! UI ( ) - > MouseButton ( 0 ) )
{
2022-05-24 09:24:33 +00:00
for ( size_t k = 0 ; k < NumEditLayers ; k + + )
2018-07-25 20:57:58 +00:00
{
2022-05-24 09:24:33 +00:00
size_t BrushIndex = k ;
2022-06-11 19:38:18 +00:00
if ( m_Brush . m_vpLayers . size ( ) ! = NumEditLayers )
2020-09-26 19:41:58 +00:00
BrushIndex = 0 ;
2022-07-12 17:35:43 +00:00
if ( BrushIndex < m_Brush . m_vpLayers . size ( ) )
apEditLayers [ k ] - > FillSelection ( m_Brush . IsEmpty ( ) , m_Brush . m_vpLayers [ BrushIndex ] , r ) ;
2018-07-25 20:57:58 +00:00
}
2010-05-29 07:25:38 +00:00
}
2008-01-12 12:27:55 +00:00
else
{
2010-05-29 07:25:38 +00:00
//editor.map.groups[selected_group]->mapscreen();
2022-05-24 09:24:33 +00:00
for ( size_t k = 0 ; k < NumEditLayers ; k + + )
2022-06-30 22:36:32 +00:00
apEditLayers [ k ] - > BrushSelecting ( r ) ;
2021-09-22 19:48:55 +00:00
UI ( ) - > MapScreen ( ) ;
2010-05-29 07:25:38 +00:00
}
}
}
else
{
2015-07-22 22:43:09 +00:00
if ( UI ( ) - > MouseButton ( 1 ) )
2018-10-02 01:52:01 +00:00
{
2022-06-11 19:38:18 +00:00
for ( auto & pLayer : m_Brush . m_vpLayers )
2018-10-02 01:52:01 +00:00
{
2022-05-24 09:24:33 +00:00
if ( pLayer - > m_BrushRefCount = = 1 )
delete pLayer ;
2018-10-02 01:52:01 +00:00
}
2010-05-29 07:25:38 +00:00
m_Brush . Clear ( ) ;
2018-10-02 01:52:01 +00:00
}
2010-05-29 07:25:38 +00:00
2022-02-26 17:49:06 +00:00
if ( UI ( ) - > MouseButton ( 0 ) & & s_Operation = = OP_NONE & & ! m_QuadKnifeActive )
2010-05-29 07:25:38 +00:00
{
2011-02-12 10:40:36 +00:00
UI ( ) - > SetActiveItem ( s_pEditorID ) ;
2010-05-29 07:25:38 +00:00
if ( m_Brush . IsEmpty ( ) )
s_Operation = OP_BRUSH_GRAB ;
else
{
s_Operation = OP_BRUSH_DRAW ;
2022-05-24 09:24:33 +00:00
for ( size_t k = 0 ; k < NumEditLayers ; k + + )
2008-01-12 12:27:55 +00:00
{
2022-05-24 09:24:33 +00:00
size_t BrushIndex = k ;
2022-06-11 19:38:18 +00:00
if ( m_Brush . m_vpLayers . size ( ) ! = NumEditLayers )
2020-09-26 19:41:58 +00:00
BrushIndex = 0 ;
2022-06-30 22:36:32 +00:00
if ( apEditLayers [ k ] - > m_Type = = m_Brush . m_vpLayers [ BrushIndex ] - > m_Type )
apEditLayers [ k ] - > BrushPlace ( m_Brush . m_vpLayers [ BrushIndex ] , wx , wy ) ;
2008-01-12 12:27:55 +00:00
}
}
2011-08-11 08:59:14 +00:00
2020-09-26 19:41:58 +00:00
CLayerTiles * pLayer = ( CLayerTiles * ) GetSelectedLayerType ( 0 , LAYERTYPE_TILES ) ;
2016-04-30 18:11:26 +00:00
if ( ( Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) | | Input ( ) - > KeyIsPressed ( KEY_RSHIFT ) ) & & pLayer )
2011-08-11 08:59:14 +00:00
s_Operation = OP_BRUSH_PAINT ;
2008-01-12 12:27:55 +00:00
}
2010-05-29 07:25:38 +00:00
if ( ! m_Brush . IsEmpty ( ) )
2008-01-12 12:27:55 +00:00
{
2010-05-29 07:25:38 +00:00
m_Brush . m_OffsetX = - ( int ) wx ;
m_Brush . m_OffsetY = - ( int ) wy ;
2022-06-11 19:38:18 +00:00
for ( const auto & pLayer : m_Brush . m_vpLayers )
2008-01-12 12:27:55 +00:00
{
2022-05-24 09:24:33 +00:00
if ( pLayer - > m_Type = = LAYERTYPE_TILES )
2008-01-12 12:27:55 +00:00
{
2020-09-26 19:41:58 +00:00
m_Brush . m_OffsetX = - ( int ) ( wx / 32.0f ) * 32 ;
m_Brush . m_OffsetY = - ( int ) ( wy / 32.0f ) * 32 ;
2008-01-12 12:27:55 +00:00
break ;
}
}
2010-05-29 07:25:38 +00:00
2022-06-30 22:36:32 +00:00
CLayerGroup * pGroup = GetSelectedGroup ( ) ;
if ( ! m_ShowPicker & & pGroup )
2010-06-25 16:56:58 +00:00
{
2022-06-30 22:36:32 +00:00
m_Brush . m_OffsetX + = pGroup - > m_OffsetX ;
m_Brush . m_OffsetY + = pGroup - > m_OffsetY ;
m_Brush . m_ParallaxX = pGroup - > m_ParallaxX ;
m_Brush . m_ParallaxY = pGroup - > m_ParallaxY ;
2022-08-06 01:30:37 +00:00
m_Brush . m_ParallaxZoom = pGroup - > m_ParallaxZoom ;
2010-06-25 16:56:58 +00:00
m_Brush . Render ( ) ;
float w , h ;
m_Brush . GetSize ( & w , & h ) ;
IGraphics : : CLineItem Array [ 4 ] = {
IGraphics : : CLineItem ( 0 , 0 , w , 0 ) ,
IGraphics : : CLineItem ( w , 0 , w , h ) ,
IGraphics : : CLineItem ( w , h , 0 , h ) ,
IGraphics : : CLineItem ( 0 , h , 0 , 0 ) } ;
2012-08-12 10:41:50 +00:00
Graphics ( ) - > TextureClear ( ) ;
2010-06-25 16:56:58 +00:00
Graphics ( ) - > LinesBegin ( ) ;
Graphics ( ) - > LinesDraw ( Array , 4 ) ;
Graphics ( ) - > LinesEnd ( ) ;
}
2008-01-12 12:27:55 +00:00
}
}
}
2010-05-29 07:25:38 +00:00
2014-10-10 17:11:21 +00:00
// quad & sound editing
2008-01-12 12:27:55 +00:00
{
2011-05-04 23:50:23 +00:00
if ( ! m_ShowPicker & & m_Brush . IsEmpty ( ) )
2008-01-12 12:27:55 +00:00
{
2008-01-13 22:03:32 +00:00
// fetch layers
2022-06-30 22:36:32 +00:00
CLayerGroup * pGroup = GetSelectedGroup ( ) ;
if ( pGroup )
pGroup - > MapScreen ( ) ;
2010-05-29 07:25:38 +00:00
2022-05-24 09:24:33 +00:00
for ( size_t k = 0 ; k < NumEditLayers ; k + + )
2008-01-12 12:27:55 +00:00
{
2022-06-30 22:36:32 +00:00
if ( apEditLayers [ k ] - > m_Type = = LAYERTYPE_QUADS )
2008-01-12 12:27:55 +00:00
{
2022-06-30 22:36:32 +00:00
CLayerQuads * pLayer = ( CLayerQuads * ) apEditLayers [ k ] ;
2010-05-29 07:25:38 +00:00
2011-08-15 18:12:31 +00:00
if ( ! m_ShowEnvelopePreview )
m_ShowEnvelopePreview = 2 ;
2010-05-29 07:25:38 +00:00
2022-02-26 17:49:06 +00:00
if ( m_QuadKnifeActive )
2022-06-11 19:38:18 +00:00
DoQuadKnife ( m_vSelectedQuads [ m_SelectedQuadIndex ] ) ;
2022-02-26 17:49:06 +00:00
else
2008-01-13 22:03:32 +00:00
{
2022-02-26 17:49:06 +00:00
Graphics ( ) - > TextureClear ( ) ;
Graphics ( ) - > QuadsBegin ( ) ;
2022-06-11 19:38:18 +00:00
for ( size_t i = 0 ; i < pLayer - > m_vQuads . size ( ) ; i + + )
2022-02-26 17:49:06 +00:00
{
for ( int v = 0 ; v < 4 ; v + + )
2022-06-11 19:38:18 +00:00
DoQuadPoint ( & pLayer - > m_vQuads [ i ] , i , v ) ;
2010-05-29 07:25:38 +00:00
2022-06-11 19:38:18 +00:00
DoQuad ( & pLayer - > m_vQuads [ i ] , i ) ;
2022-02-26 17:49:06 +00:00
}
Graphics ( ) - > QuadsEnd ( ) ;
2008-01-13 22:03:32 +00:00
}
2008-01-12 12:27:55 +00:00
}
2014-10-10 17:11:21 +00:00
2022-06-30 22:36:32 +00:00
if ( apEditLayers [ k ] - > m_Type = = LAYERTYPE_SOUNDS )
2014-10-10 17:11:21 +00:00
{
2022-06-30 22:36:32 +00:00
CLayerSounds * pLayer = ( CLayerSounds * ) apEditLayers [ k ] ;
2014-10-10 17:11:21 +00:00
2012-08-12 10:41:50 +00:00
Graphics ( ) - > TextureClear ( ) ;
2014-10-10 17:11:21 +00:00
Graphics ( ) - > QuadsBegin ( ) ;
2022-06-11 19:38:18 +00:00
for ( size_t i = 0 ; i < pLayer - > m_vSources . size ( ) ; i + + )
2014-10-10 17:11:21 +00:00
{
2022-06-11 19:38:18 +00:00
DoSoundSource ( & pLayer - > m_vSources [ i ] , i ) ;
2014-10-10 17:11:21 +00:00
}
Graphics ( ) - > QuadsEnd ( ) ;
}
2008-01-12 12:27:55 +00:00
}
2010-05-29 07:25:38 +00:00
2021-09-22 19:48:55 +00:00
UI ( ) - > MapScreen ( ) ;
2010-05-29 07:25:38 +00:00
}
2014-10-10 17:11:21 +00:00
}
2010-05-29 07:25:38 +00:00
2014-10-10 17:11:21 +00:00
// do panning
2022-05-27 08:55:32 +00:00
if ( UI ( ) - > CheckActiveItem ( s_pEditorID ) )
2014-10-10 17:11:21 +00:00
{
if ( s_Operation = = OP_PAN_WORLD )
2008-01-12 12:27:55 +00:00
{
2022-08-06 15:33:58 +00:00
m_WorldOffsetX - = m_MouseDeltaX * m_MouseWScale ;
m_WorldOffsetY - = m_MouseDeltaY * m_MouseWScale ;
2014-10-10 17:11:21 +00:00
}
else if ( s_Operation = = OP_PAN_EDITOR )
{
2022-08-06 15:33:58 +00:00
m_EditorOffsetX - = m_MouseDeltaX * m_MouseWScale ;
m_EditorOffsetY - = m_MouseDeltaY * m_MouseWScale ;
2014-10-10 17:11:21 +00:00
}
2008-01-12 12:27:55 +00:00
2014-10-10 17:11:21 +00:00
// release mouse
if ( ! UI ( ) - > MouseButton ( 0 ) )
{
s_Operation = OP_NONE ;
2022-05-27 09:59:14 +00:00
UI ( ) - > SetActiveItem ( nullptr ) ;
2008-01-13 22:03:32 +00:00
}
2008-01-12 12:27:55 +00:00
}
2021-11-06 15:44:40 +00:00
if ( ! Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) & & ! Input ( ) - > KeyIsPressed ( KEY_RSHIFT ) & &
2021-12-18 11:23:20 +00:00
! Input ( ) - > ModifierIsPressed ( ) & &
2021-11-20 09:42:28 +00:00
m_Dialog = = DIALOG_NONE & & m_EditBoxActive = = 0 )
2021-11-06 15:44:40 +00:00
{
float PanSpeed = 64.0f ;
if ( Input ( ) - > KeyPress ( KEY_A ) )
2022-08-06 15:33:58 +00:00
m_WorldOffsetX - = PanSpeed * m_MouseWScale ;
2021-11-06 15:44:40 +00:00
else if ( Input ( ) - > KeyPress ( KEY_D ) )
2022-08-06 15:33:58 +00:00
m_WorldOffsetX + = PanSpeed * m_MouseWScale ;
2021-11-06 15:44:40 +00:00
if ( Input ( ) - > KeyPress ( KEY_W ) )
2022-08-06 15:33:58 +00:00
m_WorldOffsetY - = PanSpeed * m_MouseWScale ;
2021-11-06 15:44:40 +00:00
else if ( Input ( ) - > KeyPress ( KEY_S ) )
2022-08-06 15:33:58 +00:00
m_WorldOffsetY + = PanSpeed * m_MouseWScale ;
2021-11-06 15:44:40 +00:00
}
2008-01-12 12:27:55 +00:00
}
2022-05-27 08:55:32 +00:00
else if ( UI ( ) - > CheckActiveItem ( s_pEditorID ) )
2010-06-20 13:27:44 +00:00
{
// release mouse
if ( ! UI ( ) - > MouseButton ( 0 ) )
{
s_Operation = OP_NONE ;
2022-05-27 09:59:14 +00:00
UI ( ) - > SetActiveItem ( nullptr ) ;
2010-06-20 13:27:44 +00:00
}
}
2010-05-29 07:25:38 +00:00
2012-01-08 00:14:52 +00:00
if ( ! m_ShowPicker & & GetSelectedGroup ( ) & & GetSelectedGroup ( ) - > m_UseClipping )
2008-03-29 11:44:03 +00:00
{
2022-06-30 22:36:32 +00:00
CLayerGroup * pGameGroup = m_Map . m_pGameGroup ;
pGameGroup - > MapScreen ( ) ;
2011-08-11 08:59:14 +00:00
2012-08-12 10:41:50 +00:00
Graphics ( ) - > TextureClear ( ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > LinesBegin ( ) ;
2020-09-26 19:41:58 +00:00
CUIRect r ;
r . x = GetSelectedGroup ( ) - > m_ClipX ;
r . y = GetSelectedGroup ( ) - > m_ClipY ;
r . w = GetSelectedGroup ( ) - > m_ClipW ;
r . h = GetSelectedGroup ( ) - > m_ClipH ;
IGraphics : : CLineItem Array [ 4 ] = {
IGraphics : : CLineItem ( r . x , r . y , r . x + r . w , r . y ) ,
IGraphics : : CLineItem ( r . x + r . w , r . y , r . x + r . w , r . y + r . h ) ,
IGraphics : : CLineItem ( r . x + r . w , r . y + r . h , r . x , r . y + r . h ) ,
IGraphics : : CLineItem ( r . x , r . y + r . h , r . x , r . y ) } ;
Graphics ( ) - > SetColor ( 1 , 0 , 0 , 1 ) ;
Graphics ( ) - > LinesDraw ( Array , 4 ) ;
2010-05-29 07:25:38 +00:00
2009-10-27 14:38:53 +00:00
Graphics ( ) - > LinesEnd ( ) ;
2008-03-29 11:44:03 +00:00
}
2008-01-12 12:27:55 +00:00
2010-05-29 07:25:38 +00:00
// render screen sizes
2014-08-20 22:05:44 +00:00
if ( m_ProofBorders & & ! m_ShowPicker )
2008-01-12 12:27:55 +00:00
{
2022-06-30 22:36:32 +00:00
CLayerGroup * pGameGroup = m_Map . m_pGameGroup ;
pGameGroup - > MapScreen ( ) ;
2010-05-29 07:25:38 +00:00
2012-08-12 10:41:50 +00:00
Graphics ( ) - > TextureClear ( ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > LinesBegin ( ) ;
2010-05-29 07:25:38 +00:00
2016-07-18 06:55:35 +00:00
// possible screen sizes (white border)
2010-05-29 07:25:38 +00:00
float aLastPoints [ 4 ] ;
float Start = 1.0f ; //9.0f/16.0f;
2020-09-26 19:41:58 +00:00
float End = 16.0f / 9.0f ;
2010-05-29 07:25:38 +00:00
const int NumSteps = 20 ;
for ( int i = 0 ; i < = NumSteps ; i + + )
2008-01-12 12:27:55 +00:00
{
2010-05-29 07:25:38 +00:00
float aPoints [ 4 ] ;
2020-09-26 19:41:58 +00:00
float Aspect = Start + ( End - Start ) * ( i / ( float ) NumSteps ) ;
2010-05-29 07:25:38 +00:00
2022-05-17 13:00:06 +00:00
RenderTools ( ) - > MapScreenToWorld (
2010-05-29 07:25:38 +00:00
m_WorldOffsetX , m_WorldOffsetY ,
2022-08-04 23:16:44 +00:00
100.0f , 100.0f , 100.0f , 0.0f , 0.0f , Aspect , 1.0f , aPoints ) ;
2010-05-29 07:25:38 +00:00
2008-01-12 12:27:55 +00:00
if ( i = = 0 )
{
2010-05-29 07:25:38 +00:00
IGraphics : : CLineItem Array [ 2 ] = {
IGraphics : : CLineItem ( aPoints [ 0 ] , aPoints [ 1 ] , aPoints [ 2 ] , aPoints [ 1 ] ) ,
IGraphics : : CLineItem ( aPoints [ 0 ] , aPoints [ 3 ] , aPoints [ 2 ] , aPoints [ 3 ] ) } ;
Graphics ( ) - > LinesDraw ( Array , 2 ) ;
2008-01-12 12:27:55 +00:00
}
if ( i ! = 0 )
{
2010-05-29 07:25:38 +00:00
IGraphics : : CLineItem Array [ 4 ] = {
IGraphics : : CLineItem ( aPoints [ 0 ] , aPoints [ 1 ] , aLastPoints [ 0 ] , aLastPoints [ 1 ] ) ,
IGraphics : : CLineItem ( aPoints [ 2 ] , aPoints [ 1 ] , aLastPoints [ 2 ] , aLastPoints [ 1 ] ) ,
IGraphics : : CLineItem ( aPoints [ 0 ] , aPoints [ 3 ] , aLastPoints [ 0 ] , aLastPoints [ 3 ] ) ,
IGraphics : : CLineItem ( aPoints [ 2 ] , aPoints [ 3 ] , aLastPoints [ 2 ] , aLastPoints [ 3 ] ) } ;
Graphics ( ) - > LinesDraw ( Array , 4 ) ;
2008-01-12 12:27:55 +00:00
}
2010-05-29 07:25:38 +00:00
if ( i = = NumSteps )
2008-01-12 12:27:55 +00:00
{
2010-05-29 07:25:38 +00:00
IGraphics : : CLineItem Array [ 2 ] = {
IGraphics : : CLineItem ( aPoints [ 0 ] , aPoints [ 1 ] , aPoints [ 0 ] , aPoints [ 3 ] ) ,
IGraphics : : CLineItem ( aPoints [ 2 ] , aPoints [ 1 ] , aPoints [ 2 ] , aPoints [ 3 ] ) } ;
Graphics ( ) - > LinesDraw ( Array , 2 ) ;
2008-01-12 12:27:55 +00:00
}
2010-05-29 07:25:38 +00:00
mem_copy ( aLastPoints , aPoints , sizeof ( aPoints ) ) ;
2008-01-12 12:27:55 +00:00
}
2016-07-18 06:55:35 +00:00
// two screen sizes (green and red border)
2008-01-12 12:27:55 +00:00
{
2020-09-26 19:41:58 +00:00
Graphics ( ) - > SetColor ( 1 , 0 , 0 , 1 ) ;
2008-01-17 23:09:49 +00:00
for ( int i = 0 ; i < 2 ; i + + )
2008-01-12 12:27:55 +00:00
{
2010-05-29 07:25:38 +00:00
float aPoints [ 4 ] ;
2020-09-26 19:41:58 +00:00
float aAspects [ ] = { 4.0f / 3.0f , 16.0f / 10.0f , 5.0f / 4.0f , 16.0f / 9.0f } ;
2010-05-29 07:25:38 +00:00
float Aspect = aAspects [ i ] ;
2022-05-17 13:00:06 +00:00
RenderTools ( ) - > MapScreenToWorld (
2010-05-29 07:25:38 +00:00
m_WorldOffsetX , m_WorldOffsetY ,
2022-08-04 23:16:44 +00:00
100.0f , 100.0f , 100.0f , 0.0f , 0.0f , Aspect , 1.0f , aPoints ) ;
2010-05-29 07:25:38 +00:00
2009-10-27 14:38:53 +00:00
CUIRect r ;
2010-05-29 07:25:38 +00:00
r . x = aPoints [ 0 ] ;
r . y = aPoints [ 1 ] ;
2020-09-26 19:41:58 +00:00
r . w = aPoints [ 2 ] - aPoints [ 0 ] ;
r . h = aPoints [ 3 ] - aPoints [ 1 ] ;
2010-05-29 07:25:38 +00:00
IGraphics : : CLineItem Array [ 4 ] = {
2020-09-26 19:41:58 +00:00
IGraphics : : CLineItem ( r . x , r . y , r . x + r . w , r . y ) ,
IGraphics : : CLineItem ( r . x + r . w , r . y , r . x + r . w , r . y + r . h ) ,
IGraphics : : CLineItem ( r . x + r . w , r . y + r . h , r . x , r . y + r . h ) ,
IGraphics : : CLineItem ( r . x , r . y + r . h , r . x , r . y ) } ;
2010-05-29 07:25:38 +00:00
Graphics ( ) - > LinesDraw ( Array , 4 ) ;
2020-09-26 19:41:58 +00:00
Graphics ( ) - > SetColor ( 0 , 1 , 0 , 1 ) ;
2008-01-12 12:27:55 +00:00
}
}
2009-10-27 14:38:53 +00:00
Graphics ( ) - > LinesEnd ( ) ;
2016-07-18 06:55:35 +00:00
// tee position (blue circle)
{
2012-08-12 10:41:50 +00:00
Graphics ( ) - > TextureClear ( ) ;
2016-07-18 06:55:35 +00:00
Graphics ( ) - > QuadsBegin ( ) ;
2020-09-26 19:41:58 +00:00
Graphics ( ) - > SetColor ( 0 , 0 , 1 , 0.3f ) ;
RenderTools ( ) - > DrawCircle ( m_WorldOffsetX , m_WorldOffsetY - 3.0f , 20.0f , 32 ) ;
2016-07-18 06:55:35 +00:00
Graphics ( ) - > QuadsEnd ( ) ;
}
2008-01-12 12:27:55 +00:00
}
2010-05-29 07:25:38 +00:00
2018-03-13 20:59:07 +00:00
if ( ! m_ShowPicker & & m_ShowTileInfo & & m_ShowEnvelopePreview ! = 0 & & GetSelectedLayer ( 0 ) & & GetSelectedLayer ( 0 ) - > m_Type = = LAYERTYPE_QUADS )
2011-08-15 18:12:31 +00:00
{
GetSelectedGroup ( ) - > MapScreen ( ) ;
2020-09-26 19:41:58 +00:00
CLayerQuads * pLayer = ( CLayerQuads * ) GetSelectedLayer ( 0 ) ;
2012-08-12 10:41:50 +00:00
IGraphics : : CTextureHandle Texture ;
2022-06-11 19:38:18 +00:00
if ( pLayer - > m_Image > = 0 & & pLayer - > m_Image < ( int ) m_Map . m_vpImages . size ( ) )
Texture = m_Map . m_vpImages [ pLayer - > m_Image ] - > m_Texture ;
2011-08-15 18:12:31 +00:00
2022-06-11 19:38:18 +00:00
DoQuadEnvelopes ( pLayer - > m_vQuads , Texture ) ;
2011-08-15 18:12:31 +00:00
m_ShowEnvelopePreview = 0 ;
2014-01-19 03:02:01 +00:00
}
2011-08-14 14:31:48 +00:00
2021-09-22 19:48:55 +00:00
UI ( ) - > MapScreen ( ) ;
2009-10-27 14:38:53 +00:00
//UI()->ClipDisable();
2007-05-22 15:03:32 +00:00
}
2020-11-07 23:02:34 +00:00
float CEditor : : ScaleFontSize ( char * pText , int TextSize , float FontSize , int Width )
2020-10-04 20:37:48 +00:00
{
2022-06-13 16:28:13 +00:00
while ( TextRender ( ) - > TextWidth ( nullptr , FontSize , pText , - 1 , - 1.0f ) > Width )
2020-10-04 20:37:48 +00:00
{
if ( FontSize > 6.0f )
{
FontSize - - ;
}
else
{
2020-11-07 23:02:34 +00:00
pText [ str_length ( pText ) - 4 ] = ' \0 ' ;
2020-12-31 09:03:15 +00:00
str_append ( pText , " … " , TextSize ) ;
2020-10-04 20:37:48 +00:00
}
}
return FontSize ;
}
2019-04-26 21:47:34 +00:00
int CEditor : : DoProperties ( CUIRect * pToolBox , CProperty * pProps , int * pIDs , int * pNewVal , ColorRGBA Color )
2007-05-22 15:03:32 +00:00
{
2010-05-29 07:25:38 +00:00
int Change = - 1 ;
2008-01-12 12:27:55 +00:00
2010-05-29 07:25:38 +00:00
for ( int i = 0 ; pProps [ i ] . m_pName ; i + + )
2007-05-22 15:03:32 +00:00
{
2010-05-29 07:25:38 +00:00
CUIRect Slot ;
pToolBox - > HSplitTop ( 13.0f , & Slot , pToolBox ) ;
CUIRect Label , Shifter ;
Slot . VSplitMid ( & Label , & Shifter ) ;
Shifter . HMargin ( 1.0f , & Shifter ) ;
2022-03-11 16:34:48 +00:00
UI ( ) - > DoLabel ( & Label , pProps [ i ] . m_pName , 10.0f , TEXTALIGN_LEFT ) ;
2010-05-29 07:25:38 +00:00
if ( pProps [ i ] . m_Type = = PROPTYPE_INT_STEP )
2008-01-12 12:27:55 +00:00
{
2010-05-29 07:25:38 +00:00
CUIRect Inc , Dec ;
char aBuf [ 64 ] ;
Shifter . VSplitRight ( 10.0f , & Shifter , & Inc ) ;
Shifter . VSplitLeft ( 10.0f , & Dec , & Shifter ) ;
2020-09-26 19:41:58 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %d " , pProps [ i ] . m_Value ) ;
int NewValue = UiDoValueSelector ( ( char * ) & pIDs [ i ] , & Shifter , " " , pProps [ i ] . m_Value , pProps [ i ] . m_Min , pProps [ i ] . m_Max , 1 , 1.0f , " Use left mouse button to drag and change the value. Hold shift to be more precise. Rightclick to edit as text. " , false , false , 0 , & Color ) ;
2018-03-13 20:59:07 +00:00
if ( NewValue ! = pProps [ i ] . m_Value )
2016-06-02 11:50:06 +00:00
{
* pNewVal = NewValue ;
Change = i ;
}
2022-06-13 16:28:13 +00:00
if ( DoButton_ButtonDec ( ( char * ) & pIDs [ i ] + 1 , nullptr , 0 , & Dec , 0 , " Decrease " ) )
2008-01-12 12:27:55 +00:00
{
2020-09-26 19:41:58 +00:00
* pNewVal = pProps [ i ] . m_Value - 1 ;
2010-05-29 07:25:38 +00:00
Change = i ;
2008-01-12 12:27:55 +00:00
}
2022-06-13 16:28:13 +00:00
if ( DoButton_ButtonInc ( ( ( char * ) & pIDs [ i ] ) + 2 , nullptr , 0 , & Inc , 0 , " Increase " ) )
2008-01-12 12:27:55 +00:00
{
2020-09-26 19:41:58 +00:00
* pNewVal = pProps [ i ] . m_Value + 1 ;
2010-05-29 07:25:38 +00:00
Change = i ;
2008-01-12 12:27:55 +00:00
}
}
2010-05-29 07:25:38 +00:00
else if ( pProps [ i ] . m_Type = = PROPTYPE_BOOL )
2008-03-21 17:39:09 +00:00
{
2010-05-29 07:25:38 +00:00
CUIRect No , Yes ;
Shifter . VSplitMid ( & No , & Yes ) ;
2011-03-20 16:04:03 +00:00
if ( DoButton_ButtonDec ( & pIDs [ i ] , " No " , ! pProps [ i ] . m_Value , & No , 0 , " " ) )
2008-03-21 17:39:09 +00:00
{
2010-05-29 07:25:38 +00:00
* pNewVal = 0 ;
Change = i ;
2008-03-21 17:39:09 +00:00
}
2020-09-26 19:41:58 +00:00
if ( DoButton_ButtonInc ( ( ( char * ) & pIDs [ i ] ) + 1 , " Yes " , pProps [ i ] . m_Value , & Yes , 0 , " " ) )
2008-03-21 17:39:09 +00:00
{
2010-05-29 07:25:38 +00:00
* pNewVal = 1 ;
Change = i ;
2008-03-21 17:39:09 +00:00
}
2010-05-29 07:25:38 +00:00
}
else if ( pProps [ i ] . m_Type = = PROPTYPE_INT_SCROLL )
2008-01-12 12:27:55 +00:00
{
2015-03-30 09:44:32 +00:00
int NewValue = UiDoValueSelector ( & pIDs [ i ] , & Shifter , " " , pProps [ i ] . m_Value , pProps [ i ] . m_Min , pProps [ i ] . m_Max , 1 , 1.0f , " Use left mouse button to drag and change the value. Hold shift to be more precise. Rightclick to edit as text. " ) ;
2010-05-29 07:25:38 +00:00
if ( NewValue ! = pProps [ i ] . m_Value )
2008-01-12 12:27:55 +00:00
{
2010-05-29 07:25:38 +00:00
* pNewVal = NewValue ;
Change = i ;
2008-01-12 12:27:55 +00:00
}
}
2015-07-08 11:55:02 +00:00
else if ( pProps [ i ] . m_Type = = PROPTYPE_ANGLE_SCROLL )
{
2016-06-02 13:31:12 +00:00
CUIRect Inc , Dec ;
Shifter . VSplitRight ( 10.0f , & Shifter , & Inc ) ;
Shifter . VSplitLeft ( 10.0f , & Dec , & Shifter ) ;
2016-04-30 18:11:26 +00:00
bool Shift = Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) | | Input ( ) - > KeyIsPressed ( KEY_RSHIFT ) ;
2019-09-20 20:57:35 +00:00
int Step = Shift ? 1 : 45 ;
2015-07-15 00:34:50 +00:00
int Value = pProps [ i ] . m_Value ;
2019-09-20 20:57:35 +00:00
int NewValue = UiDoValueSelector ( & pIDs [ i ] , & Shifter , " " , Value , pProps [ i ] . m_Min , pProps [ i ] . m_Max , Shift ? 1 : 45 , Shift ? 1.0f : 10.0f , " Use left mouse button to drag and change the value. Hold shift to be more precise. Rightclick to edit as text. " , false , false , 0 ) ;
2022-06-13 16:28:13 +00:00
if ( DoButton_ButtonDec ( & pIDs [ i ] + 1 , nullptr , 0 , & Dec , 0 , " Decrease " ) )
2016-06-02 13:31:12 +00:00
{
2019-09-20 20:57:35 +00:00
NewValue = ( round_ceil ( ( pProps [ i ] . m_Value / ( float ) Step ) ) - 1 ) * Step ;
if ( NewValue < 0 )
NewValue + = 360 ;
2016-06-02 13:31:12 +00:00
}
2022-06-13 16:28:13 +00:00
if ( DoButton_ButtonInc ( & pIDs [ i ] + 2 , nullptr , 0 , & Inc , 0 , " Increase " ) )
2019-09-20 20:57:35 +00:00
NewValue = ( pProps [ i ] . m_Value + Step ) / Step * Step ;
if ( NewValue ! = pProps [ i ] . m_Value )
2016-06-02 13:31:12 +00:00
{
2019-09-20 20:57:35 +00:00
* pNewVal = NewValue % 360 ;
2016-06-02 13:31:12 +00:00
Change = i ;
}
2015-07-08 11:55:02 +00:00
}
2010-05-29 07:25:38 +00:00
else if ( pProps [ i ] . m_Type = = PROPTYPE_COLOR )
2008-01-12 12:27:55 +00:00
{
2022-06-30 22:36:32 +00:00
static const char * s_apTexts [ 4 ] = { " R " , " G " , " B " , " A " } ;
2010-05-29 07:25:38 +00:00
static int s_aShift [ ] = { 24 , 16 , 8 , 0 } ;
2015-08-22 15:50:34 +00:00
int NewColor = 0 ;
2015-08-17 12:10:08 +00:00
// extra space
CUIRect ColorBox , ColorSlots ;
2020-09-26 19:41:58 +00:00
pToolBox - > HSplitTop ( 3.0f * 13.0f , & Slot , pToolBox ) ;
2015-08-17 12:10:08 +00:00
Slot . VSplitMid ( & ColorBox , & ColorSlots ) ;
ColorBox . HMargin ( 1.0f , & ColorBox ) ;
ColorBox . VMargin ( 6.0f , & ColorBox ) ;
2010-05-29 07:25:38 +00:00
2008-01-12 12:27:55 +00:00
for ( int c = 0 ; c < 4 ; c + + )
{
2020-09-26 19:41:58 +00:00
int v = ( pProps [ i ] . m_Value > > s_aShift [ c ] ) & 0xff ;
2022-06-30 22:36:32 +00:00
NewColor | = UiDoValueSelector ( ( ( char * ) & pIDs [ i ] ) + c , & Shifter , s_apTexts [ c ] , v , 0 , 255 , 1 , 1.0f , " Use left mouse button to drag and change the color value. Hold shift to be more precise. Rightclick to edit as text. " ) < < s_aShift [ c ] ;
2008-01-12 12:27:55 +00:00
if ( c ! = 3 )
{
2015-08-17 12:10:08 +00:00
ColorSlots . HSplitTop ( 13.0f , & Shifter , & ColorSlots ) ;
2010-05-29 07:25:38 +00:00
Shifter . HMargin ( 1.0f , & Shifter ) ;
2008-01-12 12:27:55 +00:00
}
}
2010-05-29 07:25:38 +00:00
2015-08-20 10:51:30 +00:00
// hex
pToolBox - > HSplitTop ( 13.0f , & Slot , pToolBox ) ;
2022-06-13 16:28:13 +00:00
Slot . VSplitMid ( nullptr , & Shifter ) ;
2015-08-20 10:51:30 +00:00
Shifter . HMargin ( 1.0f , & Shifter ) ;
2020-09-26 19:41:58 +00:00
int NewColorHex = pProps [ i ] . m_Value & 0xff ;
NewColorHex | = UiDoValueSelector ( ( ( char * ) & pIDs [ i ] - 1 ) , & Shifter , " " , ( pProps [ i ] . m_Value > > 8 ) & 0xFFFFFF , 0 , 0xFFFFFF , 1 , 1.0f , " Use left mouse button to drag and change the color value. Hold shift to be more precise. Rightclick to edit as text. " , false , true ) < < 8 ;
2015-08-20 10:51:30 +00:00
// color picker
2022-03-20 11:57:50 +00:00
ColorRGBA ColorPick = ColorRGBA (
2020-09-26 19:41:58 +00:00
( ( pProps [ i ] . m_Value > > s_aShift [ 0 ] ) & 0xff ) / 255.0f ,
( ( pProps [ i ] . m_Value > > s_aShift [ 1 ] ) & 0xff ) / 255.0f ,
( ( pProps [ i ] . m_Value > > s_aShift [ 2 ] ) & 0xff ) / 255.0f ,
2015-08-17 12:10:08 +00:00
1.0f ) ;
2017-02-21 16:10:08 +00:00
2015-08-17 12:10:08 +00:00
static int s_ColorPicker , s_ColorPickerID ;
2022-03-20 11:57:50 +00:00
if ( DoButton_ColorPicker ( & s_ColorPicker , & ColorBox , & ColorPick ) )
2015-08-17 12:10:08 +00:00
{
2022-04-04 18:51:19 +00:00
ms_PickerColor = color_cast < ColorHSVA > ( ColorPick ) ;
2015-08-17 12:10:08 +00:00
UiInvokePopupMenu ( & s_ColorPickerID , 0 , UI ( ) - > MouseX ( ) , UI ( ) - > MouseY ( ) , 180 , 150 , PopupColorPicker ) ;
}
if ( UI ( ) - > HotItem ( ) = = & ms_SVPicker | | UI ( ) - > HotItem ( ) = = & ms_HuePicker )
{
2019-04-26 12:06:32 +00:00
ColorRGBA c = color_cast < ColorRGBA > ( ms_PickerColor ) ;
2020-09-26 19:41:58 +00:00
NewColor = ( ( int ) ( c . r * 255.0f ) & 0xff ) < < 24 | ( ( int ) ( c . g * 255.0f ) & 0xff ) < < 16 | ( ( int ) ( c . b * 255.0f ) & 0xff ) < < 8 | ( pProps [ i ] . m_Value & 0xff ) ;
2015-08-17 12:10:08 +00:00
}
2015-08-20 10:51:30 +00:00
//
2010-05-29 07:25:38 +00:00
if ( NewColor ! = pProps [ i ] . m_Value )
2008-01-12 12:27:55 +00:00
{
2010-05-29 07:25:38 +00:00
* pNewVal = NewColor ;
Change = i ;
2008-01-12 12:27:55 +00:00
}
2015-08-20 10:51:30 +00:00
else if ( NewColorHex ! = pProps [ i ] . m_Value )
{
* pNewVal = NewColorHex ;
Change = i ;
}
2008-01-12 12:27:55 +00:00
}
2010-05-29 07:25:38 +00:00
else if ( pProps [ i ] . m_Type = = PROPTYPE_IMAGE )
2008-01-13 22:37:58 +00:00
{
2010-05-29 07:25:38 +00:00
char aBuf [ 64 ] ;
if ( pProps [ i ] . m_Value < 0 )
2011-03-20 16:04:03 +00:00
str_copy ( aBuf , " None " , sizeof ( aBuf ) ) ;
2008-01-17 23:09:49 +00:00
else
2022-06-11 19:38:18 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %s " , m_Map . m_vpImages [ pProps [ i ] . m_Value ] - > m_aName ) ;
2010-05-29 07:25:38 +00:00
2020-11-07 23:02:34 +00:00
float FontSize = ScaleFontSize ( aBuf , sizeof ( aBuf ) , 10.0f , Shifter . w ) ;
2022-06-13 16:28:13 +00:00
if ( DoButton_Ex ( & pIDs [ i ] , aBuf , 0 , & Shifter , 0 , nullptr , CUI : : CORNER_ALL , FontSize ) )
2010-05-29 07:25:38 +00:00
PopupSelectImageInvoke ( pProps [ i ] . m_Value , UI ( ) - > MouseX ( ) , UI ( ) - > MouseY ( ) ) ;
int r = PopupSelectImageResult ( ) ;
2008-01-17 23:09:49 +00:00
if ( r > = - 1 )
2008-01-13 22:37:58 +00:00
{
2010-05-29 07:25:38 +00:00
* pNewVal = r ;
Change = i ;
2008-01-13 22:37:58 +00:00
}
}
2010-10-09 16:38:23 +00:00
else if ( pProps [ i ] . m_Type = = PROPTYPE_SHIFT )
{
CUIRect Left , Right , Up , Down ;
2022-01-26 19:19:44 +00:00
Shifter . VSplitMid ( & Left , & Up , 2.0f ) ;
2010-10-09 16:38:23 +00:00
Left . VSplitLeft ( 10.0f , & Left , & Shifter ) ;
Shifter . VSplitRight ( 10.0f , & Shifter , & Right ) ;
2020-09-26 19:41:58 +00:00
RenderTools ( ) - > DrawUIRect ( & Shifter , ColorRGBA ( 1 , 1 , 1 , 0.5f ) , 0 , 0.0f ) ;
2022-03-11 16:34:48 +00:00
UI ( ) - > DoLabel ( & Shifter , " X " , 10.0f , TEXTALIGN_CENTER ) ;
2010-10-09 16:38:23 +00:00
Up . VSplitLeft ( 10.0f , & Up , & Shifter ) ;
Shifter . VSplitRight ( 10.0f , & Shifter , & Down ) ;
2020-09-26 19:41:58 +00:00
RenderTools ( ) - > DrawUIRect ( & Shifter , ColorRGBA ( 1 , 1 , 1 , 0.5f ) , 0 , 0.0f ) ;
2022-03-11 16:34:48 +00:00
UI ( ) - > DoLabel ( & Shifter , " Y " , 10.0f , TEXTALIGN_CENTER ) ;
2011-03-20 16:04:03 +00:00
if ( DoButton_ButtonDec ( & pIDs [ i ] , " - " , 0 , & Left , 0 , " Left " ) )
2010-10-09 16:38:23 +00:00
{
* pNewVal = 1 ;
Change = i ;
}
2020-09-26 19:41:58 +00:00
if ( DoButton_ButtonInc ( ( ( char * ) & pIDs [ i ] ) + 3 , " + " , 0 , & Right , 0 , " Right " ) )
2010-10-09 16:38:23 +00:00
{
* pNewVal = 2 ;
Change = i ;
}
2020-09-26 19:41:58 +00:00
if ( DoButton_ButtonDec ( ( ( char * ) & pIDs [ i ] ) + 1 , " - " , 0 , & Up , 0 , " Up " ) )
2010-10-09 16:38:23 +00:00
{
* pNewVal = 4 ;
Change = i ;
}
2020-09-26 19:41:58 +00:00
if ( DoButton_ButtonInc ( ( ( char * ) & pIDs [ i ] ) + 2 , " + " , 0 , & Down , 0 , " Down " ) )
2010-10-09 16:38:23 +00:00
{
* pNewVal = 8 ;
Change = i ;
}
}
2014-10-08 15:33:06 +00:00
else if ( pProps [ i ] . m_Type = = PROPTYPE_SOUND )
{
char aBuf [ 64 ] ;
if ( pProps [ i ] . m_Value < 0 )
str_copy ( aBuf , " None " , sizeof ( aBuf ) ) ;
else
2022-06-11 19:38:18 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %s " , m_Map . m_vpSounds [ pProps [ i ] . m_Value ] - > m_aName ) ;
2014-10-08 15:33:06 +00:00
2020-11-07 23:02:34 +00:00
float FontSize = ScaleFontSize ( aBuf , sizeof ( aBuf ) , 10.0f , Shifter . w ) ;
2022-06-13 16:28:13 +00:00
if ( DoButton_Ex ( & pIDs [ i ] , aBuf , 0 , & Shifter , 0 , nullptr , CUI : : CORNER_ALL , FontSize ) )
2014-10-08 15:33:06 +00:00
PopupSelectSoundInvoke ( pProps [ i ] . m_Value , UI ( ) - > MouseX ( ) , UI ( ) - > MouseY ( ) ) ;
int r = PopupSelectSoundResult ( ) ;
if ( r > = - 1 )
{
* pNewVal = r ;
Change = i ;
}
}
2018-10-03 16:16:58 +00:00
else if ( pProps [ i ] . m_Type = = PROPTYPE_AUTOMAPPER )
{
char aBuf [ 64 ] ;
2022-06-11 19:38:18 +00:00
if ( pProps [ i ] . m_Value < 0 | | pProps [ i ] . m_Min < 0 | | pProps [ i ] . m_Min > = ( int ) m_Map . m_vpImages . size ( ) )
2018-10-03 16:16:58 +00:00
str_copy ( aBuf , " None " , sizeof ( aBuf ) ) ;
else
2022-06-11 19:38:18 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %s " , m_Map . m_vpImages [ pProps [ i ] . m_Min ] - > m_AutoMapper . GetConfigName ( pProps [ i ] . m_Value ) ) ;
2018-10-03 16:16:58 +00:00
2020-11-07 23:02:34 +00:00
float FontSize = ScaleFontSize ( aBuf , sizeof ( aBuf ) , 10.0f , Shifter . w ) ;
2022-06-13 16:28:13 +00:00
if ( DoButton_Ex ( & pIDs [ i ] , aBuf , 0 , & Shifter , 0 , nullptr , CUI : : CORNER_ALL , FontSize ) )
2018-10-03 16:16:58 +00:00
PopupSelectConfigAutoMapInvoke ( pProps [ i ] . m_Value , UI ( ) - > MouseX ( ) , UI ( ) - > MouseY ( ) ) ;
int r = PopupSelectConfigAutoMapResult ( ) ;
if ( r > = - 1 )
{
* pNewVal = r ;
Change = i ;
}
}
2020-01-23 19:26:06 +00:00
else if ( pProps [ i ] . m_Type = = PROPTYPE_ENVELOPE )
{
CUIRect Inc , Dec ;
char aBuf [ 64 ] ;
2020-01-23 20:24:48 +00:00
int CurValue = pProps [ i ] . m_Value ;
2020-01-23 19:26:06 +00:00
Shifter . VSplitRight ( 10.0f , & Shifter , & Inc ) ;
Shifter . VSplitLeft ( 10.0f , & Dec , & Shifter ) ;
2020-01-23 20:24:48 +00:00
if ( CurValue < = 0 )
2020-01-23 19:48:42 +00:00
str_copy ( aBuf , " None " , sizeof ( aBuf ) ) ;
2022-06-11 19:38:18 +00:00
else if ( m_Map . m_vpEnvelopes [ CurValue - 1 ] - > m_aName [ 0 ] )
str_format ( aBuf , sizeof ( aBuf ) , " %d: %s " , CurValue , m_Map . m_vpEnvelopes [ CurValue - 1 ] - > m_aName ) ;
2020-01-23 19:48:42 +00:00
else
2020-10-04 20:37:48 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %d " , CurValue ) ;
2020-01-23 19:26:06 +00:00
2020-11-07 23:02:34 +00:00
float FontSize = ScaleFontSize ( aBuf , sizeof ( aBuf ) , 10.0f , Shifter . w ) ;
2020-01-23 19:26:06 +00:00
RenderTools ( ) - > DrawUIRect ( & Shifter , Color , 0 , 5.0f ) ;
2022-03-11 16:34:48 +00:00
UI ( ) - > DoLabel ( & Shifter , aBuf , FontSize , TEXTALIGN_CENTER ) ;
2020-01-23 19:26:06 +00:00
2022-06-13 16:28:13 +00:00
if ( DoButton_ButtonDec ( ( char * ) & pIDs [ i ] + 1 , nullptr , 0 , & Dec , 0 , " Previous Envelope " ) )
2020-01-23 19:26:06 +00:00
{
2020-09-26 19:41:58 +00:00
* pNewVal = pProps [ i ] . m_Value - 1 ;
2020-01-23 19:26:06 +00:00
Change = i ;
}
2022-06-13 16:28:13 +00:00
if ( DoButton_ButtonInc ( ( ( char * ) & pIDs [ i ] ) + 2 , nullptr , 0 , & Inc , 0 , " Next Envelope " ) )
2020-01-23 19:26:06 +00:00
{
2020-09-26 19:41:58 +00:00
* pNewVal = pProps [ i ] . m_Value + 1 ;
2020-01-23 19:26:06 +00:00
Change = i ;
}
}
2007-05-22 15:03:32 +00:00
}
2008-03-21 00:13:55 +00:00
2010-05-29 07:25:38 +00:00
return Change ;
2007-05-22 15:03:32 +00:00
}
2018-04-04 19:41:14 +00:00
void CEditor : : RenderLayers ( CUIRect ToolBox , CUIRect View )
2007-05-22 15:03:32 +00:00
{
2010-05-29 07:25:38 +00:00
if ( ! m_GuiActive )
2008-01-12 12:27:55 +00:00
return ;
2007-12-02 17:55:45 +00:00
2021-11-26 20:55:31 +00:00
CUIRect LayersBox = ToolBox ;
2010-05-29 07:25:38 +00:00
CUIRect Slot , Button ;
char aBuf [ 64 ] ;
2007-12-02 17:55:45 +00:00
2020-09-26 19:41:58 +00:00
float LayersHeight = 12.0f ; // Height of AddGroup button
2010-06-05 22:46:47 +00:00
static float s_ScrollValue = 0 ;
2022-06-11 19:38:18 +00:00
for ( auto & pGroup : m_Map . m_vpGroups )
2011-07-12 15:54:59 +00:00
{
2010-06-14 01:18:44 +00:00
// Each group is 19.0f
// Each layer is 14.0f
2011-07-12 15:54:59 +00:00
LayersHeight + = 19.0f ;
2022-05-24 09:24:33 +00:00
if ( ! pGroup - > m_Collapse )
2022-06-11 19:38:18 +00:00
LayersHeight + = pGroup - > m_vpLayers . size ( ) * 14.0f ;
2011-07-12 15:54:59 +00:00
}
2010-06-05 22:46:47 +00:00
2010-06-14 01:18:44 +00:00
float ScrollDifference = LayersHeight - LayersBox . h ;
2010-06-05 22:46:47 +00:00
2020-09-26 19:41:58 +00:00
if ( LayersHeight > LayersBox . h ) // Do we even need a scrollbar?
2010-06-05 22:46:47 +00:00
{
CUIRect Scroll ;
2021-11-26 20:55:31 +00:00
LayersBox . VSplitRight ( 20.0f , & LayersBox , & Scroll ) ;
s_ScrollValue = UIEx ( ) - > DoScrollbarV ( & s_ScrollValue , & Scroll , s_ScrollValue ) ;
2011-07-12 16:38:33 +00:00
if ( UI ( ) - > MouseInside ( & Scroll ) | | UI ( ) - > MouseInside ( & LayersBox ) )
{
2020-09-26 19:41:58 +00:00
int ScrollNum = ( int ) ( ( LayersHeight - LayersBox . h ) / 15.0f ) + 1 ;
2011-07-12 16:38:33 +00:00
if ( ScrollNum > 0 )
{
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyPress ( KEY_MOUSE_WHEEL_UP ) )
2020-09-26 19:41:58 +00:00
s_ScrollValue = clamp ( s_ScrollValue - 1.0f / ScrollNum , 0.0f , 1.0f ) ;
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyPress ( KEY_MOUSE_WHEEL_DOWN ) )
2020-09-26 19:41:58 +00:00
s_ScrollValue = clamp ( s_ScrollValue + 1.0f / ScrollNum , 0.0f , 1.0f ) ;
2011-07-12 16:38:33 +00:00
}
}
2010-06-05 22:46:47 +00:00
}
2010-06-14 01:18:44 +00:00
float LayerStartAt = ScrollDifference * s_ScrollValue ;
if ( LayerStartAt < 0.0f )
LayerStartAt = 0.0f ;
2010-06-05 22:46:47 +00:00
2010-06-14 01:18:44 +00:00
float LayerStopAt = LayersHeight - ScrollDifference * ( 1 - s_ScrollValue ) ;
float LayerCur = 0 ;
2010-06-05 22:46:47 +00:00
2010-05-29 07:25:38 +00:00
// render layers
2007-12-02 17:55:45 +00:00
{
2022-06-11 19:38:18 +00:00
for ( int g = 0 ; g < ( int ) m_Map . m_vpGroups . size ( ) ; g + + )
2007-12-02 17:55:45 +00:00
{
2010-06-05 22:46:47 +00:00
if ( LayerCur > LayerStopAt )
break ;
2022-06-11 19:38:18 +00:00
else if ( LayerCur + m_Map . m_vpGroups [ g ] - > m_vpLayers . size ( ) * 14.0f + 19.0f < LayerStartAt )
2010-06-05 22:46:47 +00:00
{
2022-06-11 19:38:18 +00:00
LayerCur + = m_Map . m_vpGroups [ g ] - > m_vpLayers . size ( ) * 14.0f + 19.0f ;
2010-06-05 22:46:47 +00:00
continue ;
}
2019-03-11 13:00:59 +00:00
CUIRect VisibleToggle ;
2010-06-05 22:46:47 +00:00
if ( LayerCur > = LayerStartAt )
2008-01-12 12:27:55 +00:00
{
2010-06-05 22:46:47 +00:00
LayersBox . HSplitTop ( 12.0f , & Slot , & LayersBox ) ;
Slot . VSplitLeft ( 12 , & VisibleToggle , & Slot ) ;
2022-06-11 19:38:18 +00:00
if ( DoButton_Ex ( & m_Map . m_vpGroups [ g ] - > m_Visible , m_Map . m_vpGroups [ g ] - > m_Visible ? " V " : " H " , m_Map . m_vpGroups [ g ] - > m_Collapse ? 1 : 0 , & VisibleToggle , 0 , " Toggle group visibility " , CUI : : CORNER_L , 10.0f , 0 ) )
m_Map . m_vpGroups [ g ] - > m_Visible = ! m_Map . m_vpGroups [ g ] - > m_Visible ;
2010-05-29 07:25:38 +00:00
2022-06-11 19:38:18 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " #%d %s " , g , m_Map . m_vpGroups [ g ] - > m_aName ) ;
2011-07-12 01:14:46 +00:00
float FontSize = 10.0f ;
2022-06-13 16:28:13 +00:00
while ( TextRender ( ) - > TextWidth ( nullptr , FontSize , aBuf , - 1 , - 1.0f ) > Slot . w )
2011-07-12 01:14:46 +00:00
FontSize - - ;
2022-06-11 19:38:18 +00:00
if ( int Result = DoButton_Ex ( & m_Map . m_vpGroups [ g ] , aBuf , g = = m_SelectedGroup , & Slot ,
BUTTON_CONTEXT , m_Map . m_vpGroups [ g ] - > m_Collapse ? " Select group. Shift click to select all layers. Double click to expand. " : " Select group. Shift click to select all layers. Double click to collapse. " , CUI : : CORNER_R , FontSize ) )
2010-06-05 22:46:47 +00:00
{
2020-09-26 19:41:58 +00:00
if ( g ! = m_SelectedGroup )
2020-09-02 15:11:57 +00:00
SelectLayer ( 0 , g ) ;
2020-09-22 12:28:14 +00:00
2020-09-22 12:47:21 +00:00
if ( ( Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) | | Input ( ) - > KeyIsPressed ( KEY_RSHIFT ) ) & & m_SelectedGroup = = g )
2018-07-25 20:57:58 +00:00
{
2022-06-11 19:38:18 +00:00
m_vSelectedLayers . clear ( ) ;
for ( size_t i = 0 ; i < m_Map . m_vpGroups [ g ] - > m_vpLayers . size ( ) ; i + + )
2018-07-25 20:57:58 +00:00
{
2022-02-26 17:49:06 +00:00
AddSelectedLayer ( i ) ;
2018-07-25 20:57:58 +00:00
}
}
2010-05-29 07:25:38 +00:00
2010-06-05 22:46:47 +00:00
static int s_GroupPopupId = 0 ;
if ( Result = = 2 )
2022-08-06 00:31:42 +00:00
UiInvokePopupMenu ( & s_GroupPopupId , 0 , UI ( ) - > MouseX ( ) , UI ( ) - > MouseY ( ) , 145 , 256 , PopupGroup ) ;
2011-07-12 15:54:59 +00:00
2022-06-11 19:38:18 +00:00
if ( ! m_Map . m_vpGroups [ g ] - > m_vpLayers . empty ( ) & & Input ( ) - > MouseDoubleClick ( ) )
m_Map . m_vpGroups [ g ] - > m_Collapse ^ = 1 ;
2010-06-05 22:46:47 +00:00
}
LayersBox . HSplitTop ( 2.0f , & Slot , & LayersBox ) ;
}
2010-06-14 01:18:44 +00:00
LayerCur + = 14.0f ;
2010-05-29 07:25:38 +00:00
2022-06-11 19:38:18 +00:00
for ( int i = 0 ; i < ( int ) m_Map . m_vpGroups [ g ] - > m_vpLayers . size ( ) ; i + + )
2008-01-12 12:27:55 +00:00
{
2010-06-14 01:18:44 +00:00
if ( LayerCur > LayerStopAt )
break ;
else if ( LayerCur < LayerStartAt )
2010-06-05 22:46:47 +00:00
{
2010-06-14 01:18:44 +00:00
LayerCur + = 14.0f ;
2010-06-05 22:46:47 +00:00
continue ;
}
2022-06-11 19:38:18 +00:00
if ( m_Map . m_vpGroups [ g ] - > m_Collapse )
2011-07-12 15:54:59 +00:00
continue ;
2008-01-12 12:27:55 +00:00
//visible
2010-05-29 07:25:38 +00:00
LayersBox . HSplitTop ( 12.0f , & Slot , & LayersBox ) ;
2022-06-13 16:28:13 +00:00
Slot . VSplitLeft ( 12.0f , nullptr , & Button ) ;
2010-05-29 07:25:38 +00:00
Button . VSplitLeft ( 15 , & VisibleToggle , & Button ) ;
2008-01-12 12:27:55 +00:00
2022-06-11 19:38:18 +00:00
if ( DoButton_Ex ( & m_Map . m_vpGroups [ g ] - > m_vpLayers [ i ] - > m_Visible , m_Map . m_vpGroups [ g ] - > m_vpLayers [ i ] - > m_Visible ? " V " : " H " , 0 , & VisibleToggle , 0 , " Toggle layer visibility " , CUI : : CORNER_L , 10.0f , 0 ) )
m_Map . m_vpGroups [ g ] - > m_vpLayers [ i ] - > m_Visible = ! m_Map . m_vpGroups [ g ] - > m_vpLayers [ i ] - > m_Visible ;
2008-01-12 12:27:55 +00:00
2022-06-11 19:38:18 +00:00
if ( m_Map . m_vpGroups [ g ] - > m_vpLayers [ i ] - > m_aName [ 0 ] )
str_copy ( aBuf , m_Map . m_vpGroups [ g ] - > m_vpLayers [ i ] - > m_aName , sizeof ( aBuf ) ) ;
2011-07-12 01:14:46 +00:00
else
2019-03-24 01:44:33 +00:00
{
2022-06-11 19:38:18 +00:00
if ( m_Map . m_vpGroups [ g ] - > m_vpLayers [ i ] - > m_Type = = LAYERTYPE_TILES )
2019-03-24 01:44:33 +00:00
{
2022-06-11 19:38:18 +00:00
CLayerTiles * pTiles = ( CLayerTiles * ) m_Map . m_vpGroups [ g ] - > m_vpLayers [ i ] ;
str_copy ( aBuf , pTiles - > m_Image > = 0 ? m_Map . m_vpImages [ pTiles - > m_Image ] - > m_aName : " Tiles " , sizeof ( aBuf ) ) ;
2019-03-24 01:44:33 +00:00
}
2022-06-11 19:38:18 +00:00
else if ( m_Map . m_vpGroups [ g ] - > m_vpLayers [ i ] - > m_Type = = LAYERTYPE_QUADS )
2019-03-24 01:44:33 +00:00
{
2022-06-11 19:38:18 +00:00
CLayerQuads * pQuads = ( CLayerQuads * ) m_Map . m_vpGroups [ g ] - > m_vpLayers [ i ] ;
str_copy ( aBuf , pQuads - > m_Image > = 0 ? m_Map . m_vpImages [ pQuads - > m_Image ] - > m_aName : " Quads " , sizeof ( aBuf ) ) ;
2019-03-24 01:44:33 +00:00
}
2022-06-11 19:38:18 +00:00
else if ( m_Map . m_vpGroups [ g ] - > m_vpLayers [ i ] - > m_Type = = LAYERTYPE_SOUNDS )
2019-03-24 01:44:33 +00:00
{
2022-06-11 19:38:18 +00:00
CLayerSounds * pSounds = ( CLayerSounds * ) m_Map . m_vpGroups [ g ] - > m_vpLayers [ i ] ;
str_copy ( aBuf , pSounds - > m_Sound > = 0 ? m_Map . m_vpSounds [ pSounds - > m_Sound ] - > m_aName : " Sounds " , sizeof ( aBuf ) ) ;
2019-03-24 01:44:33 +00:00
}
if ( str_length ( aBuf ) > 11 )
str_format ( aBuf , sizeof ( aBuf ) , " %.8s... " , aBuf ) ;
}
2011-07-12 01:14:46 +00:00
float FontSize = 10.0f ;
2022-06-13 16:28:13 +00:00
while ( TextRender ( ) - > TextWidth ( nullptr , FontSize , aBuf , - 1 , - 1.0f ) > Button . w )
2011-07-12 01:14:46 +00:00
FontSize - - ;
2018-07-25 20:57:58 +00:00
int Checked = 0 ;
2020-09-26 19:41:58 +00:00
if ( g = = m_SelectedGroup )
2018-07-25 20:57:58 +00:00
{
2022-06-11 19:38:18 +00:00
for ( const auto & Selected : m_vSelectedLayers )
2018-07-25 20:57:58 +00:00
{
2022-05-24 09:24:33 +00:00
if ( Selected = = i )
2018-07-25 20:57:58 +00:00
{
Checked = 1 ;
2020-01-19 16:48:07 +00:00
break ;
2018-07-25 20:57:58 +00:00
}
}
}
2018-10-02 01:52:01 +00:00
2022-06-11 19:38:18 +00:00
if ( m_Map . m_vpGroups [ g ] - > m_vpLayers [ i ] = = m_Map . m_pGameLayer | |
m_Map . m_vpGroups [ g ] - > m_vpLayers [ i ] = = m_Map . m_pFrontLayer | |
m_Map . m_vpGroups [ g ] - > m_vpLayers [ i ] = = m_Map . m_pSwitchLayer | |
m_Map . m_vpGroups [ g ] - > m_vpLayers [ i ] = = m_Map . m_pTuneLayer | |
m_Map . m_vpGroups [ g ] - > m_vpLayers [ i ] = = m_Map . m_pSpeedupLayer | |
m_Map . m_vpGroups [ g ] - > m_vpLayers [ i ] = = m_Map . m_pTeleLayer )
2015-06-28 13:02:48 +00:00
{
Checked + = 6 ;
}
2022-06-11 19:38:18 +00:00
if ( int Result = DoButton_Ex ( m_Map . m_vpGroups [ g ] - > m_vpLayers [ i ] , aBuf , Checked , & Button ,
2020-09-26 19:41:58 +00:00
BUTTON_CONTEXT , " Select layer. Shift click to select multiple. " , CUI : : CORNER_R , FontSize ) )
2008-01-12 12:27:55 +00:00
{
2020-08-08 08:33:18 +00:00
static CLayerPopupContext s_LayerPopupContext = { } ;
if ( Result = = 1 )
2018-07-25 20:57:58 +00:00
{
2020-08-08 08:33:18 +00:00
if ( ( Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) | | Input ( ) - > KeyIsPressed ( KEY_RSHIFT ) ) & & m_SelectedGroup = = g )
{
2022-06-11 19:38:18 +00:00
auto Position = std : : find ( m_vSelectedLayers . begin ( ) , m_vSelectedLayers . end ( ) , i ) ;
if ( Position ! = m_vSelectedLayers . end ( ) )
m_vSelectedLayers . erase ( Position ) ;
2022-05-24 09:24:33 +00:00
else
2022-02-26 17:49:06 +00:00
AddSelectedLayer ( i ) ;
2020-08-08 08:33:18 +00:00
}
else if ( ! ( Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) | | Input ( ) - > KeyIsPressed ( KEY_RSHIFT ) ) )
{
2020-09-02 15:11:24 +00:00
SelectLayer ( i , g ) ;
2020-08-08 08:33:18 +00:00
}
2018-07-25 20:57:58 +00:00
}
2020-08-08 08:33:18 +00:00
else if ( Result = = 2 )
2020-02-28 15:25:27 +00:00
{
2020-09-02 15:11:24 +00:00
bool IsLayerSelected = false ;
2020-09-26 19:41:58 +00:00
if ( m_SelectedGroup = = g )
2020-09-02 15:11:24 +00:00
{
2022-06-11 19:38:18 +00:00
for ( const auto & Selected : m_vSelectedLayers )
2020-09-02 15:11:24 +00:00
{
2022-05-24 09:24:33 +00:00
if ( Selected = = i )
2020-09-02 15:11:24 +00:00
{
IsLayerSelected = true ;
break ;
}
}
}
2020-09-22 12:28:14 +00:00
2020-09-22 12:47:21 +00:00
if ( ! IsLayerSelected )
2020-09-02 15:11:24 +00:00
{
SelectLayer ( i , g ) ;
}
2022-06-11 19:38:18 +00:00
if ( m_vSelectedLayers . size ( ) > 1 )
2020-02-28 15:25:27 +00:00
{
bool AllTile = true ;
2022-06-11 19:38:18 +00:00
for ( size_t j = 0 ; AllTile & & j < m_vSelectedLayers . size ( ) ; j + + )
2020-02-28 15:25:27 +00:00
{
2022-06-11 19:38:18 +00:00
if ( m_Map . m_vpGroups [ m_SelectedGroup ] - > m_vpLayers [ m_vSelectedLayers [ j ] ] - > m_Type = = LAYERTYPE_TILES )
s_LayerPopupContext . m_vpLayers . push_back ( ( CLayerTiles * ) m_Map . m_vpGroups [ m_SelectedGroup ] - > m_vpLayers [ m_vSelectedLayers [ j ] ] ) ;
2020-02-28 15:25:27 +00:00
else
AllTile = false ;
}
// Don't allow editing if all selected layers are tile layers
if ( ! AllTile )
2022-06-11 19:38:18 +00:00
s_LayerPopupContext . m_vpLayers . clear ( ) ;
2020-02-28 15:25:27 +00:00
}
else
2022-06-11 19:38:18 +00:00
s_LayerPopupContext . m_vpLayers . clear ( ) ;
2020-02-28 15:25:27 +00:00
UiInvokePopupMenu ( & s_LayerPopupContext , 0 , UI ( ) - > MouseX ( ) , UI ( ) - > MouseY ( ) , 120 , 300 , PopupLayer , & s_LayerPopupContext ) ;
}
2008-01-12 12:27:55 +00:00
}
2010-05-29 07:25:38 +00:00
2010-06-14 01:18:44 +00:00
LayerCur + = 14.0f ;
2010-05-29 07:25:38 +00:00
LayersBox . HSplitTop ( 2.0f , & Slot , & LayersBox ) ;
2008-01-12 12:27:55 +00:00
}
2010-06-14 01:18:44 +00:00
if ( LayerCur > LayerStartAt & & LayerCur < LayerStopAt )
LayersBox . HSplitTop ( 5.0f , & Slot , & LayersBox ) ;
LayerCur + = 5.0f ;
2007-12-02 17:55:45 +00:00
}
}
2010-05-29 07:25:38 +00:00
2021-07-17 10:48:22 +00:00
if ( Input ( ) - > KeyPress ( KEY_DOWN ) & & m_Dialog = = DIALOG_NONE & & m_EditBoxActive = = 0 )
2020-08-08 09:35:52 +00:00
{
if ( Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) | | Input ( ) - > KeyIsPressed ( KEY_RSHIFT ) )
{
2022-06-11 19:38:18 +00:00
if ( m_vSelectedLayers [ m_vSelectedLayers . size ( ) - 1 ] < ( int ) m_Map . m_vpGroups [ m_SelectedGroup ] - > m_vpLayers . size ( ) - 1 )
AddSelectedLayer ( m_vSelectedLayers [ m_vSelectedLayers . size ( ) - 1 ] + 1 ) ;
2020-08-08 09:35:52 +00:00
}
else
{
int CurrentLayer = 0 ;
2022-06-11 19:38:18 +00:00
for ( const auto & Selected : m_vSelectedLayers )
2022-05-24 09:24:33 +00:00
CurrentLayer = maximum ( Selected , CurrentLayer ) ;
2020-08-08 09:35:52 +00:00
SelectLayer ( CurrentLayer ) ;
2022-06-11 19:38:18 +00:00
if ( m_vSelectedLayers [ 0 ] < ( int ) m_Map . m_vpGroups [ m_SelectedGroup ] - > m_vpLayers . size ( ) - 1 )
2020-08-08 09:35:52 +00:00
{
2022-06-11 19:38:18 +00:00
SelectLayer ( m_vSelectedLayers [ 0 ] + 1 ) ;
2020-08-08 09:35:52 +00:00
}
else
{
2022-06-11 19:38:18 +00:00
for ( size_t Group = m_SelectedGroup + 1 ; Group < m_Map . m_vpGroups . size ( ) ; Group + + )
2020-08-08 09:35:52 +00:00
{
2022-06-11 19:38:18 +00:00
if ( ! m_Map . m_vpGroups [ Group ] - > m_vpLayers . empty ( ) )
2020-08-08 09:35:52 +00:00
{
2020-09-02 15:11:24 +00:00
SelectLayer ( 0 , Group ) ;
2020-08-08 09:35:52 +00:00
break ;
}
}
}
}
}
2021-07-17 10:48:22 +00:00
if ( Input ( ) - > KeyPress ( KEY_UP ) & & m_Dialog = = DIALOG_NONE & & m_EditBoxActive = = 0 )
2020-08-08 09:35:52 +00:00
{
if ( Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) | | Input ( ) - > KeyIsPressed ( KEY_RSHIFT ) )
{
2022-06-11 19:38:18 +00:00
if ( m_vSelectedLayers [ m_vSelectedLayers . size ( ) - 1 ] > 0 )
AddSelectedLayer ( m_vSelectedLayers [ m_vSelectedLayers . size ( ) - 1 ] - 1 ) ;
2020-08-08 09:35:52 +00:00
}
else
{
int CurrentLayer = std : : numeric_limits < int > : : max ( ) ;
2022-06-11 19:38:18 +00:00
for ( const auto & Selected : m_vSelectedLayers )
2022-05-24 09:24:33 +00:00
CurrentLayer = minimum ( Selected , CurrentLayer ) ;
2020-08-08 09:35:52 +00:00
SelectLayer ( CurrentLayer ) ;
2022-06-11 19:38:18 +00:00
if ( m_vSelectedLayers [ 0 ] > 0 )
2020-08-08 09:35:52 +00:00
{
2022-06-11 19:38:18 +00:00
SelectLayer ( m_vSelectedLayers [ 0 ] - 1 ) ;
2020-08-08 09:35:52 +00:00
}
else
{
for ( int Group = m_SelectedGroup - 1 ; Group > = 0 ; Group - - )
{
2022-06-11 19:38:18 +00:00
if ( ! m_Map . m_vpGroups [ Group ] - > m_vpLayers . empty ( ) )
2020-08-08 09:35:52 +00:00
{
2022-06-11 19:38:18 +00:00
SelectLayer ( m_Map . m_vpGroups [ Group ] - > m_vpLayers . size ( ) - 1 , Group ) ;
2020-08-08 09:35:52 +00:00
break ;
}
}
}
}
}
2010-06-05 22:46:47 +00:00
if ( LayerCur < = LayerStopAt )
2007-12-02 17:55:45 +00:00
{
2010-05-29 07:25:38 +00:00
LayersBox . HSplitTop ( 12.0f , & Slot , & LayersBox ) ;
2008-01-13 22:03:32 +00:00
2010-05-29 07:25:38 +00:00
static int s_NewGroupButton = 0 ;
2019-03-11 13:00:59 +00:00
if ( DoButton_Editor ( & s_NewGroupButton , " Add group " , 0 , & Slot , CUI : : CORNER_R , " Adds a new group " ) )
2008-01-12 12:27:55 +00:00
{
2010-05-29 07:25:38 +00:00
m_Map . NewGroup ( ) ;
2022-06-11 19:38:18 +00:00
m_SelectedGroup = m_Map . m_vpGroups . size ( ) - 1 ;
2007-12-02 17:55:45 +00:00
}
}
2022-04-08 12:59:33 +00:00
SelectLayerByTile ( s_ScrollValue ) ;
}
void CEditor : : SelectLayerByTile ( float & Scroll )
{
2022-04-11 09:28:05 +00:00
// ctrl+rightclick a map index to select the layer that has a tile there
2022-04-08 12:59:33 +00:00
static bool s_CtrlClick = false ;
static int s_Selected = 0 ;
int MatchedGroup = - 1 ;
int MatchedLayer = - 1 ;
int Matches = 0 ;
bool IsFound = false ;
int TotalLayers = 0 ;
int SelectedLayer = 0 ;
if ( UI ( ) - > MouseButton ( 1 ) & & Input ( ) - > ModifierIsPressed ( ) )
{
if ( s_CtrlClick )
return ;
s_CtrlClick = true ;
2022-06-11 19:38:18 +00:00
for ( size_t g = 0 ; g < m_Map . m_vpGroups . size ( ) ; g + + )
2022-04-08 12:59:33 +00:00
{
2022-06-11 19:38:18 +00:00
for ( size_t l = 0 ; l < m_Map . m_vpGroups [ g ] - > m_vpLayers . size ( ) ; l + + )
2022-04-08 12:59:33 +00:00
{
TotalLayers + + ;
if ( IsFound )
continue ;
2022-06-11 19:38:18 +00:00
if ( m_Map . m_vpGroups [ g ] - > m_vpLayers [ l ] - > m_Type ! = LAYERTYPE_TILES )
2022-04-08 12:59:33 +00:00
continue ;
2022-06-11 19:38:18 +00:00
CLayerTiles * pTiles = ( CLayerTiles * ) m_Map . m_vpGroups [ g ] - > m_vpLayers [ l ] ;
int x = ( int ) UI ( ) - > MouseWorldX ( ) / 32 + m_Map . m_vpGroups [ g ] - > m_OffsetX ;
int y = ( int ) UI ( ) - > MouseWorldY ( ) / 32 + m_Map . m_vpGroups [ g ] - > m_OffsetY ;
2022-04-08 12:59:33 +00:00
if ( x < 0 | | x > = pTiles - > m_Width )
continue ;
if ( y < 0 | | y > = pTiles - > m_Height )
continue ;
CTile Tile = pTiles - > GetTile ( x , y ) ;
if ( Tile . m_Index )
{
if ( MatchedGroup = = - 1 )
{
MatchedGroup = g ;
MatchedLayer = l ;
SelectedLayer = TotalLayers ;
}
if ( + + Matches > s_Selected )
{
s_Selected + + ;
MatchedGroup = g ;
MatchedLayer = l ;
IsFound = true ;
SelectedLayer = TotalLayers ;
}
}
}
}
if ( MatchedGroup ! = - 1 & & MatchedLayer ! = - 1 )
{
if ( ! IsFound )
s_Selected = 1 ;
Scroll = ( float ) SelectedLayer / ( float ) TotalLayers ;
SelectLayer ( MatchedLayer , MatchedGroup ) ;
}
}
else
s_CtrlClick = false ;
2008-01-12 12:27:55 +00:00
}
2010-10-07 21:51:07 +00:00
void CEditor : : ReplaceImage ( const char * pFileName , int StorageType , void * pUser )
2008-01-19 12:32:08 +00:00
{
2010-05-29 07:25:38 +00:00
CEditor * pEditor = ( CEditor * ) pUser ;
CEditorImage ImgInfo ( pEditor ) ;
2010-10-07 21:51:07 +00:00
if ( ! pEditor - > Graphics ( ) - > LoadPNG ( & ImgInfo , pFileName , StorageType ) )
2008-01-19 12:32:08 +00:00
return ;
2010-05-29 07:25:38 +00:00
2022-06-11 19:38:18 +00:00
CEditorImage * pImg = pEditor - > m_Map . m_vpImages [ pEditor - > m_SelectedImage ] ;
2016-07-02 08:33:37 +00:00
pEditor - > Graphics ( ) - > UnloadTexture ( & ( pImg - > m_Texture ) ) ;
2022-03-01 22:19:49 +00:00
free ( pImg - > m_pData ) ;
2022-06-13 16:28:13 +00:00
pImg - > m_pData = nullptr ;
2010-05-29 07:25:38 +00:00
* pImg = ImgInfo ;
2017-08-30 11:59:42 +00:00
IStorage : : StripPathAndExtension ( pFileName , pImg - > m_aName , sizeof ( pImg - > m_aName ) ) ;
2019-07-17 01:00:09 +00:00
pImg - > m_External = IsVanillaImage ( pImg - > m_aName ) ;
2020-09-20 16:42:17 +00:00
2020-09-26 16:57:19 +00:00
if ( ! pImg - > m_External & & g_Config . m_ClEditorDilate = = 1 & & pImg - > m_Format = = CImageInfo : : FORMAT_RGBA )
2020-09-20 16:42:17 +00:00
{
int ColorChannelCount = 0 ;
2020-09-26 16:57:19 +00:00
if ( ImgInfo . m_Format = = CImageInfo : : FORMAT_RGBA )
2020-09-20 16:42:17 +00:00
ColorChannelCount = 4 ;
DilateImage ( ( unsigned char * ) ImgInfo . m_pData , ImgInfo . m_Width , ImgInfo . m_Height , ColorChannelCount ) ;
}
2011-07-08 23:09:06 +00:00
pImg - > m_AutoMapper . Load ( pImg - > m_aName ) ;
2020-09-21 03:57:54 +00:00
int TextureLoadFlag = pEditor - > Graphics ( ) - > HasTextureArrays ( ) ? IGraphics : : TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics : : TEXLOAD_TO_3D_TEXTURE ;
if ( ImgInfo . m_Width % 16 ! = 0 | | ImgInfo . m_Height % 16 ! = 0 )
TextureLoadFlag = 0 ;
pImg - > m_Texture = pEditor - > Graphics ( ) - > LoadTextureRaw ( ImgInfo . m_Width , ImgInfo . m_Height , ImgInfo . m_Format , ImgInfo . m_pData , CImageInfo : : FORMAT_AUTO , TextureLoadFlag , pFileName ) ;
2022-06-13 16:28:13 +00:00
ImgInfo . m_pData = nullptr ;
2010-06-02 16:12:32 +00:00
pEditor - > SortImages ( ) ;
2022-06-11 19:38:18 +00:00
for ( size_t i = 0 ; i < pEditor - > m_Map . m_vpImages . size ( ) ; + + i )
2010-10-16 09:05:42 +00:00
{
2022-06-11 19:38:18 +00:00
if ( ! str_comp ( pEditor - > m_Map . m_vpImages [ i ] - > m_aName , pImg - > m_aName ) )
2011-08-11 08:59:14 +00:00
pEditor - > m_SelectedImage = i ;
2010-10-16 09:05:42 +00:00
}
pEditor - > m_Dialog = DIALOG_NONE ;
2008-01-19 12:32:08 +00:00
}
2010-10-07 21:51:07 +00:00
void CEditor : : AddImage ( const char * pFileName , int StorageType , void * pUser )
2008-01-13 16:30:30 +00:00
{
2010-05-29 07:25:38 +00:00
CEditor * pEditor = ( CEditor * ) pUser ;
CEditorImage ImgInfo ( pEditor ) ;
2010-10-07 21:51:07 +00:00
if ( ! pEditor - > Graphics ( ) - > LoadPNG ( & ImgInfo , pFileName , StorageType ) )
2008-01-13 16:30:30 +00:00
return ;
2010-10-16 09:05:42 +00:00
// check if we have that image already
char aBuf [ 128 ] ;
2017-08-30 11:59:42 +00:00
IStorage : : StripPathAndExtension ( pFileName , aBuf , sizeof ( aBuf ) ) ;
2022-06-11 19:38:18 +00:00
for ( const auto & pImage : pEditor - > m_Map . m_vpImages )
2010-05-29 07:25:38 +00:00
{
2022-05-24 09:24:33 +00:00
if ( ! str_comp ( pImage - > m_aName , aBuf ) )
2011-08-11 08:59:14 +00:00
return ;
2010-05-29 07:25:38 +00:00
}
2022-06-11 19:38:18 +00:00
if ( pEditor - > m_Map . m_vpImages . size ( ) > = 64 ) // hard limit for teeworlds
2020-09-19 18:52:28 +00:00
{
pEditor - > m_PopupEventType = pEditor - > POPEVENT_IMAGE_MAX ;
pEditor - > m_PopupEventActivated = true ;
return ;
}
2010-10-16 09:05:42 +00:00
CEditorImage * pImg = new CEditorImage ( pEditor ) ;
* pImg = ImgInfo ;
2020-09-20 16:42:17 +00:00
pImg - > m_External = IsVanillaImage ( aBuf ) ;
2020-09-26 16:57:19 +00:00
if ( ! pImg - > m_External & & g_Config . m_ClEditorDilate = = 1 & & pImg - > m_Format = = CImageInfo : : FORMAT_RGBA )
2020-09-20 16:42:17 +00:00
{
int ColorChannelCount = 0 ;
2020-09-26 16:57:19 +00:00
if ( ImgInfo . m_Format = = CImageInfo : : FORMAT_RGBA )
2020-09-20 16:42:17 +00:00
ColorChannelCount = 4 ;
DilateImage ( ( unsigned char * ) ImgInfo . m_pData , ImgInfo . m_Width , ImgInfo . m_Height , ColorChannelCount ) ;
}
2020-09-21 03:57:54 +00:00
int TextureLoadFlag = pEditor - > Graphics ( ) - > HasTextureArrays ( ) ? IGraphics : : TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics : : TEXLOAD_TO_3D_TEXTURE ;
if ( ImgInfo . m_Width % 16 ! = 0 | | ImgInfo . m_Height % 16 ! = 0 )
TextureLoadFlag = 0 ;
pImg - > m_Texture = pEditor - > Graphics ( ) - > LoadTextureRaw ( ImgInfo . m_Width , ImgInfo . m_Height , ImgInfo . m_Format , ImgInfo . m_pData , CImageInfo : : FORMAT_AUTO , TextureLoadFlag , pFileName ) ;
2022-06-13 16:28:13 +00:00
ImgInfo . m_pData = nullptr ;
2010-10-16 09:05:42 +00:00
str_copy ( pImg - > m_aName , aBuf , sizeof ( pImg - > m_aName ) ) ;
2011-07-08 23:09:06 +00:00
pImg - > m_AutoMapper . Load ( pImg - > m_aName ) ;
2022-06-11 19:38:18 +00:00
pEditor - > m_Map . m_vpImages . push_back ( pImg ) ;
2010-06-02 16:12:32 +00:00
pEditor - > SortImages ( ) ;
2022-06-11 19:38:18 +00:00
if ( pEditor - > m_SelectedImage > = 0 & & ( size_t ) pEditor - > m_SelectedImage < pEditor - > m_Map . m_vpImages . size ( ) )
2010-10-16 09:05:42 +00:00
{
for ( int i = 0 ; i < = pEditor - > m_SelectedImage ; + + i )
2022-06-11 19:38:18 +00:00
if ( ! str_comp ( pEditor - > m_Map . m_vpImages [ i ] - > m_aName , aBuf ) )
2010-10-16 09:05:42 +00:00
{
pEditor - > m_SelectedImage + + ;
break ;
}
}
pEditor - > m_Dialog = DIALOG_NONE ;
2008-01-13 16:30:30 +00:00
}
2014-10-08 12:50:25 +00:00
void CEditor : : AddSound ( const char * pFileName , int StorageType , void * pUser )
{
CEditor * pEditor = ( CEditor * ) pUser ;
2014-10-24 20:13:46 +00:00
// check if we have that sound already
2014-10-08 12:50:25 +00:00
char aBuf [ 128 ] ;
2017-08-30 11:59:42 +00:00
IStorage : : StripPathAndExtension ( pFileName , aBuf , sizeof ( aBuf ) ) ;
2022-06-11 19:38:18 +00:00
for ( const auto & pSound : pEditor - > m_Map . m_vpSounds )
2014-10-08 12:50:25 +00:00
{
2022-05-24 09:24:33 +00:00
if ( ! str_comp ( pSound - > m_aName , aBuf ) )
2014-10-08 12:50:25 +00:00
return ;
}
2014-10-11 12:50:16 +00:00
// load external
2022-06-14 19:13:25 +00:00
void * pData ;
unsigned DataSize ;
if ( ! pEditor - > Storage ( ) - > ReadFile ( pFileName , StorageType , & pData , & DataSize ) )
2014-10-24 23:07:24 +00:00
{
2014-10-27 15:23:53 +00:00
dbg_msg ( " sound/opus " , " failed to open file. filename='%s' " , pFileName ) ;
2014-10-11 12:50:16 +00:00
return ;
2014-10-24 23:07:24 +00:00
}
2014-10-11 12:50:16 +00:00
2014-10-08 14:53:25 +00:00
// load sound
2020-09-26 19:41:58 +00:00
int SoundId = pEditor - > Sound ( ) - > LoadOpusFromMem ( pData , ( unsigned ) DataSize , true ) ;
2014-10-08 14:53:25 +00:00
if ( SoundId = = - 1 )
2022-06-14 19:13:25 +00:00
{
free ( pData ) ;
2014-10-08 14:53:25 +00:00
return ;
2022-06-14 19:13:25 +00:00
}
2014-10-08 14:53:25 +00:00
// add sound
2014-10-11 11:38:45 +00:00
CEditorSound * pSound = new CEditorSound ( pEditor ) ;
2014-10-08 14:53:25 +00:00
pSound - > m_SoundID = SoundId ;
2022-06-14 19:13:25 +00:00
pSound - > m_DataSize = DataSize ;
2014-10-11 12:50:16 +00:00
pSound - > m_pData = pData ;
2014-10-08 12:50:25 +00:00
str_copy ( pSound - > m_aName , aBuf , sizeof ( pSound - > m_aName ) ) ;
2022-06-11 19:38:18 +00:00
pEditor - > m_Map . m_vpSounds . push_back ( pSound ) ;
2014-10-08 14:53:25 +00:00
2022-06-11 19:38:18 +00:00
if ( pEditor - > m_SelectedSound > = 0 & & ( size_t ) pEditor - > m_SelectedSound < pEditor - > m_Map . m_vpSounds . size ( ) )
2014-10-08 12:50:25 +00:00
{
for ( int i = 0 ; i < = pEditor - > m_SelectedSound ; + + i )
2022-06-11 19:38:18 +00:00
if ( ! str_comp ( pEditor - > m_Map . m_vpSounds [ i ] - > m_aName , aBuf ) )
2014-10-08 12:50:25 +00:00
{
pEditor - > m_SelectedSound + + ;
break ;
}
}
2015-07-09 00:08:14 +00:00
2014-10-08 12:50:25 +00:00
pEditor - > m_Dialog = DIALOG_NONE ;
}
2014-11-09 13:58:28 +00:00
void CEditor : : ReplaceSound ( const char * pFileName , int StorageType , void * pUser )
{
CEditor * pEditor = ( CEditor * ) pUser ;
2015-07-09 00:08:14 +00:00
2014-11-09 13:58:28 +00:00
// load external
2022-06-14 19:13:25 +00:00
void * pData ;
unsigned DataSize ;
if ( ! pEditor - > Storage ( ) - > ReadFile ( pFileName , StorageType , & pData , & DataSize ) )
2014-11-09 13:58:28 +00:00
{
dbg_msg ( " sound/opus " , " failed to open file. filename='%s' " , pFileName ) ;
return ;
}
2022-06-11 19:38:18 +00:00
CEditorSound * pSound = pEditor - > m_Map . m_vpSounds [ pEditor - > m_SelectedSound ] ;
2014-11-09 13:58:28 +00:00
// unload sample
pEditor - > Sound ( ) - > UnloadSample ( pSound - > m_SoundID ) ;
2022-03-01 22:19:49 +00:00
free ( pSound - > m_pData ) ;
2022-06-13 16:28:13 +00:00
pSound - > m_pData = nullptr ;
2014-11-09 13:58:28 +00:00
// replace sound
2017-08-30 11:59:42 +00:00
IStorage : : StripPathAndExtension ( pFileName , pSound - > m_aName , sizeof ( pSound - > m_aName ) ) ;
2020-09-26 19:41:58 +00:00
pSound - > m_SoundID = pEditor - > Sound ( ) - > LoadOpusFromMem ( pData , ( unsigned ) DataSize , true ) ;
2014-11-09 13:58:28 +00:00
pSound - > m_pData = pData ;
pSound - > m_DataSize = DataSize ;
pEditor - > m_Dialog = DIALOG_NONE ;
}
2010-05-29 07:25:38 +00:00
static int gs_ModifyIndexDeletedIndex ;
static void ModifyIndexDeleted ( int * pIndex )
2008-01-19 12:32:08 +00:00
{
2010-05-29 07:25:38 +00:00
if ( * pIndex = = gs_ModifyIndexDeletedIndex )
* pIndex = - 1 ;
else if ( * pIndex > gs_ModifyIndexDeletedIndex )
* pIndex = * pIndex - 1 ;
2008-01-19 12:32:08 +00:00
}
2020-02-28 15:25:27 +00:00
int CEditor : : PopupImage ( CEditor * pEditor , CUIRect View , void * pContext )
2008-01-13 22:03:32 +00:00
{
2010-05-29 07:25:38 +00:00
static int s_ReplaceButton = 0 ;
static int s_RemoveButton = 0 ;
2008-01-13 22:03:32 +00:00
2010-05-29 07:25:38 +00:00
CUIRect Slot ;
View . HSplitTop ( 2.0f , & Slot , & View ) ;
View . HSplitTop ( 12.0f , & Slot , & View ) ;
2022-06-11 19:38:18 +00:00
CEditorImage * pImg = pEditor - > m_Map . m_vpImages [ pEditor - > m_SelectedImage ] ;
2010-05-29 07:25:38 +00:00
static int s_ExternalButton = 0 ;
if ( pImg - > m_External )
2008-01-19 14:23:53 +00:00
{
2011-03-20 16:04:03 +00:00
if ( pEditor - > DoButton_MenuItem ( & s_ExternalButton , " Embed " , 0 , & Slot , 0 , " Embeds the image into the map file. " ) )
2008-01-19 14:23:53 +00:00
{
2010-05-29 07:25:38 +00:00
pImg - > m_External = 0 ;
2008-01-19 14:23:53 +00:00
return 1 ;
}
2021-03-19 00:06:37 +00:00
View . HSplitTop ( 5.0f , & Slot , & View ) ;
View . HSplitTop ( 12.0f , & Slot , & View ) ;
2008-01-19 14:23:53 +00:00
}
2021-03-19 00:06:37 +00:00
else if ( IsVanillaImage ( pImg - > m_aName ) )
2010-05-29 07:25:38 +00:00
{
2011-03-20 16:04:03 +00:00
if ( pEditor - > DoButton_MenuItem ( & s_ExternalButton , " Make external " , 0 , & Slot , 0 , " Removes the image from the map file. " ) )
2008-01-19 14:23:53 +00:00
{
2010-05-29 07:25:38 +00:00
pImg - > m_External = 1 ;
2008-01-19 14:23:53 +00:00
return 1 ;
}
2021-03-19 00:06:37 +00:00
View . HSplitTop ( 5.0f , & Slot , & View ) ;
View . HSplitTop ( 12.0f , & Slot , & View ) ;
2008-01-19 14:23:53 +00:00
}
2011-03-20 16:04:03 +00:00
if ( pEditor - > DoButton_MenuItem ( & s_ReplaceButton , " Replace " , 0 , & Slot , 0 , " Replaces the image with a new one " ) )
2008-01-13 22:03:32 +00:00
{
2011-03-20 16:04:03 +00:00
pEditor - > InvokeFileDialog ( IStorage : : TYPE_ALL , FILETYPE_IMG , " Replace Image " , " Replace " , " mapres " , " " , ReplaceImage , pEditor ) ;
2008-01-13 22:03:32 +00:00
return 1 ;
}
2018-10-01 19:45:29 +00:00
View . HSplitTop ( 5.0f , & Slot , & View ) ;
2010-05-29 07:25:38 +00:00
View . HSplitTop ( 12.0f , & Slot , & View ) ;
2011-03-20 16:04:03 +00:00
if ( pEditor - > DoButton_MenuItem ( & s_RemoveButton , " Remove " , 0 , & Slot , 0 , " Removes the image from the map " ) )
2008-01-13 22:03:32 +00:00
{
2010-05-29 07:25:38 +00:00
delete pImg ;
2022-06-11 19:38:18 +00:00
pEditor - > m_Map . m_vpImages . erase ( pEditor - > m_Map . m_vpImages . begin ( ) + pEditor - > m_SelectedImage ) ;
2010-05-29 07:25:38 +00:00
gs_ModifyIndexDeletedIndex = pEditor - > m_SelectedImage ;
pEditor - > m_Map . ModifyImageIndex ( ModifyIndexDeleted ) ;
2008-01-13 22:03:32 +00:00
return 1 ;
}
return 0 ;
}
2020-02-28 15:25:27 +00:00
int CEditor : : PopupSound ( CEditor * pEditor , CUIRect View , void * pContext )
2014-10-08 12:50:25 +00:00
{
2014-11-09 13:58:28 +00:00
static int s_ReplaceButton = 0 ;
2014-10-08 12:50:25 +00:00
static int s_RemoveButton = 0 ;
CUIRect Slot ;
View . HSplitTop ( 2.0f , & Slot , & View ) ;
View . HSplitTop ( 12.0f , & Slot , & View ) ;
if ( pEditor - > DoButton_MenuItem ( & s_ReplaceButton , " Replace " , 0 , & Slot , 0 , " Replaces the sound with a new one " ) )
{
2014-11-09 13:58:28 +00:00
pEditor - > InvokeFileDialog ( IStorage : : TYPE_ALL , FILETYPE_SOUND , " Replace sound " , " Replace " , " mapres " , " " , ReplaceSound , pEditor ) ;
2014-10-08 12:50:25 +00:00
return 1 ;
2014-11-09 13:58:28 +00:00
}
2014-10-08 12:50:25 +00:00
2018-10-01 19:45:29 +00:00
View . HSplitTop ( 5.0f , & Slot , & View ) ;
2014-10-08 12:50:25 +00:00
View . HSplitTop ( 12.0f , & Slot , & View ) ;
2022-06-11 19:38:18 +00:00
CEditorSound * pSound = pEditor - > m_Map . m_vpSounds [ pEditor - > m_SelectedSound ] ;
2014-10-08 12:50:25 +00:00
if ( pEditor - > DoButton_MenuItem ( & s_RemoveButton , " Remove " , 0 , & Slot , 0 , " Removes the sound from the map " ) )
{
delete pSound ;
2022-06-11 19:38:18 +00:00
pEditor - > m_Map . m_vpSounds . erase ( pEditor - > m_Map . m_vpSounds . begin ( ) + pEditor - > m_SelectedSound ) ;
2014-10-08 12:50:25 +00:00
gs_ModifyIndexDeletedIndex = pEditor - > m_SelectedSound ;
2014-10-11 11:38:45 +00:00
pEditor - > m_Map . ModifySoundIndex ( ModifyIndexDeleted ) ;
2014-10-08 12:50:25 +00:00
return 1 ;
}
return 0 ;
}
2020-09-21 17:36:26 +00:00
void CEditor : : SelectGameLayer ( )
{
2022-06-11 19:38:18 +00:00
for ( size_t g = 0 ; g < m_Map . m_vpGroups . size ( ) ; g + + )
2020-09-21 17:36:26 +00:00
{
2022-06-11 19:38:18 +00:00
for ( size_t i = 0 ; i < m_Map . m_vpGroups [ g ] - > m_vpLayers . size ( ) ; i + + )
2020-09-21 17:36:26 +00:00
{
2022-06-11 19:38:18 +00:00
if ( m_Map . m_vpGroups [ g ] - > m_vpLayers [ i ] = = m_Map . m_pGameLayer )
2020-09-21 17:36:26 +00:00
{
SelectLayer ( i , g ) ;
return ;
}
}
}
}
2020-10-09 20:49:52 +00:00
static bool ImageNameLess ( const CEditorImage * const & a , const CEditorImage * const & b )
2010-06-02 16:12:32 +00:00
{
2020-10-09 20:49:52 +00:00
return str_comp ( a - > m_aName , b - > m_aName ) < 0 ;
2010-06-02 16:12:32 +00:00
}
2022-06-13 16:28:13 +00:00
static int * gs_pSortedIndex = nullptr ;
2010-06-02 16:12:32 +00:00
static void ModifySortedIndex ( int * pIndex )
{
2020-10-09 20:49:52 +00:00
if ( * pIndex > = 0 )
2010-06-02 16:12:32 +00:00
* pIndex = gs_pSortedIndex [ * pIndex ] ;
}
void CEditor : : SortImages ( )
{
2022-06-11 19:38:18 +00:00
if ( ! std : : is_sorted ( m_Map . m_vpImages . begin ( ) , m_Map . m_vpImages . end ( ) , ImageNameLess ) )
2010-06-02 16:12:32 +00:00
{
2022-06-11 20:03:23 +00:00
std : : vector < CEditorImage * > vpTemp = m_Map . m_vpImages ;
gs_pSortedIndex = new int [ vpTemp . size ( ) ] ;
2010-06-02 16:12:32 +00:00
2022-06-11 19:38:18 +00:00
std : : sort ( m_Map . m_vpImages . begin ( ) , m_Map . m_vpImages . end ( ) , ImageNameLess ) ;
2022-06-11 20:03:23 +00:00
for ( size_t OldIndex = 0 ; OldIndex < vpTemp . size ( ) ; OldIndex + + )
2020-10-09 20:49:52 +00:00
{
2022-06-11 19:38:18 +00:00
for ( size_t NewIndex = 0 ; NewIndex < m_Map . m_vpImages . size ( ) ; NewIndex + + )
2020-10-09 20:49:52 +00:00
{
2022-06-11 20:03:23 +00:00
if ( vpTemp [ OldIndex ] = = m_Map . m_vpImages [ NewIndex ] )
2020-10-09 20:49:52 +00:00
{
2010-06-02 16:12:32 +00:00
gs_pSortedIndex [ OldIndex ] = NewIndex ;
2020-10-09 20:49:52 +00:00
break ;
}
}
}
2010-06-02 16:12:32 +00:00
m_Map . ModifyImageIndex ( ModifySortedIndex ) ;
2020-09-26 19:41:58 +00:00
delete [ ] gs_pSortedIndex ;
2022-06-13 16:28:13 +00:00
gs_pSortedIndex = nullptr ;
2010-06-02 16:12:32 +00:00
}
}
2011-08-11 08:59:14 +00:00
2018-04-04 19:41:14 +00:00
void CEditor : : RenderImages ( CUIRect ToolBox , CUIRect View )
2008-01-12 12:27:55 +00:00
{
2021-11-26 20:55:31 +00:00
if ( ! m_GuiActive )
return ;
2010-06-05 22:46:47 +00:00
static float s_ScrollValue = 0 ;
2022-06-11 19:38:18 +00:00
float ImagesHeight = 30.0f + 14.0f * m_Map . m_vpImages . size ( ) + 27.0f ;
2010-06-14 01:18:44 +00:00
float ScrollDifference = ImagesHeight - ToolBox . h ;
2010-06-05 22:46:47 +00:00
2020-09-26 19:41:58 +00:00
if ( ImagesHeight > ToolBox . h ) // Do we even need a scrollbar?
2010-06-05 22:46:47 +00:00
{
CUIRect Scroll ;
2021-11-26 20:55:31 +00:00
ToolBox . VSplitRight ( 20.0f , & ToolBox , & Scroll ) ;
s_ScrollValue = UIEx ( ) - > DoScrollbarV ( & s_ScrollValue , & Scroll , s_ScrollValue ) ;
2011-07-12 16:38:33 +00:00
if ( UI ( ) - > MouseInside ( & Scroll ) | | UI ( ) - > MouseInside ( & ToolBox ) )
{
2020-09-26 19:41:58 +00:00
int ScrollNum = ( int ) ( ( ImagesHeight - ToolBox . h ) / 14.0f ) + 1 ;
2011-07-12 16:38:33 +00:00
if ( ScrollNum > 0 )
{
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyPress ( KEY_MOUSE_WHEEL_UP ) )
2020-09-26 19:41:58 +00:00
s_ScrollValue = clamp ( s_ScrollValue - 1.0f / ScrollNum , 0.0f , 1.0f ) ;
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyPress ( KEY_MOUSE_WHEEL_DOWN ) )
2020-09-26 19:41:58 +00:00
s_ScrollValue = clamp ( s_ScrollValue + 1.0f / ScrollNum , 0.0f , 1.0f ) ;
2011-07-12 16:38:33 +00:00
}
}
2010-06-05 22:46:47 +00:00
}
2010-06-14 01:18:44 +00:00
float ImageStartAt = ScrollDifference * s_ScrollValue ;
if ( ImageStartAt < 0.0f )
ImageStartAt = 0.0f ;
2010-06-05 22:46:47 +00:00
2010-06-14 01:18:44 +00:00
float ImageStopAt = ImagesHeight - ScrollDifference * ( 1 - s_ScrollValue ) ;
float ImageCur = 0.0f ;
2010-06-05 22:46:47 +00:00
2008-01-19 14:23:53 +00:00
for ( int e = 0 ; e < 2 ; e + + ) // two passes, first embedded, then external
2008-01-12 12:27:55 +00:00
{
2010-05-29 07:25:38 +00:00
CUIRect Slot ;
2010-06-05 22:46:47 +00:00
if ( ImageCur > ImageStopAt )
break ;
else if ( ImageCur > = ImageStartAt )
{
ToolBox . HSplitTop ( 15.0f , & Slot , & ToolBox ) ;
if ( e = = 0 )
2022-01-21 15:20:15 +00:00
UI ( ) - > DoLabel ( & Slot , " Embedded " , 12.0f , TEXTALIGN_CENTER ) ;
2010-06-05 22:46:47 +00:00
else
2022-01-21 15:20:15 +00:00
UI ( ) - > DoLabel ( & Slot , " External " , 12.0f , TEXTALIGN_CENTER ) ;
2010-06-05 22:46:47 +00:00
}
2010-06-14 01:18:44 +00:00
ImageCur + = 15.0f ;
2010-05-29 07:25:38 +00:00
2022-06-11 19:38:18 +00:00
for ( int i = 0 ; i < ( int ) m_Map . m_vpImages . size ( ) ; i + + )
2008-01-13 22:03:32 +00:00
{
2022-06-11 19:38:18 +00:00
if ( ( e & & ! m_Map . m_vpImages [ i ] - > m_External ) | |
( ! e & & m_Map . m_vpImages [ i ] - > m_External ) )
2008-01-19 14:23:53 +00:00
{
continue ;
}
2010-05-29 07:25:38 +00:00
2010-06-05 22:46:47 +00:00
if ( ImageCur > ImageStopAt )
break ;
else if ( ImageCur < ImageStartAt )
{
2010-06-14 01:18:44 +00:00
ImageCur + = 14.0f ;
2010-06-05 22:46:47 +00:00
continue ;
}
2010-06-14 01:18:44 +00:00
ImageCur + = 14.0f ;
2010-06-05 22:46:47 +00:00
2010-05-29 07:25:38 +00:00
char aBuf [ 128 ] ;
2022-06-11 19:38:18 +00:00
str_copy ( aBuf , m_Map . m_vpImages [ i ] - > m_aName , sizeof ( aBuf ) ) ;
2010-05-29 07:25:38 +00:00
ToolBox . HSplitTop ( 12.0f , & Slot , & ToolBox ) ;
2014-07-10 03:20:40 +00:00
int Selected = m_SelectedImage = = i ;
2014-12-15 17:59:21 +00:00
2022-06-11 19:38:18 +00:00
const bool ImageUsed = std : : any_of ( m_Map . m_vpGroups . cbegin ( ) , m_Map . m_vpGroups . cend ( ) , [ i ] ( const auto & pGroup ) {
return std : : any_of ( pGroup - > m_vpLayers . cbegin ( ) , pGroup - > m_vpLayers . cend ( ) , [ i ] ( const auto & pLayer ) {
2022-05-24 09:24:33 +00:00
if ( pLayer - > m_Type = = LAYERTYPE_QUADS )
2022-05-28 08:45:15 +00:00
return static_cast < CLayerQuads * > ( pLayer ) - > m_Image = = i ;
2022-05-24 09:24:33 +00:00
else if ( pLayer - > m_Type = = LAYERTYPE_TILES )
2022-05-28 08:45:15 +00:00
return static_cast < CLayerTiles * > ( pLayer ) - > m_Image = = i ;
return false ;
} ) ;
} ) ;
2022-05-24 09:24:33 +00:00
if ( ! ImageUsed )
Selected + = 2 ; // Image is unused
2014-07-10 03:20:40 +00:00
2014-12-15 17:59:21 +00:00
if ( Selected < 2 & & e = = 1 )
{
2022-06-11 19:38:18 +00:00
if ( ! IsVanillaImage ( m_Map . m_vpImages [ i ] - > m_aName ) )
2014-12-15 17:59:21 +00:00
{
Selected + = 4 ; // Image should be embedded
2018-06-29 21:28:49 +00:00
}
2014-12-15 17:59:21 +00:00
}
2015-03-29 00:32:07 +00:00
float FontSize = 10.0f ;
2022-06-13 16:28:13 +00:00
while ( TextRender ( ) - > TextWidth ( nullptr , FontSize , aBuf , - 1 , - 1.0f ) > Slot . w )
2015-03-29 00:32:07 +00:00
FontSize - - ;
2022-06-11 19:38:18 +00:00
if ( int Result = DoButton_Ex ( & m_Map . m_vpImages [ i ] , aBuf , Selected , & Slot ,
2020-09-26 19:41:58 +00:00
BUTTON_CONTEXT , " Select image. " , 0 , FontSize ) )
2008-01-19 14:23:53 +00:00
{
2010-05-29 07:25:38 +00:00
m_SelectedImage = i ;
2011-02-12 10:40:36 +00:00
static int s_PopupImageID = 0 ;
2010-05-29 07:25:38 +00:00
if ( Result = = 2 )
2021-03-19 00:06:37 +00:00
{
2022-06-11 19:38:18 +00:00
CEditorImage * pImg = m_Map . m_vpImages [ m_SelectedImage ] ;
2021-03-19 00:06:37 +00:00
int Height ;
if ( pImg - > m_External | | IsVanillaImage ( pImg - > m_aName ) )
Height = 60 ;
else
Height = 43 ;
UiInvokePopupMenu ( & s_PopupImageID , 0 , UI ( ) - > MouseX ( ) , UI ( ) - > MouseY ( ) , 120 , Height , PopupImage ) ;
}
2008-01-19 14:23:53 +00:00
}
2010-05-29 07:25:38 +00:00
2022-06-13 16:28:13 +00:00
ToolBox . HSplitTop ( 2.0f , nullptr , & ToolBox ) ;
2007-12-02 17:55:45 +00:00
}
2011-08-04 21:51:54 +00:00
// separator
ToolBox . HSplitTop ( 5.0f , & Slot , & ToolBox ) ;
ImageCur + = 5.0f ;
2020-09-26 19:41:58 +00:00
IGraphics : : CLineItem LineItem ( Slot . x , Slot . y + Slot . h / 2 , Slot . x + Slot . w , Slot . y + Slot . h / 2 ) ;
2012-08-12 10:41:50 +00:00
Graphics ( ) - > TextureClear ( ) ;
2011-08-04 21:51:54 +00:00
Graphics ( ) - > LinesBegin ( ) ;
Graphics ( ) - > LinesDraw ( & LineItem , 1 ) ;
Graphics ( ) - > LinesEnd ( ) ;
2007-12-02 17:55:45 +00:00
}
2008-01-13 16:30:30 +00:00
2020-08-08 10:21:27 +00:00
if ( Input ( ) - > KeyPress ( KEY_DOWN ) & & m_Dialog = = DIALOG_NONE )
{
int OldImage = m_SelectedImage ;
2022-06-11 19:38:18 +00:00
m_SelectedImage = clamp ( m_SelectedImage , 0 , ( int ) m_Map . m_vpImages . size ( ) - 1 ) ;
for ( size_t i = m_SelectedImage + 1 ; i < m_Map . m_vpImages . size ( ) ; i + + )
2020-08-08 10:21:27 +00:00
{
2022-06-11 19:38:18 +00:00
if ( m_Map . m_vpImages [ i ] - > m_External = = m_Map . m_vpImages [ m_SelectedImage ] - > m_External )
2020-08-08 10:21:27 +00:00
{
m_SelectedImage = i ;
break ;
}
}
2022-06-11 19:38:18 +00:00
if ( m_SelectedImage = = OldImage & & ! m_Map . m_vpImages [ m_SelectedImage ] - > m_External )
2020-08-08 10:21:27 +00:00
{
2022-06-11 19:38:18 +00:00
for ( size_t i = 0 ; i < m_Map . m_vpImages . size ( ) ; i + + )
2020-08-08 10:21:27 +00:00
{
2022-06-11 19:38:18 +00:00
if ( m_Map . m_vpImages [ i ] - > m_External )
2020-08-08 10:21:27 +00:00
{
m_SelectedImage = i ;
break ;
}
}
}
}
if ( Input ( ) - > KeyPress ( KEY_UP ) & & m_Dialog = = DIALOG_NONE )
{
int OldImage = m_SelectedImage ;
2022-06-11 19:38:18 +00:00
m_SelectedImage = clamp ( m_SelectedImage , 0 , ( int ) m_Map . m_vpImages . size ( ) - 1 ) ;
2020-08-08 10:21:27 +00:00
for ( int i = m_SelectedImage - 1 ; i > = 0 ; i - - )
{
2022-06-11 19:38:18 +00:00
if ( m_Map . m_vpImages [ i ] - > m_External = = m_Map . m_vpImages [ m_SelectedImage ] - > m_External )
2020-08-08 10:21:27 +00:00
{
m_SelectedImage = i ;
break ;
}
}
2022-06-11 19:38:18 +00:00
if ( m_SelectedImage = = OldImage & & m_Map . m_vpImages [ m_SelectedImage ] - > m_External )
2020-08-08 10:21:27 +00:00
{
2022-06-11 19:38:18 +00:00
for ( int i = ( int ) m_Map . m_vpImages . size ( ) - 1 ; i > = 0 ; i - - )
2020-08-08 10:21:27 +00:00
{
2022-06-11 19:38:18 +00:00
if ( ! m_Map . m_vpImages [ i ] - > m_External )
2020-08-08 10:21:27 +00:00
{
m_SelectedImage = i ;
break ;
}
}
}
}
2015-04-07 23:15:52 +00:00
// render image
2015-04-17 18:14:14 +00:00
int i = m_SelectedImage ;
2022-06-11 19:38:18 +00:00
if ( i > = 0 & & ( size_t ) i < m_Map . m_vpImages . size ( ) )
2015-04-07 23:15:52 +00:00
{
CUIRect r ;
View . Margin ( 10.0f , & r ) ;
if ( r . h < r . w )
r . w = r . h ;
else
r . h = r . w ;
2022-06-11 19:38:18 +00:00
float Max = ( float ) ( maximum ( m_Map . m_vpImages [ i ] - > m_Width , m_Map . m_vpImages [ i ] - > m_Height ) ) ;
r . w * = m_Map . m_vpImages [ i ] - > m_Width / Max ;
r . h * = m_Map . m_vpImages [ i ] - > m_Height / Max ;
Graphics ( ) - > TextureSet ( m_Map . m_vpImages [ i ] - > m_Texture ) ;
2015-04-07 23:15:52 +00:00
Graphics ( ) - > BlendNormal ( ) ;
Graphics ( ) - > WrapClamp ( ) ;
Graphics ( ) - > QuadsBegin ( ) ;
IGraphics : : CQuadItem QuadItem ( r . x , r . y , r . w , r . h ) ;
Graphics ( ) - > QuadsDrawTL ( & QuadItem , 1 ) ;
Graphics ( ) - > QuadsEnd ( ) ;
Graphics ( ) - > WrapNormal ( ) ;
}
2014-06-11 22:36:26 +00:00
//if(ImageCur + 27.0f > ImageStopAt)
// return;
2010-06-14 01:18:44 +00:00
2010-05-29 07:25:38 +00:00
CUIRect Slot ;
ToolBox . HSplitTop ( 5.0f , & Slot , & ToolBox ) ;
2008-01-13 16:30:30 +00:00
2010-05-29 07:25:38 +00:00
// new image
static int s_NewImageButton = 0 ;
ToolBox . HSplitTop ( 12.0f , & Slot , & ToolBox ) ;
2011-03-20 16:04:03 +00:00
if ( DoButton_Editor ( & s_NewImageButton , " Add " , 0 , & Slot , 0 , " Load a new image to use in the map " ) )
InvokeFileDialog ( IStorage : : TYPE_ALL , FILETYPE_IMG , " Add Image " , " Add " , " mapres " , " " , AddImage , this ) ;
2010-05-29 07:25:38 +00:00
}
2018-04-04 19:41:14 +00:00
void CEditor : : RenderSounds ( CUIRect ToolBox , CUIRect View )
2014-10-08 12:50:25 +00:00
{
2021-11-26 20:55:31 +00:00
if ( ! m_GuiActive )
return ;
2014-10-08 12:50:25 +00:00
static float s_ScrollValue = 0 ;
2022-06-11 19:38:18 +00:00
float SoundsHeight = 30.0f + 14.0f * m_Map . m_vpSounds . size ( ) + 27.0f ;
2014-10-08 12:50:25 +00:00
float ScrollDifference = SoundsHeight - ToolBox . h ;
2020-09-26 19:41:58 +00:00
if ( SoundsHeight > ToolBox . h ) // Do we even need a scrollbar?
2014-10-08 12:50:25 +00:00
{
CUIRect Scroll ;
2021-11-26 20:55:31 +00:00
ToolBox . VSplitRight ( 20.0f , & ToolBox , & Scroll ) ;
s_ScrollValue = UIEx ( ) - > DoScrollbarV ( & s_ScrollValue , & Scroll , s_ScrollValue ) ;
2014-10-08 12:50:25 +00:00
if ( UI ( ) - > MouseInside ( & Scroll ) | | UI ( ) - > MouseInside ( & ToolBox ) )
{
2020-09-26 19:41:58 +00:00
int ScrollNum = ( int ) ( ( SoundsHeight - ToolBox . h ) / 14.0f ) + 1 ;
2014-10-08 12:50:25 +00:00
if ( ScrollNum > 0 )
{
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyPress ( KEY_MOUSE_WHEEL_UP ) )
2020-09-26 19:41:58 +00:00
s_ScrollValue = clamp ( s_ScrollValue - 1.0f / ScrollNum , 0.0f , 1.0f ) ;
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyPress ( KEY_MOUSE_WHEEL_DOWN ) )
2020-09-26 19:41:58 +00:00
s_ScrollValue = clamp ( s_ScrollValue + 1.0f / ScrollNum , 0.0f , 1.0f ) ;
2014-10-08 12:50:25 +00:00
}
}
}
float SoundStartAt = ScrollDifference * s_ScrollValue ;
if ( SoundStartAt < 0.0f )
SoundStartAt = 0.0f ;
float SoundStopAt = SoundsHeight - ScrollDifference * ( 1 - s_ScrollValue ) ;
2014-10-23 10:19:26 +00:00
float SoundCur = 0.0f ;
2014-10-08 12:50:25 +00:00
2020-10-17 14:41:00 +00:00
CUIRect Slot ;
ToolBox . HSplitTop ( 15.0f , & Slot , & ToolBox ) ;
2022-01-21 15:20:15 +00:00
UI ( ) - > DoLabel ( & Slot , " Embedded " , 12.0f , TEXTALIGN_CENTER ) ;
2020-10-17 14:41:00 +00:00
SoundCur + = 15.0f ;
2014-10-08 12:50:25 +00:00
2022-06-11 19:38:18 +00:00
for ( int i = 0 ; i < ( int ) m_Map . m_vpSounds . size ( ) ; i + + )
2020-10-17 14:41:00 +00:00
{
2014-10-23 10:19:26 +00:00
if ( SoundCur > SoundStopAt )
2014-10-08 12:50:25 +00:00
break ;
2020-10-17 14:41:00 +00:00
else if ( SoundCur < SoundStartAt )
2014-10-08 12:50:25 +00:00
{
2014-10-23 10:19:26 +00:00
SoundCur + = 14.0f ;
2020-10-17 14:41:00 +00:00
continue ;
}
SoundCur + = 14.0f ;
2014-10-08 12:50:25 +00:00
2020-10-17 14:41:00 +00:00
char aBuf [ 128 ] ;
2022-06-11 19:38:18 +00:00
str_copy ( aBuf , m_Map . m_vpSounds [ i ] - > m_aName , sizeof ( aBuf ) ) ;
2020-10-17 14:41:00 +00:00
ToolBox . HSplitTop ( 12.0f , & Slot , & ToolBox ) ;
2014-12-15 17:59:21 +00:00
2020-10-17 14:41:00 +00:00
int Selected = m_SelectedSound = = i ;
2022-06-11 19:38:18 +00:00
const bool SoundUsed = std : : any_of ( m_Map . m_vpGroups . cbegin ( ) , m_Map . m_vpGroups . cend ( ) , [ i ] ( const auto & pGroup ) {
return std : : any_of ( pGroup - > m_vpLayers . cbegin ( ) , pGroup - > m_vpLayers . cend ( ) , [ i ] ( const auto & pLayer ) {
2022-05-24 09:24:33 +00:00
if ( pLayer - > m_Type = = LAYERTYPE_SOUNDS )
2022-05-28 08:45:15 +00:00
return static_cast < CLayerSounds * > ( pLayer ) - > m_Sound = = i ;
return false ;
} ) ;
} ) ;
2022-05-24 09:24:33 +00:00
if ( ! SoundUsed )
Selected + = 2 ; // Sound is unused
2015-03-29 00:32:07 +00:00
2020-10-17 14:41:00 +00:00
float FontSize = 10.0f ;
2022-06-13 16:28:13 +00:00
while ( TextRender ( ) - > TextWidth ( nullptr , FontSize , aBuf , - 1 , - 1.0f ) > Slot . w )
2020-10-17 14:41:00 +00:00
FontSize - - ;
2014-10-08 12:50:25 +00:00
2022-06-11 19:38:18 +00:00
if ( int Result = DoButton_Ex ( & m_Map . m_vpSounds [ i ] , aBuf , Selected , & Slot ,
2020-10-17 14:41:00 +00:00
BUTTON_CONTEXT , " Select sound. " , 0 , FontSize ) )
{
m_SelectedSound = i ;
2014-10-08 12:50:25 +00:00
2020-10-17 14:41:00 +00:00
static int s_PopupSoundID = 0 ;
if ( Result = = 2 )
UiInvokePopupMenu ( & s_PopupSoundID , 0 , UI ( ) - > MouseX ( ) , UI ( ) - > MouseY ( ) , 120 , 43 , PopupSound ) ;
2014-10-08 12:50:25 +00:00
}
2022-06-13 16:28:13 +00:00
ToolBox . HSplitTop ( 2.0f , nullptr , & ToolBox ) ;
2014-10-08 12:50:25 +00:00
}
2020-10-17 14:41:00 +00:00
// separator
ToolBox . HSplitTop ( 5.0f , & Slot , & ToolBox ) ;
IGraphics : : CLineItem LineItem ( Slot . x , Slot . y + Slot . h / 2 , Slot . x + Slot . w , Slot . y + Slot . h / 2 ) ;
Graphics ( ) - > TextureClear ( ) ;
Graphics ( ) - > LinesBegin ( ) ;
Graphics ( ) - > LinesDraw ( & LineItem , 1 ) ;
Graphics ( ) - > LinesEnd ( ) ;
2020-08-08 10:21:27 +00:00
if ( Input ( ) - > KeyPress ( KEY_DOWN ) & & m_Dialog = = DIALOG_NONE )
{
2022-06-11 19:38:18 +00:00
m_SelectedSound = clamp ( m_SelectedSound , 0 , ( int ) m_Map . m_vpSounds . size ( ) - 1 ) ;
if ( m_SelectedSound = = ( int ) m_Map . m_vpSounds . size ( ) - 1 )
2020-10-17 14:41:00 +00:00
m_SelectedSound = 0 ;
else
m_SelectedSound + = 1 ;
2020-08-08 10:21:27 +00:00
}
if ( Input ( ) - > KeyPress ( KEY_UP ) & & m_Dialog = = DIALOG_NONE )
{
2022-06-11 19:38:18 +00:00
m_SelectedSound = clamp ( m_SelectedSound , 0 , ( int ) m_Map . m_vpSounds . size ( ) - 1 ) ;
if ( m_SelectedSound = = 0 & & ! m_Map . m_vpSounds . empty ( ) )
m_SelectedSound = m_Map . m_vpSounds . size ( ) - 1 ;
2020-10-17 14:41:00 +00:00
else
m_SelectedSound - = 1 ;
2020-08-08 10:21:27 +00:00
}
2020-10-17 14:41:00 +00:00
//CUIRect Slot;
2014-10-08 12:50:25 +00:00
ToolBox . HSplitTop ( 5.0f , & Slot , & ToolBox ) ;
// new Sound
static int s_NewSoundButton = 0 ;
ToolBox . HSplitTop ( 12.0f , & Slot , & ToolBox ) ;
if ( DoButton_Editor ( & s_NewSoundButton , " Add " , 0 , & Slot , 0 , " Load a new sound to use in the map " ) )
InvokeFileDialog ( IStorage : : TYPE_ALL , FILETYPE_SOUND , " Add Sound " , " Add " , " mapres " , " " , AddSound , this ) ;
}
2011-02-21 10:23:30 +00:00
static int EditorListdirCallback ( const char * pName , int IsDir , int StorageType , void * pUser )
2008-01-12 12:27:55 +00:00
{
2020-09-26 19:41:58 +00:00
CEditor * pEditor = ( CEditor * ) pUser ;
2010-10-07 21:51:07 +00:00
if ( ( pName [ 0 ] = = ' . ' & & ( pName [ 1 ] = = 0 | |
2020-09-26 19:41:58 +00:00
( pName [ 1 ] = = ' . ' & & pName [ 2 ] = = 0 & & ( ! str_comp ( pEditor - > m_pFileDialogPath , " maps " ) | | ! str_comp ( pEditor - > m_pFileDialogPath , " mapres " ) ) ) ) ) | |
2018-07-25 08:29:05 +00:00
( ! IsDir & & ( ( pEditor - > m_FileDialogFileType = = CEditor : : FILETYPE_MAP & & ! str_endswith ( pName , " .map " ) ) | |
2020-09-26 19:41:58 +00:00
( pEditor - > m_FileDialogFileType = = CEditor : : FILETYPE_IMG & & ! str_endswith ( pName , " .png " ) ) | |
( pEditor - > m_FileDialogFileType = = CEditor : : FILETYPE_SOUND & & ! str_endswith ( pName , " .opus " ) ) ) ) )
2011-02-21 10:23:30 +00:00
return 0 ;
2010-05-29 07:25:38 +00:00
2010-10-06 21:07:35 +00:00
CEditor : : CFilelistItem Item ;
str_copy ( Item . m_aFilename , pName , sizeof ( Item . m_aFilename ) ) ;
if ( IsDir )
str_format ( Item . m_aName , sizeof ( Item . m_aName ) , " %s/ " , pName ) ;
else
2014-10-11 11:38:45 +00:00
{
2020-10-26 11:56:21 +00:00
int LenEnding = pEditor - > m_FileDialogFileType = = CEditor : : FILETYPE_SOUND ? 5 : 4 ;
str_truncate ( Item . m_aName , sizeof ( Item . m_aName ) , pName , str_length ( pName ) - LenEnding ) ;
2014-10-11 11:38:45 +00:00
}
2010-10-06 21:07:35 +00:00
Item . m_IsDir = IsDir ! = 0 ;
2010-10-07 21:51:07 +00:00
Item . m_IsLink = false ;
2010-10-06 21:07:35 +00:00
Item . m_StorageType = StorageType ;
2022-06-11 19:38:18 +00:00
pEditor - > m_vFileList . push_back ( Item ) ;
2011-02-21 10:23:30 +00:00
return 0 ;
2010-06-01 20:49:35 +00:00
}
2010-10-07 21:51:07 +00:00
void CEditor : : AddFileDialogEntry ( int Index , CUIRect * pView )
2010-06-01 20:49:35 +00:00
{
2010-09-12 11:15:59 +00:00
m_FilesCur + + ;
2020-09-26 19:41:58 +00:00
if ( m_FilesCur - 1 < m_FilesStartAt | | m_FilesCur > = m_FilesStopAt )
2008-10-29 12:15:58 +00:00
return ;
2010-05-29 07:25:38 +00:00
2010-11-17 18:46:50 +00:00
CUIRect Button , FileIcon ;
2010-05-29 07:25:38 +00:00
pView - > HSplitTop ( 15.0f , & Button , pView ) ;
2022-06-13 16:28:13 +00:00
pView - > HSplitTop ( 2.0f , nullptr , pView ) ;
2010-11-17 18:46:50 +00:00
Button . VSplitLeft ( Button . h , & FileIcon , & Button ) ;
2022-06-13 16:28:13 +00:00
Button . VSplitLeft ( 5.0f , nullptr , & Button ) ;
2010-11-17 18:46:50 +00:00
2022-06-25 15:16:20 +00:00
RenderTools ( ) - > RenderIcon ( IMAGE_FILEICONS , m_vFileList [ Index ] . m_IsDir ? SPRITE_FILE_FOLDER : SPRITE_FILE_MAP2 , & FileIcon ) ;
2010-05-29 07:25:38 +00:00
2022-06-13 16:28:13 +00:00
if ( DoButton_File ( & m_vFileList [ Index ] , m_vFileList [ Index ] . m_aName , m_FilesSelectedIndex = = Index , & Button , 0 , nullptr ) )
2008-01-13 22:03:32 +00:00
{
2022-06-11 19:38:18 +00:00
if ( ! m_vFileList [ Index ] . m_IsDir )
str_copy ( m_aFileDialogFileName , m_vFileList [ Index ] . m_aFilename , sizeof ( m_aFileDialogFileName ) ) ;
2010-10-07 21:51:07 +00:00
else
m_aFileDialogFileName [ 0 ] = 0 ;
2012-08-12 10:41:50 +00:00
m_PreviewImageIsLoaded = false ;
2022-02-10 16:40:03 +00:00
m_FileDialogActivate | = Index = = m_FilesSelectedIndex & & Input ( ) - > MouseDoubleClick ( ) ;
m_FilesSelectedIndex = Index ;
2008-01-13 22:03:32 +00:00
}
2008-01-12 12:27:55 +00:00
}
2010-05-29 07:25:38 +00:00
void CEditor : : RenderFileDialog ( )
2008-01-12 12:27:55 +00:00
{
// GUI coordsys
2021-09-22 19:48:55 +00:00
UI ( ) - > MapScreen ( ) ;
2010-05-29 07:25:38 +00:00
CUIRect View = * UI ( ) - > Screen ( ) ;
2014-03-28 21:47:57 +00:00
CUIRect Preview ;
2011-03-20 21:53:50 +00:00
float Width = View . w , Height = View . h ;
2020-09-26 19:41:58 +00:00
RenderTools ( ) - > DrawUIRect ( & View , ColorRGBA ( 0 , 0 , 0 , 0.25f ) , 0 , 0 ) ;
2010-05-29 07:25:38 +00:00
View . VMargin ( 150.0f , & View ) ;
View . HMargin ( 50.0f , & View ) ;
2020-09-26 19:41:58 +00:00
RenderTools ( ) - > DrawUIRect ( & View , ColorRGBA ( 0 , 0 , 0 , 0.75f ) , CUI : : CORNER_ALL , 5.0f ) ;
2010-05-29 07:25:38 +00:00
View . Margin ( 10.0f , & View ) ;
2012-01-08 12:14:02 +00:00
CUIRect Title , FileBox , FileBoxLabel , ButtonBar , Scroll , PathBox ;
2010-05-29 07:25:38 +00:00
View . HSplitTop ( 18.0f , & Title , & View ) ;
2022-06-13 16:28:13 +00:00
View . HSplitTop ( 5.0f , nullptr , & View ) ; // some spacing
2010-05-29 07:25:38 +00:00
View . HSplitBottom ( 14.0f , & View , & ButtonBar ) ;
2022-06-13 16:28:13 +00:00
View . HSplitBottom ( 10.0f , & View , nullptr ) ; // some spacing
2012-01-08 12:14:02 +00:00
View . HSplitBottom ( 14.0f , & View , & PathBox ) ;
2022-06-13 16:28:13 +00:00
View . HSplitBottom ( 5.0f , & View , nullptr ) ; // some spacing
2010-05-29 07:25:38 +00:00
View . HSplitBottom ( 14.0f , & View , & FileBox ) ;
FileBox . VSplitLeft ( 55.0f , & FileBoxLabel , & FileBox ) ;
2022-06-13 16:28:13 +00:00
View . HSplitBottom ( 10.0f , & View , nullptr ) ; // some spacing
2018-03-13 20:59:07 +00:00
if ( m_FileDialogFileType = = CEditor : : FILETYPE_IMG )
2014-03-28 21:47:57 +00:00
View . VSplitMid ( & View , & Preview ) ;
2021-11-26 20:55:31 +00:00
View . VSplitRight ( 20.0f , & View , & Scroll ) ;
2010-05-29 07:25:38 +00:00
2008-01-13 16:30:30 +00:00
// title
2019-04-26 21:47:34 +00:00
RenderTools ( ) - > DrawUIRect ( & Title , ColorRGBA ( 1 , 1 , 1 , 0.25f ) , CUI : : CORNER_ALL , 4.0f ) ;
2010-05-29 07:25:38 +00:00
Title . VMargin ( 10.0f , & Title ) ;
2022-03-11 16:34:48 +00:00
UI ( ) - > DoLabel ( & Title , m_pFileDialogTitle , 12.0f , TEXTALIGN_LEFT ) ;
2010-05-29 07:25:38 +00:00
2012-01-08 12:14:02 +00:00
// pathbox
char aPath [ 128 ] , aBuf [ 128 ] ;
if ( m_FilesSelectedIndex ! = - 1 )
2022-06-11 19:38:18 +00:00
Storage ( ) - > GetCompletePath ( m_vFileList [ m_FilesSelectedIndex ] . m_StorageType , m_pFileDialogPath , aPath , sizeof ( aPath ) ) ;
2012-01-08 12:14:02 +00:00
else
aPath [ 0 ] = 0 ;
str_format ( aBuf , sizeof ( aBuf ) , " Current path: %s " , aPath ) ;
2022-03-11 16:34:48 +00:00
UI ( ) - > DoLabel ( & PathBox , aBuf , 10.0f , TEXTALIGN_LEFT ) ;
2017-02-21 16:10:08 +00:00
2010-10-07 21:51:07 +00:00
if ( m_FileDialogStorageType = = IStorage : : TYPE_SAVE )
{
2016-08-20 23:47:39 +00:00
// filebox
2022-03-11 16:34:48 +00:00
UI ( ) - > DoLabel ( & FileBoxLabel , " Filename: " , 10.0f , TEXTALIGN_LEFT ) ;
2021-12-03 19:15:44 +00:00
static float s_FileBoxID = 0 ;
2011-07-12 01:14:46 +00:00
if ( DoEditBox ( & s_FileBoxID , & FileBox , m_aFileDialogFileName , sizeof ( m_aFileDialogFileName ) , 10.0f , & s_FileBoxID ) )
2010-10-07 21:51:07 +00:00
{
// remove '/' and '\'
for ( int i = 0 ; m_aFileDialogFileName [ i ] ; + + i )
if ( m_aFileDialogFileName [ i ] = = ' / ' | | m_aFileDialogFileName [ i ] = = ' \\ ' )
2020-09-26 19:41:58 +00:00
str_copy ( & m_aFileDialogFileName [ i ] , & m_aFileDialogFileName [ i + 1 ] , ( int ) ( sizeof ( m_aFileDialogFileName ) ) - i ) ;
2010-10-07 21:51:07 +00:00
m_FilesSelectedIndex = - 1 ;
}
2021-11-22 17:26:13 +00:00
if ( m_FileDialogOpening )
UI ( ) - > SetActiveItem ( & s_FileBoxID ) ;
2010-10-07 21:51:07 +00:00
}
2016-08-20 23:47:39 +00:00
else
{
//searchbox
2022-06-13 16:28:13 +00:00
FileBox . VSplitRight ( 250 , & FileBox , nullptr ) ;
2016-08-20 23:47:39 +00:00
CUIRect ClearBox ;
FileBox . VSplitRight ( 15 , & FileBox , & ClearBox ) ;
2017-02-21 16:10:08 +00:00
2022-03-11 16:34:48 +00:00
UI ( ) - > DoLabel ( & FileBoxLabel , " Search: " , 10.0f , TEXTALIGN_LEFT ) ;
2018-10-08 15:38:22 +00:00
str_copy ( m_aFileDialogPrevSearchText , m_aFileDialogSearchText , sizeof ( m_aFileDialogPrevSearchText ) ) ;
2021-12-03 19:15:44 +00:00
static float s_SearchBoxID = 0 ;
2020-09-26 19:41:58 +00:00
DoEditBox ( & s_SearchBoxID , & FileBox , m_aFileDialogSearchText , sizeof ( m_aFileDialogSearchText ) , 10.0f , & s_SearchBoxID , false , CUI : : CORNER_L ) ;
2020-09-01 07:48:51 +00:00
if ( m_FileDialogOpening )
UI ( ) - > SetActiveItem ( & s_SearchBoxID ) ;
2017-02-21 16:10:08 +00:00
2016-08-20 23:47:39 +00:00
// clearSearchbox button
{
static int s_ClearButton = 0 ;
2021-11-26 20:55:31 +00:00
RenderTools ( ) - > DrawUIRect ( & ClearBox , ColorRGBA ( 1 , 1 , 1 , 0.33f * UI ( ) - > ButtonColorMul ( & s_ClearButton ) ) , CUI : : CORNER_R , 3.0f ) ;
2022-01-21 15:20:15 +00:00
UI ( ) - > DoLabel ( & ClearBox , " × " , 10.0f , TEXTALIGN_CENTER ) ;
2022-05-13 22:26:15 +00:00
if ( UI ( ) - > DoButtonLogic ( & s_ClearButton , 0 , & ClearBox ) )
2016-08-20 23:47:39 +00:00
{
m_aFileDialogSearchText [ 0 ] = 0 ;
UI ( ) - > SetActiveItem ( & s_SearchBoxID ) ;
}
}
2018-10-08 15:38:22 +00:00
if ( str_comp ( m_aFileDialogPrevSearchText , m_aFileDialogSearchText ) )
m_FileDialogScrollValue = 0.0f ;
2016-08-20 23:47:39 +00:00
}
2010-05-29 07:25:38 +00:00
2020-09-01 07:48:51 +00:00
m_FileDialogOpening = false ;
2020-09-26 19:41:58 +00:00
int Num = ( int ) ( View . h / 17.0f ) + 1 ;
2021-11-26 20:55:31 +00:00
m_FileDialogScrollValue = UIEx ( ) - > DoScrollbarV ( & m_FileDialogScrollValue , & Scroll , m_FileDialogScrollValue ) ;
2010-05-29 07:25:38 +00:00
2018-10-08 15:39:23 +00:00
int ScrollNum = 0 ;
2022-06-11 19:38:18 +00:00
for ( size_t i = 0 ; i < m_vFileList . size ( ) ; i + + )
2018-10-08 15:39:23 +00:00
{
2022-06-11 19:38:18 +00:00
m_vFileList [ i ] . m_IsVisible = false ;
if ( ! m_aFileDialogSearchText [ 0 ] | | str_utf8_find_nocase ( m_vFileList [ i ] . m_aName , m_aFileDialogSearchText ) )
2018-10-08 15:39:23 +00:00
{
AddFileDialogEntry ( i , & View ) ;
2022-06-11 19:38:18 +00:00
m_vFileList [ i ] . m_IsVisible = true ;
2018-10-08 15:39:23 +00:00
ScrollNum + + ;
}
}
ScrollNum - = Num - 1 ;
2010-05-29 07:25:38 +00:00
if ( ScrollNum > 0 )
2009-01-10 17:17:38 +00:00
{
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyPress ( KEY_MOUSE_WHEEL_UP ) )
2020-09-26 19:41:58 +00:00
m_FileDialogScrollValue - = 3.0f / ScrollNum ;
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyPress ( KEY_MOUSE_WHEEL_DOWN ) )
2020-09-26 19:41:58 +00:00
m_FileDialogScrollValue + = 3.0f / ScrollNum ;
2009-01-10 17:17:38 +00:00
}
else
2010-05-29 07:25:38 +00:00
ScrollNum = 0 ;
2010-10-07 21:51:07 +00:00
if ( m_FilesSelectedIndex > - 1 )
{
2022-06-11 19:38:18 +00:00
if ( ! m_vFileList [ m_FilesSelectedIndex ] . m_IsVisible )
2019-04-13 11:18:47 +00:00
{
m_FilesSelectedIndex = 0 ;
}
2010-10-07 21:51:07 +00:00
for ( int i = 0 ; i < Input ( ) - > NumEvents ( ) ; i + + )
{
int NewIndex = - 1 ;
2020-09-26 19:41:58 +00:00
if ( Input ( ) - > GetEvent ( i ) . m_Flags & IInput : : FLAG_PRESS )
2010-10-07 21:51:07 +00:00
{
2018-10-08 16:07:25 +00:00
if ( Input ( ) - > GetEvent ( i ) . m_Key = = KEY_DOWN )
{
2022-06-11 19:38:18 +00:00
for ( NewIndex = m_FilesSelectedIndex + 1 ; NewIndex < ( int ) m_vFileList . size ( ) ; NewIndex + + )
2018-10-08 16:07:25 +00:00
{
2022-06-11 19:38:18 +00:00
if ( m_vFileList [ NewIndex ] . m_IsVisible )
2018-10-08 16:07:25 +00:00
break ;
}
}
if ( Input ( ) - > GetEvent ( i ) . m_Key = = KEY_UP )
{
for ( NewIndex = m_FilesSelectedIndex - 1 ; NewIndex > = 0 ; NewIndex - - )
{
2022-06-11 19:38:18 +00:00
if ( m_vFileList [ NewIndex ] . m_IsVisible )
2018-10-08 16:07:25 +00:00
break ;
}
}
2010-10-07 21:51:07 +00:00
}
2022-06-11 19:38:18 +00:00
if ( NewIndex > - 1 & & NewIndex < ( int ) m_vFileList . size ( ) )
2010-10-07 21:51:07 +00:00
{
//scroll
2020-09-26 19:41:58 +00:00
float IndexY = View . y - m_FileDialogScrollValue * ScrollNum * 17.0f + NewIndex * 17.0f ;
2022-03-20 11:57:50 +00:00
int ScrollPos = View . y > IndexY ? - 1 : View . y + View . h < IndexY + 17.0f ? 1 : 0 ;
if ( ScrollPos )
2010-10-07 21:51:07 +00:00
{
2022-03-20 11:57:50 +00:00
if ( ScrollPos < 0 )
2020-09-26 19:41:58 +00:00
m_FileDialogScrollValue = ( ( float ) ( NewIndex ) + 0.5f ) / ScrollNum ;
2010-10-07 21:51:07 +00:00
else
2020-09-26 19:41:58 +00:00
m_FileDialogScrollValue = ( ( float ) ( NewIndex - Num ) + 2.5f ) / ScrollNum ;
2010-10-07 21:51:07 +00:00
}
2022-06-11 19:38:18 +00:00
if ( ! m_vFileList [ NewIndex ] . m_IsDir )
str_copy ( m_aFileDialogFileName , m_vFileList [ NewIndex ] . m_aFilename , sizeof ( m_aFileDialogFileName ) ) ;
2010-10-07 21:51:07 +00:00
else
m_aFileDialogFileName [ 0 ] = 0 ;
m_FilesSelectedIndex = NewIndex ;
2012-08-12 10:41:50 +00:00
m_PreviewImageIsLoaded = false ;
2010-10-07 21:51:07 +00:00
}
}
2014-03-28 21:47:57 +00:00
2012-08-12 10:41:50 +00:00
if ( m_FileDialogFileType = = CEditor : : FILETYPE_IMG & & ! m_PreviewImageIsLoaded & & m_FilesSelectedIndex > - 1 )
2014-03-28 21:47:57 +00:00
{
2022-06-11 19:38:18 +00:00
if ( str_endswith ( m_vFileList [ m_FilesSelectedIndex ] . m_aFilename , " .png " ) )
2014-03-28 21:47:57 +00:00
{
2014-10-28 21:54:24 +00:00
char aBuffer [ 1024 ] ;
2022-06-11 19:38:18 +00:00
str_format ( aBuffer , sizeof ( aBuffer ) , " %s/%s " , m_pFileDialogPath , m_vFileList [ m_FilesSelectedIndex ] . m_aFilename ) ;
2014-10-28 21:54:24 +00:00
if ( Graphics ( ) - > LoadPNG ( & m_FilePreviewImageInfo , aBuffer , IStorage : : TYPE_ALL ) )
{
2021-05-21 12:57:55 +00:00
m_FilePreviewImage = Graphics ( ) - > LoadTextureRaw ( m_FilePreviewImageInfo . m_Width , m_FilePreviewImageInfo . m_Height , m_FilePreviewImageInfo . m_Format , m_FilePreviewImageInfo . m_pData , m_FilePreviewImageInfo . m_Format , 0 ) ;
2020-11-25 12:05:53 +00:00
CImageInfo DummyInfo = m_FilePreviewImageInfo ;
2022-06-13 16:28:13 +00:00
m_FilePreviewImageInfo . m_pData = nullptr ;
2020-11-25 12:05:53 +00:00
Graphics ( ) - > FreePNG ( & DummyInfo ) ;
2012-08-12 10:41:50 +00:00
m_PreviewImageIsLoaded = true ;
2014-10-28 21:54:24 +00:00
}
2014-03-28 21:47:57 +00:00
}
}
2022-01-22 12:24:45 +00:00
if ( m_FileDialogFileType = = CEditor : : FILETYPE_IMG & & m_PreviewImageIsLoaded )
2014-03-28 21:47:57 +00:00
{
int w = m_FilePreviewImageInfo . m_Width ;
int h = m_FilePreviewImageInfo . m_Height ;
2022-01-22 12:24:45 +00:00
if ( m_FilePreviewImageInfo . m_Width > Preview . w ) // NOLINT(clang-analyzer-core.UndefinedBinaryOperatorResult)
2014-03-28 21:47:57 +00:00
{
h = m_FilePreviewImageInfo . m_Height * Preview . w / m_FilePreviewImageInfo . m_Width ;
w = Preview . w ;
}
2018-03-13 20:59:07 +00:00
if ( h > Preview . h )
2014-03-28 21:47:57 +00:00
{
2022-05-28 00:15:42 +00:00
w = w * Preview . h / h ;
2014-03-28 21:47:57 +00:00
h = Preview . h ;
}
Graphics ( ) - > TextureSet ( m_FilePreviewImage ) ;
Graphics ( ) - > BlendNormal ( ) ;
Graphics ( ) - > QuadsBegin ( ) ;
IGraphics : : CQuadItem QuadItem ( Preview . x , Preview . y , w , h ) ;
Graphics ( ) - > QuadsDrawTL ( & QuadItem , 1 ) ;
Graphics ( ) - > QuadsEnd ( ) ;
}
2010-10-07 21:51:07 +00:00
}
for ( int i = 0 ; i < Input ( ) - > NumEvents ( ) ; i + + )
{
2021-11-22 17:12:30 +00:00
if ( Input ( ) - > GetEvent ( i ) . m_Flags & IInput : : FLAG_PRESS & & ! UiPopupOpen ( ) & & ! m_PopupEventActivated )
2010-10-07 21:51:07 +00:00
{
if ( Input ( ) - > GetEvent ( i ) . m_Key = = KEY_RETURN | | Input ( ) - > GetEvent ( i ) . m_Key = = KEY_KP_ENTER )
2020-09-01 07:47:17 +00:00
m_FileDialogActivate = true ;
2010-10-07 21:51:07 +00:00
}
}
2020-09-26 19:41:58 +00:00
if ( m_FileDialogScrollValue < 0 )
m_FileDialogScrollValue = 0 ;
if ( m_FileDialogScrollValue > 1 )
m_FileDialogScrollValue = 1 ;
2010-10-07 21:51:07 +00:00
2020-09-26 19:41:58 +00:00
m_FilesStartAt = ( int ) ( ScrollNum * m_FileDialogScrollValue ) ;
2010-09-12 11:15:59 +00:00
if ( m_FilesStartAt < 0 )
m_FilesStartAt = 0 ;
2010-05-29 07:25:38 +00:00
2020-09-26 19:41:58 +00:00
m_FilesStopAt = m_FilesStartAt + Num ;
2010-05-29 07:25:38 +00:00
2010-09-12 11:15:59 +00:00
m_FilesCur = 0 ;
2010-05-29 07:25:38 +00:00
2008-10-29 12:15:58 +00:00
// set clipping
2010-05-29 07:25:38 +00:00
UI ( ) - > ClipEnable ( & View ) ;
2008-10-29 12:15:58 +00:00
// disable clipping again
2009-10-27 14:38:53 +00:00
UI ( ) - > ClipDisable ( ) ;
2010-05-29 07:25:38 +00:00
2008-01-13 16:30:30 +00:00
// the buttons
2010-05-29 07:25:38 +00:00
static int s_OkButton = 0 ;
static int s_CancelButton = 0 ;
2010-10-16 16:33:54 +00:00
static int s_NewFolderButton = 0 ;
2011-07-12 21:31:39 +00:00
static int s_MapInfoButton = 0 ;
2008-01-13 16:30:30 +00:00
2010-05-29 07:25:38 +00:00
CUIRect Button ;
ButtonBar . VSplitRight ( 50.0f , & ButtonBar , & Button ) ;
2022-06-11 19:38:18 +00:00
bool IsDir = m_FilesSelectedIndex > = 0 & & m_vFileList [ m_FilesSelectedIndex ] . m_IsDir ;
2022-06-13 16:28:13 +00:00
if ( DoButton_Editor ( & s_OkButton , IsDir ? " Open " : m_pFileDialogButtonText , 0 , & Button , 0 , nullptr ) | | m_FileDialogActivate )
2008-01-13 16:30:30 +00:00
{
2020-09-01 07:47:17 +00:00
m_FileDialogActivate = false ;
2020-09-26 19:41:58 +00:00
if ( IsDir ) // folder
2010-10-07 21:51:07 +00:00
{
2022-06-11 19:38:18 +00:00
if ( str_comp ( m_vFileList [ m_FilesSelectedIndex ] . m_aFilename , " .. " ) = = 0 ) // parent folder
2010-10-07 21:51:07 +00:00
{
if ( fs_parent_dir ( m_pFileDialogPath ) )
2020-09-26 19:41:58 +00:00
m_pFileDialogPath = m_aFileDialogCurrentFolder ; // leave the link
2010-10-07 21:51:07 +00:00
}
2020-09-26 19:41:58 +00:00
else // sub folder
2010-10-07 21:51:07 +00:00
{
2022-06-11 19:38:18 +00:00
if ( m_vFileList [ m_FilesSelectedIndex ] . m_IsLink )
2010-10-07 21:51:07 +00:00
{
2020-09-26 19:41:58 +00:00
m_pFileDialogPath = m_aFileDialogCurrentLink ; // follow the link
2022-06-11 19:38:18 +00:00
str_copy ( m_aFileDialogCurrentLink , m_vFileList [ m_FilesSelectedIndex ] . m_aFilename , sizeof ( m_aFileDialogCurrentLink ) ) ;
2010-10-07 21:51:07 +00:00
}
else
{
2021-09-13 08:06:34 +00:00
char aTemp [ IO_MAX_PATH_LENGTH ] ;
2010-10-07 21:51:07 +00:00
str_copy ( aTemp , m_pFileDialogPath , sizeof ( aTemp ) ) ;
2022-06-11 19:38:18 +00:00
str_format ( m_pFileDialogPath , IO_MAX_PATH_LENGTH , " %s/%s " , aTemp , m_vFileList [ m_FilesSelectedIndex ] . m_aFilename ) ;
2010-10-07 21:51:07 +00:00
}
}
FilelistPopulate ( ! str_comp ( m_pFileDialogPath , " maps " ) | | ! str_comp ( m_pFileDialogPath , " mapres " ) ? m_FileDialogStorageType :
2022-06-11 19:38:18 +00:00
m_vFileList [ m_FilesSelectedIndex ] . m_StorageType ) ;
if ( m_FilesSelectedIndex > = 0 & & ! m_vFileList [ m_FilesSelectedIndex ] . m_IsDir )
str_copy ( m_aFileDialogFileName , m_vFileList [ m_FilesSelectedIndex ] . m_aFilename , sizeof ( m_aFileDialogFileName ) ) ;
2010-10-07 21:51:07 +00:00
else
m_aFileDialogFileName [ 0 ] = 0 ;
}
else // file
{
2011-03-21 23:31:42 +00:00
str_format ( m_aFileSaveName , sizeof ( m_aFileSaveName ) , " %s/%s " , m_pFileDialogPath , m_aFileDialogFileName ) ;
if ( ! str_comp ( m_pFileDialogButtonText , " Save " ) )
{
IOHANDLE File = Storage ( ) - > OpenFile ( m_aFileSaveName , IOFLAG_READ , IStorage : : TYPE_SAVE ) ;
if ( File )
{
io_close ( File ) ;
m_PopupEventType = POPEVENT_SAVE ;
m_PopupEventActivated = true ;
}
2020-09-26 19:41:58 +00:00
else if ( m_pfnFileDialogFunc )
2022-06-11 19:38:18 +00:00
m_pfnFileDialogFunc ( m_aFileSaveName , m_FilesSelectedIndex > = 0 ? m_vFileList [ m_FilesSelectedIndex ] . m_StorageType : m_FileDialogStorageType , m_pFileDialogUser ) ;
2020-09-26 19:41:58 +00:00
}
else if ( m_pfnFileDialogFunc )
2022-06-11 19:38:18 +00:00
m_pfnFileDialogFunc ( m_aFileSaveName , m_FilesSelectedIndex > = 0 ? m_vFileList [ m_FilesSelectedIndex ] . m_StorageType : m_FileDialogStorageType , m_pFileDialogUser ) ;
2010-10-07 21:51:07 +00:00
}
2008-01-13 16:30:30 +00:00
}
2010-05-29 07:25:38 +00:00
ButtonBar . VSplitRight ( 40.0f , & ButtonBar , & Button ) ;
ButtonBar . VSplitRight ( 50.0f , & ButtonBar , & Button ) ;
2022-06-13 16:28:13 +00:00
if ( DoButton_Editor ( & s_CancelButton , " Cancel " , 0 , & Button , 0 , nullptr ) | | Input ( ) - > KeyIsPressed ( KEY_ESCAPE ) )
2010-05-29 07:25:38 +00:00
m_Dialog = DIALOG_NONE ;
2010-10-16 16:33:54 +00:00
if ( m_FileDialogStorageType = = IStorage : : TYPE_SAVE )
{
ButtonBar . VSplitLeft ( 70.0f , & Button , & ButtonBar ) ;
2022-06-13 16:28:13 +00:00
if ( DoButton_Editor ( & s_NewFolderButton , " New folder " , 0 , & Button , 0 , nullptr ) )
2010-10-16 16:33:54 +00:00
{
2021-12-03 17:01:37 +00:00
m_aFileDialogNewFolderName [ 0 ] = 0 ;
2022-06-30 22:36:32 +00:00
m_aFileDialogErrString [ 0 ] = 0 ;
2011-03-20 21:53:50 +00:00
static int s_NewFolderPopupID = 0 ;
2020-09-26 19:41:58 +00:00
UiInvokePopupMenu ( & s_NewFolderPopupID , 0 , Width / 2.0f - 200.0f , Height / 2.0f - 100.0f , 400.0f , 200.0f , PopupNewFolder ) ;
2022-05-27 09:59:14 +00:00
UI ( ) - > SetActiveItem ( nullptr ) ;
2010-10-16 16:33:54 +00:00
}
}
2011-07-12 21:31:39 +00:00
if ( m_FileDialogStorageType = = IStorage : : TYPE_SAVE )
{
2022-06-13 16:28:13 +00:00
ButtonBar . VSplitLeft ( 40.0f , nullptr , & ButtonBar ) ;
2011-07-12 21:31:39 +00:00
ButtonBar . VSplitLeft ( 70.0f , & Button , & ButtonBar ) ;
2022-06-13 16:28:13 +00:00
if ( DoButton_Editor ( & s_MapInfoButton , " Map details " , 0 , & Button , 0 , nullptr ) )
2011-07-12 21:31:39 +00:00
{
str_copy ( m_Map . m_MapInfo . m_aAuthorTmp , m_Map . m_MapInfo . m_aAuthor , sizeof ( m_Map . m_MapInfo . m_aAuthorTmp ) ) ;
str_copy ( m_Map . m_MapInfo . m_aVersionTmp , m_Map . m_MapInfo . m_aVersion , sizeof ( m_Map . m_MapInfo . m_aVersionTmp ) ) ;
str_copy ( m_Map . m_MapInfo . m_aCreditsTmp , m_Map . m_MapInfo . m_aCredits , sizeof ( m_Map . m_MapInfo . m_aCreditsTmp ) ) ;
str_copy ( m_Map . m_MapInfo . m_aLicenseTmp , m_Map . m_MapInfo . m_aLicense , sizeof ( m_Map . m_MapInfo . m_aLicenseTmp ) ) ;
static int s_MapInfoPopupID = 0 ;
2020-09-26 19:41:58 +00:00
UiInvokePopupMenu ( & s_MapInfoPopupID , 0 , Width / 2.0f - 200.0f , Height / 2.0f - 100.0f , 400.0f , 200.0f , PopupMapInfo ) ;
2022-05-27 09:59:14 +00:00
UI ( ) - > SetActiveItem ( nullptr ) ;
2011-07-12 21:31:39 +00:00
}
}
2008-01-13 16:30:30 +00:00
}
2010-10-07 21:51:07 +00:00
void CEditor : : FilelistPopulate ( int StorageType )
2010-09-12 11:15:59 +00:00
{
2022-06-11 19:38:18 +00:00
m_vFileList . clear ( ) ;
2010-10-07 21:51:07 +00:00
if ( m_FileDialogStorageType ! = IStorage : : TYPE_SAVE & & ! str_comp ( m_pFileDialogPath , " maps " ) )
{
CFilelistItem Item ;
str_copy ( Item . m_aFilename , " downloadedmaps " , sizeof ( Item . m_aFilename ) ) ;
str_copy ( Item . m_aName , " downloadedmaps/ " , sizeof ( Item . m_aName ) ) ;
Item . m_IsDir = true ;
Item . m_IsLink = true ;
Item . m_StorageType = IStorage : : TYPE_SAVE ;
2022-06-11 19:38:18 +00:00
m_vFileList . push_back ( Item ) ;
2010-10-07 21:51:07 +00:00
}
Storage ( ) - > ListDirectory ( StorageType , m_pFileDialogPath , EditorListdirCallback , this ) ;
2022-06-11 19:38:18 +00:00
std : : sort ( m_vFileList . begin ( ) , m_vFileList . end ( ) ) ;
m_FilesSelectedIndex = m_vFileList . empty ( ) ? - 1 : 0 ;
2012-08-12 10:41:50 +00:00
m_PreviewImageIsLoaded = false ;
2020-09-01 07:47:17 +00:00
m_FileDialogActivate = false ;
2014-10-24 21:03:16 +00:00
2022-06-11 19:38:18 +00:00
if ( m_FilesSelectedIndex > = 0 & & ! m_vFileList [ m_FilesSelectedIndex ] . m_IsDir )
str_copy ( m_aFileDialogFileName , m_vFileList [ m_FilesSelectedIndex ] . m_aFilename , sizeof ( m_aFileDialogFileName ) ) ;
2014-10-24 21:03:16 +00:00
else
m_aFileDialogFileName [ 0 ] = 0 ;
2010-09-12 11:15:59 +00:00
}
2010-10-07 21:51:07 +00:00
void CEditor : : InvokeFileDialog ( int StorageType , int FileType , const char * pTitle , const char * pButtonText ,
2010-05-29 07:25:38 +00:00
const char * pBasePath , const char * pDefaultName ,
2010-10-07 21:51:07 +00:00
void ( * pfnFunc ) ( const char * pFileName , int StorageType , void * pUser ) , void * pUser )
2008-01-13 16:30:30 +00:00
{
2010-10-06 21:07:35 +00:00
m_FileDialogStorageType = StorageType ;
2010-09-12 11:15:59 +00:00
m_pFileDialogTitle = pTitle ;
m_pFileDialogButtonText = pButtonText ;
m_pfnFileDialogFunc = pfnFunc ;
m_pFileDialogUser = pUser ;
m_aFileDialogFileName [ 0 ] = 0 ;
2016-08-20 23:47:39 +00:00
m_aFileDialogSearchText [ 0 ] = 0 ;
2010-10-07 21:51:07 +00:00
m_aFileDialogCurrentFolder [ 0 ] = 0 ;
m_aFileDialogCurrentLink [ 0 ] = 0 ;
m_pFileDialogPath = m_aFileDialogCurrentFolder ;
m_FileDialogFileType = FileType ;
m_FileDialogScrollValue = 0.0f ;
2012-08-12 10:41:50 +00:00
m_PreviewImageIsLoaded = false ;
2020-09-01 07:48:51 +00:00
m_FileDialogOpening = true ;
2010-05-29 07:25:38 +00:00
if ( pDefaultName )
2010-09-12 11:15:59 +00:00
str_copy ( m_aFileDialogFileName , pDefaultName , sizeof ( m_aFileDialogFileName ) ) ;
2010-05-29 07:25:38 +00:00
if ( pBasePath )
2010-10-07 21:51:07 +00:00
str_copy ( m_aFileDialogCurrentFolder , pBasePath , sizeof ( m_aFileDialogCurrentFolder ) ) ;
2011-08-11 08:59:14 +00:00
2010-10-07 21:51:07 +00:00
FilelistPopulate ( m_FileDialogStorageType ) ;
2010-05-29 07:25:38 +00:00
2020-09-01 07:48:51 +00:00
m_FileDialogOpening = true ;
2010-05-29 07:25:38 +00:00
m_Dialog = DIALOG_FILE ;
2007-12-02 17:55:45 +00:00
}
2010-05-29 07:25:38 +00:00
void CEditor : : RenderModebar ( CUIRect View )
2007-12-02 17:55:45 +00:00
{
2010-05-29 07:25:38 +00:00
CUIRect Button ;
2007-12-02 17:55:45 +00:00
2008-01-12 12:27:55 +00:00
// mode buttons
2007-12-02 17:55:45 +00:00
{
2010-05-29 07:25:38 +00:00
View . VSplitLeft ( 65.0f , & Button , & View ) ;
2022-06-13 16:28:13 +00:00
Button . HSplitTop ( 30.0f , nullptr , & Button ) ;
2010-05-29 07:25:38 +00:00
static int s_Button = 0 ;
2014-10-08 12:50:25 +00:00
const char * pButName = " " ;
if ( m_Mode = = MODE_LAYERS )
pButName = " Layers " ;
else if ( m_Mode = = MODE_IMAGES )
pButName = " Images " ;
else if ( m_Mode = = MODE_SOUNDS )
pButName = " Sounds " ;
2018-02-04 15:00:47 +00:00
int MouseButton = DoButton_Tab ( & s_Button , pButName , 0 , & Button , 0 , " Switch between images, sounds and layers management. " ) ;
2020-08-11 10:21:28 +00:00
if ( MouseButton = = 2 | | ( Input ( ) - > KeyPress ( KEY_LEFT ) & & m_Dialog = = DIALOG_NONE & & m_EditBoxActive = = 0 ) )
2015-04-27 11:43:02 +00:00
{
2018-03-13 20:59:07 +00:00
if ( m_Mode = = MODE_LAYERS )
2015-04-27 11:43:02 +00:00
m_Mode = MODE_SOUNDS ;
else if ( m_Mode = = MODE_IMAGES )
m_Mode = MODE_LAYERS ;
else
m_Mode = MODE_IMAGES ;
}
2020-08-11 10:21:28 +00:00
else if ( MouseButton = = 1 | | ( Input ( ) - > KeyPress ( KEY_RIGHT ) & & m_Dialog = = DIALOG_NONE & & m_EditBoxActive = = 0 ) )
2010-05-29 07:25:38 +00:00
{
2018-03-13 20:59:07 +00:00
if ( m_Mode = = MODE_LAYERS )
2011-08-11 08:59:14 +00:00
m_Mode = MODE_IMAGES ;
2014-10-08 12:50:25 +00:00
else if ( m_Mode = = MODE_IMAGES )
m_Mode = MODE_SOUNDS ;
2011-08-11 08:59:14 +00:00
else
m_Mode = MODE_LAYERS ;
2010-05-29 07:25:38 +00:00
}
2007-12-02 17:55:45 +00:00
}
2008-01-12 12:27:55 +00:00
2022-06-13 16:28:13 +00:00
View . VSplitLeft ( 5.0f , nullptr , & View ) ;
2008-01-12 12:27:55 +00:00
}
2010-05-29 07:25:38 +00:00
void CEditor : : RenderStatusbar ( CUIRect View )
2008-01-12 12:27:55 +00:00
{
2010-05-29 07:25:38 +00:00
CUIRect Button ;
View . VSplitRight ( 60.0f , & View , & Button ) ;
static int s_EnvelopeButton = 0 ;
2015-04-21 02:25:49 +00:00
int MouseButton = DoButton_Editor ( & s_EnvelopeButton , " Envelopes " , m_ShowEnvelopeEditor , & Button , 0 , " Toggles the envelope editor. " ) ;
if ( MouseButton = = 2 )
2020-09-26 19:41:58 +00:00
m_ShowEnvelopeEditor = ( m_ShowEnvelopeEditor + 3 ) % 4 ;
2015-04-21 02:25:49 +00:00
else if ( MouseButton = = 1 )
2020-09-26 19:41:58 +00:00
m_ShowEnvelopeEditor = ( m_ShowEnvelopeEditor + 1 ) % 4 ;
2011-07-13 20:38:32 +00:00
if ( MouseButton )
{
m_ShowServerSettingsEditor = false ;
}
View . VSplitRight ( 100.0f , & View , & Button ) ;
2022-06-13 16:28:13 +00:00
Button . VSplitRight ( 10.0f , & Button , nullptr ) ;
2011-07-13 20:38:32 +00:00
static int s_SettingsButton = 0 ;
if ( DoButton_Editor ( & s_SettingsButton , " Server settings " , m_ShowServerSettingsEditor , & Button , 0 , " Toggles the server settings editor. " ) )
{
m_ShowEnvelopeEditor = 0 ;
m_ShowServerSettingsEditor ^ = 1 ;
}
2010-05-29 07:25:38 +00:00
if ( m_pTooltip )
2008-01-17 23:09:49 +00:00
{
2019-04-08 17:39:55 +00:00
char aBuf [ 512 ] ;
2010-05-29 07:25:38 +00:00
if ( ms_pUiGotContext & & ms_pUiGotContext = = UI ( ) - > HotItem ( ) )
2011-03-20 16:04:03 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %s Right click for context menu. " , m_pTooltip ) ;
2008-01-17 23:09:49 +00:00
else
2019-04-08 17:39:55 +00:00
str_copy ( aBuf , m_pTooltip , sizeof ( aBuf ) ) ;
2020-11-07 23:02:34 +00:00
float FontSize = ScaleFontSize ( aBuf , sizeof ( aBuf ) , 10.0f , View . w ) ;
2022-03-11 16:34:48 +00:00
SLabelProperties Props ;
Props . m_MaxWidth = View . w ;
UI ( ) - > DoLabel ( & View , aBuf , FontSize , TEXTALIGN_LEFT , Props ) ;
2008-01-17 23:09:49 +00:00
}
2008-01-12 12:27:55 +00:00
}
2021-02-08 21:26:26 +00:00
bool CEditor : : IsEnvelopeUsed ( int EnvelopeIndex ) const
2018-10-14 13:53:14 +00:00
{
2022-06-11 19:38:18 +00:00
for ( const auto & pGroup : m_Map . m_vpGroups )
2018-10-14 13:53:14 +00:00
{
2022-06-11 19:38:18 +00:00
for ( const auto & pLayer : pGroup - > m_vpLayers )
2018-10-14 13:53:14 +00:00
{
2022-05-24 09:24:33 +00:00
if ( pLayer - > m_Type = = LAYERTYPE_QUADS )
2018-10-14 13:53:14 +00:00
{
2022-05-24 09:24:33 +00:00
CLayerQuads * pLayerQuads = ( CLayerQuads * ) pLayer ;
2022-06-11 19:38:18 +00:00
for ( const auto & Quad : pLayerQuads - > m_vQuads )
2018-10-14 13:53:14 +00:00
{
2022-05-24 09:24:33 +00:00
if ( Quad . m_PosEnv = = EnvelopeIndex | | Quad . m_ColorEnv = = EnvelopeIndex )
2018-10-14 13:53:14 +00:00
{
return true ;
}
}
}
2022-05-24 09:24:33 +00:00
else if ( pLayer - > m_Type = = LAYERTYPE_SOUNDS )
2018-10-14 13:53:14 +00:00
{
2022-05-24 09:24:33 +00:00
CLayerSounds * pLayerSounds = ( CLayerSounds * ) pLayer ;
2022-06-11 19:38:18 +00:00
for ( const auto & Source : pLayerSounds - > m_vSources )
2018-10-14 13:53:14 +00:00
{
2022-05-24 09:24:33 +00:00
if ( Source . m_PosEnv = = EnvelopeIndex | | Source . m_SoundEnv = = EnvelopeIndex )
2018-10-14 13:53:14 +00:00
{
return true ;
}
}
}
2022-05-24 09:24:33 +00:00
else if ( pLayer - > m_Type = = LAYERTYPE_TILES )
2018-10-14 13:53:14 +00:00
{
2022-05-24 09:24:33 +00:00
CLayerTiles * pLayerTiles = ( CLayerTiles * ) pLayer ;
if ( pLayerTiles - > m_ColorEnv = = EnvelopeIndex )
2018-10-14 13:53:14 +00:00
return true ;
}
}
}
return false ;
}
2010-05-29 07:25:38 +00:00
void CEditor : : RenderEnvelopeEditor ( CUIRect View )
2008-01-12 12:27:55 +00:00
{
2020-09-26 19:41:58 +00:00
if ( m_SelectedEnvelope < 0 )
m_SelectedEnvelope = 0 ;
2022-06-11 19:38:18 +00:00
if ( m_SelectedEnvelope > = ( int ) m_Map . m_vpEnvelopes . size ( ) )
m_SelectedEnvelope = m_Map . m_vpEnvelopes . size ( ) - 1 ;
2008-01-12 12:27:55 +00:00
2022-06-13 16:28:13 +00:00
CEnvelope * pEnvelope = nullptr ;
2022-06-11 19:38:18 +00:00
if ( m_SelectedEnvelope > = 0 & & m_SelectedEnvelope < ( int ) m_Map . m_vpEnvelopes . size ( ) )
pEnvelope = m_Map . m_vpEnvelopes [ m_SelectedEnvelope ] ;
2008-01-12 12:27:55 +00:00
2010-05-29 07:25:38 +00:00
CUIRect ToolBar , CurveBar , ColorBar ;
View . HSplitTop ( 15.0f , & ToolBar , & View ) ;
View . HSplitTop ( 15.0f , & CurveBar , & View ) ;
ToolBar . Margin ( 2.0f , & ToolBar ) ;
CurveBar . Margin ( 2.0f , & CurveBar ) ;
2008-01-12 12:27:55 +00:00
2015-03-30 11:06:05 +00:00
bool CurrentEnvelopeSwitched = false ;
2008-01-12 12:27:55 +00:00
// do the toolbar
2007-12-02 17:55:45 +00:00
{
2010-05-29 07:25:38 +00:00
CUIRect Button ;
2022-06-13 16:28:13 +00:00
CEnvelope * pNewEnv = nullptr ;
2010-05-29 07:25:38 +00:00
2014-10-11 14:05:36 +00:00
ToolBar . VSplitRight ( 50.0f , & ToolBar , & Button ) ;
static int s_NewSoundButton = 0 ;
2014-10-24 20:13:46 +00:00
if ( DoButton_Editor ( & s_NewSoundButton , " Sound+ " , 0 , & Button , 0 , " Creates a new sound envelope " ) )
2014-10-11 14:05:36 +00:00
{
m_Map . m_Modified = true ;
2014-10-11 18:05:48 +00:00
pNewEnv = m_Map . NewEnvelope ( 1 ) ;
2014-10-11 14:05:36 +00:00
}
ToolBar . VSplitRight ( 5.0f , & ToolBar , & Button ) ;
2010-05-29 07:25:38 +00:00
ToolBar . VSplitRight ( 50.0f , & ToolBar , & Button ) ;
static int s_New4dButton = 0 ;
2011-03-20 16:04:03 +00:00
if ( DoButton_Editor ( & s_New4dButton , " Color+ " , 0 , & Button , 0 , " Creates a new color envelope " ) )
2011-03-21 23:31:42 +00:00
{
m_Map . m_Modified = true ;
2010-05-29 07:25:38 +00:00
pNewEnv = m_Map . NewEnvelope ( 4 ) ;
2011-03-21 23:31:42 +00:00
}
2010-05-29 07:25:38 +00:00
ToolBar . VSplitRight ( 5.0f , & ToolBar , & Button ) ;
ToolBar . VSplitRight ( 50.0f , & ToolBar , & Button ) ;
static int s_New2dButton = 0 ;
2014-10-24 20:15:55 +00:00
if ( DoButton_Editor ( & s_New2dButton , " Pos.+ " , 0 , & Button , 0 , " Creates a new position envelope " ) )
2011-03-21 23:31:42 +00:00
{
m_Map . m_Modified = true ;
2010-05-29 07:25:38 +00:00
pNewEnv = m_Map . NewEnvelope ( 3 ) ;
2011-03-21 23:31:42 +00:00
}
2011-01-06 03:46:10 +00:00
2010-08-06 18:18:53 +00:00
// Delete button
if ( m_SelectedEnvelope > = 0 )
{
ToolBar . VSplitRight ( 10.0f , & ToolBar , & Button ) ;
ToolBar . VSplitRight ( 50.0f , & ToolBar , & Button ) ;
static int s_DelButton = 0 ;
2011-03-20 16:04:03 +00:00
if ( DoButton_Editor ( & s_DelButton , " Delete " , 0 , & Button , 0 , " Delete this envelope " ) )
2010-08-06 18:18:53 +00:00
{
2011-03-21 23:31:42 +00:00
m_Map . m_Modified = true ;
2010-08-06 18:18:53 +00:00
m_Map . DeleteEnvelope ( m_SelectedEnvelope ) ;
2022-06-11 19:38:18 +00:00
if ( m_SelectedEnvelope > = ( int ) m_Map . m_vpEnvelopes . size ( ) )
m_SelectedEnvelope = m_Map . m_vpEnvelopes . size ( ) - 1 ;
2022-06-13 16:28:13 +00:00
pEnvelope = m_SelectedEnvelope > = 0 ? m_Map . m_vpEnvelopes [ m_SelectedEnvelope ] : nullptr ;
2010-08-06 18:18:53 +00:00
}
}
2010-05-29 07:25:38 +00:00
if ( pNewEnv ) // add the default points
2007-12-02 17:55:45 +00:00
{
2010-05-29 07:25:38 +00:00
if ( pNewEnv - > m_Channels = = 4 )
2008-01-12 12:27:55 +00:00
{
2015-09-18 21:47:07 +00:00
pNewEnv - > AddPoint ( 0 , f2fx ( 1.0f ) , f2fx ( 1.0f ) , f2fx ( 1.0f ) , f2fx ( 1.0f ) ) ;
pNewEnv - > AddPoint ( 1000 , f2fx ( 1.0f ) , f2fx ( 1.0f ) , f2fx ( 1.0f ) , f2fx ( 1.0f ) ) ;
2008-01-12 12:27:55 +00:00
}
else
{
2010-05-29 07:25:38 +00:00
pNewEnv - > AddPoint ( 0 , 0 ) ;
pNewEnv - > AddPoint ( 1000 , 0 ) ;
2008-01-12 12:27:55 +00:00
}
}
2010-05-29 07:25:38 +00:00
CUIRect Shifter , Inc , Dec ;
ToolBar . VSplitLeft ( 60.0f , & Shifter , & ToolBar ) ;
Shifter . VSplitRight ( 15.0f , & Shifter , & Inc ) ;
Shifter . VSplitLeft ( 15.0f , & Dec , & Shifter ) ;
char aBuf [ 512 ] ;
2022-06-11 19:38:18 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %d/%d " , m_SelectedEnvelope + 1 , ( int ) m_Map . m_vpEnvelopes . size ( ) ) ;
2018-10-09 10:41:52 +00:00
2019-04-26 21:47:34 +00:00
ColorRGBA EnvColor = ColorRGBA ( 1 , 1 , 1 , 0.5f ) ;
2022-06-11 19:38:18 +00:00
if ( ! m_Map . m_vpEnvelopes . empty ( ) )
2018-10-09 10:41:52 +00:00
{
2018-10-14 13:53:14 +00:00
EnvColor = IsEnvelopeUsed ( m_SelectedEnvelope ) ?
2020-09-26 19:41:58 +00:00
ColorRGBA ( 1 , 0.7f , 0.7f , 0.5f ) :
ColorRGBA ( 0.7f , 1 , 0.7f , 0.5f ) ;
2018-10-09 10:41:52 +00:00
}
RenderTools ( ) - > DrawUIRect ( & Shifter , EnvColor , 0 , 0.0f ) ;
2022-03-11 16:34:48 +00:00
UI ( ) - > DoLabel ( & Shifter , aBuf , 10.0f , TEXTALIGN_CENTER ) ;
2010-05-29 07:25:38 +00:00
static int s_PrevButton = 0 ;
2022-06-13 16:28:13 +00:00
if ( DoButton_ButtonDec ( & s_PrevButton , nullptr , 0 , & Dec , 0 , " Previous Envelope " ) )
2015-03-30 11:06:05 +00:00
{
2010-05-29 07:25:38 +00:00
m_SelectedEnvelope - - ;
2015-03-30 11:06:05 +00:00
if ( m_SelectedEnvelope < 0 )
2022-06-11 19:38:18 +00:00
m_SelectedEnvelope = m_Map . m_vpEnvelopes . size ( ) - 1 ;
2015-06-28 14:17:23 +00:00
CurrentEnvelopeSwitched = true ;
2015-03-30 11:06:05 +00:00
}
2010-05-29 07:25:38 +00:00
static int s_NextButton = 0 ;
2022-06-13 16:28:13 +00:00
if ( DoButton_ButtonInc ( & s_NextButton , nullptr , 0 , & Inc , 0 , " Next Envelope " ) )
2015-03-30 11:06:05 +00:00
{
2010-05-29 07:25:38 +00:00
m_SelectedEnvelope + + ;
2022-06-11 19:38:18 +00:00
if ( m_SelectedEnvelope > = ( int ) m_Map . m_vpEnvelopes . size ( ) )
2015-06-28 14:17:23 +00:00
m_SelectedEnvelope = 0 ;
CurrentEnvelopeSwitched = true ;
2015-03-30 11:06:05 +00:00
}
2010-05-29 07:25:38 +00:00
if ( pEnvelope )
2008-01-12 12:27:55 +00:00
{
2010-05-29 07:25:38 +00:00
ToolBar . VSplitLeft ( 15.0f , & Button , & ToolBar ) ;
ToolBar . VSplitLeft ( 35.0f , & Button , & ToolBar ) ;
2022-03-11 16:34:48 +00:00
UI ( ) - > DoLabel ( & Button , " Name: " , 10.0f , TEXTALIGN_LEFT ) ;
2010-05-29 07:25:38 +00:00
ToolBar . VSplitLeft ( 80.0f , & Button , & ToolBar ) ;
2011-07-12 01:14:46 +00:00
static float s_NameBox = 0 ;
if ( DoEditBox ( & s_NameBox , & Button , pEnvelope - > m_aName , sizeof ( pEnvelope - > m_aName ) , 10.0f , & s_NameBox ) )
2014-01-19 03:02:01 +00:00
{
2011-03-21 23:31:42 +00:00
m_Map . m_Modified = true ;
2014-01-19 03:02:01 +00:00
}
2007-12-02 17:55:45 +00:00
}
}
2010-05-29 07:25:38 +00:00
2010-08-06 18:18:53 +00:00
bool ShowColorBar = false ;
if ( pEnvelope & & pEnvelope - > m_Channels = = 4 )
{
ShowColorBar = true ;
View . HSplitTop ( 20.0f , & ColorBar , & View ) ;
ColorBar . Margin ( 2.0f , & ColorBar ) ;
2012-08-12 10:41:50 +00:00
RenderBackground ( ColorBar , m_CheckerTexture , 16.0f , 1.0f ) ;
2010-08-06 18:18:53 +00:00
}
2012-08-12 10:41:50 +00:00
RenderBackground ( View , m_CheckerTexture , 32.0f , 0.1f ) ;
2010-08-06 18:18:53 +00:00
2010-05-29 07:25:38 +00:00
if ( pEnvelope )
2007-12-02 17:55:45 +00:00
{
2022-06-15 17:34:41 +00:00
static std : : vector < int > s_vSelection ;
static int s_EnvelopeEditorID = 0 ;
2010-05-29 07:25:38 +00:00
static int s_ActiveChannels = 0xf ;
2020-09-26 19:41:58 +00:00
ColorRGBA aColors [ ] = { ColorRGBA ( 1 , 0.2f , 0.2f ) , ColorRGBA ( 0.2f , 1 , 0.2f ) , ColorRGBA ( 0.2f , 0.2f , 1 ) , ColorRGBA ( 1 , 1 , 0.2f ) } ;
2015-07-24 22:04:12 +00:00
2010-05-29 07:25:38 +00:00
if ( pEnvelope )
2008-01-12 12:27:55 +00:00
{
2010-05-29 07:25:38 +00:00
CUIRect Button ;
2008-01-12 12:27:55 +00:00
2010-05-29 07:25:38 +00:00
ToolBar . VSplitLeft ( 15.0f , & Button , & ToolBar ) ;
2022-06-30 22:36:32 +00:00
static const char * s_aapNames [ 4 ] [ 4 ] = {
2014-10-11 18:05:48 +00:00
{ " V " , " " , " " , " " } ,
{ " " , " " , " " , " " } ,
2008-01-12 12:27:55 +00:00
{ " X " , " Y " , " R " , " " } ,
{ " R " , " G " , " B " , " A " } ,
} ;
2010-05-29 07:25:38 +00:00
2022-06-30 22:36:32 +00:00
static const char * s_aapDescriptions [ 4 ] [ 4 ] = {
2014-10-11 18:05:48 +00:00
{ " Volume of the envelope " , " " , " " , " " } ,
{ " " , " " , " " , " " } ,
2011-03-20 16:04:03 +00:00
{ " X-axis of the envelope " , " Y-axis of the envelope " , " Rotation of the envelope " , " " } ,
{ " Red value of the envelope " , " Green value of the envelope " , " Blue value of the envelope " , " Alpha value of the envelope " } ,
2010-08-15 23:29:11 +00:00
} ;
2010-05-29 07:25:38 +00:00
static int s_aChannelButtons [ 4 ] = { 0 } ;
int Bit = 1 ;
2020-09-26 19:41:58 +00:00
for ( int i = 0 ; i < pEnvelope - > m_Channels ; i + + , Bit < < = 1 )
2008-01-12 12:27:55 +00:00
{
2010-05-29 07:25:38 +00:00
ToolBar . VSplitLeft ( 15.0f , & Button , & ToolBar ) ;
2022-06-30 22:36:32 +00:00
if ( DoButton_Env ( & s_aChannelButtons [ i ] , s_aapNames [ pEnvelope - > m_Channels - 1 ] [ i ] , s_ActiveChannels & Bit , & Button , s_aapDescriptions [ pEnvelope - > m_Channels - 1 ] [ i ] , aColors [ i ] ) )
2010-05-29 07:25:38 +00:00
s_ActiveChannels ^ = Bit ;
2008-01-12 12:27:55 +00:00
}
2011-12-04 13:34:27 +00:00
// sync checkbox
ToolBar . VSplitLeft ( 15.0f , & Button , & ToolBar ) ;
ToolBar . VSplitLeft ( 12.0f , & Button , & ToolBar ) ;
static int s_SyncButton ;
2020-09-26 19:41:58 +00:00
if ( DoButton_Editor ( & s_SyncButton , pEnvelope - > m_Synchronized ? " X " : " " , 0 , & Button , 0 , " Synchronize envelope animation to game time (restarts when you touch the start line) " ) )
2011-12-04 13:34:27 +00:00
pEnvelope - > m_Synchronized = ! pEnvelope - > m_Synchronized ;
ToolBar . VSplitLeft ( 4.0f , & Button , & ToolBar ) ;
ToolBar . VSplitLeft ( 80.0f , & Button , & ToolBar ) ;
2022-03-11 16:34:48 +00:00
UI ( ) - > DoLabel ( & Button , " Synchronized " , 10.0f , TEXTALIGN_LEFT ) ;
2010-05-29 07:25:38 +00:00
}
float EndTime = pEnvelope - > EndTime ( ) ;
if ( EndTime < 1 )
EndTime = 1 ;
pEnvelope - > FindTopBottom ( s_ActiveChannels ) ;
float Top = pEnvelope - > m_Top ;
float Bottom = pEnvelope - > m_Bottom ;
if ( Top < 1 )
Top = 1 ;
if ( Bottom > = 0 )
Bottom = 0 ;
2020-09-26 19:41:58 +00:00
float TimeScale = EndTime / View . w ;
float ValueScale = ( Top - Bottom ) / View . h ;
2010-05-29 07:25:38 +00:00
if ( UI ( ) - > MouseInside ( & View ) )
2022-06-15 17:34:41 +00:00
UI ( ) - > SetHotItem ( & s_EnvelopeEditorID ) ;
2010-05-29 07:25:38 +00:00
2022-06-15 17:34:41 +00:00
if ( UI ( ) - > HotItem ( ) = = & s_EnvelopeEditorID )
2008-01-12 12:27:55 +00:00
{
// do stuff
2010-05-29 07:25:38 +00:00
if ( pEnvelope )
2008-01-12 12:27:55 +00:00
{
2009-10-27 14:38:53 +00:00
if ( UI ( ) - > MouseButtonClicked ( 1 ) )
2008-01-12 12:27:55 +00:00
{
// add point
2020-09-26 19:41:58 +00:00
int Time = ( int ) ( ( ( UI ( ) - > MouseX ( ) - View . x ) * TimeScale ) * 1000.0f ) ;
2010-05-29 07:25:38 +00:00
//float env_y = (UI()->MouseY()-view.y)/TimeScale;
2022-07-01 04:42:36 +00:00
ColorRGBA Channels ;
pEnvelope - > Eval ( Time / 1000.0f , Channels ) ;
2010-05-29 07:25:38 +00:00
pEnvelope - > AddPoint ( Time ,
2022-07-01 04:42:36 +00:00
f2fx ( Channels . r ) , f2fx ( Channels . g ) ,
f2fx ( Channels . b ) , f2fx ( Channels . a ) ) ;
2011-03-21 23:31:42 +00:00
m_Map . m_Modified = true ;
2008-01-12 12:27:55 +00:00
}
2010-05-29 07:25:38 +00:00
2011-08-15 18:12:31 +00:00
m_ShowEnvelopePreview = 1 ;
2011-03-20 16:04:03 +00:00
m_pTooltip = " Press right mouse button to create a new point " ;
2008-01-12 12:27:55 +00:00
}
}
// render lines
{
2010-05-29 07:25:38 +00:00
UI ( ) - > ClipEnable ( & View ) ;
2012-08-12 10:41:50 +00:00
Graphics ( ) - > TextureClear ( ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > LinesBegin ( ) ;
2010-05-29 07:25:38 +00:00
for ( int c = 0 ; c < pEnvelope - > m_Channels ; c + + )
2008-01-12 12:27:55 +00:00
{
2020-09-26 19:41:58 +00:00
if ( s_ActiveChannels & ( 1 < < c ) )
Graphics ( ) - > SetColor ( aColors [ c ] . r , aColors [ c ] . g , aColors [ c ] . b , 1 ) ;
2008-01-12 12:27:55 +00:00
else
2020-09-26 19:41:58 +00:00
Graphics ( ) - > SetColor ( aColors [ c ] . r * 0.5f , aColors [ c ] . g * 0.5f , aColors [ c ] . b * 0.5f , 1 ) ;
2010-05-29 07:25:38 +00:00
float PrevX = 0 ;
2022-07-01 04:42:36 +00:00
ColorRGBA Channels ;
pEnvelope - > Eval ( 0.000001f , Channels ) ;
float PrevValue = Channels [ c ] ;
2010-05-29 07:25:38 +00:00
2020-09-26 19:41:58 +00:00
int Steps = ( int ) ( ( View . w / UI ( ) - > Screen ( ) - > w ) * Graphics ( ) - > ScreenWidth ( ) ) ;
2010-05-29 07:25:38 +00:00
for ( int i = 1 ; i < = Steps ; i + + )
2008-01-12 12:27:55 +00:00
{
2020-09-26 19:41:58 +00:00
float a = i / ( float ) Steps ;
2022-07-01 04:42:36 +00:00
pEnvelope - > Eval ( a * EndTime , Channels ) ;
float v = Channels [ c ] ;
2020-09-26 19:41:58 +00:00
v = ( v - Bottom ) / ( Top - Bottom ) ;
2010-05-29 07:25:38 +00:00
2020-09-26 19:41:58 +00:00
IGraphics : : CLineItem LineItem ( View . x + PrevX * View . w , View . y + View . h - PrevValue * View . h , View . x + a * View . w , View . y + View . h - v * View . h ) ;
2010-05-29 07:25:38 +00:00
Graphics ( ) - > LinesDraw ( & LineItem , 1 ) ;
PrevX = a ;
PrevValue = v ;
2008-01-12 12:27:55 +00:00
}
}
2009-10-27 14:38:53 +00:00
Graphics ( ) - > LinesEnd ( ) ;
UI ( ) - > ClipDisable ( ) ;
2008-01-12 12:27:55 +00:00
}
2010-05-29 07:25:38 +00:00
2008-01-12 12:27:55 +00:00
// render curve options
2007-12-02 17:55:45 +00:00
{
2022-06-11 19:38:18 +00:00
for ( int i = 0 ; i < ( int ) pEnvelope - > m_vPoints . size ( ) - 1 ; i + + )
2008-01-12 12:27:55 +00:00
{
2022-06-11 19:38:18 +00:00
float t0 = pEnvelope - > m_vPoints [ i ] . m_Time / 1000.0f / EndTime ;
float t1 = pEnvelope - > m_vPoints [ i + 1 ] . m_Time / 1000.0f / EndTime ;
2008-01-12 12:27:55 +00:00
//dbg_msg("", "%f", end_time);
2010-05-29 07:25:38 +00:00
2009-10-27 14:38:53 +00:00
CUIRect v ;
2020-09-26 19:41:58 +00:00
v . x = CurveBar . x + ( t0 + ( t1 - t0 ) * 0.5f ) * CurveBar . w ;
2010-05-29 07:25:38 +00:00
v . y = CurveBar . y ;
v . h = CurveBar . h ;
v . w = CurveBar . h ;
2020-09-26 19:41:58 +00:00
v . x - = v . w / 2 ;
2022-06-11 19:38:18 +00:00
void * pID = & pEnvelope - > m_vPoints [ i ] . m_Curvetype ;
2022-06-30 22:36:32 +00:00
const char * apTypeName [ ] = {
2020-09-26 19:41:58 +00:00
" N " , " L " , " S " , " F " , " M " } ;
2020-05-19 09:29:35 +00:00
const char * pTypeName = " Invalid " ;
2022-06-30 22:36:32 +00:00
if ( 0 < = pEnvelope - > m_vPoints [ i ] . m_Curvetype & & pEnvelope - > m_vPoints [ i ] . m_Curvetype < ( int ) std : : size ( apTypeName ) )
pTypeName = apTypeName [ pEnvelope - > m_vPoints [ i ] . m_Curvetype ] ;
2020-05-19 09:29:35 +00:00
if ( DoButton_Editor ( pID , pTypeName , 0 , & v , 0 , " Switch curve type " ) )
2022-06-11 19:38:18 +00:00
pEnvelope - > m_vPoints [ i ] . m_Curvetype = ( pEnvelope - > m_vPoints [ i ] . m_Curvetype + 1 ) % NUM_CURVETYPES ;
2008-01-12 12:27:55 +00:00
}
}
2010-05-29 07:25:38 +00:00
2008-01-12 12:27:55 +00:00
// render colorbar
2010-05-29 07:25:38 +00:00
if ( ShowColorBar )
2008-01-12 12:27:55 +00:00
{
2012-08-12 10:41:50 +00:00
Graphics ( ) - > TextureClear ( ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsBegin ( ) ;
2022-06-11 19:38:18 +00:00
for ( int i = 0 ; i < ( int ) pEnvelope - > m_vPoints . size ( ) - 1 ; i + + )
2008-01-12 12:27:55 +00:00
{
2022-06-11 19:38:18 +00:00
float r0 = fx2f ( pEnvelope - > m_vPoints [ i ] . m_aValues [ 0 ] ) ;
float g0 = fx2f ( pEnvelope - > m_vPoints [ i ] . m_aValues [ 1 ] ) ;
float b0 = fx2f ( pEnvelope - > m_vPoints [ i ] . m_aValues [ 2 ] ) ;
float a0 = fx2f ( pEnvelope - > m_vPoints [ i ] . m_aValues [ 3 ] ) ;
float r1 = fx2f ( pEnvelope - > m_vPoints [ i + 1 ] . m_aValues [ 0 ] ) ;
float g1 = fx2f ( pEnvelope - > m_vPoints [ i + 1 ] . m_aValues [ 1 ] ) ;
float b1 = fx2f ( pEnvelope - > m_vPoints [ i + 1 ] . m_aValues [ 2 ] ) ;
float a1 = fx2f ( pEnvelope - > m_vPoints [ i + 1 ] . m_aValues [ 3 ] ) ;
2010-05-29 07:25:38 +00:00
IGraphics : : CColorVertex Array [ 4 ] = { IGraphics : : CColorVertex ( 0 , r0 , g0 , b0 , a0 ) ,
2020-09-26 19:41:58 +00:00
IGraphics : : CColorVertex ( 1 , r1 , g1 , b1 , a1 ) ,
IGraphics : : CColorVertex ( 2 , r1 , g1 , b1 , a1 ) ,
IGraphics : : CColorVertex ( 3 , r0 , g0 , b0 , a0 ) } ;
2010-05-29 07:25:38 +00:00
Graphics ( ) - > SetColorVertex ( Array , 4 ) ;
2022-06-11 19:38:18 +00:00
float x0 = pEnvelope - > m_vPoints [ i ] . m_Time / 1000.0f / EndTime ;
2020-09-26 19:41:58 +00:00
// float y0 = (fx2f(envelope->points[i].values[c])-bottom)/(top-bottom);
2022-06-11 19:38:18 +00:00
float x1 = pEnvelope - > m_vPoints [ i + 1 ] . m_Time / 1000.0f / EndTime ;
2008-01-12 12:27:55 +00:00
//float y1 = (fx2f(envelope->points[i+1].values[c])-bottom)/(top-bottom);
2009-10-27 14:38:53 +00:00
CUIRect v ;
2020-09-26 19:41:58 +00:00
v . x = ColorBar . x + x0 * ColorBar . w ;
2010-05-29 07:25:38 +00:00
v . y = ColorBar . y ;
2020-09-26 19:41:58 +00:00
v . w = ( x1 - x0 ) * ColorBar . w ;
2010-05-29 07:25:38 +00:00
v . h = ColorBar . h ;
IGraphics : : CQuadItem QuadItem ( v . x , v . y , v . w , v . h ) ;
Graphics ( ) - > QuadsDrawTL ( & QuadItem , 1 ) ;
2008-01-12 12:27:55 +00:00
}
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsEnd ( ) ;
2008-01-12 12:27:55 +00:00
}
2010-05-29 07:25:38 +00:00
2008-01-12 12:27:55 +00:00
// render handles
2015-03-30 03:06:08 +00:00
2015-03-30 09:44:32 +00:00
// keep track of last Env
2022-06-13 16:28:13 +00:00
static void * s_pID = nullptr ;
2015-03-30 03:06:08 +00:00
2015-03-30 09:44:32 +00:00
// chars for textinput
static char s_aStrCurTime [ 32 ] = " 0.000 " ;
static char s_aStrCurValue [ 32 ] = " 0.000 " ;
2015-03-30 03:06:08 +00:00
2015-03-30 11:06:05 +00:00
if ( CurrentEnvelopeSwitched )
{
2022-06-13 16:28:13 +00:00
s_pID = nullptr ;
2015-03-30 11:06:05 +00:00
// update displayed text
str_format ( s_aStrCurTime , sizeof ( s_aStrCurTime ) , " 0.000 " ) ;
str_format ( s_aStrCurValue , sizeof ( s_aStrCurValue ) , " 0.000 " ) ;
}
2008-01-12 12:27:55 +00:00
{
2010-05-29 07:25:38 +00:00
int CurrentValue = 0 , CurrentTime = 0 ;
2012-08-12 10:41:50 +00:00
Graphics ( ) - > TextureClear ( ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsBegin ( ) ;
2010-05-29 07:25:38 +00:00
for ( int c = 0 ; c < pEnvelope - > m_Channels ; c + + )
2008-01-12 12:27:55 +00:00
{
2020-09-26 19:41:58 +00:00
if ( ! ( s_ActiveChannels & ( 1 < < c ) ) )
2008-01-12 12:27:55 +00:00
continue ;
2010-05-29 07:25:38 +00:00
2022-06-11 19:38:18 +00:00
for ( size_t i = 0 ; i < pEnvelope - > m_vPoints . size ( ) ; i + + )
2008-01-12 12:27:55 +00:00
{
2022-06-11 19:38:18 +00:00
float x0 = pEnvelope - > m_vPoints [ i ] . m_Time / 1000.0f / EndTime ;
float y0 = ( fx2f ( pEnvelope - > m_vPoints [ i ] . m_aValues [ c ] ) - Bottom ) / ( Top - Bottom ) ;
2010-05-29 07:25:38 +00:00
CUIRect Final ;
2020-09-26 19:41:58 +00:00
Final . x = View . x + x0 * View . w ;
Final . y = View . y + View . h - y0 * View . h ;
2010-05-29 07:25:38 +00:00
Final . x - = 2.0f ;
Final . y - = 2.0f ;
Final . w = 4.0f ;
Final . h = 4.0f ;
2022-06-11 19:38:18 +00:00
void * pID = & pEnvelope - > m_vPoints [ i ] . m_aValues [ c ] ;
2008-01-12 12:27:55 +00:00
2010-05-29 07:25:38 +00:00
if ( UI ( ) - > MouseInside ( & Final ) )
2011-02-12 10:40:36 +00:00
UI ( ) - > SetHotItem ( pID ) ;
2010-05-29 07:25:38 +00:00
float ColorMod = 1.0f ;
2022-05-27 08:55:32 +00:00
if ( UI ( ) - > CheckActiveItem ( pID ) )
2008-01-12 12:27:55 +00:00
{
2009-10-27 14:38:53 +00:00
if ( ! UI ( ) - > MouseButton ( 0 ) )
2008-01-12 12:27:55 +00:00
{
2011-08-15 18:12:31 +00:00
m_SelectedQuadEnvelope = - 1 ;
m_SelectedEnvelopePoint = - 1 ;
2011-08-14 14:31:48 +00:00
2022-05-27 09:59:14 +00:00
UI ( ) - > SetActiveItem ( nullptr ) ;
2008-01-12 12:27:55 +00:00
}
else
2011-08-11 08:59:14 +00:00
{
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) | | Input ( ) - > KeyIsPressed ( KEY_RSHIFT ) )
2008-01-12 12:27:55 +00:00
{
if ( i ! = 0 )
{
2021-12-18 11:23:20 +00:00
if ( Input ( ) - > ModifierIsPressed ( ) )
2022-06-11 19:38:18 +00:00
pEnvelope - > m_vPoints [ i ] . m_Time + = ( int ) ( ( m_MouseDeltaX ) ) ;
2010-07-18 11:44:30 +00:00
else
2022-06-11 19:38:18 +00:00
pEnvelope - > m_vPoints [ i ] . m_Time + = ( int ) ( ( m_MouseDeltaX * TimeScale ) * 1000.0f ) ;
if ( pEnvelope - > m_vPoints [ i ] . m_Time < pEnvelope - > m_vPoints [ i - 1 ] . m_Time )
pEnvelope - > m_vPoints [ i ] . m_Time = pEnvelope - > m_vPoints [ i - 1 ] . m_Time + 1 ;
if ( i + 1 ! = pEnvelope - > m_vPoints . size ( ) & & pEnvelope - > m_vPoints [ i ] . m_Time > pEnvelope - > m_vPoints [ i + 1 ] . m_Time )
pEnvelope - > m_vPoints [ i ] . m_Time = pEnvelope - > m_vPoints [ i + 1 ] . m_Time - 1 ;
2008-01-12 12:27:55 +00:00
}
}
2011-04-13 15:47:02 +00:00
else
{
2021-12-18 11:23:20 +00:00
if ( Input ( ) - > ModifierIsPressed ( ) )
2022-06-11 19:38:18 +00:00
pEnvelope - > m_vPoints [ i ] . m_aValues [ c ] - = f2fx ( m_MouseDeltaY * 0.001f ) ;
2011-04-13 15:47:02 +00:00
else
2022-06-11 19:38:18 +00:00
pEnvelope - > m_vPoints [ i ] . m_aValues [ c ] - = f2fx ( m_MouseDeltaY * ValueScale ) ;
2011-04-13 15:47:02 +00:00
}
2011-08-15 18:12:31 +00:00
m_SelectedQuadEnvelope = m_SelectedEnvelope ;
m_ShowEnvelopePreview = 1 ;
m_SelectedEnvelopePoint = i ;
2015-03-30 09:44:32 +00:00
m_Map . m_Modified = true ;
2008-01-12 12:27:55 +00:00
}
2010-05-29 07:25:38 +00:00
ColorMod = 100.0f ;
2020-09-26 19:41:58 +00:00
Graphics ( ) - > SetColor ( 1 , 1 , 1 , 1 ) ;
2008-01-12 12:27:55 +00:00
}
2011-02-12 10:40:36 +00:00
else if ( UI ( ) - > HotItem ( ) = = pID )
2008-01-12 12:27:55 +00:00
{
2009-10-27 14:38:53 +00:00
if ( UI ( ) - > MouseButton ( 0 ) )
2008-01-12 12:27:55 +00:00
{
2022-06-15 17:34:41 +00:00
s_vSelection . clear ( ) ;
s_vSelection . push_back ( i ) ;
2011-02-12 10:40:36 +00:00
UI ( ) - > SetActiveItem ( pID ) ;
2015-03-30 09:44:32 +00:00
// track it
s_pID = pID ;
2008-01-12 12:27:55 +00:00
}
// remove point
2015-03-30 09:44:32 +00:00
if ( UI ( ) - > MouseButtonClicked ( 1 ) )
2011-03-21 23:31:42 +00:00
{
2015-03-30 11:06:05 +00:00
if ( s_pID = = pID )
{
2022-06-13 16:28:13 +00:00
s_pID = nullptr ;
2015-03-30 11:06:05 +00:00
// update displayed text
str_format ( s_aStrCurTime , sizeof ( s_aStrCurTime ) , " 0.000 " ) ;
str_format ( s_aStrCurValue , sizeof ( s_aStrCurValue ) , " 0.000 " ) ;
}
2022-06-11 19:38:18 +00:00
pEnvelope - > m_vPoints . erase ( pEnvelope - > m_vPoints . begin ( ) + i ) ;
2011-03-21 23:31:42 +00:00
m_Map . m_Modified = true ;
}
2010-05-29 07:25:38 +00:00
2011-08-15 18:12:31 +00:00
m_ShowEnvelopePreview = 1 ;
2010-05-29 07:25:38 +00:00
ColorMod = 100.0f ;
2020-09-26 19:41:58 +00:00
Graphics ( ) - > SetColor ( 1 , 0.75f , 0.75f , 1 ) ;
2018-02-04 15:00:47 +00:00
m_pTooltip = " Left mouse to drag. Hold ctrl to be more precise. Hold shift to alter time point as well. Right click to delete. " ;
2008-01-12 12:27:55 +00:00
}
2016-04-30 18:11:26 +00:00
if ( pID = = s_pID & & ( Input ( ) - > KeyIsPressed ( KEY_RETURN ) | | Input ( ) - > KeyIsPressed ( KEY_KP_ENTER ) ) )
2015-03-30 09:44:32 +00:00
{
if ( i ! = 0 )
{
2022-06-11 19:38:18 +00:00
pEnvelope - > m_vPoints [ i ] . m_Time = str_tofloat ( s_aStrCurTime ) * 1000.0f ;
2015-03-30 03:06:08 +00:00
2022-06-11 19:38:18 +00:00
if ( pEnvelope - > m_vPoints [ i ] . m_Time < pEnvelope - > m_vPoints [ i - 1 ] . m_Time )
pEnvelope - > m_vPoints [ i ] . m_Time = pEnvelope - > m_vPoints [ i - 1 ] . m_Time + 1 ;
if ( i + 1 ! = pEnvelope - > m_vPoints . size ( ) & & pEnvelope - > m_vPoints [ i ] . m_Time > pEnvelope - > m_vPoints [ i + 1 ] . m_Time )
pEnvelope - > m_vPoints [ i ] . m_Time = pEnvelope - > m_vPoints [ i + 1 ] . m_Time - 1 ;
2015-03-30 09:44:32 +00:00
}
else
2022-06-11 19:38:18 +00:00
pEnvelope - > m_vPoints [ i ] . m_Time = 0.0f ;
2015-03-30 03:06:08 +00:00
2022-06-11 19:38:18 +00:00
str_format ( s_aStrCurTime , sizeof ( s_aStrCurTime ) , " %.3f " , pEnvelope - > m_vPoints [ i ] . m_Time / 1000.0f ) ;
2015-03-30 03:27:33 +00:00
2022-06-11 19:38:18 +00:00
pEnvelope - > m_vPoints [ i ] . m_aValues [ c ] = f2fx ( str_tofloat ( s_aStrCurValue ) ) ;
2015-03-30 09:44:32 +00:00
}
2015-03-30 03:06:08 +00:00
2022-05-30 20:44:12 +00:00
if ( UI ( ) - > CheckActiveItem ( pID ) )
2015-03-30 09:44:32 +00:00
{
2022-06-11 19:38:18 +00:00
CurrentTime = pEnvelope - > m_vPoints [ i ] . m_Time ;
CurrentValue = pEnvelope - > m_vPoints [ i ] . m_aValues [ c ] ;
2015-03-30 03:06:08 +00:00
2015-03-30 09:44:32 +00:00
// update displayed text
2020-09-26 19:41:58 +00:00
str_format ( s_aStrCurTime , sizeof ( s_aStrCurTime ) , " %.3f " , CurrentTime / 1000.0f ) ;
2015-03-30 09:44:32 +00:00
str_format ( s_aStrCurValue , sizeof ( s_aStrCurValue ) , " %.3f " , fx2f ( CurrentValue ) ) ;
2008-01-12 12:27:55 +00:00
}
2010-05-29 07:25:38 +00:00
2022-05-24 09:24:33 +00:00
if ( m_SelectedQuadEnvelope = = m_SelectedEnvelope & & m_SelectedEnvelopePoint = = ( int ) i )
2011-08-15 18:12:31 +00:00
Graphics ( ) - > SetColor ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
else
2020-09-26 19:41:58 +00:00
Graphics ( ) - > SetColor ( aColors [ c ] . r * ColorMod , aColors [ c ] . g * ColorMod , aColors [ c ] . b * ColorMod , 1.0f ) ;
2010-05-29 07:25:38 +00:00
IGraphics : : CQuadItem QuadItem ( Final . x , Final . y , Final . w , Final . h ) ;
Graphics ( ) - > QuadsDrawTL ( & QuadItem , 1 ) ;
2008-01-12 12:27:55 +00:00
}
}
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsEnd ( ) ;
2008-01-12 12:27:55 +00:00
2015-03-30 09:44:32 +00:00
CUIRect ToolBar1 ;
CUIRect ToolBar2 ;
2015-03-30 03:06:08 +00:00
2015-03-30 09:44:32 +00:00
ToolBar . VSplitMid ( & ToolBar1 , & ToolBar2 ) ;
2018-03-13 20:59:07 +00:00
if ( ToolBar . w > ToolBar . h * 21 )
2015-04-07 14:43:51 +00:00
{
ToolBar1 . VMargin ( 3.0f , & ToolBar1 ) ;
ToolBar2 . VMargin ( 3.0f , & ToolBar2 ) ;
2015-03-30 03:27:33 +00:00
2015-04-07 14:43:51 +00:00
CUIRect Label1 ;
CUIRect Label2 ;
2015-03-30 03:27:33 +00:00
2015-04-07 14:43:51 +00:00
ToolBar1 . VSplitMid ( & Label1 , & ToolBar1 ) ;
ToolBar2 . VSplitMid ( & Label2 , & ToolBar2 ) ;
2015-03-30 03:27:33 +00:00
2022-03-11 16:34:48 +00:00
UI ( ) - > DoLabel ( & Label1 , " Value: " , 10.0f , TEXTALIGN_LEFT ) ;
UI ( ) - > DoLabel ( & Label2 , " Time (in s): " , 10.0f , TEXTALIGN_LEFT ) ;
2015-04-07 14:43:51 +00:00
}
2015-03-30 03:06:08 +00:00
2021-12-03 19:15:44 +00:00
static float s_ValNumber = 0 ;
2015-03-30 09:44:32 +00:00
DoEditBox ( & s_ValNumber , & ToolBar1 , s_aStrCurValue , sizeof ( s_aStrCurValue ) , 10.0f , & s_ValNumber ) ;
2021-12-03 19:15:44 +00:00
static float s_TimeNumber = 0 ;
2015-03-30 09:44:32 +00:00
DoEditBox ( & s_TimeNumber , & ToolBar2 , s_aStrCurTime , sizeof ( s_aStrCurTime ) , 10.0f , & s_TimeNumber ) ;
2007-12-02 17:55:45 +00:00
}
}
2008-01-12 12:27:55 +00:00
}
2020-10-06 10:58:37 +00:00
void CEditor : : RenderServerSettingsEditor ( CUIRect View , bool ShowServerSettingsEditorLast )
2011-07-13 20:38:32 +00:00
{
static int s_CommandSelectedIndex = - 1 ;
CUIRect ToolBar ;
View . HSplitTop ( 20.0f , & ToolBar , & View ) ;
ToolBar . Margin ( 2.0f , & ToolBar ) ;
// do the toolbar
{
CUIRect Button ;
// command line
2022-06-13 16:28:13 +00:00
ToolBar . VSplitLeft ( 5.0f , nullptr , & Button ) ;
2022-01-21 15:20:15 +00:00
UI ( ) - > DoLabel ( & Button , " Command: " , 12.0f , TEXTALIGN_LEFT ) ;
2011-07-13 20:38:32 +00:00
2022-06-13 16:28:13 +00:00
Button . VSplitLeft ( 70.0f , nullptr , & Button ) ;
Button . VSplitLeft ( 180.0f , & Button , nullptr ) ;
2020-10-05 15:14:43 +00:00
static int s_ClearButton = 0 ;
DoClearableEditBox ( & m_CommandBox , & s_ClearButton , & Button , m_aSettingsCommand , sizeof ( m_aSettingsCommand ) , 12.0f , & m_CommandBox , false , CUI : : CORNER_ALL ) ;
2011-07-13 20:38:32 +00:00
2020-10-06 10:58:37 +00:00
if ( ! ShowServerSettingsEditorLast ) // Just activated
UI ( ) - > SetActiveItem ( & m_CommandBox ) ;
2011-07-13 20:38:32 +00:00
// buttons
ToolBar . VSplitRight ( 50.0f , & ToolBar , & Button ) ;
static int s_AddButton = 0 ;
2022-01-01 13:27:37 +00:00
if ( DoButton_Editor ( & s_AddButton , " Add " , 0 , & Button , 0 , " Add a command to command list. " ) | | ( ( Input ( ) - > KeyPress ( KEY_RETURN ) | | Input ( ) - > KeyPress ( KEY_KP_ENTER ) ) & & UI ( ) - > LastActiveItem ( ) = = & m_CommandBox & & m_Dialog = = DIALOG_NONE ) )
2011-07-13 20:38:32 +00:00
{
if ( m_aSettingsCommand [ 0 ] ! = 0 & & str_find ( m_aSettingsCommand , " " ) )
{
bool Found = false ;
2022-06-11 19:38:18 +00:00
for ( const auto & Setting : m_Map . m_vSettings )
2022-05-24 09:24:33 +00:00
if ( ! str_comp ( Setting . m_aCommand , m_aSettingsCommand ) )
2011-07-13 20:38:32 +00:00
{
Found = true ;
break ;
}
if ( ! Found )
{
CEditorMap : : CSetting Setting ;
str_copy ( Setting . m_aCommand , m_aSettingsCommand , sizeof ( Setting . m_aCommand ) ) ;
2022-06-11 19:38:18 +00:00
m_Map . m_vSettings . push_back ( Setting ) ;
s_CommandSelectedIndex = m_Map . m_vSettings . size ( ) - 1 ;
2011-07-13 20:38:32 +00:00
}
}
2020-10-06 10:58:37 +00:00
UI ( ) - > SetActiveItem ( & m_CommandBox ) ;
2011-07-13 20:38:32 +00:00
}
2022-06-11 19:38:18 +00:00
if ( ! m_Map . m_vSettings . empty ( ) & & s_CommandSelectedIndex > = 0 & & ( size_t ) s_CommandSelectedIndex < m_Map . m_vSettings . size ( ) )
2011-07-13 20:38:32 +00:00
{
2020-10-05 15:14:43 +00:00
ToolBar . VSplitRight ( 50.0f , & ToolBar , & Button ) ;
2022-06-13 16:28:13 +00:00
Button . VSplitRight ( 5.0f , & Button , nullptr ) ;
2020-10-05 15:14:43 +00:00
static int s_ModButton = 0 ;
2022-01-01 13:27:37 +00:00
if ( DoButton_Editor ( & s_ModButton , " Mod " , 0 , & Button , 0 , " Modify a command from the command list. " ) | | ( Input ( ) - > KeyPress ( KEY_M ) & & UI ( ) - > LastActiveItem ( ) ! = & m_CommandBox & & m_Dialog = = DIALOG_NONE ) )
2020-10-05 15:14:43 +00:00
{
2022-06-11 19:38:18 +00:00
if ( str_comp ( m_Map . m_vSettings [ s_CommandSelectedIndex ] . m_aCommand , m_aSettingsCommand ) ! = 0 & & m_aSettingsCommand [ 0 ] ! = 0 & & str_find ( m_aSettingsCommand , " " ) )
2020-10-05 15:14:43 +00:00
{
bool Found = false ;
int i ;
2022-06-11 19:38:18 +00:00
for ( i = 0 ; i < ( int ) m_Map . m_vSettings . size ( ) ; i + + )
if ( i ! = s_CommandSelectedIndex & & ! str_comp ( m_Map . m_vSettings [ i ] . m_aCommand , m_aSettingsCommand ) )
2020-10-05 15:14:43 +00:00
{
Found = true ;
break ;
}
if ( Found )
{
2022-06-11 19:38:18 +00:00
m_Map . m_vSettings . erase ( m_Map . m_vSettings . begin ( ) + s_CommandSelectedIndex ) ;
2020-10-05 15:14:43 +00:00
s_CommandSelectedIndex = i > s_CommandSelectedIndex ? i - 1 : i ;
}
else
{
2022-06-11 19:38:18 +00:00
str_copy ( m_Map . m_vSettings [ s_CommandSelectedIndex ] . m_aCommand , m_aSettingsCommand , sizeof ( m_Map . m_vSettings [ s_CommandSelectedIndex ] . m_aCommand ) ) ;
2020-10-05 15:14:43 +00:00
}
}
2020-10-06 10:58:37 +00:00
UI ( ) - > SetActiveItem ( & m_CommandBox ) ;
2020-10-05 15:14:43 +00:00
}
2011-07-13 20:38:32 +00:00
ToolBar . VSplitRight ( 50.0f , & ToolBar , & Button ) ;
2022-06-13 16:28:13 +00:00
Button . VSplitRight ( 5.0f , & Button , nullptr ) ;
2020-01-16 14:01:45 +00:00
static int s_DelButton = 0 ;
2022-01-01 13:27:37 +00:00
if ( DoButton_Editor ( & s_DelButton , " Del " , 0 , & Button , 0 , " Delete a command from the command list. " ) | | ( Input ( ) - > KeyPress ( KEY_DELETE ) & & UI ( ) - > LastActiveItem ( ) ! = & m_CommandBox & & m_Dialog = = DIALOG_NONE ) )
2020-10-05 15:14:43 +00:00
{
2022-06-11 19:38:18 +00:00
m_Map . m_vSettings . erase ( m_Map . m_vSettings . begin ( ) + s_CommandSelectedIndex ) ;
if ( s_CommandSelectedIndex > = ( int ) m_Map . m_vSettings . size ( ) )
s_CommandSelectedIndex = m_Map . m_vSettings . size ( ) - 1 ;
2020-10-06 10:58:37 +00:00
if ( s_CommandSelectedIndex > = 0 )
2022-06-11 19:38:18 +00:00
str_copy ( m_aSettingsCommand , m_Map . m_vSettings [ s_CommandSelectedIndex ] . m_aCommand , sizeof ( m_aSettingsCommand ) ) ;
2020-10-06 10:58:37 +00:00
UI ( ) - > SetActiveItem ( & m_CommandBox ) ;
2020-10-05 15:14:43 +00:00
}
2020-12-14 11:06:11 +00:00
ToolBar . VSplitRight ( 25.0f , & ToolBar , & Button ) ;
2022-06-13 16:28:13 +00:00
Button . VSplitRight ( 5.0f , & Button , nullptr ) ;
2020-12-14 11:06:11 +00:00
static int s_DownButton = 0 ;
2022-06-11 19:38:18 +00:00
if ( s_CommandSelectedIndex < ( int ) m_Map . m_vSettings . size ( ) - 1 & & DoButton_Editor ( & s_DownButton , " ▼ " , 0 , & Button , 0 , " Move command down " ) )
2020-12-14 11:06:11 +00:00
{
2022-06-11 19:38:18 +00:00
std : : swap ( m_Map . m_vSettings [ s_CommandSelectedIndex ] , m_Map . m_vSettings [ s_CommandSelectedIndex + 1 ] ) ;
2020-12-14 11:06:11 +00:00
s_CommandSelectedIndex + + ;
}
ToolBar . VSplitRight ( 25.0f , & ToolBar , & Button ) ;
2022-06-13 16:28:13 +00:00
Button . VSplitRight ( 5.0f , & Button , nullptr ) ;
2020-12-14 11:06:11 +00:00
static int s_UpButton = 0 ;
if ( s_CommandSelectedIndex > 0 & & DoButton_Editor ( & s_UpButton , " ▲ " , 0 , & Button , 0 , " Move command up " ) )
{
2022-06-11 19:38:18 +00:00
std : : swap ( m_Map . m_vSettings [ s_CommandSelectedIndex ] , m_Map . m_vSettings [ s_CommandSelectedIndex - 1 ] ) ;
2020-12-14 11:06:11 +00:00
s_CommandSelectedIndex - - ;
}
2011-07-13 20:38:32 +00:00
}
}
2022-06-13 16:28:13 +00:00
View . HSplitTop ( 2.0f , nullptr , & View ) ;
2012-08-12 10:41:50 +00:00
RenderBackground ( View , m_CheckerTexture , 32.0f , 0.1f ) ;
2011-07-13 20:38:32 +00:00
CUIRect ListBox ;
View . Margin ( 1.0f , & ListBox ) ;
2022-06-11 19:38:18 +00:00
float ListHeight = 17.0f * m_Map . m_vSettings . size ( ) ;
2011-07-13 20:38:32 +00:00
static float s_ScrollValue = 0 ;
float ScrollDifference = ListHeight - ListBox . h ;
2020-09-26 19:41:58 +00:00
if ( ListHeight > ListBox . h ) // Do we even need a scrollbar?
2011-07-13 20:38:32 +00:00
{
CUIRect Scroll ;
2021-11-26 20:55:31 +00:00
ListBox . VSplitRight ( 20.0f , & ListBox , & Scroll ) ;
s_ScrollValue = UIEx ( ) - > DoScrollbarV ( & s_ScrollValue , & Scroll , s_ScrollValue ) ;
2011-07-13 20:38:32 +00:00
if ( UI ( ) - > MouseInside ( & Scroll ) | | UI ( ) - > MouseInside ( & ListBox ) )
{
2020-09-26 19:41:58 +00:00
int ScrollNum = ( int ) ( ( ListHeight - ListBox . h ) / 17.0f ) + 1 ;
2011-07-13 20:38:32 +00:00
if ( ScrollNum > 0 )
{
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyPress ( KEY_MOUSE_WHEEL_UP ) )
2020-09-26 19:41:58 +00:00
s_ScrollValue = clamp ( s_ScrollValue - 1.0f / ScrollNum , 0.0f , 1.0f ) ;
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyPress ( KEY_MOUSE_WHEEL_DOWN ) )
2020-09-26 19:41:58 +00:00
s_ScrollValue = clamp ( s_ScrollValue + 1.0f / ScrollNum , 0.0f , 1.0f ) ;
2011-07-13 20:38:32 +00:00
}
}
2011-07-13 20:38:32 +00:00
}
float ListStartAt = ScrollDifference * s_ScrollValue ;
if ( ListStartAt < 0.0f )
ListStartAt = 0.0f ;
float ListStopAt = ListHeight - ScrollDifference * ( 1 - s_ScrollValue ) ;
float ListCur = 0 ;
UI ( ) - > ClipEnable ( & ListBox ) ;
2022-06-11 19:38:18 +00:00
for ( size_t i = 0 ; i < m_Map . m_vSettings . size ( ) ; i + + )
2011-07-13 20:38:32 +00:00
{
if ( ListCur > ListStopAt )
break ;
if ( ListCur > = ListStartAt )
{
CUIRect Button ;
ListBox . HSplitTop ( 15.0f , & Button , & ListBox ) ;
2022-06-13 16:28:13 +00:00
ListBox . HSplitTop ( 2.0f , nullptr , & ListBox ) ;
Button . VSplitLeft ( 5.0f , nullptr , & Button ) ;
2011-07-13 20:38:32 +00:00
2022-06-13 16:28:13 +00:00
if ( DoButton_MenuItem ( & m_Map . m_vSettings [ i ] , m_Map . m_vSettings [ i ] . m_aCommand , s_CommandSelectedIndex > = 0 & & ( size_t ) s_CommandSelectedIndex = = i , & Button , 0 , nullptr ) )
2020-10-05 15:14:43 +00:00
{
2011-07-13 20:38:32 +00:00
s_CommandSelectedIndex = i ;
2022-06-11 19:38:18 +00:00
str_copy ( m_aSettingsCommand , m_Map . m_vSettings [ i ] . m_aCommand , sizeof ( m_aSettingsCommand ) ) ;
2020-10-06 10:58:37 +00:00
UI ( ) - > SetActiveItem ( & m_CommandBox ) ;
2020-10-05 15:14:43 +00:00
}
2011-07-13 20:38:32 +00:00
}
ListCur + = 17.0f ;
}
UI ( ) - > ClipDisable ( ) ;
}
2020-02-28 15:25:27 +00:00
int CEditor : : PopupMenuFile ( CEditor * pEditor , CUIRect View , void * pContext )
2008-01-13 13:42:59 +00:00
{
2010-05-29 07:25:38 +00:00
static int s_NewMapButton = 0 ;
static int s_SaveButton = 0 ;
static int s_SaveAsButton = 0 ;
2015-07-26 10:05:14 +00:00
static int s_SaveCopyButton = 0 ;
2010-05-29 07:25:38 +00:00
static int s_OpenButton = 0 ;
2016-08-23 01:08:36 +00:00
static int s_OpenCurrentMapButton = 0 ;
2010-05-29 07:25:38 +00:00
static int s_AppendButton = 0 ;
static int s_ExitButton = 0 ;
CUIRect Slot ;
View . HSplitTop ( 2.0f , & Slot , & View ) ;
View . HSplitTop ( 12.0f , & Slot , & View ) ;
2020-08-10 07:27:31 +00:00
if ( pEditor - > DoButton_MenuItem ( & s_NewMapButton , " New " , 0 , & Slot , 0 , " Creates a new map (ctrl+n) " ) )
2010-05-29 07:25:38 +00:00
{
2011-03-21 23:31:42 +00:00
if ( pEditor - > HasUnsavedData ( ) )
{
pEditor - > m_PopupEventType = POPEVENT_NEW ;
pEditor - > m_PopupEventActivated = true ;
}
else
{
pEditor - > Reset ( ) ;
pEditor - > m_aFileName [ 0 ] = 0 ;
}
2008-01-13 22:03:32 +00:00
return 1 ;
}
2008-01-13 13:42:59 +00:00
2010-05-29 07:25:38 +00:00
View . HSplitTop ( 10.0f , & Slot , & View ) ;
View . HSplitTop ( 12.0f , & Slot , & View ) ;
2020-08-10 07:27:31 +00:00
if ( pEditor - > DoButton_MenuItem ( & s_OpenButton , " Load " , 0 , & Slot , 0 , " Opens a map for editing (ctrl+l) " ) )
2008-01-13 22:03:32 +00:00
{
2011-03-21 23:31:42 +00:00
if ( pEditor - > HasUnsavedData ( ) )
{
pEditor - > m_PopupEventType = POPEVENT_LOAD ;
pEditor - > m_PopupEventActivated = true ;
}
else
pEditor - > InvokeFileDialog ( IStorage : : TYPE_ALL , FILETYPE_MAP , " Load map " , " Load " , " maps " , " " , pEditor - > CallbackOpenMap , pEditor ) ;
2008-01-13 22:03:32 +00:00
return 1 ;
}
2008-01-13 13:42:59 +00:00
2016-08-23 01:08:36 +00:00
View . HSplitTop ( 2.0f , & Slot , & View ) ;
View . HSplitTop ( 12.0f , & Slot , & View ) ;
2020-05-15 15:05:45 +00:00
if ( pEditor - > DoButton_MenuItem ( & s_OpenCurrentMapButton , " Load Current Map " , 0 , & Slot , 0 , " Opens the current in game map for editing (ctrl+alt+l) " ) )
2016-08-21 19:14:41 +00:00
{
if ( pEditor - > HasUnsavedData ( ) )
{
2016-08-23 01:08:36 +00:00
pEditor - > m_PopupEventType = POPEVENT_LOADCURRENT ;
2016-08-21 19:14:41 +00:00
pEditor - > m_PopupEventActivated = true ;
}
else
2016-08-23 01:08:36 +00:00
{
pEditor - > LoadCurrentMap ( ) ;
}
2016-08-21 19:14:41 +00:00
return 1 ;
}
2008-01-13 13:42:59 +00:00
2010-05-29 07:25:38 +00:00
View . HSplitTop ( 10.0f , & Slot , & View ) ;
View . HSplitTop ( 12.0f , & Slot , & View ) ;
2020-08-10 07:27:31 +00:00
if ( pEditor - > DoButton_MenuItem ( & s_AppendButton , " Append " , 0 , & Slot , 0 , " Opens a map and adds everything from that map to the current one (ctrl+a) " ) )
2008-03-09 23:29:14 +00:00
{
2011-03-21 23:31:42 +00:00
pEditor - > InvokeFileDialog ( IStorage : : TYPE_ALL , FILETYPE_MAP , " Append map " , " Append " , " maps " , " " , pEditor - > CallbackAppendMap , pEditor ) ;
2008-03-09 23:29:14 +00:00
return 1 ;
}
2010-05-29 07:25:38 +00:00
View . HSplitTop ( 10.0f , & Slot , & View ) ;
View . HSplitTop ( 12.0f , & Slot , & View ) ;
2015-07-26 10:05:14 +00:00
if ( pEditor - > DoButton_MenuItem ( & s_SaveButton , " Save " , 0 , & Slot , 0 , " Saves the current map (ctrl+s) " ) )
2008-01-13 22:03:32 +00:00
{
2011-03-21 23:31:42 +00:00
if ( pEditor - > m_aFileName [ 0 ] & & pEditor - > m_ValidSaveFilename )
{
str_copy ( pEditor - > m_aFileSaveName , pEditor - > m_aFileName , sizeof ( pEditor - > m_aFileSaveName ) ) ;
pEditor - > m_PopupEventType = POPEVENT_SAVE ;
pEditor - > m_PopupEventActivated = true ;
}
2010-05-29 07:25:38 +00:00
else
2011-03-21 23:31:42 +00:00
pEditor - > InvokeFileDialog ( IStorage : : TYPE_SAVE , FILETYPE_MAP , " Save map " , " Save " , " maps " , " " , pEditor - > CallbackSaveMap , pEditor ) ;
2008-01-13 22:03:32 +00:00
return 1 ;
}
2008-01-13 13:42:59 +00:00
2010-05-29 07:25:38 +00:00
View . HSplitTop ( 2.0f , & Slot , & View ) ;
View . HSplitTop ( 12.0f , & Slot , & View ) ;
2015-07-26 10:05:14 +00:00
if ( pEditor - > DoButton_MenuItem ( & s_SaveAsButton , " Save As " , 0 , & Slot , 0 , " Saves the current map under a new name (ctrl+shift+s) " ) )
2008-01-13 22:03:32 +00:00
{
2011-03-21 23:31:42 +00:00
pEditor - > InvokeFileDialog ( IStorage : : TYPE_SAVE , FILETYPE_MAP , " Save map " , " Save " , " maps " , " " , pEditor - > CallbackSaveMap , pEditor ) ;
2008-01-13 22:03:32 +00:00
return 1 ;
}
2010-05-29 07:25:38 +00:00
2015-07-26 10:05:14 +00:00
View . HSplitTop ( 2.0f , & Slot , & View ) ;
View . HSplitTop ( 12.0f , & Slot , & View ) ;
if ( pEditor - > DoButton_MenuItem ( & s_SaveCopyButton , " Save Copy " , 0 , & Slot , 0 , " Saves a copy of the current map under a new name (ctrl+shift+alt+s) " ) )
{
pEditor - > InvokeFileDialog ( IStorage : : TYPE_SAVE , FILETYPE_MAP , " Save map " , " Save " , " maps " , " " , pEditor - > CallbackSaveCopyMap , pEditor ) ;
return 1 ;
}
2010-05-29 07:25:38 +00:00
View . HSplitTop ( 10.0f , & Slot , & View ) ;
View . HSplitTop ( 12.0f , & Slot , & View ) ;
2011-03-20 16:04:03 +00:00
if ( pEditor - > DoButton_MenuItem ( & s_ExitButton , " Exit " , 0 , & Slot , 0 , " Exits from the editor " ) )
2009-05-31 09:44:20 +00:00
{
2011-03-21 23:31:42 +00:00
if ( pEditor - > HasUnsavedData ( ) )
{
pEditor - > m_PopupEventType = POPEVENT_EXIT ;
pEditor - > m_PopupEventActivated = true ;
}
else
g_Config . m_ClEditor = 0 ;
2009-05-31 09:44:20 +00:00
return 1 ;
2010-05-29 07:25:38 +00:00
}
2008-01-13 22:03:32 +00:00
return 0 ;
2008-01-13 13:42:59 +00:00
}
2008-01-13 22:03:32 +00:00
2010-05-29 07:25:38 +00:00
void CEditor : : RenderMenubar ( CUIRect MenuBar )
2008-01-13 22:03:32 +00:00
{
2022-05-31 17:40:17 +00:00
CUIRect FileButton ;
static int s_FileButton = 0 ;
MenuBar . VSplitLeft ( 60.0f , & FileButton , & MenuBar ) ;
2022-06-13 16:28:13 +00:00
if ( DoButton_Menu ( & s_FileButton , " File " , 0 , & FileButton , 0 , nullptr ) )
2022-05-31 17:40:17 +00:00
UiInvokePopupMenu ( & s_FileButton , 1 , FileButton . x , FileButton . y + FileButton . h - 1.0f , 120 , 160 , PopupMenuFile , this ) ;
2008-01-13 22:03:32 +00:00
2014-09-12 21:07:47 +00:00
CUIRect Info , Close ;
2022-06-13 16:28:13 +00:00
MenuBar . VSplitLeft ( 40.0f , nullptr , & MenuBar ) ;
2014-09-12 21:07:47 +00:00
MenuBar . VSplitRight ( 20.0f , & MenuBar , & Close ) ;
2022-06-13 16:28:13 +00:00
Close . VSplitLeft ( 5.0f , nullptr , & Close ) ;
2020-09-26 19:41:58 +00:00
MenuBar . VSplitLeft ( MenuBar . w * 0.75f , & MenuBar , & Info ) ;
2010-10-07 22:04:46 +00:00
char aBuf [ 128 ] ;
2011-03-20 16:04:03 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " File: %s " , m_aFileName ) ;
2022-03-11 16:34:48 +00:00
UI ( ) - > DoLabel ( & MenuBar , aBuf , 10.0f , TEXTALIGN_LEFT ) ;
2012-01-08 12:16:19 +00:00
2017-09-03 06:53:54 +00:00
char aTimeStr [ 6 ] ;
2017-09-03 06:48:21 +00:00
str_timestamp_format ( aTimeStr , sizeof ( aTimeStr ) , " %H:%M " ) ;
2015-07-01 14:38:17 +00:00
2020-09-26 19:41:58 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " X: %i, Y: %i, Z: %i, A: %.1f, G: %i %s " , ( int ) UI ( ) - > MouseWorldX ( ) / 32 , ( int ) UI ( ) - > MouseWorldY ( ) / 32 , m_ZoomLevel , m_AnimateSpeed , m_GridFactor , aTimeStr ) ;
2022-03-11 16:34:48 +00:00
UI ( ) - > DoLabel ( & Info , aBuf , 10.0f , TEXTALIGN_RIGHT ) ;
2014-09-12 21:07:47 +00:00
static int s_CloseButton = 0 ;
2020-10-06 10:25:10 +00:00
if ( DoButton_Editor ( & s_CloseButton , " × " , 0 , & Close , 0 , " Exits from the editor " , 0 ) | | ( m_Dialog = = DIALOG_NONE & & ! UiPopupOpen ( ) & & ! m_PopupEventActivated & & Input ( ) - > KeyPress ( KEY_ESCAPE ) ) )
2020-09-03 12:08:26 +00:00
g_Config . m_ClEditor = 0 ;
2008-01-13 22:03:32 +00:00
}
2008-01-13 13:42:59 +00:00
2010-05-29 07:25:38 +00:00
void CEditor : : Render ( )
2008-01-12 12:27:55 +00:00
{
// basic start
2022-03-20 17:04:00 +00:00
Graphics ( ) - > Clear ( 0.0f , 0.0f , 0.0f ) ;
2010-05-29 07:25:38 +00:00
CUIRect View = * UI ( ) - > Screen ( ) ;
2021-09-22 19:48:55 +00:00
UI ( ) - > MapScreen ( ) ;
2010-05-29 07:25:38 +00:00
2011-03-21 23:31:42 +00:00
float Width = View . w ;
float Height = View . h ;
2008-01-12 12:27:55 +00:00
// reset tip
2022-06-13 16:28:13 +00:00
m_pTooltip = nullptr ;
2010-05-29 07:25:38 +00:00
2012-01-08 12:36:47 +00:00
if ( m_EditBoxActive )
- - m_EditBoxActive ;
2008-01-12 12:27:55 +00:00
// render checker
2012-08-12 10:41:50 +00:00
RenderBackground ( View , m_CheckerTexture , 32.0f , 1.0f ) ;
2010-05-29 07:25:38 +00:00
2022-02-07 14:56:54 +00:00
CUIRect MenuBar , CModeBar , ToolBar , StatusBar , ExtraEditor , ToolBox ;
2022-06-11 19:38:18 +00:00
m_ShowPicker = Input ( ) - > KeyIsPressed ( KEY_SPACE ) ! = 0 & & m_Dialog = = DIALOG_NONE & & m_EditBoxActive = = 0 & & UI ( ) - > LastActiveItem ( ) ! = & m_CommandBox & & m_vSelectedLayers . size ( ) = = 1 ;
2010-05-29 07:25:38 +00:00
if ( m_GuiActive )
2008-01-12 12:27:55 +00:00
{
2010-05-29 07:25:38 +00:00
View . HSplitTop ( 16.0f , & MenuBar , & View ) ;
View . HSplitTop ( 53.0f , & ToolBar , & View ) ;
2010-06-05 22:46:47 +00:00
View . VSplitLeft ( 100.0f , & ToolBox , & View ) ;
2010-05-29 07:25:38 +00:00
View . HSplitBottom ( 16.0f , & View , & StatusBar ) ;
2011-05-04 23:50:23 +00:00
if ( m_ShowEnvelopeEditor & & ! m_ShowPicker )
2008-03-29 11:44:03 +00:00
{
2017-03-21 10:24:44 +00:00
float Size = 125.0f ;
2010-05-29 07:25:38 +00:00
if ( m_ShowEnvelopeEditor = = 2 )
2017-03-21 10:24:44 +00:00
Size * = 2.0f ;
2010-05-29 07:25:38 +00:00
else if ( m_ShowEnvelopeEditor = = 3 )
2017-03-21 10:24:44 +00:00
Size * = 3.0f ;
View . HSplitBottom ( Size , & View , & ExtraEditor ) ;
2008-03-29 11:44:03 +00:00
}
2011-07-13 20:38:32 +00:00
if ( m_ShowServerSettingsEditor & & ! m_ShowPicker )
View . HSplitBottom ( 250.0f , & View , & ExtraEditor ) ;
2008-03-29 11:44:03 +00:00
}
2018-06-26 20:51:43 +00:00
else
{
// hack to get keyboard inputs from toolbar even when GUI is not active
2019-01-11 09:48:21 +00:00
ToolBar . x = - 100 ;
ToolBar . y = - 100 ;
ToolBar . w = 50 ;
ToolBar . h = 50 ;
2018-06-26 20:51:43 +00:00
}
2010-05-29 07:25:38 +00:00
2008-03-29 11:44:03 +00:00
// a little hack for now
2010-05-29 07:25:38 +00:00
if ( m_Mode = = MODE_LAYERS )
2018-04-04 19:41:14 +00:00
DoMapEditor ( View ) ;
2010-05-29 07:25:38 +00:00
2011-08-16 20:16:48 +00:00
// do zooming
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyPress ( KEY_KP_MINUS ) & & m_Dialog = = DIALOG_NONE & & m_EditBoxActive = = 0 )
2011-08-16 20:16:48 +00:00
m_ZoomLevel + = 50 ;
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyPress ( KEY_KP_PLUS ) & & m_Dialog = = DIALOG_NONE & & m_EditBoxActive = = 0 )
2011-08-16 20:16:48 +00:00
m_ZoomLevel - = 50 ;
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyPress ( KEY_KP_MULTIPLY ) & & m_Dialog = = DIALOG_NONE & & m_EditBoxActive = = 0 )
2011-08-16 20:16:48 +00:00
{
m_EditorOffsetX = 0 ;
m_EditorOffsetY = 0 ;
m_ZoomLevel = 100 ;
}
2018-10-02 01:52:01 +00:00
for ( int i = KEY_1 ; i < = KEY_0 ; i + + )
{
if ( m_Dialog ! = DIALOG_NONE | | m_EditBoxActive ! = 0 )
break ;
if ( Input ( ) - > KeyPress ( i ) )
{
int Slot = i - KEY_1 ;
2021-12-18 11:23:20 +00:00
if ( Input ( ) - > ModifierIsPressed ( ) & & ! m_Brush . IsEmpty ( ) )
2018-10-02 01:52:01 +00:00
{
dbg_msg ( " editor " , " saving current brush to %d " , Slot ) ;
if ( m_apSavedBrushes [ Slot ] )
{
CLayerGroup * pPrev = m_apSavedBrushes [ Slot ] ;
2022-06-11 19:38:18 +00:00
for ( auto & pLayer : pPrev - > m_vpLayers )
2018-10-02 01:52:01 +00:00
{
2022-05-24 09:24:33 +00:00
if ( pLayer - > m_BrushRefCount = = 1 )
delete pLayer ;
2018-10-02 01:52:01 +00:00
else
2022-05-24 09:24:33 +00:00
pLayer - > m_BrushRefCount - - ;
2018-10-02 01:52:01 +00:00
}
}
delete m_apSavedBrushes [ Slot ] ;
m_apSavedBrushes [ Slot ] = new CLayerGroup ( m_Brush ) ;
2022-06-11 19:38:18 +00:00
for ( auto & pLayer : m_apSavedBrushes [ Slot ] - > m_vpLayers )
2022-05-24 09:24:33 +00:00
pLayer - > m_BrushRefCount + + ;
2018-10-02 01:52:01 +00:00
}
else if ( m_apSavedBrushes [ Slot ] )
{
dbg_msg ( " editor " , " loading brush from slot %d " , Slot ) ;
CLayerGroup * pNew = m_apSavedBrushes [ Slot ] ;
2022-06-11 19:38:18 +00:00
for ( auto & pLayer : pNew - > m_vpLayers )
2022-05-24 09:24:33 +00:00
pLayer - > m_BrushRefCount + + ;
2018-10-02 01:52:01 +00:00
m_Brush = * pNew ;
}
}
}
2014-08-20 22:21:18 +00:00
float Brightness = 0.25f ;
2011-07-12 16:38:33 +00:00
2010-05-29 07:25:38 +00:00
if ( m_GuiActive )
2008-03-29 11:44:03 +00:00
{
2020-09-26 19:41:58 +00:00
RenderBackground ( MenuBar , m_BackgroundTexture , 128.0f , Brightness * 0 ) ;
2010-05-29 07:25:38 +00:00
MenuBar . Margin ( 2.0f , & MenuBar ) ;
2008-03-29 11:44:03 +00:00
2012-08-12 10:41:50 +00:00
RenderBackground ( ToolBox , m_BackgroundTexture , 128.0f , Brightness ) ;
2010-05-29 07:25:38 +00:00
ToolBox . Margin ( 2.0f , & ToolBox ) ;
2012-08-12 10:41:50 +00:00
RenderBackground ( ToolBar , m_BackgroundTexture , 128.0f , Brightness ) ;
2010-05-29 07:25:38 +00:00
ToolBar . Margin ( 2.0f , & ToolBar ) ;
ToolBar . VSplitLeft ( 100.0f , & CModeBar , & ToolBar ) ;
2012-08-12 10:41:50 +00:00
RenderBackground ( StatusBar , m_BackgroundTexture , 128.0f , Brightness ) ;
2010-05-29 07:25:38 +00:00
StatusBar . Margin ( 2.0f , & StatusBar ) ;
2018-06-26 20:51:43 +00:00
}
2007-05-22 15:03:32 +00:00
2019-04-05 23:15:02 +00:00
// show mentions
if ( m_GuiActive & & m_Mentions )
{
char aBuf [ 16 ] ;
if ( m_Mentions = = 1 )
{
2019-04-06 11:46:47 +00:00
str_copy ( aBuf , Localize ( " 1 new mention " ) , sizeof ( aBuf ) ) ;
2019-04-05 23:15:02 +00:00
}
else if ( m_Mentions < = 9 )
{
2019-04-06 11:46:47 +00:00
str_format ( aBuf , sizeof ( aBuf ) , Localize ( " %d new mentions " ) , m_Mentions ) ;
2019-04-05 23:15:02 +00:00
}
else
{
2019-04-06 11:46:47 +00:00
str_copy ( aBuf , Localize ( " 9+ new mentions " ) , sizeof ( aBuf ) ) ;
2019-04-05 23:15:02 +00:00
}
TextRender ( ) - > TextColor ( 1.0f , 0.0f , 0.0f , 1.0f ) ;
2022-06-13 16:28:13 +00:00
TextRender ( ) - > Text ( nullptr , 5.0f , 27.0f , 10.0f , aBuf , - 1.0f ) ;
2019-04-05 23:15:02 +00:00
TextRender ( ) - > TextColor ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
}
2018-06-26 20:51:43 +00:00
// do the toolbar
if ( m_Mode = = MODE_LAYERS )
DoToolbar ( ToolBar ) ;
2010-05-29 07:25:38 +00:00
2020-06-20 23:43:59 +00:00
if ( m_Dialog = = DIALOG_NONE )
{
2021-12-18 11:23:20 +00:00
bool ModPressed = Input ( ) - > ModifierIsPressed ( ) ;
2020-06-20 23:43:59 +00:00
bool ShiftPressed = Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) | | Input ( ) - > KeyIsPressed ( KEY_RSHIFT ) ;
bool AltPressed = Input ( ) - > KeyIsPressed ( KEY_LALT ) | | Input ( ) - > KeyIsPressed ( KEY_RALT ) ;
2020-08-10 07:27:31 +00:00
// ctrl+n to create new map
2021-12-18 11:23:20 +00:00
if ( Input ( ) - > KeyPress ( KEY_N ) & & ModPressed )
2020-08-10 07:27:31 +00:00
{
2020-09-26 19:41:58 +00:00
if ( HasUnsavedData ( ) )
{
if ( ! m_PopupEventWasActivated )
2020-08-10 07:27:31 +00:00
{
2020-09-26 19:41:58 +00:00
m_PopupEventType = POPEVENT_NEW ;
m_PopupEventActivated = true ;
2020-08-10 07:27:31 +00:00
}
2020-09-26 19:41:58 +00:00
}
else
{
Reset ( ) ;
m_aFileName [ 0 ] = 0 ;
}
2020-08-10 07:27:31 +00:00
}
// ctrl+a to append map
2021-12-18 11:23:20 +00:00
if ( Input ( ) - > KeyPress ( KEY_A ) & & ModPressed )
2020-08-10 07:27:31 +00:00
{
InvokeFileDialog ( IStorage : : TYPE_ALL , FILETYPE_MAP , " Append map " , " Append " , " maps " , " " , CallbackAppendMap , this ) ;
}
2020-06-20 23:43:59 +00:00
// ctrl+o or ctrl+l to open
2021-12-18 11:23:20 +00:00
if ( ( Input ( ) - > KeyPress ( KEY_O ) | | Input ( ) - > KeyPress ( KEY_L ) ) & & ModPressed )
2020-06-20 23:43:59 +00:00
{
if ( ShiftPressed )
{
if ( HasUnsavedData ( ) )
{
if ( ! m_PopupEventWasActivated )
{
m_PopupEventType = POPEVENT_LOADCURRENT ;
m_PopupEventActivated = true ;
}
}
else
{
LoadCurrentMap ( ) ;
}
}
else
{
if ( HasUnsavedData ( ) )
{
if ( ! m_PopupEventWasActivated )
{
m_PopupEventType = POPEVENT_LOAD ;
m_PopupEventActivated = true ;
}
}
else
{
InvokeFileDialog ( IStorage : : TYPE_ALL , FILETYPE_MAP , " Load map " , " Load " , " maps " , " " , CallbackOpenMap , this ) ;
}
}
}
2021-05-22 09:24:48 +00:00
// ctrl+shift+alt+s to save as
2021-12-18 11:23:20 +00:00
if ( Input ( ) - > KeyPress ( KEY_S ) & & ModPressed & & ShiftPressed & & AltPressed )
2021-05-22 09:24:48 +00:00
InvokeFileDialog ( IStorage : : TYPE_SAVE , FILETYPE_MAP , " Save map " , " Save " , " maps " , " " , CallbackSaveCopyMap , this ) ;
// ctrl+shift+s to save as
2021-12-18 11:23:20 +00:00
else if ( Input ( ) - > KeyPress ( KEY_S ) & & ModPressed & & ShiftPressed )
2021-05-22 09:24:48 +00:00
InvokeFileDialog ( IStorage : : TYPE_SAVE , FILETYPE_MAP , " Save map " , " Save " , " maps " , " " , CallbackSaveMap , this ) ;
2020-06-20 23:43:59 +00:00
// ctrl+s to save
2021-12-18 11:23:20 +00:00
else if ( Input ( ) - > KeyPress ( KEY_S ) & & ModPressed )
2020-06-20 23:43:59 +00:00
{
if ( m_aFileName [ 0 ] & & m_ValidSaveFilename )
{
if ( ! m_PopupEventWasActivated )
{
str_copy ( m_aFileSaveName , m_aFileName , sizeof ( m_aFileSaveName ) ) ;
CallbackSaveMap ( m_aFileSaveName , IStorage : : TYPE_SAVE , this ) ;
}
}
else
InvokeFileDialog ( IStorage : : TYPE_SAVE , FILETYPE_MAP , " Save map " , " Save " , " maps " , " " , CallbackSaveMap , this ) ;
}
}
2018-06-26 20:51:43 +00:00
if ( m_GuiActive )
{
2019-03-18 01:34:24 +00:00
if ( ! m_ShowPicker )
2008-01-12 12:27:55 +00:00
{
2019-03-18 01:34:24 +00:00
if ( m_ShowEnvelopeEditor | | m_ShowServerSettingsEditor )
{
2012-08-12 10:41:50 +00:00
RenderBackground ( ExtraEditor , m_BackgroundTexture , 128.0f , Brightness ) ;
2019-03-18 01:34:24 +00:00
ExtraEditor . Margin ( 2.0f , & ExtraEditor ) ;
}
2014-01-19 03:02:01 +00:00
}
2010-05-29 07:25:38 +00:00
2018-04-04 19:41:14 +00:00
if ( m_Mode = = MODE_LAYERS )
RenderLayers ( ToolBox , View ) ;
else if ( m_Mode = = MODE_IMAGES )
RenderImages ( ToolBox , View ) ;
else if ( m_Mode = = MODE_SOUNDS )
RenderSounds ( ToolBox , View ) ;
}
2008-03-29 11:44:03 +00:00
2021-09-22 19:48:55 +00:00
UI ( ) - > MapScreen ( ) ;
2008-01-12 12:27:55 +00:00
2010-05-29 07:25:38 +00:00
if ( m_GuiActive )
2008-01-12 12:27:55 +00:00
{
2010-05-29 07:25:38 +00:00
RenderMenubar ( MenuBar ) ;
RenderModebar ( CModeBar ) ;
2017-07-22 10:18:53 +00:00
if ( ! m_ShowPicker )
{
if ( m_ShowEnvelopeEditor )
RenderEnvelopeEditor ( ExtraEditor ) ;
2020-10-06 10:58:37 +00:00
static bool s_ShowServerSettingsEditorLast = false ;
2017-07-22 10:18:53 +00:00
if ( m_ShowServerSettingsEditor )
2020-10-06 10:58:37 +00:00
{
RenderServerSettingsEditor ( ExtraEditor , s_ShowServerSettingsEditorLast ) ;
}
s_ShowServerSettingsEditorLast = m_ShowServerSettingsEditor ;
2017-07-22 10:18:53 +00:00
}
2008-01-12 12:27:55 +00:00
}
2008-01-13 16:30:30 +00:00
2010-05-29 07:25:38 +00:00
if ( m_Dialog = = DIALOG_FILE )
2008-01-13 22:03:32 +00:00
{
2010-05-29 07:25:38 +00:00
static int s_NullUiTarget = 0 ;
UI ( ) - > SetHotItem ( & s_NullUiTarget ) ;
RenderFileDialog ( ) ;
2008-01-13 22:03:32 +00:00
}
2011-03-21 23:31:42 +00:00
if ( m_PopupEventActivated )
{
static int s_PopupID = 0 ;
2020-09-26 19:41:58 +00:00
UiInvokePopupMenu ( & s_PopupID , 0 , Width / 2.0f - 200.0f , Height / 2.0f - 100.0f , 400.0f , 200.0f , PopupEvent ) ;
2011-03-21 23:31:42 +00:00
m_PopupEventActivated = false ;
2011-08-13 17:22:01 +00:00
m_PopupEventWasActivated = true ;
2011-03-21 23:31:42 +00:00
}
2010-05-29 07:25:38 +00:00
UiDoPopupMenu ( ) ;
2020-09-24 16:52:31 +00:00
if ( m_Dialog = = DIALOG_NONE & & ! m_MouseInsidePopup & & UI ( ) - > MouseInside ( & View ) )
{
// Determines in which direction to zoom.
int Zoom = 0 ;
if ( Input ( ) - > KeyPress ( KEY_MOUSE_WHEEL_UP ) )
Zoom - - ;
if ( Input ( ) - > KeyPress ( KEY_MOUSE_WHEEL_DOWN ) )
Zoom + + ;
if ( Zoom ! = 0 )
{
float OldLevel = m_ZoomLevel ;
2021-10-27 18:05:26 +00:00
m_ZoomLevel = maximum ( m_ZoomLevel + Zoom * 20 , 10 ) ;
if ( g_Config . m_ClLimitMaxZoomLevel )
m_ZoomLevel = minimum ( m_ZoomLevel , 2000 ) ;
2020-09-24 16:52:31 +00:00
if ( g_Config . m_EdZoomTarget )
ZoomMouseTarget ( ( float ) m_ZoomLevel / OldLevel ) ;
}
}
2020-09-24 16:53:11 +00:00
m_WorldZoom = m_ZoomLevel / 100.0f ;
2020-09-24 16:52:31 +00:00
2010-05-29 07:25:38 +00:00
if ( m_GuiActive )
RenderStatusbar ( StatusBar ) ;
2008-03-29 14:34:40 +00:00
//
2010-05-29 07:25:38 +00:00
if ( g_Config . m_EdShowkeys )
2008-03-29 14:34:40 +00:00
{
2021-09-22 19:48:55 +00:00
UI ( ) - > MapScreen ( ) ;
2010-05-29 07:25:38 +00:00
CTextCursor Cursor ;
2020-09-26 19:41:58 +00:00
TextRender ( ) - > SetCursor ( & Cursor , View . x + 10 , View . y + View . h - 24 - 10 , 24.0f , TEXTFLAG_RENDER ) ;
2010-05-29 07:25:38 +00:00
int NKeys = 0 ;
2008-03-29 14:34:40 +00:00
for ( int i = 0 ; i < KEY_LAST ; i + + )
{
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyIsPressed ( i ) )
2008-03-29 14:34:40 +00:00
{
2010-05-29 07:25:38 +00:00
if ( NKeys )
TextRender ( ) - > TextEx ( & Cursor , " + " , - 1 ) ;
TextRender ( ) - > TextEx ( & Cursor , Input ( ) - > KeyName ( i ) , - 1 ) ;
NKeys + + ;
2008-03-29 14:34:40 +00:00
}
}
}
2010-05-29 07:25:38 +00:00
if ( m_ShowMousePointer )
2008-09-01 18:38:08 +00:00
{
// render butt ugly mouse cursor
2009-10-27 14:38:53 +00:00
float mx = UI ( ) - > MouseX ( ) ;
float my = UI ( ) - > MouseY ( ) ;
2020-09-15 14:18:12 +00:00
Graphics ( ) - > WrapClamp ( ) ;
2012-08-12 10:41:50 +00:00
Graphics ( ) - > TextureSet ( m_CursorTexture ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsBegin ( ) ;
2010-05-29 07:25:38 +00:00
if ( ms_pUiGotContext = = UI ( ) - > HotItem ( ) )
2020-09-26 19:41:58 +00:00
Graphics ( ) - > SetColor ( 1 , 0 , 0 , 1 ) ;
IGraphics : : CQuadItem QuadItem ( mx , my , 16.0f , 16.0f ) ;
2010-05-29 07:25:38 +00:00
Graphics ( ) - > QuadsDrawTL ( & QuadItem , 1 ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsEnd ( ) ;
2020-09-15 14:18:12 +00:00
Graphics ( ) - > WrapNormal ( ) ;
2008-09-01 18:38:08 +00:00
}
2020-09-24 16:52:31 +00:00
m_MouseInsidePopup = false ;
2008-01-12 12:27:55 +00:00
}
2010-05-29 07:25:38 +00:00
void CEditor : : Reset ( bool CreateDefault )
2007-05-22 15:03:32 +00:00
{
2010-05-29 07:25:38 +00:00
m_Map . Clean ( ) ;
2008-01-12 12:27:55 +00:00
2014-01-19 03:02:01 +00:00
//delete undo file
char aBuffer [ 1024 ] ;
m_pStorage - > GetCompletePath ( IStorage : : TYPE_SAVE , " editor/ " , aBuffer , sizeof ( aBuffer ) ) ;
2018-10-02 01:52:01 +00:00
mem_zero ( m_apSavedBrushes , sizeof m_apSavedBrushes ) ;
2008-01-12 12:27:55 +00:00
// create default layers
2010-05-29 07:25:38 +00:00
if ( CreateDefault )
2022-02-11 10:10:03 +00:00
{
m_EditorWasUsedBefore = true ;
m_Map . CreateDefault ( GetEntitiesTexture ( ) ) ;
}
2010-05-29 07:25:38 +00:00
2020-09-21 17:36:26 +00:00
SelectGameLayer ( ) ;
2022-06-11 19:38:18 +00:00
m_vSelectedQuads . clear ( ) ;
2010-05-29 07:25:38 +00:00
m_SelectedPoints = 0 ;
m_SelectedEnvelope = 0 ;
m_SelectedImage = 0 ;
2014-10-10 17:11:21 +00:00
m_SelectedSound = 0 ;
m_SelectedSource = - 1 ;
2011-08-11 08:59:14 +00:00
2010-06-09 23:09:51 +00:00
m_WorldOffsetX = 0 ;
m_WorldOffsetY = 0 ;
m_EditorOffsetX = 0.0f ;
m_EditorOffsetY = 0.0f ;
2011-08-11 08:59:14 +00:00
2010-06-09 23:09:51 +00:00
m_WorldZoom = 1.0f ;
m_ZoomLevel = 200 ;
m_MouseDeltaX = 0 ;
m_MouseDeltaY = 0 ;
m_MouseDeltaWx = 0 ;
m_MouseDeltaWy = 0 ;
2011-03-21 23:31:42 +00:00
m_Map . m_Modified = false ;
2011-08-14 14:31:48 +00:00
m_ShowEnvelopePreview = 0 ;
2017-02-21 16:10:08 +00:00
m_ShiftBy = 1 ;
2016-08-23 01:08:36 +00:00
m_Map . m_Modified = false ;
2007-05-22 15:03:32 +00:00
}
2021-02-08 21:26:26 +00:00
int CEditor : : GetLineDistance ( ) const
2011-07-10 20:16:16 +00:00
{
int LineDistance = 512 ;
if ( m_ZoomLevel < = 100 )
LineDistance = 16 ;
else if ( m_ZoomLevel < = 250 )
LineDistance = 32 ;
else if ( m_ZoomLevel < = 450 )
LineDistance = 64 ;
else if ( m_ZoomLevel < = 850 )
LineDistance = 128 ;
else if ( m_ZoomLevel < = 1550 )
LineDistance = 256 ;
return LineDistance ;
}
2014-10-07 18:07:46 +00:00
void CEditor : : ZoomMouseTarget ( float ZoomFactor )
{
// zoom to the current mouse position
// get absolute mouse position
float aPoints [ 4 ] ;
2022-05-17 13:00:06 +00:00
RenderTools ( ) - > MapScreenToWorld (
2014-10-07 18:07:46 +00:00
m_WorldOffsetX , m_WorldOffsetY ,
2022-08-04 23:16:44 +00:00
100.0f , 100.0f , 100.0f , 0.0f , 0.0f , Graphics ( ) - > ScreenAspect ( ) , m_WorldZoom , aPoints ) ;
2014-10-07 18:07:46 +00:00
2020-09-26 19:41:58 +00:00
float WorldWidth = aPoints [ 2 ] - aPoints [ 0 ] ;
float WorldHeight = aPoints [ 3 ] - aPoints [ 1 ] ;
2014-10-07 18:07:46 +00:00
2020-09-26 19:41:58 +00:00
float Mwx = aPoints [ 0 ] + WorldWidth * ( UI ( ) - > MouseX ( ) / UI ( ) - > Screen ( ) - > w ) ;
float Mwy = aPoints [ 1 ] + WorldHeight * ( UI ( ) - > MouseY ( ) / UI ( ) - > Screen ( ) - > h ) ;
2014-10-07 18:07:46 +00:00
// adjust camera
2020-09-26 19:41:58 +00:00
m_WorldOffsetX + = ( Mwx - m_WorldOffsetX ) * ( 1 - ZoomFactor ) ;
m_WorldOffsetY + = ( Mwy - m_WorldOffsetY ) * ( 1 - ZoomFactor ) ;
2014-10-07 18:07:46 +00:00
}
2010-08-06 18:18:53 +00:00
void CEditorMap : : DeleteEnvelope ( int Index )
{
2022-06-11 19:38:18 +00:00
if ( Index < 0 | | Index > = ( int ) m_vpEnvelopes . size ( ) )
2010-08-06 18:18:53 +00:00
return ;
2011-03-21 23:31:42 +00:00
m_Modified = true ;
2010-08-06 18:18:53 +00:00
// fix links between envelopes and quads
2022-06-11 19:38:18 +00:00
for ( auto & pGroup : m_vpGroups )
for ( auto & pLayer : pGroup - > m_vpLayers )
2022-05-24 09:24:33 +00:00
if ( pLayer - > m_Type = = LAYERTYPE_QUADS )
2010-08-06 18:18:53 +00:00
{
2022-05-24 09:24:33 +00:00
CLayerQuads * pLayerQuads = static_cast < CLayerQuads * > ( pLayer ) ;
2022-06-11 19:38:18 +00:00
for ( auto & Quad : pLayerQuads - > m_vQuads )
2010-08-06 18:18:53 +00:00
{
2022-05-24 09:24:33 +00:00
if ( Quad . m_PosEnv = = Index )
Quad . m_PosEnv = - 1 ;
else if ( Quad . m_PosEnv > Index )
Quad . m_PosEnv - - ;
if ( Quad . m_ColorEnv = = Index )
Quad . m_ColorEnv = - 1 ;
else if ( Quad . m_ColorEnv > Index )
Quad . m_ColorEnv - - ;
2010-08-06 18:18:53 +00:00
}
}
2022-05-24 09:24:33 +00:00
else if ( pLayer - > m_Type = = LAYERTYPE_TILES )
2011-11-09 15:06:17 +00:00
{
2022-05-24 09:24:33 +00:00
CLayerTiles * pLayerTiles = static_cast < CLayerTiles * > ( pLayer ) ;
if ( pLayerTiles - > m_ColorEnv = = Index )
pLayerTiles - > m_ColorEnv = - 1 ;
if ( pLayerTiles - > m_ColorEnv > Index )
pLayerTiles - > m_ColorEnv - - ;
2011-11-09 15:06:17 +00:00
}
2022-06-05 13:21:00 +00:00
else if ( pLayer - > m_Type = = LAYERTYPE_SOUNDS )
{
CLayerSounds * pLayerSounds = static_cast < CLayerSounds * > ( pLayer ) ;
2022-06-11 19:38:18 +00:00
for ( auto & Source : pLayerSounds - > m_vSources )
2022-06-05 13:21:00 +00:00
{
if ( Source . m_PosEnv = = Index )
Source . m_PosEnv = - 1 ;
else if ( Source . m_PosEnv > Index )
Source . m_PosEnv - - ;
if ( Source . m_SoundEnv = = Index )
Source . m_SoundEnv = - 1 ;
else if ( Source . m_SoundEnv > Index )
Source . m_SoundEnv - - ;
}
}
2010-08-06 18:18:53 +00:00
2022-06-11 19:38:18 +00:00
m_vpEnvelopes . erase ( m_vpEnvelopes . begin ( ) + Index ) ;
2010-08-06 18:18:53 +00:00
}
2010-05-29 07:25:38 +00:00
void CEditorMap : : MakeGameLayer ( CLayer * pLayer )
2008-01-12 12:27:55 +00:00
{
2010-05-29 07:25:38 +00:00
m_pGameLayer = ( CLayerGame * ) pLayer ;
m_pGameLayer - > m_pEditor = m_pEditor ;
2022-02-11 10:10:03 +00:00
m_pGameLayer - > m_Texture = m_pEditor - > GetEntitiesTexture ( ) ;
2008-01-12 12:27:55 +00:00
}
2010-05-29 07:25:38 +00:00
void CEditorMap : : MakeGameGroup ( CLayerGroup * pGroup )
2008-01-12 12:27:55 +00:00
{
2010-05-29 07:25:38 +00:00
m_pGameGroup = pGroup ;
m_pGameGroup - > m_GameGroup = true ;
2011-07-12 01:14:46 +00:00
str_copy ( m_pGameGroup - > m_aName , " Game " , sizeof ( m_pGameGroup - > m_aName ) ) ;
2008-01-12 12:27:55 +00:00
}
2010-05-29 07:25:38 +00:00
void CEditorMap : : Clean ( )
2008-03-09 23:29:14 +00:00
{
2022-06-11 19:38:18 +00:00
for ( auto & pGroup : m_vpGroups )
2020-08-16 22:07:17 +00:00
{
2022-06-11 19:38:18 +00:00
DeleteAll ( pGroup - > m_vpLayers ) ;
2020-08-16 22:07:17 +00:00
}
2022-06-11 19:38:18 +00:00
DeleteAll ( m_vpGroups ) ;
DeleteAll ( m_vpEnvelopes ) ;
DeleteAll ( m_vpImages ) ;
DeleteAll ( m_vpSounds ) ;
2010-05-29 07:25:38 +00:00
2011-07-12 21:31:39 +00:00
m_MapInfo . Reset ( ) ;
2022-06-11 19:38:18 +00:00
m_vSettings . clear ( ) ;
2011-07-13 20:38:32 +00:00
2022-06-13 16:28:13 +00:00
m_pGameLayer = nullptr ;
m_pGameGroup = nullptr ;
2011-03-21 23:31:42 +00:00
m_Modified = false ;
2011-04-09 06:41:31 +00:00
2022-06-13 16:28:13 +00:00
m_pTeleLayer = nullptr ;
m_pSpeedupLayer = nullptr ;
m_pFrontLayer = nullptr ;
m_pSwitchLayer = nullptr ;
m_pTuneLayer = nullptr ;
2008-03-09 23:29:14 +00:00
}
2012-08-12 10:41:50 +00:00
void CEditorMap : : CreateDefault ( IGraphics : : CTextureHandle EntitiesTexture )
2008-03-09 23:29:14 +00:00
{
2010-06-21 23:15:12 +00:00
// add background
CLayerGroup * pGroup = NewGroup ( ) ;
pGroup - > m_ParallaxX = 0 ;
pGroup - > m_ParallaxY = 0 ;
2022-08-10 01:51:03 +00:00
pGroup - > m_CustomParallaxZoom = 0 ;
2022-08-04 23:16:44 +00:00
pGroup - > m_ParallaxZoom = 0 ;
2010-06-21 23:15:12 +00:00
CLayerQuads * pLayer = new CLayerQuads ;
pLayer - > m_pEditor = m_pEditor ;
2019-03-28 12:41:07 +00:00
CQuad * pQuad = pLayer - > NewQuad ( 0 , 0 , 1600 , 1200 ) ;
2010-06-21 23:15:12 +00:00
pQuad - > m_aColors [ 0 ] . r = pQuad - > m_aColors [ 1 ] . r = 94 ;
pQuad - > m_aColors [ 0 ] . g = pQuad - > m_aColors [ 1 ] . g = 132 ;
pQuad - > m_aColors [ 0 ] . b = pQuad - > m_aColors [ 1 ] . b = 174 ;
pQuad - > m_aColors [ 2 ] . r = pQuad - > m_aColors [ 3 ] . r = 204 ;
pQuad - > m_aColors [ 2 ] . g = pQuad - > m_aColors [ 3 ] . g = 232 ;
pQuad - > m_aColors [ 2 ] . b = pQuad - > m_aColors [ 3 ] . b = 255 ;
pGroup - > AddLayer ( pLayer ) ;
2014-03-12 22:57:00 +00:00
// add game layer and reset front, tele, speedup, tune and switch layer pointers
2010-05-29 07:25:38 +00:00
MakeGameGroup ( NewGroup ( ) ) ;
MakeGameLayer ( new CLayerGame ( 50 , 50 ) ) ;
m_pGameGroup - > AddLayer ( m_pGameLayer ) ;
2011-04-09 06:41:31 +00:00
2022-06-13 16:28:13 +00:00
m_pFrontLayer = nullptr ;
m_pTeleLayer = nullptr ;
m_pSpeedupLayer = nullptr ;
m_pSwitchLayer = nullptr ;
m_pTuneLayer = nullptr ;
2008-03-09 23:29:14 +00:00
}
2022-02-11 10:10:03 +00:00
int CEditor : : GetTextureUsageFlag ( )
{
return Graphics ( ) - > HasTextureArrays ( ) ? IGraphics : : TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics : : TEXLOAD_TO_3D_TEXTURE ;
}
IGraphics : : CTextureHandle CEditor : : GetFrontTexture ( )
{
int TextureLoadFlag = GetTextureUsageFlag ( ) ;
if ( ! m_FrontTexture . IsValid ( ) )
m_FrontTexture = Graphics ( ) - > LoadTexture ( " editor/front.png " , IStorage : : TYPE_ALL , CImageInfo : : FORMAT_AUTO , TextureLoadFlag ) ;
return m_FrontTexture ;
}
IGraphics : : CTextureHandle CEditor : : GetTeleTexture ( )
{
int TextureLoadFlag = GetTextureUsageFlag ( ) ;
if ( ! m_TeleTexture . IsValid ( ) )
m_TeleTexture = Graphics ( ) - > LoadTexture ( " editor/tele.png " , IStorage : : TYPE_ALL , CImageInfo : : FORMAT_AUTO , TextureLoadFlag ) ;
return m_TeleTexture ;
}
IGraphics : : CTextureHandle CEditor : : GetSpeedupTexture ( )
{
int TextureLoadFlag = GetTextureUsageFlag ( ) ;
if ( ! m_SpeedupTexture . IsValid ( ) )
m_SpeedupTexture = Graphics ( ) - > LoadTexture ( " editor/speedup.png " , IStorage : : TYPE_ALL , CImageInfo : : FORMAT_AUTO , TextureLoadFlag ) ;
return m_SpeedupTexture ;
}
IGraphics : : CTextureHandle CEditor : : GetSwitchTexture ( )
{
int TextureLoadFlag = GetTextureUsageFlag ( ) ;
if ( ! m_SwitchTexture . IsValid ( ) )
m_SwitchTexture = Graphics ( ) - > LoadTexture ( " editor/switch.png " , IStorage : : TYPE_ALL , CImageInfo : : FORMAT_AUTO , TextureLoadFlag ) ;
return m_SwitchTexture ;
}
IGraphics : : CTextureHandle CEditor : : GetTuneTexture ( )
{
int TextureLoadFlag = GetTextureUsageFlag ( ) ;
if ( ! m_TuneTexture . IsValid ( ) )
m_TuneTexture = Graphics ( ) - > LoadTexture ( " editor/tune.png " , IStorage : : TYPE_ALL , CImageInfo : : FORMAT_AUTO , TextureLoadFlag ) ;
return m_TuneTexture ;
}
IGraphics : : CTextureHandle CEditor : : GetEntitiesTexture ( )
{
int TextureLoadFlag = GetTextureUsageFlag ( ) ;
if ( ! m_EntitiesTexture . IsValid ( ) )
m_EntitiesTexture = Graphics ( ) - > LoadTexture ( " editor/entities/DDNet.png " , IStorage : : TYPE_ALL , CImageInfo : : FORMAT_AUTO , TextureLoadFlag ) ;
return m_EntitiesTexture ;
}
2010-05-29 07:25:38 +00:00
void CEditor : : Init ( )
2007-05-22 15:03:32 +00:00
{
2010-05-29 07:25:38 +00:00
m_pInput = Kernel ( ) - > RequestInterface < IInput > ( ) ;
m_pClient = Kernel ( ) - > RequestInterface < IClient > ( ) ;
2021-01-10 12:47:07 +00:00
m_pConfig = Kernel ( ) - > RequestInterface < IConfigManager > ( ) - > Values ( ) ;
2010-08-17 22:06:00 +00:00
m_pConsole = Kernel ( ) - > RequestInterface < IConsole > ( ) ;
2010-05-29 07:25:38 +00:00
m_pGraphics = Kernel ( ) - > RequestInterface < IGraphics > ( ) ;
m_pTextRender = Kernel ( ) - > RequestInterface < ITextRender > ( ) ;
2010-09-12 11:15:59 +00:00
m_pStorage = Kernel ( ) - > RequestInterface < IStorage > ( ) ;
2014-10-08 14:53:25 +00:00
m_pSound = Kernel ( ) - > RequestInterface < ISound > ( ) ;
2022-05-27 16:14:31 +00:00
m_UI . Init ( m_pInput , m_pGraphics , m_pTextRender ) ;
2022-05-14 11:31:07 +00:00
m_RenderTools . Init ( m_pGraphics , m_pTextRender ) ;
2010-05-29 07:25:38 +00:00
m_Map . m_pEditor = this ;
2021-12-03 18:54:22 +00:00
UIEx ( ) - > Init ( UI ( ) , Kernel ( ) , RenderTools ( ) , Input ( ) - > GetEventsRaw ( ) , Input ( ) - > GetEventCountRaw ( ) ) ;
2021-05-26 13:01:50 +00:00
2012-08-12 10:41:50 +00:00
m_CheckerTexture = Graphics ( ) - > LoadTexture ( " editor/checker.png " , IStorage : : TYPE_ALL , CImageInfo : : FORMAT_AUTO , 0 ) ;
m_BackgroundTexture = Graphics ( ) - > LoadTexture ( " editor/background.png " , IStorage : : TYPE_ALL , CImageInfo : : FORMAT_AUTO , 0 ) ;
m_CursorTexture = Graphics ( ) - > LoadTexture ( " editor/cursor.png " , IStorage : : TYPE_ALL , CImageInfo : : FORMAT_AUTO , 0 ) ;
2010-05-29 07:25:38 +00:00
m_TilesetPicker . m_pEditor = this ;
m_TilesetPicker . MakePalette ( ) ;
m_TilesetPicker . m_Readonly = true ;
2014-08-20 22:56:35 +00:00
m_QuadsetPicker . m_pEditor = this ;
2019-03-28 12:41:07 +00:00
m_QuadsetPicker . NewQuad ( 0 , 0 , 64 , 64 ) ;
2014-08-20 22:56:35 +00:00
m_QuadsetPicker . m_Readonly = true ;
2010-05-29 07:25:38 +00:00
m_Brush . m_pMap = & m_Map ;
2022-02-11 10:10:03 +00:00
Reset ( false ) ;
2011-03-21 23:31:42 +00:00
m_Map . m_Modified = false ;
2015-08-17 12:10:08 +00:00
2019-04-26 21:47:34 +00:00
ms_PickerColor = ColorHSVA ( 1.0f , 0.0f , 0.0f ) ;
2007-12-02 17:55:45 +00:00
}
2020-09-20 00:24:17 +00:00
void CEditor : : PlaceBorderTiles ( )
2007-12-02 17:55:45 +00:00
{
2011-08-11 08:59:14 +00:00
CLayerTiles * pT = ( CLayerTiles * ) GetSelectedLayerType ( 0 , LAYERTYPE_TILES ) ;
2020-09-26 19:41:58 +00:00
for ( int i = 0 ; i < pT - > m_Width * 2 ; + + i )
2011-08-11 08:59:14 +00:00
pT - > m_pTiles [ i ] . m_Index = 1 ;
2020-09-26 19:41:58 +00:00
for ( int i = 0 ; i < pT - > m_Width * pT - > m_Height ; + + i )
2011-08-11 08:59:14 +00:00
{
2020-09-26 19:41:58 +00:00
if ( i % pT - > m_Width < 2 | | i % pT - > m_Width > pT - > m_Width - 3 )
2011-08-11 08:59:14 +00:00
pT - > m_pTiles [ i ] . m_Index = 1 ;
}
2020-09-26 19:41:58 +00:00
for ( int i = ( pT - > m_Width * ( pT - > m_Height - 2 ) ) ; i < pT - > m_Width * pT - > m_Height ; + + i )
2011-08-11 08:59:14 +00:00
pT - > m_pTiles [ i ] . m_Index = 1 ;
2010-05-29 07:25:38 +00:00
}
2022-06-15 15:37:22 +00:00
void CEditor : : OnUpdate ( )
2010-05-29 07:25:38 +00:00
{
2022-02-11 10:10:03 +00:00
if ( ! m_EditorWasUsedBefore )
{
m_EditorWasUsedBefore = true ;
Reset ( ) ;
}
2022-06-16 19:01:23 +00:00
// handle cursor movement
2021-09-15 21:52:09 +00:00
{
2022-06-16 19:01:51 +00:00
static float s_MouseX = 0.0f ;
static float s_MouseY = 0.0f ;
2022-06-15 15:37:22 +00:00
float MouseRelX = 0.0f , MouseRelY = 0.0f ;
IInput : : ECursorType CursorType = Input ( ) - > CursorRelative ( & MouseRelX , & MouseRelY ) ;
2022-06-15 10:08:14 +00:00
if ( CursorType ! = IInput : : CURSOR_NONE )
2022-06-15 15:37:22 +00:00
UIEx ( ) - > ConvertMouseMove ( & MouseRelX , & MouseRelY , CursorType ) ;
2021-12-03 18:54:22 +00:00
UIEx ( ) - > ResetMouseSlow ( ) ;
2007-12-02 17:55:45 +00:00
2022-06-16 18:47:59 +00:00
m_MouseDeltaX + = MouseRelX ;
m_MouseDeltaY + = MouseRelY ;
2021-10-23 11:48:21 +00:00
if ( ! m_LockMouse )
{
2022-06-15 15:37:22 +00:00
s_MouseX = clamp < float > ( s_MouseX + MouseRelX , 0.0f , Graphics ( ) - > WindowWidth ( ) ) ;
s_MouseY = clamp < float > ( s_MouseY + MouseRelY , 0.0f , Graphics ( ) - > WindowHeight ( ) ) ;
2021-10-23 11:48:21 +00:00
}
2021-09-15 21:52:09 +00:00
2022-06-15 15:37:22 +00:00
// update positions for ui, but only update ui when rendering
m_MouseX = UI ( ) - > Screen ( ) - > w * ( ( float ) s_MouseX / Graphics ( ) - > WindowWidth ( ) ) ;
m_MouseY = UI ( ) - > Screen ( ) - > h * ( ( float ) s_MouseY / Graphics ( ) - > WindowHeight ( ) ) ;
2010-05-29 07:25:38 +00:00
2008-01-12 12:27:55 +00:00
// fix correct world x and y
2022-06-15 15:37:22 +00:00
CLayerGroup * pGroup = GetSelectedGroup ( ) ;
if ( pGroup )
2008-01-12 12:27:55 +00:00
{
2010-05-29 07:25:38 +00:00
float aPoints [ 4 ] ;
2022-06-15 15:37:22 +00:00
pGroup - > Mapping ( aPoints ) ;
2010-05-29 07:25:38 +00:00
2020-09-26 19:41:58 +00:00
float WorldWidth = aPoints [ 2 ] - aPoints [ 0 ] ;
float WorldHeight = aPoints [ 3 ] - aPoints [ 1 ] ;
2010-05-29 07:25:38 +00:00
2022-08-06 15:33:58 +00:00
m_MouseWScale = WorldWidth / Graphics ( ) - > WindowWidth ( ) ;
2022-06-15 15:37:22 +00:00
m_MouseWorldX = aPoints [ 0 ] + WorldWidth * ( s_MouseX / Graphics ( ) - > WindowWidth ( ) ) ;
m_MouseWorldY = aPoints [ 1 ] + WorldHeight * ( s_MouseY / Graphics ( ) - > WindowHeight ( ) ) ;
2022-06-16 18:47:59 +00:00
m_MouseDeltaWx = m_MouseDeltaX * ( WorldWidth / Graphics ( ) - > WindowWidth ( ) ) ;
m_MouseDeltaWy = m_MouseDeltaY * ( WorldHeight / Graphics ( ) - > WindowHeight ( ) ) ;
2022-06-15 15:37:22 +00:00
}
else
{
m_MouseWorldX = 0.0f ;
m_MouseWorldY = 0.0f ;
2008-01-12 12:27:55 +00:00
}
2007-05-22 15:03:32 +00:00
}
2022-07-30 11:31:00 +00:00
}
2010-05-29 07:25:38 +00:00
2022-07-30 11:31:00 +00:00
void CEditor : : OnRender ( )
{
2008-01-12 12:27:55 +00:00
// toggle gui
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyPress ( KEY_TAB ) )
2010-05-29 07:25:38 +00:00
m_GuiActive = ! m_GuiActive ;
2007-12-02 17:55:45 +00:00
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyPress ( KEY_F10 ) )
2010-05-29 07:25:38 +00:00
m_ShowMousePointer = false ;
2022-06-15 15:37:22 +00:00
if ( m_Animate )
m_AnimateTime = ( time_get ( ) - m_AnimateStart ) / ( float ) time_freq ( ) ;
else
m_AnimateTime = 0 ;
ms_pUiGotContext = nullptr ;
UI ( ) - > StartCheck ( ) ;
UI ( ) - > Update ( m_MouseX , m_MouseY , m_MouseWorldX , m_MouseWorldY ) ;
2010-05-29 07:25:38 +00:00
Render ( ) ;
2022-06-16 18:47:59 +00:00
m_MouseDeltaX = 0.0f ;
m_MouseDeltaY = 0.0f ;
m_MouseDeltaWx = 0.0f ;
m_MouseDeltaWy = 0.0f ;
2016-04-30 18:11:26 +00:00
if ( Input ( ) - > KeyPress ( KEY_F10 ) )
2008-09-01 18:38:08 +00:00
{
2022-06-13 16:28:13 +00:00
Graphics ( ) - > TakeScreenshot ( nullptr ) ;
2010-05-29 07:25:38 +00:00
m_ShowMousePointer = true ;
2008-09-01 18:38:08 +00:00
}
2010-05-29 07:25:38 +00:00
2022-05-27 08:55:32 +00:00
UI ( ) - > FinishCheck ( ) ;
2016-04-30 18:11:26 +00:00
Input ( ) - > Clear ( ) ;
2007-05-22 15:03:32 +00:00
}
2020-05-15 14:29:09 +00:00
void CEditor : : LoadCurrentMap ( )
{
Load ( m_pClient - > GetCurrentMapPath ( ) , IStorage : : TYPE_ALL ) ;
m_ValidSaveFilename = true ;
2020-09-26 19:41:58 +00:00
CGameClient * pGameClient = ( CGameClient * ) Kernel ( ) - > RequestInterface < IGameClient > ( ) ;
2021-07-12 09:43:56 +00:00
vec2 Center = pGameClient - > m_Camera . m_Center ;
2020-05-15 14:29:09 +00:00
2020-05-19 16:08:27 +00:00
m_WorldOffsetX = Center . x ;
m_WorldOffsetY = Center . y ;
2020-05-15 14:29:09 +00:00
}
2010-06-22 00:07:52 +00:00
IEditor * CreateEditor ( ) { return new CEditor ; }
2011-04-09 06:41:31 +00:00
// DDRace
void CEditorMap : : MakeTeleLayer ( CLayer * pLayer )
{
m_pTeleLayer = ( CLayerTele * ) pLayer ;
m_pTeleLayer - > m_pEditor = m_pEditor ;
2022-02-11 10:10:03 +00:00
m_pTeleLayer - > m_Texture = m_pEditor - > GetTeleTexture ( ) ;
2011-04-09 06:41:31 +00:00
}
void CEditorMap : : MakeSpeedupLayer ( CLayer * pLayer )
{
m_pSpeedupLayer = ( CLayerSpeedup * ) pLayer ;
m_pSpeedupLayer - > m_pEditor = m_pEditor ;
2022-02-11 10:10:03 +00:00
m_pSpeedupLayer - > m_Texture = m_pEditor - > GetSpeedupTexture ( ) ;
2011-04-09 06:41:31 +00:00
}
void CEditorMap : : MakeFrontLayer ( CLayer * pLayer )
{
m_pFrontLayer = ( CLayerFront * ) pLayer ;
m_pFrontLayer - > m_pEditor = m_pEditor ;
2022-02-11 10:10:03 +00:00
m_pFrontLayer - > m_Texture = m_pEditor - > GetFrontTexture ( ) ;
2011-04-09 06:41:31 +00:00
}
void CEditorMap : : MakeSwitchLayer ( CLayer * pLayer )
{
m_pSwitchLayer = ( CLayerSwitch * ) pLayer ;
m_pSwitchLayer - > m_pEditor = m_pEditor ;
2022-02-11 10:10:03 +00:00
m_pSwitchLayer - > m_Texture = m_pEditor - > GetSwitchTexture ( ) ;
2011-04-09 06:41:31 +00:00
}
2014-03-12 22:57:00 +00:00
void CEditorMap : : MakeTuneLayer ( CLayer * pLayer )
{
m_pTuneLayer = ( CLayerTune * ) pLayer ;
m_pTuneLayer - > m_pEditor = m_pEditor ;
2022-02-11 10:10:03 +00:00
m_pTuneLayer - > m_Texture = m_pEditor - > GetTuneTexture ( ) ;
2014-03-12 22:57:00 +00:00
}