书写实验报告 调整开始界面 修复逃跑后重新进入战斗的问题

This commit is contained in:
2026-06-03 18:27:46 +08:00
parent ed7bb908cb
commit e0e9b5d7af
11 changed files with 268 additions and 43 deletions
+33
View File
@@ -0,0 +1,33 @@
#include "TitleMenu.h"
namespace mana::app {
std::vector<TitleMenuItem> BuildTitleMenuItems(bool hasSave)
{
std::vector<TitleMenuItem> items;
if (hasSave) {
items.push_back({
TitleMenuAction::ContinueGame,
"继续游戏",
true,
});
}
items.push_back({
TitleMenuAction::NewGame,
"开始新游戏",
true,
});
items.push_back({
TitleMenuAction::Help,
"帮助",
true,
});
items.push_back({
TitleMenuAction::Quit,
"退出游戏",
true,
});
return items;
}
} // namespace mana::app
+23
View File
@@ -0,0 +1,23 @@
#pragma once
#include <string>
#include <vector>
namespace mana::app {
enum class TitleMenuAction {
ContinueGame,
NewGame,
Help,
Quit
};
struct TitleMenuItem {
TitleMenuAction action = TitleMenuAction::ContinueGame;
std::string label;
bool enabled = true;
};
std::vector<TitleMenuItem> BuildTitleMenuItems(bool hasSave);
} // namespace mana::app
+19 -36
View File
@@ -17,6 +17,7 @@
#include "ScriptedInteractable.h"
#include "SoundAssets.h"
#include "SpriteAnimation.h"
#include "TitleMenu.h"
#include "TmxMap.h"
#include "TmxMapPool.h"
#include "TmxWorld.h"
@@ -55,6 +56,8 @@ using mana::app::kLogicalScreenHeight;
using mana::app::kLogicalScreenWidth;
using mana::app::kMinimumWindowHeight;
using mana::app::kMinimumWindowWidth;
using mana::app::TitleMenuAction;
using mana::app::TitleMenuItem;
Camera2D LogicalUiCamera(const mana::app::LogicalViewport& viewport)
{
@@ -184,12 +187,6 @@ enum class InventoryPage {
Crafting
};
enum class TitleMenuAction {
ContinueGame,
NewGame,
Help
};
enum class PauseMenuAction {
Resume,
Save,
@@ -197,12 +194,6 @@ enum class PauseMenuAction {
Quit
};
struct TitleMenuItem {
TitleMenuAction action = TitleMenuAction::ContinueGame;
std::string label;
bool enabled = true;
};
struct PauseMenuItem {
PauseMenuAction action = PauseMenuAction::Resume;
std::string label;
@@ -2650,25 +2641,7 @@ std::optional<SaveState> LoadTitleSavePreview(const Runtime& rt)
std::vector<TitleMenuItem> BuildTitleMenuItems(const Runtime& rt)
{
const bool hasSave = LoadTitleSavePreview(rt).has_value();
std::vector<TitleMenuItem> items;
if (hasSave) {
items.push_back({
TitleMenuAction::ContinueGame,
"继续游戏",
true,
});
}
items.push_back({
TitleMenuAction::NewGame,
"开始新游戏",
true,
});
items.push_back({
TitleMenuAction::Help,
"帮助",
true,
});
return items;
return mana::app::BuildTitleMenuItems(hasSave);
}
void DrawTitleButton(Runtime& rt, Font font, const TitleMenuItem& item, Rectangle bounds, bool selected)
@@ -2713,15 +2686,20 @@ void DrawTitleMenu(Runtime& rt, Font font)
DrawTextCn(font, "托诺里宠物世界", {86.0f, 70.0f}, 48.0f, Color{255, 255, 221, 255});
DrawTextCn(font, "Tonori Pet World", {90.0f, 126.0f}, 24.0f, Color{245, 219, 132, 255});
const Rectangle menuPanel{74.0f, 244.0f, 500.0f, 338.0f};
const std::vector<TitleMenuItem> items = BuildTitleMenuItems(rt);
rt.selectedTitleSlot = std::clamp(rt.selectedTitleSlot, 0, static_cast<int>(items.size()) - 1);
const float rowStartY = 330.0f;
const float rowSpacing = 78.0f;
const float rowHeight = 62.0f;
const float lastRowBottom = rowStartY + static_cast<float>(std::max(0, static_cast<int>(items.size()) - 1)) * rowSpacing + rowHeight;
const Rectangle menuPanel{74.0f, 244.0f, 500.0f, std::max(338.0f, lastRowBottom + 32.0f - 244.0f)};
DrawWindowPanel(rt, menuPanel);
DrawIcon(rt, "icon/map.png", {106.0f, 266.0f}, 30.0f);
DrawTextCn(font, "开始界面", {146.0f, 265.0f}, 27.0f, Color{255, 255, 221, 255});
std::vector<TitleMenuItem> items = BuildTitleMenuItems(rt);
rt.selectedTitleSlot = std::clamp(rt.selectedTitleSlot, 0, static_cast<int>(items.size()) - 1);
for (int i = 0; i < static_cast<int>(items.size()); ++i) {
const Rectangle row{110.0f, 330.0f + static_cast<float>(i) * 78.0f, 420.0f, 62.0f};
const Rectangle row{110.0f, rowStartY + static_cast<float>(i) * rowSpacing, 420.0f, rowHeight};
DrawTitleButton(rt, font, items[static_cast<std::size_t>(i)], row, i == rt.selectedTitleSlot);
}
@@ -2742,7 +2720,7 @@ void DrawTitleMenu(Runtime& rt, Font font)
}
if (rt.titleNewGameConfirm) {
DrawTextCn(font, "再次确认将覆盖当前存档", {112.0f, 558.0f}, 17.0f, Color{245, 219, 132, 255});
DrawTextCn(font, "再次确认将覆盖当前存档", {112.0f, lastRowBottom + 12.0f}, 17.0f, Color{245, 219, 132, 255});
}
}
@@ -4487,6 +4465,7 @@ void StartBattle(Runtime& rt, int petIndex, bool playerFirstAction = false)
RestoreActivePetForRetreat(rt);
rt.battle.player = rt.team.pets.empty() ? MakePet("Lulea", 30, 7) : rt.team.pets.front();
rt.battle.wild = rt.wildPets[petIndex].pet;
ScheduleMonsterRespawn(rt, rt.wildPets[petIndex]);
RegisterPetSeen(rt.petJournal, rt.battle.wild.name);
ApplyQuestEvent(rt.questRuntime, QuestEvent::SawPet(rt.battle.wild.name));
rt.battle.message = "野外宠物出现了";
@@ -5734,6 +5713,10 @@ void ExecuteTitleMenuAction(Runtime& rt, TitleMenuAction action, bool enabled)
rt.titleNewGameConfirm = false;
rt.mode = Mode::TitleHelp;
break;
case TitleMenuAction::Quit:
rt.titleNewGameConfirm = false;
rt.exitRequested = true;
break;
}
}