Skip to content

Commit f0536f9

Browse files
committed
三万里河东入海,五千仞岳上摩天
优化ui的状态部分,菜单项的查找逻辑
1 parent 830d3d5 commit f0536f9

File tree

5 files changed

+32
-13
lines changed

5 files changed

+32
-13
lines changed

src/BattleSceneSekiro.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,13 @@ void BattleSceneSekiro::dealEvent(BP_Event& e)
556556
int index = -1;
557557
//0攻击,5防御,3闪身,其他不处理
558558
if (engine->gameControllerGetButton(BP_CONTROLLER_BUTTON_RIGHTSHOULDER)
559+
|| engine->gameControllerGetButton(BP_CONTROLLER_BUTTON_Y)
559560
|| engine->checkKeyPress(BPK_i))
560561
{
561562
index = 0;
562563
}
563564
if (engine->gameControllerGetButton(BP_CONTROLLER_BUTTON_LEFTSHOULDER)
565+
|| engine->gameControllerGetButton(BP_CONTROLLER_BUTTON_X)
564566
|| engine->checkKeyPress(BPK_e))
565567
{
566568
index = 5;

src/RunNode.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ int RunNode::findNextVisibleChild(int i0, Direct direct)
139139
}
140140
auto current = getChild(i0);
141141

142-
int min1 = 9999, min2 = 9999 * 2;
143-
int i1 = i0;
142+
double min1 = 9999, min2 = 9999 * 10;
143+
int i1 = i0, i2 = i0;
144144
//1表示平行于按键方向上的距离,2表示垂直于按键方向上的距离
145145
for (int i = 0; i < childs_.size(); i++)
146146
{
@@ -150,6 +150,7 @@ int RunNode::findNextVisibleChild(int i0, Direct direct)
150150
}
151151
auto c = childs_[i];
152152
int dis1, dis2;
153+
double deg;
153154
switch (direct)
154155
{
155156
case DirectLeft:
@@ -173,17 +174,23 @@ int RunNode::findNextVisibleChild(int i0, Direct direct)
173174
}
174175
if (dis1 <= 0)
175176
{
176-
dis1 += 10000;
177+
continue;
178+
}
179+
deg = atan2(dis2, dis1) * 180 / 3.14159265;
180+
//fmt1::print("{} {} {} \n", dis1, dis2, deg);
181+
if (dis1 < min1 && deg < 15)
182+
{
183+
min1 = dis1;
184+
i1 = i;
177185
}
178-
if (dis1 + dis2 * 10 < min2)
186+
if (dis1 + deg * 20 < min2)
179187
{
180-
min1 = (std::min)(min1, dis1);
181-
min2 = (std::min)(min2, dis1 + dis2 * 10);
188+
min2 = dis1 + deg * 20;
182189
i1 = i;
183190
}
184-
//以上数字的取法:如有坐标一致的点,不考虑第二距离(好像不太明显,以后再改吧)
185191
}
186-
return i1;
192+
if (i1 != i0) { return i1; }
193+
return i2;
187194
}
188195

189196
int RunNode::findFristVisibleChild()

src/TitleScene.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ TitleScene::~TitleScene()
6464
void TitleScene::draw()
6565
{
6666
Engine::getInstance()->fillColor({ 0, 0, 0, 255 }, 0, 0, Engine::getInstance()->getWindowWidth(), Engine::getInstance()->getWindowHeight());
67-
TextureManager::getInstance()->renderTexture("title", 154, 0, 90);
67+
int pic[] = { 154, 154, 153, 154 };
68+
TextureManager::getInstance()->renderTexture("title", pic[battle_mode_], 0, 90);
6869
Font::getInstance()->draw(GameUtil::VERSION(), 28, 0, 0);
6970
return;
7071
//屏蔽随机头像

src/UI.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ UI::UI()
1414
ui_system_->setPosition(300, 0);
1515
addChild(ui_status_);
1616

17-
//貌似这里不能直接调用其他单例,静态量的创建顺序不确定
1817
button_status_ = std::make_shared<Button>();
1918
button_status_->setTexture("title", 122);
2019
button_item_ = std::make_shared<Button>();
@@ -28,7 +27,9 @@ UI::UI()
2827
addChild(heads_);
2928
for (int i = 0; i < TEAMMATE_COUNT; i++)
3029
{
31-
heads_->addChild(std::make_shared<Head>(), 20, 60 + i * 90);
30+
auto h = std::make_shared<Head>();
31+
heads_->addChild(h, 20, 60 + i * 90);
32+
ui_status_->getMenu()->addChild(h);
3233
}
3334
heads_->getChild(0)->setState(NodePass);
3435
//addChild(heads_);
@@ -56,6 +57,7 @@ void UI::dealEvent(BP_Event& e)
5657
std::shared_ptr<Head> head = std::dynamic_pointer_cast<Head>(heads_->getChild(i));
5758
auto role = Save::getInstance()->getTeamMate(i);
5859
head->setRole(role);
60+
head->setVisible(role != nullptr);
5961
if (role == nullptr)
6062
{
6163
continue;
@@ -88,7 +90,7 @@ void UI::dealEvent(BP_Event& e)
8890
//这里设定当前头像为Pass,令其不变暗,因为检测事件是先检测子节点,所以这里可以生效
8991
if (childs_[0] == ui_status_)
9092
{
91-
heads_->getChild(current_head_)->setState(NodePass);
93+
//heads_->getChild(current_head_)->setState(NodePass);
9294
}
9395
childs_[current_button_]->setState(NodePass);
9496

@@ -154,10 +156,12 @@ void UI::dealEvent(BP_Event& e)
154156
{
155157
heads_->setDealEvent(1);
156158
heads_->setUDStyle(1);
159+
heads_->setVisible(false);
157160
}
158161
else
159162
{
160163
heads_->setDealEvent(0);
164+
heads_->setVisible(true);
161165
}
162166
}
163167

src/UIStatus.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class UIStatus : public RunNode
1111

1212
protected:
1313
std::shared_ptr<Button> button_medicine_, button_detoxification_, button_leave_;
14-
std::shared_ptr<Menu> menu_;//, menu_equip_magic_, menu_equip_item_;
14+
std::shared_ptr<Menu> menu_; //, menu_equip_magic_, menu_equip_item_;
1515
std::vector<std::shared_ptr<Button>> equip_magics_;
1616
std::shared_ptr<Button> equip_item_;
1717

@@ -22,11 +22,16 @@ class UIStatus : public RunNode
2222
virtual void draw() override;
2323
virtual void dealEvent(BP_Event& e) override;
2424
virtual void onPressedOK() override;
25+
2526
void setShowButton(bool b) { show_button_ = b; }
2627

2728
void setRole(Role* r) { role_ = r; }
29+
2830
void setRoleName(std::string name);
31+
2932
Role* getRole() { return role_; }
3033

3134
void setExtentionVisible(bool b);
35+
36+
std::shared_ptr<Menu>& getMenu() { return menu_; }
3237
};

0 commit comments

Comments
 (0)