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;
14 uses vars
, CellUI
, console
, Canvas
, utils
, craft
, furnace
, func
, items_store
, player
, keyboard
, Items
, ItemsLogic
;
26 INV_MODE_SELECT2_DIV
=2;
28 MAX_CREATIVE_OFFSET
=248;//32*8-8
29 MAX_FASTCRAFT_OFFSET
=232;//24*10-8
31 WINDOW_INFO_INVMODE
=0;
35 WINDOW_INFO_DIV_ITEM
=0;
36 WINDOW_INFO_DIV_SUM1
=1;
37 WINDOW_INFO_DIV_SUM2
=2;
39 WINDOW_INFO_FC_MODE
=0;
43 DivWindowImg
, DivScrollImg
:image
;
44 CrWindowImg
, CrScrollImg
:image
;
46 fcWindowImg
, fcScrollImg
, fcCanCraftImg
:image
;
47 furWindowImg
, furFireImg
, furProgressImg
:image
;
49 function calcScrollBar(scrollSize
, buttonSize
, maxEl
, currentEl
:integer):integer;
53 if (currentEl
=0) or (maxEl
=0) then
56 if (currentEl
<>maxEl
) then
57 calcScrollBar
:=DivAccuracy
*(scrollSize
-buttonSize
)/maxEl
*currentEl
/DivAccuracy
;
59 calcScrollBar
:=scrollSize
-buttonSize
;
62 procedure OpenFurnaceWindow(furid
:integer);
67 SetWindowType(WINDOW_FURNACE
);
68 SetCurActive(true, CUR_SELECT1
);
70 SetWindowInfo(furid
, WINDOW_INFO_FUR_ID
);
72 if FindCurrentWindowsType
=false then
74 furWindowImg
:=ld_tex('furnace.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','gui/');
75 furFireImg
:=rotate_image_from_image(furWindowImg
, 0, 166, 14, 14, 0);
76 furProgressImg
:=rotate_image_from_image(furWindowImg
, 14, 166, 24, 17, 0);
77 furWindowImg
:=rotate_image_from_image(furWindowImg
, 0, 0, 176, 166, 0);
82 initCell(CELL_TYPE_PLAYER_INV
, id
, 0, -1, 8+j
*18, 8+i
*18, true);
89 initCell(CELL_TYPE_PLAYER_INV
, id
, 0, -1, 8+j
*18, 8+i
*18+4, true);
93 initCell(CELL_TYPE_FURNACE
, FURNACE_IN
, 0, furid
, 56, 97, true);
94 initCell(CELL_TYPE_FURNACE
, FURNACE_FUEL
, 0, furid
, 56, 133, true);
95 initCell(CELL_TYPE_FURNACE
, FURNACE_OUT
, 0, furid
, 116, 115, true);
98 procedure DrawFurnaceWindow(x
, y
:integer);
100 furid
, i
, time
:integer;
102 furid
:=GetWindowInfo(WINDOW_INFO_FUR_ID
);
104 DrawImage(furWindowImg
, x
, y
);
106 time
:=furnace
.getTime
;
107 if furnaceBurn(furid
) then
109 i
:=calcScrollBar(14, 0, furnace
.FuelTime(furid
), furnace
.endFuelTime(furid
)-time
);
110 debug('i: '+i
+'; time: '+time
+'; fueltime:'+furnace
.FuelTime(furid
)+'; c: '+(furnace
.endFuelTime(furid
)-time
));
111 SetClip(x
+56, y
+130-i
, 18, i
);
112 DrawImage(furFireImg
, x
+56, y
+116);
114 if itemBurn(furid
) then
116 i
:=calcScrollBar(24, 0, furnace
.ProgTime(furid
), furnace
.endProgTime(furid
)-time
);
118 SetClip(x
+79, y
+114, 24-i
, 17);
119 DrawImage(furProgressImg
, x
+79, y
+114);
122 SetClip(0, 0, getWidth
, getHeight
);
127 procedure CloseFurnaceWindow
;
131 if FindCurrentWindowsType
=false then
133 furWindowImg
:=nullimg
;
135 furProgressImg
:=nullimg
;
140 procedure OpenFastCraftWindow(mode
:integer);
145 SetWindowType(WINDOW_FASTCRAFT
);
146 SetCurActive(true, CUR_SELECT1
);
148 SetWindowInfo(mode
, WINDOW_INFO_FC_MODE
);
150 if FindCurrentWindowsType
=false then
152 fcWindowImg
:=ld_tex('fastcraft.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','gui/');
153 fcScrollImg
:=rotate_image_from_image(fcWindowImg
, 0, 126, 12, 15, 0);
154 fcCanCraftImg
:=rotate_image_from_image(fcWindowImg
, 12, 126, 20, 18, 0);
155 fcWindowImg
:=rotate_image_from_image(fcWindowImg
, 0, 0, 176, 126, 0);
161 initCell(CELL_TYPE_FASTCRAFT
, id
, 0, -1, 8+j
*18, 66+i
*18, false);
166 procedure DrawFastCraftWindow(x
, y
:integer);
168 mode
, craftid
:integer;
171 mode
:=GetWindowInfo(WINDOW_INFO_FC_MODE
);
172 craftid
:=getCellID(GetCurIndex(GetCur
))+GetOffset(0);//FIX IT! Indexes
174 DrawImage(fcWindowImg
, x
, y
);
175 if canCreateCraft(craftid
, mode
) then
176 DrawImage(fcCanCraftImg
, x
+87, y
+26);
181 ItemsLogic
.Draw(getCraftInItem(craftid
, id
), getCraftInSum(craftid
, id
), x
+52+j
*18, y
+17+i
*18, true);
185 ItemsLogic
.Draw(getCraftOutItem(craftid
), getCraftOutSum(craftid
), x
+108, y
+27, true);
187 i
:=calcScrollBar(52, getImageHeight(fcScrollImg
), MAX_FASTCRAFT_OFFSET
, getOffset(0));
188 drawimage(fcScrollImg
, x
+156, y
+66+i
);
191 procedure CloseFastCraftWindow
;
195 if FindCurrentWindowsType
=false then
197 fcWindowImg
:=nullimg
;
198 fcScrollImg
:=nullimg
;
199 fcCanCraftImg
:=nullimg
;
204 procedure FindFastCraftUD(n
:integer;);
206 old_cur
, offset
:integer;
208 old_cur
:=GetCurIndex(GetCur
);
209 offset
:=getOffset(0);
212 ShiftCurrentCur(FIND_CELL_UP
);
214 ShiftCurrentCur(FIND_CELL_DOWN
);
216 if old_cur
=GetCurIndex(GetCur
) then
228 if offset
>MAX_FASTCRAFT_OFFSET
then
229 offset
:=MAX_FASTCRAFT_OFFSET
;
233 SetOffset(offset
, 0);
236 procedure OpenChestWindow(n
:integer;);
241 SetWindowType(WINDOW_CHEST_INV
);
242 SetCurActive(true, CUR_SELECT1
);
244 if FindCurrentWindowsType
=false then
246 ChestWindowImg
:=ld_tex('container.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','gui/');
251 initCell(CELL_TYPE_PLAYER_INV
, id
, 0, -1, 8+j
*18, 8+i
*18, true);
258 initCell(CELL_TYPE_PLAYER_INV
, id
, 0, -1, 8+j
*18, 8+i
*18+4, true);
266 initCell(CELL_TYPE_CHEST
, id
, 0, n
, 8+j
*18, 88+i
*18, true);
271 procedure CloseChestWindow
;
275 if FindCurrentWindowsType
=false then
277 ChestWindowImg
:=nullimg
;
282 procedure OpenCreativeWindow
;
287 SetWindowType(WINDOW_CEATIVE_INV
);
288 SetCurActive(true, CUR_SELECT1
);
290 if FindCurrentWindowsType
=false then
292 CrWindowImg
:=ld_tex('creative.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','gui/');
293 CrScrollImg
:=rotate_image_from_image(CrWindowImg
, 0, 108, 12, 15, 0);
294 CrWindowImg
:=rotate_image_from_image(CrWindowImg
, 0, 0, 176, 108, 0);
299 initCell(CELL_TYPE_PLAYER_INV
, id
, 0, -1, 8+j
*18, 8+i
*18, true);
307 initCell(CELL_TYPE_CREWATIVE_INV
, id
, 1, -1, 8+j
*18, 30+i
*18, false);
312 procedure DrawCreativeWindow(x
, y
:integer;);
316 DrawImage(CrWindowImg
, x
, y
);
317 scroll
:=getOffset(1);
318 i
:=calcScrollBar(70, getImageHeight(CrScrollImg
), MAX_CREATIVE_OFFSET
, scroll
);
319 drawimage(CrScrollImg
, x
+156, y
+30+i
);
322 procedure FindCeativeUD(n
:integer;);
324 old_cur
, offset
:integer;
326 old_cur
:=GetCurIndex(GetCur
);
327 offset
:=getOffset(1);
330 ShiftCurrentCur(FIND_CELL_UP
);
332 ShiftCurrentCur(FIND_CELL_DOWN
);
334 if old_cur
=GetCurIndex(GetCur
) then
346 if offset
>MAX_CREATIVE_OFFSET
then
347 offset
:=MAX_CREATIVE_OFFSET
;
351 SetOffset(offset
, 1);
354 procedure CloseCreativeWindow
;
358 if FindCurrentWindowsType
=false then
360 CrWindowImg
:=nullimg
;
361 CrScrollImg
:=nullimg
;
366 procedure OpenDivWindow
;
370 debug('Open Div Window');
371 item
:=getItem(GetCurIndex(GetCur
));
372 sum
:=getSum(GetCurIndex(GetCur
));
375 SetWindowType(WINDOW_DIV_ITEMS
);
377 if FindCurrentWindowsType
=false then
379 DivWindowImg
:=ld_tex('partition.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','gui/');
380 DivScrollImg
:=rotate_image_from_image(DivWindowImg
, 0, 50, 15, 12, 0);
381 DivWindowImg
:=rotate_image_from_image(DivWindowImg
, 0, 0, 88, 50, 0);
384 SetWindowInfo(item
, WINDOW_INFO_DIV_ITEM
);
385 SetWindowInfo(sum
, WINDOW_INFO_DIV_SUM1
);
388 procedure DivScroll(pp
:integer);
392 sum1
:=GetWindowInfo(WINDOW_INFO_DIV_SUM1
);
393 sum2
:=GetWindowInfo(WINDOW_INFO_DIV_SUM2
);
401 SetWindowInfo(sum2
, WINDOW_INFO_DIV_SUM2
);
404 procedure DrawDivWindow(x
, y
:integer);
406 i
, item
, sum1
, sum2
:integer;
408 DrawImage(DivWindowImg
, x
, y
);
410 item
:=GetWindowInfo(WINDOW_INFO_DIV_ITEM
);
411 sum1
:=GetWindowInfo(WINDOW_INFO_DIV_SUM1
);
412 sum2
:=GetWindowInfo(WINDOW_INFO_DIV_SUM2
);
414 ItemsLogic
.Draw(item
, (sum1
-sum2
), x
+8, y
+8, true);
415 ItemsLogic
.Draw(item
, sum2
, x
+64, y
+8, true);
417 i
:=calcScrollBar(72, getImageWidth(DivScrollImg
), sum1
, sum2
);
419 drawimage(DivScrollImg
, x
+8+i
, y
+30);
422 procedure CloseDivWindow(return_val
:boolean);
427 debug('Close Div Window');
428 res
:=GetWindowInfo(WINDOW_INFO_DIV_SUM2
);
429 //Если таких окон нет, то чистим память
430 if FindCurrentWindowsType
=false then
432 DivWindowImg
:=nullimg
;
433 DivScrollImg
:=nullimg
;
436 SetWindowInfo(res
, WINDOW_INFO_DIVRES
);
441 SetCurActive(true, CUR_SELECT2
);
442 SetCurIndex(GetCurIndex(CUR_SELECT1
), CUR_SELECT2
);
443 SetWindowInfo(INV_MODE_SELECT2_DIV
, WINDOW_INFO_INVMODE
);
447 procedure OpenPlayerInventory
;
452 SetWindowType(WINDOW_PLAYER_INV
);
453 SetCurActive(true, CUR_SELECT1
);
455 //Если таких окон нет, то загружаем графику
456 if FindCurrentWindowsType
=false then
458 InvWindowImg
:=ld_tex('inventory.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','gui/');
463 initCell(CELL_TYPE_PLAYER_INV
, id
, 0, -1, 8+j
*18, 8+i
*18, true);
470 initCell(CELL_TYPE_PLAYER_INV
, id
, 0, -1, 8+j
*18, 8+i
*18+4, true);
475 procedure ClosePlayerInventory
;
479 debug('Close Player Inventory');
480 //Если таких окон нет, то чистим память
481 if FindCurrentWindowsType
=false then
483 InvWindowImg
:=nullimg
;
488 procedure DrawWindows
;
491 i
, wtype
, x
, y
:integer;
497 wtype
:=GetWindowType
;
498 if wtype
=WINDOW_PLAYER_INV
then
500 x
:=getWidth
/2-getImageWidth(InvWindowImg
)/2;
501 y
:=getHeight
/2-getImageHeight(InvWindowImg
)/2;
502 DrawImage(InvWindowImg
, x
, y
);
505 if wtype
=WINDOW_DIV_ITEMS
then
507 x
:=getWidth
/2-getImageWidth(DivWindowImg
)/2;
508 y
:=getHeight
/2-getImageHeight(DivWindowImg
)/2;
512 if wtype
=WINDOW_CEATIVE_INV
then
514 x
:=getWidth
/2-getImageWidth(CrWindowImg
)/2;
515 y
:=getHeight
/2-getImageHeight(CrWindowImg
)/2;
516 DrawCreativeWindow(x
, y
);
519 if wtype
=WINDOW_CHEST_INV
then
521 x
:=getWidth
/2-getImageWidth(ChestWindowImg
)/2;
522 y
:=getHeight
/2-getImageHeight(ChestWindowImg
)/2;
523 DrawImage(ChestWindowImg
, x
, y
);
526 if wtype
=WINDOW_FASTCRAFT
then
528 x
:=getWidth
/2-getImageWidth(fcWindowImg
)/2;
529 y
:=getHeight
/2-getImageHeight(fcWindowImg
)/2;
530 DrawFastCraftWindow(x
, y
);
533 if wtype
=WINDOW_FURNACE
then
535 x
:=getWidth
/2-getImageWidth(furWindowImg
)/2;
536 y
:=getHeight
/2-getImageHeight(furWindowImg
)/2;
537 DrawFurnaceWindow(x
, y
);
539 DrawCellLayer(i
, x
, y
);
540 DrawCursors(i
, x
, y
);
544 procedure OpSwapItems(Idx1
, Idx2
:integer);
546 tmp_item
, tmp_sum
:integer;
548 tmp_item
:=getItem(Idx1
);
549 tmp_sum
:=getSum(Idx1
);
551 setItem(getItem(Idx2
), Idx1
);
552 setSum(getSum(Idx2
), Idx1
);
554 setItem(tmp_item
, Idx2
);
555 setSum(tmp_sum
, Idx2
);
558 function OpAddItems(Idx1
, Idx2
:integer):boolean;
560 tmp_item1
, tmp_sum1
:integer;
561 tmp_item2
, tmp_sum2
:integer;
564 tmp_item1
:=GetItem(Idx1
);
565 tmp_sum1
:=GetSum(Idx1
);
566 tmp_item2
:=GetItem(Idx2
);
567 tmp_sum2
:=GetSum(Idx2
);
570 if (tmp_item1
=tmp_item2
) and (Idx1
<>Idx2
) then
571 if tmp_sum2
< Items
.GetMaximum(tmp_item2
) then
573 tmp_sum2
:=tmp_sum2
+tmp_sum1
;
576 if tmp_sum2
> GetMaximum(tmp_item2
) then
578 tmp_sum1
:= tmp_sum2
- Items
.GetMaximum(tmp_item2
);
579 tmp_sum2
:= tmp_sum2
- tmp_sum1
;
588 SetItem(tmp_item1
, Idx1
);
589 SetSum(tmp_sum1
, Idx1
);
590 SetItem(tmp_item2
, Idx2
);
591 SetSum(tmp_sum2
, Idx2
);
595 procedure SetActiveCursor(n
:integer;);
599 if n
=CUR_SELECT1
then
605 SetCurActive(true, n
);
606 SetCurIndex(GetCurIndex(n2
), n
);
609 procedure decItem(curidx
:integer);
611 SetSum(GetSum(curidx
)-1, curidx
);
615 procedure HandlerSelect2Div
;
619 idx1
:=GetCurIndex(CUR_SELECT1
);
620 idx2
:=GetCurIndex(CUR_SELECT2
);
622 if GetItem(idx2
)=0 then
624 SetItem(GetItem(idx1
), idx2
);
625 SetSum(GetWindowInfo(WINDOW_INFO_DIVRES
), idx2
);
627 SetSum(GetSum(idx1
)-GetSum(idx2
), idx1
);
636 mode
:=GetWindowInfo(WINDOW_INFO_INVMODE
);
638 //Нажали кнопку - выбрали первый элемент
639 if mode
=INV_MODE_SELECT1
then
641 //Активируем второй курсор и ставим его над первым курсором
642 SetActiveCursor(CUR_SELECT2
);
643 SetWindowInfo(INV_MODE_SELECT2
, WINDOW_INFO_INVMODE
);
646 //Нажали кнопку - выбрали второй элемент, произвели сложение и переходим к режиму выбора первого элемента.
647 if mode
=INV_MODE_SELECT2
then
649 //Складывваем предметы курсора 1 и курсора 2
650 if OpAddItems(GetCurIndex(CUR_SELECT1
), GetCurIndex(CUR_SELECT2
)) then
651 OpSwapItems(GetCurIndex(CUR_SELECT1
), GetCurIndex(CUR_SELECT2
));
652 //Передаём управление первому курсору
653 SetActiveCursor(CUR_SELECT1
);
654 SetCurActive(false, CUR_SELECT2
);
655 SetWindowInfo(INV_MODE_SELECT1
, WINDOW_INFO_INVMODE
);
658 if mode
=INV_MODE_SELECT2_DIV
then
661 SetActiveCursor(CUR_SELECT1
);
662 SetCurActive(false, CUR_SELECT2
);
663 SetWindowInfo(INV_MODE_SELECT1
, WINDOW_INFO_INVMODE
);
667 function CanDivItem
:boolean;
669 if Items
.IsDividable(getItem(GetCurIndex(GetCur
))) then
670 if (GetCur
=CUR_SELECT1
) and (getSum(GetCurIndex(GetCur
))>0) then
674 procedure StdCellKeyHandler
;
676 if clickedKey(KEY_WIN_SELECT
) then
677 SetTimer(1000, T_KEY_DIVITEM
);
679 if pressedKey(KEY_WIN_SELECT
) then
681 if GetTimer(T_KEY_DIVITEM
)=TIMER_OK
then
685 ResetTimer(T_KEY_DIVITEM
);
690 if GetTimer(T_KEY_DIVITEM
)>TIMER_OK
then
693 ResetTimer(T_KEY_DIVITEM
);
700 item
, curidx
:integer;
702 curidx
:=GetCurIndex(GetCur
);
703 item
:=getItem(curidx
);
705 if clickedKey(KEY_WIN_DROP
) then
706 SetTimer(1000, T_KEY_DROPITEM
);
708 if pressedKey(KEY_WIN_DROP
) then
710 if GetTimer(T_KEY_DROPITEM
)=TIMER_OK
then
712 player
.dropItem(item
, GetSum(curidx
));
715 ResetTimer(T_KEY_DROPITEM
);
720 if GetTimer(T_KEY_DROPITEM
)>TIMER_OK
then
722 if Items
.IsDividable(item
) then
724 player
.dropItem(item
, 1);
727 ResetTimer(T_KEY_DROPITEM
);
732 function WindowKeyHanler
:boolean;
735 craftid
, mode
:integer;
737 WinType
:=GetWindowType
;
738 if WinType
=WINDOW_PLAYER_INV
then
740 if clickedKey(KEY_WIN_UP
) then
741 ShiftCurrentCur(FIND_CELL_UP
);
742 if clickedKey(KEY_WIN_DOWN
) then
743 ShiftCurrentCur(FIND_CELL_DOWN
);
744 if clickedKey(KEY_WIN_LEFT
) then
745 ShiftCurrentCur(FIND_CELL_LEFT
);
746 if clickedKey(KEY_WIN_RIGHT
) then
747 ShiftCurrentCur(FIND_CELL_RIGHT
);
752 if clickedKey(KEY_WIN_EXIT
) then
753 ClosePlayerInventory
;
755 if clickedKey(KEY_WIN_ALT
) then
757 ClosePlayerInventory
;
758 OpenFastCraftWindow(0);
762 if WinType
=WINDOW_DIV_ITEMS
then
764 if clickedKey(KEY_WIN_LEFT
) then
766 if clickedKey(KEY_WIN_RIGHT
) then
769 if clickedKey(KEY_WIN_SELECT
) then
770 CloseDivWindow(true);
772 if clickedKey(KEY_WIN_EXIT
) then
773 CloseDivWindow(false);
776 if WinType
=WINDOW_CEATIVE_INV
then
778 if clickedKey(KEY_WIN_UP
) then
780 if clickedKey(KEY_WIN_DOWN
) then
782 if clickedKey(KEY_WIN_LEFT
) then
783 ShiftCurrentCur(FIND_CELL_LEFT
);
784 if clickedKey(KEY_WIN_RIGHT
) then
785 ShiftCurrentCur(FIND_CELL_RIGHT
);
790 if clickedKey(KEY_WIN_EXIT
) then
794 if WinType
=WINDOW_CHEST_INV
then
796 if clickedKey(KEY_WIN_UP
) then
797 ShiftCurrentCur(FIND_CELL_UP
);
798 if clickedKey(KEY_WIN_DOWN
) then
799 ShiftCurrentCur(FIND_CELL_DOWN
);
800 if clickedKey(KEY_WIN_LEFT
) then
801 ShiftCurrentCur(FIND_CELL_LEFT
);
802 if clickedKey(KEY_WIN_RIGHT
) then
803 ShiftCurrentCur(FIND_CELL_RIGHT
);
808 if clickedKey(KEY_WIN_EXIT
) then
812 if WinType
=WINDOW_FASTCRAFT
then
814 if clickedKey(KEY_WIN_UP
) then
816 if clickedKey(KEY_WIN_DOWN
) then
818 if clickedKey(KEY_WIN_LEFT
) then
819 ShiftCurrentCur(FIND_CELL_LEFT
);
820 if clickedKey(KEY_WIN_RIGHT
) then
821 ShiftCurrentCur(FIND_CELL_RIGHT
);
823 if clickedKey(KEY_WIN_SELECT
) then
825 mode
:=GetWindowInfo(WINDOW_INFO_FC_MODE
);
826 craftid
:=getCellID(GetCurIndex(GetCur
))+GetOffset(0);
827 createCraft(craftid
, mode
);
830 if clickedKey(KEY_WIN_ALT
) then
836 if clickedKey(KEY_WIN_EXIT
) then
840 if WinType
=WINDOW_FURNACE
then
842 if clickedKey(KEY_WIN_UP
) then
843 ShiftCurrentCur(FIND_CELL_UP
);
844 if clickedKey(KEY_WIN_DOWN
) then
845 ShiftCurrentCur(FIND_CELL_DOWN
);
846 if clickedKey(KEY_WIN_LEFT
) then
847 ShiftCurrentCur(FIND_CELL_LEFT
);
848 if clickedKey(KEY_WIN_RIGHT
) then
849 ShiftCurrentCur(FIND_CELL_RIGHT
);
854 if clickedKey(KEY_WIN_EXIT
) then
858 WindowKeyHanler
:=true;