1 // Object Viewer Qt GUI Editor plugin <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "nelgui_ctrl.h"
22 #include "nel/misc/path.h"
23 #include "nel/gui/view_renderer.h"
24 #include "nel/gui/interface_group.h"
25 #include "nel/gui/widget_manager.h"
26 #include "nel/gui/action_handler.h"
27 #include "nel/gui/lua_manager.h"
28 #include "nel/gui/event_listener.h"
29 #include "nel/misc/path.h"
30 #include "nel/misc/i18n.h"
33 #include <QTimerEvent>
34 #include "editor_selection_watcher.h"
36 #include "../core/Nel3DWidget/nel3d_widget.h"
40 std::set
< std::string
> hwCursors
;
42 NelGUICtrl::NelGUICtrl( QObject
*parent
) :
48 w
= new Nel3DWidget();
49 eventListener
= new NLGUI::CEventListener();
53 NelGUICtrl::~NelGUICtrl()
59 NLGUI::CViewRenderer::release();
60 NLMISC::CI18N::setNoResolution( false );
66 void NelGUICtrl::init()
68 NLMISC::CI18N::setNoResolution( true );
69 NLMISC::CPath::remapExtension( "dds", "tga", true );
70 NLMISC::CPath::remapExtension( "dds", "png", true );
71 NLMISC::CPath::remapExtension( "png", "tga", true );
74 w
->createTextContext( "Ryzom.ttf" );
76 NLGUI::CAHManager::setEditorMode( true );
77 NLGUI::CLuaManager::setEditorMode( true );
78 NLGUI::CInterfaceElement::setEditorMode( true );
80 NLGUI::CViewRenderer::setDriver( w
->getDriver() );
81 NLGUI::CViewRenderer::setTextContext( w
->getTextContext() );
82 NLGUI::CViewRenderer::hwCursors
= &hwCursors
;
83 NLGUI::CViewRenderer::getInstance()->init();
85 CWidgetManager::getInstance()->getParser()->setEditorMode( true );
87 watcher
= new CEditorSelectionWatcher();
90 bool NelGUICtrl::parse( SProjectFiles
&files
)
93 IParser
*parser
= CWidgetManager::getInstance()->getParser();
95 if( !loadMapFiles( files
.mapFiles
) )
98 if( !parser
->parseInterface( files
.guiFiles
, false ) )
101 CWidgetManager::getInstance()->updateAllLocalisedElements();
102 CWidgetManager::getInstance()->activateMasterGroup( files
.masterGroup
, true );
104 CInterfaceElement
*e
= CWidgetManager::getInstance()->getElementFromId( files
.activeGroup
);
106 e
->setActive( true );
113 bool NelGUICtrl::loadMapFiles( const std::vector
< std::string
> &v
)
115 std::vector
< std::string
>::const_iterator itr
;
116 for( itr
= v
.begin(); itr
!= v
.end(); ++itr
)
118 const std::string
&file
= *itr
;
119 std::string::size_type i
= file
.find_last_of( '.' );
120 std::string mapFile
= file
.substr( 0, i
);
121 mapFile
.append( ".txt" );
123 if( !CViewRenderer::getInstance()->loadTextures( file
, mapFile
, false ) )
125 CViewRenderer::getInstance()->reset();
133 bool NelGUICtrl::createNewGUI( const std::string
&project
, const std::string
&window
)
136 bool ok
= CWidgetManager::getInstance()->createNewGUI( project
, window
);
140 std::string mg
= std::string( "ui:" ) + project
;
141 std::string ag
= mg
+ ":" + window
;
143 CWidgetManager::getInstance()->updateAllLocalisedElements();
144 CWidgetManager::getInstance()->activateMasterGroup( mg
, true );
146 CInterfaceElement
*e
= CWidgetManager::getInstance()->getElementFromId( ag
);
148 e
->setActive( true );
155 void NelGUICtrl::reset()
159 killTimer( timerID
);
161 CWidgetManager::getInstance()->unregisterSelectionWatcher( watcher
);
162 CWidgetManager::getInstance()->reset();
163 CWidgetManager::getInstance()->getParser()->removeAll();
164 CViewRenderer::getInstance()->reset();
168 void NelGUICtrl::draw()
170 w
->getDriver()->clearBuffers( NLMISC::CRGBA::Black
);
171 CWidgetManager::getInstance()->checkCoords();
172 CWidgetManager::getInstance()->drawViews( 0 );
173 w
->getDriver()->swapBuffers();
176 void NelGUICtrl::timerEvent( QTimerEvent
*evnt
)
178 if( evnt
->timerId() == timerID
)
182 w
->getDriver()->EventServer
.pump();
192 void NelGUICtrl::onGUILoaded()
194 timerID
= startTimer( 25 );
196 Q_EMIT
guiLoadComplete();
198 CWidgetManager::getInstance()->registerSelectionWatcher( watcher
);
201 void NelGUICtrl::show()
204 timerID
= startTimer( 200 );
208 eventListener
->addToServer( &w
->getDriver()->EventServer
);
213 void NelGUICtrl::hide()
217 killTimer( timerID
);
223 eventListener
->removeFromServer();
228 void NelGUICtrl::setWorkDir( const QString
&dir
)
230 IParser
*parser
= CWidgetManager::getInstance()->getParser();
231 parser
->setWorkDir( std::string( dir
.toUtf8().constData() ) );
234 QWidget
* NelGUICtrl::getViewPort()