📄 menus.java
字号:
// All menu items are kept in a pool.
// We sequentially store each menu's list of menu items as a continuous block from the menu item pool.
// Menu Item Pool
public static final byte[] m_menu_item_pool = new byte[MENU_ITEM_POOL_SIZE];
private static int m_menu_item_pool_size = 0; // number of menu items we have in the menu item pool
// Menu stack
public static final byte[] m_menu_stack = new byte[MAX_MENU_DEPTH];
public static final byte[] m_menu_item_stack = new byte[MAX_MENU_DEPTH];
public static final byte[] m_menu_top_stack = new byte[MAX_MENU_DEPTH];
public static int m_current_stack_height = 0;
public static int m_current_menu = 0; // currently active menu
public static int m_current_menu_item = 0; // position of currently selected menu item
public static int m_next_menu = m_current_menu; // the menu we want to goto next
public static int m_next_menu_item = m_current_menu_item; // position of the menu item we want to goto next
public static int m_menu_state = MENU_STATE_NORMAL; // state of current menu
public static int m_menu_anim_state = MENU_ANIM_STATE_NORMAL; // animation state of current menu
public static int m_prev_engine_state = 0; // the engine state we were in before coming to the menu
public static int m_menu_timer = 0;
public static int m_menu_item_timer = 0;
public static int m_current_menu_top = 0; // menu item position of the first displayed menu item (for scrolling menus)
public static int m_next_menu_top = 0; //
// text screen variables
public static int m_text = NONE;
public static int m_text_width = MENU_ITEM_TEXT_WIDTH;
public static int m_text_height = MENU_ITEM_TEXT_HEIGHT;
public static int m_text_page = 0;
public static int m_text_num_pages = 0;
public static int m_text_type = TEXT_TYPE_WINDOW;
public static int m_text_anchor = Graphics.HCENTER;
public static int m_text_next = NONE;
// score screen variables
public static boolean mb_skip_score = false; // pressed any key to skip score screen count up
public static boolean mb_high_score = false; // did you get a high score?
public static int m_unlocked = NONE; // something was unlocked?
// high score list
public static int m_highscore_type = Level.SCORE_ADVENTURE;
// level select list
public static int m_level_list_type = Level.TYPE_PUZZLE;
public static int m_level_list_start = 0; // the starting level for this level select page
public static int m_level_list_size = 1; // the total number of levels to list
// confirmation screen
public static int m_confirm_event = 0; // menu event that we want to bring up a confirmation menu for
// current window dimensions
public static int m_window_top;
public static int m_window_left;
public static int m_window_width;
public static int m_window_height;
public static boolean mb_go_back = false; // going back with left soft key
// General Menu parameters
public static boolean mb_menu_wraps = true;
public static boolean mb_use_main_menu = false;
public static int m_menu_item_y_space = MENU_ITEM_Y_SPACE;
// class initializer.
public static void poke() { Thread.yield(); }
/* clear all menus */
private static final void clearAllMenus() {
m_menu_item_pool_size = 0;
for (int i=0; i<NUM_MENUS; ++i) { m_menu_list_start[i] = 0; }
}
/* initialize a menu with some default values */
private static final void initMenu(int id) { initMenu(id, NONE, MENU_TYPE_NORMAL); }
private static final void initMenu(int id, int title, int type) {
m_menu_title[id] = (short)title;
m_menu_type[id] = (byte)type;
m_menu_list_start[id] = (id>=NUM_MENUS-1) ? (byte)m_menu_item_pool_size : m_menu_list_start[id+1];
}
/* initialize a menu item with some default values */
private static final void initMenuItem(int id) { initMenuItem(id, NONE, MENU_ITEM_TYPE_NORMAL, NONE, MENU_ITEM_STATE_NORMAL); }
private static final void initMenuItem(int id, int text, int type, int pointer) {
initMenuItem(id, text, type, pointer, MENU_ITEM_STATE_NORMAL);
}
private static final void initMenuItem(int id, int text, int type, int pointer, int state_flags) {
m_menu_item_text[id] = (short)text;
m_menu_item_type[id] = (byte)type;
//m_menu_item_state[id] = (byte)(MENU_ITEM_STATE_NORMAL & state_flags);
setMenuItemState(id, state_flags);
//m_menu_item_anim_state[id] = MENU_ITEM_ANIM_STATE_NORMAL;
m_menu_item_pointer[id] = (byte)pointer;
}
/* adds a menu item to a menu */
private static final void insertMenuItem(int menu_item_id, int menu_id) {
int pool_insert_position = m_menu_list_start[menu_id] + getListLength(menu_id);
// shift all of the following items in the pool forward by one
for (int j=m_menu_item_pool_size; j>pool_insert_position; --j) { m_menu_item_pool[j] = m_menu_item_pool[j-1]; }
// shift all list start references on all affected menus forward by one
for (int i=menu_id+1; i<NUM_MENUS; ++i) { m_menu_list_start[i]++; }
// insert the item into the pool
m_menu_item_pool[pool_insert_position] = (byte)menu_item_id;
// update the item pool size
m_menu_item_pool_size++;
}
/* removes all instances for a menu item from a menu */
private static final void removeMenuItem(int menu_item_id, int menu_id) {
for (int i=m_menu_list_start[menu_id]; i<m_menu_list_start[menu_id]+getListLength(menu_id); ++i) {
if (m_menu_item_pool[i] == menu_item_id) {
// shift all of the following items in the pool back by one
for (int j=i; j<m_menu_item_pool_size-1; ++j) { m_menu_item_pool[j] = m_menu_item_pool[j+1]; }
// shift all list start references on all affected menus back by one
for (int k=menu_id+1; k<NUM_MENUS; ++k) { m_menu_list_start[k]--; }
// update the item pool size
m_menu_item_pool_size--;
}
}
}
/* remove all menu items from a menu's list */
private static final void clearMenu(int menu_id) {
int list_length = getListLength(menu_id);
for (int i=0; i<list_length; ++i) removeMenuItem(getMenuItem(menu_id,0), menu_id);
}
/* Returns the position of the next selectable menu item for the specified menu. */
private static final int getNextItem(int menu_id, int current_item_position) {
return getNextItem(menu_id, current_item_position, MENU_ITEM_STATE_NORMAL);
}
private static final int getNextItem(int menu_id, int current_item_position, int state_flags) {
int list_length = getListLength(menu_id);
do {
if (++current_item_position >= list_length) {
if (mb_menu_wraps) current_item_position -= list_length;
else return current_item_position;
}
//} while ( !checkMenuItemState(getMenuItem(menu_id, current_item_position), state_flags) ); // find the next item that is selectable
} while ( checkMenuItemState(getMenuItem(menu_id, current_item_position), MENU_ITEM_STATE_INACTIVE) ); // find the next item that is selectable
return current_item_position;
}
/* Returns the position of the previous selectable menu item for the specified menu. */
private static final int getPrevItem(int menu_id, int current_item_position) {
return getPrevItem(menu_id, current_item_position, MENU_ITEM_STATE_NORMAL);
}
private static final int getPrevItem(int menu_id, int current_item_position, int state_flags) {
int list_length = getListLength(menu_id);
do {
if (--current_item_position < 0) {
if (mb_menu_wraps) current_item_position += list_length;
else return current_item_position;
}
//} while ( !checkMenuItemState(getMenuItem(menu_id, current_item_position), state_flags) ); // find the prev item that is selectable
} while ( checkMenuItemState(getMenuItem(menu_id, current_item_position), MENU_ITEM_STATE_INACTIVE) ); // find the next item that is selectable
return current_item_position;
}
/* return the length of a menu's item list */
private static final int getListLength(int menu_id) {
return (menu_id == NUM_MENUS-1) ? m_menu_item_pool_size - m_menu_list_start[menu_id] :
m_menu_list_start[menu_id+1] - m_menu_list_start[menu_id];
}
/* return the id of a menu item from this menu's list */
private static final int getMenuItem(int menu_id, int position) {
return m_menu_item_pool[m_menu_list_start[menu_id] + position];
}
/* return the position of the first selectable menu item from this menu's list */
private static final int getFirstMenuItem(int menu_id) {
int list_length = getListLength(menu_id);
for (int i=0; i<list_length; ++i) if (!checkMenuItemState(getMenuItem(menu_id, i), MENU_ITEM_STATE_INACTIVE)) return i;
return NONE;
}
// update scrolling bounds when pressing up
private static final void scrollUpMenu() {
m_menu_item_timer = 0;
if (m_next_menu_item <= m_next_menu_top) {
m_next_menu_top = m_next_menu_item;
return;
}
// if we have wrapped to the bottom
if (m_next_menu_item > m_current_menu_item) {
int top_position = m_next_menu_item - (getNumItemsDisplayed(m_current_menu, m_current_menu_top)-1);
m_next_menu_top = (top_position < 0) ? 0 : top_position;
}
}
// update scrolling bounds when pressing down
private static final void scrollDownMenu() {
m_menu_item_timer = 0;
// if we have wrapped to the top
if (m_next_menu_item < m_current_menu_item) {
m_next_menu_top = getScrollTop(m_current_menu);
return;
}
int top_position = m_next_menu_item - (getNumItemsDisplayed(m_current_menu, m_current_menu_top)-1);
if (top_position < 0) top_position = 0;
if (top_position >= m_current_menu_top) m_next_menu_top = top_position;
}
// return the initial scroll top position for this menu
private static final int getScrollTop(int menu_id) {
int num_display = getNumItemsDisplayed(menu_id, 0);
int scroll_top_position = getFirstMenuItem(menu_id) - (num_display-1);
return (scroll_top_position < 0) ? 0 : scroll_top_position;
}
// get the number of menu items we can display to fit the current menu height
private static final int getNumItemsDisplayed(int menu_id, int top_item_position) {
int height = 0;
int num_items = 0;
int item_id = getMenuItem(menu_id, top_item_position);
int max_height = getMenuMaxHeight(menu_id);
int list_length = getListLength(menu_id);
while (height+getMenuItemHeight(item_id) <= max_height) {
height += getMenuItemHeight(item_id);
num_items++;
top_item_position++;
item_id = getMenuItem(menu_id, top_item_position);
//if (item_id == getMenuItem(menu_id, 0)) break; // stop if wrapped
if (top_item_position >= list_length) break;
}
return num_items;
}
private static final void setMenuItemState(int menu_item_id, int state_flag) {
m_menu_item_state[menu_item_id] = (byte)(MENU_ITEM_STATE_NORMAL | state_flag);
}
private static final boolean checkMenuItemState(int menu_item_id, int state_flag) {
return (m_menu_item_state[menu_item_id] & state_flag) == state_flag;
}
/* set the next active menu */
public static final void setMenu(int menu_id) {
if (menu_id==NONE) return;
//#if DefaultConfiguration || Nokia_6600 || Nokia_6600_Unobfuscated || Nokia_3220 || Nokia_3220_Unobfuscated || Razr
if (menu_id == MENU_INGAME) Engine.pauseSound();
//#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -