Project

General

Profile

Feature #546 » 0050-Lua-Add-server.popup_image.patch

main - Marko Lindqvist, 05/06/2024 12:59 AM

View differences:

client/gui-gtk-3.22/dialogs.c
gtk_window_present(GTK_WINDOW(dialog));
}
/**********************************************************************//**
Popup image window
**************************************************************************/
void popup_image(const char *tag, int width, int height)
{
struct sprite *spr = load_popup_sprite(tag);
if (spr != NULL) {
GdkPixbuf *pix = sprite_get_pixbuf(spr);
GtkWidget *win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
GtkWidget *img = gtk_image_new_from_pixbuf(pix);
gtk_window_set_default_size(GTK_WINDOW(win), width, height);
gtk_container_add(GTK_CONTAINER(win), img);
gtk_widget_show(win);
unload_popup_sprite(tag);
} else {
log_error(_("No image for tag \"%s\", requested by the server."), tag);
}
}
client/gui-gtk-4.0/dialogs.c
gtk_window_present(GTK_WINDOW(dialog));
}
/**********************************************************************//**
Popup image window
**************************************************************************/
void popup_image(const char *tag, int width, int height)
{
struct sprite *spr = load_popup_sprite(tag);
if (spr != NULL) {
GdkPixbuf *pix = sprite_get_pixbuf(spr);
GtkWidget *win = gtk_window_new();
GtkWidget *img = gtk_image_new_from_pixbuf(pix);
gtk_window_set_default_size(GTK_WINDOW(win), width, height);
gtk_window_set_child(GTK_WINDOW(win), img);
gtk_widget_show(win);
unload_popup_sprite(tag);
} else {
log_error(_("No image for tag \"%s\", requested by the server."), tag);
}
}
client/gui-gtk-5.0/dialogs.c
gtk_window_present(GTK_WINDOW(dialog));
}
/**********************************************************************//**
Popup image window
**************************************************************************/
void popup_image(const char *tag, int width, int height)
{
struct sprite *spr = load_popup_sprite(tag);
if (spr != NULL) {
GdkPixbuf *pix = sprite_get_pixbuf(spr);
GtkWidget *win = gtk_window_new();
GtkWidget *img = gtk_image_new_from_pixbuf(pix);
gtk_window_set_default_size(GTK_WINDOW(win), width, height);
gtk_window_set_child(GTK_WINDOW(win), img);
gtk_widget_show(win);
unload_popup_sprite(tag);
} else {
log_error(_("No image for tag \"%s\", requested by the server."), tag);
}
}
client/gui-qt/dialogs.cpp
#include <QTableWidgetItem>
#include <QTextEdit>
#include <QVBoxLayout>
#include <QWindow>
#include <QtMath>
// utility
......
popup_act_confirmation_dialog(hdr, body_text, data);
}
/**********************************************************************//**
Popup image window
**************************************************************************/
void qtg_popup_image(const char *tag, int width, int height)
{
struct sprite *spr = load_popup_sprite(tag);
if (spr != nullptr) {
QDialog *win = new QDialog(gui());
QVBoxLayout *layout = new QVBoxLayout(win);
QPixmap *pm = new QPixmap(*spr->pm);
QLabel *lbl = new QLabel;
win->setFixedSize(width, height);
lbl->setPixmap(*pm);
layout->addWidget(lbl);
win->setLayout(layout);
win->show();
unload_popup_sprite(tag);
} else {
log_error(_("No image for tag \"%s\", requested by the server."), tag);
}
}
client/gui-qt/pages.cpp
void fc_client::create_main_page(void)
{
QPixmap main_graphics(tileset_main_intro_filename(tileset));
QLabel* free_main_pic = new QLabel;
QLabel *free_main_pic = new QLabel;
QPainter painter(&main_graphics);
QStringList buttons_names;
int buttons_nr;
client/gui-qt/qtg_cxxside.cpp
= qtg_real_units_report_dialog_update;
funcs->endgame_report_dialog_start = qtg_endgame_report_dialog_start;
funcs->endgame_report_dialog_player = qtg_endgame_report_dialog_player;
funcs->popup_image = qtg_popup_image;
}
client/gui-qt/qtg_cxxside.h
void qtg_endgame_report_dialog_start(const struct packet_endgame_report *packet);
void qtg_endgame_report_dialog_player(const struct packet_endgame_player *packet);
void qtg_popup_image(const char *tag, int width, int height);
#endif // FC__QTG_CXXSIDE_H
client/gui-sdl2/dialogs.c
/* TODO: Implement. Currently just pass everything as confirmed */
action_confirmation(data, TRUE);
}
struct advanced_dialog *advanced_image_popup = NULL;
/**********************************************************************//**
User interacted with image popup dialog.
**************************************************************************/
static int image_popup_window_callback(struct widget *pwindow)
{
if (PRESSED_EVENT(main_data.event)) {
move_window_group(advanced_image_popup->begin_widget_list, pwindow);
}
return -1;
}
/**********************************************************************//**
User interacted with image popup dialog close button.
**************************************************************************/
static int exit_image_popup_callback(struct widget *pwidget)
{
if (PRESSED_EVENT(main_data.event)) {
if (advanced_image_popup != NULL) {
popdown_window_group_dialog(advanced_image_popup->begin_widget_list,
advanced_image_popup->end_widget_list);
FC_FREE(advanced_image_popup->scroll);
FC_FREE(advanced_image_popup);
flush_dirty();
}
}
return -1;
}
/**********************************************************************//**
Popup image window
**************************************************************************/
void popup_image(const char *tag, int width, int height)
{
if (advanced_image_popup == NULL) {
struct sprite *spr = load_popup_sprite(tag);
if (spr != NULL) {
struct widget *win = create_window_skeleton(NULL, NULL, 0);
struct widget *buf;
SDL_Surface *surf = copy_surface(GET_SURF(spr));
SDL_Rect dst;
SDL_Rect area;
advanced_image_popup = fc_calloc(1, sizeof(struct advanced_dialog));
win->action = image_popup_window_callback;
set_wstate(win, FC_WS_NORMAL);
add_to_gui_list(ID_WINDOW, win);
advanced_image_popup->end_widget_list = win;
/* Create exit button */
buf = create_themeicon(current_theme->small_cancel_icon, win->dst,
WF_WIDGET_HAS_INFO_LABEL | WF_RESTORE_BACKGROUND);
buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
FONTO_ATTENTION);
buf->action = exit_image_popup_callback;
set_wstate(buf, FC_WS_NORMAL);
buf->key = SDLK_ESCAPE;
add_to_gui_list(ID_BUTTON, buf);
advanced_image_popup->begin_widget_list = buf;
resize_window(win, NULL, get_theme_color(COLOR_THEME_BACKGROUND),
win->size.w - win->area.w + width,
win->size.h - win->area.h + buf->area.h + height);
widget_set_position(win,
(main_window_width() - win->size.w) / 2,
(main_window_height() - win->size.h) / 2);
area = win->area;
dst.x = area.x;
dst.y = area.y + buf->size.y;
alphablit(surf, NULL, win->theme, &dst, 255);
/* Redraw */
redraw_group(advanced_image_popup->begin_widget_list, win, 0);
widget_flush(win);
unload_popup_sprite(tag);
} else {
log_error(_("No image for tag \"%s\", requested by the server."), tag);
}
}
}
client/gui-sdl3/dialogs.c
/* TODO: Implement. Currently just pass everything as confirmed */
action_confirmation(data, TRUE);
}
struct advanced_dialog *advanced_image_popup = NULL;
/**********************************************************************//**
User interacted with image popup dialog.
**************************************************************************/
static int image_popup_window_callback(struct widget *pwindow)
{
if (PRESSED_EVENT(main_data.event)) {
move_window_group(advanced_image_popup->begin_widget_list, pwindow);
}
return -1;
}
/**********************************************************************//**
User interacted with image popup dialog close button.
**************************************************************************/
static int exit_image_popup_callback(struct widget *pwidget)
{
if (PRESSED_EVENT(main_data.event)) {
if (advanced_image_popup != NULL) {
popdown_window_group_dialog(advanced_image_popup->begin_widget_list,
advanced_image_popup->end_widget_list);
FC_FREE(advanced_image_popup->scroll);
FC_FREE(advanced_image_popup);
flush_dirty();
}
}
return -1;
}
/**********************************************************************//**
Popup image window
**************************************************************************/
void popup_image(const char *tag, int width, int height)
{
if (advanced_image_popup == NULL) {
struct sprite *spr = load_popup_sprite(tag);
if (spr != NULL) {
struct widget *win = create_window_skeleton(NULL, NULL, 0);
struct widget *buf;
SDL_Surface *surf = copy_surface(GET_SURF(spr));
SDL_Rect dst;
SDL_Rect area;
advanced_image_popup = fc_calloc(1, sizeof(struct advanced_dialog));
win->action = image_popup_window_callback;
set_wstate(win, FC_WS_NORMAL);
add_to_gui_list(ID_WINDOW, win);
advanced_image_popup->end_widget_list = win;
/* Create exit button */
buf = create_themeicon(current_theme->small_cancel_icon, win->dst,
WF_WIDGET_HAS_INFO_LABEL | WF_RESTORE_BACKGROUND);
buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
FONTO_ATTENTION);
buf->action = exit_image_popup_callback;
set_wstate(buf, FC_WS_NORMAL);
buf->key = SDLK_ESCAPE;
add_to_gui_list(ID_BUTTON, buf);
advanced_image_popup->begin_widget_list = buf;
resize_window(win, NULL, get_theme_color(COLOR_THEME_BACKGROUND),
win->size.w - win->area.w + width,
win->size.h - win->area.h + buf->area.h + height);
widget_set_position(win,
(main_window_width() - win->size.w) / 2,
(main_window_height() - win->size.h) / 2);
area = win->area;
dst.x = area.x;
dst.y = area.y + buf->size.y;
alphablit(surf, NULL, win->theme, &dst, 255);
/* Redraw */
redraw_group(advanced_image_popup->begin_widget_list, win, 0);
widget_flush(win);
unload_popup_sprite(tag);
} else {
log_error(_("No image for tag \"%s\", requested by the server."), tag);
}
}
}
client/gui-stub/dialogs.c
/* Just confirm */
action_confirmation(data, TRUE);
}
/**********************************************************************//**
Popup image window
**************************************************************************/
void gui_popup_image(const char *tag, int width, int height)
{
}
client/gui_cbsetter.c
funcs->gui_clear_theme = gui_gui_clear_theme;
funcs->get_gui_specific_themes_directories = gui_get_gui_specific_themes_directories;
funcs->get_usable_themes_in_directory = gui_get_usable_themes_in_directory;
funcs->popup_image = gui_popup_image;
}
client/gui_interface.c
{
funcs.endgame_report_dialog_player(packet);
}
/**********************************************************************//**
Call popup_image callback
**************************************************************************/
void popup_image(const char *tag, int width, int height)
{
funcs.popup_image(tag, width, height);
}
client/gui_interface.h
void (*real_units_report_dialog_update)(void *unused);
void (*endgame_report_dialog_start)(const struct packet_endgame_report *packet);
void (*endgame_report_dialog_player)(const struct packet_endgame_player *packet);
void (*popup_image)(const char *tag, int width, int height);
};
struct gui_funcs *get_gui_funcs(void);
client/include/dialogs_g.h
GUI_FUNC_PROTO(void, update_infra_dialog, void)
GUI_FUNC_PROTO(void, popup_image, const char *tag, int width, int height)
#endif /* FC__DIALOGS_G_H */
client/packhand.c
play_single_track(tag);
}
/************************************************************************//**
Popup image
****************************************************************************/
void handle_popup_image(const char *tag)
{
popup_image(tag, 500, 500);
}
/************************************************************************//**
Open meeting
****************************************************************************/
client/tilespec.c
/*
* Information about an individual sprite. All fields except 'sprite' are
* filled at the time of the scan of the specfile. 'Sprite' is
* set/cleared on demand in load_sprite/unload_sprite.
* set/cleared on demand in load_sprite()/unload_sprite().
*/
struct small_sprite {
int ref_count;
......
{
return t->svg_height;
}
/************************************************************************//**
Load sprite from popup image tag
****************************************************************************/
struct sprite *load_popup_sprite(const char *tag)
{
return load_sprite(tileset, tag, TRUE, TRUE, FALSE);
}
/************************************************************************//**
Unload sprite from popup image tag
****************************************************************************/
void unload_popup_sprite(const char *tag)
{
unload_sprite(tileset, tag);
}
client/tilespec.h
int index_ts_topology(int idx);
struct sprite *load_popup_sprite(const char *tag);
void unload_popup_sprite(const char *tag);
#ifdef __cplusplus
}
#endif /* __cplusplus */
common/networking/packets.def
Max used id:
============
Max id: 514
Max id: 515
Packets are not ordered by their id, but by their category. New packet
with higher id may get added to existing category, and not to the end of file.
......
STRING tag[MAX_LEN_NAME];
end
PACKET_POPUP_IMAGE = 515; sc, lsend, handle-via-fields
STRING tag[MAX_LEN_NAME];
end
/*************** Webclient specific packets ****************/
/* Use range 256:511 for these */
server/scripting/api_server_base.c
return TRUE;
}
/**********************************************************************//**
Popup image to player
**************************************************************************/
bool api_popup_image(lua_State *L, Player *pplayer, const char *tag)
{
struct packet_popup_image p;
LUASCRIPT_CHECK_STATE(L, FALSE);
LUASCRIPT_CHECK_SELF(L, pplayer, FALSE);
LUASCRIPT_CHECK_ARG_NIL(L, tag, 3, API_TYPE_STRING, FALSE);
sz_strlcpy(p.tag, tag);
lsend_packet_popup_image(pplayer->connections, &p);
return TRUE;
}
/**********************************************************************//**
Return the formatted value of the setting or NULL if no such setting
exists.
server/scripting/api_server_base.h
const char *api_server_setting_get(lua_State *L, const char *sett_name);
bool api_play_music(lua_State *L, Player *pplayer, const char *tag);
bool api_popup_image(lua_State *L, Player *pplayer, const char *tag);
#endif /* FC__API_SERVER_BASE_H */
server/scripting/tolua_server.pkg
@ civilization_score (lua_State *L, Player *pplayer);
bool api_play_music
@ play_music (lua_State *L, Player *pplayer, const char *tag);
bool api_popup_image
@ popup_image (lua_State *L, Player *pplayer, const char *tag);
module setting {
const char *api_server_setting_get
(3-3/4)