Skip to content

Commit

Permalink
Edit tile style #475
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Feb 25, 2020
1 parent ceab931 commit b812541
Show file tree
Hide file tree
Showing 7 changed files with 297 additions and 105 deletions.
22 changes: 13 additions & 9 deletions src/cdogs/tile_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,7 @@ void TileClassInit(
}
t->Mask = mask;
t->MaskAlt = maskAlt;
if (t->Name != NULL)
{
// Generate the pic in case it doesn't exist
PicManagerGenerateMaskedStylePic(
pm, t->Name, style, type, mask, maskAlt, false);
t->Pic = TileClassGetPic(pm, t);
CASSERT(t->Pic != NULL, "cannot find tile pic");
}
TileClassReloadPic(t, pm);
}
void TileClassInitDefault(
TileClass *t, PicManager *pm, const TileClass *base,
Expand Down Expand Up @@ -212,6 +205,17 @@ void TileClassInitDefault(
t, pm, base, style, TileClassBaseStyleType(base->Type),
mask, maskAlt);
}
void TileClassReloadPic(TileClass *t, PicManager *pm)
{
if (t->Name != NULL)
{
// Generate the pic in case it doesn't exist
PicManagerGenerateMaskedStylePic(
pm, t->Name, t->Style, t->StyleType, t->Mask, t->MaskAlt, false);
t->Pic = TileClassGetPic(pm, t);
CASSERT(t->Pic != NULL, "cannot find tile pic");
}
}
const TileClass *TileClassesGetMaskedTile(
const TileClass *baseClass, const char *style, const char *type,
const color_t mask, const color_t maskAlt)
Expand All @@ -235,6 +239,7 @@ TileClass *TileClassesAdd(
if (error != MAP_OK)
{
LOG(LM_MAIN, LL_ERROR, "failed to add tile class %s: %d", buf, error);
TileClassDestroy(t);
return NULL;
}
LOG(LM_MAIN, LL_DEBUG, "add tile class %s", buf);
Expand Down Expand Up @@ -270,7 +275,6 @@ const Pic *TileClassGetPic(const PicManager *pm, const TileClass *tc)
buf, "%s/%s/%s/%s/%s",
tc->Name, tc->Style, tc->StyleType, maskName, maskAltName);
const Pic *pic = PicManagerGetPic(pm, buf);
CASSERT(pic != NULL, "tile has no pic");
return pic;
}

Expand Down
1 change: 1 addition & 0 deletions src/cdogs/tile_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ void TileClassInit(
void TileClassInitDefault(
TileClass *t, PicManager *pm, const TileClass *base,
const char *forceStyle, const color_t *forceMask);
void TileClassReloadPic(TileClass *t, PicManager *pm);
const char *TileClassBaseStyleType(const TileClassType type);
void TileClassCopy(TileClass *dst, const TileClass *src);
const TileClass *StrTileClass(const char *name);
Expand Down
22 changes: 3 additions & 19 deletions src/cdogsed/char_editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ static const char *IndexHairName(const int i);
static int NumCharacterClasses(void);
static const char *IndexGunName(const int i);
static int NumGuns(void);
static void TexArrayInit(CArray* arr, const int count);
static void TexArrayTerminate(CArray *arr);
static int GunIndex(const WeaponClass *wc);
static void AddCharacterTextures(EditorContext *ec);
static bool Draw(SDL_Window *win, struct nk_context *ctx, void *data);
Expand Down Expand Up @@ -121,12 +119,10 @@ void CharEditor(
CA_FOREACH_END()

TexArrayInit(&ec.texIdsGuns, NumGuns());
for (int i = 0; i < NumGuns(); i++)
{
const GLuint *texid = CArrayGet(&ec.texIdsGuns, i);
const WeaponClass *wc = IndexWeaponClassReal(i);
CA_FOREACH(const GLuint, texid, ec.texIdsGuns)
const WeaponClass *wc = IndexWeaponClassReal(_ca_index);
LoadTexFromPic(*texid, wc->Icon);
}
CA_FOREACH_END()

ec.anim = AnimationGetActorAnimation(ACTORANIMATION_WALKING);
ec.previewDir = DIRECTION_DOWN;
Expand Down Expand Up @@ -213,18 +209,6 @@ static int GunIndex(const WeaponClass *wc)
return -1;
}

static void TexArrayInit(CArray *arr, const int count)
{
CArrayInit(arr, sizeof(GLuint));
CArrayResize(arr, count, NULL);
glGenTextures(count, (GLuint*)arr->data);
}
static void TexArrayTerminate(CArray *arr)
{
glDeleteTextures((GLsizei)arr->size, (const GLuint*)arr->data);
CArrayTerminate(arr);
}

static void AddCharacter(EditorContext *ec, const int cloneIdx);
static int MoveCharacter(
EditorContext *ec, const int selectedIndex, const int d);
Expand Down
14 changes: 14 additions & 0 deletions src/cdogsed/editor_ui_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
*/
#include "editor_ui_common.h"

#include <SDL_opengl.h>

#include <cdogs/events.h>
#include <cdogs/font.h>
#include <cdogs/gamedata.h>
Expand Down Expand Up @@ -472,3 +474,15 @@ char *GetClassNames(const int len, const char *(*indexNameFunc)(const int))
}
return names;
}

