Skip to content

Commit

Permalink
Re-construct menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Alx-Lai authored and john0312 committed Aug 17, 2024
1 parent 91d10a4 commit 2524d93
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions fw/Core/Hitcon/App/BadUsbApp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ void BadUsbApp::OnExit() { g_usb_logic.StopScript(); }
void BadUsbApp::OnButton(button_t button) {
switch (button & BUTTON_VALUE_MASK) {
case BUTTON_BACK:
badge_controller.OnAppEnd(this);
badge_controller.BackToMenu(this);
break;
}
}

void BadUsbApp::OnScriptFinished(void *unsed) {
badge_controller.OnAppEnd(this);
badge_controller.BackToMenu(this);
}
} // namespace usb
} // namespace hitcon
6 changes: 2 additions & 4 deletions fw/Core/Hitcon/App/ConnectMenuApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ class ConnectMenuApp : public MenuApp {
public:
ConnectMenuApp() : MenuApp(connect_menu_entries, connect_menu_entries_len) {}
void OnButtonMode() override {}
void OnButtonBack() override { badge_controller.change_app(&show_name_app); }
void OnButtonLongBack() override {
badge_controller.change_app(&show_name_app);
}
void OnButtonBack() override {}
void OnButtonLongBack() override {}
};

extern ConnectMenuApp connect_menu;
Expand Down
4 changes: 1 addition & 3 deletions fw/Core/Hitcon/App/DinoApp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ void DinoApp::OnButton(button_t button) {

switch (button & BUTTON_VALUE_MASK) {
case BUTTON_BACK:
badge_controller.change_app(&main_menu);
break;
case BUTTON_LONG_BACK:
badge_controller.change_app(&show_name_app);
badge_controller.BackToMenu(this);
break;
default:
break;
Expand Down
15 changes: 13 additions & 2 deletions fw/Core/Hitcon/App/ShowNameApp.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ShowNameApp.h"

#include <App/ConnectMenuApp.h>
#include <App/MainMenuApp.h>
#include <App/NameSettingApp.h>
#include <Logic/BadgeController.h>
Expand All @@ -15,6 +16,8 @@

using namespace hitcon::service::sched;
using hitcon::game::gameLogic;
using hitcon::service::xboard::g_xboard_logic;
using hitcon::service::xboard::UsartConnectState;

namespace hitcon {

Expand Down Expand Up @@ -59,11 +62,19 @@ void ShowNameApp::OnExit() {
void ShowNameApp::OnButton(button_t button) {
switch (button) {
case BUTTON_LONG_MODE:
badge_controller.change_app(&name_setting_menu);
if (g_xboard_logic.GetConnectState() == UsartConnectState::Connect) {
badge_controller.change_app(&connect_menu);
} else {
badge_controller.change_app(&name_setting_menu);
}
break;

case BUTTON_MODE:
badge_controller.change_app(&main_menu);
if (g_xboard_logic.GetConnectState() == UsartConnectState::Connect) {
badge_controller.change_app(&connect_menu);
} else {
badge_controller.change_app(&main_menu);
}
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion fw/Core/Hitcon/App/ShowScoreApp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void ShowScoreApp::ShowScore() {
}

void ShowScoreApp::OnButton(button_t button) {
badge_controller.change_app(&main_menu);
badge_controller.BackToMenu(this);
}

} // namespace hitcon
12 changes: 1 addition & 11 deletions fw/Core/Hitcon/App/SnakeApp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,12 @@ void SnakeApp::OnButton(button_t button) {
}
break;
case BUTTON_BACK:
// local leave
if (mode == MODE_MULTIPLAYER) {
uint8_t code = PACKET_GAME_LEAVE;
g_xboard_logic.QueueDataForTx(&code, 1, SNAKE_RECV_ID);
}
// leave action
badge_controller.change_app(&main_menu);
break;
case BUTTON_LONG_BACK:
// local leave 2
if (mode == MODE_MULTIPLAYER) {
uint8_t code = PACKET_GAME_LEAVE;
g_xboard_logic.QueueDataForTx(&code, 1, SNAKE_RECV_ID);
}
// leave action 2
badge_controller.change_app(&show_name_app);
badge_controller.BackToMenu(this);
break;
default:
break;
Expand Down
11 changes: 2 additions & 9 deletions fw/Core/Hitcon/App/TetrisApp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void TetrisApp::OnXboardRecv(void *arg) {
break;

case PACKET_ABORT_GAME:
badge_controller.change_app(&main_menu);
badge_controller.BackToMenu(this);
break;
}
}
Expand Down Expand Up @@ -141,19 +141,12 @@ void TetrisApp::OnButton(button_t button) {
break;

case BUTTON_BACK:
if (multiplayer) {
uint8_t code = PACKET_ABORT_GAME;
g_xboard_logic.QueueDataForTx(&code, 1, TETRIS_RECV_ID);
}
badge_controller.OnAppEnd(this);
break;

case BUTTON_LONG_BACK:
if (multiplayer) {
uint8_t code = PACKET_ABORT_GAME;
g_xboard_logic.QueueDataForTx(&code, 1, TETRIS_RECV_ID);
}
badge_controller.OnAppEnd(this);
badge_controller.BackToMenu(this);
break;

default:
Expand Down
12 changes: 9 additions & 3 deletions fw/Core/Hitcon/Logic/BadgeController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <App/ConnectMenuApp.h>
#include <App/EditNameApp.h>
#include <App/HardwareTestApp.h>
#include <App/MainMenuApp.h>
#include <App/ShowNameApp.h>
#include <Logic/IrController.h>
#include <Logic/XBoardLogic.h>
Expand All @@ -12,6 +13,8 @@

using hitcon::ir::irController;
using hitcon::service::sched::my_assert;
using hitcon::service::xboard::g_xboard_logic;
using hitcon::service::xboard::UsartConnectState;

namespace hitcon {
BadgeController badge_controller;
Expand Down Expand Up @@ -45,11 +48,14 @@ void BadgeController::change_app(App *new_app) {
if (current_app) current_app->OnEntry();
}

void BadgeController::OnAppEnd(App *ending_app) {
void BadgeController::BackToMenu(App *ending_app) {
my_assert(current_app == ending_app);

// TODO: Change this.
change_app(&show_name_app);
if (g_xboard_logic.GetConnectState() == UsartConnectState::Connect) {
change_app(&connect_menu);
} else {
change_app(&main_menu);
}
}

void BadgeController::OnButton(void *arg1) {
Expand Down
2 changes: 1 addition & 1 deletion fw/Core/Hitcon/Logic/BadgeController.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BadgeController {

// App should call this to denote that the app has ended and wishes to return
// to the main menu (or similar).
void OnAppEnd(App *ending_app);
void BackToMenu(App *ending_app);

// TODO: This is called whenever a separate board connects.
void OnXBoardConnect(void *unused);
Expand Down
2 changes: 1 addition & 1 deletion fw/Core/Hitcon/Logic/XBoardGameController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void XBoardGameController::TryExitApp() {
if (connected_) {
badge_controller.change_app(&connect_menu);
} else {
badge_controller.OnAppEnd(&g_send_data_app);
badge_controller.BackToMenu(&g_send_data_app);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions fw/Core/Hitcon/Logic/XBoardLogic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ void XBoardLogic::PingRoutine(void *) {
CheckPong();
}

enum UsartConnectState XBoardLogic::GetConnectState() { return connect_state; }

} // namespace xboard
} // namespace service
} // namespace hitcon
2 changes: 2 additions & 0 deletions fw/Core/Hitcon/Logic/XBoardLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class XBoardLogic {
// - `handler_id`: should be the same as `QueueDataForTx`
void SetOnPacketArrive(callback_t callback, void *self, RecvFnId handler_id);

enum UsartConnectState GetConnectState();

private:
// buffer variables

Expand Down

0 comments on commit 2524d93

Please sign in to comment.