Skip to content

Commit

Permalink
Fix brush tile type #475
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Jan 30, 2020
1 parent e2f84c1 commit c870f6b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
7 changes: 6 additions & 1 deletion src/cdogsed/editor_ui_common.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2014, 2016-2017, 2019 Cong Xu
Copyright (c) 2014, 2016-2017, 2019-2020 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -442,3 +442,8 @@ static void CloseChange(void *data, int d)
UNUSED(data);
UNUSED(d);
}

void TileClassGetBrushName(char *buf, const TileClass *tc)
{
sprintf(buf, "%s (%s)", tc->Name, tc->Style);
}
4 changes: 3 additions & 1 deletion src/cdogsed/editor_ui_common.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2014, 2016 Cong Xu
Copyright (c) 2014, 2016, 2020 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -93,3 +93,5 @@ static void MissionCheckTypeFunc(UIObject *o, void *data)\
}\
o->IsVisible = true;\
}

void TileClassGetBrushName(char *buf, const TileClass *tc);
21 changes: 16 additions & 5 deletions src/cdogsed/editor_ui_static.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2013-2016, 2019 Cong Xu
Copyright (c) 2013-2016, 2019-2020 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -34,6 +34,7 @@
#include <cdogs/draw/draw.h>
#include <cdogs/events.h>
#include <cdogs/font.h>
#include <cdogs/log.h>
#include <cdogs/map.h>

#include "editor_ui_common.h"
Expand All @@ -47,9 +48,19 @@ MISSION_CHECK_TYPE_FUNC(MAPTYPE_STATIC)
static const char *BrushGetTypeStr(EditorBrush *brush, int isMain)
{
static char s[128];
sprintf(s, "Brush %d: %s",
isMain ? 1 : 2,
IMapTypeStr(isMain ? brush->MainType : brush->SecondaryType));
const int idx = isMain ? brush->MainType : brush->SecondaryType;
char tcName[256];
sprintf(tcName, "%d", idx);
const TileClass *tc;
if (hashmap_get(
gMission.missionData->u.Static.TileClasses, tcName, (any_t *)&tc) !=
MAP_OK)
{
LOG(LM_EDIT, LL_ERROR, "cannot find tile class key: %s", tcName);
return "";
}
TileClassGetBrushName(tcName, tc);
sprintf(s, "Brush %d: %s", isMain ? 1 : 2, tcName);
return s;
}
static const char *BrushGetMainTypeStr(UIObject *o, void *data)
Expand Down Expand Up @@ -376,7 +387,7 @@ UIObject *CreateStaticMapObjs(

UIObjectDestroy(o);
o = UIObjectCreate(
UITYPE_LABEL, 0, svec2i_zero(), svec2i(60, th));
UITYPE_LABEL, 0, svec2i_zero(), svec2i(90, th));
pos.x = x;
pos.y += o2->Size.y;
o2 = UIObjectCopy(o);
Expand Down
3 changes: 2 additions & 1 deletion src/cdogsed/tile_brush.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
#include "tile_brush.h"

#include "editor_ui_common.h"
#include "nk_window.h"


Expand Down Expand Up @@ -136,7 +137,7 @@ static int DrawTileType(any_t data, any_t key)
}
// TODO: use keys instead of index
char name[256];
sprintf(name, "%s (%s)", tc->Name, tc->Style);
TileClassGetBrushName(name, tc);
const int selected = *tbData->brushIdx == tbData->tileIdx;
if (nk_select_label(tbData->ctx, name,
NK_TEXT_ALIGN_BOTTOM | NK_TEXT_ALIGN_CENTERED, selected))
Expand Down

0 comments on commit c870f6b

Please sign in to comment.