Menu Preparations

This commit is contained in:
Andre Schweiger 2017-01-30 12:40:07 +01:00
parent a014be2c5a
commit c107f82abb
8 changed files with 327 additions and 206 deletions

View file

@ -28,6 +28,7 @@
#define MENU_SETTINGS_TP 13 #define MENU_SETTINGS_TP 13
#define MENU_DUNGEON 14 #define MENU_DUNGEON 14
#define MENU_NPC 15 #define MENU_NPC 15
#define MENU_MULTIPLAYER 16
#define NPC_GIRL 0 #define NPC_GIRL 0
#define NPC_PRIEST 1 #define NPC_PRIEST 1
@ -136,6 +137,7 @@ char* currentCraftTitle;
s16 curInvSel; s16 curInvSel;
bool quitGame; bool quitGame;
s8 currentSelection; s8 currentSelection;
bool isRemote;
u16 daytime; u16 daytime;
int day; int day;

View file

@ -1,7 +1,7 @@
#include "Menu.h" #include "Menu.h"
char options[][12] = {"Start Game", "How To Play","Settings", "About", "Exit"}; char options[][12] = {"Start Game", "Join Game", "How To Play","Settings", "About", "Exit"};
char pOptions[][24] = {"Return to game", "Save Progress", "Exit to title"}; char pOptions[][24] = {"Return to game", "Save Progress", "Host World", "Exit to title"};
char keybOptions[][24] = {"Exit and Save", "Exit and Don't save","Reset to default"}; char keybOptions[][24] = {"Exit and Save", "Exit and Don't save","Reset to default"};
char setOptions[][24] = {"Rebind Buttons", "Texture packs", "Debug Text: ", "N3DS Speedup: ", "Return to title"}; char setOptions[][24] = {"Rebind Buttons", "Texture packs", "Debug Text: ", "N3DS Speedup: ", "Return to title"};
@ -380,8 +380,8 @@ void tickMenu(int menu){
if(!areYouSure && !areYouSureSave){ if(!areYouSure && !areYouSureSave){
if(pauseSaveDisplayTimer > 0) --pauseSaveDisplayTimer; if(pauseSaveDisplayTimer > 0) --pauseSaveDisplayTimer;
if (k_pause.clicked || k_decline.clicked) currentMenu = MENU_NONE; if (k_pause.clicked || k_decline.clicked) currentMenu = MENU_NONE;
if (k_up.clicked){ --currentSelection; if(currentSelection < 0)currentSelection=2;} if (k_up.clicked){ --currentSelection; if(currentSelection < 0)currentSelection=3;}
if (k_down.clicked){ ++currentSelection; if(currentSelection > 2)currentSelection=0;} if (k_down.clicked){ ++currentSelection; if(currentSelection > 3)currentSelection=0;}
if (k_accept.clicked){ if (k_accept.clicked){
switch(currentSelection){ switch(currentSelection){
case 0: case 0:
@ -391,6 +391,10 @@ void tickMenu(int menu){
if(currentLevel!=5) areYouSureSave = true; if(currentLevel!=5) areYouSureSave = true;
break; break;
case 2: case 2:
networkHost();
currentMenu = MENU_NONE;
break;
case 3:
areYouSure = true; areYouSure = true;
break; break;
} }
@ -413,6 +417,8 @@ void tickMenu(int menu){
currentSelection = 0; currentSelection = 0;
currentMenu = MENU_TITLE; currentMenu = MENU_TITLE;
networkDisconnect();
playMusic(music_menu); playMusic(music_menu);
} else if (k_decline.clicked){ } else if (k_decline.clicked){
areYouSure = false; areYouSure = false;
@ -565,6 +571,7 @@ void tickMenu(int menu){
playSound(snd_test); playSound(snd_test);
initGame = 1; initGame = 1;
currentMenu = MENU_NONE; currentMenu = MENU_NONE;
isRemote = false;
} }
} }
} else if (areYouSure){ } else if (areYouSure){
@ -588,6 +595,7 @@ void tickMenu(int menu){
playSound(snd_test); playSound(snd_test);
initGame = 2; initGame = 2;
++worldFileCount; ++worldFileCount;
isRemote = false;
} }
} }
if((k_touch.px != 0 || k_touch.py != 0) && touchDelay == 0){ if((k_touch.px != 0 || k_touch.py != 0) && touchDelay == 0){
@ -636,7 +644,7 @@ void tickMenu(int menu){
} }
if(k_decline.clicked){ if(k_decline.clicked){
currentMenu = MENU_TITLE; currentMenu = MENU_TITLE;
currentSelection = 2; currentSelection = 3;
} }
if(k_accept.clicked){ if(k_accept.clicked){
switch(currentSelection){ switch(currentSelection){
@ -708,8 +716,8 @@ void tickMenu(int menu){
} }
} }
if (k_up.clicked){ --currentSelection; if(currentSelection < 0)currentSelection=4;} if (k_up.clicked){ --currentSelection; if(currentSelection < 0)currentSelection=5;}
if (k_down.clicked){ ++currentSelection; if(currentSelection > 4)currentSelection=0;} if (k_down.clicked){ ++currentSelection; if(currentSelection > 5)currentSelection=0;}
if(k_accept.clicked){ if(k_accept.clicked){
switch(currentSelection){ switch(currentSelection){
@ -721,17 +729,21 @@ void tickMenu(int menu){
areYouSure = false; areYouSure = false;
break; break;
case 1: case 1:
currentMenu = MENU_MULTIPLAYER;
currentSelection = 0;
break;
case 2:
sprintf(pageText,"Page: %d/%d",pageNum+1,maxPageNum+1); sprintf(pageText,"Page: %d/%d",pageNum+1,maxPageNum+1);
currentMenu = MENU_TUTORIAL; currentMenu = MENU_TUTORIAL;
break; break;
case 2: case 3:
currentSelection = 0; currentSelection = 0;
currentMenu = MENU_SETTINGS; currentMenu = MENU_SETTINGS;
break; break;
case 3: case 4:
currentMenu = MENU_ABOUT; currentMenu = MENU_ABOUT;
break; break;
case 4: case 5:
quitGame = true; quitGame = true;
break; break;
} }
@ -740,7 +752,7 @@ void tickMenu(int menu){
break; break;
case MENU_TUTORIAL: case MENU_TUTORIAL:
if(k_decline.clicked){ if(k_decline.clicked){
currentSelection = 1; currentSelection = 2;
currentMenu = MENU_TITLE; currentMenu = MENU_TITLE;
} }
if(k_menuNext.clicked){ if(k_menuNext.clicked){
@ -760,6 +772,25 @@ void tickMenu(int menu){
case MENU_NPC: case MENU_NPC:
tickNPCMenu(); tickNPCMenu();
break; break;
case MENU_MULTIPLAYER:
networkScan();
if (k_decline.clicked){
currentMenu = MENU_TITLE;
currentSelection = 1;
}
if (k_up.clicked){ --currentSelection; if(currentSelection < 0) currentSelection = (networkGetScanCount()>0 ? networkGetScanCount()-1 : 0);}
if (k_down.clicked){ ++currentSelection; if(currentSelection >= networkGetScanCount()) currentSelection=0;}
if(k_accept.clicked){
//TODO: Join World
if(networkConnect(currentSelection)) {
initGame = 1;
currentMenu = MENU_NONE;
isRemote = true;
}
}
break;
} }
} }
@ -1064,7 +1095,7 @@ void renderMenu(int menu,int xscr,int yscr){
offsetX = 0;offsetY = 0; offsetX = 0;offsetY = 0;
renderFrame(1,1,24,14,0xFF1010AF); renderFrame(1,1,24,14,0xFF1010AF);
drawText("Paused",164,32); drawText("Paused",164,32);
for(i = 2; i >= 0; --i){ for(i = 3; i >= 0; --i){
char* msg = pOptions[i]; char* msg = pOptions[i];
u32 color = 0xFF7F7F7F; u32 color = 0xFF7F7F7F;
if(i == currentSelection) color = 0xFFFFFFFF; if(i == currentSelection) color = 0xFFFFFFFF;
@ -1072,7 +1103,7 @@ void renderMenu(int menu,int xscr,int yscr){
color = 0xFF7F7FFF; color = 0xFF7F7FFF;
if(i == currentSelection) color = 0xFFAFAFFF; if(i == currentSelection) color = 0xFFAFAFFF;
} }
drawTextColor(msg,(400 - (strlen(msg) * 12))/2, (i * 24) + 100, color); drawTextColor(msg,(400 - (strlen(msg) * 12))/2, (i * 24) + 88, color);
} }
if(pauseSaveDisplayTimer > 0) drawTextColor("Game Saved!", (400-(11*12))/2, 64,0xFF20FF20); if(pauseSaveDisplayTimer > 0) drawTextColor("Game Saved!", (400-(11*12))/2, 64,0xFF20FF20);
@ -1355,12 +1386,12 @@ void renderMenu(int menu,int xscr,int yscr){
renderTitle(76,16); renderTitle(76,16);
for(i = 4; i >= 0; --i){ for(i = 5; i >= 0; --i){
char* msg = options[i]; char* msg = options[i];
u32 color = 0xFF7F7F7F; u32 color = 0xFF7F7F7F;
if(i == currentSelection) color = 0xFFFFFFFF; if(i == currentSelection) color = 0xFFFFFFFF;
drawSizedTextColor(msg,((200 - (strlen(msg) * 8))/2) + 1, (((8 + i) * 20 - 50) >> 1) + 1,2.0, 0xFF000000); drawSizedTextColor(msg,((200 - (strlen(msg) * 8))/2) + 1, (((8 + i) * 20 - 58) >> 1) + 1,2.0, 0xFF000000);
drawSizedTextColor(msg,(200 - (strlen(msg) * 8))/2, ((8 + i) * 20 - 50) >> 1,2.0, color); drawSizedTextColor(msg,(200 - (strlen(msg) * 8))/2, ((8 + i) * 20 - 58) >> 1,2.0, color);
} }
drawText(versionText,2,225); drawText(versionText,2,225);
@ -1382,7 +1413,9 @@ void renderMenu(int menu,int xscr,int yscr){
switch(currentSelection){ switch(currentSelection){
case 0: // "Start Game" case 0: // "Start Game"
break; break;
case 1: // "How To Play" case 1: // "Join Game"
break;
case 2: // "How To Play"
startX = 72;startY = 54; startX = 72;startY = 54;
render16(startX,startY,96,208,0);//C-PAD render16(startX,startY,96,208,0);//C-PAD
startX = 72;startY = 37; startX = 72;startY = 37;
@ -1399,11 +1432,11 @@ void renderMenu(int menu,int xscr,int yscr){
render16(startX,startY,160,208,0);//C-PAD right render16(startX,startY,160,208,0);//C-PAD right
drawTextColor("Learn the basics",64,24,0xFF7FFFFF); drawTextColor("Learn the basics",64,24,0xFF7FFFFF);
break; break;
case 2: // "Settings" case 3: // "Settings"
drawTextColor("Modify the game's feel",(320 - (22 * 12))/2,24,0xFF7FFFFF); drawTextColor("Modify the game's feel",(320 - (22 * 12))/2,24,0xFF7FFFFF);
renderc(48,48,0,112,64,32,0); renderc(48,48,0,112,64,32,0);
break; break;
case 3: // "About" case 4: // "About"
drawTextColor("Who made this game?",(320 - (19 * 12))/2,24,0xFF7FFFFF); drawTextColor("Who made this game?",(320 - (19 * 12))/2,24,0xFF7FFFFF);
// Secret code ;) // Secret code ;)
@ -1419,7 +1452,7 @@ void renderMenu(int menu,int xscr,int yscr){
//drawSizedText("(Totally not a secret code or anything)",4,160,1); //drawSizedText("(Totally not a secret code or anything)",4,160,1);
break; break;
case 4: // "Exit" case 5: // "Exit"
drawTextColor("Exit to the homebrew menu",(320 - (25 * 12))/2,24,0xFF7FFFFF); drawTextColor("Exit to the homebrew menu",(320 - (25 * 12))/2,24,0xFF7FFFFF);
drawTextColor("(bye-bye)",(320 - (9 * 12))/2,100,0xFF7FFFFF); drawTextColor("(bye-bye)",(320 - (9 * 12))/2,100,0xFF7FFFFF);
break; break;
@ -1439,6 +1472,41 @@ void renderMenu(int menu,int xscr,int yscr){
renderNPCMenu(xscr, yscr); renderNPCMenu(xscr, yscr);
sf2d_end_frame(); sf2d_end_frame();
break; break;
case MENU_MULTIPLAYER:
sf2d_start_frame(GFX_TOP, GFX_LEFT);
sf2d_draw_rectangle(0, 0, 400, 240, 0xFF0C0C0C); //You might think "real" black would be better, but it actually looks better that way
offsetX = 0;offsetY = (currentSelection * 32) - 48;
drawText("Select a world",122,-16);
for(i = 0; i < networkGetScanCount(); ++i){
int color = 0xFF921020;
char * text = malloc((50+8+1) * sizeof(char));
memset(text, 0, (50+8+1) * sizeof(char));
networkGetScanName(text, i);
strcpy(text, "'s World");
if(i != currentSelection) color &= 0xFF7F7F7F; // Darken color.
renderFrame(1,i*4,24,(i*4)+4,color);
drawText(text,(400-(strlen(text)*12))/2,i*64+24);
free(text);
}
offsetX = 0;offsetY = 0;
sf2d_end_frame();
sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
sf2d_draw_rectangle(0, 0, 320, 240, 0xFF0C0C0C); //You might think "real" black would be better, but it actually looks better that way
drawTextColor("Searching for Worlds",40,12,0xFF3FFFFF);
drawText("Press or to scroll", 28, 50);
renderButtonIcon(k_up.input & -k_up.input, 98, 48, 1);
renderButtonIcon(k_down.input & -k_down.input, 160, 48, 1);
drawText("Press to join world", (320-21*12)/2, 100);
renderButtonIcon(k_accept.input & -k_accept.input, 104, 98, 1);
drawText("Press to return", 58, 150);
renderButtonIcon(k_decline.input & -k_decline.input, 128, 148, 1);
sf2d_end_frame();
break;
} }
} }

View file

@ -3,6 +3,7 @@
#include "MenuTutorial.h" #include "MenuTutorial.h"
#include "texturepack.h" #include "texturepack.h"
#include "Quests.h" #include "Quests.h"
#include "Network.h"
void initMenus(); void initMenus();

View file

@ -1,5 +1,6 @@
#include "Network.h" #include "Network.h"
#include "PacketHandler.h"
#include <stdlib.h> #include <stdlib.h>
#include <malloc.h> #include <malloc.h>
#include <string.h> #include <string.h>
@ -186,10 +187,7 @@ void networkRecieve() {
if(actualSize) { if(actualSize) {
networkPacket *packet = (networkPacket*) networkBuffer; networkPacket *packet = (networkPacket*) networkBuffer;
//TODO: Differenciate the packets and process them processPacket(packet, packet->analyze.type);
if(packet->analyze.type==0) {
}
} }
} }
} }

View file

@ -10,15 +10,36 @@
#define NETWORK_MAXPLAYERS UDS_MAXNODES #define NETWORK_MAXPLAYERS UDS_MAXNODES
//packet type ids
#define PACKET_REQUEST_MAPDATA 1
#define PACKET_MAPDATA 2
//TODO: Every other packet struct should start with a u8 type to match this //TODO: Every other packet struct should start with a u8 type to match this
typedef struct { typedef struct {
u8 type; u8 type;
} packetAnalyze; } packetAnalyze;
typedef struct {
u8 type;
u8 level;
} packetRequestMapData;
typedef struct {
u8 type;
u8 level;
u8 offset; //-> data is at offset*128 to offset*128+127
u8 map[128];
u8 data[128];
} packetMapData;
typedef struct { typedef struct {
union { union {
packetAnalyze analyze; packetAnalyze analyze;
packetRequestMapData requestMapData;
packetMapData mapData;
}; };
} networkPacket; } networkPacket;

10
source/PacketHandler.c Normal file
View file

@ -0,0 +1,10 @@
#include "PacketHandler.h"
void processPacket(networkPacket *packet, u8 type) {
//TODO: Differenciate the packets and process them
if(type==PACKET_REQUEST_MAPDATA) {
} else if(type==PACKET_MAPDATA) {
}
}

5
source/PacketHandler.h Normal file
View file

@ -0,0 +1,5 @@
#pragma once
#include "Network.h"
void processPacket(networkPacket *packet, u8 type);

View file

@ -41,7 +41,7 @@ void initNewMap() {
createAndValidateUndergroundMap(128, 128, 3, 4, map[4], data[4]); createAndValidateUndergroundMap(128, 128, 3, 4, map[4], data[4]);
} }
void setupGame(bool loadUpWorld) { void setupGame(bool loadUpWorld, bool remote) {
currentLevel = 1; currentLevel = 1;
// Reset entity manager. // Reset entity manager.
@ -50,6 +50,7 @@ void setupGame(bool loadUpWorld) {
initMiniMapData(); initMiniMapData();
if(!remote) {
if (!loadUpWorld) { if (!loadUpWorld) {
initNewMap(); initNewMap();
initPlayer(); initPlayer();
@ -73,6 +74,17 @@ void setupGame(bool loadUpWorld) {
updateMusic(currentLevel, daytime); updateMusic(currentLevel, daytime);
initMiniMap(loadUpWorld); initMiniMap(loadUpWorld);
} else {
//TODO: Can Packets get dropped - if yes, should resending be handled by network functions (so I dont need to do it everywhere)
networkPacket packet = {
.requestMapData = {
.type = PACKET_REQUEST_MAPDATA,
.level = 1
}
};
networkSend(&packet, sizeof(packetRequestMapData));
}
shouldRenderMap = false; shouldRenderMap = false;
mScrollX = 0; mScrollX = 0;
mScrollY = 0; mScrollY = 0;
@ -102,6 +114,8 @@ void setupBGMap(bool loadUpWorld) {
int xscr = 0, yscr = 0; int xscr = 0, yscr = 0;
void tick() { void tick() {
//TODO: Some stuff DOES need to happen even on client side
if(!isRemote) {
if (player.p.isDead) { if (player.p.isDead) {
if (player.p.endTimer < 1) { if (player.p.endTimer < 1) {
currentMenu = MENU_LOSE; currentMenu = MENU_LOSE;
@ -167,7 +181,7 @@ void tick() {
|| (e->x > player.x - 160 && e->y > player.y - 125 && e->x < player.x + 160 && e->y < player.y + 125)) || (e->x > player.x - 160 && e->y > player.y - 125 && e->x < player.x + 160 && e->y < player.y + 125))
tickEntity(e); tickEntity(e);
} }
}
} }
char debugText[34]; char debugText[34];
@ -265,9 +279,11 @@ int main() {
if (quitGame) break; if (quitGame) break;
if (initGame > 0) setupGame(initGame == 1 ? true : false); if (initGame > 0) setupGame(initGame == 1 ? true : false, isRemote);
if (initBGMap > 0) setupBGMap(initBGMap == 1 ? true : false); if (initBGMap > 0) setupBGMap(initBGMap == 1 ? true : false);
networkRecieve();
if (currentMenu == 0) { if (currentMenu == 0) {
tick(); tick();
sf2d_start_frame(GFX_TOP, GFX_LEFT); sf2d_start_frame(GFX_TOP, GFX_LEFT);