DEADSOFTWARE

3b642f53e2aa8df8c132dec823717e04168c8d06
[cavecraft.git] / src / invui.mpsrc
1 unit invui;
3 interface
4 procedure OpenFurnaceWindow(furid:integer);
5 procedure OpenFastCraftWindow(mode:integer);
6 procedure OpenChestWindow(n:integer;);
7 procedure OpenCreativeWindow;
8 procedure OpenPlayerInventory;
9 procedure DrawWindows;
10 function WindowKeyHanler:boolean;
12 implementation
13 uses vars, CellUI, console, Canvas, items, utils, craft, furnace, func, items_store, player, keyboard;
14 const
15 WINDOW_PLAYER_INV=1;
16 WINDOW_DIV_ITEMS=2;
17 WINDOW_CEATIVE_INV=3;
18 WINDOW_CHEST_INV=4;
19 WINDOW_FASTCRAFT=5;
20 WINDOW_FURNACE=6;
22 INV_MODE_SELECT1=0;
23 INV_MODE_SELECT2=1;
24 INV_MODE_SELECT2_DIV=2;
26 MAX_CREATIVE_OFFSET=248;//32*8-8
27 MAX_FASTCRAFT_OFFSET=232;//24*10-8
29 WINDOW_INFO_INVMODE=0;
30 WINDOW_INFO_DIVRES=1;
31 WINDOW_INFO_FUR_ID=2;
33 WINDOW_INFO_DIV_ITEM=0;
34 WINDOW_INFO_DIV_SUM1=1;
35 WINDOW_INFO_DIV_SUM2=2;
37 WINDOW_INFO_FC_MODE=0;
39 var
40 InvWindowImg:image;
41 DivWindowImg, DivScrollImg:image;
42 CrWindowImg, CrScrollImg:image;
43 ChestWindowImg:image;
44 fcWindowImg, fcScrollImg, fcCanCraftImg:image;
45 furWindowImg, furFireImg, furProgressImg:image;
47 function calcScrollBar(scrollSize, buttonSize, maxEl, currentEl:integer):integer;
48 const
49 DivAccuracy=100000;
50 begin
51 if (currentEl=0) or (maxEl=0) then
52 calcScrollBar:=0;
53 else
54 if (currentEl<>maxEl) then
55 calcScrollBar:=DivAccuracy*(scrollSize-buttonSize)/maxEl*currentEl/DivAccuracy;
56 else
57 calcScrollBar:=scrollSize-buttonSize;
58 end;
60 procedure OpenFurnaceWindow(furid:integer);
61 var
62 i, j, id:integer;
63 begin
64 NewLayer;
65 SetWindowType(WINDOW_FURNACE);
66 SetCurActive(true, CUR_SELECT1);
68 SetWindowInfo(furid, WINDOW_INFO_FUR_ID);
70 if FindCurrentWindowsType=false then
71 begin
72 furWindowImg:=ld_tex('furnace.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','gui/');
73 furFireImg:=rotate_image_from_image(furWindowImg, 0, 166, 14, 14, 0);
74 furProgressImg:=rotate_image_from_image(furWindowImg, 14, 166, 24, 17, 0);
75 furWindowImg:=rotate_image_from_image(furWindowImg, 0, 0, 176, 166, 0);
76 end;
78 for j:=0 to 8 do
79 begin
80 initCell(CELL_TYPE_PLAYER_INV, id, 0, -1, 8+j*18, 8+i*18, true);
81 id:=id+1;
82 end;
84 for i:=1 to 3 do
85 for j:=0 to 8 do
86 begin
87 initCell(CELL_TYPE_PLAYER_INV, id, 0, -1, 8+j*18, 8+i*18+4, true);
88 id:=id+1;
89 end;
91 initCell(CELL_TYPE_FURNACE, FURNACE_IN, 0, furid, 56, 97, true);
92 initCell(CELL_TYPE_FURNACE, FURNACE_FUEL, 0, furid, 56, 133, true);
93 initCell(CELL_TYPE_FURNACE, FURNACE_OUT, 0, furid, 116, 115, true);
94 end;
96 procedure DrawFurnaceWindow(x, y:integer);
97 var
98 furid, i, time:integer;
99 begin
100 furid:=GetWindowInfo(WINDOW_INFO_FUR_ID);
102 DrawImage(furWindowImg, x, y);
104 time:=furnace.getTime;
105 if furnaceBurn(furid) then
106 begin
107 i:=calcScrollBar(14, 0, furnace.FuelTime(furid), furnace.endFuelTime(furid)-time);
108 debug('i: '+i+'; time: '+time+'; fueltime:'+furnace.FuelTime(furid)+'; c: '+(furnace.endFuelTime(furid)-time));
109 SetClip(x+56, y+130-i, 18, i);
110 DrawImage(furFireImg, x+56, y+116);
112 if itemBurn(furid) then
113 begin
114 i:=calcScrollBar(24, 0, furnace.ProgTime(furid), furnace.endProgTime(furid)-time);
116 SetClip(x+79, y+114, 24-i, 17);
117 DrawImage(furProgressImg, x+79, y+114);
118 end;
120 SetClip(0, 0, getWidth, getHeight);
121 end;
123 end;
125 procedure CloseFurnaceWindow;
126 var
127 nullimg:image;
128 begin
129 if FindCurrentWindowsType=false then
130 begin
131 furWindowImg:=nullimg;
132 furFireImg:=nullimg;
133 furProgressImg:=nullimg;
134 end;
135 DelLayer;
136 end;
138 procedure OpenFastCraftWindow(mode:integer);
139 var
140 i, j, id:integer;
141 begin
142 NewLayer;
143 SetWindowType(WINDOW_FASTCRAFT);
144 SetCurActive(true, CUR_SELECT1);
146 SetWindowInfo(mode, WINDOW_INFO_FC_MODE);
148 if FindCurrentWindowsType=false then
149 begin
150 fcWindowImg:=ld_tex('fastcraft.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','gui/');
151 fcScrollImg:=rotate_image_from_image(fcWindowImg, 0, 126, 12, 15, 0);
152 fcCanCraftImg:=rotate_image_from_image(fcWindowImg, 12, 126, 20, 18, 0);
153 fcWindowImg:=rotate_image_from_image(fcWindowImg, 0, 0, 176, 126, 0);
154 end;
156 for i:=0 to 2 do
157 for j:=0 to 7 do
158 begin
159 initCell(CELL_TYPE_FASTCRAFT, id, 0, -1, 8+j*18, 66+i*18, false);
160 id:=id+1;
161 end;
162 end;
164 procedure DrawFastCraftWindow(x, y:integer);
165 var
166 mode, craftid:integer;
167 i, j, id:integer;
168 begin
169 mode:=GetWindowInfo(WINDOW_INFO_FC_MODE);
170 craftid:=getCellID(GetCurIndex(GetCur))+GetOffset(0);//FIX IT! Indexes
172 DrawImage(fcWindowImg, x, y);
173 if canCreateCraft(craftid, mode) then
174 DrawImage(fcCanCraftImg, x+87, y+26);
176 for i:=0 to 1 do
177 for j:=0 to 1 do
178 begin
179 drawItem(getCraftInItem(craftid, id), getCraftInSum(craftid, id), x+52+j*18, y+17+i*18, true);
180 id:=id+1;
181 end;
183 drawItem(getCraftOutItem(craftid), getCraftOutSum(craftid), x+108, y+27, true);
185 i:=calcScrollBar(52, getImageHeight(fcScrollImg), MAX_FASTCRAFT_OFFSET, getOffset(0));
186 drawimage(fcScrollImg, x+156, y+66+i);
187 end;
189 procedure CloseFastCraftWindow;
190 var
191 nullimg:image;
192 begin
193 if FindCurrentWindowsType=false then
194 begin
195 fcWindowImg:=nullimg;
196 fcScrollImg:=nullimg;
197 fcCanCraftImg:=nullimg;
198 end;
199 DelLayer;
200 end;
202 procedure FindFastCraftUD(n:integer;);
203 var
204 old_cur, offset:integer;
205 begin
206 old_cur:=GetCurIndex(GetCur);
207 offset:=getOffset(0);
209 if n<0 then
210 ShiftCurrentCur(FIND_CELL_UP);
211 if n>0 then
212 ShiftCurrentCur(FIND_CELL_DOWN);
214 if old_cur=GetCurIndex(GetCur) then
215 begin
216 if n<0 then
217 begin
218 offset:=offset-8;
219 if offset<0 then
220 offset:=0;
221 end;
222 else
223 if n>0 then
224 begin
225 offset:=offset+8;
226 if offset>MAX_FASTCRAFT_OFFSET then
227 offset:=MAX_FASTCRAFT_OFFSET;
228 end;
229 end;
231 SetOffset(offset, 0);
232 end;
234 procedure OpenChestWindow(n:integer;);
235 var
236 i, j, id:integer;
237 begin
238 NewLayer;
239 SetWindowType(WINDOW_CHEST_INV);
240 SetCurActive(true, CUR_SELECT1);
242 if FindCurrentWindowsType=false then
243 begin
244 ChestWindowImg:=ld_tex('container.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','gui/');
245 end;
247 for j:=0 to 8 do
248 begin
249 initCell(CELL_TYPE_PLAYER_INV, id, 0, -1, 8+j*18, 8+i*18, true);
250 id:=id+1;
251 end;
253 for i:=1 to 3 do
254 for j:=0 to 8 do
255 begin
256 initCell(CELL_TYPE_PLAYER_INV, id, 0, -1, 8+j*18, 8+i*18+4, true);
257 id:=id+1;
258 end;
260 id:=0;
261 for i:=0 to 2 do
262 for j:=0 to 8 do
263 begin
264 initCell(CELL_TYPE_CHEST, id, 0, n, 8+j*18, 88+i*18, true);
265 id:=id+1;
266 end;
267 end;
269 procedure CloseChestWindow;
270 var
271 nullimg:image;
272 begin
273 if FindCurrentWindowsType=false then
274 begin
275 ChestWindowImg:=nullimg;
276 end;
277 DelLayer;
278 end;
280 procedure OpenCreativeWindow;
281 var
282 i, j, id:integer;
283 begin
284 NewLayer;
285 SetWindowType(WINDOW_CEATIVE_INV);
286 SetCurActive(true, CUR_SELECT1);
288 if FindCurrentWindowsType=false then
289 begin
290 CrWindowImg:=ld_tex('creative.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','gui/');
291 CrScrollImg:=rotate_image_from_image(CrWindowImg, 0, 108, 12, 15, 0);
292 CrWindowImg:=rotate_image_from_image(CrWindowImg, 0, 0, 176, 108, 0);
293 end;
295 for j:=0 to 8 do
296 begin
297 initCell(CELL_TYPE_PLAYER_INV, id, 0, -1, 8+j*18, 8+i*18, true);
298 id:=id+1;
299 end;
301 id:=0;
302 for i:=0 to 3 do
303 for j:=0 to 7 do
304 begin
305 initCell(CELL_TYPE_CREWATIVE_INV, id, 1, -1, 8+j*18, 30+i*18, false);
306 id:=id+1;
307 end;
308 end;
310 procedure DrawCreativeWindow(x, y:integer;);
311 var
312 scroll, i:integer;
313 begin
314 DrawImage(CrWindowImg, x, y);
315 scroll:=getOffset(1);
316 i:=calcScrollBar(70, getImageHeight(CrScrollImg), MAX_CREATIVE_OFFSET, scroll);
317 drawimage(CrScrollImg, x+156, y+30+i);
318 end;
320 procedure FindCeativeUD(n:integer;);
321 var
322 old_cur, offset:integer;
323 begin
324 old_cur:=GetCurIndex(GetCur);
325 offset:=getOffset(1);
327 if n<0 then
328 ShiftCurrentCur(FIND_CELL_UP);
329 if n>0 then
330 ShiftCurrentCur(FIND_CELL_DOWN);
332 if old_cur=GetCurIndex(GetCur) then
333 begin
334 if n<0 then
335 begin
336 offset:=offset-8;
337 if offset<0 then
338 offset:=0;
339 end;
340 else
341 if n>0 then
342 begin
343 offset:=offset+8;
344 if offset>MAX_CREATIVE_OFFSET then
345 offset:=MAX_CREATIVE_OFFSET;
346 end;
347 end;
349 SetOffset(offset, 1);
350 end;
352 procedure CloseCreativeWindow;
353 var
354 nullimg:image;
355 begin
356 if FindCurrentWindowsType=false then
357 begin
358 CrWindowImg:=nullimg;
359 CrScrollImg:=nullimg;
360 end;
361 DelLayer;
362 end;
364 procedure OpenDivWindow;
365 var
366 item, sum:integer;
367 begin
368 debug('Open Div Window');
369 item:=getItem(GetCurIndex(GetCur));
370 sum:=getSum(GetCurIndex(GetCur));
372 NewLayer;
373 SetWindowType(WINDOW_DIV_ITEMS);
375 if FindCurrentWindowsType=false then
376 begin
377 DivWindowImg:=ld_tex('partition.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','gui/');
378 DivScrollImg:=rotate_image_from_image(DivWindowImg, 0, 50, 15, 12, 0);
379 DivWindowImg:=rotate_image_from_image(DivWindowImg, 0, 0, 88, 50, 0);
380 end;
382 SetWindowInfo(item, WINDOW_INFO_DIV_ITEM);
383 SetWindowInfo(sum, WINDOW_INFO_DIV_SUM1);
384 end;
386 procedure DivScroll(pp:integer);
387 var
388 sum1, sum2:integer;
389 begin
390 sum1:=GetWindowInfo(WINDOW_INFO_DIV_SUM1);
391 sum2:=GetWindowInfo(WINDOW_INFO_DIV_SUM2);
393 sum2:=sum2+pp;
394 if sum2<0 then
395 sum2:=0;
396 if sum2>sum1 then
397 sum2:=sum1;
399 SetWindowInfo(sum2, WINDOW_INFO_DIV_SUM2);
400 end;
402 procedure DrawDivWindow(x, y:integer);
403 var
404 i, item, sum1, sum2:integer;
405 begin
406 DrawImage(DivWindowImg, x, y);
408 item:=GetWindowInfo(WINDOW_INFO_DIV_ITEM);
409 sum1:=GetWindowInfo(WINDOW_INFO_DIV_SUM1);
410 sum2:=GetWindowInfo(WINDOW_INFO_DIV_SUM2);
412 drawItem(item, (sum1-sum2), x+8, y+8, true);
413 drawItem(item, sum2, x+64, y+8, true);
415 i:=calcScrollBar(72, getImageWidth(DivScrollImg), sum1, sum2);
417 drawimage(DivScrollImg, x+8+i, y+30);
418 end;
420 procedure CloseDivWindow(return_val:boolean);
421 var
422 res:integer;
423 nullimg:image;
424 begin
425 debug('Close Div Window');
426 res:=GetWindowInfo(WINDOW_INFO_DIV_SUM2);
427 //Если таких окон нет, то чистим память
428 if FindCurrentWindowsType=false then
429 begin
430 DivWindowImg:=nullimg;
431 DivScrollImg:=nullimg;
432 end;
433 DelLayer;
434 SetWindowInfo(res, WINDOW_INFO_DIVRES);
436 if return_val then
437 begin
438 SetCur(CUR_SELECT2);
439 SetCurActive(true, CUR_SELECT2);
440 SetCurIndex(GetCurIndex(CUR_SELECT1), CUR_SELECT2);
441 SetWindowInfo(INV_MODE_SELECT2_DIV, WINDOW_INFO_INVMODE);
442 end;
443 end;
445 procedure OpenPlayerInventory;
446 var
447 i, j, id:integer;
448 begin
449 NewLayer;
450 SetWindowType(WINDOW_PLAYER_INV);
451 SetCurActive(true, CUR_SELECT1);
453 //Если таких окон нет, то загружаем графику
454 if FindCurrentWindowsType=false then
455 begin
456 InvWindowImg:=ld_tex('inventory.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','gui/');
457 end;
459 for j:=0 to 8 do
460 begin
461 initCell(CELL_TYPE_PLAYER_INV, id, 0, -1, 8+j*18, 8+i*18, true);
462 id:=id+1;
463 end;
465 for i:=1 to 3 do
466 for j:=0 to 8 do
467 begin
468 initCell(CELL_TYPE_PLAYER_INV, id, 0, -1, 8+j*18, 8+i*18+4, true);
469 id:=id+1;
470 end;
471 end;
473 procedure ClosePlayerInventory;
474 var
475 nullimg:image;
476 begin
477 debug('Close Player Inventory');
478 //Если таких окон нет, то чистим память
479 if FindCurrentWindowsType=false then
480 begin
481 InvWindowImg:=nullimg;
482 end;
483 DelLayer;
484 end;
486 procedure DrawWindows;
487 var
488 max:integer;
489 i, wtype, x, y:integer;
490 begin
491 max:=CellLayer;
492 for i:=0 to max do
493 begin
494 setCellLayer(i);
495 wtype:=GetWindowType;
496 if wtype=WINDOW_PLAYER_INV then
497 begin
498 x:=getWidth/2-getImageWidth(InvWindowImg)/2;
499 y:=getHeight/2-getImageHeight(InvWindowImg)/2;
500 DrawImage(InvWindowImg, x, y);
501 end;
502 else
503 if wtype=WINDOW_DIV_ITEMS then
504 begin
505 x:=getWidth/2-getImageWidth(DivWindowImg)/2;
506 y:=getHeight/2-getImageHeight(DivWindowImg)/2;
507 DrawDivWindow(x, y);
508 end;
509 else
510 if wtype=WINDOW_CEATIVE_INV then
511 begin
512 x:=getWidth/2-getImageWidth(CrWindowImg)/2;
513 y:=getHeight/2-getImageHeight(CrWindowImg)/2;
514 DrawCreativeWindow(x, y);
515 end;
516 else
517 if wtype=WINDOW_CHEST_INV then
518 begin
519 x:=getWidth/2-getImageWidth(ChestWindowImg)/2;
520 y:=getHeight/2-getImageHeight(ChestWindowImg)/2;
521 DrawImage(ChestWindowImg, x, y);
522 end;
523 else
524 if wtype=WINDOW_FASTCRAFT then
525 begin
526 x:=getWidth/2-getImageWidth(fcWindowImg)/2;
527 y:=getHeight/2-getImageHeight(fcWindowImg)/2;
528 DrawFastCraftWindow(x, y);
529 end;
530 else
531 if wtype=WINDOW_FURNACE then
532 begin
533 x:=getWidth/2-getImageWidth(furWindowImg)/2;
534 y:=getHeight/2-getImageHeight(furWindowImg)/2;
535 DrawFurnaceWindow(x, y);
536 end;
537 DrawCellLayer(i, x, y);
538 DrawCursors(i, x, y);
539 end;
540 end;
542 procedure OpSwapItems(Idx1, Idx2:integer);
543 var
544 tmp_item, tmp_sum:integer;
545 begin
546 tmp_item:=getItem(Idx1);
547 tmp_sum:=getSum(Idx1);
549 setItem(getItem(Idx2), Idx1);
550 setSum(getSum(Idx2), Idx1);
552 setItem(tmp_item, Idx2);
553 setSum(tmp_sum, Idx2);
554 end;
556 function OpAddItems(Idx1, Idx2:integer):boolean;
557 var
558 tmp_item1, tmp_sum1:integer;
559 tmp_item2, tmp_sum2:integer;
560 fresult:boolean;
561 begin
562 tmp_item1:=GetItem(Idx1);
563 tmp_sum1:=GetSum(Idx1);
564 tmp_item2:=GetItem(Idx2);
565 tmp_sum2:=GetSum(Idx2);
566 fresult:=true;
568 if (tmp_item1=tmp_item2) and (Idx1<>Idx2) then
569 if tmp_sum2<getItemMax(tmp_item2) then
570 begin
571 tmp_sum2:=tmp_sum2+tmp_sum1;
572 tmp_sum1:=0;
574 if tmp_sum2>getItemMax(tmp_item2) then
575 begin
576 tmp_sum1:=tmp_sum2-getItemMax(tmp_item2);
577 tmp_sum2:=tmp_sum2-tmp_sum1;
578 end;
580 if tmp_sum1<=0 then
581 tmp_item1:=0;
583 fresult:=false;
584 end;
586 SetItem(tmp_item1, Idx1);
587 SetSum(tmp_sum1, Idx1);
588 SetItem(tmp_item2, Idx2);
589 SetSum(tmp_sum2, Idx2);
590 OpAddItems:=fresult;
591 end;
593 procedure SetActiveCursor(n:integer;);
594 var
595 n2:integer;
596 begin
597 if n=CUR_SELECT1 then
598 n2:=CUR_SELECT2;
599 else
600 n2:=CUR_SELECT1;
602 SetCur(n);
603 SetCurActive(true, n);
604 SetCurIndex(GetCurIndex(n2), n);
605 end;
607 procedure decItem(curidx:integer);
608 begin
609 SetSum(GetSum(curidx)-1, curidx);
610 fixNullCell(curidx);
611 end;
613 procedure HandlerSelect2Div;
614 var
615 idx1, idx2:integer;
616 begin
617 idx1:=GetCurIndex(CUR_SELECT1);
618 idx2:=GetCurIndex(CUR_SELECT2);
620 if GetItem(idx2)=0 then
621 begin
622 SetItem(GetItem(idx1), idx2);
623 SetSum(GetWindowInfo(WINDOW_INFO_DIVRES), idx2);
625 SetSum(GetSum(idx1)-GetSum(idx2), idx1);
626 fixNullCell(idx1);
627 end;
628 end;
630 procedure Select;
631 var
632 mode:integer;
633 begin
634 mode:=GetWindowInfo(WINDOW_INFO_INVMODE);
636 //Нажали кнопку - выбрали первый элемент
637 if mode=INV_MODE_SELECT1 then
638 begin
639 //Активируем второй курсор и ставим его над первым курсором
640 SetActiveCursor(CUR_SELECT2);
641 SetWindowInfo(INV_MODE_SELECT2, WINDOW_INFO_INVMODE);
642 end;
643 else
644 //Нажали кнопку - выбрали второй элемент, произвели сложение и переходим к режиму выбора первого элемента.
645 if mode=INV_MODE_SELECT2 then
646 begin
647 //Складывваем предметы курсора 1 и курсора 2
648 if OpAddItems(GetCurIndex(CUR_SELECT1), GetCurIndex(CUR_SELECT2)) then
649 OpSwapItems(GetCurIndex(CUR_SELECT1), GetCurIndex(CUR_SELECT2));
650 //Передаём управление первому курсору
651 SetActiveCursor(CUR_SELECT1);
652 SetCurActive(false, CUR_SELECT2);
653 SetWindowInfo(INV_MODE_SELECT1, WINDOW_INFO_INVMODE);
654 end;
655 else
656 if mode=INV_MODE_SELECT2_DIV then
657 begin
658 HandlerSelect2Div;
659 SetActiveCursor(CUR_SELECT1);
660 SetCurActive(false, CUR_SELECT2);
661 SetWindowInfo(INV_MODE_SELECT1, WINDOW_INFO_INVMODE);
662 end;
663 end;
665 function CanDivItem:boolean;
666 begin
667 if getItemDiv(getItem(GetCurIndex(GetCur))) then
668 if (GetCur=CUR_SELECT1) and (getSum(GetCurIndex(GetCur))>0) then
669 CanDivItem:=true;
670 end;
672 procedure StdCellKeyHandler;
673 begin
674 if clickedKey(KEY_WIN_SELECT) then
675 SetTimer(1000, T_KEY_DIVITEM);
677 if pressedKey(KEY_WIN_SELECT) then
678 begin
679 if GetTimer(T_KEY_DIVITEM)=TIMER_OK then
680 begin
681 if CanDivItem then
682 OpenDivWindow;
683 ResetTimer(T_KEY_DIVITEM);
684 end;
685 end;
686 else
687 begin
688 if GetTimer(T_KEY_DIVITEM)>TIMER_OK then
689 begin
690 Select;
691 ResetTimer(T_KEY_DIVITEM);
692 end;
693 end;
694 end;
696 procedure keyDrop;
697 var
698 item, curidx:integer;
699 begin
700 curidx:=GetCurIndex(GetCur);
701 item:=getItem(curidx);
703 if clickedKey(KEY_WIN_DROP) then
704 SetTimer(1000, T_KEY_DROPITEM);
706 if pressedKey(KEY_WIN_DROP) then
707 begin
708 if GetTimer(T_KEY_DROPITEM)=TIMER_OK then
709 begin
710 player.dropItem(item, GetSum(curidx));
711 SetItem(0, curidx);
712 SetSum(0, curidx);
713 ResetTimer(T_KEY_DROPITEM);
714 end;
715 end;
716 else
717 begin
718 if GetTimer(T_KEY_DROPITEM)>TIMER_OK then
719 begin
720 if getItemDiv(item) then
721 begin
722 player.dropItem(item, 1);
723 decItem(curidx);
724 end;
725 ResetTimer(T_KEY_DROPITEM);
726 end;
727 end;
728 end;
730 function WindowKeyHanler:boolean;
731 var
732 WinType:integer;
733 craftid, mode:integer;
734 begin
735 WinType:=GetWindowType;
736 if WinType=WINDOW_PLAYER_INV then
737 begin
738 if clickedKey(KEY_WIN_UP) then
739 ShiftCurrentCur(FIND_CELL_UP);
740 if clickedKey(KEY_WIN_DOWN) then
741 ShiftCurrentCur(FIND_CELL_DOWN);
742 if clickedKey(KEY_WIN_LEFT) then
743 ShiftCurrentCur(FIND_CELL_LEFT);
744 if clickedKey(KEY_WIN_RIGHT) then
745 ShiftCurrentCur(FIND_CELL_RIGHT);
747 StdCellKeyHandler;
748 keyDrop;
750 if clickedKey(KEY_WIN_EXIT) then
751 ClosePlayerInventory;
753 if clickedKey(KEY_WIN_ALT) then
754 begin
755 ClosePlayerInventory;
756 OpenFastCraftWindow(0);
757 end;
758 end;
759 else
760 if WinType=WINDOW_DIV_ITEMS then
761 begin
762 if clickedKey(KEY_WIN_LEFT) then
763 DivScroll(-1);
764 if clickedKey(KEY_WIN_RIGHT) then
765 DivScroll(1);
767 if clickedKey(KEY_WIN_SELECT) then
768 CloseDivWindow(true);
770 if clickedKey(KEY_WIN_EXIT) then
771 CloseDivWindow(false);
772 end;
773 else
774 if WinType=WINDOW_CEATIVE_INV then
775 begin
776 if clickedKey(KEY_WIN_UP) then
777 FindCeativeUD(-1);
778 if clickedKey(KEY_WIN_DOWN) then
779 FindCeativeUD(1);
780 if clickedKey(KEY_WIN_LEFT) then
781 ShiftCurrentCur(FIND_CELL_LEFT);
782 if clickedKey(KEY_WIN_RIGHT) then
783 ShiftCurrentCur(FIND_CELL_RIGHT);
785 StdCellKeyHandler;
786 keyDrop;
788 if clickedKey(KEY_WIN_EXIT) then
789 CloseCreativeWindow;
790 end;
791 else
792 if WinType=WINDOW_CHEST_INV then
793 begin
794 if clickedKey(KEY_WIN_UP) then
795 ShiftCurrentCur(FIND_CELL_UP);
796 if clickedKey(KEY_WIN_DOWN) then
797 ShiftCurrentCur(FIND_CELL_DOWN);
798 if clickedKey(KEY_WIN_LEFT) then
799 ShiftCurrentCur(FIND_CELL_LEFT);
800 if clickedKey(KEY_WIN_RIGHT) then
801 ShiftCurrentCur(FIND_CELL_RIGHT);
803 StdCellKeyHandler;
804 keyDrop;
806 if clickedKey(KEY_WIN_EXIT) then
807 CloseChestWindow;
808 end;
809 else
810 if WinType=WINDOW_FASTCRAFT then
811 begin
812 if clickedKey(KEY_WIN_UP) then
813 FindFastCraftUD(-1);
814 if clickedKey(KEY_WIN_DOWN) then
815 FindFastCraftUD(1);
816 if clickedKey(KEY_WIN_LEFT) then
817 ShiftCurrentCur(FIND_CELL_LEFT);
818 if clickedKey(KEY_WIN_RIGHT) then
819 ShiftCurrentCur(FIND_CELL_RIGHT);
821 if clickedKey(KEY_WIN_SELECT) then
822 begin
823 mode:=GetWindowInfo(WINDOW_INFO_FC_MODE);
824 craftid:=getCellID(GetCurIndex(GetCur))+GetOffset(0);
825 createCraft(craftid, mode);
826 end;
828 if clickedKey(KEY_WIN_ALT) then
829 begin
830 CloseChestWindow;
831 OpenPlayerInventory;
832 end;
834 if clickedKey(KEY_WIN_EXIT) then
835 CloseChestWindow;
836 end;
837 else
838 if WinType=WINDOW_FURNACE then
839 begin
840 if clickedKey(KEY_WIN_UP) then
841 ShiftCurrentCur(FIND_CELL_UP);
842 if clickedKey(KEY_WIN_DOWN) then
843 ShiftCurrentCur(FIND_CELL_DOWN);
844 if clickedKey(KEY_WIN_LEFT) then
845 ShiftCurrentCur(FIND_CELL_LEFT);
846 if clickedKey(KEY_WIN_RIGHT) then
847 ShiftCurrentCur(FIND_CELL_RIGHT);
849 StdCellKeyHandler;
850 keyDrop;
852 if clickedKey(KEY_WIN_EXIT) then
853 CloseFurnaceWindow;
854 end;
855 else
856 WindowKeyHanler:=true;
857 end;
859 end.