Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add library for creating GUI menus #370

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Changes from 9 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1148314
Create gui_menu.sc
Ghoulboy78 Apr 6, 2023
a4db6da
Getting rid of previous test functions
Ghoulboy78 Apr 6, 2023
8bf50b4
Rearranged code, made prettier example
Ghoulboy78 Apr 6, 2023
15e45e5
Adding dynamic buttons (+ examples)
Ghoulboy78 Apr 6, 2023
9c4f693
editing testing tools
Ghoulboy78 Apr 6, 2023
9fe65df
Adding storage slots
Ghoulboy78 Apr 7, 2023
054ea20
Bugfix
Ghoulboy78 Apr 7, 2023
ebb23da
adding player variable in button action callback
Ghoulboy78 Apr 7, 2023
1bdfce2
Switching from map to list
Ghoulboy78 Apr 7, 2023
989c917
Framework for pages functionality
Ghoulboy78 Apr 8, 2023
2a6b878
Added page switching funcionality
Ghoulboy78 Apr 9, 2023
7f965b8
Added ability for different pages to have different titles
Ghoulboy78 Apr 10, 2023
e07d2fb
Different pages can have different inventory sizes!
Ghoulboy78 Apr 10, 2023
f1647e8
Fixed bug which allowed player to mess up screen
Ghoulboy78 Apr 10, 2023
a65370d
Added button labels
Ghoulboy78 Apr 10, 2023
1703bef
Fixed bug causing incorrect inventory shape opened incase of nondefau…
Ghoulboy78 Apr 10, 2023
ac88016
Renaming to .scl and removing testing stuff
Ghoulboy78 Apr 10, 2023
19d4ebc
Added ability to have all types of gui screen
Ghoulboy78 Apr 10, 2023
cb0ac79
Added callback for anvil GUI modification
Ghoulboy78 Apr 10, 2023
ffa42d0
Giving more info with anvil item modification
Ghoulboy78 Apr 10, 2023
18f1dbf
Added select_recipe events
Ghoulboy78 Apr 10, 2023
f484d7b
Added dynamic slots
Ghoulboy78 Apr 11, 2023
a8b34e2
Added additional screen callback for programmers
Ghoulboy78 Apr 11, 2023
c8a4f96
Added loom pattern selection
Ghoulboy78 Apr 11, 2023
8767362
Added stonecutter and loom functionality
Ghoulboy78 Apr 11, 2023
f11babf
Extracted page switching to new function
Ghoulboy78 Apr 11, 2023
c905785
Added lectern button detection
Ghoulboy78 Apr 11, 2023
4086355
Fixing bug with dynamic slots
Ghoulboy78 Apr 11, 2023
55810ce
Added enchantment table function
Ghoulboy78 Jun 23, 2023
89c4396
Removed name placeholders
Ghoulboy78 Jun 23, 2023
8c18bd0
Added descriptive documentation
Ghoulboy78 Jun 26, 2023
79d297d
Added on_init
Ghoulboy78 Jun 26, 2023
438cfbd
Create test_gui_menu.sc
Ghoulboy78 Jun 26, 2023
0f2d8b9
Added `on_select_crafting_recipe` event to furnace/blast furnace/smok…
Ghoulboy78 Aug 3, 2023
6fac304
returning proper icon item array
Ghoulboy78 Dec 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions programs/fundamentals/gui_menu.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

__on_player_swings_hand(player, hand)-> (
if(hand=='mainhand' && player~'holds':0=='brewing_stand',
call_gui_menu(global_Test_GUI, player)
)
);

//Config

global_inventory_sizes={
'generic_3x3'->9,
'generic_9x1'->9,
'generic_9x2'->18,
'generic_9x3'->27,
'generic_9x4'->36,
'generic_9x5'->45,
'generic_9x6'->54
};

//Certain names are subject to change, so instead I'll store them in global variables while I'm still fiddling with exact nomenclature
global_static_buttons='buttons';
global_dynamic_buttons='dynamic_buttons';
global_storage_slots='storage_slots';

