mirror of
https://github.com/joel16/VitaShell.git
synced 2024-11-23 11:49:40 +00:00
Add new dialogbox (List Dialog) and make it default for START button
This commit is contained in:
parent
d9949d5100
commit
614d9d3f0e
2
Makefile
2
Makefile
@ -1,7 +1,7 @@
|
||||
TITLE_ID = VITASHELL
|
||||
TARGET = VitaShell
|
||||
OBJS = main.o init.o io_process.o package_installer.o network_update.o context_menu.o archive.o photo.o audioplayer.o file.o text.o hex.o sfo.o \
|
||||
uncommon_dialog.o message_dialog.o ime_dialog.o config.o theme.o language.o utils.o sha1.o \
|
||||
uncommon_dialog.o message_dialog.o ime_dialog.o config.o theme.o language.o utils.o sha1.o list_dialog.o \
|
||||
minizip/unzip.o minizip/ioapi.o bm.o audio/vita_audio.o audio/player.o audio/id3.o audio/oggplayer.o audio/mp3player.o audio/mp3xing.o \
|
||||
libmad/bit.o libmad/decoder.o libmad/fixed.o libmad/frame.o \
|
||||
libmad/huffman.o libmad/layer12.o libmad/layer3.o \
|
||||
|
@ -134,6 +134,8 @@ void loadLanguage(int id) {
|
||||
LANGUAGE_ENTRY(HASH_FILE_QUESTION),
|
||||
|
||||
// Others
|
||||
LANGUAGE_ENTRY(TOOLBOX),
|
||||
LANGUAGE_ENTRY(SYSINFO_TITLE),
|
||||
LANGUAGE_ENTRY(PLEASE_WAIT),
|
||||
LANGUAGE_ENTRY(SAVE_MODIFICATIONS),
|
||||
LANGUAGE_ENTRY(NO_SPACE_ERROR),
|
||||
|
@ -92,6 +92,8 @@ enum LanguageContainer {
|
||||
HASH_FILE_QUESTION,
|
||||
|
||||
// Others
|
||||
TOOLBOX,
|
||||
SYSINFO_TITLE,
|
||||
PLEASE_WAIT,
|
||||
SAVE_MODIFICATIONS,
|
||||
NO_SPACE_ERROR,
|
||||
|
170
list_dialog.c
Normal file
170
list_dialog.c
Normal file
@ -0,0 +1,170 @@
|
||||
/*
|
||||
VitaShell
|
||||
Copyright (C) 2015-2016, TheFloW
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
#include "init.h"
|
||||
#include "theme.h"
|
||||
#include "language.h"
|
||||
#include "utils.h"
|
||||
#include "list_dialog.h"
|
||||
|
||||
static int is_open = LIST_DIALOG_CLOSE;
|
||||
static List* current_list = NULL;
|
||||
static ListDialog list_dialog;
|
||||
static int max_entry_show = 0;
|
||||
static int base_pos = 0;
|
||||
static int rel_pos = 0;
|
||||
|
||||
int getListDialogMode()
|
||||
{
|
||||
return is_open;
|
||||
}
|
||||
|
||||
void loadListDialog(List* list) {
|
||||
base_pos = 0;
|
||||
rel_pos = 0;
|
||||
current_list = list;
|
||||
|
||||
list_dialog.height = 0.0f;
|
||||
list_dialog.width = 0.0f;
|
||||
|
||||
// Calculate max width
|
||||
int z;
|
||||
float width;
|
||||
for (z = 0;z < current_list->n_list_entries; z++)
|
||||
{
|
||||
width = vita2d_pgf_text_width(font, FONT_SIZE, language_container[current_list->list_entries[z].name]);
|
||||
if (width > list_dialog.width)
|
||||
list_dialog.width = width;
|
||||
}
|
||||
|
||||
width = vita2d_pgf_text_width(font, FONT_SIZE, language_container[current_list->title]);
|
||||
if (width > list_dialog.width)
|
||||
list_dialog.width = width;
|
||||
|
||||
// Calculate height
|
||||
int list_calc_height = current_list->n_list_entries;
|
||||
if (list_calc_height > LIST_MAX_ENTRY)
|
||||
list_calc_height = LIST_MAX_ENTRY;
|
||||
|
||||
max_entry_show = list_calc_height;
|
||||
|
||||
list_dialog.height = (SHELL_MARGIN_Y * 3) + (list_calc_height * SHELL_MARGIN_Y);
|
||||
|
||||
// Margin
|
||||
list_dialog.width += 2.0f * SHELL_MARGIN_X;
|
||||
list_dialog.height += 4.0f * SHELL_MARGIN_Y;
|
||||
|
||||
list_dialog.x = CENTER(SCREEN_WIDTH, list_dialog.width);
|
||||
list_dialog.y = CENTER(SCREEN_HEIGHT, list_dialog.height);
|
||||
list_dialog.scale = 0.0f;
|
||||
list_dialog.animation_mode = LIST_DIALOG_OPENING;
|
||||
list_dialog.status = SCE_COMMON_DIALOG_STATUS_RUNNING;
|
||||
|
||||
is_open = LIST_DIALOG_OPEN;
|
||||
}
|
||||
|
||||
float easeOut3(float x0, float x1, float a) {
|
||||
float dx = (x1 - x0);
|
||||
return ((dx * a) > 0.01f) ? (dx * a) : dx;
|
||||
}
|
||||
|
||||
void drawListDialog() {
|
||||
if (is_open == LIST_DIALOG_CLOSE)
|
||||
return;
|
||||
|
||||
// Dialog background
|
||||
vita2d_draw_texture_scale_rotate_hotspot(dialog_image, list_dialog.x + list_dialog.width / 2.0f,
|
||||
list_dialog.y + list_dialog.height / 2.0f,
|
||||
list_dialog.scale * (list_dialog.width / vita2d_texture_get_width(dialog_image)),
|
||||
list_dialog.scale * (list_dialog.height / vita2d_texture_get_height(dialog_image)),
|
||||
0.0f, vita2d_texture_get_width(dialog_image) / 2.0f, vita2d_texture_get_height(dialog_image) / 2.0f);
|
||||
|
||||
// Easing out
|
||||
if (list_dialog.animation_mode == LIST_DIALOG_CLOSING) {
|
||||
if (list_dialog.scale > 0.0f) {
|
||||
list_dialog.scale -= easeOut3(0.0f, list_dialog.scale, 0.25f);
|
||||
} else {
|
||||
list_dialog.animation_mode = LIST_DIALOG_CLOSED;
|
||||
list_dialog.status = SCE_COMMON_DIALOG_STATUS_FINISHED;
|
||||
}
|
||||
}
|
||||
|
||||
if (list_dialog.animation_mode == LIST_DIALOG_OPENING) {
|
||||
if (list_dialog.scale < 1.0f) {
|
||||
list_dialog.scale += easeOut3(list_dialog.scale, 1.0f, 0.25f);
|
||||
} else {
|
||||
list_dialog.animation_mode = LIST_DIALOG_OPENED;
|
||||
}
|
||||
}
|
||||
|
||||
if (list_dialog.animation_mode == LIST_DIALOG_OPENED) {
|
||||
pgf_draw_text(list_dialog.x + CENTER(list_dialog.width, vita2d_pgf_text_width(font, FONT_SIZE, language_container[current_list->title])), list_dialog.y + FONT_Y_SPACE, TEXT_COLOR, FONT_SIZE, language_container[current_list->title]);
|
||||
|
||||
int z;
|
||||
for (z = 0;z < LIST_MAX_ENTRY && (base_pos + z) < current_list->n_list_entries; z++) {
|
||||
uint32_t color = (rel_pos == z) ? TEXT_FOCUS_COLOR : TEXT_COLOR;
|
||||
pgf_draw_text(list_dialog.x + CENTER(list_dialog.width, vita2d_pgf_text_width(font, FONT_SIZE, language_container[current_list->list_entries[(z + base_pos)].name])), list_dialog.y + (FONT_Y_SPACE * 3) + (FONT_Y_SPACE * z), color, FONT_SIZE, language_container[current_list->list_entries[(z + base_pos)].name]);
|
||||
}
|
||||
|
||||
int max_base_pos = current_list->n_list_entries - LIST_MAX_ENTRY;
|
||||
if (base_pos < max_base_pos && current_list->n_list_entries > LIST_MAX_ENTRY) {
|
||||
pgf_draw_text(list_dialog.x + CENTER(list_dialog.width, vita2d_pgf_text_width(font, FONT_SIZE, DOWN_ARROW)), list_dialog.y + (FONT_Y_SPACE * 3) + (FONT_Y_SPACE * max_entry_show), TEXT_COLOR, FONT_SIZE, DOWN_ARROW);
|
||||
}
|
||||
|
||||
if (base_pos > 0 && current_list->n_list_entries > LIST_MAX_ENTRY) {
|
||||
pgf_draw_text(list_dialog.x + CENTER(list_dialog.width, vita2d_pgf_text_width(font, FONT_SIZE, UP_ARROW)), list_dialog.y + (FONT_Y_SPACE * 2), TEXT_COLOR, FONT_SIZE, UP_ARROW);
|
||||
}
|
||||
} else if (list_dialog.animation_mode == LIST_DIALOG_CLOSED) {
|
||||
is_open = LIST_DIALOG_CLOSE;
|
||||
}
|
||||
}
|
||||
|
||||
void listDialogCtrl() {
|
||||
if (is_open == LIST_DIALOG_CLOSE)
|
||||
return;
|
||||
|
||||
if (pressed_buttons & SCE_CTRL_CANCEL && current_list->can_escape)
|
||||
list_dialog.animation_mode = LIST_DIALOG_CLOSING;
|
||||
|
||||
if (pressed_buttons & SCE_CTRL_CROSS) {
|
||||
if (current_list->listSelectCallback)
|
||||
if (current_list->listSelectCallback(base_pos + rel_pos) == LIST_CALL_CLOSE)
|
||||
list_dialog.animation_mode = LIST_DIALOG_CLOSING;
|
||||
}
|
||||
|
||||
if (hold_buttons & SCE_CTRL_UP || hold2_buttons & SCE_CTRL_LEFT_ANALOG_UP) {
|
||||
if (rel_pos > 0) {
|
||||
rel_pos--;
|
||||
} else {
|
||||
if (base_pos > 0) {
|
||||
base_pos--;
|
||||
}
|
||||
}
|
||||
} else if (hold_buttons & SCE_CTRL_DOWN || hold2_buttons & SCE_CTRL_LEFT_ANALOG_DOWN) {
|
||||
if ((rel_pos + 1) < current_list->n_list_entries) {
|
||||
if ((rel_pos + 1) < LIST_MAX_ENTRY) {
|
||||
rel_pos++;
|
||||
} else {
|
||||
if ((base_pos + rel_pos + 1) < current_list->n_list_entries) {
|
||||
base_pos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
75
list_dialog.h
Normal file
75
list_dialog.h
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
VitaShell
|
||||
Copyright (C) 2015-2016, TheFloW
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __LIST_DIALOG_H__
|
||||
#define __LIST_DIALOG_H__
|
||||
|
||||
#define CENTER(a, b) (((a) - (b)) / 2)
|
||||
#define LIST_MAX_ENTRY 5
|
||||
|
||||
#define UP_ARROW "\xe2\x96\xb2"
|
||||
#define DOWN_ARROW "\xe2\x96\xbc"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int animation_mode;
|
||||
int status;
|
||||
float x;
|
||||
float y;
|
||||
float width;
|
||||
float height;
|
||||
float scale;
|
||||
} ListDialog;
|
||||
|
||||
typedef struct {
|
||||
int name;
|
||||
} ListEntry;
|
||||
|
||||
typedef struct {
|
||||
int title;
|
||||
ListEntry *list_entries;
|
||||
int n_list_entries;
|
||||
int can_escape;
|
||||
int (* listSelectCallback)(int pos);
|
||||
} List;
|
||||
|
||||
enum ListDialogState
|
||||
{
|
||||
LIST_DIALOG_OPEN,
|
||||
LIST_DIALOG_CLOSE
|
||||
};
|
||||
|
||||
enum ListDialogCall
|
||||
{
|
||||
LIST_CALL_NONE,
|
||||
LIST_CALL_CLOSE
|
||||
};
|
||||
|
||||
enum ListAnimationMode {
|
||||
LIST_DIALOG_CLOSED,
|
||||
LIST_DIALOG_CLOSING,
|
||||
LIST_DIALOG_OPENED,
|
||||
LIST_DIALOG_OPENING,
|
||||
};
|
||||
|
||||
int getListDialogMode();
|
||||
void loadListDialog(List* list);
|
||||
void drawListDialog();
|
||||
void listDialogCtrl();
|
||||
|
||||
#endif
|
101
main.c
101
main.c
@ -44,6 +44,7 @@
|
||||
#include "language.h"
|
||||
#include "utils.h"
|
||||
#include "sfo.h"
|
||||
#include "list_dialog.h"
|
||||
|
||||
#include "audio/vita_audio.h"
|
||||
|
||||
@ -83,6 +84,8 @@ int SCE_CTRL_ENTER = SCE_CTRL_CROSS, SCE_CTRL_CANCEL = SCE_CTRL_CIRCLE;
|
||||
// Dialog step
|
||||
volatile int dialog_step = DIALOG_STEP_NONE;
|
||||
|
||||
static List toolbox_list;
|
||||
|
||||
// Use custom config
|
||||
int use_custom_config = 1;
|
||||
|
||||
@ -469,6 +472,16 @@ MenuEntry menu_more_entries[] = {
|
||||
|
||||
#define N_MENU_MORE_ENTRIES (sizeof(menu_more_entries) / sizeof(MenuEntry))
|
||||
|
||||
enum ListToolboxEntrys {
|
||||
LIST_TOOLBOX_ENTRY_SYSINFO,
|
||||
};
|
||||
|
||||
ListEntry list_toolbox_entries[] = {
|
||||
{ SYSINFO_TITLE },
|
||||
};
|
||||
|
||||
#define N_LIST_TOOLBOX_ENTRIES (sizeof(list_toolbox_entries) / sizeof(ListEntry))
|
||||
|
||||
void setContextMenuVisibilities() {
|
||||
int i;
|
||||
|
||||
@ -595,6 +608,49 @@ void setContextMenuMoreVisibilities() {
|
||||
setContextMenuMorePos(-1);
|
||||
}
|
||||
|
||||
int listToolboxEnterCallback(int pos) {
|
||||
switch (pos) {
|
||||
case LIST_TOOLBOX_ENTRY_SYSINFO:
|
||||
{
|
||||
// System software version
|
||||
SceSystemSwVersionParam sw_ver_param;
|
||||
sw_ver_param.size = sizeof(SceSystemSwVersionParam);
|
||||
sceKernelGetSystemSwVersion(&sw_ver_param);
|
||||
|
||||
// MAC address
|
||||
SceNetEtherAddr mac;
|
||||
sceNetGetMacAddress(&mac, 0);
|
||||
|
||||
char mac_string[32];
|
||||
sprintf(mac_string, "%02X:%02X:%02X:%02X:%02X:%02X", mac.data[0], mac.data[1], mac.data[2], mac.data[3], mac.data[4], mac.data[5]);
|
||||
|
||||
// Get IP
|
||||
char ip[16];
|
||||
|
||||
SceNetCtlInfo info;
|
||||
if (sceNetCtlInetGetInfo(SCE_NETCTL_INFO_GET_IP_ADDRESS, &info) < 0) {
|
||||
strcpy(ip, "-");
|
||||
} else {
|
||||
strcpy(ip, info.ip_address);
|
||||
}
|
||||
|
||||
// Memory card
|
||||
uint64_t free_size = 0, max_size = 0;
|
||||
sceAppMgrGetDevInfo("ux0:", &max_size, &free_size);
|
||||
|
||||
char free_size_string[16], max_size_string[16];
|
||||
getSizeString(free_size_string, free_size);
|
||||
getSizeString(max_size_string, max_size);
|
||||
|
||||
// System information dialog
|
||||
initMessageDialog(SCE_MSG_DIALOG_BUTTON_TYPE_OK, language_container[SYS_INFO], sw_ver_param.version_string, sceKernelGetModelForCDialog(), mac_string, ip, free_size_string, max_size_string, scePowerGetBatteryLifePercent());
|
||||
dialog_step = DIALOG_STEP_SYSTEM;
|
||||
}
|
||||
}
|
||||
|
||||
return LIST_DIALOG_CLOSE;
|
||||
}
|
||||
|
||||
int contextMenuEnterCallback(int pos, void* context) {
|
||||
switch (pos) {
|
||||
case MENU_ENTRY_MARK_UNMARK_ALL:
|
||||
@ -1189,41 +1245,17 @@ int dialogSteps() {
|
||||
}
|
||||
|
||||
void fileBrowserMenuCtrl() {
|
||||
// System information
|
||||
// Show toolbox list dialog
|
||||
if (current_buttons & SCE_CTRL_START) {
|
||||
// System software version
|
||||
SceSystemSwVersionParam sw_ver_param;
|
||||
sw_ver_param.size = sizeof(SceSystemSwVersionParam);
|
||||
sceKernelGetSystemSwVersion(&sw_ver_param);
|
||||
if (getListDialogMode() == LIST_DIALOG_CLOSE) {
|
||||
toolbox_list.title = TOOLBOX;
|
||||
toolbox_list.list_entries = list_toolbox_entries;
|
||||
toolbox_list.n_list_entries = N_LIST_TOOLBOX_ENTRIES;
|
||||
toolbox_list.can_escape = 1;
|
||||
toolbox_list.listSelectCallback = listToolboxEnterCallback;
|
||||
|
||||
// MAC address
|
||||
SceNetEtherAddr mac;
|
||||
sceNetGetMacAddress(&mac, 0);
|
||||
|
||||
char mac_string[32];
|
||||
sprintf(mac_string, "%02X:%02X:%02X:%02X:%02X:%02X", mac.data[0], mac.data[1], mac.data[2], mac.data[3], mac.data[4], mac.data[5]);
|
||||
|
||||
// Get IP
|
||||
char ip[16];
|
||||
|
||||
SceNetCtlInfo info;
|
||||
if (sceNetCtlInetGetInfo(SCE_NETCTL_INFO_GET_IP_ADDRESS, &info) < 0) {
|
||||
strcpy(ip, "-");
|
||||
} else {
|
||||
strcpy(ip, info.ip_address);
|
||||
loadListDialog(&toolbox_list);
|
||||
}
|
||||
|
||||
// Memory card
|
||||
uint64_t free_size = 0, max_size = 0;
|
||||
sceAppMgrGetDevInfo("ux0:", &max_size, &free_size);
|
||||
|
||||
char free_size_string[16], max_size_string[16];
|
||||
getSizeString(free_size_string, free_size);
|
||||
getSizeString(max_size_string, max_size);
|
||||
|
||||
// System information dialog
|
||||
initMessageDialog(SCE_MSG_DIALOG_BUTTON_TYPE_OK, language_container[SYS_INFO], sw_ver_param.version_string, sceKernelGetModelForCDialog(), mac_string, ip, free_size_string, max_size_string, scePowerGetBatteryLifePercent());
|
||||
dialog_step = DIALOG_STEP_SYSTEM;
|
||||
}
|
||||
|
||||
// FTP
|
||||
@ -1431,6 +1463,8 @@ int shellMain() {
|
||||
if (dialog_step == DIALOG_STEP_NONE) {
|
||||
if (getContextMenuMode() != CONTEXT_MENU_CLOSED) {
|
||||
contextMenuCtrl(&context_menu);
|
||||
} else if (getListDialogMode() != LIST_DIALOG_CLOSE) {
|
||||
listDialogCtrl();
|
||||
} else {
|
||||
fileBrowserMenuCtrl();
|
||||
}
|
||||
@ -1588,6 +1622,9 @@ int shellMain() {
|
||||
// Draw context menu
|
||||
drawContextMenu(&context_menu);
|
||||
|
||||
// Draw list dialog
|
||||
drawListDialog();
|
||||
|
||||
// End drawing
|
||||
endDrawing();
|
||||
}
|
||||
|
@ -78,4 +78,6 @@ NO_SPACE_ERROR = "There is not enough free space on the me
|
||||
WIFI_ERROR = "You must use Wi-Fi to do this."
|
||||
FTP_SERVER = "FTP server is now running at\ftp://%s:%i\\Press 'OK' to keep it in background.\Press 'Cancel' to disconnect."
|
||||
SYS_INFO = "System software: %s\Model: 0x%08X\MAC address: %s\IP address: %s\Memory card: %s/%s\Battery level: %d%%"
|
||||
UPDATE_QUESTION = "VitaShell %s is now available.\\Do you want to update the application?"
|
||||
UPDATE_QUESTION = "VitaShell %s is now available.\\Do you want to update the application?"
|
||||
TOOLBOX = "Toolbox"
|
||||
SYSINFO_TITLE = "System Information"
|
Loading…
Reference in New Issue
Block a user