void TexArrayInit(CArray* arr, const int count)
{
CArrayInit(arr, sizeof(GLuint));
CArrayResize(arr, count, NULL);
glGenTextures(count, (GLuint*)arr->data);
}
void TexArrayTerminate(CArray* arr)
{
glDeleteTextures((GLsizei)arr->size, (const GLuint*)arr->data);
CArrayTerminate(arr);
}
3 changes: 3 additions & 0 deletions src/cdogsed/editor_ui_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,6 @@ static void MissionCheckTypeFunc(UIObject *o, void *data)\
void TileClassGetBrushName(char *buf, const TileClass *tc);
// Get a null-separated string; for nk_combo_separator
char *GetClassNames(const int len, const char *(*indexNameFunc)(const int));

void TexArrayInit(CArray* arr, const int count);
void TexArrayTerminate(CArray* arr);
21 changes: 15 additions & 6 deletions src/cdogsed/nk_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,12 @@ int nk_combo_separator_image(struct nk_context *ctx,
}

// Also draw currently selected image
const struct nk_image comboImg = nk_image_id(img_ids[selected]);
BeforeDrawTex(img_ids[selected]);
nk_draw_image(&ctx->current->buffer, bounds, &comboImg, nk_white);
if (img_ids != NULL)
{
const struct nk_image comboImg = nk_image_id(img_ids[selected]);
BeforeDrawTex(img_ids[selected]);
nk_draw_image(&ctx->current->buffer, bounds, &comboImg, nk_white);
}

return selected;
}
Expand Down Expand Up @@ -267,15 +270,21 @@ void DrawPic(
struct nk_context *ctx, const Pic *pic, const GLuint texid,
const struct vec2i pos, const float scale)
{
LoadTexFromPic(texid, pic);
if (pic != NULL)
{
LoadTexFromPic(texid, pic);
}
struct nk_image tex = nk_image_id((int)texid);
BeforeDrawTex(texid);
struct nk_rect bounds;
nk_layout_widget_space(&bounds, ctx, ctx->current, nk_true);
bounds.x += pos.x * scale;
bounds.y += pos.y * scale;
bounds.w = pic->size.x * scale;
bounds.h = pic->size.y * scale;
if (pic != NULL)
{
bounds.w = pic->size.x * scale;
bounds.h = pic->size.y * scale;
}
nk_draw_image(&ctx->current->buffer, bounds, &tex, nk_white);
}

Expand Down
Loading

0 comments on commit b812541

Please sign in to comment.