Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions apps/oc4core/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1109,8 +1109,9 @@ namespace oc4::host
m_queued.push_front({ info, active });
next = m_queued.begin();
}
// (one wonder's movie after the other, each once the last is closed)
if (next->info && next->info->getButtonPopupType() == BUTTONPOPUP_PYTHON_SCREEN && screenUp && screenUp())
// (the game's queued popups wait while a screen of its own or a talk is up, as the original's: a tech's splash first)
if (next->info && (next->info->getButtonPopupType() == BUTTONPOPUP_PYTHON_SCREEN || !next->added) &&
((screenUp && screenUp()) || (diplomacyUp && diplomacyUp())))
return;
if (next->ready)
{
Expand Down
1 change: 1 addition & 0 deletions apps/oc4core/Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ namespace oc4::host
bool isDiploOrPopupWaiting() override { return isPopupUp() || isPopupQueued() || (diplomacyWaiting && diplomacyWaiting()); }
// A talk is up or waits (the host's diplomacy).
std::function<bool()> diplomacyWaiting;
std::function<bool()> diplomacyUp; // (a talk is up)
std::function<void(CvDiploParameters*, PlayerTypes)> diplomacyAsked; // (a talk the player asked for)
// The player's contact with a leader (CvPlayer::contact): the talk waits in the player's
// queue for the screen, as the AI's do.
Expand Down
20 changes: 20 additions & 0 deletions apps/oc4core/Screens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ if _walls:
py::module_ screens = py::module_::import("oc4screens");
screens.attr("setResolution")(width, height);
m_mainId = py::module_::import("CvScreenEnums").attr("MAIN_INTERFACE").cast<int>();
m_techChooserId = py::module_::import("CvScreenEnums").attr("TECH_CHOOSER").cast<int>();
py::module_::import("CvScreensInterface").attr("showMainInterface")();
m_utility.gameInterface().makeInterfaceDirty();
m_utility.gameInterface().techSplash = true;
Expand Down Expand Up @@ -1033,9 +1034,28 @@ if _walls:
// plays its turns so, the military advisor's flashing plots end so).
const float dt = m_lastUpdate.time_since_epoch().count() ? std::min(std::chrono::duration<float>(now - m_lastUpdate).count(), 0.25f) : 0.0f;
m_lastUpdate = now;
bool techChooser = false;
for (py::handle id : screens.attr("shownScreens")().cast<py::list>())
if (const int screen = id.cast<int>(); screen != kDiplomacyScreen)
{
entry.attr("update")(py::make_tuple(screen, dt));
techChooser = techChooser || screen == m_techChooserId;
}
// The tech advisor told when the research changes, as the original engine does
// (CvScreensInterface.forceScreenUpdate: "forced from net message"): a tech clicked,
// queued with Shift, learnt, the turns left. Its techs then take their colours and
// numbers again (CvTechChooser.updateTechRecords).
// (read through the scripts' CyPlayer and CyTeam, oc4screens.researchState: the core's
// own functions are not all exported to the engine on Windows)
const std::string research = techChooser ? screens.attr("researchState")().cast<std::string>() : std::string();
if (research.empty())
m_research.clear();
else if (research != m_research)
{
// (redrawn when it comes up: the original's shows the turns left at once)
entry.attr(m_research.empty() ? "forceScreenRedraw" : "forceScreenUpdate")(py::make_tuple(m_techChooserId));
m_research = research;
}
if (ui.anyDirty())
entry.attr("forceScreenRedraw")(py::make_tuple(m_mainId));
// Diplomacy: the next talk waiting, when nothing is up (the game's script says what the
Expand Down
2 changes: 2 additions & 0 deletions apps/oc4core/Screens.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ namespace oc4::host
bool m_active = false;
bool m_menu = false; // the main menu, not the game's screens
int m_mainId = -1, m_failures = 0;
int m_techChooserId = -1;
std::string m_research; // the active player's research when the tech advisor was last told (empty: not up)
long long m_version = -1;
std::pair<int, int> m_laidOut{ -1, -1 }, m_seenSize{ -1, -1 }; // the size the screens were made for; the window's
std::chrono::steady_clock::time_point m_sizeChanged;
Expand Down
1 change: 1 addition & 0 deletions apps/oc4core/Utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace oc4::host
std::filesystem::create_directories(m_logDir);
m_text.setTagResolver(resolveTextTag);
m_interface.diplomacyWaiting = [this] { return m_diplomacy.active() || m_diplomacy.waiting(); };
m_interface.diplomacyUp = [this] { return m_diplomacy.active(); };
m_interface.diplomacyAsked = [this](CvDiploParameters* params, PlayerTypes p) { m_diplomacy.ask(params, p); };
m_interface.sounds = &m_sounds;
}
Expand Down
22 changes: 21 additions & 1 deletion apps/oc4core/python/oc4screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@ def _changed():
_version[0] += 1


