3b642f53e2aa8df8c132dec823717e04168c8d06
4 procedure OpenFurnaceWindow(furid
:integer);
5 procedure OpenFastCraftWindow(mode
:integer);
6 procedure OpenChestWindow(n
:integer;);
7 procedure OpenCreativeWindow
;
8 procedure OpenPlayerInventory
;
10 function WindowKeyHanler
:boolean;
13 uses vars
, CellUI
, console
, Canvas
, items
, utils
, craft
, furnace
, func
, items_store
, player
, keyboard
;
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;
33 WINDOW_INFO_DIV_ITEM
=0;
34 WINDOW_INFO_DIV_SUM1
=1;
35 WINDOW_INFO_DIV_SUM2
=2;
37 WINDOW_INFO_FC_MODE
=0;
41 DivWindowImg
, DivScrollImg
:image
;
42 CrWindowImg
, CrScrollImg
:image
;
44 fcWindowImg
, fcScrollImg
, fcCanCraftImg
:image
;
45 furWindowImg
, furFireImg
, furProgressImg
:image
;
47 function calcScrollBar(scrollSize
, buttonSize
, maxEl
, currentEl
:integer):integer;
51 if (currentEl
=0) or (maxEl
=0) then
54 if (currentEl
<>maxEl
) then
55 calcScrollBar
:=DivAccuracy
*(scrollSize
-buttonSize
)/maxEl
*currentEl
/DivAccuracy
;
57 calcScrollBar
:=scrollSize
-buttonSize
;
60 procedure OpenFurnaceWindow(furid
:integer);
65 SetWindowType(WINDOW_FURNACE
);
66 SetCurActive(true, CUR_SELECT1
);
68 SetWindowInfo(furid
, WINDOW_INFO_FUR_ID
);
70 if FindCurrentWindowsType
=false then
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);
80 initCell(CELL_TYPE_PLAYER_INV
, id
, 0, -1, 8+j
*18, 8+i
*18, true);
87 initCell(CELL_TYPE_PLAYER_INV
, id
, 0, -1, 8+j
*18, 8+i
*18+4, true);
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);
96 procedure DrawFurnaceWindow(x
, y
:integer);
98 furid
, i
, time
:integer;
100 furid
:=GetWindowInfo(WINDOW_INFO_FUR_ID
);
102 DrawImage(furWindowImg
, x
, y
);
104 time
:=furnace
.getTime
;
105 if furnaceBurn(furid
) then
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
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);
120 SetClip(0, 0, getWidth
, getHeight
);
125 procedure CloseFurnaceWindow
;
129 if FindCurrentWindowsType
=false then
131 furWindowImg
:=nullimg
;
133 furProgressImg
:=nullimg
;
138 procedure OpenFastCraftWindow(mode
:integer);
143 SetWindowType(WINDOW_FASTCRAFT
);
144 SetCurActive(true, CUR_SELECT1
);
146 SetWindowInfo(mode
, WINDOW_INFO_FC_MODE
);
148 if FindCurrentWindowsType
=false then
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);
159 initCell(CELL_TYPE_FASTCRAFT
, id
, 0, -1, 8+j
*18, 66+i
*18, false);
164 procedure DrawFastCraftWindow(x
, y
:integer);
166 mode
, craftid
:integer;
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);
179 drawItem(getCraftInItem(craftid
, id
), getCraftInSum(craftid
, id
), x
+52+j
*18, y
+17+i
*18, true);
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
);
189 procedure CloseFastCraftWindow
;
193 if FindCurrentWindowsType
=false then
195 fcWindowImg
:=nullimg
;
196 fcScrollImg
:=nullimg
;
197 fcCanCraftImg
:=nullimg
;
202 procedure FindFastCraftUD(n
:integer;);
204 old_cur
, offset
:integer;
206 old_cur
:=GetCurIndex(GetCur
);
207 offset
:=getOffset(0);
210 ShiftCurrentCur(FIND_CELL_UP
);
212 ShiftCurrentCur(FIND_CELL_DOWN
);
214 if old_cur
=GetCurIndex(GetCur
) then
226 if offset
>MAX_FASTCRAFT_OFFSET
then
227 offset
:=MAX_FASTCRAFT_OFFSET
;
231 SetOffset(offset
, 0);
234 procedure OpenChestWindow(n
:integer;);
239 SetWindowType(WINDOW_CHEST_INV
);
240 SetCurActive(true, CUR_SELECT1
);
242 if FindCurrentWindowsType
=false then
244 ChestWindowImg
:=ld_tex('container.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','gui/');
249 initCell(CELL_TYPE_PLAYER_INV
, id
, 0, -1, 8+j
*18, 8+i
*18, true);
256 initCell(CELL_TYPE_PLAYER_INV
, id
, 0, -1, 8+j
*18, 8+i
*18+4, true);
264 initCell(CELL_TYPE_CHEST
, id
, 0, n
, 8+j
*18, 88+i
*18, true);
269 procedure CloseChestWindow
;
273 if FindCurrentWindowsType
=false then
275 ChestWindowImg
:=nullimg
;
280 procedure OpenCreativeWindow
;
285 SetWindowType(WINDOW_CEATIVE_INV
);
286 SetCurActive(true, CUR_SELECT1
);
288 if FindCurrentWindowsType
=false then
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);
297 initCell(CELL_TYPE_PLAYER_INV
, id
, 0, -1, 8+j
*18, 8+i
*18, true);
305 initCell(CELL_TYPE_CREWATIVE_INV
, id
, 1, -1, 8+j
*18, 30+i
*18, false);
310 procedure DrawCreativeWindow(x
, y
:integer;);
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
);
320 procedure FindCeativeUD(n
:integer;);
322 old_cur
, offset
:integer;
324 old_cur
:=GetCurIndex(GetCur
);
325 offset
:=getOffset(1);
328 ShiftCurrentCur(FIND_CELL_UP
);
330 ShiftCurrentCur(FIND_CELL_DOWN
);
332 if old_cur
=GetCurIndex(GetCur
) then
344 if offset
>MAX_CREATIVE_OFFSET
then
345 offset
:=MAX_CREATIVE_OFFSET
;
349 SetOffset(offset
, 1);
352 procedure CloseCreativeWindow
;
356 if FindCurrentWindowsType
=false then
358 CrWindowImg
:=nullimg
;
359 CrScrollImg
:=nullimg
;
364 procedure OpenDivWindow
;
368 debug('Open Div Window');
369 item
:=getItem(GetCurIndex(GetCur
));
370 sum
:=getSum(GetCurIndex(GetCur
));
373 SetWindowType(WINDOW_DIV_ITEMS
);
375 if FindCurrentWindowsType
=false then
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);
382 SetWindowInfo(item
, WINDOW_INFO_DIV_ITEM
);
383 SetWindowInfo(sum
, WINDOW_INFO_DIV_SUM1
);
386 procedure DivScroll(pp
:integer);
390 sum1
:=GetWindowInfo(WINDOW_INFO_DIV_SUM1
);
391 sum2
:=GetWindowInfo(WINDOW_INFO_DIV_SUM2
);
399 SetWindowInfo(sum2
, WINDOW_INFO_DIV_SUM2
);
402 procedure DrawDivWindow(x
, y
:integer);
404 i
, item
, sum1
, sum2
:integer;
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);
420 procedure CloseDivWindow(return_val
:boolean);
425 debug('Close Div Window');
426 res
:=GetWindowInfo(WINDOW_INFO_DIV_SUM2
);
427 //Если таких окон нет, то чистим память
428 if FindCurrentWindowsType
=false then
430 DivWindowImg
:=nullimg
;
431 DivScrollImg
:=nullimg
;
434 SetWindowInfo(res
, WINDOW_INFO_DIVRES
);
439 SetCurActive(true, CUR_SELECT2
);
440 SetCurIndex(GetCurIndex(CUR_SELECT1
), CUR_SELECT2
);
441 SetWindowInfo(INV_MODE_SELECT2_DIV
, WINDOW_INFO_INVMODE
);
445 procedure OpenPlayerInventory
;
450 SetWindowType(WINDOW_PLAYER_INV
);
451 SetCurActive(true, CUR_SELECT1
);
453 //Если таких окон нет, то загружаем графику
454 if FindCurrentWindowsType
=false then
456 InvWindowImg
:=ld_tex('inventory.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','gui/');
461 initCell(CELL_TYPE_PLAYER_INV
, id
, 0, -1, 8+j
*18, 8+i
*18, true);
468 initCell(CELL_TYPE_PLAYER_INV
, id
, 0, -1, 8+j
*18, 8+i
*18+4, true);
473 procedure ClosePlayerInventory
;
477 debug('Close Player Inventory');
478 //Если таких окон нет, то чистим память
479 if FindCurrentWindowsType
=false then
481 InvWindowImg
:=nullimg
;
486 procedure DrawWindows
;
489 i
, wtype
, x
, y
:integer;
495 wtype
:=GetWindowType
;
496 if wtype
=WINDOW_PLAYER_INV
then
498 x
:=getWidth
/2-getImageWidth(InvWindowImg
)/2;
499 y
:=getHeight
/2-getImageHeight(InvWindowImg
)/2;
500 DrawImage(InvWindowImg
, x
, y
);
503 if wtype
=WINDOW_DIV_ITEMS
then
505 x
:=getWidth
/2-getImageWidth(DivWindowImg
)/2;
506 y
:=getHeight
/2-getImageHeight(DivWindowImg
)/2;
510 if wtype
=WINDOW_CEATIVE_INV
then
512 x
:=getWidth
/2-getImageWidth(CrWindowImg
)/2;
513 y
:=getHeight
/2-getImageHeight(CrWindowImg
)/2;
514 DrawCreativeWindow(x
, y
);
517 if wtype
=WINDOW_CHEST_INV
then
519 x
:=getWidth
/2-getImageWidth(ChestWindowImg
)/2;
520 y
:=getHeight
/2-getImageHeight(ChestWindowImg
)/2;
521 DrawImage(ChestWindowImg
, x
, y
);
524 if wtype
=WINDOW_FASTCRAFT
then
526 x
:=getWidth
/2-getImageWidth(fcWindowImg
)/2;
527 y
:=getHeight
/2-getImageHeight(fcWindowImg
)/2;
528 DrawFastCraftWindow(x
, y
);
531 if wtype
=WINDOW_FURNACE
then
533 x
:=getWidth
/2-getImageWidth(furWindowImg
)/2;
534 y
:=getHeight
/2-getImageHeight(furWindowImg
)/2;
535 DrawFurnaceWindow(x
, y
);
537 DrawCellLayer(i
, x
, y
);
538 DrawCursors(i
, x
, y
);
542 procedure OpSwapItems(Idx1
, Idx2
:integer);
544 tmp_item
, tmp_sum
:integer;
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
);
556 function OpAddItems(Idx1
, Idx2
:integer):boolean;
558 tmp_item1
, tmp_sum1
:integer;
559 tmp_item2
, tmp_sum2
:integer;
562 tmp_item1
:=GetItem(Idx1
);
563 tmp_sum1
:=GetSum(Idx1
);
564 tmp_item2
:=GetItem(Idx2
);
565 tmp_sum2
:=GetSum(Idx2
);
568 if (tmp_item1
=tmp_item2
) and (Idx1
<>Idx2
) then
569 if tmp_sum2
<getItemMax(tmp_item2
) then
571 tmp_sum2
:=tmp_sum2
+tmp_sum1
;
574 if tmp_sum2
>getItemMax(tmp_item2
) then
576 tmp_sum1
:=tmp_sum2
-getItemMax(tmp_item2
);
577 tmp_sum2
:=tmp_sum2
-tmp_sum1
;
586 SetItem(tmp_item1
, Idx1
);
587 SetSum(tmp_sum1
, Idx1
);
588 SetItem(tmp_item2
, Idx2
);
589 SetSum(tmp_sum2
, Idx2
);
593 procedure SetActiveCursor(n
:integer;);
597 if n
=CUR_SELECT1
then
603 SetCurActive(true, n
);
604 SetCurIndex(GetCurIndex(n2
), n
);
607 procedure decItem(curidx
:integer);
609 SetSum(GetSum(curidx
)-1, curidx
);
613 procedure HandlerSelect2Div
;
617 idx1
:=GetCurIndex(CUR_SELECT1
);
618 idx2
:=GetCurIndex(CUR_SELECT2
);
620 if GetItem(idx2
)=0 then
622 SetItem(GetItem(idx1
), idx2
);
623 SetSum(GetWindowInfo(WINDOW_INFO_DIVRES
), idx2
);
625 SetSum(GetSum(idx1
)-GetSum(idx2
), idx1
);
634 mode
:=GetWindowInfo(WINDOW_INFO_INVMODE
);
636 //Нажали кнопку - выбрали первый элемент
637 if mode
=INV_MODE_SELECT1
then
639 //Активируем второй курсор и ставим его над первым курсором
640 SetActiveCursor(CUR_SELECT2
);
641 SetWindowInfo(INV_MODE_SELECT2
, WINDOW_INFO_INVMODE
);
644 //Нажали кнопку - выбрали второй элемент, произвели сложение и переходим к режиму выбора первого элемента.
645 if mode
=INV_MODE_SELECT2
then
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
);
656 if mode
=INV_MODE_SELECT2_DIV
then
659 SetActiveCursor(CUR_SELECT1
);
660 SetCurActive(false, CUR_SELECT2
);
661 SetWindowInfo(INV_MODE_SELECT1
, WINDOW_INFO_INVMODE
);
665 function CanDivItem
:boolean;
667 if getItemDiv(getItem(GetCurIndex(GetCur
))) then
668 if (GetCur
=CUR_SELECT1
) and (getSum(GetCurIndex(GetCur
))>0) then
672 procedure StdCellKeyHandler
;
674 if clickedKey(KEY_WIN_SELECT
) then
675 SetTimer(1000, T_KEY_DIVITEM
);
677 if pressedKey(KEY_WIN_SELECT
) then
679 if GetTimer(T_KEY_DIVITEM
)=TIMER_OK
then
683 ResetTimer(T_KEY_DIVITEM
);
688 if GetTimer(T_KEY_DIVITEM
)>TIMER_OK
then
691 ResetTimer(T_KEY_DIVITEM
);
698 item
, curidx
:integer;
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
708 if GetTimer(T_KEY_DROPITEM
)=TIMER_OK
then
710 player
.dropItem(item
, GetSum(curidx
));
713 ResetTimer(T_KEY_DROPITEM
);
718 if GetTimer(T_KEY_DROPITEM
)>TIMER_OK
then
720 if getItemDiv(item
) then
722 player
.dropItem(item
, 1);
725 ResetTimer(T_KEY_DROPITEM
);
730 function WindowKeyHanler
:boolean;
733 craftid
, mode
:integer;
735 WinType
:=GetWindowType
;
736 if WinType
=WINDOW_PLAYER_INV
then
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
);
750 if clickedKey(KEY_WIN_EXIT
) then
751 ClosePlayerInventory
;
753 if clickedKey(KEY_WIN_ALT
) then
755 ClosePlayerInventory
;
756 OpenFastCraftWindow(0);
760 if WinType
=WINDOW_DIV_ITEMS
then
762 if clickedKey(KEY_WIN_LEFT
) then
764 if clickedKey(KEY_WIN_RIGHT
) then
767 if clickedKey(KEY_WIN_SELECT
) then
768 CloseDivWindow(true);
770 if clickedKey(KEY_WIN_EXIT
) then
771 CloseDivWindow(false);
774 if WinType
=WINDOW_CEATIVE_INV
then
776 if clickedKey(KEY_WIN_UP
) then
778 if clickedKey(KEY_WIN_DOWN
) then
780 if clickedKey(KEY_WIN_LEFT
) then
781 ShiftCurrentCur(FIND_CELL_LEFT
);
782 if clickedKey(KEY_WIN_RIGHT
) then
783 ShiftCurrentCur(FIND_CELL_RIGHT
);
788 if clickedKey(KEY_WIN_EXIT
) then
792 if WinType
=WINDOW_CHEST_INV
then
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
);
806 if clickedKey(KEY_WIN_EXIT
) then
810 if WinType
=WINDOW_FASTCRAFT
then
812 if clickedKey(KEY_WIN_UP
) then
814 if clickedKey(KEY_WIN_DOWN
) then
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
823 mode
:=GetWindowInfo(WINDOW_INFO_FC_MODE
);
824 craftid
:=getCellID(GetCurIndex(GetCur
))+GetOffset(0);
825 createCraft(craftid
, mode
);
828 if clickedKey(KEY_WIN_ALT
) then
834 if clickedKey(KEY_WIN_EXIT
) then
838 if WinType
=WINDOW_FURNACE
then
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
);
852 if clickedKey(KEY_WIN_EXIT
) then
856 WindowKeyHanler
:=true;