1 /*
2 * sprite_keywait.c: ���ץ饤�ȥ����Ԥ�
3 *
4 * Copyright (C) 1997-1998 Masaki Chikama (Wren) <chikama@kasumi.ipl.mech.nagoya-u.ac.jp>
5 * 1998- <masaki-c@is.aist-nara.ac.jp>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22 /* $Id: sprite_keywait.c,v 1.2 2003/05/09 05:14:34 chikama Exp $ */
23
24 #include "config.h"
25
26 #include <stdio.h>
27 #include <glib.h>
28
29 #include "portab.h"
30 #include "system.h"
31 #include "counter.h"
32 #include "ags.h"
33 #include "nact.h"
34 #include "imput.h"
35 #include "ngraph.h"
36 #include "surface.h"
37 #include "sact.h"
38 #include "sprite.h"
39 #include "sactsound.h"
40
41
42 static void hidesprite(sprite_t *sp);
43 static boolean waitcond(int endtime);
44
45
46
47 // ���露��ä�
hidesprite(sprite_t * sp)48 static void hidesprite(sprite_t *sp) {
49 int i;
50
51 for (i = 255; i >= 0; i-=32) {
52 sp->blendrate = i;
53 sp_updateme(sp);
54 sp_update_clipped();
55 sys_keywait(10, FALSE);
56 }
57
58 sp_updateme(sp);
59 sp->show = FALSE;
60 sp_update_clipped();
61 }
62
63 /*
64 �����Ԥ���λ�ξ������å�
65 @param endtime: �����
66 @return: ��λ�ʤ� TRUE����³�ʤ� FALSE
67
68 ���ץ饤�Ȥ��ɥ�åפ��줿���γƼ������ޤ�
69 */
waitcond(int endtime)70 static boolean waitcond(int endtime) {
71 int curtime = get_high_counter(SYSTEMCOUNTER_MSEC);
72 if (curtime >= endtime) return TRUE;
73
74 if (sact.dropped) {
75 sact.draggedsp->u.get.dragging = FALSE;
76 if (sact.waitkey != -1) {
77 // drop�������ץ饤�Ȥ露��ä�
78 hidesprite(sact.draggedsp);
79 sact.sp_result_get = sact.draggedsp->no;
80 sact.sp_result_put = sact.waitkey;
81 sp_free(sact.draggedsp->no);
82 sact.draggedsp = NULL;
83 sact.dropped = FALSE;
84 return TRUE;
85 } else {
86 // PUT/SWPUT���ץ饤�Ȱʳ��ΤȤ����drop�������
87 sprite_t *sp = sact.draggedsp;
88 if (sact.draggedsp->type == SPRITE_GETA) {
89 // ��Ȥξ��ˤ�ä����᤹
90 spev_move_waitend(sp, sp->loc.x, sp->loc.y, 150);
91 } else {
92 // ���ξ���α�ޤ�
93 sp->loc = sp->cur;
94 }
95
96 // drop��������С��Ĥ餹
97 if (sact.draggedsp->numsound3) {
98 ssnd_play(sact.draggedsp->numsound3);
99 }
100 sact.draggedsp = NULL;
101 sact.dropped = FALSE;
102 }
103 }
104
105 // ����¾�������Ϥ�����н�λ
106 return sact.waitkey == -1 ? FALSE : TRUE;
107 }
108
109 /*
110 ���ץ饤�ȥ����Ԥ�
111 @param vOK: 0�ʤ�б�����å�
112 @param vRND: �����å����ץ饤�Ȥ��ֹ�
113 @param vD01: ���åȥ��ץ饤�Ȥ��ֹ�
114 @param vD02: �ץåȥ��ץ饤�Ȥ��ֹ�
115 @param vD03: �����ॢ���Ȥ������=1, ���ʤ����=0
116 @param wTime: �����ॢ���Ȼ��� (1/100sec)
117 */
sp_keywait(int * vOK,int * vRND,int * vD01,int * vD02,int * vD03,int timeout)118 int sp_keywait(int *vOK, int *vRND, int *vD01, int *vD02, int *vD03, int timeout) {
119 int curtime, endtime;
120
121 // �Ȥꤢ����������
122 sp_update_all(TRUE);
123
124 // depthmap �����
125 g_slist_foreach(sact.updatelist, sp_draw_dmap, NULL);
126
127 sact.waittype = KEYWAIT_SPRITE;
128 sact.waitkey = -1;
129 sact.sp_result_sw = 0;
130 sact.sp_result_get = 0;
131 sact.sp_result_put = 0;
132 sact.draggedsp = NULL;
133
134 {
135 // �Ȥꤢ���������ߤΥޥ������֤����äơ�switch sprite ��
136 // ���֤����Ƥ���
137 agsevent_t agse;
138 MyPoint p;
139 sys_getMouseInfo(&p, FALSE);
140 agse.type = AGSEVENT_MOUSE_MOTION;
141 agse.d1 = p.x;
142 agse.d2 = p.y;
143 agse.d3 = 0;
144 nact->ags.eventcb(&agse);
145 }
146
147 // ��λ���֤η�
148 curtime = get_high_counter(SYSTEMCOUNTER_MSEC);
149 endtime = timeout < 0 ? G_MAXINT: (curtime + timeout * 10);
150
151 // ���ץ饤�ȥ����Ԥ��ᥤ��
152 while (!waitcond(endtime)) {
153 sys_keywait(25, TRUE);
154 }
155
156 if (sact.waitkey == 0) {
157 // �����������
158 *vOK = 0;
159 if (vD03) *vD03 = 0;
160 } else if (sact.waitkey == -1) {
161 // timeout
162 *vOK = 1;
163 if (vD03) *vD03 = 1;
164 } else {
165 *vOK = 1;
166 if (vD03) *vD03 = 0;
167 }
168
169 *vRND = sact.sp_result_sw;
170 *vD01 = sact.sp_result_get;
171 *vD02 = sact.sp_result_put;
172
173 sact.waittype = KEYWAIT_NONE;
174
175 return OK;
176 }
177
178
179