def researchState():
"""The active player's research as a string that changes when the tech advisor should be told
(the tech researched, its progress, the rate, the queue's places, the techs known, the turn); ''
with no active player."""
gc = _cpe.CyGlobalContext()
game = _cpe.CyGame()
iPlayer = game.getActivePlayer()
if iPlayer < 0:
return ''
player = gc.getPlayer(iPlayer)
team = gc.getTeam(player.getTeam())
current = player.getCurrentResearch()
places = [team.isHasTech(i) and -1 or player.getQueuePosition(i) for i in range(gc.getNumTechInfos())]
return repr((game.getGameTurn(), current, current >= 0 and team.getResearchProgress(current) or 0,
player.calculateResearchRate(-1), places))


beforeDisplay = [] # (called before the display list is made: oc4options lays its window out)


Expand Down Expand Up @@ -617,7 +634,10 @@ def addPanel(self, szName, title, helpText, bVerticalLayout, bScrollable, iX, iY
def addScrollPanel(self, szName, title, iX, iY, iWidth, iHeight, eStyle):
w = self._s.add(szName, 'panel')
w.text, w.scroll = _text(title), True
w.x, w.y, w.w, w.h, w.pstyle = int(iX), int(iY), int(iWidth), int(iHeight), _style(_cpe.PanelStyles, eStyle)
# (drawn as nothing whatever its style: the engine's GScrollPanel is transparent,
# GFC_CF_TRANSPARENT in Civ4Theme_ScrollPanel.thm; the tech advisor's techs lie on its
# parchment, SCREEN_BG_OPAQUE under the panel, not on the external style's blue)
w.x, w.y, w.w, w.h, w.pstyle = int(iX), int(iY), int(iWidth), int(iHeight), 'PANEL_STYLE_EMPTY'
# (inside the theme's layout margin, GFC_Control_Layout's Size_OuterMargin of 8: the
# WorldBuilder's load/save buttons, at 0 in their panel at 70, line up with its landmark and
# erase buttons at 8 and 43; the city screen's resource names fit their columns)
Expand Down
16 changes: 16 additions & 0 deletions src/render/Theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,11 @@ namespace oc4::render
if (const Value* f = has("FactorColor"))
if (const Value* combine = resolve(s, has("FactorCombine"));
combine && combine->kind == Value::Kind::Call && !combine->args.empty() && combine->args[0].text == "Modulate")
{
tinted = colour(s, f, tint, tintAlpha);
l.panelColour = tinted && f->kind == Value::Kind::Name && f->text == "GFC_Control_Panel_Color_Inner";
l.tintAlpha = tintAlpha;
}
if (const Value* v = has("Image"))
l.image = bitmap(s, v, tinted ? &tint : nullptr, tintAlpha);
if (const Value* v = has("Center"))
Expand Down Expand Up @@ -938,6 +942,18 @@ namespace oc4::render
return out;
}

Theme::Skin Theme::recoloured(const Skin& skin, Color colour)
{
Skin out = skin;
for (Layer& l : out)
if (l.panelColour)
{
l.image = modulate(l.image, colour, l.tintAlpha);
l.center = modulate(l.center, colour, l.tintAlpha);
}
return out;
}

Theme::Bitmap Theme::addSigned(const Bitmap& b, Color c)
{
if (!b)
Expand Down
7 changes: 7 additions & 0 deletions src/render/Theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ namespace oc4::render
bool section[4]{ true, true, true, true }; // its left, top, right, bottom columns / rows drawn
Color fill{}; // Middle::Fill
float fillAlpha = 0;
// Tinted by the panel's own inner colour (FactorColor GFC_Control_Panel_Color_Inner),
// which a script's setPanelColor changes (the tech advisor's known, researched and
// open techs); its alpha the theme's.
bool panelColour = false;
float tintAlpha = 1;
};
using Skin = std::vector<Layer>;
struct Panel
Expand Down Expand Up @@ -125,6 +130,8 @@ namespace oc4::render
Bitmap addSigned(const Bitmap& bitmap, Color colour);
// The bitmap multiplied by the colour (the Modulate combine): a bar's fill in its colour.
Bitmap modulate(const Bitmap& bitmap, Color colour, float alpha = 1);
// The skin with its panel colour layers tinted by another colour (setPanelColor).
Skin recoloured(const Skin& skin, Color colour);
// Font size 1..4 (the markup's <font=n>); the theme's, else the nearest it has.
Font font(int size, bool bold = false, bool italic = false) const;

Expand Down
5 changes: 3 additions & 2 deletions src/render/UiLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,9 @@ namespace oc4::render
}
else if (const Theme::Panel* p = themedPanel(it))
{
Theme::draw(o, p->inner, x0, y0, x1, y1, it.alpha);
Theme::draw(o, p->border, x0, y0, x1, y1, it.alpha);
// (in the script's colour, setPanelColor, where the theme tints it by its own)
Theme::draw(o, it.hasColor ? m_theme.recoloured(p->inner, it.color) : p->inner, x0, y0, x1, y1, it.alpha);
Theme::draw(o, it.hasColor ? m_theme.recoloured(p->border, it.color) : p->border, x0, y0, x1, y1, it.alpha);
}
else if (!emptyPanel(it.style))
{
Expand Down
Loading