1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
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 General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "ngi/ngi.h"
24 
25 #include "ngi/constants.h"
26 
27 #include "ngi/gameloader.h"
28 #include "ngi/motion.h"
29 #include "ngi/scenes.h"
30 #include "ngi/statics.h"
31 #include "ngi/input.h"
32 
33 #include "ngi/interaction.h"
34 
35 namespace NGI {
36 
sceneDbgMenu_initScene(Scene * sc)37 void sceneDbgMenu_initScene(Scene *sc) {
38 	g_vars->selector = sc->getPictureObjectById(PIC_SCD_SEL, 0);
39 	getGameLoaderInteractionController()->disableFlag24();
40 	setInputDisabled(0);
41 }
42 
sceneHandlerDbgMenu_getObjectAtXY(int x,int y)43 GameObject *sceneHandlerDbgMenu_getObjectAtXY(int x, int y) {
44 	if (!g_nmi->_currentScene)
45 		return 0;
46 
47 	for (uint i = 1; i < g_nmi->_currentScene->_picObjList.size(); i++) {
48 		PictureObject *pic = g_nmi->_currentScene->_picObjList[i];
49 
50 		if (x >= pic->_ox && y >= pic->_oy) {
51 			const Dims dims = pic->getDimensions();
52 			if (x <= pic->_ox + dims.x && y <= pic->_oy + dims.y && pic != g_vars->selector)
53 				return pic;
54 		}
55 	}
56 
57 	return 0;
58 }
59 
sceneHandlerDbgMenu(ExCommand * ex)60 int sceneHandlerDbgMenu(ExCommand *ex) {
61 	if (ex->_messageKind != 17)
62 		return 0;
63 
64 	int mx = g_nmi->_mouseScreenPos.x + g_nmi->_sceneRect.left;
65 	int my = g_nmi->_mouseScreenPos.y + g_nmi->_sceneRect.top;
66 
67 	if (ex->_messageNum == 29) {
68 		GameObject *obj = sceneHandlerDbgMenu_getObjectAtXY(mx, my);
69 		if (obj && canInteractAny(0, obj, -3) ) {
70 			getGameLoaderInteractionController()->enableFlag24();
71 			handleObjectInteraction(0, obj, 0);
72 		}
73 		return 0;
74 	}
75 	if (ex->_messageNum != 33) {
76 		if (ex->_messageNum == MSG_RESTARTGAME) {
77 			g_nmi->_needRestart = true;
78 			return 0;
79 		}
80 		return 0;
81 	}
82 
83 	g_nmi->_cursorId = PIC_CSR_DEFAULT;
84 	GameObject *obj = g_nmi->_currentScene->getStaticANIObjectAtPos(mx, my);
85 	if (obj) {
86 		if (canInteractAny(0, obj, -3)) {
87 			g_nmi->_cursorId = PIC_CSR_DEFAULT;
88 			g_nmi->setCursor(PIC_CSR_DEFAULT);
89 			return 0;
90 		}
91 	} else {
92 		obj = sceneHandlerDbgMenu_getObjectAtXY(mx, my);
93 		if (obj && canInteractAny(0, obj, -3) ) {
94 			g_vars->selector->_flags |= 4;
95 			g_vars->selector->setOXY(obj->_ox, obj->_oy);
96 			g_nmi->_cursorId = PIC_CSR_DEFAULT;
97 			g_nmi->setCursor(PIC_CSR_DEFAULT);
98 			return 0;
99 		}
100 		g_vars->selector->_flags &= 0xFFFB;
101 	}
102 	g_nmi->setCursor(g_nmi->_cursorId);
103 
104 	return 0;
105 }
106 
107 } // End of namespace NGI
108