2013-05-05 16:42:55 +00:00
# include "mainterrainform.h"
# include "ui_mainterrainform.h"
2013-06-09 17:36:30 +00:00
# include <QMessageBox>
# include "dialogbaseterrainnoise.h"
2013-05-09 17:13:04 +00:00
# include "dialogterrainpainting.h"
2013-05-10 08:10:07 +00:00
# include "previewterrainshape.h"
2013-11-12 22:15:35 +00:00
# include "common/freeformhelper.h"
2013-05-09 17:13:04 +00:00
# include "tools.h"
2013-10-29 20:28:59 +00:00
# include "Scenery.h"
2013-11-12 20:34:35 +00:00
# include "textures/public.h"
2013-05-09 17:13:04 +00:00
2013-05-05 16:42:55 +00:00
MainTerrainForm : : MainTerrainForm ( QWidget * parent ) :
QWidget ( parent ) ,
ui ( new Ui : : MainTerrainForm )
{
2013-05-09 17:13:04 +00:00
_terrain = ( TerrainDefinition * ) TerrainDefinitionClass . create ( ) ;
2013-05-05 16:42:55 +00:00
ui - > setupUi ( this ) ;
2013-05-09 17:13:04 +00:00
2013-06-20 17:01:39 +00:00
// TEMP
ui - > button_dialog_basenoise - > hide ( ) ;
2013-05-09 17:13:04 +00:00
_form_helper = new FreeFormHelper ( this ) ;
2013-05-10 08:10:07 +00:00
_renderer_shape = new PreviewTerrainShape ( _terrain ) ;
2013-05-25 13:33:37 +00:00
_form_helper - > addPreview ( ui - > preview_shape , _renderer_shape ) ;
2013-05-09 17:13:04 +00:00
2013-05-25 13:33:37 +00:00
_form_helper - > addDoubleInputSlider ( ui - > input_scaling , & _terrain - > scaling , 0.1 , 3.0 , 0.03 , 0.3 ) ;
2013-06-09 13:11:03 +00:00
_form_helper - > addDoubleInputSlider ( ui - > input_height , & _terrain - > height , 1.0 , 90.0 , 0.5 , 5.0 ) ;
2013-05-25 13:33:37 +00:00
_form_helper - > addDoubleInputSlider ( ui - > input_shadow_smoothing , & _terrain - > shadow_smoothing , 0.0 , 0.3 , 0.003 , 0.03 ) ;
2013-06-09 16:08:01 +00:00
_form_helper - > addDoubleInputSlider ( ui - > input_water_height , & _terrain - > water_height , - 1.0 , 1.0 , 0.01 , 0.1 ) ;
2013-05-09 17:13:04 +00:00
2013-05-25 13:33:37 +00:00
_form_helper - > setApplyButton ( ui - > button_apply ) ;
_form_helper - > setRevertButton ( ui - > button_revert ) ;
_form_helper - > setExploreButton ( ui - > button_explore ) ;
_form_helper - > setRenderButton ( ui - > button_render ) ;
2013-05-09 17:13:04 +00:00
2013-06-09 17:36:30 +00:00
connect ( ui - > button_dialog_basenoise , SIGNAL ( clicked ( ) ) , this , SLOT ( buttonBaseNoisePressed ( ) ) ) ;
2013-05-25 13:33:37 +00:00
connect ( ui - > button_dialog_painting , SIGNAL ( clicked ( ) ) , this , SLOT ( buttonPaintingPressed ( ) ) ) ;
connect ( ui - > button_goto_textures , SIGNAL ( clicked ( ) ) , this , SLOT ( buttonTexturesPressed ( ) ) ) ;
2013-05-09 17:13:04 +00:00
_form_helper - > startManaging ( ) ;
2013-05-05 16:42:55 +00:00
}
MainTerrainForm : : ~ MainTerrainForm ( )
{
2013-05-09 17:13:04 +00:00
delete _form_helper ;
2013-05-05 16:42:55 +00:00
delete ui ;
2013-05-10 08:10:07 +00:00
delete _renderer_shape ;
2013-05-09 17:13:04 +00:00
TerrainDefinitionClass . destroy ( _terrain ) ;
}
void MainTerrainForm : : refreshFromLocalData ( )
{
qint64 memused = terrainGetMemoryStats ( _terrain ) ;
if ( memused > 0 )
{
2013-08-21 21:22:13 +00:00
_form_helper - > setLabelText ( ui - > label_painting_info , tr ( " Memory used by sculpted data: %1 " ) . arg ( getHumanMemory ( memused ) ) ) ;
2013-05-09 17:13:04 +00:00
}
else
{
2013-08-21 21:22:13 +00:00
_form_helper - > setLabelText ( ui - > label_painting_info , tr ( " No manual scuplting done " ) ) ;
2013-05-09 17:13:04 +00:00
}
2013-06-09 16:08:01 +00:00
ui - > widget_base_noise_preview - > setNoise ( _terrain - > _height_noise ) ;
2013-05-09 17:13:04 +00:00
}
void MainTerrainForm : : refreshFromFellowData ( )
{
2013-11-13 22:03:02 +00:00
double disp = texturesGetMaximalDisplacement ( Scenery : : getCurrent ( ) - > getTextures ( ) ) ;
2013-06-20 20:11:41 +00:00
if ( disp = = 0.0 )
{
ui - > label_info_textures - > setText ( tr ( " No displacement textures " ) ) ;
}
else
{
ui - > label_info_textures - > setText ( tr ( " Maximal displacement : %1% of total height " ) . arg ( 100.0 * disp / _terrain - > height , 0 , ' f ' , 1 ) ) ;
}
2013-05-09 17:13:04 +00:00
}
void MainTerrainForm : : updateLocalDataFromScenery ( )
{
2013-11-13 22:03:02 +00:00
Scenery : : getCurrent ( ) - > getTerrain ( _terrain ) ;
2013-05-09 17:13:04 +00:00
}
void MainTerrainForm : : commitLocalDataToScenery ( )
{
2013-11-13 22:03:02 +00:00
Scenery : : getCurrent ( ) - > setTerrain ( _terrain ) ;
2013-05-09 17:13:04 +00:00
}
2013-05-14 20:32:56 +00:00
void MainTerrainForm : : alterRenderer ( Renderer * renderer )
{
TerrainRendererClass . bind ( renderer , _terrain ) ;
}
2013-06-09 17:36:30 +00:00
void MainTerrainForm : : buttonBaseNoisePressed ( )
{
int erase ;
if ( terrainGetMemoryStats ( _terrain ) > 0 )
{
erase = QMessageBox : : question ( this , tr ( " Paysages 3D - Base noise edition " ) , tr ( " You have manual modifications on this terrain, regenerating base noise may produce weird results. " ) , tr ( " Keep my changes anyway " ) , tr ( " Erase my changes " ) ) ;
}
else
{
erase = 0 ;
}
if ( DialogBaseTerrainNoise : : editNoise ( this , _terrain - > _height_noise ) )
{
if ( erase )
{
terrainClearPainting ( _terrain - > height_map ) ;
}
}
}
2013-05-09 17:13:04 +00:00
void MainTerrainForm : : buttonPaintingPressed ( )
{
DialogTerrainPainting dialog ( this , _terrain ) ;
_form_helper - > openDialog ( & dialog ) ;
}
void MainTerrainForm : : buttonTexturesPressed ( )
{
2013-06-20 20:21:09 +00:00
// Switch to textures tab
_form_helper - > gotoMainTab ( 1 ) ;
2013-05-05 16:42:55 +00:00
}