Refactor complete. Time for bug huntin'
This commit is contained in:
302
src/menus/storage_menu.nvgt
Normal file
302
src/menus/storage_menu.nvgt
Normal file
@@ -0,0 +1,302 @@
|
||||
// Base storage menu system
|
||||
// Functions for interacting with base storage (deposit/withdraw items)
|
||||
|
||||
void move_small_game_to_storage(int amount) {
|
||||
for (int i = 0; i < amount; i++) {
|
||||
string game_type = "small game";
|
||||
if (inv_small_game_types.length() > 0) {
|
||||
game_type = inv_small_game_types[0];
|
||||
inv_small_game_types.remove_at(0);
|
||||
}
|
||||
storage_small_game_types.insert_last(game_type);
|
||||
}
|
||||
}
|
||||
|
||||
void move_small_game_to_personal(int amount) {
|
||||
for (int i = 0; i < amount; i++) {
|
||||
string game_type = "small game";
|
||||
if (storage_small_game_types.length() > 0) {
|
||||
game_type = storage_small_game_types[0];
|
||||
storage_small_game_types.remove_at(0);
|
||||
}
|
||||
inv_small_game_types.insert_last(game_type);
|
||||
}
|
||||
}
|
||||
|
||||
int prompt_transfer_amount(const string prompt, int max_amount) {
|
||||
string input = ui_input_box("Inventory", prompt + " (max " + max_amount + ")", "");
|
||||
int amount = parse_int(input);
|
||||
if (amount <= 0) return 0;
|
||||
if (amount > max_amount) amount = max_amount;
|
||||
return amount;
|
||||
}
|
||||
|
||||
void deposit_item(int item_type) {
|
||||
int available = get_personal_count(item_type);
|
||||
if (available <= 0) {
|
||||
speak_with_history("Nothing to deposit.", true);
|
||||
return;
|
||||
}
|
||||
int capacity = BASE_STORAGE_MAX - get_storage_count(item_type);
|
||||
if (capacity <= 0) {
|
||||
speak_with_history("Storage for that item is full.", true);
|
||||
return;
|
||||
}
|
||||
int max_transfer = (available < capacity) ? available : capacity;
|
||||
int amount = prompt_transfer_amount("Deposit how many?", max_transfer);
|
||||
if (amount <= 0) return;
|
||||
|
||||
if (item_type == ITEM_STICKS) { inv_sticks -= amount; storage_sticks += amount; }
|
||||
else if (item_type == ITEM_VINES) { inv_vines -= amount; storage_vines += amount; }
|
||||
else if (item_type == ITEM_REEDS) { inv_reeds -= amount; storage_reeds += amount; }
|
||||
else if (item_type == ITEM_STONES) { inv_stones -= amount; storage_stones += amount; }
|
||||
else if (item_type == ITEM_LOGS) { inv_logs -= amount; storage_logs += amount; }
|
||||
else if (item_type == ITEM_CLAY) { inv_clay -= amount; storage_clay += amount; }
|
||||
else if (item_type == ITEM_SMALL_GAME) { inv_small_game -= amount; storage_small_game += amount; move_small_game_to_storage(amount); }
|
||||
else if (item_type == ITEM_MEAT) { inv_meat -= amount; storage_meat += amount; }
|
||||
else if (item_type == ITEM_SKINS) { inv_skins -= amount; storage_skins += amount; }
|
||||
else if (item_type == ITEM_FEATHERS) { inv_feathers -= amount; storage_feathers += amount; }
|
||||
else if (item_type == ITEM_DOWN) { inv_down -= amount; storage_down += amount; }
|
||||
else if (item_type == ITEM_INCENSE) { inv_incense -= amount; storage_incense += amount; }
|
||||
else if (item_type == ITEM_SPEARS) { inv_spears -= amount; storage_spears += amount; }
|
||||
else if (item_type == ITEM_SLINGS) { inv_slings -= amount; storage_slings += amount; }
|
||||
else if (item_type == ITEM_AXES) { inv_axes -= amount; storage_axes += amount; }
|
||||
else if (item_type == ITEM_SNARES) { inv_snares -= amount; storage_snares += amount; }
|
||||
else if (item_type == ITEM_KNIVES) { inv_knives -= amount; storage_knives += amount; }
|
||||
else if (item_type == ITEM_FISHING_POLES) { inv_fishing_poles -= amount; storage_fishing_poles += amount; }
|
||||
else if (item_type == ITEM_ROPES) { inv_ropes -= amount; storage_ropes += amount; }
|
||||
else if (item_type == ITEM_REED_BASKETS) { inv_reed_baskets -= amount; storage_reed_baskets += amount; }
|
||||
else if (item_type == ITEM_CLAY_POTS) { inv_clay_pots -= amount; storage_clay_pots += amount; }
|
||||
else if (item_type == ITEM_SKIN_HATS) { inv_skin_hats -= amount; storage_skin_hats += amount; }
|
||||
else if (item_type == ITEM_SKIN_GLOVES) { inv_skin_gloves -= amount; storage_skin_gloves += amount; }
|
||||
else if (item_type == ITEM_SKIN_PANTS) { inv_skin_pants -= amount; storage_skin_pants += amount; }
|
||||
else if (item_type == ITEM_SKIN_TUNICS) { inv_skin_tunics -= amount; storage_skin_tunics += amount; }
|
||||
else if (item_type == ITEM_MOCCASINS) { inv_moccasins -= amount; storage_moccasins += amount; }
|
||||
else if (item_type == ITEM_SKIN_POUCHES) { inv_skin_pouches -= amount; storage_skin_pouches += amount; }
|
||||
|
||||
cleanup_equipment_after_inventory_change();
|
||||
speak_with_history("Deposited " + amount + " " + get_item_label(item_type) + ".", true);
|
||||
}
|
||||
|
||||
void deposit_item_max(int item_type) {
|
||||
int available = get_personal_count(item_type);
|
||||
if (available <= 0) {
|
||||
speak_with_history("Nothing to deposit.", true);
|
||||
return;
|
||||
}
|
||||
|
||||
int capacity = BASE_STORAGE_MAX - get_storage_count(item_type);
|
||||
if (capacity <= 0) {
|
||||
speak_with_history("Storage for that item is full.", true);
|
||||
return;
|
||||
}
|
||||
|
||||
int amount = (available < capacity) ? available : capacity;
|
||||
|
||||
if (item_type == ITEM_STICKS) { inv_sticks -= amount; storage_sticks += amount; }
|
||||
else if (item_type == ITEM_VINES) { inv_vines -= amount; storage_vines += amount; }
|
||||
else if (item_type == ITEM_REEDS) { inv_reeds -= amount; storage_reeds += amount; }
|
||||
else if (item_type == ITEM_STONES) { inv_stones -= amount; storage_stones += amount; }
|
||||
else if (item_type == ITEM_LOGS) { inv_logs -= amount; storage_logs += amount; }
|
||||
else if (item_type == ITEM_CLAY) { inv_clay -= amount; storage_clay += amount; }
|
||||
else if (item_type == ITEM_SMALL_GAME) { inv_small_game -= amount; storage_small_game += amount; move_small_game_to_storage(amount); }
|
||||
else if (item_type == ITEM_MEAT) { inv_meat -= amount; storage_meat += amount; }
|
||||
else if (item_type == ITEM_SKINS) { inv_skins -= amount; storage_skins += amount; }
|
||||
else if (item_type == ITEM_FEATHERS) { inv_feathers -= amount; storage_feathers += amount; }
|
||||
else if (item_type == ITEM_DOWN) { inv_down -= amount; storage_down += amount; }
|
||||
else if (item_type == ITEM_INCENSE) { inv_incense -= amount; storage_incense += amount; }
|
||||
else if (item_type == ITEM_SPEARS) { inv_spears -= amount; storage_spears += amount; }
|
||||
else if (item_type == ITEM_SLINGS) { inv_slings -= amount; storage_slings += amount; }
|
||||
else if (item_type == ITEM_AXES) { inv_axes -= amount; storage_axes += amount; }
|
||||
else if (item_type == ITEM_SNARES) { inv_snares -= amount; storage_snares += amount; }
|
||||
else if (item_type == ITEM_KNIVES) { inv_knives -= amount; storage_knives += amount; }
|
||||
else if (item_type == ITEM_FISHING_POLES) { inv_fishing_poles -= amount; storage_fishing_poles += amount; }
|
||||
else if (item_type == ITEM_ROPES) { inv_ropes -= amount; storage_ropes += amount; }
|
||||
else if (item_type == ITEM_REED_BASKETS) { inv_reed_baskets -= amount; storage_reed_baskets += amount; }
|
||||
else if (item_type == ITEM_CLAY_POTS) { inv_clay_pots -= amount; storage_clay_pots += amount; }
|
||||
else if (item_type == ITEM_SKIN_HATS) { inv_skin_hats -= amount; storage_skin_hats += amount; }
|
||||
else if (item_type == ITEM_SKIN_GLOVES) { inv_skin_gloves -= amount; storage_skin_gloves += amount; }
|
||||
else if (item_type == ITEM_SKIN_PANTS) { inv_skin_pants -= amount; storage_skin_pants += amount; }
|
||||
else if (item_type == ITEM_SKIN_TUNICS) { inv_skin_tunics -= amount; storage_skin_tunics += amount; }
|
||||
else if (item_type == ITEM_MOCCASINS) { inv_moccasins -= amount; storage_moccasins += amount; }
|
||||
else if (item_type == ITEM_SKIN_POUCHES) { inv_skin_pouches -= amount; storage_skin_pouches += amount; }
|
||||
|
||||
cleanup_equipment_after_inventory_change();
|
||||
speak_with_history("Deposited " + amount + " " + get_item_label(item_type) + ".", true);
|
||||
}
|
||||
|
||||
void withdraw_item(int item_type) {
|
||||
int available = get_storage_count(item_type);
|
||||
if (available <= 0) {
|
||||
speak_with_history("Nothing to withdraw.", true);
|
||||
return;
|
||||
}
|
||||
int capacity = get_personal_stack_limit() - get_personal_count(item_type);
|
||||
if (capacity <= 0) {
|
||||
speak_with_history("You can't carry any more " + get_item_label(item_type) + ".", true);
|
||||
return;
|
||||
}
|
||||
int max_transfer = (available < capacity) ? available : capacity;
|
||||
int amount = prompt_transfer_amount("Withdraw how many?", max_transfer);
|
||||
if (amount <= 0) return;
|
||||
|
||||
if (item_type == ITEM_STICKS) { storage_sticks -= amount; inv_sticks += amount; }
|
||||
else if (item_type == ITEM_VINES) { storage_vines -= amount; inv_vines += amount; }
|
||||
else if (item_type == ITEM_REEDS) { storage_reeds -= amount; inv_reeds += amount; }
|
||||
else if (item_type == ITEM_STONES) { storage_stones -= amount; inv_stones += amount; }
|
||||
else if (item_type == ITEM_LOGS) { storage_logs -= amount; inv_logs += amount; }
|
||||
else if (item_type == ITEM_CLAY) { storage_clay -= amount; inv_clay += amount; }
|
||||
else if (item_type == ITEM_SMALL_GAME) { storage_small_game -= amount; inv_small_game += amount; move_small_game_to_personal(amount); }
|
||||
else if (item_type == ITEM_MEAT) { storage_meat -= amount; inv_meat += amount; }
|
||||
else if (item_type == ITEM_SKINS) { storage_skins -= amount; inv_skins += amount; }
|
||||
else if (item_type == ITEM_FEATHERS) { storage_feathers -= amount; inv_feathers += amount; }
|
||||
else if (item_type == ITEM_DOWN) { storage_down -= amount; inv_down += amount; }
|
||||
else if (item_type == ITEM_INCENSE) { storage_incense -= amount; inv_incense += amount; }
|
||||
else if (item_type == ITEM_SPEARS) { storage_spears -= amount; inv_spears += amount; }
|
||||
else if (item_type == ITEM_SLINGS) { storage_slings -= amount; inv_slings += amount; }
|
||||
else if (item_type == ITEM_AXES) { storage_axes -= amount; inv_axes += amount; }
|
||||
else if (item_type == ITEM_SNARES) { storage_snares -= amount; inv_snares += amount; }
|
||||
else if (item_type == ITEM_KNIVES) { storage_knives -= amount; inv_knives += amount; }
|
||||
else if (item_type == ITEM_FISHING_POLES) { storage_fishing_poles -= amount; inv_fishing_poles += amount; }
|
||||
else if (item_type == ITEM_ROPES) { storage_ropes -= amount; inv_ropes += amount; }
|
||||
else if (item_type == ITEM_REED_BASKETS) { storage_reed_baskets -= amount; inv_reed_baskets += amount; }
|
||||
else if (item_type == ITEM_CLAY_POTS) { storage_clay_pots -= amount; inv_clay_pots += amount; }
|
||||
else if (item_type == ITEM_SKIN_HATS) { storage_skin_hats -= amount; inv_skin_hats += amount; }
|
||||
else if (item_type == ITEM_SKIN_GLOVES) { storage_skin_gloves -= amount; inv_skin_gloves += amount; }
|
||||
else if (item_type == ITEM_SKIN_PANTS) { storage_skin_pants -= amount; inv_skin_pants += amount; }
|
||||
else if (item_type == ITEM_SKIN_TUNICS) { storage_skin_tunics -= amount; inv_skin_tunics += amount; }
|
||||
else if (item_type == ITEM_MOCCASINS) { storage_moccasins -= amount; inv_moccasins += amount; }
|
||||
else if (item_type == ITEM_SKIN_POUCHES) { storage_skin_pouches -= amount; inv_skin_pouches += amount; }
|
||||
|
||||
speak_with_history("Withdrew " + amount + " " + get_item_label(item_type) + ".", true);
|
||||
}
|
||||
|
||||
void withdraw_item_max(int item_type) {
|
||||
int available = get_storage_count(item_type);
|
||||
if (available <= 0) {
|
||||
speak_with_history("Nothing to withdraw.", true);
|
||||
return;
|
||||
}
|
||||
|
||||
int personal_limit = get_personal_stack_limit();
|
||||
int current_personal = get_personal_count(item_type);
|
||||
int space = personal_limit - current_personal;
|
||||
|
||||
if (space <= 0) {
|
||||
speak_with_history("Can't carry any more.", true);
|
||||
return;
|
||||
}
|
||||
|
||||
int amount = (available < space) ? available : space;
|
||||
|
||||
if (item_type == ITEM_STICKS) { storage_sticks -= amount; inv_sticks += amount; }
|
||||
else if (item_type == ITEM_VINES) { storage_vines -= amount; inv_vines += amount; }
|
||||
else if (item_type == ITEM_REEDS) { storage_reeds -= amount; inv_reeds += amount; }
|
||||
else if (item_type == ITEM_STONES) { storage_stones -= amount; inv_stones += amount; }
|
||||
else if (item_type == ITEM_LOGS) { storage_logs -= amount; inv_logs += amount; }
|
||||
else if (item_type == ITEM_CLAY) { storage_clay -= amount; inv_clay += amount; }
|
||||
else if (item_type == ITEM_SMALL_GAME) { storage_small_game -= amount; inv_small_game += amount; move_small_game_to_personal(amount); }
|
||||
else if (item_type == ITEM_MEAT) { storage_meat -= amount; inv_meat += amount; }
|
||||
else if (item_type == ITEM_SKINS) { storage_skins -= amount; inv_skins += amount; }
|
||||
else if (item_type == ITEM_FEATHERS) { storage_feathers -= amount; inv_feathers += amount; }
|
||||
else if (item_type == ITEM_DOWN) { storage_down -= amount; inv_down += amount; }
|
||||
else if (item_type == ITEM_INCENSE) { storage_incense -= amount; inv_incense += amount; }
|
||||
else if (item_type == ITEM_SPEARS) { storage_spears -= amount; inv_spears += amount; }
|
||||
else if (item_type == ITEM_SLINGS) { storage_slings -= amount; inv_slings += amount; }
|
||||
else if (item_type == ITEM_AXES) { storage_axes -= amount; inv_axes += amount; }
|
||||
else if (item_type == ITEM_SNARES) { storage_snares -= amount; inv_snares += amount; }
|
||||
else if (item_type == ITEM_KNIVES) { storage_knives -= amount; inv_knives += amount; }
|
||||
else if (item_type == ITEM_FISHING_POLES) { storage_fishing_poles -= amount; inv_fishing_poles += amount; }
|
||||
else if (item_type == ITEM_ROPES) { storage_ropes -= amount; inv_ropes += amount; }
|
||||
else if (item_type == ITEM_REED_BASKETS) { storage_reed_baskets -= amount; inv_reed_baskets += amount; }
|
||||
else if (item_type == ITEM_CLAY_POTS) { storage_clay_pots -= amount; inv_clay_pots += amount; }
|
||||
else if (item_type == ITEM_SKIN_HATS) { storage_skin_hats -= amount; inv_skin_hats += amount; }
|
||||
else if (item_type == ITEM_SKIN_GLOVES) { storage_skin_gloves -= amount; inv_skin_gloves += amount; }
|
||||
else if (item_type == ITEM_SKIN_PANTS) { storage_skin_pants -= amount; inv_skin_pants += amount; }
|
||||
else if (item_type == ITEM_SKIN_TUNICS) { storage_skin_tunics -= amount; inv_skin_tunics += amount; }
|
||||
else if (item_type == ITEM_MOCCASINS) { storage_moccasins -= amount; inv_moccasins += amount; }
|
||||
else if (item_type == ITEM_SKIN_POUCHES) { storage_skin_pouches -= amount; inv_skin_pouches += amount; }
|
||||
|
||||
speak_with_history("Withdrew " + amount + " " + get_item_label(item_type) + ".", true);
|
||||
}
|
||||
|
||||
void build_storage_inventory_options(string[]@ options, int[]@ item_types) {
|
||||
options.resize(0);
|
||||
item_types.resize(0);
|
||||
options.insert_last("Sticks: " + storage_sticks); item_types.insert_last(ITEM_STICKS);
|
||||
options.insert_last("Vines: " + storage_vines); item_types.insert_last(ITEM_VINES);
|
||||
options.insert_last("Reeds: " + storage_reeds); item_types.insert_last(ITEM_REEDS);
|
||||
options.insert_last("Stones: " + storage_stones); item_types.insert_last(ITEM_STONES);
|
||||
options.insert_last("Logs: " + storage_logs); item_types.insert_last(ITEM_LOGS);
|
||||
options.insert_last("Clay: " + storage_clay); item_types.insert_last(ITEM_CLAY);
|
||||
options.insert_last("Small Game: " + storage_small_game); item_types.insert_last(ITEM_SMALL_GAME);
|
||||
options.insert_last("Meat: " + storage_meat); item_types.insert_last(ITEM_MEAT);
|
||||
options.insert_last("Skins: " + storage_skins); item_types.insert_last(ITEM_SKINS);
|
||||
options.insert_last("Feathers: " + storage_feathers); item_types.insert_last(ITEM_FEATHERS);
|
||||
options.insert_last("Down: " + storage_down); item_types.insert_last(ITEM_DOWN);
|
||||
options.insert_last("Incense: " + storage_incense); item_types.insert_last(ITEM_INCENSE);
|
||||
options.insert_last("Spears: " + storage_spears); item_types.insert_last(ITEM_SPEARS);
|
||||
options.insert_last("Slings: " + storage_slings); item_types.insert_last(ITEM_SLINGS);
|
||||
options.insert_last("Axes: " + storage_axes); item_types.insert_last(ITEM_AXES);
|
||||
options.insert_last("Snares: " + storage_snares); item_types.insert_last(ITEM_SNARES);
|
||||
options.insert_last("Knives: " + storage_knives); item_types.insert_last(ITEM_KNIVES);
|
||||
options.insert_last("Fishing Poles: " + storage_fishing_poles); item_types.insert_last(ITEM_FISHING_POLES);
|
||||
options.insert_last("Ropes: " + storage_ropes); item_types.insert_last(ITEM_ROPES);
|
||||
options.insert_last("Reed Baskets: " + storage_reed_baskets); item_types.insert_last(ITEM_REED_BASKETS);
|
||||
options.insert_last("Clay Pots: " + storage_clay_pots); item_types.insert_last(ITEM_CLAY_POTS);
|
||||
options.insert_last("Skin Hats: " + storage_skin_hats); item_types.insert_last(ITEM_SKIN_HATS);
|
||||
options.insert_last("Skin Gloves: " + storage_skin_gloves); item_types.insert_last(ITEM_SKIN_GLOVES);
|
||||
options.insert_last("Skin Pants: " + storage_skin_pants); item_types.insert_last(ITEM_SKIN_PANTS);
|
||||
options.insert_last("Skin Tunics: " + storage_skin_tunics); item_types.insert_last(ITEM_SKIN_TUNICS);
|
||||
options.insert_last("Moccasins: " + storage_moccasins); item_types.insert_last(ITEM_MOCCASINS);
|
||||
options.insert_last("Skin Pouches: " + storage_skin_pouches); item_types.insert_last(ITEM_SKIN_POUCHES);
|
||||
}
|
||||
|
||||
void run_storage_menu() {
|
||||
if (world_storages.length() == 0) {
|
||||
speak_with_history("No storage built.", true);
|
||||
return;
|
||||
}
|
||||
|
||||
speak_with_history("Base storage.", true);
|
||||
|
||||
int selection = 0;
|
||||
string[] options;
|
||||
int[] item_types;
|
||||
build_storage_inventory_options(options, item_types);
|
||||
|
||||
while(true) {
|
||||
wait(5);
|
||||
menu_background_tick();
|
||||
if (key_pressed(KEY_ESCAPE)) {
|
||||
speak_with_history("Closed.", true);
|
||||
break;
|
||||
}
|
||||
|
||||
if (key_pressed(KEY_DOWN)) {
|
||||
selection++;
|
||||
if (selection >= options.length()) selection = 0;
|
||||
speak_with_history(options[selection], true);
|
||||
}
|
||||
|
||||
if (key_pressed(KEY_UP)) {
|
||||
selection--;
|
||||
if (selection < 0) selection = options.length() - 1;
|
||||
speak_with_history(options[selection], true);
|
||||
}
|
||||
|
||||
if (key_pressed(KEY_RETURN)) {
|
||||
withdraw_item(item_types[selection]);
|
||||
build_storage_inventory_options(options, item_types);
|
||||
if (selection >= options.length()) selection = 0;
|
||||
speak_with_history(options[selection], true);
|
||||
}
|
||||
|
||||
if (key_pressed(KEY_TAB)) {
|
||||
withdraw_item_max(item_types[selection]);
|
||||
build_storage_inventory_options(options, item_types);
|
||||
if (selection >= options.length()) selection = 0;
|
||||
speak_with_history(options[selection], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user