global_Test={
'inventory_shape'->'generic_3x3',
'title'->format('db Test GUI menu!'),
global_static_buttons->{
0->['red_stained_glass_pane', _(player, button)->print(player, 'Pressed the red button!')],
4->['green_stained_glass_pane', _(player, button)->print(player, str('Clicked with %s button', if(button, 'Right', 'Left')))]
},
global_dynamic_buttons->{
1->[ //Blue button to black button
'blue_stained_glass_pane',
_(screen, player, button)->inventory_set(screen, 1, 1, if(inventory_get(screen, 1):0=='blue_stained_glass_pane', 'black_stained_glass_pane', 'blue_stained_glass_pane'));
],

6->[ //Turns the slot above purple
'lime_stained_glass_pane',
_(screen, player, button)->(
inventory_set(screen, 3, 1, if(inventory_get(screen, 3)==null, 'purple_stained_glass_pane', 'air'));
)
],
},
global_storage_slots->{ //These slots can be used for storage by the player
8->['stone', 4, null], //This is simply the first item that will be available in the slot, it will subsequently be overwritten by whatever the player places in that slot
5, 2 //leaving this blank makes the slot blank
}
};

new_gui_menu(gui_screen)->( //Stores GUI data in intermediary map form, so the programmer can call them at any time with call_gui_menu() function
if(type(gui_screen)!='map' || !has(gui_screen, 'inventory_shape'),
throw('Invalid gui creation: '+gui_screen)
);

inventory_shape = gui_screen:'inventory_shape';

inventory_size = global_inventory_sizes:inventory_shape;

if(inventory_size==0,
throw('Invalid gui creation: Must be one of '+keys(global_inventory_sizes)+', not '+inventory_shape)
);

{
'inventory_shape'->inventory_shape, //shape of the inventory, copied from above
'title'->gui_screen:'title', //Fancy GUI title
'on_created'->_(screen, outer(gui_screen))->(// Fiddling with the screen after it's made to add fancy visual bits
for(gui_screen:global_static_buttons,
inventory_set(screen, _, 1, gui_screen:global_static_buttons:_:0)
);
for(gui_screen:global_dynamic_buttons,
inventory_set(screen, _, 1, gui_screen:global_dynamic_buttons:_:0)
);
for(gui_screen:global_storage_slots,
[item, count, nbt] = gui_screen:global_storage_slots:_ || ['air', 0, null];
inventory_set(screen, _, count, item, nbt)
);
),
'callback'->_(screen, player, action, data, outer(gui_screen), outer(inventory_size))->(//This is where most of the action happens
slot = data:'slot'; //Grabbing slot, this is the focus of the action

if(action=='pickup', //This is equivalent of clicking (button action)
if(has(gui_screen:global_static_buttons, slot), //Plain, vanilla button
call(gui_screen:global_static_buttons:slot:1, player, data:'button'),
has(gui_screen:global_dynamic_buttons, slot), //A more exciting button
call(gui_screen:global_dynamic_buttons:slot:1, screen, player, data:'button')
);
);

//Saving items in storage slots when closing
if(action=='close',
for(gui_screen:global_storage_slots,
gui_screen:global_storage_slots:_ = inventory_get(screen, _);
);
);

//Disabling quick move cos it messes up the GUI, and there's no reason to allow it
//Also preventing the player from tampering with button slots
//Unless the slot is marked as a storage slot, in which case we allow it
if((action=='quick_move'||slot<inventory_size)&&!has(gui_screen:global_storage_slots,slot),
'cancel'
);
)
}
);

call_gui_menu(gui_menu, player)->( //Opens the screen to the player, returns screen for further manipulation
screen = create_screen(player, gui_menu:'inventory_shape', gui_menu:'title', gui_menu:'callback');
call(gui_menu:'on_created', screen);
screen
);

global_Test_GUI = new_gui_menu(global_Test);