|
地板

楼主 |
发表于 2020-9-3 18:24:48
|
只看该作者
征兵时部队浮动信息
征兵要选择武将,为让玩家直观看到此个组合能达到效果,需要显示组合后该部队的各项数值,这个各项数值随着选中武将变化而变动,叫浮动信息。
浮数信息是以浮动标签形式实现的。游戏中是下图的右侧部分。
实现浮动信息逻辑
让自底向上说明这个逻辑。
要得出浮动信息需要部队对象,要创建一个临时unit对象就要兵种、组队三武将、归属城市信息。hero面板只能提供武将列表中哪些个索引被选择,recruit面板则几乎有全部信息,为此让recurit面板完成创建unit对象和最后显示,具体操作:- @dlg:hero面板所有对框话指针。要由它知道hero菜单信息和计算浮动数据显示在的起始坐标。
- void recruit_pane::on_hero_list_draw(gui::dialog* dlg)
- {
- std::vector<size_t> checked_heros = dlg->get_menu().checked();
- if (checked_heros.empty()) {
- resources::screen->hide_unit_tooltip();
- return;
- }
- std::vector<hero*> heros = city_.fresh_heros();
- std::sort(heros.begin(), heros.end(), compare_leadership);
- const unit_type* t = (*unit_types_)[index_];
- std::vector<const hero*> v;
- v.push_back(heros[checked_heros[0]]);
- if (checked_heros.size() > 1) {
- v.push_back(heros[checked_heros[1]]);
- }
- if (checked_heros.size() > 2) {
- v.push_back(heros[checked_heros[2]]);
- }
- type_heros_pair pair(t, v);
- unit temp(units_, heros_, pair, city_.cityno(), false);
- gui::dialog::dimension_measurements dim = dlg->get_layout();
- resources::screen->show_unit_tooltip(temp, dim.interior.x + dim.interior.w + 5, dim.interior.y - 28);
- }
复制代码 那on_hero_list_draw是如何被调用?——使用回调,在hero面板的draw_contents()调用该函数。
要在hero_list_pane::draw_contents()调用,需要注意:
1、hero对话框中(其它对话框也一样),菜单内部操作不能刷新面板,要通过一种机制告知对话框上层,对话框上层检测到需要刷新了,然后去控制剧新面板。
2、一直来实现效果:菜单选中行发生该变时会刷新面板。用第1点机制来说:菜单选中行发生变动,菜单的selected_变量改变值;对话框上层一直在循环,循环发现菜单的selected_发生改变,于是去调用面板set_selection();面板的set_selection()把自己设为dirty状态,widgets机制再使此个结果调用面板的draw_contents()。
3、菜单中选择框选中、不选中操作不会引起菜单行发生变动。
以上3点可以得出,要让选择框选中和不选中导致调用面板的draw_contents()就须要改变对话框上层认为该去调用set_selection()条件。- if ((menu_->selection() != info.selection) || menu_->checks_dirty() || info.first_time) {
- menu_->clear_checks_dirty();
- info.selection = menu_->selection();
- int selection = info.selection;
- if (selection < 0) {
- selection = 0;
- }
- if (!preview_panes_.empty()) {
- for (pp_iterator i = preview_panes_.begin(); i != preview_panes_.end(); ++i) {
- (**i).set_selection(selection);
- ......
复制代码 menu_->checks_dirty()是新加条件。当有选择框发生选择改变时它返回true。
注:因为选择框变动导致的面板set_selection,这时菜单选择项并未改变,面板set_selection要知道这个情况,改为即使菜单选中项没改变也要去设置面板为dirty状态。 |
|